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