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