dolibarr 24.0.0-beta
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';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
42require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
43require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
47
48// Load translation files required by the page
49$langs->loadLangs(array("bills", "compta", "accountancy", "productbatch", "products"));
50
51$action = GETPOST('action');
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$object = new stdClass();
116
117$arrayfields = array(
118 'fd.rowid' => array('label' => "LineId", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
119 'f.ref' => array('label' => "Invoice", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
120 'f.datef' => array('label' => "Date", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // f.datef, f.ref, fd.rowid
121 'p.ref' => array('label' => "ProductRef", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
122 'fd.description' => array('label' => "ProductDescription", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
123 'fd.total_ht' => array('label' => "Amount", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
124 'fd.tva_tx' => array('label' => "VATRate", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
125 's.nom' => array('label' => "ThirdParty", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
126 'co.label' => array('label' => "Country", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
127 's.tva_intra' => array('label' => "VATIntra", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
128 'aa.account_number' => array('label' => "AccountAccounting", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
129);
130// @phpstan-ignore-next-line
131$arrayfields = dol_sort_array($arrayfields, 'position');
132
133
134/*
135 * Actions
136 */
137
138$parameters = array('arrayfields' => &$arrayfields);
139$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
140if ($reshook < 0) {
141 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
142}
143
144if (empty($reshook)) {
145 // Selection of new fields
146 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
147
148 // Purge search criteria
149 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
150 $search_societe = '';
151 $search_lineid = '';
152 $search_ref = '';
153 $search_invoice = '';
154 $search_label = '';
155 $search_desc = '';
156 $search_amount = '';
157 $search_account = '';
158 $search_vat = '';
159 $search_date_startday = '';
160 $search_date_startmonth = '';
161 $search_date_startyear = '';
162 $search_date_endday = '';
163 $search_date_endmonth = '';
164 $search_date_endyear = '';
165 $search_date_start = '';
166 $search_date_end = '';
167 $search_country = '';
168 $search_tvaintra = '';
169 }
170
171 if (is_array($changeaccount) && count($changeaccount) > 0 && $user->hasRight('accounting', 'bind', 'write')) {
172 $error = 0;
173
174 if (!(GETPOSTINT('account_parent') >= 0)) {
175 $error++;
176 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
177 }
178
179 if (!$error) {
180 $db->begin();
181
182 $sql1 = "UPDATE ".MAIN_DB_PREFIX."facturedet";
183 $sql1 .= " SET fk_code_ventilation = ".(GETPOSTINT('account_parent') > 0 ? GETPOSTINT('account_parent') : 0);
184 $sql1 .= ' WHERE rowid IN ('.$db->sanitize(implode(',', $changeaccount)).')';
185
186 dol_syslog('accountancy/customer/lines.php::changeaccount sql= '.$sql1);
187 $resql1 = $db->query($sql1);
188 if (!$resql1) {
189 $error++;
190 setEventMessages($db->lasterror(), null, 'errors');
191 }
192 if (!$error) {
193 $db->commit();
194 setEventMessages($langs->trans("Save"), null, 'mesgs');
195 } else {
196 $db->rollback();
197 setEventMessages($db->lasterror(), null, 'errors');
198 }
199
200 $account_parent = ''; // Protection to avoid to mass apply it a second time
201 }
202 }
203}
204
205if (GETPOST('sortfield') == 'f.datef, f.ref, fd.rowid') {
206 $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1);
207 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
208 $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_DONE", $value, 'yesno', 0, '', $conf->entity);
209}
210
211/*
212 * View
213 */
214
215$form = new Form($db);
216$formother = new FormOther($db);
217
218$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
219
220llxHeader('', $langs->trans("CustomersVentilation").' - '.$langs->trans("Dispatched"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-customer page-lines');
221
222print '<script type="text/javascript">
223 $(function () {
224 $(\'#select-all\').click(function(event) {
225 // Iterate each checkbox
226 $(\':checkbox\').each(function() {
227 this.checked = true;
228 });
229 });
230 $(\'#unselect-all\').click(function(event) {
231 // Iterate each checkbox
232 $(\':checkbox\').each(function() {
233 this.checked = false;
234 });
235 });
236 });
237 </script>';
238
239/*
240 * Customer Invoice lines
241 */
242$sql = "SELECT f.rowid as facid, f.ref as ref, f.type as ftype, f.situation_cycle_ref, f.datef, f.ref_client,";
243$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,";
244$sql .= " s.rowid as socid, s.nom as name, s.code_client,";
245if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
246 $sql .= " spe.accountancy_code_customer as code_compta_client,";
247 $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
248} else {
249 $sql .= " s.code_compta as code_compta_client,";
250 $sql .= " s.code_compta_fournisseur,";
251}
252$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,";
253if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
254 $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
255} else {
256 $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
257}
258$sql .= " aa.rowid as fk_compte, aa.account_number, aa.label as label_account, aa.labelshort as labelshort_account,";
259$sql .= " fd.situation_percent,";
260$sql .= " co.code as country_code, co.label as country,";
261$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";
262$parameters = array();
263$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
264$sql .= $hookmanager->resPrint;
265$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd";
266$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
267if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
268 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
269}
270$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
271$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture";
272$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
273if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
274 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
275}
276$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
277// Add table from hooks
278$parameters = array();
279$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
280$sql .= $hookmanager->resPrint;
281$sql .= " WHERE fd.fk_code_ventilation > 0";
282$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
283$sql .= " AND f.fk_statut > 0";
284if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
285 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
286} else {
287 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
288}
289// Add search filter like
290if ($search_societe) {
291 $sql .= natural_search('s.nom', $search_societe);
292}
293if ($search_lineid) {
294 $sql .= natural_search("fd.rowid", $search_lineid, 1);
295}
296if (strlen(trim($search_invoice))) {
297 $sql .= natural_search("f.ref", $search_invoice);
298}
299if (strlen(trim($search_ref))) {
300 $sql .= natural_search("p.ref", $search_ref);
301}
302if (strlen(trim($search_label))) {
303 $sql .= natural_search("p.label", $search_label);
304}
305if (strlen(trim($search_desc))) {
306 $sql .= natural_search("fd.description", $search_desc);
307}
308if (strlen(trim($search_amount))) {
309 $sql .= natural_search("fd.total_ht", $search_amount, 1);
310}
311if (strlen(trim($search_account))) {
312 $sql .= natural_search("aa.account_number", $search_account);
313}
314if (strlen(trim($search_vat))) {
315 $sql .= natural_search("fd.tva_tx", price2num($search_vat), 1);
316}
317if ($search_date_start) {
318 $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
319}
320if ($search_date_end) {
321 $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
322}
323if (strlen(trim($search_country))) {
324 $arrayofcode = getCountriesInEEC();
325 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
326 foreach ($arrayofcode as $key => $value) {
327 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
328 if ($value != $mysoc->country_code) {
329 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
330 }
331 }
332 if ($search_country == 'special_allnotme') {
333 $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
334 } elseif ($search_country == 'special_eec') {
335 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
336 } elseif ($search_country == 'special_eecnotme') {
337 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
338 } elseif ($search_country == 'special_noteec') {
339 $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
340 } else {
341 $sql .= natural_search("co.code", $search_country);
342 }
343}
344if (strlen(trim($search_tvaintra))) {
345 $sql .= natural_search("s.tva_intra", $search_tvaintra);
346}
347$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
348// Add where from hooks
349$parameters = array();
350$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
351$sql .= $hookmanager->resPrint;
352
353$sql .= $db->order($sortfield, $sortorder);
354
355// Count total nb of records
356$nbtotalofrecords = '';
357if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
358 $result = $db->query($sql);
359 $nbtotalofrecords = $db->num_rows($result);
360 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
361 $page = 0;
362 $offset = 0;
363 }
364}
365
366$sql .= $db->plimit($limit + 1, $offset);
367
368dol_syslog("/accountancy/customer/lines.php", LOG_DEBUG);
369$result = $db->query($sql);
370if ($result) {
371 $num_lines = $db->num_rows($result);
372 $i = 0;
373
374 $param = '';
375 if ($contextpage != $_SERVER["PHP_SELF"]) {
376 $param .= '&contextpage='.urlencode($contextpage);
377 }
378 if ($limit > 0 && $limit != $conf->liste_limit) {
379 $param .= '&limit='.((int) $limit);
380 }
381 if ($search_societe) {
382 $param .= "&search_societe=".urlencode($search_societe);
383 }
384 if ($search_invoice) {
385 $param .= "&search_invoice=".urlencode($search_invoice);
386 }
387 if ($search_ref) {
388 $param .= "&search_ref=".urlencode($search_ref);
389 }
390 if ($search_label) {
391 $param .= "&search_label=".urlencode($search_label);
392 }
393 if ($search_desc) {
394 $param .= "&search_desc=".urlencode($search_desc);
395 }
396 if ($search_account) {
397 $param .= "&search_account=".urlencode($search_account);
398 }
399 if ($search_vat) {
400 $param .= "&search_vat=".urlencode($search_vat);
401 }
402 if ($search_date_startday) {
403 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
404 }
405 if ($search_date_startmonth) {
406 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
407 }
408 if ($search_date_startyear) {
409 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
410 }
411 if ($search_date_endday) {
412 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
413 }
414 if ($search_date_endmonth) {
415 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
416 }
417 if ($search_date_endyear) {
418 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
419 }
420 if ($search_country) {
421 $param .= "&search_country=".urlencode($search_country);
422 }
423 if ($search_tvaintra) {
424 $param .= "&search_tvaintra=".urlencode($search_tvaintra);
425 }
426 // Add $param from hooks
427 $parameters = array('param' => &$param);
428 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
429 $param .= $hookmanager->resPrint;
430
431 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
432 print '<input type="hidden" name="action" value="ventil">';
433 if ($optioncss != '') {
434 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
435 }
436 print '<input type="hidden" name="token" value="'.newToken().'">';
437 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
438 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
439 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
440 print '<input type="hidden" name="page" value="'.$page.'">';
441
442 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
443 print_barre_liste($langs->trans("InvoiceLinesDone").'<br><span class="opacityhigh small">'.$langs->trans("DescVentilDoneCustomer").'</span>', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit, 0, 0, 1);
444
445 print '<br>'.$langs->trans("ChangeAccount").' <div class="inline-block paddingbottom paddingtop">';
446 print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
447 print '<input type="submit" class="button small smallpaddingimp valignmiddle" value="'.$langs->trans("ChangeBinding").'"/></div>';
448 print '<br><br>';
449
450 $moreforfilter = '';
451
452 $varpage = $contextpage;
453 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
454 $selectedfields = $htmlofselectarray;
455 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
456
457 print '<div class="div-table-responsive">';
458 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
459
460 print '<tr class="liste_titre_filter">';
461 // Action column
462 if ($conf->main_checkbox_left_column) {
463 print '<td class="liste_titre maxwidthsearch center actioncolumn">';
464 $searchpicto = $form->showFilterButtons('left');
465 print $searchpicto;
466 print '</td>';
467 }
468 // Line ID
469 if (!empty($arrayfields['fd.rowid']['checked'])) {
470 print '<td class="liste_titre" data-key="lineid">';
471 print '<input type="text" class="flat maxwidth40" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'">';
472 print '</td>';
473 }
474 // Ref invoice
475 if (!empty($arrayfields['f.ref']['checked'])) {
476 print '<td class="liste_titre" data-key="invoice">';
477 print '<input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'">';
478 print '</td>';
479 }
480 // Date
481 if (!empty($arrayfields['f.datef']['checked'])) {
482 print '<td class="liste_titre center">';
483 print '<div class="nowrapfordate">';
484 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
485 print '</div>';
486 print '<div class="nowrapfordate">';
487 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
488 print '</div>';
489 print '</td>';
490 }
491 // Product ref
492 if (!empty($arrayfields['p.ref']['checked'])) {
493 print '<td class="liste_titre" data-key="ref">';
494 print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
495 print '</td>';
496 }
497 //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
498 // Description
499 if (!empty($arrayfields['fd.description']['checked'])) {
500 print '<td class="liste_titre" data-key="desc">';
501 print '<input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'">';
502 print '</td>';
503 }
504 // Amount
505 if (!empty($arrayfields['fd.total_ht']['checked'])) {
506 print '<td class="liste_titre" data-key="amount">';
507 print '<input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
508 print '</td>';
509 }
510 // VAT
511 if (!empty($arrayfields['fd.tva_tx']['checked'])) {
512 print '<td class="liste_titre" data-key="vat">';
513 print '<input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'">';
514 print '</td>';
515 }
516 // Thirdparty
517 if (!empty($arrayfields['s.nom']['checked'])) {
518 print '<td class="liste_titre" data-key="societe">';
519 print '<input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
520 print '</td>';
521 }
522 // Country
523 if (!empty($arrayfields['co.label']['checked'])) {
524 print '<td class="liste_titre" data-key="country">';
525 print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth125', 'code2', 1, 0, 1);
526 //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
527 print '</td>';
528 }
529 // TVA Intracom
530 if (!empty($arrayfields['s.tva_intra']['checked'])) {
531 print '<td class="liste_titre">';
532 print '<input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'">';
533 print '</td>';
534 }
535 // Account
536 if (!empty($arrayfields['aa.account_number']['checked'])) {
537 print '<td class="liste_titre">';
538 print '<input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).'">';
539 print '</td>';
540 }
541 // Fields from hook
542 $parameters = array('arrayfields' => $arrayfields);
543 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
544 print $hookmanager->resPrint;
545 // Action column
546 if (!$conf->main_checkbox_left_column) {
547 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
548 $searchpicto = $form->showFilterButtons();
549 print $searchpicto;
550 print '</td>';
551 }
552 print "</tr>\n";
553
554 // Fields title label
555 // --------------------------------------------------------------------
556
557 $totalarray = array();
558 $totalarray['nbfield'] = 0;
559
560 print '<tr class="liste_titre">';
561 // Action column
562 if ($conf->main_checkbox_left_column) {
563 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
564 $totalarray['nbfield']++;
565 }
566 // Line ID
567 if (!empty($arrayfields['fd.rowid']['checked'])) {
568 print_liste_field_titre($arrayfields['fd.rowid']['label'], $_SERVER["PHP_SELF"], "fd.rowid", "", $param, '', $sortfield, $sortorder);
569 $totalarray['nbfield']++;
570 }
571 // Ref invoice
572 if (!empty($arrayfields['f.ref']['checked'])) {
573 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
574 $totalarray['nbfield']++;
575 }
576 // Date
577 if (!empty($arrayfields['f.datef']['checked'])) {
578 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef, f.ref, fd.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
579 $totalarray['nbfield']++;
580 }
581 // Product ref
582 if (!empty($arrayfields['p.ref']['checked'])) {
583 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
584 $totalarray['nbfield']++;
585 }
586 //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
587 // description
588 if (!empty($arrayfields['fd.description']['checked'])) {
589 print_liste_field_titre($arrayfields['fd.description']['label'], $_SERVER["PHP_SELF"], "fd.description", "", $param, '', $sortfield, $sortorder);
590 $totalarray['nbfield']++;
591 }
592 // Amount
593 if (!empty($arrayfields['fd.total_ht']['checked'])) {
594 print_liste_field_titre($arrayfields['fd.total_ht']['label'], $_SERVER["PHP_SELF"], "fd.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
595 $totalarray['nbfield']++;
596 }
597 // VAT
598 if (!empty($arrayfields['fd.tva_tx']['checked'])) {
599 print_liste_field_titre($arrayfields['fd.tva_tx']['label'], $_SERVER["PHP_SELF"], "fd.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
600 $totalarray['nbfield']++;
601 }
602 // Thirdparty
603 if (!empty($arrayfields['s.nom']['checked'])) {
604 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
605 $totalarray['nbfield']++;
606 }
607 // Country
608 if (!empty($arrayfields['co.label']['checked'])) {
609 print_liste_field_titre($arrayfields['co.label']['label'], $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
610 $totalarray['nbfield']++;
611 }
612 // TVA Intracom
613 if (!empty($arrayfields['s.tva_intra']['checked'])) {
614 print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
615 $totalarray['nbfield']++;
616 }
617 // Account
618 if (!empty($arrayfields['aa.account_number']['checked'])) {
619 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
620 $totalarray['nbfield']++;
621 }
622 // Hook fields
623 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
624 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
625 print $hookmanager->resPrint;
626 // Action column
627 if (!$conf->main_checkbox_left_column) {
628 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
629 $totalarray['nbfield']++;
630 }
631 print "</tr>\n";
632
633 $thirdpartystatic = new Societe($db);
634 $facturestatic = new Facture($db);
635 $productstatic = new Product($db);
636 $accountingaccountstatic = new AccountingAccount($db);
637 $totalarray = array();
638 $totalarray['nbfield'] = 0;
639
640 $i = 0;
641 while ($i < min($num_lines, $limit)) {
642 $objp = $db->fetch_object($result);
643
644 $facturestatic->ref = $objp->ref;
645 $facturestatic->id = $objp->facid;
646 $facturestatic->type = $objp->ftype;
647
648 $thirdpartystatic->id = $objp->socid;
649 $thirdpartystatic->name = $objp->name;
650 $thirdpartystatic->client = $objp->client;
651 $thirdpartystatic->fournisseur = $objp->fournisseur;
652 $thirdpartystatic->code_client = $objp->code_client;
653 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
654 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
655 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
656 $thirdpartystatic->email = $objp->email;
657 $thirdpartystatic->country_code = $objp->country_code;
658
659 $productstatic->ref = $objp->product_ref;
660 $productstatic->id = $objp->product_id;
661 $productstatic->label = $objp->product_label;
662 $productstatic->type = $objp->line_type;
663 $productstatic->status = $objp->tosell;
664 $productstatic->status_buy = $objp->tobuy;
665 $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
666 $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
667 $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
668
669 $accountingaccountstatic->rowid = $objp->fk_compte;
670 $accountingaccountstatic->label = $objp->label_account;
671 $accountingaccountstatic->labelshort = $objp->labelshort_account;
672 $accountingaccountstatic->account_number = $objp->account_number;
673
674 print '<tr class="oddeven">';
675
676 // Action column
677 if ($conf->main_checkbox_left_column) {
678 print '<td class="nowrap center actioncolumn">';
679 $selected = in_array($objp->rowid, $changeaccount);
680 print '<input id="cb'.$objp->rowid.'" class="flat checkforselect checkforaction" type="checkbox" name="changeaccount[]" value="'.$objp->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
681 print '</td>';
682 if (!$i) {
683 $totalarray['nbfield']++;
684 }
685 }
686 // Line id
687 if (!empty($arrayfields['fd.rowid']['checked'])) {
688 print '<td>'.$objp->rowid.'</td>';
689 $totalarray['nbfield']++;
690 }
691 // Ref Invoice
692 if (!empty($arrayfields['f.ref']['checked'])) {
693 print '<td class="nowraponall tdoverflowmax125">'.$facturestatic->getNomUrl(1).'</td>';
694 $totalarray['nbfield']++;
695 }
696 // Date invoice
697 if (!empty($arrayfields['f.datef']['checked'])) {
698 print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
699 $totalarray['nbfield']++;
700 }
701 // Ref Product
702 if (!empty($arrayfields['p.ref']['checked'])) {
703 print '<td class="tdoverflowmax100 cell2linesheight">';
704 if ($productstatic->id > 0) {
705 print $productstatic->getNomUrl(1);
706 } else {
707 print '&nbsp;';
708 }
709 //if ($productstatic->id > 0 && $objp->product_label) {
710 print '<br>';
711 //}
712 if ($objp->product_label) {
713 print '<span class="opacitymedium">'.$objp->product_label.'</span>';
714 } else {
715 print '&nbsp;';
716 }
717 print '</td>';
718 $totalarray['nbfield']++;
719 }
720 // Description
721 if (!empty($arrayfields['fd.description']['checked'])) {
722 $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description, 1));
723 print '<td class="tdoverflowmax200 small" title="'.dol_escape_htmltag($text).'">';
724 $trunclength = getDolGlobalInt('ACCOUNTING_LENGTH_DESCRIPTION', 32);
725 print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
726 print '</td>';
727 $totalarray['nbfield']++;
728 }
729 // Amount
730 if (!empty($arrayfields['fd.total_ht']['checked'])) {
731 print '<td class="right nowraponall amount">';
732
733 // Create a compensation rate for old situation invoice feature.
734 $situation_ratio = 1;
735 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
736 if ($objp->situation_cycle_ref) {
737 // Avoid divide by 0
738 if ($objp->situation_percent == 0) {
739 $situation_ratio = 0;
740 } else {
741 $line = new FactureLigne($db);
742 $line->fetch($objp->rowid);
743
744 // Situation invoices handling
745 $prev_progress = $line->get_prev_progress($objp->facid);
746
747 $situation_ratio = ($objp->situation_percent - $prev_progress) / $objp->situation_percent;
748 }
749 }
750 print price($objp->total_ht * $situation_ratio);
751 } else {
752 print price($objp->total_ht);
753 }
754 print '</td>';
755 $totalarray['nbfield']++;
756 }
757 // Vat rate
758 if (!empty($arrayfields['fd.tva_tx']['checked'])) {
759 print '<td class="right">'.vatrate($objp->tva_tx.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : '')).'</td>';
760 $totalarray['nbfield']++;
761 }
762 // Thirdparty
763 if (!empty($arrayfields['s.nom']['checked'])) {
764 print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
765 $totalarray['nbfield']++;
766 }
767 // Country
768 if (!empty($arrayfields['co.label']['checked'])) {
769 print '<td class="tdoverflowmax125" title="'.dolPrintHTMLForAttribute($langs->trans("Country".$objp->country_code).' ('.$objp->country_code.')').'">';
770 if ($objp->country_code) {
771 print $langs->trans("Country".$objp->country_code);
772 //print ' ('.$objp->country_code.')';
773 }
774 print '</td>';
775 $totalarray['nbfield']++;
776 }
777 // TVA Intracom
778 if (!empty($arrayfields['s.tva_intra']['checked'])) {
779 print '<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).'">'.dol_escape_htmltag($objp->tva_intra).'</td>';
780 $totalarray['nbfield']++;
781 }
782 // Account
783 if (!empty($arrayfields['aa.account_number']['checked'])) {
784 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($accountingaccountstatic->label).'">';
785 print '<a class="editfielda" href="./card.php?id='.$objp->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($param ? '?'.$param : '')).'">';
786 print img_edit();
787 print '</a> ';
788 print $accountingaccountstatic->getNomUrl(0, 1, 1, '', 1);
789 print '</td>';
790 $totalarray['nbfield']++;
791 }
792
793 // Fields from hook
794 $parameters = array('arrayfields' => $arrayfields, 'obj' => $objp, 'i' => $i, 'totalarray' => &$totalarray);
795 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
796 print $hookmanager->resPrint;
797
798 // Action column
799 if (!$conf->main_checkbox_left_column) {
800 print '<td class="nowrap center actioncolumn">';
801 $selected = in_array($objp->rowid, $changeaccount);
802 print '<input id="cb'.$objp->rowid.'" class="flat checkforselect checkforaction" type="checkbox" name="changeaccount[]" value="'.$objp->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
803 print '</td>';
804 if (!$i) {
805 $totalarray['nbfield']++;
806 }
807 }
808
809 print '</tr>';
810 $i++;
811 }
812 if ($num_lines == 0) {
813 $colspan = 1;
814 foreach ($arrayfields as $key => $val) {
815 if (!empty($val['checked'])) {
816 $colspan++;
817 }
818 }
819 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
820 }
821
822 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
823 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
824 print $hookmanager->resPrint;
825
826 print '</table>';
827 print "</div>";
828
829 if ($nbtotalofrecords > $limit) {
830 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
831 }
832
833 print '</form>';
834} else {
835 print $db->lasterror();
836}
837
838// End of page
839llxFooter();
840$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition list.php:497
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 to help generate other html components 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...
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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 '.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
isModEnabled($module)
Is Dolibarr module enabled.
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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.