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