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 
597 $sqlfields = $sql;
598 
599 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
600 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
601 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
602 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
603 if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
604  $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
605 }
606 
607 $sql .= ', '.MAIN_DB_PREFIX.'facture as f';
608 if ($sortfield == "f.datef") {
609  $sql .= $db->hintindex('idx_facture_datef');
610 }
611 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
612  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
613 }
614 
615 // We disable this. It create a bug when searching with sall and sorting on status. Also it create performance troubles.
616 /*
617 if (!$sall) {
618  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
619 }
620 */
621 if ($sall || $search_product_category > 0) {
622  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
623 }
624 if ($search_product_category > 0) {
625  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
626 }
627 
628 if (!empty($search_fac_rec_source_title)) {
629  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_rec as facrec ON f.fk_fac_rec_source=facrec.rowid';
630 }
631 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
632 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
633 // We'll need this table joined to the select in order to filter by sale
634 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
635  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
636 }
637 if ($search_user > 0) {
638  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
639  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
640 }
641 // Add table from hooks
642 $parameters = array();
643 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
644 $sql .= $hookmanager->resPrint;
645 
646 $sql .= ' WHERE f.fk_soc = s.rowid';
647 $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
648 if (empty($user->rights->societe->client->voir) && !$socid) {
649  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
650 }
651 if ($search_product_category > 0) {
652  $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
653 }
654 if ($socid > 0) {
655  $sql .= ' AND s.rowid = '.((int) $socid);
656 }
657 if ($userid) {
658  if ($userid == -1) {
659  $sql .= ' AND f.fk_user_author IS NULL';
660  } else {
661  $sql .= ' AND f.fk_user_author = '.((int) $userid);
662  }
663 }
664 if ($search_ref) {
665  $sql .= natural_search('f.ref', $search_ref);
666 }
667 if ($search_refcustomer) {
668  $sql .= natural_search('f.ref_client', $search_refcustomer);
669 }
670 if ($search_type != '' && $search_type != '-1') {
671  $sql .= " AND f.type IN (".$db->sanitize($db->escape($search_type)).")";
672 }
673 if ($search_project_ref) {
674  $sql .= natural_search('p.ref', $search_project_ref);
675 }
676 if ($search_project) {
677  $sql .= natural_search('p.title', $search_project);
678 }
679 if ($search_company) {
680  $sql .= natural_search('s.nom', $search_company);
681 }
682 if ($search_company_alias) {
683  $sql .= natural_search('s.name_alias', $search_company_alias);
684 }
685 if ($search_town) {
686  $sql .= natural_search('s.town', $search_town);
687 }
688 if ($search_zip) {
689  $sql .= natural_search("s.zip", $search_zip);
690 }
691 if ($search_state) {
692  $sql .= natural_search("state.nom", $search_state);
693 }
694 if (strlen(trim($search_country))) {
695  $arrayofcode = getCountriesInEEC();
696  $country_code_in_EEC = $country_code_in_EEC_without_me = '';
697  foreach ($arrayofcode as $key => $value) {
698  $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
699  if ($value != $mysoc->country_code) {
700  $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
701  }
702  }
703  if ($search_country == 'special_allnotme') {
704  $sql .= " AND country.code <> '".$db->escape($mysoc->country_code)."'";
705  } elseif ($search_country == 'special_eec') {
706  $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
707  } elseif ($search_country == 'special_eecnotme') {
708  $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
709  } elseif ($search_country == 'special_noteec') {
710  $sql .= " AND country.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
711  } else {
712  $sql .= natural_search("country.code", $search_country);
713  }
714 }
715 if ($search_type_thirdparty != '' && $search_type_thirdparty != '-1') {
716  $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
717 }
718 if ($search_montant_ht != '') {
719  $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
720 }
721 if ($search_montant_vat != '') {
722  $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
723 }
724 if ($search_montant_localtax1 != '') {
725  $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
726 }
727 if ($search_montant_localtax2 != '') {
728  $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
729 }
730 if ($search_montant_ttc != '') {
731  $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
732 }
733 if ($search_multicurrency_code != '') {
734  $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
735 }
736 if ($search_multicurrency_tx != '') {
737  $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
738 }
739 if ($search_multicurrency_montant_ht != '') {
740  $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
741 }
742 if ($search_multicurrency_montant_vat != '') {
743  $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
744 }
745 if ($search_multicurrency_montant_ttc != '') {
746  $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
747 }
748 if ($search_login) {
749  $sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login);
750 }
751 if ($search_categ_cus > 0) {
752  $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
753 }
754 if ($search_categ_cus == -2) {
755  $sql .= " AND cc.fk_categorie IS NULL";
756 }
757 if ($search_status != '-1' && $search_status != '') {
758  if (is_numeric($search_status) && $search_status >= 0) {
759  if ($search_status == '0') {
760  $sql .= " AND f.fk_statut = 0"; // draft
761  }
762  if ($search_status == '1') {
763  $sql .= " AND f.fk_statut = 1"; // unpayed
764  }
765  if ($search_status == '2') {
766  $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)
767  }
768  if ($search_status == '3') {
769  $sql .= " AND f.fk_statut = 3"; // abandonned
770  }
771  } else {
772  $sql .= " AND f.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; // When search_status is '1,2' for example
773  }
774 }
775 
776 if ($search_paymentmode > 0) {
777  $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
778 }
779 if ($search_paymentterms > 0) {
780  $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentterms);
781 }
782 if ($search_module_source) {
783  $sql .= natural_search("f.module_source", $search_module_source);
784 }
785 if ($search_pos_source) {
786  $sql .= natural_search("f.pos_source", $search_pos_source);
787 }
788 if ($search_date_start) {
789  $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
790 }
791 if ($search_date_end) {
792  $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
793 }
794 if ($search_date_valid_start) {
795  $sql .= " AND f.date_valid >= '".$db->idate($search_date_valid_start)."'";
796 }
797 if ($search_date_valid_end) {
798  $sql .= " AND f.date_valid <= '".$db->idate($search_date_valid_end)."'";
799 }
800 if ($search_datelimit_start) {
801  $sql .= " AND f.date_lim_reglement >= '".$db->idate($search_datelimit_start)."'";
802 }
803 if ($search_datelimit_end) {
804  $sql .= " AND f.date_lim_reglement <= '".$db->idate($search_datelimit_end)."'";
805 }
806 if ($option == 'late') {
807  $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
808 }
809 if ($search_sale > 0) {
810  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
811 }
812 if ($search_user > 0) {
813  $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);
814 }
815 if (!empty($search_fac_rec_source_title)) {
816  $sql .= natural_search('facrec.titre', $search_fac_rec_source_title);
817 }
818 // Add where from extra fields
819 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
820 // Add where from hooks
821 $parameters = array();
822 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
823 $sql .= $hookmanager->resPrint;
824 
825 // We disable this. It create a bug when searching with sall and sorting on status. Also it create performance troubles.
826 /*
827 if (!$sall) {
828  $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,';
829  $sql .= ' f.localtax1, f.localtax2,';
830  $sql .= ' f.datef, f.date_valid, f.date_lim_reglement, f.module_source, f.pos_source,';
831  $sql .= ' f.paye, f.fk_statut, f.close_code,';
832  $sql .= ' f.datec, f.tms, f.date_closing,';
833  $sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
834  $sql .= ' f.fk_user_author, f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht,';
835  $sql .= ' f.multicurrency_total_tva, f.multicurrency_total_ttc,';
836  $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,';
837  $sql .= ' typent.code,';
838  $sql .= ' state.code_departement, state.nom,';
839  $sql .= ' country.code,';
840  $sql .= " p.rowid, p.ref, p.title,";
841  $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";
842  if ($search_categ_cus && $search_categ_cus != -1) {
843  $sql .= ", cc.fk_categorie, cc.fk_soc";
844  }
845  // Add fields from extrafields
846  if (!empty($extrafields->attributes[$object->table_element]['label'])) {
847  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
848  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
849  }
850  }
851  // Add GroupBy from hooks
852  $parameters = array('all' => !empty($all) ? $all : 0, 'fieldstosearchall' => $fieldstosearchall);
853  $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
854  $sql .= $hookmanager->resPrint;
855 } else {
856 */
857 if ($sall) {
858  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
859 }
860 
861 // Add HAVING from hooks
862 $parameters = array();
863 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
864 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
865 
866 $nbtotalofrecords = '';
867 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
868  /* This old and fast method to get and count full list returns all record so use a high amount of memory.
869  $result = $db->query($sql);
870  $nbtotalofrecords = $db->num_rows($result);
871  */
872  /* The fast and low memory method to get and count full list converts the sql into a sql count */
873  if ($sall || $search_product_category > 0 || $search_user > 0) {
874  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords', $sql);
875  } else {
876  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT( f.rowid) as nbtotalofrecords', $sql);
877  $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount);
878  }
879  $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
880 
881  $resql = $db->query($sqlforcount);
882  if (! $resql) {
883  dol_print_error($db);
884  } else {
885  $objforcount = $db->fetch_object($resql);
886  $nbtotalofrecords = $objforcount->nbtotalofrecords;
887 
888  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
889  $page = 0;
890  $offset = 0;
891  }
892  $db->free($resql);
893  }
894 }
895 
896 // Complete request and execute it with limit
897 $sql .= ' ORDER BY ';
898 $listfield = explode(',', $sortfield);
899 $listorder = explode(',', $sortorder);
900 foreach ($listfield as $key => $value) {
901  $sql .= $listfield[$key].' '.($listorder[$key] ? $listorder[$key] : 'DESC').',';
902 }
903 $sql .= ' f.rowid DESC ';
904 if ($limit) {
905  $sql .= $db->plimit($limit + 1, $offset);
906 }
907 
908 $resql = $db->query($sql);
909 
910 if ($resql) {
911  $num = $db->num_rows($resql);
912 
913  $arrayofselected = is_array($toselect) ? $toselect : array();
914 
915  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
916  $obj = $db->fetch_object($resql);
917  $id = $obj->id;
918 
919  header("Location: ".DOL_URL_ROOT.'/compta/facture/card.php?facid='.$id);
920  exit;
921  }
922 
923  llxHeader('', $langs->trans('CustomersInvoices'), 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
924 
925  if ($socid > 0) {
926  $soc = new Societe($db);
927  $soc->fetch($socid);
928  if (empty($search_company)) {
929  $search_company = $soc->name;
930  }
931  }
932 
933  $param = '&socid='.urlencode($socid);
934  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
935  $param .= '&contextpage='.urlencode($contextpage);
936  }
937  if ($limit > 0 && $limit != $conf->liste_limit) {
938  $param .= '&limit='.urlencode($limit);
939  }
940  if ($sall) {
941  $param .= '&sall='.urlencode($sall);
942  }
943  if ($search_date_startday) {
944  $param .= '&search_date_startday='.urlencode($search_date_startday);
945  }
946  if ($search_date_startmonth) {
947  $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
948  }
949  if ($search_date_startyear) {
950  $param .= '&search_date_startyear='.urlencode($search_date_startyear);
951  }
952  if ($search_date_endday) {
953  $param .= '&search_date_endday='.urlencode($search_date_endday);
954  }
955  if ($search_date_endmonth) {
956  $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
957  }
958  if ($search_date_endyear) {
959  $param .= '&search_date_endyear='.urlencode($search_date_endyear);
960  }
961  if ($search_date_valid_startday) {
962  $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
963  }
964  if ($search_date_valid_startmonth) {
965  $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
966  }
967  if ($search_date_valid_startyear) {
968  $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
969  }
970  if ($search_date_valid_endday) {
971  $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
972  }
973  if ($search_date_valid_endmonth) {
974  $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
975  }
976  if ($search_date_valid_endyear) {
977  $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
978  }
979  if ($search_datelimit_startday) {
980  $param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
981  }
982  if ($search_datelimit_startmonth) {
983  $param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
984  }
985  if ($search_datelimit_startyear) {
986  $param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
987  }
988  if ($search_datelimit_endday) {
989  $param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
990  }
991  if ($search_datelimit_endmonth) {
992  $param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
993  }
994  if ($search_datelimit_endyear) {
995  $param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
996  }
997  if ($search_ref) {
998  $param .= '&search_ref='.urlencode($search_ref);
999  }
1000  if ($search_refcustomer) {
1001  $param .= '&search_refcustomer='.urlencode($search_refcustomer);
1002  }
1003  if ($search_project_ref) {
1004  $param .= '&search_project_ref='.urlencode($search_project_ref);
1005  }
1006  if ($search_project) {
1007  $param .= '&search_project='.urlencode($search_project);
1008  }
1009  if ($search_type != '') {
1010  $param .= '&search_type='.urlencode($search_type);
1011  }
1012  if ($search_company) {
1013  $param .= '&search_societe='.urlencode($search_company);
1014  }
1015  if ($search_company_alias) {
1016  $param .= '&search_societe_alias='.urlencode($search_company_alias);
1017  }
1018  if ($search_town) {
1019  $param .= '&search_town='.urlencode($search_town);
1020  }
1021  if ($search_zip) {
1022  $param .= '&search_zip='.urlencode($search_zip);
1023  }
1024  if ($search_country) {
1025  $param .= "&search_country=".urlencode($search_country);
1026  }
1027  if ($search_sale > 0) {
1028  $param .= '&search_sale='.urlencode($search_sale);
1029  }
1030  if ($search_user > 0) {
1031  $param .= '&search_user='.urlencode($search_user);
1032  }
1033  if ($search_login) {
1034  $param .= '&search_login='.urlencode($search_login);
1035  }
1036  if ($search_product_category > 0) {
1037  $param .= '&search_product_category='.urlencode($search_product_category);
1038  }
1039  if ($search_montant_ht != '') {
1040  $param .= '&search_montant_ht='.urlencode($search_montant_ht);
1041  }
1042  if ($search_montant_vat != '') {
1043  $param .= '&search_montant_vat='.urlencode($search_montant_vat);
1044  }
1045  if ($search_montant_localtax1 != '') {
1046  $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
1047  }
1048  if ($search_montant_localtax2 != '') {
1049  $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
1050  }
1051  if ($search_montant_ttc != '') {
1052  $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
1053  }
1054  if ($search_multicurrency_code != '') {
1055  $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1056  }
1057  if ($search_multicurrency_tx != '') {
1058  $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1059  }
1060  if ($search_multicurrency_montant_ht != '') {
1061  $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1062  }
1063  if ($search_multicurrency_montant_vat != '') {
1064  $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
1065  }
1066  if ($search_multicurrency_montant_ttc != '') {
1067  $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1068  }
1069  if ($search_status != '') {
1070  $param .= '&search_status='.urlencode($search_status);
1071  }
1072  if ($search_paymentmode > 0) {
1073  $param .= '&search_paymentmode='.urlencode($search_paymentmode);
1074  }
1075  if ($search_paymentterms > 0) {
1076  $param .= '&search_paymentterms='.urlencode($search_paymentterms);
1077  }
1078  if ($search_module_source) {
1079  $param .= '&search_module_source='.urlencode($search_module_source);
1080  }
1081  if ($search_pos_source) {
1082  $param .= '&search_pos_source='.urlencode($search_pos_source);
1083  }
1084  if ($show_files) {
1085  $param .= '&show_files='.urlencode($show_files);
1086  }
1087  if ($option) {
1088  $param .= "&search_option=".urlencode($option);
1089  }
1090  if ($optioncss != '') {
1091  $param .= '&optioncss='.urlencode($optioncss);
1092  }
1093  if ($search_categ_cus > 0) {
1094  $param .= '&search_categ_cus='.urlencode($search_categ_cus);
1095  }
1096  if (!empty($search_fac_rec_source_title)) {
1097  $param .= '&search_fac_rec_source_title='.urlencode($search_fac_rec_source_title);
1098  }
1099 
1100  // Add $param from extra fields
1101  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1102  // Add $param from hooks
1103  $parameters = array();
1104  $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
1105  $param .= $hookmanager->resPrint;
1106 
1107  $arrayofmassactions = array(
1108  'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
1109  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1110  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1111  'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1112  );
1113 
1114  if (!empty($user->rights->facture->paiement)) {
1115  $arrayofmassactions['makepayment'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakePaymentAndClassifyPayed");
1116  }
1117  if (!empty($conf->prelevement->enabled) && !empty($user->rights->prelevement->bons->creer)) {
1118  $langs->load("withdrawals");
1119  $arrayofmassactions['withdrawrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeWithdrawRequest");
1120  }
1121  if (!empty($user->rights->facture->supprimer)) {
1122  if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) {
1123  $arrayofmassactions['predeletedraft'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Deletedraft");
1124  } elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { // mass deletion never possible on invoices on such situation
1125  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1126  }
1127  }
1128  if (in_array($massaction, array('presend', 'predelete', 'makepayment'))) {
1129  $arrayofmassactions = array();
1130  }
1131  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1132 
1133  // Show the new button only when this page is not opend from the Extended POS
1134  if ($contextpage != 'poslist') {
1135  $url = DOL_URL_ROOT.'/compta/facture/card.php?action=create';
1136  if (!empty($socid)) {
1137  $url .= '&socid='.$socid;
1138  }
1139  $newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', $user->rights->facture->creer);
1140  }
1141 
1142  $i = 0;
1143  print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1144 
1145  if ($optioncss != '') {
1146  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1147  }
1148  print '<input type="hidden" name="token" value="'.newToken().'">';
1149  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1150  if (!in_array($massaction, array('makepayment'))) {
1151  print '<input type="hidden" name="action" value="list">';
1152  }
1153  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1154  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1155  print '<input type="hidden" name="search_status" value="'.$search_status.'">';
1156  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1157  print '<input type="hidden" name="socid" value="'.$socid.'">';
1158 
1159  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);
1160 
1161  $topicmail = "SendBillRef";
1162  $modelmail = "facture_send";
1163  $objecttmp = new Facture($db);
1164  $trackid = 'inv'.$object->id;
1165  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1166 
1167  if ($massaction == 'makepayment') {
1168  $formconfirm = '';
1169  $formquestion = array(
1170  // 'text' => $langs->trans("ConfirmClone"),
1171  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1172  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
1173  array('type' => 'date', 'name' => 'datepaiment', 'label' => $langs->trans("Date"), 'datenow' => 1),
1174  array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 0, 0, 1, 0, 1, '', 1)),
1175  array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("BankAccount"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)),
1176  //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>'<input type="hidden" id="invoicesid" name="invoicesid" value="'.implode('#',GETPOST('toselect','array')).'">'),
1177  );
1178  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('MakePaymentAndClassifyPayed'), $langs->trans('EnterPaymentReceivedFromCustomer'), 'makepayment_confirm', $formquestion, 1, 0, 200, 500, 1);
1179  print $formconfirm;
1180  }
1181 
1182  if ($sall) {
1183  foreach ($fieldstosearchall as $key => $val) {
1184  $fieldstosearchall[$key] = $langs->trans($val);
1185  }
1186  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
1187  }
1188 
1189  // If the user can view prospects other than his'
1190  $moreforfilter = '';
1191  if ($user->rights->user->user->lire) {
1192  $langs->load("commercial");
1193  $moreforfilter .= '<div class="divsearchfield">';
1194  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1195  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250');
1196  $moreforfilter .= '</div>';
1197  }
1198  // If the user can view prospects other than his'
1199  if ($user->rights->user->user->lire) {
1200  $moreforfilter .= '<div class="divsearchfield">';
1201  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1202  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250');
1203  $moreforfilter .= '</div>';
1204  }
1205  // Filter on product tags
1206  if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
1207  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1208  $moreforfilter .= '<div class="divsearchfield">';
1209  $tmptitle = $langs->trans('IncludingProductWithTag');
1210  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1211  $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);
1212  $moreforfilter .= '</div>';
1213  }
1214  if (isModEnabled('categorie') && $user->rights->categorie->lire) {
1215  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1216  $moreforfilter .= '<div class="divsearchfield">';
1217  $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1218  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);
1219  $moreforfilter .= '</div>';
1220  }
1221  $parameters = array();
1222  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1223  if (empty($reshook)) {
1224  $moreforfilter .= $hookmanager->resPrint;
1225  } else {
1226  $moreforfilter = $hookmanager->resPrint;
1227  }
1228 
1229  if ($moreforfilter) {
1230  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1231  print $moreforfilter;
1232  print '</div>';
1233  }
1234 
1235  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1236  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1237 
1238  // Show the massaction checkboxes only when this page is not opend from the Extended POS
1239  if ($massactionbutton && $contextpage != 'poslist') {
1240  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1241  }
1242 
1243  print '<div class="div-table-responsive">';
1244  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1245 
1246  // Filters lines
1247  print '<tr class="liste_titre_filter">';
1248  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
1249  print '<td class="liste_titre">';
1250  print '</td>';
1251  }
1252  // Ref
1253  if (!empty($arrayfields['f.ref']['checked'])) {
1254  print '<td class="liste_titre" align="left">';
1255  print '<input class="flat maxwidth50imp" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1256  print '</td>';
1257  }
1258  // Ref customer
1259  if (!empty($arrayfields['f.ref_client']['checked'])) {
1260  print '<td class="liste_titre">';
1261  print '<input class="flat maxwidth50imp" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
1262  print '</td>';
1263  }
1264  // Type
1265  if (!empty($arrayfields['f.type']['checked'])) {
1266  print '<td class="liste_titre maxwidthonsmartphone">';
1267  $listtype = array(
1268  Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
1269  Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
1270  Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
1271  Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
1272  );
1273  if (!empty($conf->global->INVOICE_USE_SITUATION)) {
1274  $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
1275  }
1276  //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
1277  print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
1278  print '</td>';
1279  }
1280  // Date invoice
1281  if (!empty($arrayfields['f.datef']['checked'])) {
1282  print '<td class="liste_titre center">';
1283  print '<div class="nowrap">';
1284  print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1285  print '</div>';
1286  print '<div class="nowrap">';
1287  print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1288  print '</div>';
1289  print '</td>';
1290  }
1291  // Date valid
1292  if (!empty($arrayfields['f.date_valid']['checked'])) {
1293  print '<td class="liste_titre center">';
1294  print '<div class="nowrap">';
1295  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'));
1296  print '</div>';
1297  print '<div class="nowrap">';
1298  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'));
1299  print '</div>';
1300  print '</td>';
1301  }
1302  // Date due
1303  if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1304  print '<td class="liste_titre center">';
1305  print '<div class="nowrap">';
1306  /*
1307  print $langs->trans('From').' ';
1308  print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
1309  print '</div>';
1310  print '<div class="nowrap">';
1311  print $langs->trans('to').' ';*/
1312  print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
1313  print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
1314  print '</div>';
1315  print '</td>';
1316  }
1317  // Project ref
1318  if (!empty($arrayfields['p.ref']['checked'])) {
1319  print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project_ref" value="'.$search_project_ref.'"></td>';
1320  }
1321  // Project label
1322  if (!empty($arrayfields['p.title']['checked'])) {
1323  print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.$search_project.'"></td>';
1324  }
1325  // Thirdparty
1326  if (!empty($arrayfields['s.nom']['checked'])) {
1327  print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company" value="'.$search_company.'"'.($socid > 0 ? " disabled" : "").'></td>';
1328  }
1329  // Alias
1330  if (!empty($arrayfields['s.name_alias']['checked'])) {
1331  print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company_alias" value="'.$search_company_alias.'"></td>';
1332  }
1333  // Town
1334  if (!empty($arrayfields['s.town']['checked'])) {
1335  print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1336  }
1337  // Zip
1338  if (!empty($arrayfields['s.zip']['checked'])) {
1339  print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1340  }
1341  // State
1342  if (!empty($arrayfields['state.nom']['checked'])) {
1343  print '<td class="liste_titre">';
1344  print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1345  print '</td>';
1346  }
1347  // Country
1348  if (!empty($arrayfields['country.code_iso']['checked'])) {
1349  print '<td class="liste_titre" align="center">';
1350  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, null, 1);
1351  print '</td>';
1352  }
1353  // Company type
1354  if (!empty($arrayfields['typent.code']['checked'])) {
1355  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1356  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);
1357  print '</td>';
1358  }
1359  // Payment mode
1360  if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1361  print '<td class="liste_titre">';
1362  $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 10);
1363  print '</td>';
1364  }
1365  // Payment terms
1366  if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1367  print '<td class="liste_titre">';
1368  $form->select_conditions_paiements($search_paymentterms, 'search_paymentterms', -1, 1, 1);
1369  print '</td>';
1370  }
1371  // Module source
1372  if (!empty($arrayfields['f.module_source']['checked'])) {
1373  print '<td class="liste_titre">';
1374  print '<input class="flat maxwidth75" type="text" name="search_module_source" value="'.dol_escape_htmltag($search_module_source).'">';
1375  print '</td>';
1376  }
1377  // POS Terminal
1378  if (!empty($arrayfields['f.pos_source']['checked'])) {
1379  print '<td class="liste_titre">';
1380  print '<input class="flat maxwidth50" type="text" name="search_pos_source" value="'.dol_escape_htmltag($search_pos_source).'">';
1381  print '</td>';
1382  }
1383  if (!empty($arrayfields['f.total_ht']['checked'])) {
1384  // Amount
1385  print '<td class="liste_titre right">';
1386  print '<input class="flat" type="text" size="4" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1387  print '</td>';
1388  }
1389  if (!empty($arrayfields['f.total_tva']['checked'])) {
1390  // Amount
1391  print '<td class="liste_titre right">';
1392  print '<input class="flat" type="text" size="4" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1393  print '</td>';
1394  }
1395  if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1396  // Localtax1
1397  print '<td class="liste_titre right">';
1398  print '<input class="flat" type="text" size="4" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
1399  print '</td>';
1400  }
1401  if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1402  // Localtax2
1403  print '<td class="liste_titre right">';
1404  print '<input class="flat" type="text" size="4" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
1405  print '</td>';
1406  }
1407  if (!empty($arrayfields['f.total_ttc']['checked'])) {
1408  // Amount
1409  print '<td class="liste_titre right">';
1410  print '<input class="flat" type="text" size="4" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1411  print '</td>';
1412  }
1413  if (!empty($arrayfields['u.login']['checked'])) {
1414  // Author
1415  print '<td class="liste_titre" align="center">';
1416  print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1417  print '</td>';
1418  }
1419  if (!empty($arrayfields['sale_representative']['checked'])) {
1420  print '<td class="liste_titre"></td>';
1421  }
1422  if (!empty($arrayfields['f.retained_warranty']['checked'])) {
1423  print '<td class="liste_titre" align="right">';
1424  print '</td>';
1425  }
1426  if (!empty($arrayfields['dynamount_payed']['checked'])) {
1427  print '<td class="liste_titre right">';
1428  print '</td>';
1429  }
1430  if (!empty($arrayfields['rtp']['checked'])) {
1431  print '<td class="liste_titre right">';
1432  print '</td>';
1433  }
1434  if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1435  // Currency
1436  print '<td class="liste_titre">';
1437  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1438  print '</td>';
1439  }
1440  if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1441  // Currency rate
1442  print '<td class="liste_titre">';
1443  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1444  print '</td>';
1445  }
1446  if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1447  // Amount
1448  print '<td class="liste_titre right">';
1449  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1450  print '</td>';
1451  }
1452  if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1453  // Amount
1454  print '<td class="liste_titre right">';
1455  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1456  print '</td>';
1457  }
1458  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1459  // Amount
1460  print '<td class="liste_titre right">';
1461  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1462  print '</td>';
1463  }
1464  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1465  print '<td class="liste_titre">';
1466  print '</td>';
1467  }
1468  if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1469  print '<td class="liste_titre right">';
1470  print '</td>';
1471  }
1472  if (!empty($arrayfields['total_pa']['checked'])) {
1473  print '<td class="liste_titre right">';
1474  print '</td>';
1475  }
1476  if (!empty($arrayfields['total_margin']['checked'])) {
1477  print '<td class="liste_titre right">';
1478  print '</td>';
1479  }
1480  if (!empty($arrayfields['total_margin_rate']['checked'])) {
1481  print '<td class="liste_titre right">';
1482  print '</td>';
1483  }
1484  if (!empty($arrayfields['total_mark_rate']['checked'])) {
1485  print '<td class="liste_titre right">';
1486  print '</td>';
1487  }
1488 
1489  // Extra fields
1490  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1491 
1492  // Fields from hook
1493  $parameters = array('arrayfields'=>$arrayfields);
1494  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1495  print $hookmanager->resPrint;
1496  // Date creation
1497  if (!empty($arrayfields['f.datec']['checked'])) {
1498  print '<td class="liste_titre">';
1499  print '</td>';
1500  }
1501  // Date modification
1502  if (!empty($arrayfields['f.tms']['checked'])) {
1503  print '<td class="liste_titre">';
1504  print '</td>';
1505  }
1506  // Date closing
1507  if (!empty($arrayfields['f.date_closing']['checked'])) {
1508  print '<td class="liste_titre">';
1509  print '</td>';
1510  }
1511  if (!empty($arrayfields['f.note_public']['checked'])) {
1512  // Note public
1513  print '<td class="liste_titre">';
1514  print '</td>';
1515  }
1516  if (!empty($arrayfields['f.note_private']['checked'])) {
1517  // Note private
1518  print '<td class="liste_titre">';
1519  print '</td>';
1520  }
1521  if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
1522  // Template Invoice
1523  print '<td class="liste_titre maxwidthonsmartphone right">';
1524  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).'">';
1525  print '</td>';
1526  }
1527  // Status
1528  if (!empty($arrayfields['f.fk_statut']['checked'])) {
1529  print '<td class="liste_titre maxwidthonsmartphone right">';
1530  $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"));
1531  print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
1532  print '</td>';
1533  }
1534  // Action column
1535  print '<td class="liste_titre" align="middle">';
1536  $searchpicto = $form->showFilterButtons();
1537  print $searchpicto;
1538  print '</td>';
1539  print "</tr>\n";
1540 
1541  print '<tr class="liste_titre">';
1542  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
1543  print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1544  }
1545  if (!empty($arrayfields['f.ref']['checked'])) {
1546  print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref', '', $param, '', $sortfield, $sortorder);
1547  }
1548  if (!empty($arrayfields['f.ref_client']['checked'])) {
1549  print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], 'f.ref_client', '', $param, '', $sortfield, $sortorder);
1550  }
1551  if (!empty($arrayfields['f.type']['checked'])) {
1552  print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
1553  }
1554  if (!empty($arrayfields['f.datef']['checked'])) {
1555  print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef', '', $param, 'align="center"', $sortfield, $sortorder);
1556  }
1557  if (!empty($arrayfields['f.date_valid']['checked'])) {
1558  print_liste_field_titre($arrayfields['f.date_valid']['label'], $_SERVER['PHP_SELF'], 'f.date_valid', '', $param, 'align="center"', $sortfield, $sortorder);
1559  }
1560  if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1561  print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, 'align="center"', $sortfield, $sortorder);
1562  }
1563  if (!empty($arrayfields['p.ref']['checked'])) {
1564  print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
1565  }
1566  if (!empty($arrayfields['p.title']['checked'])) {
1567  print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER['PHP_SELF'], "p.title", '', $param, '', $sortfield, $sortorder);
1568  }
1569  if (!empty($arrayfields['s.nom']['checked'])) {
1570  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
1571  }
1572  if (!empty($arrayfields['s.name_alias']['checked'])) {
1573  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1574  }
1575  if (!empty($arrayfields['s.town']['checked'])) {
1576  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1577  }
1578  if (!empty($arrayfields['s.zip']['checked'])) {
1579  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1580  }
1581  if (!empty($arrayfields['state.nom']['checked'])) {
1582  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1583  }
1584  if (!empty($arrayfields['country.code_iso']['checked'])) {
1585  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
1586  }
1587  if (!empty($arrayfields['typent.code']['checked'])) {
1588  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
1589  }
1590  if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
1591  print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1592  }
1593  if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
1594  print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1595  }
1596  if (!empty($arrayfields['f.module_source']['checked'])) {
1597  print_liste_field_titre($arrayfields['f.module_source']['label'], $_SERVER["PHP_SELF"], "f.module_source", "", $param, "", $sortfield, $sortorder);
1598  }
1599  if (!empty($arrayfields['f.pos_source']['checked'])) {
1600  print_liste_field_titre($arrayfields['f.pos_source']['label'], $_SERVER["PHP_SELF"], "f.pos_source", "", $param, "", $sortfield, $sortorder);
1601  }
1602  if (!empty($arrayfields['f.total_ht']['checked'])) {
1603  print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1604  }
1605  if (!empty($arrayfields['f.total_tva']['checked'])) {
1606  print_liste_field_titre($arrayfields['f.total_tva']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1607  }
1608  if (!empty($arrayfields['f.total_localtax1']['checked'])) {
1609  print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, 'class="right"', $sortfield, $sortorder);
1610  }
1611  if (!empty($arrayfields['f.total_localtax2']['checked'])) {
1612  print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, 'class="right"', $sortfield, $sortorder);
1613  }
1614  if (!empty($arrayfields['f.total_ttc']['checked'])) {
1615  print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1616  }
1617  if (!empty($arrayfields['u.login']['checked'])) {
1618  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1619  }
1620  if (!empty($arrayfields['sale_representative']['checked'])) {
1621  print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1622  }
1623  if (!empty($arrayfields['f.retained_warranty']['checked'])) {
1624  print_liste_field_titre($arrayfields['f.retained_warranty']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="right"', $sortfield, $sortorder);
1625  }
1626  if (!empty($arrayfields['dynamount_payed']['checked'])) {
1627  print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1628  }
1629  if (!empty($arrayfields['rtp']['checked'])) {
1630  print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1631  }
1632  if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
1633  print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1634  }
1635  if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
1636  print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1637  }
1638  if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
1639  print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1640  }
1641  if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
1642  print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1643  }
1644  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
1645  print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1646  }
1647  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
1648  print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1649  }
1650  if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
1651  print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1652  }
1653  if (!empty($arrayfields['total_pa']['checked'])) {
1654  print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1655  }
1656  if (!empty($arrayfields['total_margin']['checked'])) {
1657  print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1658  }
1659  if (!empty($arrayfields['total_margin_rate']['checked'])) {
1660  print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1661  }
1662  if (!empty($arrayfields['total_mark_rate']['checked'])) {
1663  print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1664  }
1665  // Extra fields
1666  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1667  // Hook fields
1668  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1669  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1670  print $hookmanager->resPrint;
1671  if (!empty($arrayfields['f.datec']['checked'])) {
1672  print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1673  }
1674  if (!empty($arrayfields['f.tms']['checked'])) {
1675  print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1676  }
1677  if (!empty($arrayfields['f.date_closing']['checked'])) {
1678  print_liste_field_titre($arrayfields['f.date_closing']['label'], $_SERVER["PHP_SELF"], "f.date_closing", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1679  }
1680  if (!empty($arrayfields['f.note_public']['checked'])) {
1681  print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1682  }
1683  if (!empty($arrayfields['f.note_private']['checked'])) {
1684  print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1685  }
1686  if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
1687  print_liste_field_titre($arrayfields['f.fk_fac_rec_source']['label'], $_SERVER["PHP_SELF"], "facrec.titre", "", $param, '', $sortfield, $sortorder);
1688  }
1689  if (!empty($arrayfields['f.fk_statut']['checked'])) {
1690  print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut,f.paye,f.type", "", $param, 'class="right"', $sortfield, $sortorder);
1691  }
1692  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
1693  print "</tr>\n";
1694 
1695  $projectstatic = new Project($db);
1696  $discount = new DiscountAbsolute($db);
1697  $userstatic = new User($db);
1698 
1699  if ($num > 0) {
1700  $i = 0;
1701  $totalarray = array();
1702  $totalarray['nbfield'] = 0;
1703  $totalarray['val'] = array();
1704  $totalarray['val']['f.total_ht'] = 0;
1705  $totalarray['val']['f.total_ttc'] = 0;
1706 
1707  $with_margin_info = false;
1708  if (isModEnabled('margin') && (
1709  !empty($arrayfields['total_pa']['checked'])
1710  || !empty($arrayfields['total_margin']['checked'])
1711  || !empty($arrayfields['total_margin_rate']['checked'])
1712  || !empty($arrayfields['total_mark_rate']['checked'])
1713  )
1714  ) {
1715  $with_margin_info = true;
1716  }
1717  $total_ht = 0;
1718  $total_margin = 0;
1719 
1720  $last_num = min($num, $limit);
1721  while ($i < $last_num) {
1722  $obj = $db->fetch_object($resql);
1723 
1724  $datelimit = $db->jdate($obj->datelimite);
1725 
1726  $facturestatic->id = $obj->id;
1727  $facturestatic->ref = $obj->ref;
1728  $facturestatic->ref_client = $obj->ref_client;
1729  $facturestatic->type = $obj->type;
1730  $facturestatic->total_ht = $obj->total_ht;
1731  $facturestatic->total_tva = $obj->total_tva;
1732  $facturestatic->total_ttc = $obj->total_ttc;
1733  $facturestatic->multicurrency_code = $obj->multicurrency_code;
1734  $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1735  $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1736  $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1737  $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1738  $facturestatic->statut = $obj->fk_statut;
1739  $facturestatic->close_code = $obj->close_code;
1740  $facturestatic->total_ttc = $obj->total_ttc;
1741  $facturestatic->paye = $obj->paye;
1742  $facturestatic->fk_soc = $obj->fk_soc;
1743 
1744  $facturestatic->date = $db->jdate($obj->datef);
1745  $facturestatic->date_valid = $db->jdate($obj->date_valid);
1746  $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
1747 
1748  $facturestatic->note_public = $obj->note_public;
1749  $facturestatic->note_private = $obj->note_private;
1750  if (!empty($conf->global->INVOICE_USE_SITUATION) && !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
1751  $facturestatic->retained_warranty = $obj->retained_warranty;
1752  $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit;
1753  $facturestatic->situation_final = $obj->retained_warranty_date_limit;
1754  $facturestatic->situation_final = $obj->retained_warranty_date_limit;
1755  $facturestatic->situation_cycle_ref = $obj->situation_cycle_ref;
1756  $facturestatic->situation_counter = $obj->situation_counter;
1757  }
1758 
1759  $companystatic->id = $obj->socid;
1760  $companystatic->name = $obj->name;
1761  $companystatic->name_alias = $obj->alias;
1762  $companystatic->client = $obj->client;
1763  $companystatic->fournisseur = $obj->fournisseur;
1764  $companystatic->code_client = $obj->code_client;
1765  $companystatic->code_compta_client = $obj->code_compta_client;
1766  $companystatic->code_fournisseur = $obj->code_fournisseur;
1767  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1768  $companystatic->email = $obj->email;
1769  $companystatic->phone = $obj->phone;
1770  $companystatic->fax = $obj->fax;
1771  $companystatic->address = $obj->address;
1772  $companystatic->zip = $obj->zip;
1773  $companystatic->town = $obj->town;
1774  $companystatic->country_code = $obj->country_code;
1775 
1776  $projectstatic->id = $obj->project_id;
1777  $projectstatic->ref = $obj->project_ref;
1778  $projectstatic->title = $obj->project_label;
1779 
1780  $paiement = $facturestatic->getSommePaiement();
1781  $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1782  $totaldeposits = $facturestatic->getSumDepositsUsed();
1783  $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1784  $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1785  $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1786  $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1787  $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1788  $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1789  $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1790 
1791  if ($facturestatic->statut == Facture::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1792  $remaintopay = 0;
1793  $multicurrency_remaintopay = 0;
1794  }
1795  if ($facturestatic->type == Facture::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
1796  $remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id);
1797  $remaintopay = -$remaincreditnote;
1798  $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1799  $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1800  $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1801  $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1802  }
1803 
1804  $facturestatic->alreadypaid = $paiement;
1805 
1806  $marginInfo = array();
1807  if ($with_margin_info === true) {
1808  $facturestatic->fetch_lines();
1809  $marginInfo = $formmargin->getMarginInfosArray($facturestatic);
1810  $total_ht += $obj->total_ht;
1811  $total_margin += $marginInfo['total_margin'];
1812  }
1813 
1814  print '<tr class="oddeven"';
1815  if ($contextpage == 'poslist') {
1816  print ' onclick="parent.$(\'#poslines\').load(\'invoice.php?action=history&placeid='.$obj->id.'\', function() {parent.$.colorbox.close();';
1817  if (strpos($obj->ref, 'PROV') !== false) {
1818  //If is a draft invoice, load var to be able to add products
1819  $place = str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $obj->ref));
1820  print 'parent.place=\''.$place.'\'';
1821  }
1822  print '});"';
1823  }
1824  print '>';
1825 
1826  // No
1827  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
1828  print '<td>'.(($offset * $limit) + $i).'</td>';
1829  }
1830 
1831  // Ref
1832  if (!empty($arrayfields['f.ref']['checked'])) {
1833  print '<td class="nowraponall">';
1834 
1835  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1836 
1837  print '<td class="nobordernopadding nowraponall">';
1838  if ($contextpage == 'poslist') {
1839  print dol_escape_htmltag($obj->ref);
1840  } else {
1841  print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1);
1842  }
1843 
1844  $filename = dol_sanitizeFileName($obj->ref);
1845  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1846  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->id;
1847  print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
1848  print '</td>';
1849  print '</tr>';
1850  print '</table>';
1851 
1852  print "</td>\n";
1853  if (!$i) {
1854  $totalarray['nbfield']++;
1855  }
1856  }
1857 
1858  // Customer ref
1859  if (!empty($arrayfields['f.ref_client']['checked'])) {
1860  print '<td class="nowrap tdoverflowmax200">';
1861  print dol_escape_htmltag($obj->ref_client);
1862  print '</td>';
1863  if (!$i) {
1864  $totalarray['nbfield']++;
1865  }
1866  }
1867 
1868  // Type
1869  if (!empty($arrayfields['f.type']['checked'])) {
1870  print '<td class="nowraponall tdoverflowmax100" title="'.$facturestatic->getLibType().'">';
1871  print $facturestatic->getLibType();
1872  print "</td>";
1873  if (!$i) {
1874  $totalarray['nbfield']++;
1875  }
1876  }
1877 
1878  // Date
1879  if (!empty($arrayfields['f.datef']['checked'])) {
1880  print '<td align="center" class="nowraponall">';
1881  print dol_print_date($db->jdate($obj->datef), 'day');
1882  print '</td>';
1883  if (!$i) {
1884  $totalarray['nbfield']++;
1885  }
1886  }
1887 
1888  // Date
1889  if (!empty($arrayfields['f.date_valid']['checked'])) {
1890  print '<td align="center" class="nowraponall">';
1891  print dol_print_date($db->jdate($obj->date_valid), 'day');
1892  print '</td>';
1893  if (!$i) {
1894  $totalarray['nbfield']++;
1895  }
1896  }
1897 
1898  // Date limit
1899  if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
1900  print '<td align="center" class="nowraponall">'.dol_print_date($datelimit, 'day');
1901  if ($facturestatic->hasDelay()) {
1902  print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1903  }
1904  print '</td>';
1905  if (!$i) {
1906  $totalarray['nbfield']++;
1907  }
1908  }
1909 
1910  // Project ref
1911  if (!empty($arrayfields['p.ref']['checked'])) {
1912  print '<td class="nocellnopadd nowraponall">';
1913  if ($obj->project_id > 0) {
1914  print $projectstatic->getNomUrl(1);
1915  }
1916  print '</td>';
1917  if (!$i) {
1918  $totalarray['nbfield']++;
1919  }
1920  }
1921 
1922  // Project title
1923  if (!empty($arrayfields['p.title']['checked'])) {
1924  print '<td class="nowraponall">';
1925  if ($obj->project_id > 0) {
1926  print dol_escape_htmltag($projectstatic->title);
1927  }
1928  print '</td>';
1929  if (!$i) {
1930  $totalarray['nbfield']++;
1931  }
1932  }
1933 
1934  // Third party
1935  if (!empty($arrayfields['s.nom']['checked'])) {
1936  print '<td class="tdoverflowmax200">';
1937  if ($contextpage == 'poslist') {
1938  print dol_escape_htmltag($companystatic->name);
1939  } else {
1940  print $companystatic->getNomUrl(1, 'customer', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1941  }
1942  print '</td>';
1943  if (!$i) {
1944  $totalarray['nbfield']++;
1945  }
1946  }
1947  // Alias
1948  if (!empty($arrayfields['s.name_alias']['checked'])) {
1949  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->name_alias).'">';
1950  print dol_escape_htmltag($companystatic->name_alias);
1951  print '</td>';
1952  if (!$i) {
1953  $totalarray['nbfield']++;
1954  }
1955  }
1956  // Town
1957  if (!empty($arrayfields['s.town']['checked'])) {
1958  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1959  print dol_escape_htmltag($obj->town);
1960  print '</td>';
1961  if (!$i) {
1962  $totalarray['nbfield']++;
1963  }
1964  }
1965  // Zip
1966  if (!empty($arrayfields['s.zip']['checked'])) {
1967  print '<td class="nowraponall">';
1968  print dol_escape_htmltag($obj->zip);
1969  print '</td>';
1970  if (!$i) {
1971  $totalarray['nbfield']++;
1972  }
1973  }
1974  // State
1975  if (!empty($arrayfields['state.nom']['checked'])) {
1976  print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
1977  if (!$i) {
1978  $totalarray['nbfield']++;
1979  }
1980  }
1981  // Country
1982  if (!empty($arrayfields['country.code_iso']['checked'])) {
1983  print '<td class="center">';
1984  $tmparray = getCountry($obj->fk_pays, 'all');
1985  print $tmparray['label'];
1986  print '</td>';
1987  if (!$i) {
1988  $totalarray['nbfield']++;
1989  }
1990  }
1991  // Type ent
1992  if (!empty($arrayfields['typent.code']['checked'])) {
1993  print '<td class="center">';
1994  if (!is_array($typenArray) || count($typenArray) == 0) {
1995  $typenArray = $formcompany->typent_array(1);
1996  }
1997  print $typenArray[$obj->typent_code];
1998  print '</td>';
1999  if (!$i) {
2000  $totalarray['nbfield']++;
2001  }
2002  }
2003  // Staff
2004  if (!empty($arrayfields['staff.code']['checked'])) {
2005  print '<td class="center">';
2006  if (!is_array($conf->cache['staff']) || count($conf->cache['staff']) == 0) {
2007  $conf->cache['staff'] = $formcompany->effectif_array(1);
2008  }
2009  print $conf->cache['staff'][$obj->staff_code];
2010  print '</td>';
2011  if (!$i) {
2012  $totalarray['nbfield']++;
2013  }
2014  }
2015 
2016  // Payment mode
2017  if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
2018  print '<td class="tdoverflowmax100">';
2019  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
2020  print '</td>';
2021  if (!$i) {
2022  $totalarray['nbfield']++;
2023  }
2024  }
2025 
2026  // Payment terms
2027  if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
2028  print '<td>';
2029  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
2030  print '</td>';
2031  if (!$i) {
2032  $totalarray['nbfield']++;
2033  }
2034  }
2035 
2036  // Module Source
2037  if (!empty($arrayfields['f.module_source']['checked'])) {
2038  print '<td>';
2039  print dol_escape_htmltag($obj->module_source);
2040  print '</td>';
2041  if (!$i) {
2042  $totalarray['nbfield']++;
2043  }
2044  }
2045 
2046  // POS Terminal
2047  if (!empty($arrayfields['f.pos_source']['checked'])) {
2048  print '<td>';
2049  print dol_escape_htmltag($obj->pos_source);
2050  print '</td>';
2051  if (!$i) {
2052  $totalarray['nbfield']++;
2053  }
2054  }
2055 
2056  // Amount HT
2057  if (!empty($arrayfields['f.total_ht']['checked'])) {
2058  print '<td class="right nowraponall">'.price($obj->total_ht)."</td>\n";
2059  if (!$i) {
2060  $totalarray['nbfield']++;
2061  }
2062  if (!$i) {
2063  $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
2064  }
2065  $totalarray['val']['f.total_ht'] += $obj->total_ht;
2066  }
2067  // Amount VAT
2068  if (!empty($arrayfields['f.total_tva']['checked'])) {
2069  print '<td class="right nowraponall amount">'.price($obj->total_tva)."</td>\n";
2070  if (!$i) {
2071  $totalarray['nbfield']++;
2072  }
2073  if (!$i) {
2074  $totalarray['pos'][$totalarray['nbfield']] = 'f.total_tva';
2075  }
2076  $totalarray['val']['f.total_tva'] += $obj->total_tva;
2077  }
2078  // Amount LocalTax1
2079  if (!empty($arrayfields['f.total_localtax1']['checked'])) {
2080  print '<td class="right nowraponall amount">'.price($obj->total_localtax1)."</td>\n";
2081  if (!$i) {
2082  $totalarray['nbfield']++;
2083  }
2084  if (!$i) {
2085  $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
2086  }
2087  $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
2088  }
2089  // Amount LocalTax2
2090  if (!empty($arrayfields['f.total_localtax2']['checked'])) {
2091  print '<td class="right nowraponall amount">'.price($obj->total_localtax2)."</td>\n";
2092  if (!$i) {
2093  $totalarray['nbfield']++;
2094  }
2095  if (!$i) {
2096  $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
2097  }
2098  $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
2099  }
2100  // Amount TTC
2101  if (!empty($arrayfields['f.total_ttc']['checked'])) {
2102  print '<td class="right nowraponall amount">'.price($obj->total_ttc)."</td>\n";
2103  if (!$i) {
2104  $totalarray['nbfield']++;
2105  }
2106  if (!$i) {
2107  $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
2108  }
2109  $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
2110  }
2111 
2112  $userstatic->id = $obj->fk_user_author;
2113  $userstatic->login = $obj->login;
2114  $userstatic->lastname = $obj->lastname;
2115  $userstatic->firstname = $obj->firstname;
2116  $userstatic->email = $obj->user_email;
2117  $userstatic->statut = $obj->user_statut;
2118  $userstatic->entity = $obj->entity;
2119  $userstatic->photo = $obj->photo;
2120  $userstatic->office_phone = $obj->office_phone;
2121  $userstatic->office_fax = $obj->office_fax;
2122  $userstatic->user_mobile = $obj->user_mobile;
2123  $userstatic->job = $obj->job;
2124  $userstatic->gender = $obj->gender;
2125 
2126  // Author
2127  if (!empty($arrayfields['u.login']['checked'])) {
2128  print '<td class="tdoverflowmax200">';
2129  if ($userstatic->id) {
2130  print $userstatic->getNomUrl(-1);
2131  } else {
2132  print '&nbsp;';
2133  }
2134  print "</td>\n";
2135  if (!$i) {
2136  $totalarray['nbfield']++;
2137  }
2138  }
2139 
2140  if (!empty($arrayfields['sale_representative']['checked'])) {
2141  // Sales representatives
2142  print '<td>';
2143  if ($obj->socid > 0) {
2144  $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
2145  if ($listsalesrepresentatives < 0) {
2146  dol_print_error($db);
2147  }
2148  $nbofsalesrepresentative = count($listsalesrepresentatives);
2149  if ($nbofsalesrepresentative > 6) {
2150  // We print only number
2151  print $nbofsalesrepresentative;
2152  } elseif ($nbofsalesrepresentative > 0) {
2153  $j = 0;
2154  foreach ($listsalesrepresentatives as $val) {
2155  $userstatic->id = $val['id'];
2156  $userstatic->lastname = $val['lastname'];
2157  $userstatic->firstname = $val['firstname'];
2158  $userstatic->email = $val['email'];
2159  $userstatic->statut = $val['statut'];
2160  $userstatic->entity = $val['entity'];
2161  $userstatic->photo = $val['photo'];
2162  $userstatic->login = $val['login'];
2163  $userstatic->office_phone = $val['office_phone'];
2164  $userstatic->office_fax = $val['office_fax'];
2165  $userstatic->user_mobile = $val['user_mobile'];
2166  $userstatic->job = $val['job'];
2167  $userstatic->gender = $val['gender'];
2168  //print '<div class="float">':
2169  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2170  $j++;
2171  if ($j < $nbofsalesrepresentative) {
2172  print ' ';
2173  }
2174  //print '</div>';
2175  }
2176  }
2177  //else print $langs->trans("NoSalesRepresentativeAffected");
2178  } else {
2179  print '&nbsp;';
2180  }
2181  print '</td>';
2182  if (!$i) {
2183  $totalarray['nbfield']++;
2184  }
2185  }
2186 
2187  if (!empty($arrayfields['f.retained_warranty']['checked'])) {
2188  print '<td align="right">'.(!empty($obj->retained_warranty) ? price($obj->retained_warranty).'%' : '&nbsp;').'</td>';
2189  }
2190 
2191  if (!empty($arrayfields['dynamount_payed']['checked'])) {
2192  print '<td class="right nowraponall amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
2193  if (!$i) {
2194  $totalarray['nbfield']++;
2195  }
2196  if (!$i) {
2197  $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
2198  }
2199  $totalarray['val']['totalam'] += $totalpay;
2200  }
2201 
2202  // Pending amount
2203  if (!empty($arrayfields['rtp']['checked'])) {
2204  print '<td class="right nowraponall amount">';
2205  print (!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;');
2206  print '</td>'; // TODO Use a denormalized field
2207  if (!$i) {
2208  $totalarray['nbfield']++;
2209  }
2210  if (!$i) {
2211  $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
2212  }
2213  $totalarray['val']['rtp'] += $remaintopay;
2214  }
2215 
2216 
2217  // Currency
2218  if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
2219  print '<td class="nowraponall tdoverflowmax125" title="'.dol_escape_htmltag($obj->multicurrency_code.' - '.$langs->transnoentitiesnoconv('Currency'.$obj->multicurrency_code)).'">';
2220  if (empty($conf->global->MAIN_SHOW_ONLY_CODE_MULTICURRENCY)) {
2221  print $langs->transnoentitiesnoconv('Currency'.$obj->multicurrency_code);
2222  } else {
2223  print dol_escape_htmltag($obj->multicurrency_code);
2224  }
2225  print "</td>\n";
2226  if (!$i) {
2227  $totalarray['nbfield']++;
2228  }
2229  }
2230 
2231  // Currency rate
2232  if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
2233  print '<td class="nowraponall">';
2234  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
2235  print "</td>\n";
2236  if (!$i) {
2237  $totalarray['nbfield']++;
2238  }
2239  }
2240  // Amount HT
2241  if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
2242  print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_ht)."</td>\n";
2243  if (!$i) {
2244  $totalarray['nbfield']++;
2245  }
2246  }
2247  // Amount VAT
2248  if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
2249  print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_vat)."</td>\n";
2250  if (!$i) {
2251  $totalarray['nbfield']++;
2252  }
2253  }
2254  // Amount TTC
2255  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
2256  print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_ttc)."</td>\n";
2257  if (!$i) {
2258  $totalarray['nbfield']++;
2259  }
2260  }
2261  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
2262  print '<td class="right nowraponall amount">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
2263  if (!$i) {
2264  $totalarray['nbfield']++;
2265  }
2266  }
2267 
2268  // Pending amount
2269  if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
2270  print '<td class="right nowraponall">';
2271  print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '&nbsp;');
2272  print '</td>'; // TODO Use a denormalized field
2273  if (!$i) {
2274  $totalarray['nbfield']++;
2275  }
2276  }
2277 
2278  // Total buying or cost price
2279  if (!empty($arrayfields['total_pa']['checked'])) {
2280  print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
2281  if (!$i) {
2282  $totalarray['nbfield']++;
2283  }
2284  }
2285  // Total margin
2286  if (!empty($arrayfields['total_margin']['checked'])) {
2287  print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
2288  if (!$i) {
2289  $totalarray['nbfield']++;
2290  }
2291  if (!$i) {
2292  $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
2293  }
2294  $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
2295  }
2296  // Total margin rate
2297  if (!empty($arrayfields['total_margin_rate']['checked'])) {
2298  print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
2299  if (!$i) {
2300  $totalarray['nbfield']++;
2301  }
2302  }
2303  // Total mark rate
2304  if (!empty($arrayfields['total_mark_rate']['checked'])) {
2305  print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
2306  if (!$i) {
2307  $totalarray['nbfield']++;
2308  }
2309  if (!$i) {
2310  $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
2311  }
2312  if ($i >= $last_num - 1) {
2313  if (!empty($total_ht)) {
2314  $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
2315  } else {
2316  $totalarray['val']['total_mark_rate'] = '';
2317  }
2318  }
2319  }
2320 
2321  // Extra fields
2322  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2323  // Fields from hook
2324  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
2325  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
2326  print $hookmanager->resPrint;
2327  // Date creation
2328  if (!empty($arrayfields['f.datec']['checked'])) {
2329  print '<td class="nowraponall center">';
2330  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2331  print '</td>';
2332  if (!$i) {
2333  $totalarray['nbfield']++;
2334  }
2335  }
2336  // Date modification
2337  if (!empty($arrayfields['f.tms']['checked'])) {
2338  print '<td class="nowraponall center">';
2339  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
2340  print '</td>';
2341  if (!$i) {
2342  $totalarray['nbfield']++;
2343  }
2344  }
2345  // Date closing
2346  if (!empty($arrayfields['f.date_closing']['checked'])) {
2347  print '<td class="nowraponall center">';
2348  print dol_print_date($db->jdate($obj->date_closing), 'dayhour', 'tzuser');
2349  print '</td>';
2350  if (!$i) {
2351  $totalarray['nbfield']++;
2352  }
2353  }
2354  // Note public
2355  if (!empty($arrayfields['f.note_public']['checked'])) {
2356  print '<td class="center">';
2357  print dol_string_nohtmltag($obj->note_public);
2358  print '</td>';
2359  if (!$i) {
2360  $totalarray['nbfield']++;
2361  }
2362  }
2363  // Note private
2364  if (!empty($arrayfields['f.note_private']['checked'])) {
2365  print '<td class="center">';
2366  print dol_string_nohtmltag($obj->note_private);
2367  print '</td>';
2368  if (!$i) {
2369  $totalarray['nbfield']++;
2370  }
2371  }
2372  // Template Invoice
2373  if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
2374  print '<td class="center">';
2375  if (!empty($obj->fk_fac_rec_source)) {
2376  $facrec = new FactureRec($db);
2377  $result = $facrec->fetch($obj->fk_fac_rec_source);
2378  if ($result < 0) {
2379  setEventMessages($facrec->error, $facrec->errors, 'errors');
2380  } else {
2381  print $facrec->getNomUrl();
2382  }
2383  }
2384  print '</td>';
2385  if (!$i) {
2386  $totalarray['nbfield']++;
2387  }
2388  }
2389  // Status
2390  if (!empty($arrayfields['f.fk_statut']['checked'])) {
2391  print '<td class="nowrap right">';
2392  print $facturestatic->getLibStatut(5, $paiement);
2393  print "</td>";
2394  if (!$i) {
2395  $totalarray['nbfield']++;
2396  }
2397  }
2398 
2399  // Action column (Show the massaction button only when this page is not opend from the Extended POS)
2400  print '<td class="nowrap" align="center">';
2401  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
2402  $selected = 0;
2403  if (in_array($obj->id, $arrayofselected)) {
2404  $selected = 1;
2405  }
2406  print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
2407  }
2408  print '</td>';
2409  if (!$i) {
2410  $totalarray['nbfield']++;
2411  }
2412 
2413  print "</tr>\n";
2414 
2415  $i++;
2416  }
2417 
2418  // Show total line
2419  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2420  }
2421 
2422  // If no record found
2423  if ($num == 0) {
2424  $colspan = 1;
2425  foreach ($arrayfields as $key => $val) {
2426  if (!empty($val['checked'])) {
2427  $colspan++;
2428  }
2429  }
2430  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2431  }
2432 
2433  $db->free($resql);
2434 
2435  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2436  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
2437  print $hookmanager->resPrint;
2438 
2439  print '</table>'."\n";
2440  print '</div>'."\n";
2441 
2442  print '</form>'."\n";
2443 
2444  // Show the file area only when this page is not opend from the Extended POS
2445  if ($contextpage != 'poslist') {
2446  $hidegeneratedfilelistifempty = 1;
2447  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2448  $hidegeneratedfilelistifempty = 0;
2449  }
2450 
2451  // Show list of available documents
2452  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2453  $urlsource .= str_replace('&amp;', '&', $param);
2454 
2455  $filedir = $diroutputmassaction;
2456  $genallowed = $user->rights->facture->lire;
2457  $delallowed = $user->rights->facture->creer;
2458  $title = '';
2459 
2460  print $formfile->showdocuments('massfilesarea_invoices', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2461  }
2462 } else {
2463  dol_print_error($db);
2464 }
2465 
2466 // End of page
2467 llxFooter();
2468 $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