dolibarr 22.0.5
lines.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
5 * Copyright (C) 2014-2016 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39
49// Load translation files required by the page
50$langs->loadLangs(array("bills", "compta", "accountancy", "productbatch", "products"));
51
52$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
53
54$account_parent = GETPOST('account_parent');
55$changeaccount = GETPOST('changeaccount', 'array');
56// Search Getpost
57$search_societe = GETPOST('search_societe', 'alpha');
58$search_lineid = GETPOST('search_lineid', 'alpha');
59$search_ref = GETPOST('search_ref', 'alpha');
60$search_invoice = GETPOST('search_invoice', 'alpha');
61$search_label = GETPOST('search_label', 'alpha');
62$search_desc = GETPOST('search_desc', 'alpha');
63$search_amount = GETPOST('search_amount', 'alpha');
64$search_account = GETPOST('search_account', 'alpha');
65$search_vat = GETPOST('search_vat', 'alpha');
66$search_date_startday = GETPOSTINT('search_date_startday');
67$search_date_startmonth = GETPOSTINT('search_date_startmonth');
68$search_date_startyear = GETPOSTINT('search_date_startyear');
69$search_date_endday = GETPOSTINT('search_date_endday');
70$search_date_endmonth = GETPOSTINT('search_date_endmonth');
71$search_date_endyear = GETPOSTINT('search_date_endyear');
72$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
73$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
74$search_country = GETPOST('search_country', 'aZ09');
75$search_tvaintra = GETPOST('search_tvaintra', 'alpha');
76
77// Load variable for pagination
78$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION', $conf->liste_limit);
79$sortfield = GETPOST('sortfield', 'aZ09comma');
80$sortorder = GETPOST('sortorder', 'aZ09comma');
81$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
82if (empty($page) || $page < 0) {
83 $page = 0;
84}
85$offset = $limit * $page;
86$pageprev = $page - 1;
87$pagenext = $page + 1;
88if (!$sortfield) {
89 $sortfield = "f.datef, f.ref, fd.rowid";
90}
91if (!$sortorder) {
92 if (getDolGlobalInt('ACCOUNTING_LIST_SORT_VENTILATION_DONE') > 0) {
93 $sortorder = "DESC";
94 } else {
95 $sortorder = "ASC";
96 }
97}
98
99// Security check
100if (!isModEnabled('accounting')) {
102}
103if ($user->socid > 0) {
105}
106if (!$user->hasRight('accounting', 'bind', 'write')) {
108}
109
110// Initialize technical objects
111$contextpage = 'accountancycustomerlines';
112$hookmanager->initHooks([$contextpage ]);
113$formaccounting = new FormAccounting($db);
114
115
116$arrayfields = array(
117 'fd.rowid' => array('label' => "LineId", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
118 'f.ref' => array('label' => "Invoice", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
119 'f.datef' => array('label' => "Date", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // f.datef, f.ref, fd.rowid
120 'p.ref' => array('label' => "ProductRef", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
121 'fd.description' => array('label' => "ProductDescription", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
122 'fd.total_ht' => array('label' => "Amount", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
123 'fd.tva_tx' => array('label' => "VATRate", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
124 's.nom' => array('label' => "ThirdParty", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
125 'co.label' => array('label' => "Country", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
126 's.tva_intra' => array('label' => "VATIntra", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
127 'aa.account_number' => array('label' => "AccountAccounting", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
128);
129// @phpstan-ignore-next-line
130$arrayfields = dol_sort_array($arrayfields, 'position');
131
132/*
133 * Actions
134 */
135
136$parameters = array('arrayfields' => &$arrayfields);
137$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
138if ($reshook < 0) {
139 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140}
141
142if (empty($reshook)) {
143 // Selection of new fields
144 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
145
146 // Purge search criteria
147 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
148 $search_societe = '';
149 $search_lineid = '';
150 $search_ref = '';
151 $search_invoice = '';
152 $search_label = '';
153 $search_desc = '';
154 $search_amount = '';
155 $search_account = '';
156 $search_vat = '';
157 $search_date_startday = '';
158 $search_date_startmonth = '';
159 $search_date_startyear = '';
160 $search_date_endday = '';
161 $search_date_endmonth = '';
162 $search_date_endyear = '';
163 $search_date_start = '';
164 $search_date_end = '';
165 $search_country = '';
166 $search_tvaintra = '';
167 }
168
169 if (is_array($changeaccount) && count($changeaccount) > 0 && $user->hasRight('accounting', 'bind', 'write')) {
170 $error = 0;
171
172 if (!(GETPOSTINT('account_parent') >= 0)) {
173 $error++;
174 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
175 }
176
177 if (!$error) {
178 $db->begin();
179
180 $sql1 = "UPDATE ".MAIN_DB_PREFIX."facturedet";
181 $sql1 .= " SET fk_code_ventilation = ".(GETPOSTINT('account_parent') > 0 ? GETPOSTINT('account_parent') : 0);
182 $sql1 .= ' WHERE rowid IN ('.$db->sanitize(implode(',', $changeaccount)).')';
183
184 dol_syslog('accountancy/customer/lines.php::changeaccount sql= '.$sql1);
185 $resql1 = $db->query($sql1);
186 if (!$resql1) {
187 $error++;
188 setEventMessages($db->lasterror(), null, 'errors');
189 }
190 if (!$error) {
191 $db->commit();
192 setEventMessages($langs->trans("Save"), null, 'mesgs');
193 } else {
194 $db->rollback();
195 setEventMessages($db->lasterror(), null, 'errors');
196 }
197
198 $account_parent = ''; // Protection to avoid to mass apply it a second time
199 }
200 }
201}
202
203if (GETPOST('sortfield') == 'f.datef, f.ref, fd.rowid') {
204 $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1);
205 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
206 $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_DONE", $value, 'yesno', 0, '', $conf->entity);
207}
208
209/*
210 * View
211 */
212
213$form = new Form($db);
214$formother = new FormOther($db);
215
216$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
217
218llxHeader('', $langs->trans("CustomersVentilation").' - '.$langs->trans("Dispatched"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-customer page-lines');
219
220print '<script type="text/javascript">
221 $(function () {
222 $(\'#select-all\').click(function(event) {
223 // Iterate each checkbox
224 $(\':checkbox\').each(function() {
225 this.checked = true;
226 });
227 });
228 $(\'#unselect-all\').click(function(event) {
229 // Iterate each checkbox
230 $(\':checkbox\').each(function() {
231 this.checked = false;
232 });
233 });
234 });
235 </script>';
236
237/*
238 * Customer Invoice lines
239 */
240$sql = "SELECT f.rowid as facid, f.ref as ref, f.type as ftype, f.situation_cycle_ref, f.datef, f.ref_client,";
241$sql .= " fd.rowid, fd.description, fd.product_type as line_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.vat_src_code, fd.total_ttc, fd.situation_percent,";
242$sql .= " s.rowid as socid, s.nom as name, s.code_client,";
243if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
244 $sql .= " spe.accountancy_code_customer as code_compta_client,";
245 $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
246} else {
247 $sql .= " s.code_compta as code_compta_client,";
248 $sql .= " s.code_compta_fournisseur,";
249}
250$sql .= " p.rowid as product_id, p.fk_product_type as product_type, p.ref as product_ref, p.label as product_label, p.tobuy, p.tosell,";
251if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
252 $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
253} else {
254 $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
255}
256$sql .= " aa.rowid as fk_compte, aa.account_number, aa.label as label_account, aa.labelshort as labelshort_account,";
257$sql .= " fd.situation_percent,";
258$sql .= " co.code as country_code, co.label as country,";
259$sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
260$parameters = array();
261$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
262$sql .= $hookmanager->resPrint;
263$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
264$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
265if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
266 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
267}
268$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
269$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
270$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
271if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
272 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
273}
274$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
275// Add table from hooks
276$parameters = array();
277$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
278$sql .= $hookmanager->resPrint;
279$sql .= " WHERE fd.fk_code_ventilation > 0";
280$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
281$sql .= " AND f.fk_statut > 0";
282if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
283 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
284} else {
285 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
286}
287// Add search filter like
288if ($search_societe) {
289 $sql .= natural_search('s.nom', $search_societe);
290}
291if ($search_lineid) {
292 $sql .= natural_search("fd.rowid", $search_lineid, 1);
293}
294if (strlen(trim($search_invoice))) {
295 $sql .= natural_search("f.ref", $search_invoice);
296}
297if (strlen(trim($search_ref))) {
298 $sql .= natural_search("p.ref", $search_ref);
299}
300if (strlen(trim($search_label))) {
301 $sql .= natural_search("p.label", $search_label);
302}
303if (strlen(trim($search_desc))) {
304 $sql .= natural_search("fd.description", $search_desc);
305}
306if (strlen(trim($search_amount))) {
307 $sql .= natural_search("fd.total_ht", $search_amount, 1);
308}
309if (strlen(trim($search_account))) {
310 $sql .= natural_search("aa.account_number", $search_account);
311}
312if (strlen(trim($search_vat))) {
313 $sql .= natural_search("fd.tva_tx", price2num($search_vat), 1);
314}
315if ($search_date_start) {
316 $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
317}
318if ($search_date_end) {
319 $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
320}
321if (strlen(trim($search_country))) {
322 $arrayofcode = getCountriesInEEC();
323 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
324 foreach ($arrayofcode as $key => $value) {
325 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
326 if ($value != $mysoc->country_code) {
327 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
328 }
329 }
330 if ($search_country == 'special_allnotme') {
331 $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
332 } elseif ($search_country == 'special_eec') {
333 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
334 } elseif ($search_country == 'special_eecnotme') {
335 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
336 } elseif ($search_country == 'special_noteec') {
337 $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
338 } else {
339 $sql .= natural_search("co.code", $search_country);
340 }
341}
342if (strlen(trim($search_tvaintra))) {
343 $sql .= natural_search("s.tva_intra", $search_tvaintra);
344}
345$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
346// Add where from hooks
347$parameters = array();
348$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
349$sql .= $hookmanager->resPrint;
350
351$sql .= $db->order($sortfield, $sortorder);
352
353// Count total nb of records
354$nbtotalofrecords = '';
355if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
356 $result = $db->query($sql);
357 $nbtotalofrecords = $db->num_rows($result);
358 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
359 $page = 0;
360 $offset = 0;
361 }
362}
363
364$sql .= $db->plimit($limit + 1, $offset);
365
366dol_syslog("/accountancy/customer/lines.php", LOG_DEBUG);
367$result = $db->query($sql);
368if ($result) {
369 $num_lines = $db->num_rows($result);
370 $i = 0;
371
372 $param = '';
373 if ($contextpage != $_SERVER["PHP_SELF"]) {
374 $param .= '&contextpage='.urlencode($contextpage);
375 }
376 if ($limit > 0 && $limit != $conf->liste_limit) {
377 $param .= '&limit='.((int) $limit);
378 }
379 if ($search_societe) {
380 $param .= "&search_societe=".urlencode($search_societe);
381 }
382 if ($search_invoice) {
383 $param .= "&search_invoice=".urlencode($search_invoice);
384 }
385 if ($search_ref) {
386 $param .= "&search_ref=".urlencode($search_ref);
387 }
388 if ($search_label) {
389 $param .= "&search_label=".urlencode($search_label);
390 }
391 if ($search_desc) {
392 $param .= "&search_desc=".urlencode($search_desc);
393 }
394 if ($search_account) {
395 $param .= "&search_account=".urlencode($search_account);
396 }
397 if ($search_vat) {
398 $param .= "&search_vat=".urlencode($search_vat);
399 }
400 if ($search_date_startday) {
401 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
402 }
403 if ($search_date_startmonth) {
404 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
405 }
406 if ($search_date_startyear) {
407 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
408 }
409 if ($search_date_endday) {
410 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
411 }
412 if ($search_date_endmonth) {
413 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
414 }
415 if ($search_date_endyear) {
416 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
417 }
418 if ($search_country) {
419 $param .= "&search_country=".urlencode($search_country);
420 }
421 if ($search_tvaintra) {
422 $param .= "&search_tvaintra=".urlencode($search_tvaintra);
423 }
424 // Add $param from hooks
425 $parameters = array('param' => &$param);
426 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
427 $param .= $hookmanager->resPrint;
428
429 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
430 print '<input type="hidden" name="action" value="ventil">';
431 if ($optioncss != '') {
432 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
433 }
434 print '<input type="hidden" name="token" value="'.newToken().'">';
435 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
436 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
437 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
438 print '<input type="hidden" name="page" value="'.$page.'">';
439
440 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
441 print_barre_liste($langs->trans("InvoiceLinesDone").'<br><span class="opacitymedium small">'.$langs->trans("DescVentilDoneCustomer").'</span>', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit, 0, 0, 1);
442
443 print '<br>'.$langs->trans("ChangeAccount").' <div class="inline-block paddingbottom marginbottomonly">';
444 print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
445 print '<input type="submit" class="button small smallpaddingimp valignmiddle" value="'.$langs->trans("ChangeBinding").'"/></div>';
446
447 $moreforfilter = '';
448
449 $varpage = $contextpage;
450 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
451 $selectedfields = $htmlofselectarray;
452 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
453
454 print '<div class="div-table-responsive">';
455 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
456
457 print '<tr class="liste_titre_filter">';
458 // Action column
459 if ($conf->main_checkbox_left_column) {
460 print '<td class="liste_titre maxwidthsearch center actioncolumn">';
461 $searchpicto = $form->showFilterButtons('left');
462 print $searchpicto;
463 print '</td>';
464 }
465 // Line ID
466 if (!empty($arrayfields['fd.rowid']['checked'])) {
467 print '<td class="liste_titre" data-key="lineid">';
468 print '<input type="text" class="flat maxwidth40" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'">';
469 print '</td>';
470 }
471 // Ref invoice
472 if (!empty($arrayfields['f.ref']['checked'])) {
473 print '<td class="liste_titre" data-key="invoice">';
474 print '<input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'">';
475 print '</td>';
476 }
477 // Date
478 if (!empty($arrayfields['f.datef']['checked'])) {
479 print '<td class="liste_titre center">';
480 print '<div class="nowrapfordate">';
481 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
482 print '</div>';
483 print '<div class="nowrapfordate">';
484 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
485 print '</div>';
486 print '</td>';
487 }
488 // Product ref
489 if (!empty($arrayfields['p.ref']['checked'])) {
490 print '<td class="liste_titre" data-key="ref">';
491 print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
492 print '</td>';
493 }
494 //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
495 // Description
496 if (!empty($arrayfields['fd.description']['checked'])) {
497 print '<td class="liste_titre" data-key="desc">';
498 print '<input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'">';
499 print '</td>';
500 }
501 // Amount
502 if (!empty($arrayfields['fd.total_ht']['checked'])) {
503 print '<td class="liste_titre" data-key="amount">';
504 print '<input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
505 print '</td>';
506 }
507 // VAT
508 if (!empty($arrayfields['fd.tva_tx']['checked'])) {
509 print '<td class="liste_titre" data-key="vat">';
510 print '<input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'">';
511 print '</td>';
512 }
513 // Thirdparty
514 if (!empty($arrayfields['s.nom']['checked'])) {
515 print '<td class="liste_titre" data-key="societe">';
516 print '<input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
517 print '</td>';
518 }
519 // Country
520 if (!empty($arrayfields['co.label']['checked'])) {
521 print '<td class="liste_titre" data-key="country">';
522 print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth125', 'code2', 1, 0, 1);
523 //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
524 print '</td>';
525 }
526 // TVA Intracom
527 if (!empty($arrayfields['s.tva_intra']['checked'])) {
528 print '<td class="liste_titre">';
529 print '<input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'">';
530 print '</td>';
531 }
532 // Account
533 if (!empty($arrayfields['aa.account_number']['checked'])) {
534 print '<td class="liste_titre">';
535 print '<input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).'">';
536 print '</td>';
537 }
538 // Fields from hook
539 $parameters = array('arrayfields' => $arrayfields);
540 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
541 print $hookmanager->resPrint;
542 // Action column
543 if (!$conf->main_checkbox_left_column) {
544 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
545 $searchpicto = $form->showFilterButtons();
546 print $searchpicto;
547 print '</td>';
548 }
549 print "</tr>\n";
550
551 // Fields title label
552 // --------------------------------------------------------------------
553
554 $totalarray = array();
555 $totalarray['nbfield'] = 0;
556
557 print '<tr class="liste_titre">';
558 // Action column
559 if ($conf->main_checkbox_left_column) {
560 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
561 $totalarray['nbfield']++;
562 }
563 // Line ID
564 if (!empty($arrayfields['fd.rowid']['checked'])) {
565 print_liste_field_titre($arrayfields['fd.rowid']['label'], $_SERVER["PHP_SELF"], "fd.rowid", "", $param, '', $sortfield, $sortorder);
566 $totalarray['nbfield']++;
567 }
568 // Ref invoice
569 if (!empty($arrayfields['f.ref']['checked'])) {
570 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
571 $totalarray['nbfield']++;
572 }
573 // Date
574 if (!empty($arrayfields['f.datef']['checked'])) {
575 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef, f.ref, fd.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
576 $totalarray['nbfield']++;
577 }
578 // Product ref
579 if (!empty($arrayfields['p.ref']['checked'])) {
580 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
581 $totalarray['nbfield']++;
582 }
583 //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
584 // description
585 if (!empty($arrayfields['fd.description']['checked'])) {
586 print_liste_field_titre($arrayfields['fd.description']['label'], $_SERVER["PHP_SELF"], "fd.description", "", $param, '', $sortfield, $sortorder);
587 $totalarray['nbfield']++;
588 }
589 // Amount
590 if (!empty($arrayfields['fd.total_ht']['checked'])) {
591 print_liste_field_titre($arrayfields['fd.total_ht']['label'], $_SERVER["PHP_SELF"], "fd.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
592 $totalarray['nbfield']++;
593 }
594 // VAT
595 if (!empty($arrayfields['fd.tva_tx']['checked'])) {
596 print_liste_field_titre($arrayfields['fd.tva_tx']['label'], $_SERVER["PHP_SELF"], "fd.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
597 $totalarray['nbfield']++;
598 }
599 // Thirdparty
600 if (!empty($arrayfields['s.nom']['checked'])) {
601 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
602 $totalarray['nbfield']++;
603 }
604 // Country
605 if (!empty($arrayfields['co.label']['checked'])) {
606 print_liste_field_titre($arrayfields['co.label']['label'], $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
607 $totalarray['nbfield']++;
608 }
609 // TVA Intracom
610 if (!empty($arrayfields['s.tva_intra']['checked'])) {
611 print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
612 $totalarray['nbfield']++;
613 }
614 // Account
615 if (!empty($arrayfields['aa.account_number']['checked'])) {
616 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
617 $totalarray['nbfield']++;
618 }
619 // Hook fields
620 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
621 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
622 print $hookmanager->resPrint;
623 // Action column
624 if (!$conf->main_checkbox_left_column) {
625 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
626 $totalarray['nbfield']++;
627 }
628 print "</tr>\n";
629
630 $thirdpartystatic = new Societe($db);
631 $facturestatic = new Facture($db);
632 $productstatic = new Product($db);
633 $accountingaccountstatic = new AccountingAccount($db);
634 $totalarray = array();
635 $totalarray['nbfield'] = 0;
636
637 $i = 0;
638 while ($i < min($num_lines, $limit)) {
639 $objp = $db->fetch_object($result);
640
641 $facturestatic->ref = $objp->ref;
642 $facturestatic->id = $objp->facid;
643 $facturestatic->type = $objp->ftype;
644
645 $thirdpartystatic->id = $objp->socid;
646 $thirdpartystatic->name = $objp->name;
647 $thirdpartystatic->client = $objp->client;
648 $thirdpartystatic->fournisseur = $objp->fournisseur;
649 $thirdpartystatic->code_client = $objp->code_client;
650 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
651 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
652 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
653 $thirdpartystatic->email = $objp->email;
654 $thirdpartystatic->country_code = $objp->country_code;
655
656 $productstatic->ref = $objp->product_ref;
657 $productstatic->id = $objp->product_id;
658 $productstatic->label = $objp->product_label;
659 $productstatic->type = $objp->line_type;
660 $productstatic->status = $objp->tosell;
661 $productstatic->status_buy = $objp->tobuy;
662 $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
663 $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
664 $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
665
666 $accountingaccountstatic->rowid = $objp->fk_compte;
667 $accountingaccountstatic->label = $objp->label_account;
668 $accountingaccountstatic->labelshort = $objp->labelshort_account;
669 $accountingaccountstatic->account_number = $objp->account_number;
670
671 print '<tr class="oddeven">';
672
673 // Action column
674 if ($conf->main_checkbox_left_column) {
675 print '<td class="nowrap center actioncolumn">';
676 $selected = in_array($objp->rowid, $changeaccount);
677 print '<input id="cb'.$objp->rowid.'" class="flat checkforselect checkforaction" type="checkbox" name="changeaccount[]" value="'.$objp->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
678 print '</td>';
679 if (!$i) {
680 $totalarray['nbfield']++;
681 }
682 }
683 // Line id
684 if (!empty($arrayfields['fd.rowid']['checked'])) {
685 print '<td>'.$objp->rowid.'</td>';
686 $totalarray['nbfield']++;
687 }
688 // Ref Invoice
689 if (!empty($arrayfields['f.ref']['checked'])) {
690 print '<td class="nowraponall tdoverflowmax125">'.$facturestatic->getNomUrl(1).'</td>';
691 $totalarray['nbfield']++;
692 }
693 // Date invoice
694 if (!empty($arrayfields['f.datef']['checked'])) {
695 print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
696 $totalarray['nbfield']++;
697 }
698 // Ref Product
699 if (!empty($arrayfields['p.ref']['checked'])) {
700 print '<td class="tdoverflowmax100">';
701 if ($productstatic->id > 0) {
702 print $productstatic->getNomUrl(1);
703 } else {
704 print '&nbsp;';
705 }
706 //if ($productstatic->id > 0 && $objp->product_label) {
707 print '<br>';
708 //}
709 if ($objp->product_label) {
710 print '<span class="opacitymedium">'.$objp->product_label.'</span>';
711 } else {
712 print '&nbsp;';
713 }
714 print '</td>';
715 $totalarray['nbfield']++;
716 }
717 // Description
718 if (!empty($arrayfields['fd.description']['checked'])) {
719 $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description, 1));
720 print '<td class="tdoverflowmax200 small" title="'.dol_escape_htmltag($text).'">';
721 $trunclength = getDolGlobalInt('ACCOUNTING_LENGTH_DESCRIPTION', 32);
722 print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
723 print '</td>';
724 $totalarray['nbfield']++;
725 }
726 // Amount
727 if (!empty($arrayfields['fd.total_ht']['checked'])) {
728 print '<td class="right nowraponall amount">';
729
730 // Create a compensation rate for old situation invoice feature.
731 $situation_ratio = 1;
732 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
733 if ($objp->situation_cycle_ref) {
734 // Avoid divide by 0
735 if ($objp->situation_percent == 0) {
736 $situation_ratio = 0;
737 } else {
738 $line = new FactureLigne($db);
739 $line->fetch($objp->rowid);
740
741 // Situation invoices handling
742 $prev_progress = $line->get_prev_progress($objp->facid);
743
744 $situation_ratio = ($objp->situation_percent - $prev_progress) / $objp->situation_percent;
745 }
746 }
747 print price($objp->total_ht * $situation_ratio);
748 } else {
749 print price($objp->total_ht);
750 }
751 print '</td>';
752 $totalarray['nbfield']++;
753 }
754 // Vat rate
755 if (!empty($arrayfields['fd.tva_tx']['checked'])) {
756 print '<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : '')).'</td>';
757 $totalarray['nbfield']++;
758 }
759 // Thirdparty
760 if (!empty($arrayfields['s.nom']['checked'])) {
761 print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
762 $totalarray['nbfield']++;
763 }
764 // Country
765 if (!empty($arrayfields['co.label']['checked'])) {
766 print '<td class="tdoverflowmax125" title="'.dolPrintHTML($langs->trans("Country".$objp->country_code).' ('.$objp->country_code.')').'">';
767 if ($objp->country_code) {
768 print $langs->trans("Country".$objp->country_code).' ('.$objp->country_code.')';
769 }
770 print '</td>';
771 $totalarray['nbfield']++;
772 }
773 // TVA Intracom
774 if (!empty($arrayfields['s.tva_intra']['checked'])) {
775 print '<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).'">'.dol_escape_htmltag($objp->tva_intra).'</td>';
776 $totalarray['nbfield']++;
777 }
778 // Account
779 if (!empty($arrayfields['aa.account_number']['checked'])) {
780 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($accountingaccountstatic->label).'">';
781 print '<a class="editfielda" href="./card.php?id='.$objp->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($param ? '?'.$param : '')).'">';
782 print img_edit();
783 print '</a> ';
784 print $accountingaccountstatic->getNomUrl(0, 1, 1, '', 1);
785 print '</td>';
786 $totalarray['nbfield']++;
787 }
788
789 // Fields from hook
790 $parameters = array('arrayfields' => $arrayfields, 'obj' => $objp, 'i' => $i, 'totalarray' => &$totalarray);
791 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
792 print $hookmanager->resPrint;
793
794 // Action column
795 if (!$conf->main_checkbox_left_column) {
796 print '<td class="nowrap center actioncolumn">';
797 $selected = in_array($objp->rowid, $changeaccount);
798 print '<input id="cb'.$objp->rowid.'" class="flat checkforselect checkforaction" type="checkbox" name="changeaccount[]" value="'.$objp->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
799 print '</td>';
800 if (!$i) {
801 $totalarray['nbfield']++;
802 }
803 }
804
805 print '</tr>';
806 $i++;
807 }
808 if ($num_lines == 0) {
809 $colspan = 1;
810 foreach ($arrayfields as $key => $val) {
811 if (!empty($val['checked'])) {
812 $colspan++;
813 }
814 }
815 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
816 }
817
818 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
819 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
820 print $hookmanager->resPrint;
821
822 print '</table>';
823 print "</div>";
824
825 if ($nbtotalofrecords > $limit) {
826 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
827 }
828
829 print '</form>';
830} else {
831 print $db->lasterror();
832}
833
834// End of page
835llxFooter();
836$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$totalarray
Definition export.php:1206
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage accounting accounts.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.