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