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