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