dolibarr  13.0.2
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-2016 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 Alexandre Spangaro <aspangaro@open-dsi.fr>
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program. If not, see <https://www.gnu.org/licenses/>.
30  */
31 
38 require '../../main.inc.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42 if (!empty($conf->margin->enabled)) {
43  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
44 }
45 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
46 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
55 if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
56 
57 // Load translation files required by the page
58 $langs->loadLangs(array('bills', 'companies', 'products', 'categories'));
59 
60 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
61 $projectid = (GETPOST('projectid') ?GETPOST('projectid', 'int') : 0);
62 
63 $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
64 $ref = GETPOST('ref', 'alpha');
65 $socid = GETPOST('socid', 'int');
66 
67 $action = GETPOST('action', 'aZ09');
68 $massaction = GETPOST('massaction', 'alpha');
69 $show_files = GETPOST('show_files', 'int');
70 $confirm = GETPOST('confirm', 'alpha');
71 $toselect = GETPOST('toselect', 'array');
72 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicelist';
73 
74 if ($contextpage == 'poslist')
75 {
76  $_GET['optioncss'] = 'print';
77 }
78 
79 $lineid = GETPOST('lineid', 'int');
80 $userid = GETPOST('userid', 'int');
81 $search_product_category = GETPOST('search_product_category', 'int');
82 $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
83 $search_refcustomer = GETPOST('search_refcustomer', 'alpha');
84 $search_type = GETPOST('search_type', 'int');
85 $search_project_ref = GETPOST('search_project_ref', 'alpha');
86 $search_project = GETPOST('search_project', 'alpha');
87 $search_societe = GETPOST('search_societe', 'alpha');
88 $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
89 $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
90 $search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
91 $search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
92 $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
93 $search_login = GETPOST('search_login', 'alpha');
94 $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
95 $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
96 $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
97 $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
98 $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
99 $search_status = GETPOST('search_status', 'intcomma');
100 $search_paymentmode = GETPOST('search_paymentmode', 'int');
101 $search_paymentterms = GETPOST('search_paymentterms', 'int');
102 $search_module_source = GETPOST('search_module_source', 'alpha');
103 $search_pos_source = GETPOST('search_pos_source', 'alpha');
104 $search_town = GETPOST('search_town', 'alpha');
105 $search_zip = GETPOST('search_zip', 'alpha');
106 $search_state = GETPOST("search_state");
107 $search_country = GETPOST("search_country", 'int');
108 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
109 $search_user = GETPOST('search_user', 'int');
110 $search_sale = GETPOST('search_sale', 'int');
111 $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
112 $search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
113 $search_date_valid_start = dol_mktime(0, 0, 0, GETPOST('search_date_valid_startmonth', 'int'), GETPOST('search_date_valid_startday', 'int'), GETPOST('search_date_valid_startyear', 'int'));
114 $search_date_valid_end = dol_mktime(23, 59, 59, GETPOST('search_date_valid_endmonth', 'int'), GETPOST('search_date_valid_endday', 'int'), GETPOST('search_date_valid_endyear', 'int'));
115 $search_datelimit_start = dol_mktime(0, 0, 0, GETPOST('search_datelimit_startmonth', 'int'), GETPOST('search_datelimit_startday', 'int'), GETPOST('search_datelimit_startyear', 'int'));
116 $search_datelimit_end = dol_mktime(23, 59, 59, GETPOST('search_datelimit_endmonth', 'int'), GETPOST('search_datelimit_endday', 'int'), GETPOST('search_datelimit_endyear', 'int'));
117 $search_categ_cus = GETPOST("search_categ_cus", 'int');
118 $search_btn = GETPOST('button_search', 'alpha');
119 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
120 
121 $option = GETPOST('search_option');
122 if ($option == 'late') {
123  $search_status = '1';
124 }
125 $filtre = GETPOST('filtre', 'alpha');
126 
127 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
128 $sortfield = GETPOST("sortfield", 'alpha');
129 $sortorder = GETPOST("sortorder", 'alpha');
130 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
131 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters
132 $offset = $limit * $page;
133 if (!$sortorder && !empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == '1') $sortorder = $conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER;
134 if (!$sortorder) $sortorder = 'DESC';
135 if (!$sortfield) $sortfield = 'f.datef';
136 $pageprev = $page - 1;
137 $pagenext = $page + 1;
138 
139 // Security check
140 $fieldid = (!empty($ref) ? 'ref' : 'rowid');
141 if (!empty($user->socid)) $socid = $user->socid;
142 $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
143 
144 $diroutputmassaction = $conf->facture->dir_output.'/temp/massgeneration/'.$user->id;
145 
146 $object = new Facture($db);
147 
148 $now = dol_now();
149 
150 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
151 $object = new Facture($db);
152 $hookmanager->initHooks(array('invoicelist'));
153 $extrafields = new ExtraFields($db);
154 
155 // fetch optionals attributes and labels
156 $extrafields->fetch_name_optionals_label($object->table_element);
157 
158 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
159 
160 // List of fields to search into when doing a "search in all"
161 $fieldstosearchall = array(
162  'f.ref'=>'Ref',
163  'f.ref_client'=>'RefCustomer',
164  'pd.description'=>'Description',
165  's.nom'=>"ThirdParty",
166  's.name_alias'=>"AliasNameShort",
167  's.zip'=>"Zip",
168  's.town'=>"Town",
169  'f.note_public'=>'NotePublic',
170 );
171 if (empty($user->socid)) $fieldstosearchall["f.note_private"] = "NotePrivate";
172 
173 $checkedtypetiers = 0;
174 $arrayfields = array(
175  'f.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>5),
176  'f.ref_client'=>array('label'=>"RefCustomer", 'checked'=>1, 'position'=>10),
177  'f.type'=>array('label'=>"Type", 'checked'=>0, 'position'=>15),
178  'f.date'=>array('label'=>"DateInvoice", 'checked'=>1, 'position'=>20),
179  'f.date_valid'=>array('label'=>"DateValidation", 'checked'=>0, 'position'=>22),
180  'f.date_lim_reglement'=>array('label'=>"DateDue", 'checked'=>1, 'position'=>25),
181  'f.date_closing'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>30),
182  'p.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1), 'position'=>40),
183  'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1), 'position'=>40),
184  's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>50),
185  's.town'=>array('label'=>"Town", 'checked'=>1, 'position'=>55),
186  's.zip'=>array('label'=>"Zip", 'checked'=>1, 'position'=>60),
187  'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>65),
188  'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>70),
189  'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>75),
190  'f.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>80),
191  'f.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>1, 'position'=>85),
192  'f.module_source'=>array('label'=>"Module", 'checked'=>($contextpage == 'poslist' ? 1 : 0), 'enabled'=>($conf->cashdesk->enabled || $conf->takepos->enabled || $conf->global->INVOICE_SHOW_POS), 'position'=>90),
193  'f.pos_source'=>array('label'=>"Terminal", 'checked'=>($contextpage == 'poslist' ? 1 : 0), 'enabled'=>($conf->cashdesk->enabled || $conf->takepos->enabled || $conf->global->INVOICE_SHOW_POS), 'position'=>91),
194  'f.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>95),
195  'f.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>100),
196  'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax1_assuj == "1"), 'position'=>110),
197  'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax2_assuj == "1"), 'position'=>120),
198  'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>130),
199  'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>135),
200  'dynamount_payed'=>array('label'=>"Received", 'checked'=>0, 'position'=>140),
201  'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>150), // Not enabled by default because slow
202  'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>160),
203  'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>170),
204  'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>180),
205  'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>190),
206  'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>200),
207  'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>210),
208  'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>220), // Not enabled by default because slow
209  'total_pa' => array('label' => ($conf->global->MARGIN_TYPE == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)),
210  'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)),
211  'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)),
212  'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)),
213  'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
214  'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
215  'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
216  'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
217  'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
218 );
219 
220 if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_RETAINED_WARRANTY)
221 {
222  $arrayfields['f.retained_warranty'] = array('label'=>$langs->trans("RetainedWarranty"), 'checked'=>0, 'position'=>86);
223 }
224 
225 // Extra fields
226 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
227 
228 $object->fields = dol_sort_array($object->fields, 'position');
229 $arrayfields = dol_sort_array($arrayfields, 'position');
230 
231 
232 /*
233  * Actions
234  */
235 
236 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
237 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
238 
239 $parameters = array('socid'=>$socid);
240 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
241 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
242 
243 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
244 
245 // Do we click on purge search criteria ?
246 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
247 {
248  $search_user = '';
249  $search_sale = '';
250  $search_product_category = '';
251  $search_ref = '';
252  $search_refcustomer = '';
253  $search_type = '';
254  $search_project_ref = '';
255  $search_project = '';
256  $search_societe = '';
257  $search_montant_ht = '';
258  $search_montant_vat = '';
259  $search_montant_localtax1 = '';
260  $search_montant_localtax2 = '';
261  $search_montant_ttc = '';
262  $search_login = '';
263  $search_multicurrency_code = '';
264  $search_multicurrency_tx = '';
265  $search_multicurrency_montant_ht = '';
266  $search_multicurrency_montant_vat = '';
267  $search_multicurrency_montant_ttc = '';
268  $search_status = '';
269  $search_paymentmode = '';
270  $search_paymentterms = '';
271  $search_module_source = '';
272  $search_pos_source = '';
273  $search_town = '';
274  $search_zip = "";
275  $search_state = "";
276  $search_type = '';
277  $search_country = '';
278  $search_type_thirdparty = '';
279  $search_date_start = '';
280  $search_date_end = '';
281  $search_date_valid_start = '';
282  $search_date_valid_end = '';
283  $search_datelimit_start = '';
284  $search_datelimit_end = '';
285  $option = '';
286  $filter = '';
287  $toselect = '';
288  $search_array_options = array();
289  $search_categ_cus = 0;
290 }
291 
292 if (empty($reshook))
293 {
294  $objectclass = 'Facture';
295  $objectlabel = 'Invoices';
296  $permissiontoread = $user->rights->facture->lire;
297  $permissiontoadd = $user->rights->facture->creer;
298  $permissiontodelete = $user->rights->facture->supprimer;
299  $uploaddir = $conf->facture->dir_output;
300  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
301 }
302 
303 if ($massaction == 'makepayment') {
304  $arrayofselected = is_array($toselect) ? $toselect : array();
305 
306  $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected);
307 
308  header('Location: '.$loc);
309  exit;
310 } elseif ($massaction == 'withdrawrequest') {
311  $langs->load("withdrawals");
312 
313  if (!$user->rights->prelevement->bons->creer) {
314  $error++;
315  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
316  } else {
317  //Checking error
318  $error = 0;
319 
320  $arrayofselected = is_array($toselect) ? $toselect : array();
321  $listofbills = array();
322  foreach ($arrayofselected as $toselectid)
323  {
324  $objecttmp = new Facture($db);
325  $result = $objecttmp->fetch($toselectid);
326  if ($result > 0) {
327  $totalpaye = $objecttmp->getSommePaiement();
328  $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
329  $totaldeposits = $objecttmp->getSumDepositsUsed();
330  $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
331  if ($objecttmp->paye || $objecttmp->resteapayer == 0) {
332  $error++;
333  setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
334  } elseif ($objecttmp->resteapayer < 0) {
335  $error++;
336  setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
337  }
338  if (!($objecttmp->statut > Facture::STATUS_DRAFT)) {
339  $error++;
340  setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
341  }
342 
343  $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
344  $rsql .= " , pfd.date_traite as date_traite";
345  $rsql .= " , pfd.amount";
346  $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
347  $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
348  $rsql .= " , ".MAIN_DB_PREFIX."user as u";
349  $rsql .= " WHERE fk_facture = ".$objecttmp->id;
350  $rsql .= " AND pfd.fk_user_demande = u.rowid";
351  $rsql .= " AND pfd.traite = 0";
352  $rsql .= " ORDER BY pfd.date_demande DESC";
353 
354  $result_sql = $db->query($rsql);
355  if ($result_sql)
356  {
357  $numprlv = $db->num_rows($result_sql);
358  }
359 
360  if ($numprlv > 0) {
361  $error++;
362  setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
363  } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'PRE') {
364  $error++;
365  setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
366  } else {
367  $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
368  }
369  }
370  }
371 
372  //Massive withdraw request for request with no errors
373  if (!empty($listofbills))
374  {
375  $nbwithdrawrequestok = 0;
376  foreach ($listofbills as $aBill)
377  {
378  $db->begin();
379  $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'direct-debit', 'facture');
380  if ($result > 0)
381  {
382  $db->commit();
383  $nbwithdrawrequestok++;
384  } else {
385  $db->rollback();
386  setEventMessages($aBill->error, $aBill->errors, 'errors');
387  }
388  }
389  if ($nbwithdrawrequestok > 0)
390  {
391  setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
392  }
393  }
394  }
395 }
396 
397 
398 
399 /*
400  * View
401  */
402 
403 $form = new Form($db);
404 $formother = new FormOther($db);
405 $formfile = new FormFile($db);
406 $formmargin = null;
407 if (!empty($conf->margin->enabled)) {
408  $formmargin = new FormMargin($db);
409 }
410 $bankaccountstatic = new Account($db);
411 $facturestatic = new Facture($db);
412 $formcompany = new FormCompany($db);
413 $thirdpartystatic = new Societe($db);
414 
415 $sql = 'SELECT';
416 if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT';
417 $sql .= ' f.rowid as id, f.ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';
418 $sql .= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
419 $sql .= ' f.fk_user_author,';
420 $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,';
421 $sql .= ' f.datef as df, f.date_valid, f.date_lim_reglement as datelimite, f.module_source, f.pos_source,';
422 $sql .= ' f.paye as paye, f.fk_statut, f.close_code,';
423 $sql .= ' f.datec as date_creation, f.tms as date_update, f.date_closing as date_closing,';
424 $sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
425 $sql .= ' s.rowid as socid, s.nom as name, s.email, 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,';
426 $sql .= " typent.code as typent_code,";
427 $sql .= " state.code_departement as state_code, state.nom as state_name,";
428 $sql .= " country.code as country_code,";
429 $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
430 $sql .= " u.login";
431 // 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)
432 // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
433 if (!$sall) $sql .= ', SUM(pf.amount) as dynamount_payed, SUM(pf.multicurrency_amount) as multicurrency_dynamount_payed';
434 if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc";
435 // Add fields from extrafields
436 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
437  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
438 }
439 // Add fields from hooks
440 $parameters = array();
441 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
442 $sql .= $hookmanager->resPrint;
443 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
444 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
445 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
446 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
447 if (!empty($search_categ_cus)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
448 
449 $sql .= ', '.MAIN_DB_PREFIX.'facture as f';
450 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
451 if (!$sall) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
452 if ($sall || $search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
453 if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
454 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
455 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
456 // We'll need this table joined to the select in order to filter by sale
457 if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
458 if ($search_user > 0)
459 {
460  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
461  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
462 }
463 
464 $sql .= ' WHERE f.fk_soc = s.rowid';
465 $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
466 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
467 if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$db->escape($search_product_category);
468 if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;
469 if ($userid)
470 {
471  if ($userid == -1) $sql .= ' AND f.fk_user_author IS NULL';
472  else $sql .= ' AND f.fk_user_author = '.$userid;
473 }
474 if ($filtre)
475 {
476  $aFilter = explode(',', $filtre);
477  foreach ($aFilter as $filter)
478  {
479  $filt = explode(':', $filter);
480  $sql .= ' AND '.$db->escape(trim($filt[0])).' = '.$db->escape(trim($filt[1]));
481  }
482 }
483 if ($search_ref) $sql .= natural_search('f.ref', $search_ref);
484 if ($search_refcustomer) $sql .= natural_search('f.ref_client', $search_refcustomer);
485 if ($search_type != '' && $search_type != '-1') $sql .= " AND f.type IN (".$db->sanitize($db->escape($search_type)).")";
486 if ($search_project_ref) $sql .= natural_search('p.ref', $search_project_ref);
487 if ($search_project) $sql .= natural_search('p.title', $search_project);
488 if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
489 if ($search_town) $sql .= natural_search('s.town', $search_town);
490 if ($search_zip) $sql .= natural_search("s.zip", $search_zip);
491 if ($search_state) $sql .= natural_search("state.nom", $search_state);
492 if ($search_country) $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
493 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
494 if ($search_company) $sql .= natural_search('s.nom', $search_company);
495 if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1);
496 if ($search_montant_vat != '') $sql .= natural_search('f.tva', $search_montant_vat, 1);
497 if ($search_montant_localtax1 != '') $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
498 if ($search_montant_localtax2 != '') $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
499 if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
500 if ($search_multicurrency_code != '') $sql .= ' AND f.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"';
501 if ($search_multicurrency_tx != '') $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
502 if ($search_multicurrency_montant_ht != '') $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
503 if ($search_multicurrency_montant_vat != '') $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
504 if ($search_multicurrency_montant_ttc != '') $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
505 if ($search_login) $sql .= natural_search('u.login', $search_login);
506 if ($search_categ_cus > 0) $sql .= " AND cc.fk_categorie = ".$db->escape($search_categ_cus);
507 if ($search_categ_cus == -2) $sql .= " AND cc.fk_categorie IS NULL";
508 if ($search_status != '-1' && $search_status != '')
509 {
510  if (is_numeric($search_status) && $search_status >= 0)
511  {
512  if ($search_status == '0') $sql .= " AND f.fk_statut = 0"; // draft
513  if ($search_status == '1') $sql .= " AND f.fk_statut = 1"; // unpayed
514  if ($search_status == '2') $sql .= " AND f.fk_statut = 2"; // payed Not that some corrupted data may contains f.fk_statut = 1 AND f.paye = 1 (it means payed too but should not happend. If yes, reopen and reclassify billed)
515  if ($search_status == '3') $sql .= " AND f.fk_statut = 3"; // abandonned
516  } else {
517  $sql .= " AND f.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; // When search_status is '1,2' for example
518  }
519 }
520 
521 if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$db->escape($search_paymentmode);
522 if ($search_paymentterms > 0) $sql .= " AND f.fk_cond_reglement = ".$db->escape($search_paymentterms);
523 if ($search_module_source) $sql .= natural_search("f.module_source", $search_module_source);
524 if ($search_pos_source) $sql .= natural_search("f.pos_source", $search_pos_source);
525 if ($search_date_start) $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
526 if ($search_date_end) $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
527 if ($search_date_valid_start) $sql .= " AND f.date_valid >= '".$db->idate($search_date_valid_start)."'";
528 if ($search_date_valid_end) $sql .= " AND f.date_valid <= '".$db->idate($search_date_valid_end)."'";
529 if ($search_datelimit_start) $sql .= " AND f.date_lim_reglement >= '".$db->idate($search_datelimit_start)."'";
530 if ($search_datelimit_end) $sql .= " AND f.date_lim_reglement <= '".$db->idate($search_datelimit_end)."'";
531 if ($option == 'late') $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
532 if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".(int) $search_sale;
533 if ($search_user > 0)
534 {
535  $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
536 }
537 // Add where from extra fields
538 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
539 // Add where from hooks
540 $parameters = array();
541 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
542 $sql .= $hookmanager->resPrint;
543 
544 if (!$sall)
545 {
546  $sql .= ' GROUP BY f.rowid, f.ref, ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total, f.tva, f.total_ttc,';
547  $sql .= ' f.localtax1, f.localtax2,';
548  $sql .= ' f.datef, f.date_valid, f.date_lim_reglement, f.module_source, f.pos_source,';
549  $sql .= ' f.paye, f.fk_statut, f.close_code,';
550  $sql .= ' f.datec, f.tms, f.date_closing,';
551  $sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
552  $sql .= ' f.fk_user_author, f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva,';
553  $sql .= ' f.multicurrency_total_tva, f.multicurrency_total_ttc,';
554  $sql .= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,';
555  $sql .= ' typent.code,';
556  $sql .= ' state.code_departement, state.nom,';
557  $sql .= ' country.code,';
558  $sql .= " p.rowid, p.ref, p.title,";
559  $sql .= " u.login";
560  if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc";
561  // Add fields from extrafields
562  if (!empty($extrafields->attributes[$object->table_element]['label'])) {
563  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
564  }
565 } else {
566  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
567 }
568 
569 $sql .= ' ORDER BY ';
570 $listfield = explode(',', $sortfield);
571 $listorder = explode(',', $sortorder);
572 foreach ($listfield as $key => $value) $sql .= $listfield[$key].' '.($listorder[$key] ? $listorder[$key] : 'DESC').',';
573 $sql .= ' f.rowid DESC ';
574 
575 $nbtotalofrecords = '';
576 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
577 {
578  $result = $db->query($sql);
579  $nbtotalofrecords = $db->num_rows($result);
580  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
581  {
582  $page = 0;
583  $offset = 0;
584  }
585 }
586 
587 $sql .= $db->plimit($limit + 1, $offset);
588 
589 $resql = $db->query($sql);
590 
591 if ($resql)
592 {
593  $num = $db->num_rows($resql);
594 
595  $arrayofselected = is_array($toselect) ? $toselect : array();
596 
597  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
598  {
599  $obj = $db->fetch_object($resql);
600  $id = $obj->id;
601 
602  header("Location: ".DOL_URL_ROOT.'/compta/facture/card.php?facid='.$id);
603  exit;
604  }
605 
606  llxHeader('', $langs->trans('CustomersInvoices'), 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
607 
608  if ($socid)
609  {
610  $soc = new Societe($db);
611  $soc->fetch($socid);
612  if (empty($search_societe)) $search_societe = $soc->name;
613  }
614 
615  $param = '&socid='.$socid;
616  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
617  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
618  if ($sall) $param .= '&sall='.urlencode($sall);
619  if ($search_date_start) $param .= '&search_date_start='.urlencode($search_date_start);
620  if ($search_date_end) $param .= '&search_date_end='.urlencode($search_date_end);
621  if ($search_date_valid_start) $param .= '&search_date_valid_start='.urlencode($search_date_valid_start);
622  if ($search_date_valid_end) $param .= '&search_date_valid_end='.urlencode($search_date_valid_end);
623  if ($search_datelimit_start) $param .= '&search_datelimit_start='.urlencode($search_datelimit_start);
624  if ($search_datelimit_end) $param .= '&search_datelimit_end='.urlencode($search_datelimit_end);
625  if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
626  if ($search_refcustomer) $param .= '&search_refcustomer='.urlencode($search_refcustomer);
627  if ($search_project_ref) $param .= '&search_project_ref='.urlencode($search_project_ref);
628  if ($search_project) $param .= '&search_project='.urlencode($search_project);
629  if ($search_type != '') $param .= '&search_type='.urlencode($search_type);
630  if ($search_societe) $param .= '&search_societe='.urlencode($search_societe);
631  if ($search_town) $param .= '&search_town='.urlencode($search_town);
632  if ($search_zip) $param .= '&search_zip='.urlencode($search_zip);
633  if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale);
634  if ($search_user > 0) $param .= '&search_user='.urlencode($search_user);
635  if ($search_login) $param .= '&search_login='.urlencode($search_login);
636  if ($search_product_category > 0) $param .= '&search_product_category='.urlencode($search_product_category);
637  if ($search_montant_ht != '') $param .= '&search_montant_ht='.urlencode($search_montant_ht);
638  if ($search_montant_vat != '') $param .= '&search_montant_vat='.urlencode($search_montant_vat);
639  if ($search_montant_localtax1 != '') $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
640  if ($search_montant_localtax2 != '') $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
641  if ($search_montant_ttc != '') $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
642  if ($search_multicurrency_code != '') $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
643  if ($search_multicurrency_tx != '') $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
644  if ($search_multicurrency_montant_ht != '') $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
645  if ($search_multicurrency_montant_vat != '') $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
646  if ($search_multicurrency_montant_ttc != '') $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
647  if ($search_status != '') $param .= '&search_status='.urlencode($search_status);
648  if ($search_paymentmode > 0) $param .= '&search_paymentmode='.urlencode($search_paymentmode);
649  if ($search_paymentterms > 0) $param .= '&search_paymentterms='.urlencode($search_paymentterms);
650  if ($search_module_source) $param .= '&search_module_source='.urlencode($search_module_source);
651  if ($search_pos_source) $param .= '&search_pos_source='.urlencode($search_pos_source);
652  if ($show_files) $param .= '&show_files='.urlencode($show_files);
653  if ($option) $param .= "&search_option=".urlencode($option);
654  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
655  if ($search_categ_cus > 0) $param .= '&search_categ_cus='.urlencode($search_categ_cus);
656 
657  // Add $param from extra fields
658  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
659 
660  $arrayofmassactions = array(
661  'validate'=>$langs->trans("Validate"),
662  'generate_doc'=>$langs->trans("ReGeneratePDF"),
663  'builddoc'=>$langs->trans("PDFMerge"),
664  'presend'=>$langs->trans("SendByMail"),
665  //'makepayment'=>$langs->trans("InvoicePaymentsLimits"), TODO Blank page when using this
666  );
667  if ($conf->prelevement->enabled && !empty($user->rights->prelevement->bons->creer)) {
668  $langs->load("withdrawals");
669  $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest");
670  }
671  if ($user->rights->facture->supprimer) {
672  if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) {
673  $arrayofmassactions['predeletedraft'] = $langs->trans("Deletedraft");
674  } elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { // mass deletion never possible on invoices on such situation
675  $arrayofmassactions['predelete'] = $langs->trans("Delete");
676  }
677  }
678  if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
679  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
680 
681  // Show the new button only when this page is not opend from the Extended POS
682  if ($contextpage != 'poslist')
683  {
684  $url = DOL_URL_ROOT.'/compta/facture/card.php?action=create';
685  if (!empty($socid)) $url .= '&socid='.$socid;
686  $newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', $user->rights->facture->creer);
687  }
688 
689  $i = 0;
690  print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
691 
692  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
693  print '<input type="hidden" name="token" value="'.newToken().'">';
694  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
695  print '<input type="hidden" name="action" value="list">';
696  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
697  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
698  print '<input type="hidden" name="search_status" value="'.$search_status.'">';
699  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
700 
701  print_barre_liste($langs->trans('BillsCustomers').' '.($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
702 
703  $topicmail = "SendBillRef";
704  $modelmail = "facture_send";
705  $objecttmp = new Facture($db);
706  $trackid = 'inv'.$object->id;
707  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
708 
709  if ($sall)
710  {
711  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
712  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
713  }
714 
715  // If the user can view prospects other than his'
716  $moreforfilter = '';
717  if ($user->rights->societe->client->voir || $socid)
718  {
719  $langs->load("commercial");
720  $moreforfilter .= '<div class="divsearchfield">';
721  $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': ';
722  $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
723  $moreforfilter .= '</div>';
724  }
725  // If the user can view prospects other than his'
726  if ($user->rights->societe->client->voir || $socid)
727  {
728  $moreforfilter .= '<div class="divsearchfield">';
729  $moreforfilter .= $langs->trans('LinkedToSpecificUsers').': ';
730  $moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
731  $moreforfilter .= '</div>';
732  }
733  // If the user can view prospects other than his'
734  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire))
735  {
736  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
737  $moreforfilter .= '<div class="divsearchfield">';
738  $moreforfilter .= $langs->trans('IncludingProductWithTag').': ';
739  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
740  $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
741  $moreforfilter .= '</div>';
742  }
743  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire)
744  {
745  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
746  $moreforfilter .= '<div class="divsearchfield">';
747  $moreforfilter .= $langs->trans('CustomersProspectsCategoriesShort').': ';
748  $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1);
749  $moreforfilter .= '</div>';
750  }
751  $parameters = array();
752  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
753  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
754  else $moreforfilter = $hookmanager->resPrint;
755 
756  if ($moreforfilter)
757  {
758  print '<div class="liste_titre liste_titre_bydiv centpercent">';
759  print $moreforfilter;
760  print '</div>';
761  }
762 
763  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
764  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
765  // Show the massaction checkboxes only when this page is not opend from the Extended POS
766  if ($massactionbutton && $contextpage != 'poslist') $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
767 
768  print '<div class="div-table-responsive">';
769  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
770 
771  // Filters lines
772  print '<tr class="liste_titre_filter">';
773  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
774  print '<td class="liste_titre">';
775  print '</td>';
776  }
777  // Ref
778  if (!empty($arrayfields['f.ref']['checked']))
779  {
780  print '<td class="liste_titre" align="left">';
781  print '<input class="flat maxwidth50imp" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
782  print '</td>';
783  }
784  // Ref customer
785  if (!empty($arrayfields['f.ref_client']['checked']))
786  {
787  print '<td class="liste_titre">';
788  print '<input class="flat maxwidth50imp" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
789  print '</td>';
790  }
791  // Type
792  if (!empty($arrayfields['f.type']['checked']))
793  {
794  print '<td class="liste_titre maxwidthonsmartphone">';
795  $listtype = array(
796  Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
797  Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
798  Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
799  Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
800  );
801  if (!empty($conf->global->INVOICE_USE_SITUATION))
802  {
803  $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
804  }
805  //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
806  print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
807  print '</td>';
808  }
809  // Date invoice
810  if (!empty($arrayfields['f.date']['checked']))
811  {
812  print '<td class="liste_titre center">';
813  print '<div class="nowrap">';
814  print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
815  print '</div>';
816  print '<div class="nowrap">';
817  print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
818  print '</div>';
819  print '</td>';
820  }
821  // Date valid
822  if (!empty($arrayfields['f.date_valid']['checked']))
823  {
824  print '<td class="liste_titre center">';
825  print '<div class="nowrap">';
826  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'));
827  print '</div>';
828  print '<div class="nowrap">';
829  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'));
830  print '</div>';
831  print '</td>';
832  }
833  // Date due
834  if (!empty($arrayfields['f.date_lim_reglement']['checked']))
835  {
836  print '<td class="liste_titre center">';
837  print '<div class="nowrap">';
838  /*
839  print $langs->trans('From').' ';
840  print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
841  print '</div>';
842  print '<div class="nowrap">';
843  print $langs->trans('to').' ';*/
844  print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
845  print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
846  print '</div>';
847  print '</td>';
848  }
849  // Project ref
850  if (!empty($arrayfields['p.ref']['checked']))
851  {
852  print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project_ref" value="'.$search_project_ref.'"></td>';
853  }
854  // Project label
855  if (!empty($arrayfields['p.title']['checked']))
856  {
857  print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.$search_project.'"></td>';
858  }
859  // Thirdparty
860  if (!empty($arrayfields['s.nom']['checked']))
861  {
862  print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_societe" value="'.$search_societe.'"></td>';
863  }
864  // Town
865  if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
866  // Zip
867  if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
868  // State
869  if (!empty($arrayfields['state.nom']['checked']))
870  {
871  print '<td class="liste_titre">';
872  print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
873  print '</td>';
874  }
875  // Country
876  if (!empty($arrayfields['country.code_iso']['checked']))
877  {
878  print '<td class="liste_titre" align="center">';
879  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
880  print '</td>';
881  }
882  // Company type
883  if (!empty($arrayfields['typent.code']['checked']))
884  {
885  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
886  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'maxwidth100');
887  print '</td>';
888  }
889  // Payment mode
890  if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
891  {
892  print '<td class="liste_titre">';
893  $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 10);
894  print '</td>';
895  }
896  // Payment terms
897  if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
898  {
899  print '<td class="liste_titre">';
900  $form->select_conditions_paiements($search_paymentterms, 'search_paymentterms', -1, 1, 1);
901  print '</td>';
902  }
903  // Module source
904  if (!empty($arrayfields['f.module_source']['checked']))
905  {
906  print '<td class="liste_titre">';
907  print '<input class="flat maxwidth75" type="text" name="search_module_source" value="'.dol_escape_htmltag($search_module_source).'">';
908  print '</td>';
909  }
910  // POS Terminal
911  if (!empty($arrayfields['f.pos_source']['checked']))
912  {
913  print '<td class="liste_titre">';
914  print '<input class="flat maxwidth50" type="text" name="search_pos_source" value="'.dol_escape_htmltag($search_pos_source).'">';
915  print '</td>';
916  }
917  if (!empty($arrayfields['f.total_ht']['checked']))
918  {
919  // Amount
920  print '<td class="liste_titre right">';
921  print '<input class="flat" type="text" size="4" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
922  print '</td>';
923  }
924  if (!empty($arrayfields['f.total_vat']['checked']))
925  {
926  // Amount
927  print '<td class="liste_titre right">';
928  print '<input class="flat" type="text" size="4" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
929  print '</td>';
930  }
931  if (!empty($arrayfields['f.total_localtax1']['checked']))
932  {
933  // Localtax1
934  print '<td class="liste_titre right">';
935  print '<input class="flat" type="text" size="4" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
936  print '</td>';
937  }
938  if (!empty($arrayfields['f.total_localtax2']['checked']))
939  {
940  // Localtax2
941  print '<td class="liste_titre right">';
942  print '<input class="flat" type="text" size="4" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
943  print '</td>';
944  }
945  if (!empty($arrayfields['f.total_ttc']['checked']))
946  {
947  // Amount
948  print '<td class="liste_titre right">';
949  print '<input class="flat" type="text" size="4" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
950  print '</td>';
951  }
952  if (!empty($arrayfields['u.login']['checked']))
953  {
954  // Author
955  print '<td class="liste_titre" align="center">';
956  print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
957  print '</td>';
958  }
959  if (!empty($arrayfields['f.retained_warranty']['checked']))
960  {
961  print '<td class="liste_titre" align="right">';
962  print '</td>';
963  }
964  if (!empty($arrayfields['dynamount_payed']['checked']))
965  {
966  print '<td class="liste_titre right">';
967  print '</td>';
968  }
969  if (!empty($arrayfields['rtp']['checked']))
970  {
971  print '<td class="liste_titre right">';
972  print '</td>';
973  }
974  if (!empty($arrayfields['f.multicurrency_code']['checked']))
975  {
976  // Currency
977  print '<td class="liste_titre">';
978  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
979  print '</td>';
980  }
981  if (!empty($arrayfields['f.multicurrency_tx']['checked']))
982  {
983  // Currency rate
984  print '<td class="liste_titre">';
985  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
986  print '</td>';
987  }
988  if (!empty($arrayfields['f.multicurrency_total_ht']['checked']))
989  {
990  // Amount
991  print '<td class="liste_titre right">';
992  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
993  print '</td>';
994  }
995  if (!empty($arrayfields['f.multicurrency_total_vat']['checked']))
996  {
997  // Amount
998  print '<td class="liste_titre right">';
999  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1000  print '</td>';
1001  }
1002  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked']))
1003  {
1004  // Amount
1005  print '<td class="liste_titre right">';
1006  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1007  print '</td>';
1008  }
1009  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked']))
1010  {
1011  print '<td class="liste_titre">';
1012  print '</td>';
1013  }
1014  if (!empty($arrayfields['multicurrency_rtp']['checked']))
1015  {
1016  print '<td class="liste_titre right">';
1017  print '</td>';
1018  }
1019  if (!empty($arrayfields['f.date_closing']['checked']))
1020  {
1021  print '<td class="liste_titre">';
1022  print '</td>';
1023  }
1024  if (!empty($arrayfields['total_pa']['checked']))
1025  {
1026  print '<td class="liste_titre right">';
1027  print '</td>';
1028  }
1029  if (!empty($arrayfields['total_margin']['checked']))
1030  {
1031  print '<td class="liste_titre right">';
1032  print '</td>';
1033  }
1034  if (!empty($arrayfields['total_margin_rate']['checked']))
1035  {
1036  print '<td class="liste_titre right">';
1037  print '</td>';
1038  }
1039  if (!empty($arrayfields['total_mark_rate']['checked']))
1040  {
1041  print '<td class="liste_titre right">';
1042  print '</td>';
1043  }
1044 
1045  // Extra fields
1046  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1047 
1048  // Fields from hook
1049  $parameters = array('arrayfields'=>$arrayfields);
1050  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1051  print $hookmanager->resPrint;
1052  // Date creation
1053  if (!empty($arrayfields['f.datec']['checked']))
1054  {
1055  print '<td class="liste_titre">';
1056  print '</td>';
1057  }
1058  // Date modification
1059  if (!empty($arrayfields['f.tms']['checked']))
1060  {
1061  print '<td class="liste_titre">';
1062  print '</td>';
1063  }
1064  if (!empty($arrayfields['f.note_public']['checked']))
1065  {
1066  // Note public
1067  print '<td class="liste_titre">';
1068  print '</td>';
1069  }
1070  if (!empty($arrayfields['f.note_private']['checked']))
1071  {
1072  // Note private
1073  print '<td class="liste_titre">';
1074  print '</td>';
1075  }
1076  // Status
1077  if (!empty($arrayfields['f.fk_statut']['checked']))
1078  {
1079  print '<td class="liste_titre maxwidthonsmartphone right">';
1080  $liststatus = array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '1,2'=>$langs->trans("BillShortStatusNotPaid").'+'.$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled"));
1081  print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
1082  print '</td>';
1083  }
1084  // Action column
1085  print '<td class="liste_titre" align="middle">';
1086  $searchpicto = $form->showFilterButtons();
1087  print $searchpicto;
1088  print '</td>';
1089  print "</tr>\n";
1090 
1091  print '<tr class="liste_titre">';
1092  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1093  if (!empty($arrayfields['f.ref']['checked'])) print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref', '', $param, '', $sortfield, $sortorder);
1094  if (!empty($arrayfields['f.ref_client']['checked'])) print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], 'f.ref_client', '', $param, '', $sortfield, $sortorder);
1095  if (!empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
1096  if (!empty($arrayfields['f.date']['checked'])) print_liste_field_titre($arrayfields['f.date']['label'], $_SERVER['PHP_SELF'], 'f.datef', '', $param, 'align="center"', $sortfield, $sortorder);
1097  if (!empty($arrayfields['f.date_valid']['checked'])) print_liste_field_titre($arrayfields['f.date_valid']['label'], $_SERVER['PHP_SELF'], 'f.date_valid', '', $param, 'align="center"', $sortfield, $sortorder);
1098  if (!empty($arrayfields['f.date_lim_reglement']['checked'])) print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, 'align="center"', $sortfield, $sortorder);
1099  if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
1100  if (!empty($arrayfields['p.title']['checked'])) print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER['PHP_SELF'], "p.title", '', $param, '', $sortfield, $sortorder);
1101  if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
1102  if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1103  if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1104  if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1105  if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
1106  if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
1107  if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
1108  if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
1109  if (!empty($arrayfields['f.module_source']['checked'])) print_liste_field_titre($arrayfields['f.module_source']['label'], $_SERVER["PHP_SELF"], "f.module_source", "", $param, "", $sortfield, $sortorder);
1110  if (!empty($arrayfields['f.pos_source']['checked'])) print_liste_field_titre($arrayfields['f.pos_source']['label'], $_SERVER["PHP_SELF"], "f.pos_source", "", $param, "", $sortfield, $sortorder);
1111  if (!empty($arrayfields['f.total_ht']['checked'])) print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total', '', $param, 'class="right"', $sortfield, $sortorder);
1112  if (!empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.tva', '', $param, 'class="right"', $sortfield, $sortorder);
1113  if (!empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, 'class="right"', $sortfield, $sortorder);
1114  if (!empty($arrayfields['f.total_localtax2']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, 'class="right"', $sortfield, $sortorder);
1115  if (!empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1116  if (!empty($arrayfields['u.login']['checked'])) print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1117  if (!empty($arrayfields['f.retained_warranty']['checked'])) print_liste_field_titre($arrayfields['f.retained_warranty']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="right"', $sortfield, $sortorder);
1118  if (!empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1119  if (!empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1120  if (!empty($arrayfields['f.multicurrency_code']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1121  if (!empty($arrayfields['f.multicurrency_tx']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1122  if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1123  if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1124  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1125  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1126  if (!empty($arrayfields['multicurrency_rtp']['checked'])) print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1127  if (!empty($arrayfields['total_pa']['checked'])) print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1128  if (!empty($arrayfields['total_margin']['checked'])) print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1129  if (!empty($arrayfields['total_margin_rate']['checked'])) print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1130  if (!empty($arrayfields['total_mark_rate']['checked'])) print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1131  // Extra fields
1132  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1133  // Hook fields
1134  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1135  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1136  print $hookmanager->resPrint;
1137  if (!empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1138  if (!empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1139  if (!empty($arrayfields['f.date_closing']['checked'])) print_liste_field_titre($arrayfields['f.date_closing']['label'], $_SERVER["PHP_SELF"], "f.date_closing", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1140  if (!empty($arrayfields['f.note_public']['checked'])) print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1141  if (!empty($arrayfields['f.note_private']['checked'])) print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1142  if (!empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut,f.paye,f.type,dynamount_payed", "", $param, 'class="right"', $sortfield, $sortorder);
1143  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
1144  print "</tr>\n";
1145 
1146  $projectstatic = new Project($db);
1147  $discount = new DiscountAbsolute($db);
1148  $userstatic = new User($db);
1149 
1150  if ($num > 0)
1151  {
1152  $i = 0;
1153  $totalarray = array();
1154  while ($i < min($num, $limit))
1155  {
1156  $obj = $db->fetch_object($resql);
1157 
1158  $datelimit = $db->jdate($obj->datelimite);
1159 
1160  $facturestatic->id = $obj->id;
1161  $facturestatic->ref = $obj->ref;
1162  $facturestatic->ref_client = $obj->ref_client;
1163  $facturestatic->type = $obj->type;
1164  $facturestatic->total_ht = $obj->total_ht;
1165  $facturestatic->total_tva = $obj->total_vat;
1166  $facturestatic->total_ttc = $obj->total_ttc;
1167  $facturestatic->multicurrency_code = $obj->multicurrency_code;
1168  $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
1169  $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
1170  $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
1171  $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1172  $facturestatic->statut = $obj->fk_statut;
1173  $facturestatic->close_code = $obj->close_code;
1174  $facturestatic->total_ttc = $obj->total_ttc;
1175  $facturestatic->paye = $obj->paye;
1176  $facturestatic->fk_soc = $obj->fk_soc;
1177 
1178  $facturestatic->date = $db->jdate($obj->df);
1179  $facturestatic->date_valid = $db->jdate($obj->date_valid);
1180  $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
1181 
1182  $facturestatic->note_public = $obj->note_public;
1183  $facturestatic->note_private = $obj->note_private;
1184  if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_RETAINED_WARRANTY)
1185  {
1186  $facturestatic->retained_warranty = $obj->retained_warranty;
1187  $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit;
1188  $facturestatic->situation_final = $obj->retained_warranty_date_limit;
1189  $facturestatic->situation_final = $obj->retained_warranty_date_limit;
1190  $facturestatic->situation_cycle_ref = $obj->situation_cycle_ref;
1191  $facturestatic->situation_counter = $obj->situation_counter;
1192  }
1193  $thirdpartystatic->id = $obj->socid;
1194  $thirdpartystatic->name = $obj->name;
1195  $thirdpartystatic->client = $obj->client;
1196  $thirdpartystatic->fournisseur = $obj->fournisseur;
1197  $thirdpartystatic->code_client = $obj->code_client;
1198  $thirdpartystatic->code_compta_client = $obj->code_compta_client;
1199  $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
1200  $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1201  $thirdpartystatic->email = $obj->email;
1202  $thirdpartystatic->country_code = $obj->country_code;
1203 
1204  $projectstatic->id = $obj->project_id;
1205  $projectstatic->ref = $obj->project_ref;
1206  $projectstatic->title = $obj->project_label;
1207 
1208  $paiement = $facturestatic->getSommePaiement();
1209  $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
1210  $totaldeposits = $facturestatic->getSumDepositsUsed();
1211  $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
1212  $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
1213  $multicurrency_paiement = $facturestatic->getSommePaiement(1);
1214  $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
1215  $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
1216  $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
1217  $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
1218 
1219  if ($facturestatic->statut == Facture::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
1220  $remaintopay = 0;
1221  $multicurrency_remaintopay = 0;
1222  }
1223  if ($facturestatic->type == Facture::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consummed
1224  $remaincreditnote = $discount->getAvailableDiscounts($thirdpartystatic, '', 'rc.fk_facture_source='.$facturestatic->id);
1225  $remaintopay = -$remaincreditnote;
1226  $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
1227  $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdpartystatic, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
1228  $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
1229  $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
1230  }
1231 
1232  $facturestatic->alreadypaid = $paiement;
1233 
1234  $marginInfo = array();
1235  if (!empty($conf->margin->enabled)) {
1236  $facturestatic->fetch_lines();
1237  $marginInfo = $formmargin->getMarginInfosArray($facturestatic);
1238  }
1239 
1240  print '<tr class="oddeven"';
1241  if ($contextpage == 'poslist')
1242  {
1243  print ' onclick="parent.$(\'#poslines\').load(\'invoice.php?action=history&placeid='.$obj->id.'\', function() {parent.$.colorbox.close();});"';
1244  }
1245  print '>';
1246 
1247  // No
1248  if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
1249  print '<td>'.(($offset * $limit) + $i).'</td>';
1250  }
1251 
1252  // Ref
1253  if (!empty($arrayfields['f.ref']['checked']))
1254  {
1255  print '<td class="nowraponall">';
1256 
1257  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1258 
1259  print '<td class="nobordernopadding nowraponall">';
1260  if ($contextpage == 'poslist')
1261  {
1262  print $obj->ref;
1263  } else {
1264  print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1);
1265  }
1266 
1267  $filename = dol_sanitizeFileName($obj->ref);
1268  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1269  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->id;
1270  print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
1271  print '</td>';
1272  print '</tr>';
1273  print '</table>';
1274 
1275  print "</td>\n";
1276  if (!$i) $totalarray['nbfield']++;
1277  }
1278 
1279  // Customer ref
1280  if (!empty($arrayfields['f.ref_client']['checked']))
1281  {
1282  print '<td class="nowrap tdoverflowmax200">';
1283  print $obj->ref_client;
1284  print '</td>';
1285  if (!$i) $totalarray['nbfield']++;
1286  }
1287 
1288  // Type
1289  if (!empty($arrayfields['f.type']['checked']))
1290  {
1291  print '<td class="nowraponall tdoverflowmax100" title="'.$facturestatic->getLibType().'">';
1292  print $facturestatic->getLibType();
1293  print "</td>";
1294  if (!$i) $totalarray['nbfield']++;
1295  }
1296 
1297  // Date
1298  if (!empty($arrayfields['f.date']['checked']))
1299  {
1300  print '<td align="center" class="nowraponall">';
1301  print dol_print_date($db->jdate($obj->df), 'day');
1302  print '</td>';
1303  if (!$i) $totalarray['nbfield']++;
1304  }
1305 
1306  // Date
1307  if (!empty($arrayfields['f.date_valid']['checked']))
1308  {
1309  print '<td align="center" class="nowraponall">';
1310  print dol_print_date($db->jdate($obj->date_valid), 'day');
1311  print '</td>';
1312  if (!$i) $totalarray['nbfield']++;
1313  }
1314 
1315  // Date limit
1316  if (!empty($arrayfields['f.date_lim_reglement']['checked']))
1317  {
1318  print '<td align="center" class="nowraponall">'.dol_print_date($datelimit, 'day');
1319  if ($facturestatic->hasDelay())
1320  {
1321  print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
1322  }
1323  print '</td>';
1324  if (!$i) $totalarray['nbfield']++;
1325  }
1326 
1327  // Project ref
1328  if (!empty($arrayfields['p.ref']['checked']))
1329  {
1330  print '<td class="nocellnopadd nowraponall">';
1331  if ($obj->project_id > 0)
1332  {
1333  print $projectstatic->getNomUrl(1);
1334  }
1335  print '</td>';
1336  if (!$i) $totalarray['nbfield']++;
1337  }
1338 
1339  // Project title
1340  if (!empty($arrayfields['p.title']['checked']))
1341  {
1342  print '<td class="nowraponall">';
1343  if ($obj->project_id > 0)
1344  {
1345  print $projectstatic->title;
1346  }
1347  print '</td>';
1348  if (!$i) $totalarray['nbfield']++;
1349  }
1350 
1351  // Third party
1352  if (!empty($arrayfields['s.nom']['checked']))
1353  {
1354  print '<td class="tdoverflowmax200">';
1355  if ($contextpage == 'poslist')
1356  {
1357  print $thirdpartystatic->name;
1358  } else {
1359  print $thirdpartystatic->getNomUrl(1, 'customer');
1360  }
1361  print '</td>';
1362  if (!$i) $totalarray['nbfield']++;
1363  }
1364  // Town
1365  if (!empty($arrayfields['s.town']['checked']))
1366  {
1367  print '<td>';
1368  print $obj->town;
1369  print '</td>';
1370  if (!$i) $totalarray['nbfield']++;
1371  }
1372  // Zip
1373  if (!empty($arrayfields['s.zip']['checked']))
1374  {
1375  print '<td class="nowraponall">';
1376  print $obj->zip;
1377  print '</td>';
1378  if (!$i) $totalarray['nbfield']++;
1379  }
1380  // State
1381  if (!empty($arrayfields['state.nom']['checked']))
1382  {
1383  print "<td>".$obj->state_name."</td>\n";
1384  if (!$i) $totalarray['nbfield']++;
1385  }
1386  // Country
1387  if (!empty($arrayfields['country.code_iso']['checked']))
1388  {
1389  print '<td class="center">';
1390  $tmparray = getCountry($obj->fk_pays, 'all');
1391  print $tmparray['label'];
1392  print '</td>';
1393  if (!$i) $totalarray['nbfield']++;
1394  }
1395  // Type ent
1396  if (!empty($arrayfields['typent.code']['checked']))
1397  {
1398  print '<td class="center">';
1399  if (!is_array($typenArray) || count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
1400  print $typenArray[$obj->typent_code];
1401  print '</td>';
1402  if (!$i) $totalarray['nbfield']++;
1403  }
1404  // Staff
1405  if (!empty($arrayfields['staff.code']['checked']))
1406  {
1407  print '<td class="center">';
1408  if (!is_array($staffArray) || count($staffArray) == 0) $staffArray = $formcompany->effectif_array(1);
1409  print $staffArray[$obj->staff_code];
1410  print '</td>';
1411  if (!$i) $totalarray['nbfield']++;
1412  }
1413 
1414  // Payment mode
1415  if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
1416  {
1417  print '<td class="tdoverflowmax100">';
1418  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1419  print '</td>';
1420  if (!$i) $totalarray['nbfield']++;
1421  }
1422 
1423  // Payment terms
1424  if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
1425  {
1426  print '<td>';
1427  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
1428  print '</td>';
1429  if (!$i) $totalarray['nbfield']++;
1430  }
1431 
1432  // Module Source
1433  if (!empty($arrayfields['f.module_source']['checked']))
1434  {
1435  print '<td>';
1436  print $obj->module_source;
1437  print '</td>';
1438  if (!$i) $totalarray['nbfield']++;
1439  }
1440 
1441  // POS Terminal
1442  if (!empty($arrayfields['f.pos_source']['checked']))
1443  {
1444  print '<td>';
1445  print $obj->pos_source;
1446  print '</td>';
1447  if (!$i) $totalarray['nbfield']++;
1448  }
1449 
1450  // Amount HT
1451  if (!empty($arrayfields['f.total_ht']['checked']))
1452  {
1453  print '<td class="right nowraponall">'.price($obj->total_ht)."</td>\n";
1454  if (!$i) $totalarray['nbfield']++;
1455  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
1456  $totalarray['val']['f.total_ht'] += $obj->total_ht;
1457  }
1458  // Amount VAT
1459  if (!empty($arrayfields['f.total_vat']['checked']))
1460  {
1461  print '<td class="right nowraponall">'.price($obj->total_vat)."</td>\n";
1462  if (!$i) $totalarray['nbfield']++;
1463  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
1464  $totalarray['val']['f.total_vat'] += $obj->total_vat;
1465  }
1466  // Amount LocalTax1
1467  if (!empty($arrayfields['f.total_localtax1']['checked']))
1468  {
1469  print '<td class="right nowraponall">'.price($obj->total_localtax1)."</td>\n";
1470  if (!$i) $totalarray['nbfield']++;
1471  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
1472  $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
1473  }
1474  // Amount LocalTax2
1475  if (!empty($arrayfields['f.total_localtax2']['checked']))
1476  {
1477  print '<td class="right nowraponall">'.price($obj->total_localtax2)."</td>\n";
1478  if (!$i) $totalarray['nbfield']++;
1479  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
1480  $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
1481  }
1482  // Amount TTC
1483  if (!empty($arrayfields['f.total_ttc']['checked']))
1484  {
1485  print '<td class="right nowraponall">'.price($obj->total_ttc)."</td>\n";
1486  if (!$i) $totalarray['nbfield']++;
1487  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
1488  $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
1489  }
1490 
1491  // Author
1492  if (!empty($arrayfields['u.login']['checked']))
1493  {
1494  $userstatic->id = $obj->fk_user_author;
1495  $userstatic->login = $obj->login;
1496  print '<td class="center tdoverflowmax100">';
1497  if ($userstatic->id) print $userstatic->getLoginUrl(1);
1498  else print '&nbsp;';
1499  print "</td>\n";
1500  if (!$i) $totalarray['nbfield']++;
1501  }
1502 
1503  if (!empty($arrayfields['f.retained_warranty']['checked']))
1504  {
1505  print '<td align="right">'.(!empty($obj->retained_warranty) ?price($obj->retained_warranty).'%' : '&nbsp;').'</td>';
1506  }
1507 
1508  if (!empty($arrayfields['dynamount_payed']['checked']))
1509  {
1510  print '<td class="right nowraponall">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1511  if (!$i) $totalarray['nbfield']++;
1512  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
1513  $totalarray['val']['totalam'] += $totalpay;
1514  }
1515 
1516  // Pending amount
1517  if (!empty($arrayfields['rtp']['checked']))
1518  {
1519  print '<td class="right nowraponall">';
1520  print (!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;');
1521  print '</td>'; // TODO Use a denormalized field
1522  if (!$i) $totalarray['nbfield']++;
1523  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
1524  $totalarray['val']['rtp'] += $remaintopay;
1525  }
1526 
1527 
1528  // Currency
1529  if (!empty($arrayfields['f.multicurrency_code']['checked']))
1530  {
1531  print '<td class="nowraponall">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1532  if (!$i) $totalarray['nbfield']++;
1533  }
1534 
1535  // Currency rate
1536  if (!empty($arrayfields['f.multicurrency_tx']['checked']))
1537  {
1538  print '<td class="nowraponall">';
1539  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1540  print "</td>\n";
1541  if (!$i) $totalarray['nbfield']++;
1542  }
1543  // Amount HT
1544  if (!empty($arrayfields['f.multicurrency_total_ht']['checked']))
1545  {
1546  print '<td class="right nowraponall">'.price($obj->multicurrency_total_ht)."</td>\n";
1547  if (!$i) $totalarray['nbfield']++;
1548  }
1549  // Amount VAT
1550  if (!empty($arrayfields['f.multicurrency_total_vat']['checked']))
1551  {
1552  print '<td class="right nowraponall">'.price($obj->multicurrency_total_vat)."</td>\n";
1553  if (!$i) $totalarray['nbfield']++;
1554  }
1555  // Amount TTC
1556  if (!empty($arrayfields['f.multicurrency_total_ttc']['checked']))
1557  {
1558  print '<td class="right nowraponall">'.price($obj->multicurrency_total_ttc)."</td>\n";
1559  if (!$i) $totalarray['nbfield']++;
1560  }
1561  if (!empty($arrayfields['multicurrency_dynamount_payed']['checked']))
1562  {
1563  print '<td class="right nowraponall">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
1564  if (!$i) $totalarray['nbfield']++;
1565  }
1566 
1567  // Pending amount
1568  if (!empty($arrayfields['multicurrency_rtp']['checked']))
1569  {
1570  print '<td class="right nowraponall">';
1571  print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '&nbsp;');
1572  print '</td>'; // TODO Use a denormalized field
1573  if (!$i) $totalarray['nbfield']++;
1574  }
1575 
1576  // Total buying or cost price
1577  if (!empty($arrayfields['total_pa']['checked']))
1578  {
1579  print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
1580  if (!$i) $totalarray['nbfield']++;
1581  }
1582  // Total margin
1583  if (!empty($arrayfields['total_margin']['checked']))
1584  {
1585  print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
1586  if (!$i) $totalarray['nbfield']++;
1587  }
1588  // Total margin rate
1589  if (!empty($arrayfields['total_margin_rate']['checked']))
1590  {
1591  print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
1592  if (!$i) $totalarray['nbfield']++;
1593  }
1594  // total mark rate
1595  if (!empty($arrayfields['total_mark_rate']['checked']))
1596  {
1597  print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
1598  if (!$i) $totalarray['nbfield']++;
1599  }
1600 
1601  // Extra fields
1602  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1603  // Fields from hook
1604  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1605  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1606  print $hookmanager->resPrint;
1607  // Date creation
1608  if (!empty($arrayfields['f.datec']['checked']))
1609  {
1610  print '<td align="center" class="nowrap">';
1611  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1612  print '</td>';
1613  if (!$i) $totalarray['nbfield']++;
1614  }
1615  // Date modification
1616  if (!empty($arrayfields['f.tms']['checked']))
1617  {
1618  print '<td align="center" class="nowrap">';
1619  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1620  print '</td>';
1621  if (!$i) $totalarray['nbfield']++;
1622  }
1623  // Date closing
1624  if (!empty($arrayfields['f.date_closing']['checked']))
1625  {
1626  print '<td align="center" class="nowrap">';
1627  print dol_print_date($db->jdate($obj->date_closing), 'dayhour', 'tzuser');
1628  print '</td>';
1629  if (!$i) $totalarray['nbfield']++;
1630  }
1631  // Note public
1632  if (!empty($arrayfields['f.note_public']['checked']))
1633  {
1634  print '<td class="center">';
1635  print dol_escape_htmltag($obj->note_public);
1636  print '</td>';
1637  if (!$i) $totalarray['nbfield']++;
1638  }
1639  // Note private
1640  if (!empty($arrayfields['f.note_private']['checked']))
1641  {
1642  print '<td class="center">';
1643  print dol_escape_htmltag($obj->note_private);
1644  print '</td>';
1645  if (!$i) $totalarray['nbfield']++;
1646  }
1647  // Status
1648  if (!empty($arrayfields['f.fk_statut']['checked']))
1649  {
1650  print '<td class="nowrap right">';
1651  print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type);
1652  print "</td>";
1653  if (!$i) $totalarray['nbfield']++;
1654  }
1655 
1656  // Action column (Show the massaction button only when this page is not opend from the Extended POS)
1657  print '<td class="nowrap" align="center">';
1658  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
1659  {
1660  $selected = 0;
1661  if (in_array($obj->id, $arrayofselected)) $selected = 1;
1662  print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
1663  }
1664  print '</td>';
1665  if (!$i) $totalarray['nbfield']++;
1666 
1667  print "</tr>\n";
1668 
1669  $i++;
1670  }
1671 
1672  // Show total line
1673  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1674  }
1675 
1676  $db->free($resql);
1677 
1678  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1679  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1680  print $hookmanager->resPrint;
1681 
1682  print "</table>\n";
1683  print '</div>';
1684 
1685  print "</form>\n";
1686 
1687  // Show the file area only when this page is not opend from the Extended POS
1688  if ($contextpage != 'poslist') {
1689  $hidegeneratedfilelistifempty = 1;
1690  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
1691 
1692  // Show list of available documents
1693  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1694  $urlsource .= str_replace('&amp;', '&', $param);
1695 
1696  $filedir = $diroutputmassaction;
1697  $genallowed = $user->rights->facture->lire;
1698  $delallowed = $user->rights->facture->creer;
1699  $title = '';
1700 
1701  print $formfile->showdocuments('massfilesarea_invoices', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1702  }
1703 } else {
1704  dol_print_error($db);
1705 }
1706 
1707 // End of page
1708 llxFooter();
1709 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const TYPE_STANDARD
Standard invoice.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
const TYPE_REPLACEMENT
Replacement invoice.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
const TYPE_SITUATION
Situation invoice.
Class to manage bank accounts.
const TYPE_CREDIT_NOTE
Credit note invoice.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Classe permettant la generation de composants html autre Only common components are here...
const STATUS_DRAFT
Draft status.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an 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...
const STATUS_CLOSED
Classified paid.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
const TYPE_DEPOSIT
Deposit invoice.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
Class to manage absolute discounts.
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
Class to manage invoices.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.