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