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