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