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