dolibarr 25.0.0-alpha
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 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) 2013-2021 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
8 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
9 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
31require '../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
44require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
45require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
49
50
51// Load translation files required by the page
52$langs->loadLangs(array("bills", "companies", "compta", "accountancy", "other", "productbatch", "products"));
53
54$action = GETPOST('action', 'aZ09');
55$massaction = GETPOST('massaction', 'alpha');
56$confirm = GETPOST('confirm', 'alpha');
57$toselect = GETPOST('toselect', 'array:aZ09'); // Value can be 'X_Y'
58$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountancycustomerlist'; // To manage different context of search
59$optioncss = GETPOST('optioncss', 'alpha');
60
61$default_account = GETPOSTINT('default_account');
62
63// Search Getpost
64$search_societe = GETPOST('search_societe', 'alpha');
65$search_lineid = GETPOST('search_lineid', 'alpha'); // Can be '> 100'
66$search_ref = GETPOST('search_ref', 'alpha');
67$search_invoice = GETPOST('search_invoice', 'alpha');
68$search_label = GETPOST('search_label', 'alpha');
69$search_desc = GETPOST('search_desc', 'alpha');
70$search_amount = GETPOST('search_amount', 'alpha');
71$search_account = GETPOST('search_account', 'alpha');
72$search_vat = GETPOST('search_vat', 'alpha');
73$search_date_startday = GETPOSTINT('search_date_startday');
74$search_date_startmonth = GETPOSTINT('search_date_startmonth');
75$search_date_startyear = GETPOSTINT('search_date_startyear');
76$search_date_endday = GETPOSTINT('search_date_endday');
77$search_date_endmonth = GETPOSTINT('search_date_endmonth');
78$search_date_endyear = GETPOSTINT('search_date_endyear');
79$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
80$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
81$search_country = GETPOST('search_country', 'aZ09');
82$search_tvaintra = GETPOST('search_tvaintra', 'alpha');
83
84// Define begin binding date
85if (empty($search_date_start) && getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
86 $search_date_start = $db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'));
87}
88
89// Load variable for pagination
90$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION', $conf->liste_limit);
91$sortfield = GETPOST('sortfield', 'aZ09comma');
92$sortorder = GETPOST('sortorder', 'aZ09comma');
93$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
94if (empty($page) || $page < 0) {
95 $page = 0;
96}
97$offset = $limit * $page;
98$pageprev = $page - 1;
99$pagenext = $page + 1;
100if (!$sortfield) {
101 $sortfield = "f.datef, f.ref, l.rowid";
102}
103if (!$sortorder) {
104 if (getDolGlobalInt('ACCOUNTING_LIST_SORT_VENTILATION_TODO') > 0) {
105 $sortorder = "DESC";
106 } else {
107 $sortorder = "ASC";
108 }
109}
110
111// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
112$hookmanager->initHooks(array($contextpage));
113
114$object = new AccountingAccount($db);
115
116$formaccounting = new FormAccounting($db);
117$accountingAccount = new AccountingAccount($db);
118
119$chartaccountcode = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
120
121// Security check
122if (!isModEnabled('accounting')) {
124}
125if ($user->socid > 0) {
127}
128if (!$user->hasRight('accounting', 'bind', 'write')) {
130}
131
132$arrayfields = array(
133 'l.rowid' => array('label' => "LineId", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
134 'f.ref' => array('label' => "Invoice", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
135 'f.datef' => array('label' => "Date", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // f.datef, f.ref, l.rowid
136 'p.ref' => array('label' => "ProductRef", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
137 'l.description' => array('label' => "ProductDescription", 'position' => 1, 'checked' => '-1', 'enabled' => '1'),
138 'l.total_ht' => array('label' => "Amount", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
139 'l.tva_tx' => array('label' => "VATRate", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
140 's.nom' => array('label' => "ThirdParty", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
141 'co.label' => array('label' => "Country", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
142 's.tva_intra' => array('label' => "VATIntraShort", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
143 'aa.data_suggest' => array('label' => "DataUsedToSuggestAccount", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // Seems not used in search.
144 'aa.account_number' => array('label' => "AccountAccountingSuggest", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
145);
146// Add hook to complete $arrayfield
147$parameters = array('arrayfields' => &$arrayfields);
148$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
149// @phpstan-ignore-next-line
150$arrayfields = dol_sort_array($arrayfields, 'position');
151
152
153/*
154 * Actions
155 */
156
157if (GETPOST('cancel', 'alpha')) {
158 $action = 'list';
159 $massaction = '';
160}
161if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
162 $massaction = '';
163}
164
165$parameters = array('arrayfields' => &$arrayfields);
166$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
167if ($reshook < 0) {
168 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
169}
170
171if (empty($reshook)) {
172 // Selection of new fields
173 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
174
175 // Purge search criteria
176 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
177 $search_societe = '';
178 $search_lineid = '';
179 $search_ref = '';
180 $search_invoice = '';
181 $search_label = '';
182 $search_desc = '';
183 $search_amount = '';
184 $search_account = '';
185 $search_vat = '';
186 $search_date_startday = '';
187 $search_date_startmonth = '';
188 $search_date_startyear = '';
189 $search_date_endday = '';
190 $search_date_endmonth = '';
191 $search_date_endyear = '';
192 $search_date_start = '';
193 $search_date_end = '';
194 $search_country = '';
195 $search_tvaintra = '';
196 }
197
198 // Mass actions
199 $objectclass = 'AccountingAccount';
200 $permissiontoread = $user->hasRight('accounting', 'read');
201 $permissiontodelete = $user->hasRight('accounting', 'delete');
202 $uploaddir = $conf->accounting->dir_output;
203 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
204}
205
206
207if ($massaction == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
208 $msg = '';
209
210 if (!empty($toselect)) {
211 $msg = '<div>'.$langs->trans("SelectedLines").': '.count($toselect).'</div>';
212 $msg .= '<div class="detail">';
213 $cpt = 0;
214 $ok = 0;
215 $ko = 0;
216
217 foreach ($toselect as $maLigneCochee) {
218 $maLigneCourante = explode("_", $maLigneCochee);
219 $monId = $maLigneCourante[0];
220 $monCompte = GETPOSTINT('codeventil'.$monId);
221
222 if ($monCompte <= 0) {
223 $msg .= '<div><span class="error">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NoAccountSelected").'</span></div>';
224 $ko++;
225 } else {
226 $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet";
227 $sql .= " SET fk_code_ventilation = ".((int) $monCompte);
228 $sql .= " WHERE rowid = ".((int) $monId);
229 $sql .= " AND fk_facture IN (SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE entity IN (".getEntity('invoice', 0)."))"; // Line must belong to an object of an allowed entity
230
231 $accountventilated = new AccountingAccount($db);
232 $accountventilated->fetch($monCompte, '', 1);
233
234 dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
235 if ($db->query($sql)) {
236 $msg .= '<div><span style="color:green">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
237 $ok++;
238 } else {
239 $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NotVentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'<br> <pre>'.$sql.'</pre></span></div>';
240 $ko++;
241 }
242 }
243
244 $cpt++;
245 }
246 $msg .= '</div>';
247 $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
248 }
249}
250
251if (GETPOST('sortfield') == 'f.datef, f.ref, l.rowid') {
252 $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1);
253 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
254 $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value, 'yesno', 0, '', $conf->entity);
255}
256
257
258/*
259 * View
260 */
261
262$form = new Form($db);
263
264$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
265
266llxHeader('', $langs->trans("CustomersVentilation"), $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-accountancy accountancy-customer page-list');
267
268if (empty($chartaccountcode)) {
269 print $langs->trans("ErrorChartOfAccountSystemNotSelected");
270 // End of page
271 llxFooter();
272 $db->close();
273 exit;
274}
275
276// Customer Invoice lines
277$sql = "SELECT f.rowid as facid, f.ref, f.datef, f.type as ftype, f.situation_cycle_ref, f.fk_facture_source,";
278$sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.situation_percent, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
279$sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
280if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
281 $sql .= " ppe.accountancy_code_sell as code_sell, ppe.accountancy_code_sell_intra as code_sell_intra, ppe.accountancy_code_sell_export as code_sell_export,";
282 $sql .= " ppe.accountancy_code_buy as code_buy, ppe.accountancy_code_buy_intra as code_buy_intra, ppe.accountancy_code_buy_export as code_buy_export,";
283} else {
284 $sql .= " p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
285 $sql .= " p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
286}
287$sql .= " p.tosell as status, p.tobuy as status_buy,";
288$sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
289$sql .= " co.code as country_code, co.label as country_label,";
290$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,";
291if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
292 $sql .= " spe.accountancy_code_customer as code_compta_client,";
293 $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
294 $sql .= " spe.accountancy_code_sell as company_code_sell";
295} else {
296 $sql .= " s.code_compta as code_compta_client,";
297 $sql .= " s.code_compta_fournisseur,";
298 $sql .= " s.accountancy_code_sell as company_code_sell";
299}
300$parameters = array();
301$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
302$sql .= $hookmanager->resPrint;
303$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
304$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
305if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
306 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
307}
308$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
309$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as l ON f.rowid = l.fk_facture";
310$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
311if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
312 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
313}
314$alias_societe_perentity = !getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED') ? "s" : "spe";
315$alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
316$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON " . $alias_product_perentity . ".accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".((int) $conf->entity);
317$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".((int) $conf->entity);
318$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".((int) $conf->entity);
319$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_societe_perentity . ".accountancy_code_sell = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa4.entity = ".((int) $conf->entity);
320// Add table from hooks
321$parameters = array();
322$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
323$sql .= $hookmanager->resPrint;
324
325$sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
326$sql .= " AND l.product_type <= 2";
327// Add search filter like
328if ($search_societe) {
329 $sql .= natural_search('s.nom', $search_societe);
330}
331if ($search_lineid) {
332 $sql .= natural_search("l.rowid", $search_lineid, 1);
333}
334if (strlen(trim($search_invoice))) {
335 $sql .= natural_search("f.ref", $search_invoice);
336}
337if (strlen(trim($search_ref))) {
338 $sql .= natural_search("p.ref", $search_ref);
339}
340if (strlen(trim($search_label))) {
341 $sql .= natural_search("p.label", $search_label);
342}
343if (strlen(trim($search_desc))) {
344 $sql .= natural_search("l.description", $search_desc);
345}
346if (strlen(trim($search_amount))) {
347 $sql .= natural_search("l.total_ht", $search_amount, 1);
348}
349if (strlen(trim($search_account))) {
350 $sql .= natural_search("aa.account_number", $search_account);
351}
352if (strlen(trim($search_vat))) {
353 $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
354}
355if ($search_date_start) {
356 $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
357}
358if ($search_date_end) {
359 $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
360}
361if (strlen(trim($search_country))) {
362 $arrayofcode = getCountriesInEEC();
363 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
364 foreach ($arrayofcode as $key => $value) {
365 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
366 if ($value != $mysoc->country_code) {
367 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
368 }
369 }
370 if ($search_country == 'special_allnotme') {
371 $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
372 } elseif ($search_country == 'special_eec') {
373 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
374 } elseif ($search_country == 'special_eecnotme') {
375 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
376 } elseif ($search_country == 'special_noteec') {
377 $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
378 } else {
379 $sql .= natural_search("co.code", $search_country);
380 }
381}
382if (strlen(trim($search_tvaintra))) {
383 $sql .= natural_search("s.tva_intra", $search_tvaintra);
384}
385if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
386 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
387} else {
388 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
389}
390$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
391
392// Add where from hooks
393$parameters = array();
394$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
395$sql .= $hookmanager->resPrint;
396
397$sql .= $db->order($sortfield, $sortorder);
398
399// Count total nb of records
400$nbtotalofrecords = '';
401if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
402 $result = $db->query($sql);
403 $nbtotalofrecords = $db->num_rows($result);
404 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
405 $page = 0;
406 $offset = 0;
407 }
408}
409
410$sql .= $db->plimit($limit + 1, $offset);
411
412dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
413// MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
414// This big SELECT command may exceed the MAX_JOIN_SIZE limit => Therefore we use SQL_BIG_SELECTS=1 to disable the MAX_JOIN_SIZE security
415if ($db->type == 'mysqli') {
416 $db->query("SET SQL_BIG_SELECTS=1");
417}
418
419$result = $db->query($sql);
420if ($result) {
421 $num_lines = $db->num_rows($result);
422 $i = 0;
423
424 $arrayofselected = is_array($toselect) ? $toselect : array();
425
426 $param = '';
427 if ($contextpage != $_SERVER["PHP_SELF"]) {
428 $param .= '&contextpage='.urlencode($contextpage);
429 }
430 if ($limit > 0 && $limit != $conf->liste_limit) {
431 $param .= '&limit='.((int) $limit);
432 }
433 if ($search_societe) {
434 $param .= '&search_societe='.urlencode($search_societe);
435 }
436 if ($search_lineid) {
437 $param .= '&search_lineid='.urlencode((string) ($search_lineid));
438 }
439 if ($search_date_startday) {
440 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
441 }
442 if ($search_date_startmonth) {
443 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
444 }
445 if ($search_date_startyear) {
446 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
447 }
448 if ($search_date_endday) {
449 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
450 }
451 if ($search_date_endmonth) {
452 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
453 }
454 if ($search_date_endyear) {
455 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
456 }
457 if ($search_invoice) {
458 $param .= '&search_invoice='.urlencode($search_invoice);
459 }
460 if ($search_ref) {
461 $param .= '&search_ref='.urlencode($search_ref);
462 }
463 if ($search_label) {
464 $param .= '&search_label='.urlencode($search_label);
465 }
466 if ($search_desc) {
467 $param .= '&search_desc='.urlencode($search_desc);
468 }
469 if ($search_amount) {
470 $param .= '&search_amount='.urlencode($search_amount);
471 }
472 if ($search_vat) {
473 $param .= '&search_vat='.urlencode($search_vat);
474 }
475 if ($search_country) {
476 $param .= "&search_country=".urlencode($search_country);
477 }
478 if ($search_tvaintra) {
479 $param .= "&search_tvaintra=".urlencode($search_tvaintra);
480 }
481 // Add $param from hooks
482 $parameters = array('param' => &$param);
483 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
484 $param .= $hookmanager->resPrint;
485
486 $arrayofmassactions = array(
487 'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount"),
488 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
489 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
490 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
491 );
492 //if ($user->hasRight('mymodule', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
493 //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
494 $massactionbutton = '';
495 if ($massaction !== 'set_default_account') {
496 $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1);
497 }
498
499 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
500 print '<input type="hidden" name="action" value="ventil">';
501 if ($optioncss != '') {
502 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
503 }
504 print '<input type="hidden" name="token" value="'.newToken().'">';
505 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
506 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
507 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
508 print '<input type="hidden" name="page" value="'.$page.'">';
509
510 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
511 print_barre_liste($langs->trans("InvoiceLines").'<br><span class="opacityhigh small">'.$langs->trans("DescVentilTodoCustomer").'</span>', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, (string) $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit, 0, 0, 1);
512 print '<br>';
513
514 if ($massaction == 'set_default_account') {
515 $formquestion = array();
516 $formquestion[] = array('type' => 'other',
517 'name' => 'set_default_account',
518 'label' => $langs->trans("AccountancyCode"),
519 'value' => $formaccounting->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'));
520 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($toselect)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
521 }
522
523 if (!empty($msg)) {
524 print $msg.'<br>';
525 }
526
527 $moreforfilter = '';
528
529 $varpage = $contextpage;
530 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
531 $selectedfields = $htmlofselectarray;
532 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
533
534 print '<div class="div-table-responsive">';
535 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
536
537 // We add search filter
538 print '<tr class="liste_titre_filter">';
539 // Action column
540 if ($conf->main_checkbox_left_column) {
541 print '<td class="liste_titre maxwidthsearch center actioncolumn">';
542 $searchpicto = $form->showFilterButtons('left');
543 print $searchpicto;
544 print '</td>';
545 }
546 // Line ID
547 if (!empty($arrayfields['l.rowid']['checked'])) {
548 print '<td class="liste_titre" data-key="lineid">';
549 print '<input type="text" class="flat maxwidth40" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'">';
550 print '</td>';
551 }
552 // Ref invoice
553 if (!empty($arrayfields['f.ref']['checked'])) {
554 print '<td class="liste_titre" data-key="invoice">';
555 print '<input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'">';
556 print '</td>';
557 }
558 // Date
559 if (!empty($arrayfields['f.datef']['checked'])) {
560 print '<td class="liste_titre center">';
561 print '<div class="nowrapfordate">';
562 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
563 print '</div>';
564 print '<div class="nowrapfordate">';
565 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
566 print '</div>';
567 print '</td>';
568 }
569 // Product ref
570 if (!empty($arrayfields['p.ref']['checked'])) {
571 print '<td class="liste_titre" data-key="ref">';
572 print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
573 print '</td>';
574 }
575 // Description
576 if (!empty($arrayfields['l.description']['checked'])) {
577 print '<td class="liste_titre" data-key="desc">';
578 print '<input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'">';
579 print '</td>';
580 }
581 // Amount
582 if (!empty($arrayfields['l.total_ht']['checked'])) {
583 print '<td class="liste_titre" data-key="amount">';
584 print '<input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
585 print '</td>';
586 }
587 // VAT
588 if (!empty($arrayfields['l.tva_tx']['checked'])) {
589 print '<td class="liste_titre" data-key="vat">';
590 print '<input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'">';
591 print '</td>';
592 }
593 // Thirdparty
594 if (!empty($arrayfields['s.nom']['checked'])) {
595 print '<td class="liste_titre" data-key="societe">';
596 print '<input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
597 print '</td>';
598 }
599 // Country
600 if (!empty($arrayfields['co.label']['checked'])) {
601 print '<td class="liste_titre" data-key="country">';
602 print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth125', 'code2', 1, 0, 1);
603 print '</td>';
604 }
605 // TVA Intracom
606 if (!empty($arrayfields['s.tva_intra']['checked'])) {
607 print '<td class="liste_titre">';
608 print '<input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'">';
609 print '</td>';
610 }
611 // Data suggested
612 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
613 print '<td class="liste_titre"></td>';
614 }
615 // Account
616 if (!empty($arrayfields['aa.account_number']['checked'])) {
617 print '<td class="liste_titre"></td>';
618 }
619 // Fields from hook
620 $parameters = array('arrayfields' => $arrayfields);
621 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
622 print $hookmanager->resPrint;
623
624 // Action column
625 if (!$conf->main_checkbox_left_column) {
626 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
627 $searchpicto = $form->showFilterButtons();
628 print $searchpicto;
629 print '</td>';
630 }
631 print "</tr>\n";
632
633 // Fields title label
634 // --------------------------------------------------------------------
635 $totalarray = array();
636 $totalarray['nbfield'] = 0;
637
638 print '<tr class="liste_titre">';
639 // Action column
640 if ($conf->main_checkbox_left_column) {
641 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
642 $totalarray['nbfield']++;
643 }
644 // Line ID
645 if (!empty($arrayfields['l.rowid']['checked'])) {
646 print_liste_field_titre($arrayfields['l.rowid']['label'], $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
647 $totalarray['nbfield']++;
648 }
649 // Ref invoice
650 if (!empty($arrayfields['f.ref']['checked'])) {
651 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
652 $totalarray['nbfield']++;
653 }
654 // Date
655 if (!empty($arrayfields['f.datef']['checked'])) {
656 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
657 $totalarray['nbfield']++;
658 }
659 // Product ref
660 if (!empty($arrayfields['p.ref']['checked'])) {
661 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
662 $totalarray['nbfield']++;
663 }
664 // product description
665 if (!empty($arrayfields['l.description']['checked'])) {
666 print_liste_field_titre($arrayfields['l.description']['label'], $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
667 $totalarray['nbfield']++;
668 }
669 // Amount
670 if (!empty($arrayfields['l.total_ht']['checked'])) {
671 print_liste_field_titre($arrayfields['l.total_ht']['label'], $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
672 $totalarray['nbfield']++;
673 }
674 // VAT
675 if (!empty($arrayfields['l.tva_tx']['checked'])) {
676 print_liste_field_titre($arrayfields['l.tva_tx']['label'], $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
677 $totalarray['nbfield']++;
678 }
679 // Thirdparty
680 if (!empty($arrayfields['s.nom']['checked'])) {
681 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
682 $totalarray['nbfield']++;
683 }
684 // Country
685 if (!empty($arrayfields['co.label']['checked'])) {
686 print_liste_field_titre($arrayfields['co.label']['label'], $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
687 $totalarray['nbfield']++;
688 }
689 // TVA Intracom
690 if (!empty($arrayfields['s.tva_intra']['checked'])) {
691 print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
692 $totalarray['nbfield']++;
693 }
694 // Data suggested
695 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
696 print_liste_field_titre($arrayfields['aa.data_suggest']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
697 $totalarray['nbfield']++;
698 }
699 // Account
700 if (!empty($arrayfields['aa.account_number']['checked'])) {
701 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
702 $totalarray['nbfield']++;
703 }
704 // Hook fields
705 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
706 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
707 print $hookmanager->resPrint;
708 // Action column
709 if (!$conf->main_checkbox_left_column) {
710 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
711 $totalarray['nbfield']++;
712 }
713 print "</tr>\n";
714
715 $thirdpartystatic = new Societe($db);
716 $facture_static = new Facture($db);
717 $facture_static_det = new FactureLigne($db);
718 $product_static = new Product($db);
719
720
721 $accountingaccount_codetotid_cache = array();
722 $suggestedaccountingaccountfor = ''; // Initialise (for static analysis)
723 $suggestedaccountingaccountbydefaultfor = '';
724
725 while ($i < min($num_lines, $limit)) {
726 $objp = $db->fetch_object($result);
727
728 // product_type: 0 = service, 1 = product
729 // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
730 // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
731 $code_sell_l = '';
732 $code_sell_p = '';
733 $code_sell_t = '';
734
735 $thirdpartystatic->id = $objp->socid;
736 $thirdpartystatic->name = $objp->name;
737 $thirdpartystatic->client = $objp->client;
738 $thirdpartystatic->fournisseur = $objp->fournisseur;
739 $thirdpartystatic->code_client = $objp->code_client;
740 $thirdpartystatic->code_compta = $objp->code_compta_client; // For backward compatibility
741 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
742 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
743 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
744 $thirdpartystatic->email = $objp->email;
745 $thirdpartystatic->country_code = $objp->country_code;
746 $thirdpartystatic->tva_intra = $objp->tva_intra;
747 $thirdpartystatic->code_compta_product = $objp->company_code_sell; // The accounting account for product stored on thirdparty object (for level3 suggestion)
748
749 $product_static->ref = $objp->product_ref;
750 $product_static->id = $objp->product_id;
751 $product_static->type = $objp->type;
752 $product_static->label = $objp->product_label;
753 $product_static->status = $objp->status;
754 $product_static->status_buy = $objp->status_buy;
755 $product_static->accountancy_code_sell = $objp->code_sell;
756 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
757 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
758 $product_static->accountancy_code_buy = $objp->code_buy;
759 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
760 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
761 $product_static->tva_tx = $objp->tva_tx_prod;
762
763 $facture_static->ref = $objp->ref;
764 $facture_static->id = $objp->facid;
765 $facture_static->type = $objp->ftype;
766 $facture_static->date = $db->jdate($objp->datef);
767 $facture_static->fk_facture_source = $objp->fk_facture_source;
768
769 $facture_static_det->id = $objp->rowid;
770 $facture_static_det->total_ht = $objp->total_ht;
771 $facture_static_det->tva_tx = $objp->tva_tx_line;
772 $facture_static_det->vat_src_code = $objp->vat_src_code;
773 $facture_static_det->product_type = $objp->type_l;
774 $facture_static_det->desc = $objp->description;
775
776 $accountingAccountArray = array(
777 'dom' => $objp->aarowid,
778 'intra' => $objp->aarowid_intra,
779 'export' => $objp->aarowid_export,
780 'thirdparty' => $objp->aarowid_thirdparty);
781
782 $code_sell_p_notset = '';
783 $code_sell_t_notset = '';
784
785 $suggestedid = 0;
786
787 $return = $accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'customer');
788 if (!is_array($return) && $return < 0) {
789 setEventMessage($accountingAccount->error, 'errors');
790 } else {
791 $suggestedid = $return['suggestedid'];
792 $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor'];
793 $suggestedaccountingaccountbydefaultfor = $return['suggestedaccountingaccountbydefaultfor'];
794 $code_sell_l = $return['code_l'];
795 $code_sell_p = $return['code_p'];
796 $code_sell_t = $return['code_t'];
797 }
798 //var_dump($return);
799
800 if (!empty($code_sell_p)) {
801 // Value was defined previously
802 } else {
803 $code_sell_p_notset = 'color:orange';
804 }
805 if (empty($code_sell_l) && empty($code_sell_p)) {
806 $code_sell_p_notset = 'color:red';
807 }
808 if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
809 $code_sell_p_notset = 'color:orange';
810 }
811
812 // $code_sell_l is now default code of product/service
813 // $code_sell_p is now code of product/service
814 // $code_sell_t is now code of thirdparty
815 //var_dump($code_sell_l.' - '.$code_sell_p.' - '.$code_sell_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')');
816
817 print '<tr class="oddeven">';
818 // Action column
819 if ($conf->main_checkbox_left_column) {
820 print '<td class="nowrap center actioncolumn">';
821 $selected = in_array($objp->rowid."_".$i, $toselect);
822 print '<input type="checkbox" class="flat checkforselect checkforselect'.$facture_static_det->id.'" name="toselect[]" value="'.$facture_static_det->id."_".$i.'"'.($selected ? " checked" : "").'/>';
823 print '</td>';
824 if (!$i) {
825 $totalarray['nbfield']++;
826 }
827 }
828 // Line id
829 if (!empty($arrayfields['l.rowid']['checked'])) {
830 print '<td>'.$facture_static_det->id.'</td>';
831 $totalarray['nbfield']++;
832 }
833 // Ref Invoice
834 if (!empty($arrayfields['f.ref']['checked'])) {
835 print '<td class="nowraponall cell2linesheight">'.$facture_static->getNomUrl(1).'</td>';
836 $totalarray['nbfield']++;
837 }
838 // Invoice date
839 if (!empty($arrayfields['f.datef']['checked'])) {
840 print '<td class="center">'.dol_print_date($facture_static->date, 'day').'</td>';
841 $totalarray['nbfield']++;
842 }
843 // Ref Product
844 if (!empty($arrayfields['p.ref']['checked'])) {
845 print '<td class="tdoverflowmax125 cell2linesheight">';
846 if ($product_static->id > 0) {
847 print $product_static->getNomUrl(1);
848 }
849 if ($product_static->label) {
850 print '<br><span class="opacitymedium small">'.dol_escape_htmltag($product_static->label).'</span>';
851 }
852 print '</td>';
853 $totalarray['nbfield']++;
854 }
855 // Description of line
856 if (!empty($arrayfields['l.description']['checked'])) {
857 $text = dolGetFirstLineOfText(dol_string_nohtmltag($facture_static_det->desc, 1));
858 print '<td class="tdoverflowmax150 small classfortooltip" title="'.dol_escape_htmltag($text).'">';
859 $trunclength = getDolGlobalInt('ACCOUNTING_LENGTH_DESCRIPTION');
860 print dol_trunc($text, $trunclength);
861 print '</td>';
862 $totalarray['nbfield']++;
863 }
864 // Amount
865 if (!empty($arrayfields['l.total_ht']['checked'])) {
866 print '<td class="right nowraponall amount">';
867
868 // Create a compensation rate for old situation invoice feature.
869 $situation_ratio = 1;
870 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
871 if ($objp->situation_cycle_ref) {
872 // Avoid divide by 0
873 if ($objp->situation_percent == 0) {
874 $situation_ratio = 0;
875 } else {
876 $line = new FactureLigne($db);
877 $line->fetch($objp->rowid);
878
879 // Situation invoices handling
880 $prev_progress = $line->get_prev_progress($objp->facid);
881
882 $situation_ratio = ($objp->situation_percent - $prev_progress) / $objp->situation_percent;
883 }
884 }
885 print price($objp->total_ht * $situation_ratio);
886 } else {
887 print price($objp->total_ht);
888 }
889 print '</td>';
890 $totalarray['nbfield']++;
891 }
892 // Vat rate
893 if (!empty($arrayfields['l.tva_tx']['checked'])) {
894 $code_vat_differ = '';
895 if ($product_static->tva_tx !== $facture_static_det->tva_tx && price2num($product_static->tva_tx) && price2num($facture_static_det->tva_tx)) { // Note: having a vat rate of 0 is often the normal case when sells is intra b2b or to export
896 $code_vat_differ = 'warning bold';
897 }
898 print '<td class="right cell2linesheight'.($code_vat_differ ? ' '.$code_vat_differ : '').'">';
899 print vatrate($facture_static_det->tva_tx.($facture_static_det->vat_src_code ? ' ('.$facture_static_det->vat_src_code.')' : ''), false, 0, 0, 1);
900 print '</td>';
901 $totalarray['nbfield']++;
902 }
903 // Thirdparty
904 if (!empty($arrayfields['s.nom']['checked'])) {
905 print '<td class="tdoverflowmax125">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
906 $totalarray['nbfield']++;
907 }
908 // Country
909 if (!empty($arrayfields['co.label']['checked'])) {
910 $labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
911 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelcountry).'">';
912 print dol_escape_htmltag($labelcountry);
913 print '</td>';
914 $totalarray['nbfield']++;
915 }
916 // VAT Num
917 if (!empty($arrayfields['s.tva_intra']['checked'])) {
918 print '<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).'">'.dol_escape_htmltag($objp->tva_intra).'</td>';
919 $totalarray['nbfield']++;
920 }
921 // Found accounts
922 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
923 print '<td class="small cell2linesheight">';
924 // First show default account for any products
925 $s = '1. '.(($facture_static_det->product_type == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': ';
926 $shelp = '';
927 $ttype = 'help';
928 if ($suggestedaccountingaccountbydefaultfor == 'eec') {
929 $shelp .= $langs->trans("SaleEEC");
930 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') {
931 $shelp = $langs->trans("SaleEECWithVAT");
932 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') {
933 $shelp = $langs->trans("SaleEECWithoutVATNumber");
934 $ttype = 'warning';
935 } elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
936 $shelp .= $langs->trans("SaleExport");
937 }
938 $s .= ($code_sell_l > 0 ? length_accountg($code_sell_l) : '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>');
939 $textforrule = $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
940 // Now show account for product
941 if ($product_static->id > 0) {
942 $textforrule .= '<br>';
943 $s = '2. '.(($facture_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
944 $shelp = '';
945 $ttype = 'help';
946 if ($suggestedaccountingaccountbydefaultfor == 'eec') {
947 $shelp .= $langs->trans("SaleEEC");
948 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') {
949 $shelp = $langs->trans("SaleEECWithVAT");
950 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') {
951 $shelp = $langs->trans("SaleEECWithoutVATNumber");
952 $ttype = 'warning';
953 } elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
954 $shelp .= $langs->trans("SaleExport");
955 }
956 $s .= (empty($code_sell_p) ? '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($code_sell_p));
957 $textforrule .= $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
958 } else {
959 $textforrule .= '<br>';
960 $s = '2. '.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
961 $shelp = '';
962 $s .= $langs->trans("NotDefined");
963 $textforrule .= $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
964 }
965 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
966 $textforrule .= '<br>';
967 $s = '3. '.(($facture_static_det->product_type == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")).': ';
968 $shelp = '';
969 $s .= ($code_sell_t > 0 ? length_accountg($code_sell_t) : '<span style="'.$code_sell_t_notset.'">'.$langs->trans("NotDefined").'</span>');
970 $textforrule .= $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
971 }
972 print $textforrule;
973 print '</td>';
974 $totalarray['nbfield']++;
975 }
976 // Suggested accounting account
977 if (!empty($arrayfields['aa.account_number']['checked'])) {
978 print '<td>';
979 print $formaccounting->select_account(($default_account > 0 && $confirm === 'yes' && in_array($objp->rowid."_".$i, $toselect)) ? (string) $default_account : (string) $suggestedid, 'codeventil'.$facture_static_det->id, 1, array(), 0, 0, 'codeventil minwidth125onall maxwidth150', 'cachewithshowemptyone');
980 print '</td>';
981 $totalarray['nbfield']++;
982 }
983 // Fields from hook
984 $parameters = array('arrayfields' => $arrayfields, 'obj' => $objp, 'i' => $i, 'totalarray' => &$totalarray);
985 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
986 print $hookmanager->resPrint;
987 // Action column
988 if (!$conf->main_checkbox_left_column) {
989 print '<td class="nowrap center actioncolumn">';
990 $selected = in_array($objp->rowid."_".$i, $toselect);
991 print '<input type="checkbox" class="flat checkforselect checkforselect'.$facture_static_det->id.'" name="toselect[]" value="'.$facture_static_det->id."_".$i.'"'.($selected ? " checked" : "").'/>';
992 print '</td>';
993 if (!$i) {
994 $totalarray['nbfield']++;
995 }
996 }
997
998 print '</tr>';
999 $i++;
1000 }
1001 if ($num_lines == 0) {
1002 $colspan = 1;
1003 foreach ($arrayfields as $key => $val) {
1004 if (!empty($val['checked'])) {
1005 $colspan++;
1006 }
1007 }
1008 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1009 }
1010
1011 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1012 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1013 print $hookmanager->resPrint;
1014
1015 print '</table>';
1016 print "</div>";
1017
1018 print '</form>';
1019} else {
1020 print $db->error();
1021}
1022if ($db->type == 'mysqli') {
1023 $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
1024}
1025
1026// Add code to auto check the box when we select an account
1027print '<script type="text/javascript">
1028jQuery(document).ready(function() {
1029 jQuery(".codeventil").change(function() {
1030 var s=$(this).attr("id").replace("codeventil", "")
1031 console.log(s+" "+$(this).val());
1032 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
1033 else jQuery(".checkforselect"+s).prop("checked", true);
1034 });
1035});
1036</script>';
1037
1038// End of page
1039llxFooter();
1040$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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 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
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
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.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.