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