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