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