dolibarr 24.0.0-beta
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) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
7 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>s
8 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
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.'/product/class/product.class.php';
44require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
45require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
46require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
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') : 'accountancysupplierlist'; // To manage different context of search
59$optioncss = GETPOST('optioncss', 'alpha');
60
61$default_account = GETPOSTINT('default_account');
62
63// Search Getpost
64$search_lineid = GETPOST('search_lineid', 'alpha'); // Can be '> 100'
65$search_societe = GETPOST('search_societe', 'alpha');
66$search_ref = GETPOST('search_ref', 'alpha');
67$search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
68$search_invoice = GETPOST('search_invoice', 'alpha');
69$search_label = GETPOST('search_label', 'alpha');
70$search_desc = GETPOST('search_desc', 'alpha');
71$search_amount = GETPOST('search_amount', 'alpha');
72$search_account = GETPOST('search_account', 'alpha');
73$search_vat = GETPOST('search_vat', 'alpha');
74$search_date_startday = GETPOSTINT('search_date_startday');
75$search_date_startmonth = GETPOSTINT('search_date_startmonth');
76$search_date_startyear = GETPOSTINT('search_date_startyear');
77$search_date_endday = GETPOSTINT('search_date_endday');
78$search_date_endmonth = GETPOSTINT('search_date_endmonth');
79$search_date_endyear = GETPOSTINT('search_date_endyear');
80$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
81$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
82$search_country = GETPOST('search_country', 'aZ09');
83$search_tvaintra = GETPOST('search_tvaintra', 'alpha');
84
85// Load variable for pagination
86$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION', $conf->liste_limit);
87$sortfield = GETPOST('sortfield', 'aZ09comma');
88$sortorder = GETPOST('sortorder', 'aZ09comma');
89$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
90if (empty($page) || $page < 0) {
91 $page = 0;
92}
93$offset = $limit * $page;
94$pageprev = $page - 1;
95$pagenext = $page + 1;
96if (!$sortfield) {
97 $sortfield = "f.datef, f.ref, l.rowid";
98}
99if (!$sortorder) {
100 if (getDolGlobalInt('ACCOUNTING_LIST_SORT_VENTILATION_TODO') > 0) {
101 $sortorder = "DESC";
102 } else {
103 $sortorder = "ASC";
104 }
105}
106
107// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
108$hookmanager->initHooks(array($contextpage));
109
110$formaccounting = new FormAccounting($db);
111$accountingAccount = new AccountingAccount($db);
112
113$chartaccountcode = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
114
115// Security check
116if (!isModEnabled('accounting')) {
118}
119if ($user->socid > 0) {
121}
122if (!$user->hasRight('accounting', 'bind', 'write')) {
124}
125
126$arrayfields = array(
127 'l.rowid' => array('label' => "LineId", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
128 'f.ref' => array('label' => "Invoice", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
129 'f.libelle' => array('label' => "InvoiceLabel", 'position' => 1, 'checked' => '-1', 'enabled' => '1'),
130 'f.datef' => array('label' => "Date", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // f.datef, f.ref, l.rowid
131 'p.ref' => array('label' => "ProductRef", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
132 'l.description' => array('label' => "ProductDescription", 'position' => 1, 'checked' => '-1', 'enabled' => '1'),
133 'l.total_ht' => array('label' => "Amount", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
134 'l.tva_tx' => array('label' => "VATRate", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
135 's.nom' => array('label' => "ThirdParty", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
136 'co.label' => array('label' => "Country", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
137 's.tva_intra' => array('label' => "VATIntraShort", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
138 'aa.data_suggest' => array('label' => "DataUsedToSuggestAccount", 'position' => 1, 'checked' => '1', 'enabled' => '1'), // Seems not used in search.
139 'aa.account_number' => array('label' => "AccountAccountingSuggest", 'position' => 1, 'checked' => '1', 'enabled' => '1'),
140);
141// @phpstan-ignore-next-line
142$arrayfields = dol_sort_array($arrayfields, 'position');
143
144// Define begin binding date
145if (empty($search_date_start) && getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
146 $search_date_start = $db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'));
147}
148
149$object = null;
150
151
152/*
153 * Actions
154 */
155
156if (GETPOST('cancel', 'alpha')) {
157 $action = 'list';
158 $massaction = '';
159}
160if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
161 $massaction = '';
162}
163
164$parameters = array('arrayfields' => &$arrayfields);
165$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
166if ($reshook < 0) {
167 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
168}
169
170if (empty($reshook)) {
171 // Selection of new fields
172 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
173
174 // Purge search criteria
175 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
176 $search_societe = '';
177 $search_lineid = '';
178 $search_ref = '';
179 $search_ref_supplier = '';
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."facture_fourn_det";
227 $sql .= " SET fk_code_ventilation = ".((int) $monCompte);
228 $sql .= " WHERE rowid = ".((int) $monId);
229
230 $accountventilated = new AccountingAccount($db);
231 $accountventilated->fetch($monCompte, '', 1);
232
233 dol_syslog('accountancy/supplier/list.php', LOG_DEBUG);
234 if ($db->query($sql)) {
235 $msg .= '<div><span class="green">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
236 $ok++;
237 } else {
238 $msg .= '<div><span class="error">'.$langs->trans("ErrorDB").' : '.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NotVentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'<br> <pre>'.$sql.'</pre></span></div>';
239 $ko++;
240 }
241 }
242
243 $cpt++;
244 }
245 $msg .= '</div>';
246 $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
247 }
248}
249
250if (GETPOST('sortfield') == 'f.datef, f.ref, l.rowid') {
251 $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1);
252 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
253 $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value, 'yesno', 0, '', $conf->entity);
254}
255
256
257/*
258 * View
259 */
260
261$form = new Form($db);
262$formother = new FormOther($db);
263
264$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
265
266llxHeader('', $langs->trans("SuppliersVentilation"), $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-accountancy accountancy-supplier 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// Supplier Invoice Lines
277$sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype, f.fk_facture_source,";
278$sql .= " l.rowid, l.fk_product, l.description, l.total_ht, 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_buy as company_code_buy";
295} else {
296 $sql .= " s.code_compta as code_compta_client,";
297 $sql .= " s.code_compta_fournisseur,";
298 $sql .= " s.accountancy_code_buy as company_code_buy";
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_fourn 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."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
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_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
317$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
318$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
319$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_societe_perentity . ".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa4.entity = ".$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 (strlen($search_lineid)) {
329 $sql .= natural_search("l.rowid", $search_lineid, 1);
330}
331if (strlen($search_societe)) {
332 $sql .= natural_search('s.nom', $search_societe);
333}
334if (strlen(trim($search_invoice))) {
335 $sql .= natural_search(array("f.ref", "f.ref_supplier"), $search_invoice);
336}
337if (strlen(trim($search_ref))) {
338 $sql .= natural_search("p.ref", $search_ref);
339}
340/*if (strlen(trim($search_ref_supplier))) {
341 $sql .= natural_search("f.ref_supplier", $search_ref_supplier);
342}*/
343if (strlen(trim($search_label))) {
344 $sql .= natural_search(array("p.label", "f.libelle"), $search_label);
345}
346if (strlen(trim($search_desc))) {
347 $sql .= natural_search("l.description", $search_desc);
348}
349if (strlen(trim($search_amount))) {
350 $sql .= natural_search("l.total_ht", $search_amount, 1);
351}
352if (strlen(trim($search_account))) {
353 $sql .= natural_search("aa.account_number", $search_account);
354}
355if (strlen(trim($search_vat))) {
356 $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
357}
358if ($search_date_start) {
359 $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
360}
361if ($search_date_end) {
362 $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
363}
364if (strlen(trim($search_country))) {
365 $arrayofcode = getCountriesInEEC();
366 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
367 foreach ($arrayofcode as $key => $value) {
368 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
369 if ($value != $mysoc->country_code) {
370 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
371 }
372 }
373 if ($search_country == 'special_allnotme') {
374 $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
375 } elseif ($search_country == 'special_eec') {
376 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
377 } elseif ($search_country == 'special_eecnotme') {
378 $sql .= " AND co.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
379 } elseif ($search_country == 'special_noteec') {
380 $sql .= " AND co.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
381 } else {
382 $sql .= natural_search("co.code", $search_country);
383 }
384}
385if (strlen(trim($search_tvaintra))) {
386 $sql .= natural_search("s.tva_intra", $search_tvaintra);
387}
388if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
389 $sql .= " AND f.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_SITUATION.")";
390} else {
392}
393$sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
394
395// Add where from hooks
396$parameters = array();
397$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
398$sql .= $hookmanager->resPrint;
399
400$sql .= $db->order($sortfield, $sortorder);
401
402// Count total nb of records
403$nbtotalofrecords = '';
404if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
405 $result = $db->query($sql);
406 $nbtotalofrecords = $db->num_rows($result);
407 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
408 $page = 0;
409 $offset = 0;
410 }
411}
412
413$sql .= $db->plimit($limit + 1, $offset);
414
415dol_syslog('accountancy/supplier/list.php', LOG_DEBUG);
416// MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
417// 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
418if ($db->type == 'mysqli') {
419 $db->query("SET SQL_BIG_SELECTS=1");
420}
421
422$result = $db->query($sql);
423if ($result) {
424 $num_lines = $db->num_rows($result);
425 $i = 0;
426
427 $arrayofselected = is_array($toselect) ? $toselect : array();
428
429 $param = '';
430 if ($contextpage != $_SERVER["PHP_SELF"]) {
431 $param .= '&contextpage='.urlencode($contextpage);
432 }
433 if ($limit > 0 && $limit != $conf->liste_limit) {
434 $param .= '&limit='.((int) $limit);
435 }
436 if ($search_lineid) {
437 $param .= '&search_lineid='.urlencode((string) ($search_lineid));
438 }
439 if ($search_societe) {
440 $param .= '&search_societe='.urlencode($search_societe);
441 }
442 if ($search_date_startday) {
443 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
444 }
445 if ($search_date_startmonth) {
446 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
447 }
448 if ($search_date_startyear) {
449 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
450 }
451 if ($search_date_endday) {
452 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
453 }
454 if ($search_date_endmonth) {
455 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
456 }
457 if ($search_date_endyear) {
458 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
459 }
460 if ($search_invoice) {
461 $param .= '&search_invoice='.urlencode($search_invoice);
462 }
463 if ($search_ref) {
464 $param .= '&search_ref='.urlencode($search_ref);
465 }
466 if ($search_ref_supplier) {
467 $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
468 }
469 if ($search_label) {
470 $param .= '&search_label='.urlencode($search_label);
471 }
472 if ($search_desc) {
473 $param .= '&search_desc='.urlencode($search_desc);
474 }
475 if ($search_amount) {
476 $param .= '&search_amount='.urlencode($search_amount);
477 }
478 if ($search_vat) {
479 $param .= '&search_vat='.urlencode($search_vat);
480 }
481 if ($search_country) {
482 $param .= "&search_country=".urlencode($search_country);
483 }
484 if ($search_tvaintra) {
485 $param .= "&search_tvaintra=".urlencode($search_tvaintra);
486 }
487 // Add $param from hooks
488 $parameters = array('param' => &$param);
489 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
490 $param .= $hookmanager->resPrint;
491
492 $arrayofmassactions = array(
493 'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount"),
494 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
495 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
496 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
497 );
498 //if ($user->hasRight('mymodule', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
499 //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
500 $massactionbutton = '';
501 if ($massaction !== 'set_default_account') {
502 $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1);
503 }
504
505 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
506 print '<input type="hidden" name="action" value="ventil">';
507 if ($optioncss != '') {
508 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
509 }
510 print '<input type="hidden" name="token" value="'.newToken().'">';
511 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
512 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
513 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
514 print '<input type="hidden" name="page" value="'.$page.'">';
515
516 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
517 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);
518 print '<br>';
519
520 if ($massaction == 'set_default_account') {
521 $formquestion = array();
522 $formquestion[] = array('type' => 'other',
523 'name' => 'set_default_account',
524 'label' => $langs->trans("AccountancyCode"),
525 'value' => $formaccounting->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'));
526 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($toselect)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
527 }
528
529 if (!empty($msg)) {
530 print $msg.'<br>';
531 }
532
533 $moreforfilter = '';
534
535 $varpage = $contextpage;
536 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
537 $selectedfields = $htmlofselectarray;
538 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
539
540 print '<div class="div-table-responsive">';
541 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
542
543 // We add search filter
544 print '<tr class="liste_titre_filter">';
545 // Action column
546 if ($conf->main_checkbox_left_column) {
547 print '<td class="liste_titre maxwidthsearch center actioncolumn">';
548 $searchpicto = $form->showFilterButtons('left');
549 print $searchpicto;
550 print '</td>';
551 }
552 // Line ID
553 if (!empty($arrayfields['l.rowid']['checked'])) {
554 print '<td class="liste_titre" data-key="lineid">';
555 print '<input type="text" class="flat maxwidth40" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'">';
556 print '</td>';
557 }
558 // Ref invoice
559 if (!empty($arrayfields['f.ref']['checked'])) {
560 print '<td class="liste_titre" data-key="invoice">';
561 print '<input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'">';
562 print '</td>';
563 }
564 // Invoice label
565 if (!empty($arrayfields['f.label']['checked'])) {
566 print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
567 }
568 // Date
569 if (!empty($arrayfields['f.datef']['checked'])) {
570 print '<td class="liste_titre center">';
571 print '<div class="nowrapfordate">';
572 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
573 print '</div>';
574 print '<div class="nowrapfordate">';
575 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
576 print '</div>';
577 print '</td>';
578 }
579 // Product ref
580 if (!empty($arrayfields['p.ref']['checked'])) {
581 print '<td class="liste_titre" data-key="ref">';
582 print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
583 print '</td>';
584 }
585 // Description
586 if (!empty($arrayfields['l.description']['checked'])) {
587 print '<td class="liste_titre" data-key="desc">';
588 print '<input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'">';
589 print '</td>';
590 }
591 // Amount
592 if (!empty($arrayfields['l.total_ht']['checked'])) {
593 print '<td class="liste_titre" data-key="amount">';
594 print '<input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
595 print '</td>';
596 }
597 // VAT
598 if (!empty($arrayfields['l.tva_tx']['checked'])) {
599 print '<td class="liste_titre" data-key="vat">';
600 print '<input type="text" class="right flat maxwidth50" placeholder="%" name="search_vat" size="1" value="'.dol_escape_htmltag($search_vat).'">';
601 print '</td>';
602 }
603 // Thirdparty
604 if (!empty($arrayfields['s.nom']['checked'])) {
605 print '<td class="liste_titre" data-key="societe">';
606 print '<input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
607 print '</td>';
608 }
609 // Country
610 if (!empty($arrayfields['co.label']['checked'])) {
611 print '<td class="liste_titre" data-key="country">';
612 print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth125', 'code2', 1, 0, 1);
613 print '</td>';
614 }
615 // TVA Intracom
616 if (!empty($arrayfields['s.tva_intra']['checked'])) {
617 print '<td class="liste_titre">';
618 print '<input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'">';
619 print '</td>';
620 }
621 // Data suggested
622 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
623 print '<td class="liste_titre"></td>';
624 }
625 // Account
626 if (!empty($arrayfields['aa.account_number']['checked'])) {
627 print '<td class="liste_titre"></td>';
628 }
629 // Fields from hook
630 $parameters = array('arrayfields' => $arrayfields);
631 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
632 print $hookmanager->resPrint;
633 // Action column
634 if (!$conf->main_checkbox_left_column) {
635 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
636 $searchpicto = $form->showFilterButtons();
637 print $searchpicto;
638 print '</td>';
639 }
640 print "</tr>\n";
641
642 // Fields title label
643 // --------------------------------------------------------------------
644 $totalarray = array();
645 $totalarray['nbfield'] = 0;
646
647 print '<tr class="liste_titre">';
648 // Action column
649 if ($conf->main_checkbox_left_column) {
650 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
651 $totalarray['nbfield']++;
652 }
653 // Line ID
654 if (!empty($arrayfields['l.rowid']['checked'])) {
655 print_liste_field_titre($arrayfields['l.rowid']['label'], $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
656 $totalarray['nbfield']++;
657 }
658 // Ref invoice
659 if (!empty($arrayfields['f.ref']['checked'])) {
660 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
661 $totalarray['nbfield']++;
662 }
663 // Invoice label
664 if (!empty($arrayfields['f.libelle']['checked'])) {
665 print_liste_field_titre($arrayfields['f.libelle']['label'], $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
666 $totalarray['nbfield']++;
667 }
668 // Date
669 if (!empty($arrayfields['f.datef']['checked'])) {
670 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
671 $totalarray['nbfield']++;
672 }
673 // Product ref
674 if (!empty($arrayfields['p.ref']['checked'])) {
675 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
676 $totalarray['nbfield']++;
677 }
678 // product description
679 if (!empty($arrayfields['l.description']['checked'])) {
680 print_liste_field_titre($arrayfields['l.description']['label'], $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
681 $totalarray['nbfield']++;
682 }
683 // Amount
684 if (!empty($arrayfields['l.total_ht']['checked'])) {
685 print_liste_field_titre($arrayfields['l.total_ht']['label'], $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
686 $totalarray['nbfield']++;
687 }
688 // VAT
689 if (!empty($arrayfields['l.tva_tx']['checked'])) {
690 print_liste_field_titre($arrayfields['l.tva_tx']['label'], $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
691 $totalarray['nbfield']++;
692 }
693 // Thirdparty
694 if (!empty($arrayfields['s.nom']['checked'])) {
695 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
696 $totalarray['nbfield']++;
697 }
698 // Country
699 if (!empty($arrayfields['co.label']['checked'])) {
700 print_liste_field_titre($arrayfields['co.label']['label'], $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
701 $totalarray['nbfield']++;
702 }
703 // TVA Intracom
704 if (!empty($arrayfields['s.tva_intra']['checked'])) {
705 print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
706 $totalarray['nbfield']++;
707 }
708 // Data suggested
709 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
710 print_liste_field_titre($arrayfields['aa.data_suggest']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
711 $totalarray['nbfield']++;
712 }
713 // Account
714 if (!empty($arrayfields['aa.account_number']['checked'])) {
715 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
716 $totalarray['nbfield']++;
717 }
718 // Hook fields
719 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
720 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
721 print $hookmanager->resPrint;
722 // Action column
723 if (!$conf->main_checkbox_left_column) {
724 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
725 $totalarray['nbfield']++;
726 }
727 print "</tr>\n";
728
729 $thirdpartystatic = new Societe($db);
730 $facturefourn_static = new FactureFournisseur($db);
731 $facturefourn_static_det = new SupplierInvoiceLine($db);
732 $product_static = new Product($db);
733
734 $accountingaccount_codetotid_cache = array();
735 $suggestedaccountingaccountfor = '';
736 $suggestedaccountingaccountbydefaultfor = '';
737 $totalarray = array();
738 $totalarray['nbfield'] = 0;
739
740 while ($i < min($num_lines, $limit)) {
741 $objp = $db->fetch_object($result);
742
743 // product_type: 0 = service, 1 = product
744 // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
745 // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
746 $code_buy_l = '';
747 $code_buy_p = '';
748 $code_buy_t = '';
749
750 $thirdpartystatic->id = $objp->socid;
751 $thirdpartystatic->name = $objp->name;
752 $thirdpartystatic->client = $objp->client;
753 $thirdpartystatic->fournisseur = $objp->fournisseur;
754 $thirdpartystatic->code_client = $objp->code_client;
755 $thirdpartystatic->code_compta_client = $objp->code_compta_client;
756 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
757 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
758 $thirdpartystatic->email = $objp->email;
759 $thirdpartystatic->country_code = $objp->country_code;
760 $thirdpartystatic->tva_intra = $objp->tva_intra;
761 $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion)
762
763 $product_static->ref = $objp->product_ref;
764 $product_static->id = $objp->product_id;
765 $product_static->type = $objp->type;
766 $product_static->label = $objp->product_label;
767 $product_static->status = $objp->status;
768 $product_static->status_buy = $objp->status_buy;
769 $product_static->accountancy_code_sell = $objp->code_sell;
770 $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
771 $product_static->accountancy_code_sell_export = $objp->code_sell_export;
772 $product_static->accountancy_code_buy = $objp->code_buy;
773 $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
774 $product_static->accountancy_code_buy_export = $objp->code_buy_export;
775 $product_static->tva_tx = $objp->tva_tx_prod;
776
777 $facturefourn_static->ref = $objp->ref;
778 $facturefourn_static->id = $objp->facid;
779 $facturefourn_static->type = $objp->ftype;
780 $facturefourn_static->ref_supplier = $objp->ref_supplier;
781 $facturefourn_static->label = $objp->invoice_label;
782 $facturefourn_static->date = $db->jdate($objp->datef);
783 $facturefourn_static->fk_facture_source = $objp->fk_facture_source;
784
785 $facturefourn_static_det->id = $objp->rowid;
786 $facturefourn_static_det->total_ht = $objp->total_ht;
787 $facturefourn_static_det->tva_tx = $objp->tva_tx_line;
788 $facturefourn_static_det->vat_src_code = $objp->vat_src_code;
789 $facturefourn_static_det->product_type = $objp->type_l;
790 $facturefourn_static_det->desc = $objp->description;
791
792 $accountingAccountArray = array(
793 'dom' => $objp->aarowid,
794 'intra' => $objp->aarowid_intra,
795 'export' => $objp->aarowid_export,
796 'thirdparty' => $objp->aarowid_thirdparty);
797
798 $code_buy_p_notset = '';
799 $code_buy_t_notset = '';
800
801 $suggestedid = 0;
802
803 $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facturefourn_static, $facturefourn_static_det, $accountingAccountArray, 'supplier');
804 if (!is_array($return) && $return < 0) {
805 setEventMessage($accountingAccount->error, 'errors');
806 } else {
807 $suggestedid = $return['suggestedid'];
808 $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor'];
809 $suggestedaccountingaccountbydefaultfor = $return['suggestedaccountingaccountbydefaultfor'];
810 $code_buy_l = $return['code_l'];
811 $code_buy_p = $return['code_p'];
812 $code_buy_t = $return['code_t'];
813 }
814 //var_dump($return);
815
816 if (!empty($code_buy_p)) {
817 // Value was defined previously
818 } else {
819 $code_buy_p_notset = 'color:orange';
820 }
821 if (empty($code_buy_l) && empty($code_buy_p)) {
822 $code_buy_p_notset = 'color:red';
823 }
824 /*if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) {
825 $code_sell_p_notset = 'color:orange';
826 }*/
827
828 // $code_buy_l is now default code of product/service
829 // $code_buy_p is now code of product/service
830 // $code_buy_t is now code of thirdparty
831 //var_dump($code_buy_l.' - '.$code_buy_p.' - '.$code_buy_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')');
832
833 print '<tr class="oddeven">';
834
835 // Action column
836 if ($conf->main_checkbox_left_column) {
837 print '<td class="nowrap center actioncolumn">';
838 $selected = in_array($objp->rowid."_".$i, $toselect);
839 print '<input type="checkbox" class="flat checkforselect checkforselect'.$facturefourn_static_det->id.'" name="toselect[]" value="'.$facturefourn_static_det->id."_".$i.'"'.($selected ? " checked" : "").'/>'; print '</td>';
840 if (!$i) {
841 $totalarray['nbfield']++;
842 }
843 }
844
845 // Line id
846 if (!empty($arrayfields['l.rowid']['checked'])) {
847 print '<td>'.$facturefourn_static_det->id.'</td>';
848 $totalarray['nbfield']++;
849 }
850 // Ref Invoice
851 if (!empty($arrayfields['f.ref']['checked'])) {
852 print '<td class="nowraponall cell2linesheight">'.$facturefourn_static->getNomUrl(1);
853 if ($objp->ref_supplier) {
854 print '<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->ref_supplier).'</span>';
855 }
856 print '</td>';
857 $totalarray['nbfield']++;
858 }
859
860 // Ref supplier invoice
861 /*print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($objp->ref_supplier).'">';
862 print $objp->ref_supplier;
863 print '</td>';*/
864
865 // Supplier invoice label
866 if (!empty($arrayfields['f.libelle']['checked'])) {
867 print '<td class="tdoverflowmax100 small" title="'.dol_escape_htmltag($objp->invoice_label).'">';
868 print dolPrintHTML($objp->invoice_label);
869 print '</td>';
870 $totalarray['nbfield']++;
871 }
872 // Date
873 if (!empty($arrayfields['f.datef']['checked'])) {
874 print '<td class="center">'.dol_print_date($facturefourn_static->date, 'day').'</td>';
875 $totalarray['nbfield']++;
876 }
877 // Ref Product
878 if (!empty($arrayfields['p.ref']['checked'])) {
879 print '<td class="tdoverflowmax100 cell2linesheight">';
880 if ($product_static->id > 0) {
881 print $product_static->getNomUrl(1);
882 }
883 if ($product_static->label) {
884 print '<br><span class="opacitymedium small">'.dol_escape_htmltag($product_static->label).'</span>';
885 }
886 print '</td>';
887 $totalarray['nbfield']++;
888 }
889 // Description of line
890 if (!empty($arrayfields['l.description']['checked'])) {
891 $text = dolGetFirstLineOfText(dol_string_nohtmltag($facturefourn_static_det->desc, 1));
892 print '<td class="tdoverflowmax150 small classfortooltip" title="'.dol_escape_htmltag($text).'">';
893 $trunclength = getDolGlobalInt('ACCOUNTING_LENGTH_DESCRIPTION');
894 print dol_trunc($text, $trunclength);
895 print '</td>';
896 }
897 // Amount
898 if (!empty($arrayfields['l.total_ht']['checked'])) {
899 print '<td class="right nowraponall amount">';
900 print price($objp->total_ht);
901 print '</td>';
902 $totalarray['nbfield']++;
903 }
904 // Vat rate
905 if (!empty($arrayfields['l.tva_tx']['checked'])) {
906 $code_vat_differ = '';
907 //if ($objp->vat_tx_l != $objp->vat_tx_p && price2num($objp->vat_tx_p) && price2num($objp->vat_tx_l)) { // Note: having a vat rate of 0 is often the normal case when sells is intra b2b or to export
908 // $code_vat_differ = 'warning bold';
909 //}
910 print '<td class="right cell2linesheight'.($code_vat_differ ? ' '.$code_vat_differ : '').'">';
911 print vatrate($facturefourn_static_det->tva_tx.($facturefourn_static_det->vat_src_code ? ' ('.$facturefourn_static_det->vat_src_code.')' : ''), false, 0, 0, 1);
912 print '</td>';
913 $totalarray['nbfield']++;
914 }
915 // Thirdparty
916 if (!empty($arrayfields['s.nom']['checked'])) {
917 print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'supplier').'</td>';
918 $totalarray['nbfield']++;
919 }
920 // Country
921 if (!empty($arrayfields['co.label']['checked'])) {
922 $labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
923 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($labelcountry).'">';
924 print dol_escape_htmltag($labelcountry);
925 print '</td>';
926 $totalarray['nbfield']++;
927 }
928 // VAT Num
929 if (!empty($arrayfields['co.label']['checked'])) {
930 print '<td class="tdoverflowmax80" title="'.dol_escape_htmltag($objp->tva_intra).'">'.dol_escape_htmltag($objp->tva_intra).'</td>';
931 $totalarray['nbfield']++;
932 }
933 // Found accounts
934 if (!empty($arrayfields['aa.data_suggest']['checked'])) {
935 print '<td class="small cell2linesheight">';
936 $s = '1. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': ';
937 $shelp = '';
938 $ttype = 'help';
939 if ($suggestedaccountingaccountbydefaultfor == 'eec') {
940 $shelp .= $langs->trans("SaleEEC");
941 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') {
942 $shelp = $langs->trans("SaleEECWithVAT");
943 } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') {
944 $shelp = $langs->trans("SaleEECWithoutVATNumber");
945 $ttype = 'warning';
946 } elseif ($suggestedaccountingaccountbydefaultfor == 'export') {
947 $shelp .= $langs->trans("SaleExport");
948 }
949 $s .= ($code_buy_l > 0 ? length_accountg($code_buy_l) : '<span style="'.$code_buy_p_notset.'">'.$langs->trans("NotDefined").'</span>');
950 $textforrule = $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
951 if ($product_static->id > 0) {
952 $textforrule .= '<br>';
953 $s = '2. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
954 $shelp = '';
955 $ttype = 'help';
956 if ($suggestedaccountingaccountfor == 'eec') {
957 $shelp = $langs->trans("SaleEEC");
958 } elseif ($suggestedaccountingaccountfor == 'eecwithvat') {
959 $shelp = $langs->trans("SaleEECWithVAT");
960 } elseif ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') {
961 $shelp = $langs->trans("SaleEECWithoutVATNumber");
962 $ttype = 'warning';
963 } elseif ($suggestedaccountingaccountfor == 'export') {
964 $shelp = $langs->trans("SaleExport");
965 }
966 $s .= (empty($code_buy_p) ? '<span style="'.$code_buy_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($code_buy_p));
967 $textforrule .= $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
968 } else {
969 $textforrule .= '<br>';
970 $s = '2. '.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': ';
971 $shelp = '';
972 $s .= $langs->trans("NotDefined");
973 $textforrule .= $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
974 }
975 if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
976 $textforrule .= '<br>';
977 $s = '3. '.(($facturefourn_static_det->product_type == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")).': ';
978 $shelp = '';
979 $s .= ($code_buy_t > 0 ? length_accountg($code_buy_t) : '<span style="'.$code_buy_t_notset.'">'.$langs->trans("NotDefined").'</span>');
980 $textforrule .= $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
981 }
982 print $textforrule;
983 print '</td>';
984 $totalarray['nbfield']++;
985 }
986 // Suggested accounting account
987 if (!empty($arrayfields['aa.account_number']['checked'])) {
988 print '<td>';
989 print $formaccounting->select_account(($default_account > 0 && $confirm === 'yes' && in_array($objp->rowid."_".$i, $toselect)) ? (string) $default_account : (string) $suggestedid, 'codeventil'.$facturefourn_static_det->id, 1, array(), 0, 0, 'codeventil maxwidth150 maxwidthonsmartphone', 'cachewithshowemptyone');
990 print '</td>';
991 $totalarray['nbfield']++;
992 }
993 // Fields from hook
994 $parameters = array('arrayfields' => $arrayfields, 'obj' => $objp, 'i' => $i, 'totalarray' => &$totalarray);
995 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
996 print $hookmanager->resPrint;
997 // Action column
998 if (!$conf->main_checkbox_left_column) {
999 print '<td class="nowrap center actioncolumn">';
1000 $selected = in_array($objp->rowid."_".$i, $toselect);
1001 print '<input type="checkbox" class="flat checkforselect checkforselect'.$facturefourn_static_det->id.'" name="toselect[]" value="'.$facturefourn_static_det->id."_".$i.'"'.($selected ? " checked" : "").'/>';
1002 print '</td>';
1003 if (!$i) {
1004 $totalarray['nbfield']++;
1005 }
1006 }
1007
1008 print '</tr>';
1009 $i++;
1010 }
1011 if ($num_lines == 0) {
1012 $colspan = 1;
1013 foreach ($arrayfields as $key => $val) {
1014 if (!empty($val['checked'])) {
1015 $colspan++;
1016 }
1017 }
1018 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1019 }
1020
1021 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1022 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1023 print $hookmanager->resPrint;
1024
1025 print '</table>';
1026 print "</div>";
1027
1028 print '</form>';
1029} else {
1030 print $db->error();
1031}
1032if ($db->type == 'mysqli') {
1033 $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
1034}
1035
1036// Add code to auto check the box when we select an account
1037print '<script type="text/javascript">
1038jQuery(document).ready(function() {
1039 jQuery(".codeventil").change(function() {
1040 var s=$(this).attr("id").replace("codeventil", "")
1041 console.log(s+" "+$(this).val());
1042 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
1043 else jQuery(".checkforselect"+s).prop("checked", true);
1044 });
1045});
1046</script>';
1047
1048// End of page
1049llxFooter();
1050$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition list.php:497
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.
const TYPE_SITUATION
Situation invoice.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage line invoices.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.