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