dolibarr 23.0.3
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-2025 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$formaccounting = new FormAccounting($db);
115$accountingAccount = new AccountingAccount($db);
116
117$chartaccountcode = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
118
119// Security check
120if (!isModEnabled('accounting')) {
122}
123if ($user->socid > 0) {
125}
126if (!$user->hasRight('accounting', 'bind', 'write')) {
128}
129
130$arrayfields = array(
131 'l.rowid' => array('label' => "LineId", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
132 'f.ref' => array('label' => "Invoice", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
133 'f.datef' => array('label' => "Date", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // f.datef, f.ref, l.rowid
134 'p.ref' => array('label' => "ProductRef", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
135 'l.description' => array('label' => "ProductDescription", 'position' => 1, 'checked' => '-1', 'enabled' => '1'),
136 'l.total_ht' => array('label' => "Amount", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
137 'l.tva_tx' => array('label' => "VATRate", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
138 's.nom' => array('label' => "ThirdParty", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
139 'co.label' => array('label' => "Country", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
140 's.tva_intra' => array('label' => "VATIntraShort", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
141 'aa.data_suggest' => array('label' => "DataUsedToSuggestAccount", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // Seems not used in search.
142 'aa.account_number' => array('label' => "AccountAccountingSuggest", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
143);
144// @phpstan-ignore-next-line
145$arrayfields = dol_sort_array($arrayfields, 'position');
146
147
148/*
149 * Actions
150 */
151
152if (GETPOST('cancel', 'alpha')) {
153 $action = 'list';
154 $massaction = '';
155}
156if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
157 $massaction = '';
158}
159
160$parameters = array('arrayfields' => &$arrayfields);
161$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
162if ($reshook < 0) {
163 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
164}
165
166if (empty($reshook)) {
167 // Selection of new fields
168 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
169
170 // Purge search criteria
171 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
172 $search_societe = '';
173 $search_lineid = '';
174 $search_ref = '';
175 $search_invoice = '';
176 $search_label = '';
177 $search_desc = '';
178 $search_amount = '';
179 $search_account = '';
180 $search_vat = '';
181 $search_date_startday = '';
182 $search_date_startmonth = '';
183 $search_date_startyear = '';
184 $search_date_endday = '';
185 $search_date_endmonth = '';
186 $search_date_endyear = '';
187 $search_date_start = '';
188 $search_date_end = '';
189 $search_country = '';
190 $search_tvaintra = '';
191 }
192
193 // Mass actions
194 $objectclass = 'AccountingAccount';
195 $permissiontoread = $user->hasRight('accounting', 'read');
196 $permissiontodelete = $user->hasRight('accounting', 'delete');
197 $uploaddir = $conf->accounting->dir_output;
198 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
199}
200
201
202if ($massaction == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
203 $msg = '';
204
205 if (!empty($toselect)) {
206 $msg = '<div>'.$langs->trans("SelectedLines").': '.count($toselect).'</div>';
207 $msg .= '<div class="detail">';
208 $cpt = 0;
209 $ok = 0;
210 $ko = 0;
211
212 foreach ($toselect as $maLigneCochee) {
213 $maLigneCourante = explode("_", $maLigneCochee);
214 $monId = $maLigneCourante[0];
215 $monCompte = GETPOSTINT('codeventil'.$monId);
216
217 if ($monCompte <= 0) {
218 $msg .= '<div><span class="error">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NoAccountSelected").'</span></div>';
219 $ko++;
220 } else {
221 $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet";
222 $sql .= " SET fk_code_ventilation = ".((int) $monCompte);
223 $sql .= " WHERE rowid = ".((int) $monId);
224
225 $accountventilated = new AccountingAccount($db);
226 $accountventilated->fetch($monCompte, '', 1);
227
228 dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
229 if ($db->query($sql)) {
230 $msg .= '<div><span style="color:green">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
231 $ok++;
232 } else {
233 $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>';
234 $ko++;
235 }
236 }
237
238 $cpt++;
239 }
240 $msg .= '</div>';
241 $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
242 }
243}
244
245if (GETPOST('sortfield') == 'f.datef, f.ref, l.rowid') {
246 $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1);
247 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
248 $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value, 'yesno', 0, '', $conf->entity);
249}
250
251
252/*
253 * View
254 */
255
256$form = new Form($db);
257$formother = new FormOther($db);
258
259$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
260
261llxHeader('', $langs->trans("CustomersVentilation"), $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-accountancy accountancy-customer page-list');
262
263if (empty($chartaccountcode)) {
264 print $langs->trans("ErrorChartOfAccountSystemNotSelected");
265 // End of page
266 llxFooter();
267 $db->close();
268 exit;
269}
270
271// Customer Invoice lines
272$sql = "SELECT f.rowid as facid, f.ref, f.datef, f.type as ftype, f.situation_cycle_ref, f.fk_facture_source,";
273$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,";
274$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,";
275if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
276 $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,";
277 $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,";
278} else {
279 $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,";
280 $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,";
281}
282$sql .= " p.tosell as status, p.tobuy as status_buy,";
283$sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
284$sql .= " co.code as country_code, co.label as country_label,";
285$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,";
286if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
287 $sql .= " spe.accountancy_code_customer as code_compta_client,";
288 $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,";
289 $sql .= " spe.accountancy_code_sell as company_code_sell";
290} else {
291 $sql .= " s.code_compta as code_compta_client,";
292 $sql .= " s.code_compta_fournisseur,";
293 $sql .= " s.accountancy_code_sell as company_code_sell";
294}
295$parameters = array();
296$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
297$sql .= $hookmanager->resPrint;
298$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
299$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
300if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
301 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
302}
303$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
304$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as l ON f.rowid = l.fk_facture";
305$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
306if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
307 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
308}
309$alias_societe_perentity = !getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED') ? "s" : "spe";
310$alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
311$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 = ".$conf->entity;
312$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 = ".$conf->entity;
313$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 = ".$conf->entity;
314$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 = ".$conf->entity;
315// Add table from hooks
316$parameters = array();
317$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
318$sql .= $hookmanager->resPrint;
319
320$sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
321$sql .= " AND l.product_type <= 2";
322// Add search filter like
323if ($search_societe) {
324 $sql .= natural_search('s.nom', $search_societe);
325}
326if ($search_lineid) {
327 $sql .= natural_search("l.rowid", $search_lineid, 1);
328}
329if (strlen(trim($search_invoice))) {
330 $sql .= natural_search("f.ref", $search_invoice);
331}
332if (strlen(trim($search_ref))) {
333 $sql .= natural_search("p.ref", $search_ref);
334}
335if (strlen(trim($search_label))) {
336 $sql .= natural_search("p.label", $search_label);
337}
338if (strlen(trim($search_desc))) {
339 $sql .= natural_search("l.description", $search_desc);
340}
341if (strlen(trim($search_amount))) {
342 $sql .= natural_search("l.total_ht", $search_amount, 1);
343}
344if (strlen(trim($search_account))) {
345 $sql .= natural_search("aa.account_number", $search_account);
346}
347if (strlen(trim($search_vat))) {
348 $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
349}
350if ($search_date_start) {
351 $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
352}
353if ($search_date_end) {
354 $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
355}
356if (strlen(trim($search_country))) {
357 $arrayofcode = getCountriesInEEC();
358 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
359 foreach ($arrayofcode as $key => $value) {
360 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
361 if ($value != $mysoc->country_code) {
362 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
363 }
364 }
365 if ($search_country == 'special_allnotme') {
366 $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
367 } elseif ($search_country == 'special_eec') {
368 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
369 } elseif ($search_country == 'special_eecnotme') {
370 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
371 } elseif ($search_country == 'special_noteec') {
372 $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
373 } else {
374 $sql .= natural_search("co.code", $search_country);
375 }
376}
377if (strlen(trim($search_tvaintra))) {
378 $sql .= natural_search("s.tva_intra", $search_tvaintra);
379}
380if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
381 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
382} else {
383 $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
384}
385$sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
386
387// Add where from hooks
388$parameters = array();
389$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
390$sql .= $hookmanager->resPrint;
391
392$sql .= $db->order($sortfield, $sortorder);
393
394// Count total nb of records
395$nbtotalofrecords = '';
396if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
397 $result = $db->query($sql);
398 $nbtotalofrecords = $db->num_rows($result);
399 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
400 $page = 0;
401 $offset = 0;
402 }
403}
404
405$sql .= $db->plimit($limit + 1, $offset);
406
407dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
408// MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
409// 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
410if ($db->type == 'mysqli') {
411 $db->query("SET SQL_BIG_SELECTS=1");
412}
413
414$result = $db->query($sql);
415if ($result) {
416 $num_lines = $db->num_rows($result);
417 $i = 0;
418
419 $arrayofselected = is_array($toselect) ? $toselect : array();
420
421 $param = '';
422 if ($contextpage != $_SERVER["PHP_SELF"]) {
423 $param .= '&contextpage='.urlencode($contextpage);
424 }
425 if ($limit > 0 && $limit != $conf->liste_limit) {
426 $param .= '&limit='.((int) $limit);
427 }
428 if ($search_societe) {
429 $param .= '&search_societe='.urlencode($search_societe);
430 }
431 if ($search_lineid) {
432 $param .= '&search_lineid='.urlencode((string) ($search_lineid));
433 }
434 if ($search_date_startday) {
435 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
436 }
437 if ($search_date_startmonth) {
438 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
439 }
440 if ($search_date_startyear) {
441 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
442 }
443 if ($search_date_endday) {
444 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
445 }
446 if ($search_date_endmonth) {
447 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
448 }
449 if ($search_date_endyear) {
450 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
451 }
452 if ($search_invoice) {
453 $param .= '&search_invoice='.urlencode($search_invoice);
454 }
455 if ($search_ref) {
456 $param .= '&search_ref='.urlencode($search_ref);
457 }
458 if ($search_label) {
459 $param .= '&search_label='.urlencode($search_label);
460 }
461 if ($search_desc) {
462 $param .= '&search_desc='.urlencode($search_desc);
463 }
464 if ($search_amount) {
465 $param .= '&search_amount='.urlencode($search_amount);
466 }
467 if ($search_vat) {
468 $param .= '&search_vat='.urlencode($search_vat);
469 }
470 if ($search_country) {
471 $param .= "&search_country=".urlencode($search_country);
472 }
473 if ($search_tvaintra) {
474 $param .= "&search_tvaintra=".urlencode($search_tvaintra);
475 }
476 // Add $param from hooks
477 $parameters = array('param' => &$param);
478 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
479 $param .= $hookmanager->resPrint;
480
481 $arrayofmassactions = array(
482 'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount"),
483 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
484 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
485 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
486 );
487 //if ($user->hasRight('mymodule', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
488 //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
489 $massactionbutton = '';
490 if ($massaction !== 'set_default_account') {
491 $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1);
492 }
493
494 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
495 print '<input type="hidden" name="action" value="ventil">';
496 if ($optioncss != '') {
497 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
498 }
499 print '<input type="hidden" name="token" value="'.newToken().'">';
500 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
501 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
502 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
503 print '<input type="hidden" name="page" value="'.$page.'">';
504
505 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
506 print_barre_liste($langs->trans("InvoiceLines").'<br><span class="opacitymedium small">'.$langs->trans("DescVentilTodoCustomer").'</span>', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, (string) $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit, 0, 0, 1);
507
508 if ($massaction == 'set_default_account') {
509 $formquestion = array();
510 $formquestion[] = array('type' => 'other',
511 'name' => 'set_default_account',
512 'label' => $langs->trans("AccountancyCode"),
513 'value' => $formaccounting->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'));
514 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($toselect)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
515 }
516
517 if (!empty($msg)) {
518 print $msg.'<br>';
519 }
520
521 $moreforfilter = '';
522
523 $varpage = $contextpage;
524 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
525 $selectedfields = $htmlofselectarray;
526 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
527
528 print '<div class="div-table-responsive">';
529 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
530
531 // We add search filter
532 print '<tr class="liste_titre_filter">';
533 // Action column
534 if ($conf->main_checkbox_left_column) {
535 print '<td class="liste_titre maxwidthsearch center actioncolumn">';
536 $searchpicto = $form->showFilterButtons('left');
537 print $searchpicto;
538 print '</td>';
539 }
540 // Line ID
541 if (!empty($arrayfields['l.rowid']['checked'])) {
542 print '<td class="liste_titre" data-key="lineid">';
543 print '<input type="text" class="flat maxwidth40" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'">';
544 print '</td>';
545 }
546 // Ref invoice
547 if (!empty($arrayfields['f.ref']['checked'])) {
548 print '<td class="liste_titre" data-key="invoice">';
549 print '<input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'">';
550 print '</td>';
551 }
552 // Date
553 if (!empty($arrayfields['f.datef']['checked'])) {
554 print '<td class="liste_titre center">';
555 print '<div class="nowrapfordate">';
556 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
557 print '</div>';
558 print '<div class="nowrapfordate">';
559 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
560 print '</div>';
561 print '</td>';
562 }
563 // Product ref
564 if (!empty($arrayfields['p.ref']['checked'])) {
565 print '<td class="liste_titre" data-key="ref">';
566 print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
567 print '</td>';
568 }
569 // Description
570 if (!empty($arrayfields['l.description']['checked'])) {
571 print '<td class="liste_titre" data-key="desc">';
572 print '<input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'">';
573 print '</td>';
574 }
575 // Amount
576 if (!empty($arrayfields['l.total_ht']['checked'])) {
577 print '<td class="liste_titre" data-key="amount">';
578 print '<input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
579 print '</td>';
580 }
581 // VAT
582 if (!empty($arrayfields['l.tva_tx']['checked'])) {
583 print '<td class="liste_titre" data-key="vat">';
584 print '<input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'">';
585 print '</td>';
586 }
587 // Thirdparty
588 if (!empty($arrayfields['s.nom']['checked'])) {
589 print '<td class="liste_titre" data-key="societe">';
590 print '<input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
591 print '</td>';
592 }
593 // Country
594 if (!empty($arrayfields['co.label']['checked'])) {
595 print '<td class="liste_titre" data-key="country">';
596 print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth125', 'code2', 1, 0, 1);
597 print '</td>';
598 }
599 // TVA Intracom
600 if (!empty($arrayfields['s.tva_intra']['checked'])) {
601 print '<td class="liste_titre">';
602 print '<input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'">';
603 print '</td>';
604 }
605 // Data suggested
606 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
607 print '<td class="liste_titre"></td>';
608 }
609 // Account
610 if (!empty($arrayfields['aa.account_number']['checked'])) {
611 print '<td class="liste_titre"></td>';
612 }
613 // Fields from hook
614 $parameters = array('arrayfields' => $arrayfields);
615 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
616 print $hookmanager->resPrint;
617
618 // Action column
619 if (!$conf->main_checkbox_left_column) {
620 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
621 $searchpicto = $form->showFilterButtons();
622 print $searchpicto;
623 print '</td>';
624 }
625 print "</tr>\n";
626
627 // Fields title label
628 // --------------------------------------------------------------------
629 $totalarray = array();
630 $totalarray['nbfield'] = 0;
631
632 print '<tr class="liste_titre">';
633 // Action column
634 if ($conf->main_checkbox_left_column) {
635 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
636 $totalarray['nbfield']++;
637 }
638 // Line ID
639 if (!empty($arrayfields['l.rowid']['checked'])) {
640 print_liste_field_titre($arrayfields['l.rowid']['label'], $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
641 $totalarray['nbfield']++;
642 }
643 // Ref invoice
644 if (!empty($arrayfields['f.ref']['checked'])) {
645 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
646 $totalarray['nbfield']++;
647 }
648 // Date
649 if (!empty($arrayfields['f.datef']['checked'])) {
650 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
651 $totalarray['nbfield']++;
652 }
653 // Product ref
654 if (!empty($arrayfields['p.ref']['checked'])) {
655 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
656 $totalarray['nbfield']++;
657 }
658 // product description
659 if (!empty($arrayfields['l.description']['checked'])) {
660 print_liste_field_titre($arrayfields['l.description']['label'], $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
661 $totalarray['nbfield']++;
662 }
663 // Amount
664 if (!empty($arrayfields['l.total_ht']['checked'])) {
665 print_liste_field_titre($arrayfields['l.total_ht']['label'], $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
666 $totalarray['nbfield']++;
667 }
668 // VAT
669 if (!empty($arrayfields['l.tva_tx']['checked'])) {
670 print_liste_field_titre($arrayfields['l.tva_tx']['label'], $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
671 $totalarray['nbfield']++;
672 }
673 // Thirdparty
674 if (!empty($arrayfields['s.nom']['checked'])) {
675 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
676 $totalarray['nbfield']++;
677 }
678 // Country
679 if (!empty($arrayfields['co.label']['checked'])) {
680 print_liste_field_titre($arrayfields['co.label']['label'], $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
681 $totalarray['nbfield']++;
682 }
683 // TVA Intracom
684 if (!empty($arrayfields['s.tva_intra']['checked'])) {
685 print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
686 $totalarray['nbfield']++;
687 }
688 // Data suggested
689 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
690 print_liste_field_titre($arrayfields['aa.data_suggest']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
691 $totalarray['nbfield']++;
692 }
693 // Account
694 if (!empty($arrayfields['aa.account_number']['checked'])) {
695 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
696 $totalarray['nbfield']++;
697 }
698 // Hook fields
699 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
700 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
701 print $hookmanager->resPrint;
702 // Action column
703 if (!$conf->main_checkbox_left_column) {
704 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
705 $totalarray['nbfield']++;
706 }
707 print "</tr>\n";
708
709 $thirdpartystatic = new Societe($db);
710 $facture_static = new Facture($db);
711 $facture_static_det = new FactureLigne($db);
712 $product_static = new Product($db);
713
714
715 $accountingaccount_codetotid_cache = array();
716 $suggestedaccountingaccountfor = ''; // Initialise (for static analysis)
717 $suggestedaccountingaccountbydefaultfor = '';
718
719 while ($i < min($num_lines, $limit)) {
720 $objp = $db->fetch_object($result);
721
722 // product_type: 0 = service, 1 = product
723 // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
724 // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
725 $code_sell_l = '';
726 $code_sell_p = '';
727 $code_sell_t = '';
728
729 $thirdpartystatic->id = $objp->socid;
730 $thirdpartystatic->name = $objp->name;
731 $thirdpartystatic->client = $objp->client;
732 $thirdpartystatic->fournisseur = $objp->fournisseur;
733 $thirdpartystatic->code_client = $objp->code_client;
734 $thirdpartystatic->code_compta = $objp->code_compta_client; // For backward compatibility
735 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
736 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
737 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
738 $thirdpartystatic->email = $objp->email;
739 $thirdpartystatic->country_code = $objp->country_code;
740 $thirdpartystatic->tva_intra = $objp->tva_intra;
741 $thirdpartystatic->code_compta_product = $objp->company_code_sell; // The accounting account for product stored on thirdparty object (for level3 suggestion)
742
743 $product_static->ref = $objp->product_ref;
744 $product_static->id = $objp->product_id;
745 $product_static->type = $objp->type;
746 $product_static->label = $objp->product_label;
747 $product_static->status = $objp->status;
748 $product_static->status_buy = $objp->status_buy;
749 $product_static->accountancy_code_sell = $objp->code_sell;
750 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
751 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
752 $product_static->accountancy_code_buy = $objp->code_buy;
753 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
754 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
755 $product_static->tva_tx = $objp->tva_tx_prod;
756
757 $facture_static->ref = $objp->ref;
758 $facture_static->id = $objp->facid;
759 $facture_static->type = $objp->ftype;
760 $facture_static->date = $db->jdate($objp->datef);
761 $facture_static->fk_facture_source = $objp->fk_facture_source;
762
763 $facture_static_det->id = $objp->rowid;
764 $facture_static_det->total_ht = $objp->total_ht;
765 $facture_static_det->tva_tx = $objp->tva_tx_line;
766 $facture_static_det->vat_src_code = $objp->vat_src_code;
767 $facture_static_det->product_type = $objp->type_l;
768 $facture_static_det->desc = $objp->description;
769
770 $accountingAccountArray = array(
771 'dom' => $objp->aarowid,
772 'intra' => $objp->aarowid_intra,
773 'export' => $objp->aarowid_export,
774 'thirdparty' => $objp->aarowid_thirdparty);
775
776 $code_sell_p_notset = '';
777 $code_sell_t_notset = '';
778
779 $suggestedid = 0;
780
781 $return = $accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'customer');
782 if (!is_array($return) && $return < 0) {
783 setEventMessage($accountingAccount->error, 'errors');
784 } else {
785 $suggestedid = $return['suggestedid'];
786 $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor'];
787 $suggestedaccountingaccountbydefaultfor = $return['suggestedaccountingaccountbydefaultfor'];
788 $code_sell_l = $return['code_l'];
789 $code_sell_p = $return['code_p'];
790 $code_sell_t = $return['code_t'];
791 }
792 //var_dump($return);
793
794 if (!empty($code_sell_p)) {
795 // Value was defined previously
796 } else {
797 $code_sell_p_notset = 'color:orange';
798 }
799 if (empty($code_sell_l) && empty($code_sell_p)) {
800 $code_sell_p_notset = 'color:red';
801 }
802 if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
803 $code_sell_p_notset = 'color:orange';
804 }
805
806 // $code_sell_l is now default code of product/service
807 // $code_sell_p is now code of product/service
808 // $code_sell_t is now code of thirdparty
809 //var_dump($code_sell_l.' - '.$code_sell_p.' - '.$code_sell_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')');
810
811 print '<tr class="oddeven">';
812 // Action column
813 if ($conf->main_checkbox_left_column) {
814 print '<td class="nowrap center actioncolumn">';
815 $selected = in_array($objp->rowid."_".$i, $toselect);
816 print '<input type="checkbox" class="flat checkforselect checkforselect'.$facture_static_det->id.'" name="toselect[]" value="'.$facture_static_det->id."_".$i.'"'.($selected ? " checked" : "").'/>';
817 print '</td>';
818 if (!$i) {
819 $totalarray['nbfield']++;
820 }
821 }
822 // Line id
823 if (!empty($arrayfields['l.rowid']['checked'])) {
824 print '<td>'.$facture_static_det->id.'</td>';
825 $totalarray['nbfield']++;
826 }
827 // Ref Invoice
828 if (!empty($arrayfields['f.ref']['checked'])) {
829 print '<td class="nowraponall">'.$facture_static->getNomUrl(1).'</td>';
830 $totalarray['nbfield']++;
831 }
832 // Invoice date
833 if (!empty($arrayfields['f.datef']['checked'])) {
834 print '<td class="center">'.dol_print_date($facture_static->date, 'day').'</td>';
835 $totalarray['nbfield']++;
836 }
837 // Ref Product
838 if (!empty($arrayfields['p.ref']['checked'])) {
839 print '<td class="tdoverflowmax125">';
840 if ($product_static->id > 0) {
841 print $product_static->getNomUrl(1);
842 }
843 if ($product_static->label) {
844 print '<br><span class="opacitymedium small">'.dol_escape_htmltag($product_static->label).'</span>';
845 }
846 print '</td>';
847 $totalarray['nbfield']++;
848 }
849 // Description of line
850 if (!empty($arrayfields['l.description']['checked'])) {
851 $text = dolGetFirstLineOfText(dol_string_nohtmltag($facture_static_det->desc, 1));
852 print '<td class="tdoverflowmax150 small classfortooltip" title="'.dol_escape_htmltag($text).'">';
853 $trunclength = getDolGlobalInt('ACCOUNTING_LENGTH_DESCRIPTION');
854 print dol_trunc($text, $trunclength);
855 print '</td>';
856 $totalarray['nbfield']++;
857 }
858 // Amount
859 if (!empty($arrayfields['l.total_ht']['checked'])) {
860 print '<td class="right nowraponall amount">';
861
862 // Create a compensation rate for old situation invoice feature.
863 $situation_ratio = 1;
864 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
865 if ($objp->situation_cycle_ref) {
866 // Avoid divide by 0
867 if ($objp->situation_percent == 0) {
868 $situation_ratio = 0;
869 } else {
870 $line = new FactureLigne($db);
871 $line->fetch($objp->rowid);
872
873 // Situation invoices handling
874 $prev_progress = $line->get_prev_progress($objp->facid);
875
876 $situation_ratio = ($objp->situation_percent - $prev_progress) / $objp->situation_percent;
877 }
878 }
879 print price($objp->total_ht * $situation_ratio);
880 } else {
881 print price($objp->total_ht);
882 }
883 print '</td>';
884 $totalarray['nbfield']++;
885 }
886 // Vat rate
887 if (!empty($arrayfields['l.tva_tx']['checked'])) {
888 $code_vat_differ = '';
889 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
890 $code_vat_differ = 'warning bold';
891 }
892 print '<td class="right'.($code_vat_differ ? ' '.$code_vat_differ : '').'">';
893 print vatrate($facture_static_det->tva_tx.($facture_static_det->vat_src_code ? ' ('.$facture_static_det->vat_src_code.')' : ''));
894 print '</td>';
895 $totalarray['nbfield']++;
896 }
897 // Thirdparty
898 if (!empty($arrayfields['s.nom']['checked'])) {
899 print '<td class="tdoverflowmax125">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
900 $totalarray['nbfield']++;
901 }
902 // Country
903 if (!empty($arrayfields['co.label']['checked'])) {
904 $labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
905 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelcountry).'">';
906 print dol_escape_htmltag($labelcountry);
907 print '</td>';
908 $totalarray['nbfield']++;
909 }
910 // VAT Num
911 if (!empty($arrayfields['s.tva_intra']['checked'])) {
912 print '<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).'">'.dol_escape_htmltag($objp->tva_intra).'</td>';
913 $totalarray['nbfield']++;
914 }
915 // Found accounts
916 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
917 print '<td class="small">';
918 // First show default account for any products
919 $s = '1. '.(($facture_static_det->product_type == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': ';
920 $shelp = '';
921 $ttype = 'help';
922 if ($suggestedaccountingaccountbydefaultfor == 'eec') {
923 $shelp .= $langs->trans("SaleEEC");
924 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') {
925 $shelp = $langs->trans("SaleEECWithVAT");
926 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') {
927 $shelp = $langs->trans("SaleEECWithoutVATNumber");
928 $ttype = 'warning';
929 } elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
930 $shelp .= $langs->trans("SaleExport");
931 }
932 $s .= ($code_sell_l > 0 ? length_accountg($code_sell_l) : '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>');
933 $textforrule = $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
934 // Now show account for product
935 if ($product_static->id > 0) {
936 $textforrule .= '<br>';
937 $s = '2. '.(($facture_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
938 $shelp = '';
939 $ttype = 'help';
940 if ($suggestedaccountingaccountbydefaultfor == 'eec') {
941 $shelp .= $langs->trans("SaleEEC");
942 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') {
943 $shelp = $langs->trans("SaleEECWithVAT");
944 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') {
945 $shelp = $langs->trans("SaleEECWithoutVATNumber");
946 $ttype = 'warning';
947 } elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
948 $shelp .= $langs->trans("SaleExport");
949 }
950 $s .= (empty($code_sell_p) ? '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($code_sell_p));
951 $textforrule .= $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
952 } else {
953 $textforrule .= '<br>';
954 $s = '2. '.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
955 $shelp = '';
956 $s .= $langs->trans("NotDefined");
957 $textforrule .= $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
958 }
959 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
960 $textforrule .= '<br>';
961 $s = '3. '.(($facture_static_det->product_type == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")).': ';
962 $shelp = '';
963 $s .= ($code_sell_t > 0 ? length_accountg($code_sell_t) : '<span style="'.$code_sell_t_notset.'">'.$langs->trans("NotDefined").'</span>');
964 $textforrule .= $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
965 }
966 print $textforrule;
967 print '</td>';
968 $totalarray['nbfield']++;
969 }
970 // Suggested accounting account
971 if (!empty($arrayfields['aa.account_number']['checked'])) {
972 print '<td>';
973 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');
974 print '</td>';
975 $totalarray['nbfield']++;
976 }
977 // Fields from hook
978 $parameters = array('arrayfields' => $arrayfields, 'obj' => $objp, 'i' => $i, 'totalarray' => &$totalarray);
979 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
980 print $hookmanager->resPrint;
981 // Action column
982 if (!$conf->main_checkbox_left_column) {
983 print '<td class="nowrap center actioncolumn">';
984 $selected = in_array($objp->rowid."_".$i, $toselect);
985 print '<input type="checkbox" class="flat checkforselect checkforselect'.$facture_static_det->id.'" name="toselect[]" value="'.$facture_static_det->id."_".$i.'"'.($selected ? " checked" : "").'/>';
986 print '</td>';
987 if (!$i) {
988 $totalarray['nbfield']++;
989 }
990 }
991
992 print '</tr>';
993 $i++;
994 }
995 if ($num_lines == 0) {
996 $colspan = 1;
997 foreach ($arrayfields as $key => $val) {
998 if (!empty($val['checked'])) {
999 $colspan++;
1000 }
1001 }
1002 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1003 }
1004
1005 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1006 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1007 print $hookmanager->resPrint;
1008
1009 print '</table>';
1010 print "</div>";
1011
1012 print '</form>';
1013} else {
1014 print $db->error();
1015}
1016if ($db->type == 'mysqli') {
1017 $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
1018}
1019
1020// Add code to auto check the box when we select an account
1021print '<script type="text/javascript">
1022jQuery(document).ready(function() {
1023 jQuery(".codeventil").change(function() {
1024 var s=$(this).attr("id").replace("codeventil", "")
1025 console.log(s+" "+$(this).val());
1026 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
1027 else jQuery(".checkforselect"+s).prop("checked", true);
1028 });
1029});
1030</script>';
1031
1032// End of page
1033llxFooter();
1034$db->close();
$totalarray
Definition export.php:1216
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
Class to manage accounting accounts.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage invoice lines.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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 '.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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.
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.