dolibarr 25.0.0-alpha
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
6 * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
10 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
12 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
13 * Copyright (C) 2015-2022 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
15 * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
16 * Copyright (C) 2019-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
17 * Copyright (C) 2021-2024 Anthony Berton <anthony.berton@bb2a.fr>
18 * Copyright (C) 2023 Nick Fragoulis
19 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
20 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
21 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
22 * Copyright (C) 2024 Solution Libre SAS <contact@solution-libre.fr>
23 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 3 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <https://www.gnu.org/licenses/>.
37 */
38
45// Load Dolibarr environment
46require '../../main.inc.php';
56require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
57require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
58require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
60require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
61require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
62require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
63require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
64require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
65require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
66require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
67require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
68require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
69require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
70require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
71if (isModEnabled('order')) {
72 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
73}
74if (isModEnabled('category')) {
75 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
76 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
77}
78
79// Load translation files required by the page
80$langs->loadLangs(array('banks', 'bills', 'companies', 'products', 'categories', 'cashdesk'));
81
82$search_all = trim(GETPOST('search_all', 'alphanohtml'));
83
84// Get Parameters
85$action = GETPOST('action', 'aZ09');
86$massaction = GETPOST('massaction', 'alpha');
87$show_files = GETPOSTINT('show_files');
88$confirm = GETPOST('confirm', 'alpha');
89$toselect = GETPOST('toselect', 'array:int');
90$optioncss = GETPOST('optioncss', 'alpha');
91$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'invoicelist';
92$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
93
94if ($contextpage == 'poslist') {
95 $optioncss = 'print';
96}
97
98$id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
99$ref = GETPOST('ref', 'alpha');
100$socid = GETPOSTINT('socid');
101
102$userid = GETPOSTINT('userid');
103$search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
104$search_refcustomer = GETPOST('search_refcustomer', 'alpha');
105$search_type = GETPOST('search_type', 'intcomma');
106$search_subtype = GETPOST('search_subtype', 'intcomma');
107$search_project_ref = GETPOST('search_project_ref', 'alpha');
108$search_project = GETPOST('search_project', 'alpha');
109$search_company = GETPOST('search_company', 'alpha');
110$search_company_alias = GETPOST('search_company_alias', 'alpha');
111$search_parent_name = trim(GETPOST('search_parent_name', 'alphanohtml'));
112$search_montant_ht = GETPOST('search_montant_ht', 'alpha');
113$search_montant_vat = GETPOST('search_montant_vat', 'alpha');
114$search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
115$search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
116$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
117$search_login = GETPOST('search_login', 'alpha');
118$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
119$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
120$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
121$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
122$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
123$search_dispute_status = GETPOST('search_dispute_status', 'intcomma');
124$search_status = GETPOST('search_status', 'array:intcomma');
125// if (empty($search_status) && GETPOSTISSET('search_status')) {
126// // The parameter exists in the URL but was not recognized as an array.
127// $search_status = GETPOST('search_status', 'intcomma');
128// if ($search_status !== '' && $search_status !== '-1') {
129// $search_status = array($search_status);
130// } else {
131// $search_status = '';
132// }
133// } elseif (is_array($search_status) && count($search_status) == 0) {
134// $search_status = '';
135// }
136$search_paymentmode = GETPOST('search_paymentmode', 'intcomma');
137$search_paymentterms = GETPOST('search_paymentterms', 'intcomma');
138$search_bankaccount = GETPOST('search_bankaccount', 'intcomma');
139$search_fk_input_reason = GETPOSTINT('search_fk_input_reason');
140$search_module_source = GETPOST('search_module_source', 'alpha');
141$search_pos_source = GETPOST('search_pos_source', 'alpha');
142$search_town = GETPOST('search_town', 'alpha');
143$search_zip = GETPOST('search_zip', 'alpha');
144$search_state = GETPOST("search_state");
145$search_country = GETPOST("search_country", 'aZ09');
146$search_customer_code = GETPOST("search_customer_code", 'alphanohtml');
147$search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
148$search_user = GETPOST('search_user', 'intcomma');
149$search_sale = GETPOST('search_sale', 'intcomma');
150
151$search_date_startday = GETPOSTINT('search_date_startday');
152$search_date_startmonth = GETPOSTINT('search_date_startmonth');
153$search_date_startyear = GETPOSTINT('search_date_startyear');
154$search_date_endday = GETPOSTINT('search_date_endday');
155$search_date_endmonth = GETPOSTINT('search_date_endmonth');
156$search_date_endyear = GETPOSTINT('search_date_endyear');
157$search_date_start = GETPOSTDATE('search_date_start', 'getpost'); // Use tzserver because date invoice is a date without hour
158$search_date_end = GETPOSTDATE('search_date_end', 'getpostend');
159
160$search_date_valid_startday = GETPOSTINT('search_date_valid_startday');
161$search_date_valid_startmonth = GETPOSTINT('search_date_valid_startmonth');
162$search_date_valid_startyear = GETPOSTINT('search_date_valid_startyear');
163$search_date_valid_endday = GETPOSTINT('search_date_valid_endday');
164$search_date_valid_endmonth = GETPOSTINT('search_date_valid_endmonth');
165$search_date_valid_endyear = GETPOSTINT('search_date_valid_endyear');
166$search_date_valid_start = GETPOSTDATE('search_date_valid_start', 'getpost');
167$search_date_valid_end = GETPOSTDATE('search_date_valid_end', 'getpostend');
168$search_note_private = GETPOST('search_note_private', 'alpha');
169$search_note_public = GETPOST('search_note_public', 'alpha');
170
171$search_datelimit_startday = GETPOSTINT('search_datelimit_startday');
172$search_datelimit_startmonth = GETPOSTINT('search_datelimit_startmonth');
173$search_datelimit_startyear = GETPOSTINT('search_datelimit_startyear');
174$search_datelimit_endday = GETPOSTINT('search_datelimit_endday');
175$search_datelimit_endmonth = GETPOSTINT('search_datelimit_endmonth');
176$search_datelimit_endyear = GETPOSTINT('search_datelimit_endyear');
177$search_datelimit_start = GETPOSTDATE('search_datelimit_start', 'getpost'); // Use tzserver because date invoice is a date without hour
178$search_datelimit_end = GETPOSTDATE('search_datelimit_end', 'getpostend');
179
180
181$search_datec_start = GETPOSTDATE('search_datec_start', 'getpost', 'tzuserrel');
182$search_datec_end = GETPOSTDATE('search_datec_end', 'getpostend', 'tzuserrel');
183$search_datem_start = GETPOSTDATE('search_datem_start', 'getpost', 'tzuserrel');
184$search_datem_end = GETPOSTDATE('search_datem_end', 'getpostend', 'tzuserrel');
185
186$search_categ_cus = GETPOST("search_categ_cus", 'intcomma');
187$searchCategoryInvoiceOperator = 0;
188if (GETPOSTISSET('formfilteraction')) {
189 $searchCategoryInvoiceOperator = GETPOSTINT('search_category_invoice_operator');
190} elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
191 $searchCategoryInvoiceOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
192}
193$searchCategoryInvoiceList = GETPOST('search_category_invoice_list', 'array:int');
194// to dump type seen by phpstan during analyse
195// \PHPStan\dumpType($searchCategoryInvoiceList);
196$search_product_category = GETPOST('search_product_category', 'intcomma');
197$search_fac_rec_source_title = GETPOST("search_fac_rec_source_title", 'alpha');
198$search_fk_fac_rec_source = GETPOST('search_fk_fac_rec_source', 'int');
199$search_import_key = trim(GETPOST("search_import_key", "alpha"));
200
201$search_option = GETPOST('search_option');
202if ($search_option == 'late') {
203 $search_status = array('1');
204}
205
206$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
207$sortfield = GETPOST('sortfield', 'aZ09comma');
208$sortorder = GETPOST('sortorder', 'aZ09comma');
209$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
210if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
211 // If $page is not defined, or '' or -1 or if we click on clear filters
212 $page = 0;
213}
214
215if ($contextpage == 'poslist' && !GETPOSTISSET('limit')) {
216 $limit = 5;
217}
218
219$offset = $limit * $page;
220if (!$sortorder && getDolGlobalString('INVOICE_DEFAULT_UNPAYED_SORT_ORDER') && $search_status == '1') {
221 $sortorder = getDolGlobalString('INVOICE_DEFAULT_UNPAYED_SORT_ORDER');
222}
223if (!$sortorder) {
224 $sortorder = 'DESC';
225}
226if (!$sortfield) {
227 $sortfield = 'f.datef,f.rowid';
228}
229$pageprev = $page - 1;
230$pagenext = $page + 1;
231
232$diroutputmassaction = $conf->invoice->dir_output.'/temp/massgeneration/'.$user->id;
233
234$now = dol_now();
235$error = 0;
236$sql = '';
237
238// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
239$object = new Facture($db);
240$hookmanager->initHooks(array($contextpage));
241
242// Fetch optionals attributes and labels
243$extrafields->fetch_name_optionals_label($object->table_element);
244
245$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_') ?: [];
246
247// List of fields to search into when doing a "search in all"
248$fieldstosearchall = array(
249 'f.ref' => 'Ref',
250 'f.ref_client' => 'RefCustomer',
251 'f.note_public' => 'NotePublic',
252 's.nom' => "ThirdParty",
253 's.code_client' => "CustomerCodeShort",
254 's.name_alias' => "AliasNameShort",
255 's.zip' => "Zip",
256 's.town' => "Town",
257 'pd.description' => 'ProductDescription',
258);
259if (empty($user->socid)) {
260 $fieldstosearchall["f.note_private"] = "NotePrivate";
261}
262
263// Show POS fields if cashdesk or takepos module enabled or if global configuration to show POS fields on order list is enabled
264$showpos = (isModEnabled('cashdesk') || isModEnabled('takepos') || getDolGlobalInt('INVOICE_SHOW_POS')) ? '1' : '0';
265
266$checkedtypetiers = '0';
267$arrayfields = array(
268 'f.ref' => array('label' => "Ref", 'checked' => '1', 'position' => 5),
269 'f.ref_client' => array('label' => "RefCustomer", 'checked' => '-1', 'position' => 10),
270 'f.type' => array('label' => "Type", 'checked' => '0', 'position' => 15),
271 'f.subtype' => array('label' => "InvoiceSubtype", 'checked' => '0', 'position' => 17),
272 'f.datef' => array('label' => "DateInvoice", 'checked' => '1', 'position' => 20),
273 'f.date_valid' => array('label' => "DateValidation", 'checked' => '0', 'position' => 22),
274 'f.date_lim_reglement' => array('label' => "DateDue", 'checked' => '1', 'position' => 25),
275 'f.date_closing' => array('label' => "DateClosing", 'checked' => '0', 'position' => 30),
276 'p.ref' => array('label' => "ProjectRef", 'langfile' => 'projects', 'checked' => '1', 'enabled' => (isModEnabled('project') ? '1' : '0'), 'position' => 40),
277 'p.title' => array('label' => "ProjectLabel", 'langfile' => 'projects', 'checked' => '0', 'enabled' => (isModEnabled('project') ? '1' : '0'), 'position' => 41),
278 's.nom' => array('label' => "ThirdParty", 'checked' => '1', 'position' => 50),
279 's.name_alias' => array('label' => "AliasNameShort", 'checked' => '-1', 'position' => 51),
280 's.code_client' => array('label' => "CustomerCodeShort", 'checked' => '-1', 'position' => 52),
281 's2.nom' => array('label' => 'ParentCompany', 'position' => 32, 'checked' => '0'),
282 's.town' => array('label' => "Town", 'checked' => '-1', 'position' => 55),
283 's.zip' => array('label' => "Zip", 'checked' => '-1', 'position' => 60),
284 'state.nom' => array('label' => "StateShort", 'checked' => '0', 'position' => 65),
285 'country.code_iso' => array('label' => "Country", 'checked' => '0', 'position' => 70),
286 'typent.code' => array('label' => "ThirdPartyType", 'checked' => $checkedtypetiers, 'position' => 75),
287 'f.fk_mode_reglement' => array('label' => "PaymentMode", 'checked' => '1', 'position' => 80),
288 'f.fk_cond_reglement' => array('label' => "PaymentConditionsShort", 'checked' => '0', 'position' => 85),
289 'ba.label' => array('label' => "DefaultBankAccount", 'langfile' => 'banks', 'checked' => '0', 'enabled' => (isModEnabled('bank') ? '1' : '0'), 'position' => 192),
290 'f.fk_input_reason' => array('label' => "Source", 'checked' => 0, 'enabled' => 1, 'position' => 88),
291 'f.module_source' => array('label' => "POSModule", 'langfile' => 'cashdesk', 'checked' => ($contextpage == 'poslist' ? '1' : '0'), 'enabled' => $showpos, 'position' => 90),
292 'f.pos_source' => array('label' => "POSTerminal", 'langfile' => 'cashdesk', 'checked' => ($contextpage == 'poslist' ? '1' : '0'), 'enabled' => $showpos, 'position' => 91),
293 'f.total_ht' => array('label' => "AmountHT", 'checked' => '1', 'position' => 95),
294 'f.total_tva' => array('label' => "AmountVAT", 'checked' => '0', 'position' => 100),
295 'f.total_localtax1' => array('label' => $langs->transcountry("AmountLT1", $mysoc->country_code), 'checked' => '0', 'enabled' => ($mysoc->localtax1_assuj == "1"), 'position' => 110),
296 'f.total_localtax2' => array('label' => $langs->transcountry("AmountLT2", $mysoc->country_code), 'checked' => '0', 'enabled' => ($mysoc->localtax2_assuj == "1"), 'position' => 120),
297 'f.total_ttc' => array('label' => "AmountTTC", 'checked' => '0', 'position' => 130),
298 'dynamount_payed' => array('label' => "AlreadyPaid", 'checked' => '0', 'position' => 140),
299 'rtp' => array('label' => "RemainderToPay", 'checked' => '0', 'position' => 150), // Not enabled by default because slow
300 'f.multicurrency_code' => array('label' => 'Currency', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 280),
301 'f.multicurrency_tx' => array('label' => 'CurrencyRate', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 285),
302 'f.multicurrency_total_ht' => array('label' => 'MulticurrencyAmountHT', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 290),
303 'f.multicurrency_total_vat' => array('label' => 'MulticurrencyAmountVAT', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 291),
304 'f.multicurrency_total_ttc' => array('label' => 'MulticurrencyAmountTTC', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 292),
305 'multicurrency_dynamount_payed' => array('label' => 'MulticurrencyAlreadyPaid', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 295),
306 'multicurrency_rtp' => array('label' => 'MulticurrencyRemainderToPay', 'checked' => '0', 'enabled' => (!isModEnabled('multicurrency') ? '0' : '1'), 'position' => 296), // Not enabled by default because slow
307 'total_pa' => array('label' => ((getDolGlobalString('MARGIN_TYPE') == '1') ? 'BuyingPrice' : 'CostPrice'), 'checked' => '0', 'position' => 300, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') ? '0' : '1')),
308 'total_margin' => array('label' => 'Margin', 'langfile' => 'margins', 'checked' => '0', 'position' => 301, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') ? '0' : '1')),
309 'total_margin_rate' => array('label' => 'MarginRate', 'langfile' => 'margins', 'checked' => '0', 'position' => 302, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') || !getDolGlobalString('DISPLAY_MARGIN_RATES') ? '0' : '1')),
310 'total_mark_rate' => array('label' => 'MarkRate', 'langfile' => 'margins', 'checked' => '0', 'position' => 303, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') || !getDolGlobalString('DISPLAY_MARK_RATES') ? '0' : '1')),
311 'f.datec' => array('label' => "DateCreation", 'checked' => '0', 'position' => 500),
312 'f.tms' => array('type' => 'timestamp', 'label' => 'DateModificationShort', 'enabled' => '1', 'visible' => -1, 'notnull' => 1, 'position' => 502),
313 'u.login' => array('label' => "UserAuthor", 'checked' => '0', 'visible' => -1, 'position' => 504),
314 'sale_representative' => array('label' => "SaleRepresentativesOfThirdParty", 'checked' => '0', 'position' => 506),
315 //'f.fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'position'=>506),
316 //'f.fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'notnull'=>-1, 'position'=>508),
317 //'f.fk_user_valid' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>510),
318 //'f.fk_user_closing' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserClosing', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
319 'f.note_public' => array('label' => 'NotePublic', 'checked' => '0', 'position' => 520, 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES'))),
320 'f.note_private' => array('label' => 'NotePrivate', 'checked' => '0', 'position' => 521, 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES'))),
321 'f.fk_fac_rec_source' => array('label' => 'GeneratedFromTemplate', 'checked' => '0', 'position' => 530, 'enabled' => '1'),
322 'f.import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => '1', 'visible' => -2, 'position' => 990),
323 'f.dispute_status' => array('label' => "DisputeStatus", 'checked' => '-1', 'position' => 999),
324 'f.fk_statut' => array('label' => "Status", 'checked' => '1', 'position' => 1000),
325);
326
327if (getDolGlobalString("INVOICE_USE_SITUATION") && getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY')) {
328 $arrayfields['f.retained_warranty'] = array('label' => $langs->trans("RetainedWarranty"), 'checked' => '0', 'position' => 86);
329}
330
331$subtypearray = $object->getArrayOfInvoiceSubtypes(0);
332if (empty($subtypearray)) {
333 unset($arrayfields['f.subtype']);
334}
335
336// Overwrite $arrayfields from columns into ->fields (transition before removal of $arrayoffields)
337foreach ($object->fields as $key => $val) {
338 // If $val['visible']==0, then we never show the field
339
340 if (!empty($val['visible'])) {
341 $visible = (int) dol_eval((string) $val['visible'], 1, 1, '1');
342 $newkey = '';
343 if (array_key_exists($key, $arrayfields)) {
344 $newkey = $key;
345 } elseif (array_key_exists('f.'.$key, $arrayfields)) {
346 $newkey = 'f.'.$key;
347 } elseif (array_key_exists('s.'.$key, $arrayfields)) {
348 $newkey = 's.'.$key;
349 }
350 if ($newkey) {
351 $arrayfields[$newkey] = array(
352 'label' => $val['label'],
353 'checked' => (($visible < 0) ? '0' : '1'),
354 'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
355 'position' => $val['position'],
356 'help' => empty($val['help']) ? '' : $val['help'],
357 );
358 }
359 }
360}
361// Extra fields
362include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
363// Add hook to complete $arrayfield
364$parameters = array('arrayfields' => &$arrayfields);
365$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
366
367// For POS context, we force some fields
368if ($contextpage == 'poslist') {
369 $arrayfields["f.module_source"]['checked'] = 1;
370 $arrayfields["f.pos_source"]['checked'] = 1;
371 $arrayfields["f.date_lim_reglement"]['checked'] = 0;
372 $arrayfields["f.total_ttc"]['checked'] = 1;
373 $arrayfields["f.tms"]['checked'] = 1;
374 $arrayfields["p.ref"]['checked'] = 0;
375}
376
377$object->fields = dol_sort_array($object->fields, 'position');
378$arrayfields = dol_sort_array($arrayfields, 'position');
379
380
381// Check only if it's an internal user, external users are already filtered by $socid
382if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
383 $search_sale = $user->id;
384}
385
386// Security check
387$fieldid = (!empty($ref) ? 'ref' : 'rowid');
388if (!empty($user->socid)) {
389 $socid = $user->socid;
390}
391if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
392 $search_sale = $user->id;
393}
394
395$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
396
397
398/*
399 * Actions
400 */
401
402if (GETPOST('cancel', 'alpha')) {
403 $action = 'list';
404 $massaction = '';
405}
406if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
407 $massaction = '';
408}
409
410
411$parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
412$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
413if ($reshook < 0) {
414 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
415}
416
417
418include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
419
420// Do we click on purge search criteria ?
421if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) { // All tests are required to be compatible with all browsers
422 $search_user = '';
423 $search_sale = '';
424 $search_product_category = '';
425 $searchCategoryInvoiceList = array();
426 $search_ref = '';
427 $search_refcustomer = '';
428 $search_type = '';
429 $search_subtype = '';
430 $search_project_ref = '';
431 $search_project = '';
432 $search_company = '';
433 $search_company_alias = '';
434 $search_parent_name = '';
435 $search_montant_ht = '';
436 $search_montant_vat = '';
437 $search_montant_localtax1 = '';
438 $search_montant_localtax2 = '';
439 $search_montant_ttc = '';
440 $search_login = '';
441 $search_multicurrency_code = '';
442 $search_multicurrency_tx = '';
443 $search_multicurrency_montant_ht = '';
444 $search_multicurrency_montant_vat = '';
445 $search_multicurrency_montant_ttc = '';
446 $search_dispute_status = '';
447 $search_status = [];
448 $search_paymentmode = '';
449 $search_paymentterms = '';
450 $search_bankaccount = '';
451 $search_fk_input_reason = '';
452 $search_module_source = '';
453 $search_pos_source = '';
454 $search_town = '';
455 $search_zip = '';
456 $search_state = '';
457 $search_country = '';
458 $search_type_thirdparty = '';
459 $search_customer_code = '';
460 $search_date_startday = '';
461 $search_date_startmonth = '';
462 $search_date_startyear = '';
463 $search_date_endday = '';
464 $search_date_endmonth = '';
465 $search_date_endyear = '';
466 $search_date_start = '';
467 $search_date_end = '';
468 $search_date_valid_startday = '';
469 $search_date_valid_startmonth = '';
470 $search_date_valid_startyear = '';
471 $search_date_valid_endday = '';
472 $search_date_valid_endmonth = '';
473 $search_date_valid_endyear = '';
474 $search_date_valid_start = '';
475 $search_date_valid_end = '';
476 $search_datelimit_startday = '';
477 $search_datelimit_startmonth = '';
478 $search_datelimit_startyear = '';
479 $search_datelimit_endday = '';
480 $search_datelimit_endmonth = '';
481 $search_datelimit_endyear = '';
482 $search_datelimit_start = '';
483 $search_datelimit_end = '';
484
485 $search_datec_start = '';
486 $search_datec_end = '';
487
488 $search_datem_start = '';
489 $search_datem_end = '';
490
491 $search_fac_rec_source_title = '';
492 $search_option = '';
493 $search_import_key = '';
494 $search_categ_cus = 0;
495
496 $search_all = '';
497 $toselect = array();
498 $search_array_options = array();
499}
500
501if (empty($reshook)) {
502 $objectclass = 'Facture';
503 $objectlabel = 'Invoices';
504 $permissiontoread = $user->hasRight("facture", "lire");
505 $permissiontoadd = $user->hasRight("facture", "creer");
506 $permissiontodelete = $user->hasRight("facture", "supprimer");
507 $uploaddir = $conf->invoice->dir_output;
508 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
509}
510
511if ($action == 'makepayment_confirm' && $user->hasRight('facture', 'paiement')) {
512 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
513 $arrayofselected = is_array($toselect) ? $toselect : array();
514 if (!empty($arrayofselected)) {
515 $bankid = GETPOSTINT('bankid');
516 $paiementid = GETPOSTINT('paiementid');
517 $note_private = GETPOST('note_private', 'restricthtml');
518 $paiementdate = dol_mktime(12, 0, 0, GETPOSTINT('datepaimentmonth'), GETPOSTINT('datepaimentday'), GETPOSTINT('datepaimentyear'));
519 if (empty($paiementdate)) {
520 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
521 $error++;
522 $action = 'makepayment';
523 }
524
525 if (!$error) {
526 foreach ($arrayofselected as $toselectid) {
527 $errorpayment = 0;
528 $facture = new Facture($db);
529 $result = $facture->fetch($toselectid);
530
531 $db->begin();
532
533 if ($result < 0) {
534 setEventMessage($facture->error, 'errors');
535 $errorpayment++;
536 } else {
537 if ($facture->type != Facture::TYPE_CREDIT_NOTE && $facture->status == Facture::STATUS_VALIDATED && $facture->paye == 0) {
538 // Get both the base-currency and invoice-currency paid amount in a single query
539 $sommePaiement = $facture->getSommePaiement(-1);
540 $paiementAmount = $sommePaiement['alreadypaid'];
541
542 $totalcreditnotes = $facture->getSumCreditNotesUsed();
543 $totaldeposits = $facture->getSumDepositsUsed();
544
545 $totalallpayments = $paiementAmount + $totalcreditnotes + $totaldeposits;
546 $remaintopay = (float) price2num($facture->total_ttc - $totalallpayments);
547
548 // Remain to pay in the invoice currency (may differ from $remaintopay when multicurrency is used)
549 $multicurrency_remaintopay = (float) price2num($facture->multicurrency_total_ttc - $sommePaiement['alreadypaid_multicurrency']);
550
551 // hook to finalize the remaining amount, considering e.g. cash discount agreements
552 $parameters = array('remaintopay' => $remaintopay, 'multicurrency_remaintopay' => $multicurrency_remaintopay);
553 $reshook = $hookmanager->executeHooks('finalizeAmountOfInvoice', $parameters, $facture, $action); // Note that $action and $object may have been modified by some hooks
554 if ($reshook > 0) {
555 if (!empty($remain = (float) $hookmanager->resArray['remaintopay'])) {
556 $remaintopay = $remain;
557 }
558 if (!empty($multicurrency_remain = $hookmanager->resArray['multicurrency_remaintopay'])) {
559 $multicurrency_remaintopay = $multicurrency_remain;
560 }
561 } elseif ($reshook < 0) {
562 $error++;
563 setEventMessages($facture->ref.' '.$langs->trans("ProcessingError"), $hookmanager->errors, 'errors');
564 }
565
566 if ($remaintopay != 0) {
567 $resultBank = $facture->setBankAccount($bankid);
568 if ($resultBank < 0) {
569 setEventMessages($facture->error, null, 'errors');
570 $errorpayment++;
571 } else {
572 $paiement = new Paiement($db);
573 $paiement->datepaye = $paiementdate;
574 $paiement->amounts[$facture->id] = $remaintopay; // Array with all payments dispatching with invoice id
575 $paiement->multicurrency_amounts[$facture->id] = (float) $multicurrency_remaintopay;
576 $paiement->paiementid = $paiementid;
577 $paiement->note_private = $note_private;
578 $paiement_id = $paiement->create($user, 1, $facture->thirdparty);
579 if ($paiement_id < 0) {
580 $langs->load("errors");
581 setEventMessages($facture->ref.' '.$langs->trans($paiement->error), $paiement->errors, 'errors');
582 $errorpayment++;
583 } else {
584 $result = $paiement->addPaymentToBank($user, 'payment', '', $bankid, '', '');
585 if ($result < 0) {
586 $langs->load("errors");
587 setEventMessages($facture->ref.' '.$langs->trans($paiement->error), $paiement->errors, 'errors');
588 $errorpayment++;
589 }
590 }
591 }
592 } else {
593 setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings');
594 $errorpayment++;
595 }
596 } else {
597 setEventMessage($langs->trans('BulkPaymentNotPossibleForInvoice', $facture->ref), 'warnings');
598 $errorpayment++;
599 }
600 }
601
602 if (empty($errorpayment)) {
603 setEventMessage($langs->trans('PaymentRegisteredAndInvoiceSetToPaid', $facture->ref));
604 $db->commit();
605 } else {
606 $db->rollback();
607 }
608 }
609 }
610 }
611} elseif ($massaction == 'withdrawrequest') {
612 $langs->load("withdrawals");
613
614 if (!$user->hasRight('prelevement', 'bons', 'creer')) {
615 $error++;
616 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
617 } else {
618 //Checking error
619 $error = 0;
620
621 $arrayofselected = is_array($toselect) ? $toselect : array();
622 $listofbills = array();
623 foreach ($arrayofselected as $toselectid) {
624 $objecttmp = new Facture($db);
625 $result = $objecttmp->fetch($toselectid);
626 if ($result > 0) {
627 $totalpaid = $objecttmp->getSommePaiement();
628 $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
629 $totaldeposits = $objecttmp->getSumDepositsUsed();
630 $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
631
632 // hook to finalize the remaining amount, considering e.g. cash discount agreements
633 $parameters = array('remaintopay' => $objecttmp->resteapayer);
634 $reshook = $hookmanager->executeHooks('finalizeAmountOfInvoice', $parameters, $objecttmp, $action); // Note that $action and $object may have been modified by some hooks
635 if ($reshook > 0) {
636 if (!empty($remaintopay = $hookmanager->resArray['remaintopay'])) {
637 $objecttmp->resteapayer = $remaintopay;
638 }
639 } elseif ($reshook < 0) {
640 $error++;
641 setEventMessages($objecttmp->ref.' '.$langs->trans("ProcessingError"), $hookmanager->errors, 'errors');
642 }
643
644 if ($objecttmp->statut == Facture::STATUS_DRAFT) {
645 $error++;
646 setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
647 } elseif ($objecttmp->paye || $objecttmp->resteapayer == 0) {
648 $error++;
649 setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
650 } elseif ($objecttmp->resteapayer < 0) {
651 $error++;
652 setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
653 }
654
655 $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
656 $rsql .= " , pfd.date_traite as date_traite";
657 $rsql .= " , pfd.amount";
658 $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
659 $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
660 $rsql .= " , ".MAIN_DB_PREFIX."user as u";
661 $rsql .= " WHERE fk_facture = ".((int) $objecttmp->id);
662 $rsql .= " AND pfd.fk_user_demande = u.rowid";
663 $rsql .= " AND pfd.traite = 0";
664 $rsql .= " ORDER BY pfd.date_demande DESC";
665
666 $numprlv = 0;
667 $result_sql = $db->query($rsql);
668 if ($result_sql) {
669 $numprlv = $db->num_rows($result_sql);
670 }
671
672 if ($numprlv > 0) {
673 $error++;
674 setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
675 } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'PRE') {
676 $langs->load("errors");
677 $error++;
678 setEventMessages($objecttmp->ref.' '.$langs->trans("ErrorThisPaymentModeIsNotDirectDebit"), $objecttmp->errors, 'errors');
679 } else {
680 $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
681 }
682 }
683 }
684
685 //Massive withdraw request for request with no errors
686 if (!empty($listofbills)) {
687 $nbwithdrawrequestok = 0;
688 foreach ($listofbills as $aBill) {
689 // Note: The 2 following SQL requests are wrong but it works because we have one record into pfd for one record into pl and for into p for the same fk_facture_fourn.
690 // The table prelevement and prelevement_lignes must be removed in future and merged into prelevement_demande
691 // Step 1: Move field fk_... of llx_prelevement into llx_prelevement_lignes
692 // Step 2: Move field fk_... + status into prelevement_demande.
693 $pending = 0;
694 // Get pending requests open with no transfer receipt yet
695 $sql = "SELECT SUM(pfd.amount) as amount";
696 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
697 //if ($type == 'bank-transfer') {
698 //$sql .= " WHERE pfd.fk_facture_fourn = ".((int) $aBill->id);
699 //} else {
700 $sql .= " WHERE pfd.fk_facture = ".((int) $aBill->id);
701 //}
702 $sql .= " AND pfd.traite = 0";
703 //$sql .= " AND pfd.type = 'ban'";
704 $resql = $db->query($sql);
705 if ($resql) {
706 $obj = $db->fetch_object($resql);
707 if ($obj) {
708 $pending += (float) $obj->amount;
709 }
710 } else {
711 dol_print_error($db);
712 }
713 // Get pending request with a transfer receipt generated but not yet processed
714 $sqlPending = "SELECT SUM(pl.amount) as amount";
715 $sqlPending .= " FROM ".$db->prefix()."prelevement_lignes as pl";
716 $sqlPending .= " INNER JOIN ".$db->prefix()."prelevement as p ON p.fk_prelevement_lignes = pl.rowid";
717 //if ($type == 'bank-transfer') {
718 //$sqlPending .= " WHERE p.fk_facture_fourn = ".((int) $aBill->id);
719 //} else {
720 $sqlPending .= " WHERE p.fk_facture = ".((int) $aBill->id);
721 //}
722 $sqlPending .= " AND (pl.statut IS NULL OR pl.statut = 0)";
723 $resPending = $db->query($sqlPending);
724 if ($resPending) {
725 if ($objPending = $db->fetch_object($resPending)) {
726 $pending += (float) $objPending->amount;
727 }
728 }
729 $db->free($resPending);
730
731 $requestAmount = $aBill->resteapayer - $pending;
732
733 $db->begin();
734 $result = $aBill->demande_prelevement($user, $requestAmount, 'direct-debit', 'facture');
735 if ($requestAmount > 0) {
736 if ($result > 0) {
737 $db->commit();
738 $nbwithdrawrequestok++;
739 } else {
740 $db->rollback();
741 setEventMessages($aBill->error, $aBill->errors, 'errors');
742 }
743 } else {
744 $aBill->error = 'WithdrawRequestErrorNilAmount';
745 $aBill->errors[] = $aBill->error;
746 setEventMessages($aBill->error, $aBill->errors, 'errors');
747 }
748 }
749 if ($nbwithdrawrequestok > 0) {
750 setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
751 }
752 }
753 }
754}
755
756
757
758/*
759 * View
760 */
761
762$form = new Form($db);
763$formother = new FormOther($db);
764$formfile = new FormFile($db);
765$formmargin = new FormMargin($db);
766$facturestatic = new Facture($db);
767$accountstatic = new Account($db);
768$formcompany = new FormCompany($db);
769$companystatic = new Societe($db);
770$companyparent = new Societe($db);
771
772$company_url_list = array();
773
774if ($socid > 0) {
775 $soc = new Societe($db);
776 $soc->fetch($socid);
777 if (empty($search_company)) {
778 $search_company = $soc->name;
779 }
780} else {
781 $soc = null;
782}
783
784$title = $langs->trans('BillsCustomers').' '.(($socid > 0 && $soc !== null) ? ' - '.$soc->name : '');
785$help_url = 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes';
786
787$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
788$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
789
790// Build and execute select
791// --------------------------------------------------------------------
792$sql = 'SELECT';
793$sql .= ' f.rowid as id, f.ref, f.ref_client, f.fk_soc, f.type, f.subtype, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, ba.rowid as bid, ba.ref as bref, ba.label as blabel, ba.number as bnumber, ba.account_number as baccount_number, ba.fk_accountancy_journal as baccountancy_journal, f.total_ht, f.total_tva, f.total_ttc,';
794$sql .= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
795$sql .= ' f.fk_user_author,';
796$sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva as multicurrency_total_vat, f.multicurrency_total_ttc,';
797$sql .= ' f.datef, f.date_valid, f.date_lim_reglement as datelimite,';
798$sql .= " f.fk_input_reason,";
799$sql .= " f.module_source, f.pos_source,";
800$sql .= ' f.paye as paye, f.fk_statut as status, f.import_key, f.close_code,';
801$sql .= ' f.datec as date_creation, f.tms as date_modification, f.date_closing as date_closing,';
802$sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
803$sql .= ' f.payment_reference, f.dispute_status,';
804$sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,';
805$sql .= " s.parent as fk_parent,";
806$sql .= " s2.nom as name2,";
807$sql .= ' typent.code as typent_code,';
808$sql .= ' state.code_departement as state_code, state.nom as state_name,';
809$sql .= ' country.code as country_code,';
810$sql .= ' f.fk_fac_rec_source,';
811$sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
812$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
813// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0).
814// A Better solution to be able to sort on already paid or remain to pay is to store amount_payed in a denormalized field.
815// We disable this. It create a bug when searching with search_all and sorting on status. Also it create performance troubles.
816/*
817if (!$search_all) {
818 $sql .= ', SUM(pf.amount) as dynamount_payed, SUM(pf.multicurrency_amount) as multicurrency_dynamount_payed';
819}
820*/
821// Add fields from extrafields
822if (!empty($extrafields->attributes[$object->table_element]['label'])) {
823 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
824 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
825 }
826}
827// Add fields from hooks
828$parameters = array();
829$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
830$sql .= $hookmanager->resPrint;
831$sql = preg_replace('/,\s*$/', '', $sql);
832
833$sqlfields = $sql; // $sql fields to remove for count total
834
835$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
836$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
837$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
838$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
839$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
840$sql .= ', '.MAIN_DB_PREFIX.'facture as f';
841// Add a special index hint if we sort on datef. But only if there is not search filter set to avoid bad query plan
842if ($sortfield == "f.datef") {
843 $hasAnotherfilter = false;
844 foreach ($search_array_options as $v) {
845 if ($v !== '' && (string) $v !== '-1') {
846 $hasAnotherfilter = true;
847 break;
848 }
849 }
850 if (!$hasAnotherfilter) {
851 $sql .= $db->hintindex('idx_facture_datef');
852 }
853}
854if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
855 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
856}
857if (!empty($search_fac_rec_source_title)) {
858 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_rec as facrec ON f.fk_fac_rec_source = facrec.rowid';
859}
860$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
861$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
862$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = f.fk_account';
863// Add table from hooks
864$parameters = array();
865$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
866$sql .= $hookmanager->resPrint;
867
868$sql .= ' WHERE f.fk_soc = s.rowid';
869$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
870if ($socid > 0) {
871 $sql .= ' AND s.rowid = '.((int) $socid);
872}
873if ($userid) {
874 if ($userid == -1) {
875 $sql .= ' AND f.fk_user_author IS NULL';
876 } else {
877 $sql .= ' AND f.fk_user_author = '.((int) $userid);
878 }
879}
880if ($search_ref) {
881 $sql .= natural_search('f.ref', $search_ref);
882}
883if ($search_refcustomer) {
884 $sql .= natural_search('f.ref_client', $search_refcustomer);
885}
886if ($search_type != '' && $search_type != '-1') {
887 $sql .= " AND f.type IN (".$db->sanitize($db->escape($search_type)).")";
888}
889if ($search_subtype != '' && $search_subtype != '-1') {
890 $sql .= " AND f.subtype IN (".$db->sanitize($db->escape($search_subtype)).")";
891}
892if ($search_project_ref) {
893 $sql .= natural_search('p.ref', $search_project_ref);
894}
895if ($search_project) {
896 $sql .= natural_search('p.title', $search_project);
897}
898if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
899 $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
900} else {
901 if ($search_company) {
902 $sql .= natural_search('s.nom', $search_company);
903 }
904 if ($search_company_alias) {
905 $sql .= natural_search('s.name_alias', $search_company_alias);
906 }
907}
908if ($search_parent_name) {
909 $sql .= natural_search('s2.nom', $search_parent_name);
910}
911if ($search_customer_code) {
912 $sql .= natural_search('s.code_client', $search_customer_code);
913}
914if ($search_town) {
915 $sql .= natural_search('s.town', $search_town);
916}
917if ($search_zip) {
918 $sql .= natural_search("s.zip", $search_zip);
919}
920if ($search_state) {
921 $sql .= natural_search("state.nom", $search_state);
922}
923if (strlen(trim($search_country))) {
924 $arrayofcode = getCountriesInEEC();
925 $country_code_in_EEC = $country_code_in_EEC_without_me = '';
926 foreach ($arrayofcode as $key => $value) {
927 $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
928 if ($value != $mysoc->country_code) {
929 $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
930 }
931 }
932 if ($search_country == 'special_allnotme') {
933 $sql .= " AND country.code <> '".$db->escape($mysoc->country_code)."'";
934 } elseif ($search_country == 'special_eec') {
935 $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
936 } elseif ($search_country == 'special_eecnotme') {
937 $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
938 } elseif ($search_country == 'special_noteec') {
939 $sql .= " AND country.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
940 } else {
941 $sql .= natural_search("country.code", $search_country);
942 }
943}
944if ($search_type_thirdparty != '' && $search_type_thirdparty != '-1') {
945 $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
946}
947if ($search_montant_ht != '') {
948 $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
949}
950if ($search_montant_vat != '') {
951 $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
952}
953if ($search_montant_localtax1 != '') {
954 $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
955}
956if ($search_montant_localtax2 != '') {
957 $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
958}
959if ($search_montant_ttc != '') {
960 $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
961}
962if ($search_multicurrency_code != '') {
963 $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
964}
965if ($search_multicurrency_tx != '') {
966 $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
967}
968if ($search_multicurrency_montant_ht != '') {
969 $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
970}
971if ($search_multicurrency_montant_vat != '') {
972 $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
973}
974if ($search_multicurrency_montant_ttc != '') {
975 $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
976}
977if ($search_login) {
978 $sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login);
979}
980if ($search_dispute_status != '-1' && $search_dispute_status != '') {
981 if ($search_dispute_status == '0') {
982 $sql .= " AND (f.dispute_status IS NULL OR f.dispute_status = 0)";
983 } else {
984 $sql .= " AND f.dispute_status IN (".$db->sanitize($search_dispute_status).")";
985 }
986}
987if (is_array($search_status) && count($search_status) > 0) {
988 // 99 is not a real status but a filter for partially paid invoices
989 $search_statusArray = array_diff($search_status, ['99']);
990 $sqlstatus = [];
991 if (count($search_statusArray) > 0) {
992 $sqlstatus[] = "f.fk_statut IN (" . $db->sanitize(implode(',', array_map('intval', $search_statusArray))) . ")";
993 }
994 if (in_array('99', $search_status)) {
995 // Partially paid: validated invoice with at least one payment recorded
996 $sqlstatus[] = "(f.fk_statut = ".Facture::STATUS_VALIDATED." AND EXISTS (SELECT pf.rowid FROM ".MAIN_DB_PREFIX."paiement_facture as pf WHERE pf.fk_facture = f.rowid))";
997 }
998 $sql .= " AND (".implode(" OR ", $sqlstatus).")";
999}
1000
1001if ($search_paymentmode > 0) {
1002 $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
1003}
1004if ($search_paymentterms > 0) {
1005 $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentterms);
1006}
1007if ($search_bankaccount > 0) {
1008 $sql .= " AND ba.rowid = ".((int) $search_bankaccount);
1009}
1010if ($search_fk_input_reason > 0) {
1011 $sql .= " AND f.fk_input_reason = ".((int) $search_fk_input_reason);
1012}
1013if ($search_module_source) {
1014 $sql .= natural_search("f.module_source", $search_module_source);
1015}
1016if ($search_pos_source) {
1017 $sql .= natural_search("f.pos_source", $search_pos_source);
1018}
1019if ($search_date_start) {
1020 $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
1021}
1022if ($search_date_end) {
1023 $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
1024}
1025if ($search_date_valid_start) {
1026 $sql .= " AND f.date_valid >= '".$db->idate($search_date_valid_start)."'";
1027}
1028if ($search_date_valid_end) {
1029 $sql .= " AND f.date_valid <= '".$db->idate($search_date_valid_end)."'";
1030}
1031if ($search_datelimit_start) {
1032 $sql .= " AND f.date_lim_reglement >= '".$db->idate($search_datelimit_start)."'";
1033}
1034if ($search_datelimit_end) {
1035 $sql .= " AND f.date_lim_reglement <= '".$db->idate($search_datelimit_end)."'";
1036}
1037if ($search_note_public) {
1038 $sql .= " AND f.note_public LIKE '%".$db->escape($db->escapeforlike($search_note_public))."%'";
1039}
1040if ($search_note_private) {
1041 $sql .= " AND f.note_private LIKE '%".$db->escape($db->escapeforlike($search_note_private))."%'";
1042}
1043if ($search_datec_start) {
1044 $sql .= " AND f.datec >= '".$db->idate($search_datec_start)."'";
1045}
1046if ($search_datec_end) {
1047 $sql .= " AND f.datec <= '".$db->idate($search_datec_end)."'";
1048}
1049if ($search_datem_start) {
1050 $sql .= " AND f.tms >= '".$db->idate($search_datem_start)."'";
1051}
1052if ($search_datem_end) {
1053 $sql .= " AND f.tms <= '".$db->idate($search_datem_end)."'";
1054}
1055if ($search_option == 'late') {
1056 $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->invoice->client->warning_delay)."'";
1057}
1058/*if ($search_sale > 0) {
1059 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
1060}*/
1061if (!empty($search_fac_rec_source_title)) {
1062 $sql .= natural_search('facrec.titre', $search_fac_rec_source_title);
1063}
1064if ($search_fk_fac_rec_source) {
1065 $sql .= ' AND f.fk_fac_rec_source = ' . (int) $search_fk_fac_rec_source;
1066}
1067if ($search_import_key) {
1068 $sql .= natural_search("f.import_key", $search_import_key);
1069}
1070// Search on user
1071if ($search_user > 0) {
1072 $sql .= " AND EXISTS (";
1073 $sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople";
1074 $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec";
1075 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc";
1076 $sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element = 'facture' AND tc.source = 'internal'";
1077 $sql .= " WHERE ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user).")";
1078}
1079// Search on sale representative
1080if ($search_sale && $search_sale != '-1') {
1081 if ($search_sale == -2) {
1082 $sql .= " AND ".getSalesRepresentativeSqlFilter('f.fk_soc', 0, 1);
1083 } elseif ($search_sale > 0) {
1084 $sql .= " AND ".getSalesRepresentativeSqlFilter('f.fk_soc', (int) $search_sale);
1085 }
1086}
1087
1088// Search for tag/category ($searchCategoryInvoiceList is an array of ID)
1089if (!empty($searchCategoryInvoiceList)) {
1090 $searchCategoryInvoiceSqlList = array();
1091 $listofcategoryid = '';
1092 foreach ($searchCategoryInvoiceList as $searchCategoryInvoice) {
1093 if (intval($searchCategoryInvoice) == -2) {
1094 $searchCategoryInvoiceSqlList[] = "NOT EXISTS (SELECT ck.fk_invoice FROM ".MAIN_DB_PREFIX."categorie_invoice as ck WHERE f.rowid = ck.fk_invoice)";
1095 } elseif (intval($searchCategoryInvoice) > 0) {
1096 if ($searchCategoryInvoiceOperator == 0) {
1097 $searchCategoryInvoiceSqlList[] = " EXISTS (SELECT ck.fk_invoice FROM ".MAIN_DB_PREFIX."categorie_invoice as ck WHERE f.rowid = ck.fk_invoice AND ck.fk_categorie = ".((int) $searchCategoryInvoice).")";
1098 } else {
1099 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryInvoice);
1100 }
1101 }
1102 }
1103 if ($listofcategoryid) {
1104 $searchCategoryInvoiceSqlList[] = " EXISTS (SELECT ck.fk_invoice FROM ".MAIN_DB_PREFIX."categorie_invoice as ck WHERE f.rowid = ck.fk_invoice AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1105 }
1106 if ($searchCategoryInvoiceOperator == 1) {
1107 if (!empty($searchCategoryInvoiceSqlList)) {
1108 $sql .= " AND (".implode(' OR ', $searchCategoryInvoiceSqlList).")";
1109 }
1110 } else {
1111 if (!empty($searchCategoryInvoiceSqlList)) {
1112 $sql .= " AND (".implode(' AND ', $searchCategoryInvoiceSqlList).")";
1113 }
1114 }
1115}
1116
1117// Search for tag/category ($searchCategoryProductList is an array of ID)
1118$searchCategoryProductList = $search_product_category ? array($search_product_category) : array();
1119$searchCategoryProductOperator = 0;
1120if (!empty($searchCategoryProductList)) {
1121 $searchCategoryProductSqlList = array();
1122 $listofcategoryid = '';
1123 foreach ($searchCategoryProductList as $searchCategoryProduct) {
1124 if (intval($searchCategoryProduct) == -2) {
1125 $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture = f.rowid AND fd.fk_product = ck.fk_product)";
1126 } elseif (intval($searchCategoryProduct) > 0) {
1127 if ($searchCategoryProductOperator == 0) {
1128 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture = f.rowid AND fd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
1129 } else {
1130 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
1131 }
1132 }
1133 }
1134 if ($listofcategoryid) {
1135 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture = f.rowid AND fd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1136 }
1137 if ($searchCategoryProductOperator == 1) {
1138 if (!empty($searchCategoryProductSqlList)) {
1139 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
1140 }
1141 } else {
1142 if (!empty($searchCategoryProductSqlList)) {
1143 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
1144 }
1145 }
1146}
1147$searchCategoryCustomerList = $search_categ_cus ? array($search_categ_cus) : array();
1148$searchCategoryCustomerOperator = 0;
1149// Search for tag/category ($searchCategoryCustomerList is an array of ID)
1150if (!empty($searchCategoryCustomerList)) {
1151 $searchCategoryCustomerSqlList = array();
1152 $listofcategoryid = '';
1153 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
1154 if (intval($searchCategoryCustomer) == -2) {
1155 $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
1156 } elseif (intval($searchCategoryCustomer) > 0) {
1157 if ($searchCategoryCustomerOperator == 0) {
1158 $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategoryCustomer).")";
1159 } else {
1160 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
1161 }
1162 }
1163 }
1164 if ($listofcategoryid) {
1165 $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1166 }
1167 if ($searchCategoryCustomerOperator == 1) {
1168 if (!empty($searchCategoryCustomerSqlList)) {
1169 $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
1170 }
1171 } else {
1172 if (!empty($searchCategoryCustomerSqlList)) {
1173 $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
1174 }
1175 }
1176}
1177// Add where from extra fields
1178include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1179// Add where from hooks
1180$parameters = array();
1181$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1182$sql .= $hookmanager->resPrint;
1183
1184if ($search_all) {
1185 // Prepare the $sqltoadd for fields pd.* that need a test by doing a "or exits"
1186 $sqltoadd = '';
1187 $fieldstosearchallwithoutpd = array();
1188 $fieldstosearchallwithpd = array();
1189 foreach ($fieldstosearchall as $key => $val) {
1190 if (!preg_match('/^pd\./', $key)) {
1191 $fieldstosearchallwithoutpd[$key] = $val;
1192 } else {
1193 $fieldstosearchallwithpd[$key] = $val;
1194 }
1195 }
1196
1197 if (count($fieldstosearchallwithpd) > 0) {
1198 $sqltoadd .= " OR EXISTS (SELECT pd.rowid FROM ".MAIN_DB_PREFIX."facturedet as pd WHERE pd.fk_facture = f.rowid";
1199 $sqltoadd .= natural_search(array_keys($fieldstosearchallwithpd), '__KEYTOSEARCH__');
1200 $sqltoadd .= ')';
1201 }
1202
1203 $sql .= natural_search(array_keys($fieldstosearchallwithoutpd), $search_all, 0, 0, $sqltoadd);
1204}
1205// Add HAVING from hooks
1206$parameters = array();
1207$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1208if (empty($reshook)) {
1209 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
1210} else {
1211 $sql = $hookmanager->resPrint;
1212}
1213
1214// Count total nb of records
1215$nbtotalofrecords = '';
1216if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1217 /* The fast and low memory method to get and count full list converts the sql into a sql count */
1218 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
1219 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1220
1221 $resql = $db->query($sqlforcount);
1222 if ($resql) {
1223 $objforcount = $db->fetch_object($resql);
1224 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1225 } else {
1226 dol_print_error($db);
1227 }
1228
1229 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
1230 $page = 0;
1231 $offset = 0;
1232 }
1233 $db->free($resql);
1234}
1235
1236// Complete request and execute it with limit
1237$sql .= $db->order($sortfield, $sortorder);
1238if ($limit) {
1239 $sql .= $db->plimit($limit + 1, $offset);
1240}
1241
1242$resql = $db->query($sql);
1243if (!$resql) {
1244 dol_print_error($db);
1245 exit;
1246}
1247
1248$num = $db->num_rows($resql);
1249
1250$arrayofselected = is_array($toselect) ? $toselect : array();
1251
1252if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all) {
1253 $obj = $db->fetch_object($resql);
1254 $id = $obj->id;
1255
1256 header("Location: ".DOL_URL_ROOT.'/compta/facture/card.php?id='.$id);
1257 exit;
1258}
1259
1260// Output page
1261// --------------------------------------------------------------------
1262
1263llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist'.($contextpage == 'poslist' ? ' '.$contextpage : ''));
1264
1265
1266if ($search_fk_fac_rec_source) {
1267 $object = new FactureRec($db);
1268 $object->fetch((int) $search_fk_fac_rec_source);
1269
1270 $head = invoice_rec_prepare_head($object);
1271
1272 print dol_get_fiche_head($head, 'generated', $langs->trans('InvoicesGeneratedFromRec'), -1, $object->picto); // Add a div
1273}
1274
1275$param = '';
1276if (!empty($mode)) {
1277 $param .= '&mode='.urlencode($mode);
1278}
1279if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1280 $param .= '&contextpage='.urlencode($contextpage);
1281}
1282if ($limit > 0 && $limit != $conf->liste_limit) {
1283 $param .= '&limit='.((int) $limit);
1284}
1285if ($optioncss != '') {
1286 $param .= '&optioncss='.urlencode($optioncss);
1287}
1288if ($show_files) {
1289 $param .= '&show_files='.urlencode((string) ($show_files));
1290}
1291if ($search_all) {
1292 $param .= '&search_all='.urlencode($search_all);
1293}
1294if ($socid > 0) {
1295 $param .= '&socid='.((int) $socid);
1296}
1297if ($search_date_startday) {
1298 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
1299}
1300if ($search_date_startmonth) {
1301 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
1302}
1303if ($search_date_startyear) {
1304 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
1305}
1306if ($search_date_endday) {
1307 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
1308}
1309if ($search_date_endmonth) {
1310 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
1311}
1312if ($search_date_endyear) {
1313 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
1314}
1315if ($search_date_valid_startday) {
1316 $param .= '&search_date_valid_startday='.urlencode((string) ($search_date_valid_startday));
1317}
1318if ($search_date_valid_startmonth) {
1319 $param .= '&search_date_valid_startmonth='.urlencode((string) ($search_date_valid_startmonth));
1320}
1321if ($search_date_valid_startyear) {
1322 $param .= '&search_date_valid_startyear='.urlencode((string) ($search_date_valid_startyear));
1323}
1324if ($search_date_valid_endday) {
1325 $param .= '&search_date_valid_endday='.urlencode((string) ($search_date_valid_endday));
1326}
1327if ($search_date_valid_endmonth) {
1328 $param .= '&search_date_valid_endmonth='.urlencode((string) ($search_date_valid_endmonth));
1329}
1330if ($search_date_valid_endyear) {
1331 $param .= '&search_date_valid_endyear='.urlencode((string) ($search_date_valid_endyear));
1332}
1333if ($search_datelimit_startday) {
1334 $param .= '&search_datelimit_startday='.urlencode((string) ($search_datelimit_startday));
1335}
1336if ($search_datelimit_startmonth) {
1337 $param .= '&search_datelimit_startmonth='.urlencode((string) ($search_datelimit_startmonth));
1338}
1339if ($search_datelimit_startyear) {
1340 $param .= '&search_datelimit_startyear='.urlencode((string) ($search_datelimit_startyear));
1341}
1342if ($search_datelimit_endday) {
1343 $param .= '&search_datelimit_endday='.urlencode((string) ($search_datelimit_endday));
1344}
1345if ($search_datelimit_endmonth) {
1346 $param .= '&search_datelimit_endmonth='.urlencode((string) ($search_datelimit_endmonth));
1347}
1348if ($search_datelimit_endyear) {
1349 $param .= '&search_datelimit_endyear='.urlencode((string) ($search_datelimit_endyear));
1350}
1351if ($search_ref) {
1352 $param .= '&search_ref='.urlencode($search_ref);
1353}
1354if ($search_refcustomer) {
1355 $param .= '&search_refcustomer='.urlencode($search_refcustomer);
1356}
1357if ($search_project_ref) {
1358 $param .= '&search_project_ref='.urlencode($search_project_ref);
1359}
1360if ($search_project) {
1361 $param .= '&search_project='.urlencode($search_project);
1362}
1363if ($search_type != '') {
1364 $param .= '&search_type='.urlencode($search_type);
1365}
1366if ($search_subtype != '') {
1367 $param .= '&search_subtype='.urlencode($search_subtype);
1368}
1369if ($search_company) {
1370 $param .= '&search_company='.urlencode($search_company);
1371}
1372if ($search_company_alias) {
1373 $param .= '&search_company_alias='.urlencode($search_company_alias);
1374}
1375if ($search_parent_name != '') {
1376 $param .= '&search_parent_name='.urlencode($search_parent_name);
1377}
1378if ($search_town) {
1379 $param .= '&search_town='.urlencode($search_town);
1380}
1381if ($search_zip) {
1382 $param .= '&search_zip='.urlencode($search_zip);
1383}
1384if ($search_country) {
1385 $param .= "&search_country=".urlencode($search_country);
1386}
1387if ($search_type_thirdparty != '') {
1388 $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
1389}
1390if ($search_customer_code) {
1391 $param .= '&search_customer_code='.urlencode($search_customer_code);
1392}
1393if ($search_sale > 0) {
1394 $param .= '&search_sale='.urlencode((string) $search_sale);
1395}
1396if ($search_user > 0) {
1397 $param .= '&search_user='.urlencode((string) $search_user);
1398}
1399if ($search_login) {
1400 $param .= '&search_login='.urlencode($search_login);
1401}
1402if ($searchCategoryInvoiceOperator == 1) {
1403 $param .= "&search_category_invoice_operator=".urlencode((string) ($searchCategoryInvoiceOperator));
1404}
1405foreach ($searchCategoryInvoiceList as $searchCategoryInvoice) {
1406 $param .= "&search_category_invoice_list[]=".urlencode($searchCategoryInvoice);
1407}
1408if ($search_product_category > 0) {
1409 $param .= '&search_product_category='.urlencode((string) $search_product_category);
1410}
1411if ($search_montant_ht != '') {
1412 $param .= '&search_montant_ht='.urlencode($search_montant_ht);
1413}
1414if ($search_montant_vat != '') {
1415 $param .= '&search_montant_vat='.urlencode($search_montant_vat);
1416}
1417if ($search_montant_localtax1 != '') {
1418 $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
1419}
1420if ($search_montant_localtax2 != '') {
1421 $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
1422}
1423if ($search_montant_ttc != '') {
1424 $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
1425}
1426if ($search_multicurrency_code != '') {
1427 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1428}
1429if ($search_multicurrency_tx != '') {
1430 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1431}
1432if ($search_multicurrency_montant_ht != '') {
1433 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1434}
1435if ($search_multicurrency_montant_vat != '') {
1436 $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
1437}
1438if ($search_multicurrency_montant_ttc != '') {
1439 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1440}
1441if ($search_dispute_status != '') {
1442 $param .= '&search_dispute_status='.urlencode($search_dispute_status);
1443}
1444if (count($search_status) > 0) {
1445 foreach ($search_status as $key => $val) {
1446 $param .= '&search_status[]='.urlencode($val);
1447 }
1448}
1449if ($search_paymentmode > 0) {
1450 $param .= '&search_paymentmode='.urlencode((string) ($search_paymentmode));
1451}
1452if ($search_paymentterms > 0) {
1453 $param .= '&search_paymentterms='.urlencode((string) ($search_paymentterms));
1454}
1455if ($search_bankaccount > 0) {
1456 $param .= '&search_bankaccount='.urlencode((string) ($search_bankaccount));
1457}
1458if ($search_fk_input_reason > 0) {
1459 $param .= '&search_fk_input_reason='.urlencode((string) $search_fk_input_reason);
1460}
1461if ($search_module_source) {
1462 $param .= '&search_module_source='.urlencode($search_module_source);
1463}
1464if ($search_pos_source) {
1465 $param .= '&search_pos_source='.urlencode($search_pos_source);
1466}
1467if ($search_option) {
1468 $param .= "&search_option=".urlencode($search_option);
1469}
1470if ($search_categ_cus > 0) {
1471 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
1472}
1473if (!empty($search_fac_rec_source_title)) {
1474 $param .= '&search_fac_rec_source_title='.urlencode($search_fac_rec_source_title);
1475}
1476if ($search_fk_fac_rec_source) {
1477 $param .= '&search_fk_fac_rec_source=' . (int) $search_fk_fac_rec_source;
1478}
1479if ($search_import_key != '') {
1480 $param .= '&search_import_key='.urlencode($search_import_key);
1481}
1482
1483// Add $param from extra fields
1484include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1485// Add $param from hooks
1486$parameters = array('param' => &$param);
1487$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1488$param .= $hookmanager->resPrint;
1489
1490$arrayofmassactions = array(
1491 'validate' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
1492 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1493 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1494 'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1495);
1496
1497if (isModEnabled('category') && $user->hasRight('facture', 'creer')) {
1498 $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
1499}
1500if ($user->hasRight('facture', 'paiement')) {
1501 $arrayofmassactions['makepayment'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakePaymentAndClassifyPayed");
1502}
1503if (isModEnabled('prelevement') && $user->hasRight('prelevement', 'bons', 'creer')) {
1504 $langs->load("withdrawals");
1505 $arrayofmassactions['withdrawrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeWithdrawRequest");
1506}
1507if ($user->hasRight('facture', 'supprimer')) {
1508 if (!getDolGlobalString('INVOICE_DIABLE_MASS_DELETION_ON_DRAFT_INVOICES')) {
1509 $arrayofmassactions['predeletedraft'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Deletedraft");
1510 }
1511}
1512if ($user->hasRight("facture", "creer")) {
1513 if (!getDolGlobalInt('STOCK_CALCULATE_ON_BILL')) {
1514 $arrayofmassactions['precreatecreditnote'] = img_picto('', 'undo', 'class="pictofixedwidth"').$langs->trans("cancelByCreditNote");
1515 }
1516}
1517if (in_array($massaction, array('presend', 'predelete', 'makepayment'))) {
1518 $arrayofmassactions = array();
1519}
1520$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1521
1522
1523// Show the new button only when this page is not opened from the Extended POS
1524$newcardbutton = '';
1525if ($contextpage != 'poslist') {
1526 $url = DOL_URL_ROOT.'/compta/facture/card.php?action=create';
1527 if (!empty($object->socid)) {
1528 $url .= '&socid='.urlencode((string) $object->socid);
1529 }
1530 if (!empty($object->id)) {
1531 $url .= '&fac_rec='.urlencode((string) $object->id);
1532 }
1533 $newcardbutton = '';
1534 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
1535 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
1536 $newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/compta/facture/stats/index.php?'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'statistics' ? 2 : 1), array('morecss' => 'reposition'));
1537 $newcardbutton .= dolGetButtonTitleSeparator();
1538 $newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', $user->hasRight("facture", "creer"));
1539}
1540
1541
1542// Lines of title fields
1543$i = 0;
1544print '<form method="POST" id="searchFormList" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1545if ($optioncss != '') {
1546 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1547}
1548print '<input type="hidden" name="token" value="'.newToken().'">';
1549print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1550if (!in_array($massaction, array('makepayment'))) {
1551 print '<input type="hidden" name="action" value="list">';
1552}
1553print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1554print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1555// print '<input type="hidden" name="search_status" value="'.$search_status.'">';
1556print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1557print '<input type="hidden" name="socid" value="'.$socid.'">';
1558print '<input type="hidden" name="mode" value="'.$mode.'">';
1559
1560print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
1561
1562$topicmail = "SendBillRef";
1563$modelmail = "facture_send";
1564$objecttmp = new Facture($db);
1565$trackid = 'inv'.$object->id;
1566include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1567
1568if ($massaction == 'makepayment') {
1569 $formconfirm = '';
1570 $formquestion = array(
1571 // 'text' => $langs->trans("ConfirmClone"),
1572 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1573 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
1574 array('type' => 'date', 'name' => 'datepaiment', 'label' => $langs->trans("Date"), 'datenow' => 1),
1575 array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 0, 0, 1, 0, 1, '', 1)),
1576 array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)),
1577 array('type' => 'other', 'name' => 'note_private', 'label' => $langs->trans("Comments"), 'value' => '<textarea name="note_private" id="note_private" class="minwidth200" rows="3"></textarea>'),
1578 //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>'<input type="hidden" id="invoicesid" name="invoicesid" value="'.implode('#',GETPOST('toselect','array')).'">'),
1579 );
1580 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('MakePaymentAndClassifyPayed'), $langs->trans('EnterPaymentReceivedFromCustomer'), 'makepayment_confirm', $formquestion, 1, 0, 200, 500, 1);
1581 print $formconfirm;
1582}
1583
1584if ($search_all) {
1585 foreach ($fieldstosearchall as $key => $val) {
1586 $fieldstosearchall[$key] = $langs->trans($val);
1587 }
1588 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
1589}
1590
1591// If the user can view prospects other than his'
1592$moreforfilter = '';
1593
1594if (isModEnabled('category') && $user->hasRight('categorie', 'read')) {
1595 $formcategory = new FormCategory($db);
1596 $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_INVOICE, $searchCategoryInvoiceList, 'minwidth300', $searchCategoryInvoiceOperator ? $searchCategoryInvoiceOperator : 0);
1597}
1598if ($user->hasRight("user", "user", "lire")) {
1599 $langs->load("commercial");
1600 $moreforfilter .= '<div class="divsearchfield">';
1601 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1602 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1603 $moreforfilter .= '</div>';
1604}
1605// If the user can view other users
1606if ($user->hasRight("user", "user", "lire")) {
1607 $moreforfilter .= '<div class="divsearchfield">';
1608 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1609 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth200');
1610 $moreforfilter .= '</div>';
1611}
1612// Filter on product tags
1613if (isModEnabled('category') && $user->hasRight("categorie", "lire") && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
1614 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1615 $moreforfilter .= '<div class="divsearchfield">';
1616 $tmptitle = $langs->trans('IncludingProductWithTag');
1617 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, 0, 1);
1618 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, '', 'maxwidth300 widthcentpercentminusx', 1);
1619 $moreforfilter .= '</div>';
1620}
1621if (isModEnabled('category') && $user->hasRight("categorie", "lire")) {
1622 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1623 $moreforfilter .= '<div class="divsearchfield">';
1624 $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1625 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);
1626 $moreforfilter .= '</div>';
1627}
1628// alert on due date
1629$moreforfilter .= '<div class="divsearchfield">';
1630$moreforfilter .= '<label for="search_option">'.$langs->trans('Alert').' </label><input type="checkbox" name="search_option" id="search_option" value="late"'.($search_option == 'late' ? ' checked' : '').'>';
1631$moreforfilter .= '</div>';
1632
1633$parameters = array();
1634$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1635if (empty($reshook)) {
1636 $moreforfilter .= $hookmanager->resPrint;
1637} else {
1638 $moreforfilter = $hookmanager->resPrint;
1639}
1640
1641if (!empty($moreforfilter)) {
1642 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1643 print $moreforfilter;
1644 print '</div>';
1645}
1646
1647
1648$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1649$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
1650
1651// Show the massaction checkboxes only when this page is not opened from the Extended POS
1652if ($massactionbutton && $contextpage != 'poslist') {
1653 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1654}
1655
1656print '<div class="div-table-responsive">';
1657print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1658
1659// Fields title search
1660// --------------------------------------------------------------------
1661print '<tr class="liste_titre_filter">';
1662
1663// Action column
1664if ($conf->main_checkbox_left_column) {
1665 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
1666 $searchpicto = $form->showFilterButtons('left');
1667 print $searchpicto;
1668 print '</td>';
1669}
1670
1671if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
1672 print '<td class="liste_titre">';
1673 print '</td>';
1674}
1675// Ref
1676if (!empty($arrayfields['f.ref']['checked'])) {
1677 print '<td class="liste_titre">';
1678 print '<input class="flat maxwidth75imp" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1679 print '</td>';
1680}
1681// Ref customer
1682if (!empty($arrayfields['f.ref_client']['checked'])) {
1683 print '<td class="liste_titre">';
1684 print '<input class="flat maxwidth50imp" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
1685 print '</td>';
1686}
1687// Type
1688if (!empty($arrayfields['f.type']['checked'])) {
1689 print '<td class="liste_titre maxwidthonsmartphone">';
1690 $listtype = array(
1691 Facture::TYPE_STANDARD => $langs->trans("InvoiceStandard"),
1692 Facture::TYPE_DEPOSIT => $langs->trans("InvoiceDeposit"),
1693 Facture::TYPE_CREDIT_NOTE => $langs->trans("InvoiceAvoir"),
1694 Facture::TYPE_REPLACEMENT => $langs->trans("InvoiceReplacement"),
1695 );
1696 if (getDolGlobalString('INVOICE_USE_SITUATION')) {
1697 $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
1698 }
1699 //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
1700 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1701 print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth75');
1702 print '</td>';
1703}
1704// Invoice Subtype
1705if (!empty($arrayfields['f.subtype']['checked'])) {
1706 print '<td class="liste_titre maxwidthonsmartphone center">';
1707 print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
1708 print '</td>';
1709}
1710// Date invoice
1711if (!empty($arrayfields['f.datef']['checked'])) {
1712 print '<td class="liste_titre center">';
1713 print '<div class="nowrapfordate">';
1714 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1715 print '</div>';
1716 print '<div class="nowrapfordate">';
1717 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1718 print '</div>';
1719 print '</td>';
1720}
1721// Date valid
1722if (!empty($arrayfields['f.date_valid']['checked'])) {
1723 print '<td class="liste_titre center">';
1724 print '<div class="nowrapfordate">';
1725 print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1726 print '</div>';
1727 print '<div class="nowrapfordate">';
1728 print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1729 print '</div>';
1730 print '</td>';
1731}
1732// Date due
1733if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1734 print '<td class="liste_titre center">';
1735 print '<div class="nowrapfordate">';
1736 print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1737 print '</div>';
1738 print '<div class="nowrapfordate">';
1739 print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1740 print '</div>';
1741 print '</td>';
1742}
1743// Project ref
1744if (!empty($arrayfields['p.ref']['checked'])) {
1745 print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
1746}
1747// Project label
1748if (!empty($arrayfields['p.title']['checked'])) {
1749 print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1750}
1751// Thirdparty
1752if (!empty($arrayfields['s.nom']['checked'])) {
1753 print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company" value="'.dol_escape_htmltag((string) $search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
1754}
1755// Alias
1756if (!empty($arrayfields['s.name_alias']['checked'])) {
1757 print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
1758}
1759// Parent company
1760if (!empty($arrayfields['s2.nom']['checked'])) {
1761 print '<td class="liste_titre">';
1762 print '<input class="flat maxwidth100" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
1763 print '</td>';
1764}
1765// Customer Code
1766if (!empty($arrayfields['s.code_client']['checked'])) {
1767 print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_customer_code" value="'.dol_escape_htmltag($search_customer_code).'"></td>';
1768}
1769// Town
1770if (!empty($arrayfields['s.town']['checked'])) {
1771 print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1772}
1773// Zip
1774if (!empty($arrayfields['s.zip']['checked'])) {
1775 print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1776}
1777// State
1778if (!empty($arrayfields['state.nom']['checked'])) {
1779 print '<td class="liste_titre">';
1780 print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1781 print '</td>';
1782}
1783// Country
1784if (!empty($arrayfields['country.code_iso']['checked'])) {
1785 print '<td class="liste_titre center">';
1786 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, array(), 1);
1787 print '</td>';
1788}
1789// Company type
1790if (!empty($arrayfields['typent.code']['checked'])) {
1791 print '<td class="liste_titre maxwidthonsmartphone center">';
1792 print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC'), 'maxwidth100', 1);
1793 print '</td>';
1794}
1795// Payment mode
1796if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1797 print '<td class="liste_titre">';
1798 print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 0, 1, 'minwidth100 maxwidth100', 1);
1799 print '</td>';
1800}
1801// Payment terms
1802if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1803 print '<td class="liste_titre left">';
1804 print $form->getSelectConditionsPaiements((int) $search_paymentterms, 'search_paymentterms', -1, 1, 1, 'minwidth100 maxwidth100');
1805 print '</td>';
1806}
1807// Bank account
1808if (!empty($arrayfields['ba.label']['checked'])) {
1809 print '<td class="liste_titre">';
1810 $form->select_comptes($search_bankaccount, 'search_bankaccount', 0, '', 1, '', 0, 'maxwidth125');
1811 print '</td>';
1812}
1813// Channel
1814if (!empty($arrayfields['f.fk_input_reason']['checked'])) {
1815 print '<td class="liste_titre">';
1816 $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
1817 print '</td>';
1818}
1819// Module source
1820if (!empty($arrayfields['f.module_source']['checked'])) {
1821 print '<td class="liste_titre">';
1822 print '<input class="flat maxwidth75" type="text" name="search_module_source" value="'.dol_escape_htmltag($search_module_source).'">';
1823 print '</td>';
1824}
1825// POS Terminal
1826if (!empty($arrayfields['f.pos_source']['checked'])) {
1827 print '<td class="liste_titre">';
1828 print '<input class="flat maxwidth50" type="text" name="search_pos_source" value="'.dol_escape_htmltag($search_pos_source).'">';
1829 print '</td>';
1830}
1831if (!empty($arrayfields['f.total_ht']['checked'])) {
1832 // Amount without tax
1833 print '<td class="liste_titre right">';
1834 print '<input class="flat" type="text" size="4" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1835 print '</td>';
1836}
1837if (!empty($arrayfields['f.total_tva']['checked'])) {
1838 // Amount vat
1839 print '<td class="liste_titre right">';
1840 print '<input class="flat" type="text" size="4" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1841 print '</td>';
1842}
1843if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1844 // Localtax1
1845 print '<td class="liste_titre right">';
1846 print '<input class="flat" type="text" size="4" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
1847 print '</td>';
1848}
1849if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1850 // Localtax2
1851 print '<td class="liste_titre right">';
1852 print '<input class="flat" type="text" size="4" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
1853 print '</td>';
1854}
1855if (!empty($arrayfields['f.total_ttc']['checked'])) {
1856 // Amount inc tax
1857 print '<td class="liste_titre right">';
1858 print '<input class="flat" type="text" size="4" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1859 print '</td>';
1860}
1861if (!empty($arrayfields['u.login']['checked'])) {
1862 // Author
1863 print '<td class="liste_titre center">';
1864 print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1865 print '</td>';
1866}
1867if (!empty($arrayfields['sale_representative']['checked'])) {
1868 print '<td class="liste_titre"></td>';
1869}
1870if (!empty($arrayfields['f.retained_warranty']['checked'])) {
1871 print '<td class="liste_titre" align="right">';
1872 print '</td>';
1873}
1874if (!empty($arrayfields['dynamount_payed']['checked'])) {
1875 print '<td class="liste_titre right">';
1876 print '</td>';
1877}
1878if (!empty($arrayfields['rtp']['checked'])) {
1879 print '<td class="liste_titre">';
1880 print '</td>';
1881}
1882if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1883 // Currency
1884 print '<td class="liste_titre">';
1885 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1886 print '</td>';
1887}
1888if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1889 // Currency rate
1890 print '<td class="liste_titre">';
1891 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1892 print '</td>';
1893}
1894if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1895 // Amount
1896 print '<td class="liste_titre right">';
1897 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1898 print '</td>';
1899}
1900if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1901 // Amount
1902 print '<td class="liste_titre right">';
1903 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1904 print '</td>';
1905}
1906if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1907 // Amount
1908 print '<td class="liste_titre right">';
1909 print '<input class="flat width75" type="text" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1910 print '</td>';
1911}
1912if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1913 print '<td class="liste_titre">';
1914 print '</td>';
1915}
1916if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1917 print '<td class="liste_titre right">';
1918 print '</td>';
1919}
1920if (!empty($arrayfields['total_pa']['checked'])) {
1921 print '<td class="liste_titre right">';
1922 print '</td>';
1923}
1924if (!empty($arrayfields['total_margin']['checked'])) {
1925 print '<td class="liste_titre right">';
1926 print '</td>';
1927}
1928if (!empty($arrayfields['total_margin_rate']['checked'])) {
1929 print '<td class="liste_titre right">';
1930 print '</td>';
1931}
1932if (!empty($arrayfields['total_mark_rate']['checked'])) {
1933 print '<td class="liste_titre right">';
1934 print '</td>';
1935}
1936
1937// Extra fields
1938include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1939
1940// Fields from hook
1941$parameters = array('arrayfields' => $arrayfields);
1942$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1943print $hookmanager->resPrint;
1944// Date creation
1945if (!empty($arrayfields['f.datec']['checked'])) {
1946 print '<td class="liste_titre center">';
1947 print '<div class="nowrapfordate">';
1948 print $form->selectDate($search_datec_start ? $search_datec_start : -1, 'search_datec_start', 1, 1, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
1949 print '</div>';
1950 print '<div class="nowrapfordate">';
1951 print $form->selectDate($search_datec_end ? $search_datec_end : -1, 'search_datec_end', 1, 1, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'), 'tzuserrel');
1952 print '</div>';
1953 print '</td>';
1954}
1955// Date modification
1956if (!empty($arrayfields['f.tms']['checked'])) {
1957 print '<td class="liste_titre center">';
1958 print '<div class="nowrapfordate">';
1959 print $form->selectDate($search_datem_start ? $search_datem_start : -1, 'search_datem_start', 1, 1, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
1960 print '</div>';
1961 print '<div class="nowrapfordate">';
1962 print $form->selectDate($search_datem_end ? $search_datem_end : -1, 'search_datem_end', 1, 1, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'), 'tzuserrel');
1963 print '</div>';
1964 print '</td>';
1965}
1966// Date closing
1967if (!empty($arrayfields['f.date_closing']['checked'])) {
1968 print '<td class="liste_titre">';
1969 print '</td>';
1970}
1971if (!empty($arrayfields['f.note_public']['checked'])) {
1972 // Note public
1973 print '<td class="liste_titre">';
1974 print '<input class="flat maxwidth75" type="text" name="search_note_public" value="'.dol_escape_htmltag($search_note_public).'">';
1975 print '</td>';
1976}
1977if (!empty($arrayfields['f.note_private']['checked'])) {
1978 // Note private
1979 print '<td class="liste_titre">';
1980 print '<input class="flat maxwidth75" type="text" name="search_note_private" value="'.dol_escape_htmltag($search_note_private).'">';
1981 print '</td>';
1982}
1983if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
1984 // Template Invoice
1985 print '<td class="liste_titre maxwidthonsmartphone right">';
1986 print '<input class="flat maxwidth50imp" type="text" name="search_fac_rec_source_title" id="search_fac_rec_source_title" value="'.dol_escape_htmltag($search_fac_rec_source_title).'">';
1987 print '</td>';
1988}
1989// Import key
1990if (!empty($arrayfields['f.import_key']['checked'])) {
1991 print '<td class="liste_titre maxwidthonsmartphone center">';
1992 print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
1993 print '</td>';
1994}
1995// Dispute status
1996if (!empty($arrayfields['f.dispute_status']['checked'])) {
1997 print '<td class="liste_titre center parentonrightofpage">';
1998 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
1999 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2000 print $form->selectarray('search_dispute_status', $liststatus, $search_dispute_status, 1, 0, 0, '', 1, 0, 0, '', 'search_status width100 onrightofpage', 1);
2001 print '</td>';
2002}
2003// Status
2004if (!empty($arrayfields['f.fk_statut']['checked'])) {
2005 print '<td class="liste_titre center parentonrightofpage">';
2006 $liststatus = array(
2007 '0' => $langs->trans("BillShortStatusDraft"),
2008 '1' => $langs->trans("BillShortStatusNotPaid"),
2009 '99' => $langs->trans("BillStatusStarted"),
2010 '2' => $langs->trans("BillShortStatusPaid"),
2011 '3' => $langs->trans("BillShortStatusCanceled")
2012 );
2013 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2014 print $form->multiselectarray('search_status', $liststatus, $search_status, 0, 0, 'search_status width100 onrightofpage', 1, 0);
2015 print '</td>';
2016}
2017// Action column
2018if (!$conf->main_checkbox_left_column) {
2019 print '<td class="liste_titre center maxwidthsearch actioncolumn">';
2020 $searchpicto = $form->showFilterButtons();
2021 print $searchpicto;
2022 print '</td>';
2023} elseif ($contextpage == 'poslist') {
2024 print '<td class="liste_titre center actioncolumn"></td>';
2025}
2026print "</tr>\n";
2027
2028$totalarray = array();
2029$totalarray['nbfield'] = 0;
2030
2031// Fields title label
2032// --------------------------------------------------------------------
2033print '<tr class="liste_titre">';
2034// Action column
2035if ($conf->main_checkbox_left_column) {
2036 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
2037 $totalarray['nbfield']++;
2038}
2039if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
2040 print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
2041 $totalarray['nbfield']++;
2042}
2043if (!empty($arrayfields['f.ref']['checked'])) {
2044 print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref', '', $param, '', $sortfield, $sortorder);
2045 $totalarray['nbfield']++;
2046}
2047if (!empty($arrayfields['f.ref_client']['checked'])) {
2048 print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], 'f.ref_client', '', $param, '', $sortfield, $sortorder);
2049 $totalarray['nbfield']++;
2050}
2051if (!empty($arrayfields['f.type']['checked'])) {
2052 print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
2053 $totalarray['nbfield']++;
2054}
2055if (!empty($arrayfields['f.subtype']['checked'])) {
2056 print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder);
2057}
2058if (!empty($arrayfields['f.datef']['checked'])) {
2059 print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef', '', $param, '', $sortfield, $sortorder, 'center ');
2060 $totalarray['nbfield']++;
2061}
2062if (!empty($arrayfields['f.date_valid']['checked'])) {
2063 print_liste_field_titre($arrayfields['f.date_valid']['label'], $_SERVER['PHP_SELF'], 'f.date_valid', '', $param, '', $sortfield, $sortorder, 'center ');
2064 $totalarray['nbfield']++;
2065}
2066if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
2067 print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
2068 $totalarray['nbfield']++;
2069}
2070if (!empty($arrayfields['p.ref']['checked'])) {
2071 $langs->load("projects");
2072 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
2073 $totalarray['nbfield']++;
2074}
2075if (!empty($arrayfields['p.title']['checked'])) {
2076 print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER['PHP_SELF'], "p.title", '', $param, '', $sortfield, $sortorder);
2077 $totalarray['nbfield']++;
2078}
2079if (!empty($arrayfields['s.nom']['checked'])) {
2080 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
2081 $totalarray['nbfield']++;
2082}
2083if (!empty($arrayfields['s.name_alias']['checked'])) {
2084 // False positive @phan-suppress-next-line PhanTypeInvalidDimOffset
2085 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
2086 $totalarray['nbfield']++;
2087}
2088if (!empty($arrayfields['s2.nom']['checked'])) {
2089 print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER['PHP_SELF'], 's2.nom', '', $param, '', $sortfield, $sortorder);
2090 $totalarray['nbfield']++;
2091}
2092if (!empty($arrayfields['s.code_client']['checked'])) {
2093 print_liste_field_titre($arrayfields['s.code_client']['label'], $_SERVER['PHP_SELF'], 's.code_client', '', $param, '', $sortfield, $sortorder);
2094 $totalarray['nbfield']++;
2095}
2096if (!empty($arrayfields['s.town']['checked'])) {
2097 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
2098 $totalarray['nbfield']++;
2099}
2100if (!empty($arrayfields['s.zip']['checked'])) {
2101 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
2102 $totalarray['nbfield']++;
2103}
2104if (!empty($arrayfields['state.nom']['checked'])) {
2105 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
2106 $totalarray['nbfield']++;
2107}
2108if (!empty($arrayfields['country.code_iso']['checked'])) {
2109 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
2110 $totalarray['nbfield']++;
2111}
2112if (!empty($arrayfields['typent.code']['checked'])) {
2113 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
2114 $totalarray['nbfield']++;
2115}
2116if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
2117 print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
2118 $totalarray['nbfield']++;
2119}
2120if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
2121 print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
2122 $totalarray['nbfield']++;
2123}
2124if (!empty($arrayfields['ba.label']['checked'])) {
2125 print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
2126 $totalarray['nbfield']++;
2127}
2128if (!empty($arrayfields['f.fk_input_reason']['checked'])) {
2129 print_liste_field_titre($arrayfields['f.fk_input_reason']['label'], $_SERVER['PHP_SELF'], 'f.fk_input_reason', '', $param, '', $sortfield, $sortorder);
2130}
2131if (!empty($arrayfields['f.module_source']['checked'])) {
2132 print_liste_field_titre($arrayfields['f.module_source']['label'], $_SERVER["PHP_SELF"], "f.module_source", "", $param, "", $sortfield, $sortorder);
2133 $totalarray['nbfield']++;
2134}
2135if (!empty($arrayfields['f.pos_source']['checked'])) {
2136 print_liste_field_titre($arrayfields['f.pos_source']['label'], $_SERVER["PHP_SELF"], "f.pos_source", "", $param, "", $sortfield, $sortorder);
2137 $totalarray['nbfield']++;
2138}
2139if (!empty($arrayfields['f.total_ht']['checked'])) {
2140 print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
2141 $totalarray['nbfield']++;
2142}
2143if (!empty($arrayfields['f.total_tva']['checked'])) {
2144 print_liste_field_titre($arrayfields['f.total_tva']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
2145 $totalarray['nbfield']++;
2146}
2147if (!empty($arrayfields['f.total_localtax1']['checked'])) {
2148 print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
2149 $totalarray['nbfield']++;
2150}
2151if (!empty($arrayfields['f.total_localtax2']['checked'])) {
2152 print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
2153 $totalarray['nbfield']++;
2154}
2155if (!empty($arrayfields['f.total_ttc']['checked'])) {
2156 print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
2157 $totalarray['nbfield']++;
2158}
2159if (!empty($arrayfields['u.login']['checked'])) {
2160 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder, 'center ');
2161 $totalarray['nbfield']++;
2162}
2163if (!empty($arrayfields['sale_representative']['checked'])) {
2164 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
2165 $totalarray['nbfield']++;
2166}
2167if (!empty($arrayfields['f.retained_warranty']['checked'])) {
2168 print_liste_field_titre($arrayfields['f.retained_warranty']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2169 $totalarray['nbfield']++;
2170}
2171if (!empty($arrayfields['dynamount_payed']['checked'])) {
2172 print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2173 $totalarray['nbfield']++;
2174}
2175if (!empty($arrayfields['rtp']['checked'])) {
2176 print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2177 $totalarray['nbfield']++;
2178}
2179if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
2180 print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
2181 $totalarray['nbfield']++;
2182}
2183if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
2184 print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
2185 $totalarray['nbfield']++;
2186}
2187if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
2188 print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
2189 $totalarray['nbfield']++;
2190}
2191if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
2192 print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
2193 $totalarray['nbfield']++;
2194}
2195if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
2196 print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
2197 $totalarray['nbfield']++;
2198}
2199if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
2200 print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2201 $totalarray['nbfield']++;
2202}
2203if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
2204 print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2205 $totalarray['nbfield']++;
2206}
2207if (!empty($arrayfields['total_pa']['checked'])) {
2208 print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2209 $totalarray['nbfield']++;
2210}
2211if (!empty($arrayfields['total_margin']['checked'])) {
2212 print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2213 $totalarray['nbfield']++;
2214}
2215if (!empty($arrayfields['total_margin_rate']['checked'])) {
2216 print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2217 $totalarray['nbfield']++;
2218}
2219if (!empty($arrayfields['total_mark_rate']['checked'])) {
2220 print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
2221 $totalarray['nbfield']++;
2222}
2223// Extra fields
2224include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
2225// Hook fields
2226$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
2227$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2228print $hookmanager->resPrint;
2229if (!empty($arrayfields['f.datec']['checked'])) {
2230 print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'nowraponall center ');
2231 $totalarray['nbfield']++;
2232}
2233if (!empty($arrayfields['f.tms']['checked'])) {
2234 print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'nowraponall center ');
2235 $totalarray['nbfield']++;
2236}
2237if (!empty($arrayfields['f.date_closing']['checked'])) {
2238 print_liste_field_titre($arrayfields['f.date_closing']['label'], $_SERVER["PHP_SELF"], "f.date_closing", "", $param, '', $sortfield, $sortorder, 'nowraponall center ');
2239 $totalarray['nbfield']++;
2240}
2241if (!empty($arrayfields['f.note_public']['checked'])) {
2242 print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2243 $totalarray['nbfield']++;
2244}
2245if (!empty($arrayfields['f.note_private']['checked'])) {
2246 print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2247 $totalarray['nbfield']++;
2248}
2249if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
2250 print_liste_field_titre($arrayfields['f.fk_fac_rec_source']['label'], $_SERVER["PHP_SELF"], "facrec.titre", "", $param, '', $sortfield, $sortorder);
2251 $totalarray['nbfield']++;
2252}
2253// Import key
2254if (!empty($arrayfields['f.import_key']['checked'])) {
2255 print_liste_field_titre($arrayfields['f.import_key']['label'], $_SERVER["PHP_SELF"], "f.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
2256 $totalarray['nbfield']++;
2257}
2258// Dispute status
2259if (!empty($arrayfields['f.dispute_status']['checked'])) {
2260 print_liste_field_titre($arrayfields['f.dispute_status']['label'], $_SERVER["PHP_SELF"], "f.dispute_status,f.ref", "", $param, '', $sortfield, $sortorder, 'center ');
2261 $totalarray['nbfield']++;
2262}
2263// Status
2264if (!empty($arrayfields['f.fk_statut']['checked'])) {
2265 print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut,f.paye,f.type", "", $param, '', $sortfield, $sortorder, 'center ');
2266 $totalarray['nbfield']++;
2267}
2268// Action column
2269if (!$conf->main_checkbox_left_column) {
2270 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
2271 $totalarray['nbfield']++;
2272} elseif ($contextpage == 'poslist') {
2273 print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center actioncolumn ');
2274 $totalarray['nbfield']++;
2275}
2276
2277print "</tr>\n";
2278
2279$projectstatic = new Project($db);
2280$discount = new DiscountAbsolute($db);
2281$userstatic = new User($db);
2282
2283// Loop on record
2284// --------------------------------------------------------------------
2285if ($num > 0) {
2286 $i = 0;
2287 $savnbfield = $totalarray['nbfield'];
2288 $totalarray = array();
2289 $totalarray['nbfield'] = 0;
2290 $totalarray['val'] = array();
2291 $totalarray['val']['f.total_ht'] = 0;
2292 $totalarray['val']['f.total_tva'] = 0;
2293 $totalarray['val']['f.total_localtax1'] = 0;
2294 $totalarray['val']['f.total_localtax2'] = 0;
2295 $totalarray['val']['f.total_ttc'] = 0;
2296 $totalarray['val']['dynamount_payed'] = 0;
2297 $totalarray['val']['rtp'] = 0;
2298
2299 $typenArray = $formcompany->typent_array(1);
2300
2301 $with_margin_info = false;
2302 if (isModEnabled('margin') && (
2303 !empty($arrayfields['total_pa']['checked'])
2304 || !empty($arrayfields['total_margin']['checked'])
2305 || !empty($arrayfields['total_margin_rate']['checked'])
2306 || !empty($arrayfields['total_mark_rate']['checked'])
2307 )
2308 ) {
2309 $with_margin_info = true;
2310 }
2311 $total_ht = 0;
2312 $total_margin = 0;
2313
2314 $imaxinloop = ($limit ? min($num, $limit) : $num);
2315 while ($i < $imaxinloop) {
2316 $obj = $db->fetch_object($resql);
2317 if (empty($obj)) {
2318 break; // Should not happen
2319 }
2320
2321 $datelimit = $db->jdate($obj->datelimite);
2322
2323 $facturestatic->id = $obj->id;
2324 $facturestatic->ref = $obj->ref;
2325 $facturestatic->ref_client = $obj->ref_client; // deprecated
2326 $facturestatic->ref_customer = $obj->ref_client;
2327 $facturestatic->type = $obj->type;
2328 $facturestatic->subtype = $obj->subtype;
2329 $facturestatic->total_ht = $obj->total_ht;
2330 $facturestatic->total_tva = $obj->total_tva;
2331 $facturestatic->total_ttc = $obj->total_ttc;
2332 $facturestatic->multicurrency_code = $obj->multicurrency_code;
2333 $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
2334 $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
2335 $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
2336 $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
2337 $facturestatic->status = $obj->status;
2338 $facturestatic->close_code = $obj->close_code;
2339 $facturestatic->total_ttc = $obj->total_ttc;
2340 $facturestatic->paye = $obj->paye;
2341 $facturestatic->socid = $obj->fk_soc;
2342
2343 $facturestatic->date = $db->jdate($obj->datef);
2344 $facturestatic->date_validation = $db->jdate($obj->date_valid);
2345 $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
2346
2347 $facturestatic->note_public = $obj->note_public;
2348 $facturestatic->note_private = $obj->note_private;
2349
2350 if (getDolGlobalString('INVOICE_USE_SITUATION') && getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY')) {
2351 $facturestatic->retained_warranty = $obj->retained_warranty;
2352 $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit;
2353 $facturestatic->situation_final = $obj->situation_final;
2354 $facturestatic->situation_cycle_ref = $obj->situation_cycle_ref;
2355 $facturestatic->situation_counter = $obj->situation_counter;
2356 }
2357
2358 $facturestatic->payment_reference = $obj->payment_reference;
2359 $facturestatic->dispute_status = $obj->dispute_status;
2360
2361 $companystatic->id = $obj->socid;
2362 $companystatic->name = $obj->name;
2363 $companystatic->name_alias = $obj->alias;
2364 $companystatic->client = $obj->client;
2365 $companystatic->fournisseur = $obj->fournisseur;
2366 $companystatic->code_client = $obj->code_client;
2367 $companystatic->code_compta_client = $obj->code_compta_client;
2368 $companystatic->code_fournisseur = $obj->code_fournisseur;
2369 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2370 $companystatic->email = $obj->email;
2371 $companystatic->phone = $obj->phone;
2372 $companystatic->fax = $obj->fax;
2373 $companystatic->address = $obj->address;
2374 $companystatic->zip = $obj->zip;
2375 $companystatic->town = $obj->town;
2376 $companystatic->country_code = $obj->country_code;
2377
2378 $projectstatic->id = $obj->project_id;
2379 $projectstatic->ref = $obj->project_ref;
2380 $projectstatic->title = $obj->project_label;
2381
2382 $paiement = $facturestatic->getSommePaiement();
2383 $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
2384 $totaldeposits = $facturestatic->getSumDepositsUsed();
2385 $totalallpayments = $paiement + $totalcreditnotes + $totaldeposits;
2386 $remaintopay = $obj->total_ttc - $totalallpayments;
2387
2388 $multicurrency_paiement = $facturestatic->getSommePaiement(1);
2389 $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
2390 $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
2391
2392 $totalallpayments = $paiement + $totalcreditnotes + $totaldeposits;
2393 $remaintopay = price2num($facturestatic->total_ttc - $totalallpayments);
2394
2395 $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
2396 $multicurrency_remaintopay = (float) price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
2397
2398 if ($facturestatic->status == Facture::STATUS_CLOSED) {
2399 $remaintopay = 0;
2400 $multicurrency_remaintopay = 0;
2401 }
2402 if ($facturestatic->type == Facture::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
2403 $remaincreditnote = $discount->getAvailableDiscounts($companystatic, null, 'rc.fk_facture_source='.$facturestatic->id);
2404 $remaintopay = -$remaincreditnote;
2405 $totalallpayments = price2num($facturestatic->total_ttc - $remaintopay);
2406 $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($companystatic, null, 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
2407 $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
2408 $multicurrency_totalpay = (float) price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
2409 }
2410
2411 $facturestatic->alreadypaid = $paiement;
2412 $facturestatic->totalpaid = $paiement;
2413 $facturestatic->totalcreditnotes = $totalcreditnotes;
2414 $facturestatic->totaldeposits = $totaldeposits;
2415
2416 $marginInfo = array();
2417 if ($with_margin_info) {
2418 $facturestatic->fetch_lines();
2419 $marginInfo = $formmargin->getMarginInfosArray($facturestatic);
2420 $total_ht += $obj->total_ht;
2421 $total_margin += $marginInfo['total_margin'];
2422 }
2423
2424 $object = $facturestatic;
2425
2426 if ($mode == 'kanban') {
2427 if ($i == 0) {
2428 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
2429 print '<div class="box-flex-container kanban">';
2430 }
2431 // Output Kanban
2432 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2433 $selected = 0;
2434 if (in_array($object->id, $arrayofselected)) {
2435 $selected = 1;
2436 }
2437 }
2438
2439 $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $companystatic->getNomUrl(1, '', 12), 'userauthor' => $userstatic->getNomUrl(1), 'selected' => in_array($object->id, $arrayofselected));
2440 print $facturestatic->getKanbanView('', $arraydata);
2441 if ($i == ($imaxinloop - 1)) {
2442 print '</div>';
2443 print '</td></tr>';
2444 }
2445 } else {
2446 // Show line of result
2447 $j = 0;
2448 print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select status'.$object->status.((getDolGlobalInt('MAIN_FINISHED_LINES_OPACITY') == 1 && $obj->status > 1) ? ' opacitymedium' : '').'"';
2449 if ($contextpage == 'poslist') {
2450 print ' onclick="if (event.target.closest(\'.dropdown, .actioncolumn, a, input\')) return; parent.$(\'#poslines\').load(\'invoice.php?action=history&placeid='.$obj->id.'\', function() {parent.$.colorbox.close();';
2451 if (strpos($obj->ref, 'PROV') !== false) {
2452 //If is a draft invoice, load var to be able to add products
2453 $place = str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $obj->ref));
2454 print 'parent.place=\''.dol_escape_js($place).'\'';
2455 }
2456 print '});"';
2457 }
2458 print '>';
2459
2460 // Action column
2461 if ($conf->main_checkbox_left_column) {
2462 print '<td class="nowrap center">';
2463 if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2464 $selected = 0;
2465 if (in_array($obj->id, $arrayofselected)) {
2466 $selected = 1;
2467 }
2468 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
2469 }
2470 print '</td>';
2471 if (!$i) {
2472 $totalarray['nbfield']++;
2473 }
2474 }
2475
2476 // No
2477 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER_IN_LIST')) {
2478 print '<td>'.(($offset * $limit) + $i).'</td>';
2479 if (!$i) {
2480 $totalarray['nbfield']++;
2481 }
2482 }
2483
2484 // Ref
2485 if (!empty($arrayfields['f.ref']['checked'])) {
2486 print '<td class="nowraponall">';
2487
2488 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
2489
2490 print '<td class="nobordernopadding nowraponall">';
2491 if ($contextpage == 'poslist') {
2492 print dolPrintHTML($obj->ref);
2493 } else {
2494 print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1);
2495 }
2496
2497 $filename = dol_sanitizeFileName($obj->ref);
2498 $filepath = $conf->invoice->multidir_output[$obj->entity] ?? $conf->invoice->dir_output;
2499 $filedir = $filepath.'/'.$filename;
2500
2501 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->id;
2502 print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
2503 print '</td>';
2504 print '</tr>';
2505 print '</table>';
2506
2507 print "</td>\n";
2508 if (!$i) {
2509 $totalarray['nbfield']++;
2510 }
2511 }
2512
2513 // Customer ref
2514 if (!empty($arrayfields['f.ref_client']['checked'])) {
2515 $tdcss = (getDolGlobalInt('MAIN_SHOW_GLOBAL_REF_CUSTOMER_SUPPLIER') ? 'class="minwidth400 maxwidth400"' : 'class="nowrap tdoverflowmax200"');
2516 print '<td title="'.dolPrintHTMLForAttribute($obj->ref_client).'" '.$tdcss.'>';
2517 print '<span class="doltext opacitymedium">';
2518 print dolPrintHTML($obj->ref_client);
2519 print '</span>';
2520 print '</td>';
2521 if (!$i) {
2522 $totalarray['nbfield']++;
2523 }
2524 }
2525
2526 // Type
2527 if (!empty($arrayfields['f.type']['checked'])) {
2528 print '<td class="nowraponall tdoverflowmax100" title="'.$facturestatic->getLibType().'">';
2529 print $facturestatic->getLibType(2);
2530 print "</td>";
2531 if (!$i) {
2532 $totalarray['nbfield']++;
2533 }
2534 }
2535
2536 // Invoice Subtype
2537 if (!empty($arrayfields['f.subtype']['checked'])) {
2538 $labeltoshow = '';
2539 if ($facturestatic->subtype > 0) {
2540 $labeltoshow = $facturestatic->getSubtypeLabel('facture');
2541 }
2542 print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
2543 print $labeltoshow;
2544 print "</td>";
2545 if (!$i) {
2546 $totalarray['nbfield']++;
2547 }
2548 }
2549
2550 // Date
2551 if (!empty($arrayfields['f.datef']['checked'])) {
2552 print '<td class="nowraponall center">';
2553 print dol_print_date($db->jdate($obj->datef), 'day');
2554 print '</td>';
2555 if (!$i) {
2556 $totalarray['nbfield']++;
2557 }
2558 }
2559
2560 // Date
2561 if (!empty($arrayfields['f.date_valid']['checked'])) {
2562 print '<td class="nowraponall center">';
2563 print dol_print_date($db->jdate($obj->date_valid), 'day');
2564 print '</td>';
2565 if (!$i) {
2566 $totalarray['nbfield']++;
2567 }
2568 }
2569
2570 // Date limit
2571 if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
2572 print '<td class="nowraponall center">'.dol_print_date($datelimit, 'day');
2573 if ($facturestatic->hasDelay()) {
2574 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
2575 }
2576 print '</td>';
2577 if (!$i) {
2578 $totalarray['nbfield']++;
2579 }
2580 }
2581
2582 // Project ref
2583 if (!empty($arrayfields['p.ref']['checked'])) {
2584 print '<td class="nocellnopadd nowraponall">';
2585 if ($obj->project_id > 0) {
2586 print $projectstatic->getNomUrl(1);
2587 }
2588 print '</td>';
2589 if (!$i) {
2590 $totalarray['nbfield']++;
2591 }
2592 }
2593
2594 // Project label
2595 if (!empty($arrayfields['p.title']['checked'])) {
2596 print '<td class="nowraponall">';
2597 if ($obj->project_id > 0) {
2598 print dol_escape_htmltag($projectstatic->title);
2599 }
2600 print '</td>';
2601 if (!$i) {
2602 $totalarray['nbfield']++;
2603 }
2604 }
2605
2606 // Third party
2607 if (!empty($arrayfields['s.nom']['checked'])) {
2608 print '<td class="tdoverflowmax150">';
2609 if ($contextpage == 'poslist') {
2610 print dol_escape_htmltag($companystatic->name);
2611 } else {
2612 print $companystatic->getNomUrl(1, 'customer', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2613 }
2614 print '</td>';
2615 if (!$i) {
2616 $totalarray['nbfield']++;
2617 }
2618 }
2619 // Alias name
2620 if (!empty($arrayfields['s.name_alias']['checked'])) {
2621 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->name_alias).'">';
2622 print dol_escape_htmltag($companystatic->name_alias);
2623 print '</td>';
2624 if (!$i) {
2625 $totalarray['nbfield']++;
2626 }
2627 }
2628 // Parent company
2629 if (!empty($arrayfields['s2.nom']['checked'])) {
2630 print '<td class="tdoverflowmax200">';
2631 if ($obj->fk_parent > 0) {
2632 if (!isset($company_url_list[$obj->fk_parent])) {
2633 $companyparent = new Societe($db);
2634 $res = $companyparent->fetch($obj->fk_parent);
2635 if ($res > 0) {
2636 $company_url_list[$obj->fk_parent] = $companyparent->getNomUrl(1);
2637 }
2638 }
2639 if (isset($company_url_list[$obj->fk_parent])) {
2640 print $company_url_list[$obj->fk_parent];
2641 }
2642 }
2643 print "</td>";
2644 if (!$i) {
2645 $totalarray['nbfield']++;
2646 }
2647 }
2648 // Customer Code
2649 if (!empty($arrayfields['s.code_client']['checked'])) {
2650 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->code_client).'">';
2651 print dol_escape_htmltag($companystatic->code_client);
2652 print '</td>';
2653 if (!$i) {
2654 $totalarray['nbfield']++;
2655 }
2656 }
2657 // Town
2658 if (!empty($arrayfields['s.town']['checked'])) {
2659 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
2660 print dolPrintLabel($obj->town);
2661 print '</td>';
2662 if (!$i) {
2663 $totalarray['nbfield']++;
2664 }
2665 }
2666 // Zip
2667 if (!empty($arrayfields['s.zip']['checked'])) {
2668 print '<td class="nowraponall">';
2669 print dolPrintLabel($obj->zip);
2670 print '</td>';
2671 if (!$i) {
2672 $totalarray['nbfield']++;
2673 }
2674 }
2675 // State
2676 if (!empty($arrayfields['state.nom']['checked'])) {
2677 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">'.dol_escape_htmltag($obj->state_name)."</td>\n";
2678 if (!$i) {
2679 $totalarray['nbfield']++;
2680 }
2681 }
2682 // Country
2683 if (!empty($arrayfields['country.code_iso']['checked'])) {
2684 $tmparray = getCountry($obj->fk_pays, 'all');
2685 print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($tmparray['label']).'">';
2686 print dolPrintLabel($tmparray['label']);
2687 print '</td>';
2688 if (!$i) {
2689 $totalarray['nbfield']++;
2690 }
2691 }
2692 // Type ent
2693 if (!empty($arrayfields['typent.code']['checked'])) {
2694 if (!is_array($typenArray) || count($typenArray) == 0) {
2695 $typenArray = $formcompany->typent_array(1);
2696 }
2697 print '<td class="center tdoverflowmax100" title="'.dolPrintHTMLForAttribute($typenArray[$obj->typent_code]).'">';
2698 if (!empty($obj->typent_code)) {
2699 print $typenArray[$obj->typent_code];
2700 }
2701 print '</td>';
2702 if (!$i) {
2703 $totalarray['nbfield']++;
2704 }
2705 }
2706 // Staff
2707 if (!empty($arrayfields['staff.code']['checked'])) {
2708 if (!is_array($conf->cache['staff']) || count($conf->cache['staff']) == 0) {
2709 $conf->cache['staff'] = $formcompany->effectif_array(1);
2710 }
2711 print '<td class="center tdoverflowmax100" title="'.dolPrintHTML($conf->cache['staff'][$obj->staff_code]).'">';
2712 print $conf->cache['staff'][$obj->staff_code];
2713 print '</td>';
2714 if (!$i) {
2715 $totalarray['nbfield']++;
2716 }
2717 }
2718
2719 // Payment mode
2720 if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
2721 $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
2722 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
2723 print $s;
2724 print '</td>';
2725 if (!$i) {
2726 $totalarray['nbfield']++;
2727 }
2728 }
2729
2730 // Payment terms
2731 if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
2732 $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', -1, -1, 1);
2733 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
2734 print $s;
2735 print '</td>';
2736 if (!$i) {
2737 $totalarray['nbfield']++;
2738 }
2739 }
2740
2741 // Bank account
2742 if (!empty($arrayfields['ba.label']['checked'])) {
2743 print '<td>';
2744 if (!empty($obj->bid)) {
2745 $accountstatic->id = $obj->bid;
2746 $accountstatic->ref = $obj->bref;
2747 $accountstatic->label = $obj->blabel;
2748 $accountstatic->number = $obj->bnumber;
2749 $accountstatic->account_number = $obj->baccount_number;
2750 $accountstatic->accountancy_journal = $obj->baccountancy_journal;
2751 print $accountstatic->getNomUrl(1);
2752 }
2753 print '</td>';
2754 if (!$i) {
2755 $totalarray['nbfield']++;
2756 }
2757 }
2758
2759 // Input channel
2760 if (!empty($arrayfields['f.fk_input_reason']['checked'])) {
2761 print '<td>';
2762 $form->formInputReason($_SERVER['PHP_SELF'], (string) $obj->fk_input_reason, 'none');
2763 print '</td>';
2764 if (!$i) {
2765 $totalarray['nbfield']++;
2766 }
2767 }
2768
2769 // Module Source
2770 if (!empty($arrayfields['f.module_source']['checked'])) {
2771 print '<td>';
2772 print dol_escape_htmltag($obj->module_source);
2773 print '</td>';
2774 if (!$i) {
2775 $totalarray['nbfield']++;
2776 }
2777 }
2778 // POS Terminal
2779 if (!empty($arrayfields['f.pos_source']['checked'])) {
2780 print '<td>';
2781 print dol_escape_htmltag($obj->pos_source);
2782 print '</td>';
2783 if (!$i) {
2784 $totalarray['nbfield']++;
2785 }
2786 }
2787
2788 // Amount HT
2789 if (!empty($arrayfields['f.total_ht']['checked'])) {
2790 print '<td class="right nowraponall"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
2791 if (!$i) {
2792 $totalarray['nbfield']++;
2793 }
2794 if (!$i) {
2795 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
2796 }
2797 $totalarray['val']['f.total_ht'] += $obj->total_ht;
2798 }
2799 // Amount VAT
2800 if (!empty($arrayfields['f.total_tva']['checked'])) {
2801 print '<td class="right nowraponall amount">'.price($obj->total_tva)."</td>\n";
2802 if (!$i) {
2803 $totalarray['nbfield']++;
2804 }
2805 if (!$i) {
2806 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_tva';
2807 }
2808 $totalarray['val']['f.total_tva'] += $obj->total_tva;
2809 }
2810 // Amount LocalTax1
2811 if (!empty($arrayfields['f.total_localtax1']['checked'])) {
2812 print '<td class="right nowraponall amount">'.price($obj->total_localtax1)."</td>\n";
2813 if (!$i) {
2814 $totalarray['nbfield']++;
2815 }
2816 if (!$i) {
2817 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
2818 }
2819 $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
2820 }
2821 // Amount LocalTax2
2822 if (!empty($arrayfields['f.total_localtax2']['checked'])) {
2823 print '<td class="right nowraponall amount">'.price($obj->total_localtax2)."</td>\n";
2824 if (!$i) {
2825 $totalarray['nbfield']++;
2826 }
2827 if (!$i) {
2828 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
2829 }
2830 $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
2831 }
2832 // Amount TTC
2833 if (!empty($arrayfields['f.total_ttc']['checked'])) {
2834 print '<td class="right nowraponall amount">'.price($obj->total_ttc)."</td>\n";
2835 if (!$i) {
2836 $totalarray['nbfield']++;
2837 }
2838 if (!$i) {
2839 $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
2840 }
2841 $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
2842 }
2843
2844 $userstatic->id = $obj->fk_user_author;
2845 $userstatic->login = $obj->login;
2846 $userstatic->lastname = $obj->lastname;
2847 $userstatic->firstname = $obj->firstname;
2848 $userstatic->email = $obj->user_email;
2849 $userstatic->status = $obj->user_statut;
2850 $userstatic->entity = $obj->entity;
2851 $userstatic->photo = $obj->photo;
2852 $userstatic->office_phone = $obj->office_phone;
2853 $userstatic->office_fax = $obj->office_fax;
2854 $userstatic->user_mobile = $obj->user_mobile;
2855 $userstatic->job = $obj->job;
2856 $userstatic->gender = $obj->gender;
2857
2858 // Author
2859 if (!empty($arrayfields['u.login']['checked'])) {
2860 print '<td class="tdoverflowmax100">';
2861 if ($userstatic->id) {
2862 print $userstatic->getNomUrl(-1);
2863 } else {
2864 print '&nbsp;';
2865 }
2866 print "</td>\n";
2867 if (!$i) {
2868 $totalarray['nbfield']++;
2869 }
2870 }
2871
2872 if (!empty($arrayfields['sale_representative']['checked'])) {
2873 // Sales representatives
2874 print '<td>';
2875 if ($obj->socid > 0) {
2876 $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
2877 if ($listsalesrepresentatives < 0) {
2878 dol_print_error($db);
2879 }
2880 $nbofsalesrepresentative = count($listsalesrepresentatives);
2881 if ($nbofsalesrepresentative > 6) {
2882 // We print only number
2883 print $nbofsalesrepresentative;
2884 } elseif ($nbofsalesrepresentative > 0) {
2885 $j = 0;
2886 foreach ($listsalesrepresentatives as $val) {
2887 $userstatic->id = $val['id'];
2888 $userstatic->lastname = $val['lastname'];
2889 $userstatic->firstname = $val['firstname'];
2890 $userstatic->email = $val['email'];
2891 $userstatic->status = $val['statut'];
2892 $userstatic->entity = $val['entity'];
2893 $userstatic->photo = $val['photo'];
2894 $userstatic->login = $val['login'];
2895 $userstatic->office_phone = $val['office_phone'];
2896 $userstatic->office_fax = $val['office_fax'];
2897 $userstatic->user_mobile = $val['user_mobile'];
2898 $userstatic->job = $val['job'];
2899 $userstatic->gender = $val['gender'];
2900 //print '<div class="float">':
2901 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2902 $j++;
2903 if ($j < $nbofsalesrepresentative) {
2904 print ' ';
2905 }
2906 //print '</div>';
2907 }
2908 }
2909 //else print $langs->trans("NoSalesRepresentativeAffected");
2910 }
2911 print '</td>';
2912 if (!$i) {
2913 $totalarray['nbfield']++;
2914 }
2915 }
2916
2917 if (!empty($arrayfields['f.retained_warranty']['checked'])) {
2918 print '<td align="right">'.(!empty($obj->retained_warranty) ? price($obj->retained_warranty).'%' : '&nbsp;').'</td>';
2919 if (!$i) {
2920 $totalarray['nbfield']++;
2921 }
2922 }
2923
2924 if (!empty($arrayfields['dynamount_payed']['checked'])) {
2925 print '<td class="right nowraponall amount">'.(!empty($totalallpayments) ? price($totalallpayments, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
2926 if (!$i) {
2927 $totalarray['nbfield']++;
2928 }
2929 if (!$i) {
2930 $totalarray['pos'][$totalarray['nbfield']] = 'dynamount_payed';
2931 }
2932 $totalarray['val']['dynamount_payed'] += $totalallpayments;
2933 }
2934
2935 // Pending amount
2936 if (!empty($arrayfields['rtp']['checked'])) {
2937 print '<td class="right nowraponall amount">';
2938 print(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;');
2939 print '</td>'; // TODO Use a denormalized field
2940 if (!$i) {
2941 $totalarray['nbfield']++;
2942 }
2943 if (!$i) {
2944 $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
2945 }
2946 $totalarray['val']['rtp'] += $remaintopay;
2947 }
2948
2949
2950 // Currency
2951 if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
2952 if (!getDolGlobalString('MAIN_SHOW_ONLY_CODE_MULTICURRENCY') && !empty($obj->multicurrency_code)) {
2953 $title = $obj->multicurrency_code.' - '.$langs->transnoentitiesnoconv('Currency'.$obj->multicurrency_code);
2954 $label = $langs->transnoentitiesnoconv('Currency'.$obj->multicurrency_code);
2955 } else {
2956 $title = $obj->multicurrency_code;
2957 $label = $obj->multicurrency_code;
2958 }
2959 print '<td class="nowraponall tdoverflowmax125" title="'.dolPrintHTMLForAttribute($title).'">';
2960 print dolPrintHTML($label);
2961 print "</td>\n";
2962 if (!$i) {
2963 $totalarray['nbfield']++;
2964 }
2965 }
2966
2967 // Currency rate
2968 if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
2969 print '<td class="nowraponall">';
2970 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->id, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
2971 print "</td>\n";
2972 if (!$i) {
2973 $totalarray['nbfield']++;
2974 }
2975 }
2976 $currencykey = !empty($obj->multicurrency_code) ? $obj->multicurrency_code : $conf->currency;
2977 // Amount HT
2978 if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
2979 print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_ht)."</td>\n";
2980 if (!$i) {
2981 $totalarray['nbfield']++;
2982 $totalarray['pospercurrency'][$totalarray['nbfield']] = 'f.multicurrency_total_ht';
2983 }
2984 $totalarray['valpercurrency'][$currencykey]['f.multicurrency_total_ht'] = ($totalarray['valpercurrency'][$currencykey]['f.multicurrency_total_ht'] ?? 0) + $obj->multicurrency_total_ht;
2985 }
2986 // Amount VAT
2987 if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
2988 print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_vat)."</td>\n";
2989 if (!$i) {
2990 $totalarray['nbfield']++;
2991 $totalarray['pospercurrency'][$totalarray['nbfield']] = 'f.multicurrency_total_vat';
2992 }
2993 $totalarray['valpercurrency'][$currencykey]['f.multicurrency_total_vat'] = ($totalarray['valpercurrency'][$currencykey]['f.multicurrency_total_vat'] ?? 0) + $obj->multicurrency_total_vat;
2994 }
2995 // Amount TTC
2996 if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
2997 print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_ttc)."</td>\n";
2998 if (!$i) {
2999 $totalarray['nbfield']++;
3000 $totalarray['pospercurrency'][$totalarray['nbfield']] = 'f.multicurrency_total_ttc';
3001 }
3002 $totalarray['valpercurrency'][$currencykey]['f.multicurrency_total_ttc'] = ($totalarray['valpercurrency'][$currencykey]['f.multicurrency_total_ttc'] ?? 0) + $obj->multicurrency_total_ttc;
3003 }
3004 // Dyn amount
3005 if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
3006 print '<td class="right nowraponall amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
3007 if (!$i) {
3008 $totalarray['nbfield']++;
3009 }
3010 }
3011
3012 // Pending amount
3013 if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
3014 print '<td class="right nowraponall amount">';
3015 print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '&nbsp;');
3016 print '</td>'; // TODO Use a denormalized field ?
3017 if (!$i) {
3018 $totalarray['nbfield']++;
3019 }
3020 }
3021
3022 // Total buying or cost price
3023 if (!empty($arrayfields['total_pa']['checked'])) {
3024 print '<td class="right nowrap">'.price($marginInfo['pa_total'], 0, $langs, 1, -1, 'MT').'</td>';
3025 if (!$i) {
3026 $totalarray['nbfield']++;
3027 $totalarray['pos'][$totalarray['nbfield']] = 'total_pa';
3028 }
3029 if (empty($totalarray['val']['total_pa'])) {
3030 $totalarray['val']['total_pa'] = 0;
3031 }
3032 $totalarray['val']['total_pa'] += $marginInfo['pa_total'];
3033 }
3034 // Total margin
3035 if (!empty($arrayfields['total_margin']['checked'])) {
3036 print '<td class="right nowrap">'.price($marginInfo['total_margin'], 0, $langs, 1, -1, 'MT').'</td>';
3037 if (!$i) {
3038 $totalarray['nbfield']++;
3039 $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
3040 }
3041 if (empty($totalarray['val']['total_margin'])) {
3042 $totalarray['val']['total_margin'] = 0;
3043 }
3044 $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
3045 }
3046 // Total margin rate
3047 if (!empty($arrayfields['total_margin_rate']['checked'])) {
3048 print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], 0, '', 0, 0, 2).'%').'</td>';
3049 if (!$i) {
3050 $totalarray['nbfield']++;
3051 }
3052 }
3053 // Total mark rate
3054 if (!empty($arrayfields['total_mark_rate']['checked'])) {
3055 print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], 0, '', 0, 0, 2).'%').'</td>';
3056 if (!$i) {
3057 $totalarray['nbfield']++;
3058 $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
3059 }
3060 if ($i >= $imaxinloop - 1) {
3061 if (!empty($total_ht)) {
3062 $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
3063 } else {
3064 $totalarray['val']['total_mark_rate'] = '';
3065 }
3066 }
3067 }
3068
3069 // Extra fields
3070 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
3071 // Fields from hook
3072 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
3073 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3074 print $hookmanager->resPrint;
3075 // Date creation
3076 if (!empty($arrayfields['f.datec']['checked'])) {
3077 print '<td class="nowraponall center">';
3078 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuserrel');
3079 print '</td>';
3080 if (!$i) {
3081 $totalarray['nbfield']++;
3082 }
3083 }
3084 // Date modification
3085 if (!empty($arrayfields['f.tms']['checked'])) {
3086 print '<td class="nowraponall center">';
3087 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuserrel');
3088 print '</td>';
3089 if (!$i) {
3090 $totalarray['nbfield']++;
3091 }
3092 }
3093 // Date closing
3094 if (!empty($arrayfields['f.date_closing']['checked'])) {
3095 print '<td class="nowraponall center">';
3096 print dol_print_date($db->jdate($obj->date_closing), 'dayhour', 'tzuserrel');
3097 print '</td>';
3098 if (!$i) {
3099 $totalarray['nbfield']++;
3100 }
3101 }
3102 // Note public
3103 if (!empty($arrayfields['f.note_public']['checked'])) {
3104 print '<td class="sensiblehtmlcontent center">';
3105 print '<div class="small lineheightsmall twolinesmax-normallineheight">'.dolPrintHTML(dolGetFirstLineOfText($obj->note_public, 5)).'</div>';
3106 print '</td>';
3107 if (!$i) {
3108 $totalarray['nbfield']++;
3109 }
3110 }
3111 // Note private
3112 if (!empty($arrayfields['f.note_private']['checked'])) {
3113 print '<td class="sensiblehtmlcontent center">';
3114 print '<div class="small lineheightsmall twolinesmax-normallineheight">'.dolPrintHTML(dolGetFirstLineOfText($obj->note_private, 5)).'</div>';
3115 print '</td>';
3116 if (!$i) {
3117 $totalarray['nbfield']++;
3118 }
3119 }
3120 // Template Invoice
3121 if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
3122 print '<td class="center">';
3123 if (!empty($obj->fk_fac_rec_source)) {
3124 $facrec = new FactureRec($db);
3125 $result = $facrec->fetch($obj->fk_fac_rec_source);
3126 if ($result < 0) {
3127 setEventMessages($facrec->error, $facrec->errors, 'errors');
3128 } else {
3129 print $facrec->getNomUrl();
3130 }
3131 }
3132 print '</td>';
3133 if (!$i) {
3134 $totalarray['nbfield']++;
3135 }
3136 }
3137
3138 // Import key
3139 if (!empty($arrayfields['f.import_key']['checked'])) {
3140 print '<td class="nowrap center">'.dol_escape_htmltag($obj->import_key).'</td>';
3141 if (!$i) {
3142 $totalarray['nbfield']++;
3143 }
3144 }
3145
3146 // Dispute status
3147 if (!empty($arrayfields['f.dispute_status']['checked'])) {
3148 print '<td class="nowrap center">';
3149 if ($facturestatic->dispute_status) {
3150 $liststatus = Facture::ARRAY_OF_DISPUTE_STATUS;
3151 print $langs->trans($liststatus[$facturestatic->dispute_status]['label']);
3152 }
3153 print "</td>";
3154 if (!$i) {
3155 $totalarray['nbfield']++;
3156 }
3157 }
3158
3159 // Status
3160 if (!empty($arrayfields['f.fk_statut']['checked'])) {
3161 print '<td class="nowrap center">';
3162 print $facturestatic->getLibStatut(5, $totalallpayments);
3163 print "</td>";
3164 if (!$i) {
3165 $totalarray['nbfield']++;
3166 }
3167 }
3168
3169 // Action column (Show the massaction button only when this page is not opened from the Extended POS)
3170
3171 if (!$conf->main_checkbox_left_column) {
3172 print '<td class="nowrap center">';
3173 if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
3174 $selected = 0;
3175 if (in_array($obj->id, $arrayofselected)) {
3176 $selected = 1;
3177 }
3178 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
3179 }
3180 print '</td>';
3181 if (!$i) {
3182 $totalarray['nbfield']++;
3183 }
3184 } elseif ($contextpage == 'poslist') {
3185 print '<td class="nowrap center actioncolumn">';
3186 if ($obj->module_source == 'takepos' && in_array($obj->status, array(Facture::STATUS_VALIDATED, Facture::STATUS_CLOSED)) && $obj->type != Facture::TYPE_CREDIT_NOTE && $user->hasRight('takepos', 'run')) {
3187 print '<a class="valignmiddle" href="#" onclick="event.stopPropagation(); parent.CloneTicket('.((int) $obj->id).'); parent.$.colorbox.close(); return false;" title="'.dol_escape_htmltag($langs->trans('CloneTicket')).'">'.img_picto($langs->trans('CloneTicket'), 'clone').'</a>';
3188 }
3189 print '</td>';
3190 if (!$i) {
3191 $totalarray['nbfield']++;
3192 }
3193 }
3194
3195 print "</tr>\n";
3196 }
3197
3198 $i++;
3199 }
3200
3201 // Use correct digits number for totals
3202 $totalarray['val']['total_pa'] = (isset($totalarray['val']['total_pa']) ? price2num($totalarray['val']['total_pa'], 'MT') : null);
3203 $totalarray['val']['total_margin'] = (isset($totalarray['val']['total_margin']) ? price2num($totalarray['val']['total_margin'], 'MT') : null);
3204
3205 // Show total line
3206 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
3207}
3208
3209// If no record found
3210if ($num == 0) {
3211 $colspan = 1;
3212 foreach ($arrayfields as $key => $val) {
3213 if (!empty($val['checked'])) {
3214 $colspan++;
3215 }
3216 }
3217 if ($contextpage == 'poslist' && $conf->main_checkbox_left_column) {
3218 $colspan++;
3219 }
3220 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
3221}
3222
3223$db->free($resql);
3224
3225$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
3226$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3227print $hookmanager->resPrint;
3228
3229print '</table>'."\n";
3230print '</div>'."\n";
3231
3232print '</form>'."\n";
3233
3234// Show the file area only when this page is not opened from the Extended POS
3235if ($contextpage != 'poslist') {
3236 $hidegeneratedfilelistifempty = 1;
3237 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
3238 $hidegeneratedfilelistifempty = 0;
3239 }
3240
3241 // Show list of available documents
3242 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
3243 $urlsource .= str_replace('&amp;', '&', $param);
3244
3245 $filedir = $diroutputmassaction;
3246 $genallowed = $user->hasRight("facture", "lire");
3247 $delallowed = $user->hasRight("facture", "creer");
3248 $title = '';
3249
3250 print $formfile->showdocuments('massfilesarea_invoices', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
3251}
3252
3253// End of page
3254llxFooter();
3255$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 bank accounts.
Class to manage absolute discounts.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage forms for categories.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage "other" html components Only common components are here.
Class to help generate other html components Only common components are here.
Class to manage payments of customer invoices.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
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...
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object information.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.