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