dolibarr  17.0.4
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 // Load Dolibarr environment
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 
38 $langs->loadLangs(array("sendings", "receptions", "deliveries", 'companies', 'bills', 'orders'));
39 
40 $socid = GETPOST('socid', 'int');
41 $massaction = GETPOST('massaction', 'alpha');
42 $toselect = GETPOST('toselect', 'array');
43 
44 $diroutputmassaction = $conf->reception->dir_output.'/temp/massgeneration/'.$user->id;
45 
46 $search_ref_rcp = GETPOST("search_ref_rcp");
47 $search_ref_liv = GETPOST('search_ref_liv');
48 $search_ref_supplier = GETPOST('search_ref_supplier');
49 $search_company = GETPOST("search_company");
50 $search_town = GETPOST('search_town', 'alpha');
51 $search_zip = GETPOST('search_zip', 'alpha');
52 $search_state = GETPOST("search_state");
53 $search_country = GETPOST("search_country", 'int');
54 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
55 $search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
56 $search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
57 $search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
58 $search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
59 $search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
60 $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
61 $search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear); // Use tzserver
62 $search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
63 $search_date_create_startday = GETPOST('search_date_create_startday', 'int');
64 $search_date_create_startmonth = GETPOST('search_date_create_startmonth', 'int');
65 $search_date_create_startyear = GETPOST('search_date_create_startyear', 'int');
66 $search_date_create_endday = GETPOST('search_date_create_endday', 'int');
67 $search_date_create_endmonth = GETPOST('search_date_create_endmonth', 'int');
68 $search_date_create_endyear = GETPOST('search_date_create_endyear', 'int');
69 $search_date_create_start = dol_mktime(0, 0, 0, $search_date_create_startmonth, $search_date_create_startday, $search_date_create_startyear); // Use tzserver
70 $search_date_create_end = dol_mktime(23, 59, 59, $search_date_create_endmonth, $search_date_create_endday, $search_date_create_endyear);
71 $search_billed = GETPOST("search_billed", 'int');
72 $sall = GETPOST('sall', 'alphanohtml');
73 $optioncss = GETPOST('optioncss', 'alpha');
74 
75 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
76 $sortfield = GETPOST('sortfield', 'aZ09comma');
77 $sortorder = GETPOST('sortorder', 'aZ09comma');
78 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
79 if (!$sortfield) {
80  $sortfield = "e.ref";
81 }
82 if (!$sortorder) {
83  $sortorder = "DESC";
84 }
85 if (empty($page) || $page == -1) {
86  $page = 0;
87 } // If $page is not defined, or '' or -1
88 $offset = $limit * $page;
89 $pageprev = $page - 1;
90 $pagenext = $page + 1;
91 
92 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
93 $contextpage = 'receptionlist';
94 
95 $search_status = GETPOST('search_status', 'intcomma');
96 
97 $object = new Reception($db);
98 
99 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
100 $hookmanager->initHooks(array('receptionlist'));
101 $extrafields = new ExtraFields($db);
102 
103 // fetch optionals attributes and labels
104 $extrafields->fetch_name_optionals_label($object->table_element);
105 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
106 
107 // List of fields to search into when doing a "search in all"
108 $fieldstosearchall = array(
109  'e.ref'=>"Ref",
110  's.nom'=>"ThirdParty",
111  'e.note_public'=>'NotePublic',
112 );
113 if (empty($user->socid)) {
114  $fieldstosearchall["e.note_private"] = "NotePrivate";
115 }
116 
117 $checkedtypetiers = 0;
118 $arrayfields = array(
119  'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
120  'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
121  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
122  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
123  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
124  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
125  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
126  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
127  'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
128  'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
129  'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
130  'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
131  'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)))
132 );
133 
134 // Extra fields
135 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
136 
137 $object->fields = dol_sort_array($object->fields, 'position');
138 $arrayfields = dol_sort_array($arrayfields, 'position');
139 
140 $error = 0;
141 
142 // Security check
143 $receptionid = GETPOST('id', 'int');
144 if ($user->socid) {
145  $socid = $user->socid;
146 }
147 $result = restrictedArea($user, 'reception', $receptionid, '');
148 
149 
150 /*
151  * Actions
152  */
153 
154 if (GETPOST('cancel')) {
155  $action = 'list'; $massaction = '';
156 }
157 if (!GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') {
158  $massaction = '';
159 }
160 
161 $parameters = array('socid'=>$socid);
162 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
163 if ($reshook < 0) {
164  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
165 }
166 
167 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
168 
169 // Purge search criteria
170 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
171  $search_ref_supplier = '';
172  $search_ref_rcp = '';
173  $search_ref_liv = '';
174  $search_company = '';
175  $search_town = '';
176  $search_zip = "";
177  $search_state = "";
178  $search_country = '';
179  $search_type_thirdparty = '';
180  $search_date_delivery_startday = '';
181  $search_date_delivery_startmonth = '';
182  $search_date_delivery_startyear = '';
183  $search_date_delivery_endday = '';
184  $search_date_delivery_endmonth = '';
185  $search_date_delivery_endyear = '';
186  $search_date_delivery_start = '';
187  $search_date_delivery_end = '';
188  $search_date_create_startday = '';
189  $search_date_create_startmonth = '';
190  $search_date_create_startyear = '';
191  $search_date_create_endday = '';
192  $search_date_create_endmonth = '';
193  $search_date_create_endyear = '';
194  $search_date_create_start = '';
195  $search_date_create_end = '';
196  $search_billed = '';
197  $search_status = '';
198  $search_array_options = array();
199 }
200 
201 if (empty($reshook)) {
202  // Mass actions
203  $objectclass = 'Reception';
204  $objectlabel = 'Receptions';
205  $permissiontoread = $user->rights->reception->lire;
206  $permissiontoadd = $user->rights->reception->creer;
207  $permissiontodelete = $user->rights->reception->supprimer;
208  $uploaddir = $conf->reception->multidir_output[$conf->entity];
209  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
210 
211  if ($massaction == 'confirm_createbills') {
212  $receptions = GETPOST('toselect', 'array');
213  $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
214  $validate_invoices = GETPOST('validate_invoices', 'int');
215 
216  $errors = array();
217 
218  $TFact = array();
219  $TFactThird = array();
220  $TFactThirdNbLines = array();
221 
222  $nb_bills_created = 0;
223  $lastid= 0;
224  $lastref = '';
225 
226  $db->begin();
227 
228  //sort ids to keep order if one bill per third
229  sort($receptions);
230  foreach ($receptions as $id_reception) {
231  $rcp = new Reception($db);
232  // We only invoice reception that are validated
233  if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != $rcp::STATUS_VALIDATED) {
234  $errors[] = $langs->trans('StatusOfRefMustBe', $rcp->ref, $langs->transnoentities("StatusSupplierOrderValidatedShort"));
235  $error++;
236  continue;
237  }
238 
239  $objecttmp = new FactureFournisseur($db);
240  if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
241  // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we re-use it.
242  $objecttmp = $TFactThird[$rcp->socid];
243 
244  // Add all links of this new reception to the existing invoice
245  $objecttmp->fetchObjectLinked();
246  $rcp->fetchObjectLinked();
247  if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
248  foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
249  if (empty($objecttmp->linkedObjectsIds['order_supplier']) || !in_array($value, $objecttmp->linkedObjectsIds['order_supplier'])) { //Dont try to link if already linked
250  $objecttmp->add_object_linked('order_supplier', $value); // add supplier order linked object
251  }
252  }
253  }
254  } else {
255  // If we want one invoice per reception or if there is no first invoice yet for this thirdparty.
256  $objecttmp->socid = $rcp->socid;
257  $objecttmp->type = $objecttmp::TYPE_STANDARD;
258  $objecttmp->cond_reglement_id = $rcp->cond_reglement_id || $rcp->thirdparty->cond_reglement_supplier_id;
259  $objecttmp->mode_reglement_id = $rcp->mode_reglement_id || $rcp->thirdparty->mode_reglement_supplier_id;
260 
261  $objecttmp->fk_account = !empty($rcp->thirdparty->fk_account) ? $rcp->thirdparty->fk_account : 0;
262  $objecttmp->remise_percent = !empty($rcp->thirdparty->remise_percent) ? $rcp->thirdparty->remise_percent : 0;
263  $objecttmp->remise_absolue = !empty($rcp->thirdparty->remise_absolue) ? $rcp->thirdparty->remise_absolue : 0;
264 
265  $objecttmp->fk_project = $rcp->fk_project;
266  //$objecttmp->multicurrency_code = $rcp->multicurrency_code;
267  if (empty($createbills_onebythird)) {
268  $objecttmp->ref_supplier = $rcp->ref;
269  } else {
270  // Set a unique value for the invoice for the n reception
271  $objecttmp->ref_supplier = $langs->trans("Reception").' '.dol_print_date(dol_now(), 'dayhourlog').'-'.$rcp->socid;
272  }
273 
274  $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
275  if (empty($datefacture)) {
276  $datefacture = dol_now();
277  }
278 
279  $objecttmp->date = $datefacture;
280  $objecttmp->origin = 'reception';
281  $objecttmp->origin_id = $id_reception;
282 
283  $objecttmp->array_options = $rcp->array_options; // Copy extrafields
284 
285  // Set $objecttmp->linked_objects with all links order_supplier existing on reception, so same links will be added to the generated supplier invoice
286  $rcp->fetchObjectLinked();
287  if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
288  foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
289  $objecttmp->linked_objects['order_supplier'] = $value;
290  }
291  }
292 
293  $res = $objecttmp->create($user); // This should create the supplier invoice + links into $objecttmp->linked_objects + add a link to ->origin_id
294 
295  //var_dump($objecttmp->error);exit;
296  if ($res > 0) {
297  $nb_bills_created++;
298  $lastref = $objecttmp->ref;
299  $lastid = $objecttmp->id;
300 
301  $TFactThird[$rcp->socid] = $objecttmp;
302  $TFactThirdNbLines[$rcp->socid] = 0; //init nblines to have lines ordered by expedition and rang
303  } else {
304  $langs->load("errors");
305  $errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
306  $error++;
307  }
308  }
309 
310  if ($objecttmp->id > 0) {
311  $res = $objecttmp->add_object_linked($objecttmp->origin, $id_reception);
312 
313  if ($res == 0) {
314  $errors[] = $objecttmp->error;
315  $error++;
316  }
317 
318  if (!$error) {
319  $lines = $rcp->lines;
320  if (empty($lines) && method_exists($rcp, 'fetch_lines')) {
321  $rcp->fetch_lines();
322  $lines = $rcp->lines;
323  }
324 
325  $fk_parent_line = 0;
326  $num = count($lines);
327 
328  for ($i = 0; $i < $num; $i++) {
329  $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
330  // If we build one invoice for several reception, we must put the ref of reception on the invoice line
331  if (!empty($createbills_onebythird)) {
332  $desc = dol_concatdesc($desc, $langs->trans("Reception").' '.$rcp->ref.' - '.dol_print_date($rcp->date, 'day'));
333  }
334 
335  if ($lines[$i]->subprice < 0) {
336  // Negative line, we create a discount line
337  $discount = new DiscountAbsolute($db);
338  $discount->fk_soc = $objecttmp->socid;
339  $discount->amount_ht = abs($lines[$i]->total_ht);
340  $discount->amount_tva = abs($lines[$i]->total_tva);
341  $discount->amount_ttc = abs($lines[$i]->total_ttc);
342  $discount->tva_tx = $lines[$i]->tva_tx;
343  $discount->fk_user = $user->id;
344  $discount->description = $desc;
345  $discountid = $discount->create($user);
346  if ($discountid > 0) {
347  $result = $objecttmp->insert_discount($discountid);
348  //$result=$discount->link_to_invoice($lineid,$id);
349  } else {
350  setEventMessages($discount->error, $discount->errors, 'errors');
351  $error++;
352  break;
353  }
354  } else {
355  // Positive line
356  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
357  // Date start
358  $date_start = false;
359  if ($lines[$i]->date_debut_prevue) {
360  $date_start = $lines[$i]->date_debut_prevue;
361  }
362  if ($lines[$i]->date_debut_reel) {
363  $date_start = $lines[$i]->date_debut_reel;
364  }
365  if ($lines[$i]->date_start) {
366  $date_start = $lines[$i]->date_start;
367  }
368  //Date end
369  $date_end = false;
370  if ($lines[$i]->date_fin_prevue) {
371  $date_end = $lines[$i]->date_fin_prevue;
372  }
373  if ($lines[$i]->date_fin_reel) {
374  $date_end = $lines[$i]->date_fin_reel;
375  }
376  if ($lines[$i]->date_end) {
377  $date_end = $lines[$i]->date_end;
378  }
379  // Reset fk_parent_line for no child products and special product
380  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
381  $fk_parent_line = 0;
382  }
383 
384  // Extrafields
385  if (method_exists($lines[$i], 'fetch_optionals')) {
386  $lines[$i]->fetch_optionals();
387  $array_options = $lines[$i]->array_options;
388  }
389 
390  $objecttmp->context['createfromclone'];
391 
392  $rang = $i;
393  //there may already be rows from previous receptions
394  if (!empty($createbills_onebythird))
395  $rang = $TFactThirdNbLines[$rcp->socid];
396 
397  $result = $objecttmp->addline(
398  $desc,
399  $lines[$i]->subprice,
400  $lines[$i]->tva_tx,
401  $lines[$i]->localtax1_tx,
402  $lines[$i]->localtax2_tx,
403  $lines[$i]->qty,
404  $lines[$i]->fk_product,
405  $lines[$i]->remise_percent,
406  $date_start,
407  $date_end,
408  0,
409  $lines[$i]->info_bits,
410  'HT',
411  $product_type,
412  $rang,
413  false,
414  0,
415  null,
416  $lines[$i]->rowid,
417  0,
418  $lines[$i]->ref_supplier
419  );
420 
421  $rcp->add_object_linked('facture_fourn_det', $result);
422 
423  if ($result > 0) {
424  $lineid = $result;
425  if (!empty($createbills_onebythird)) //increment rang to keep order
426  $TFactThirdNbLines[$rcp->socid]++;
427  } else {
428  $lineid = 0;
429  $error++;
430  break;
431  }
432  // Defined the new fk_parent_line
433  if ($result > 0 && $lines[$i]->product_type == 9) {
434  $fk_parent_line = $result;
435  }
436  }
437  }
438  }
439  }
440 
441  //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
442 
443  if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) {
444  $TFactThird[$rcp->socid] = $objecttmp;
445  } else {
446  $TFact[$objecttmp->id] = $objecttmp;
447  }
448  }
449 
450  // Build doc with all invoices
451  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
452  $toselect = array();
453 
454  if (!$error && $validate_invoices) {
455  $massaction = $action = 'builddoc';
456  foreach ($TAllFact as &$objecttmp) {
457  $result = $objecttmp->validate($user);
458  if ($result <= 0) {
459  $error++;
460  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
461  break;
462  }
463 
464  $id = $objecttmp->id; // For builddoc action
465  $object =$objecttmp;
466 
467  // Fac builddoc
468  $donotredirect = 1;
469  $upload_dir = $conf->fournisseur->facture->dir_output;
470  $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
471 
472  // Call action to build doc
473  $savobject = $object;
474  $object = $objecttmp;
475  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
476  $object = $savobject;
477  }
478 
479  $massaction = $action = 'confirm_createbills';
480  }
481 
482  if (!$error) {
483  $db->commit();
484 
485  if ($nb_bills_created == 1) {
486  $texttoshow = $langs->trans('BillXCreated', '{s1}');
487  $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
488  setEventMessages($texttoshow, null, 'mesgs');
489  } else {
490  setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
491  }
492  } else {
493  $db->rollback();
494 
495  $action = 'create';
496  $_GET["origin"] = $_POST["origin"];
497  $_GET["originid"] = $_POST["originid"];
498  setEventMessages($object->error, $errors, 'errors');
499  $error++;
500  }
501  }
502 }
503 
504 
505 /*
506  * View
507  */
508 
509 $form = new Form($db);
510 $companystatic = new Societe($db);
511 $reception = new Reception($db);
512 $formcompany = new FormCompany($db);
513 $formfile = new FormFile($db);
514 
515 
516 $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
517 llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
518 
519 $sql = "SELECT e.rowid, e.ref, e.ref_supplier, e.date_reception as date_reception, e.date_delivery as delivery_date, l.date_delivery as date_reception2, e.fk_statut, e.billed,";
520 $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
521 $sql .= " typent.code as typent_code,";
522 $sql .= " state.code_departement as state_code, state.nom as state_name,";
523 $sql .= ' e.date_creation as date_creation, e.tms as date_update';
524 // Add fields from extrafields
525 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
526  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
527  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
528  }
529 }
530 // Add fields from hooks
531 $parameters = array();
532 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
533 $sql .= $hookmanager->resPrint;
534 
535 $sqlfields = $sql; // $sql fields to remove for count total
536 
537 $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
538 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
539  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
540 }
541 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
542 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
543 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
544 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
545 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
546 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
547 if (empty($user->rights->societe->client->voir) && !$socid) { // Internal user with no permission to see all
548  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
549 }
550 // Add joins from hooks
551 $parameters = array();
552 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
553 $sql .= $hookmanager->resPrint;
554 $sql .= " WHERE e.entity IN (".getEntity('reception').")";
555 if (empty($user->rights->societe->client->voir) && !$socid) { // Internal user with no permission to see all
556  $sql .= " AND e.fk_soc = sc.fk_soc";
557  $sql .= " AND sc.fk_user = ".((int) $user->id);
558 }
559 if ($socid) {
560  $sql .= " AND e.fk_soc = ".((int) $socid);
561 }
562 if ($search_status <> '' && $search_status >= 0) {
563  $sql .= " AND e.fk_statut = ".((int) $search_status);
564 }
565 if ($search_billed != '' && $search_billed >= 0) {
566  $sql .= ' AND e.billed = '.((int) $search_billed);
567 }
568 if ($search_town) {
569  $sql .= natural_search('s.town', $search_town);
570 }
571 if ($search_zip) {
572  $sql .= natural_search("s.zip", $search_zip);
573 }
574 if ($search_state) {
575  $sql .= natural_search("state.nom", $search_state);
576 }
577 if ($search_country) {
578  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
579 }
580 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
581  $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
582 }
583 if ($search_date_delivery_start) {
584  $sql .= " AND e.date_delivery >= '".$db->idate($search_date_delivery_start)."'";
585 }
586 if ($search_date_delivery_end) {
587  $sql .= " AND e.date_delivery <= '".$db->idate($search_date_delivery_end)."'";
588 }
589 if ($search_date_create_start) {
590  $sql .= " AND e.date_creation >= '".$db->idate($search_date_create_start)."'";
591 }
592 if ($search_date_create_end) {
593  $sql .= " AND e.date_creation <= '".$db->idate($search_date_create_end)."'";
594 }
595 if ($search_ref_rcp) {
596  $sql .= natural_search('e.ref', $search_ref_rcp);
597 }
598 if ($search_ref_liv) {
599  $sql .= natural_search('l.ref', $search_ref_liv);
600 }
601 if ($search_company) {
602  $sql .= natural_search('s.nom', $search_company);
603 }
604 if ($search_ref_supplier) {
605  $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
606 }
607 if ($sall) {
608  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
609 }
610 
611 // Add where from extra fields
612 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
613 // Add where from hooks
614 $parameters = array();
615 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
616 $sql .= $hookmanager->resPrint;
617 
618 $nbtotalofrecords = '';
619 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
620  /* The fast and low memory method to get and count full list converts the sql into a sql count */
621  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
622  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
623  $resql = $db->query($sqlforcount);
624  if ($resql) {
625  $objforcount = $db->fetch_object($resql);
626  $nbtotalofrecords = $objforcount->nbtotalofrecords;
627  } else {
628  dol_print_error($db);
629  }
630 
631  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
632  $page = 0;
633  $offset = 0;
634  }
635  $db->free($resql);
636 }
637 
638 // Complete request and execute it with limit
639 $sql .= $db->order($sortfield, $sortorder);
640 if ($limit) {
641  $sql .= $db->plimit($limit + 1, $offset);
642 }
643 
644 //print $sql;
645 $resql = $db->query($sql);
646 if (!$resql) {
647  dol_print_error($db);
648  exit;
649 }
650 
651 $num = $db->num_rows($resql);
652 
653 $reception = new Reception($db);
654 
655 $arrayofselected = is_array($toselect) ? $toselect : array();
656 
657 $param = '';
658 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
659  $param .= '&contextpage='.urlencode($contextpage);
660 }
661 if ($limit > 0 && $limit != $conf->liste_limit) {
662  $param .= '&limit='.urlencode($limit);
663 }
664 if ($sall) {
665  $param .= "&sall=".urlencode($sall);
666 }
667 if ($search_ref_rcp) {
668  $param .= "&search_ref_rcp=".urlencode($search_ref_rcp);
669 }
670 if ($search_ref_liv) {
671  $param .= "&search_ref_liv=".urlencode($search_ref_liv);
672 }
673 if ($search_company) {
674  $param .= "&search_company=".urlencode($search_company);
675 }
676 if ($optioncss != '') {
677  $param .= '&optioncss='.urlencode($optioncss);
678 }
679 if ($search_billed != '' && $search_billed >= 0) {
680  $param .= "&search_billed=".urlencode($search_billed);
681 }
682 if ($search_town) {
683  $param .= "&search_town=".urlencode($search_town);
684 }
685 if ($search_zip) {
686  $param .= "&search_zip=".urlencode($search_zip);
687 }
688 if ($search_state) {
689  $param .= "&search_state=".urlencode($search_state);
690 }
691 if ($search_status != '') {
692  $param .= "&search_status=".urlencode($search_status);
693 }
694 if ($search_country) {
695  $param .= "&search_country=".urlencode($search_country);
696 }
697 if ($search_type_thirdparty) {
698  $param .= "&search_type_thirdparty=".urlencode($search_type_thirdparty);
699 }
700 if ($search_date_delivery_startday) {
701  $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
702 }
703 if ($search_date_delivery_startmonth) {
704  $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
705 }
706 if ($search_date_delivery_startyear) {
707  $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
708 }
709 if ($search_date_delivery_endday) {
710  $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
711 }
712 if ($search_date_delivery_endmonth) {
713  $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
714 }
715 if ($search_date_delivery_endyear) {
716  $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
717 }
718 if ($search_date_create_startday) {
719  $param .= '&search_date_create_startday='.urlencode($search_date_create_startday);
720 }
721 if ($search_date_create_startmonth) {
722  $param .= '&search_date_create_startmonth='.urlencode($search_date_create_startmonth);
723 }
724 if ($search_date_create_startyear) {
725  $param .= '&search_date_create_startyear='.urlencode($search_date_create_startyear);
726 }
727 if ($search_date_create_endday) {
728  $param .= '&search_date_create_endday='.urlencode($search_date_create_endday);
729 }
730 if ($search_date_create_endmonth) {
731  $param .= '&search_date_create_endmonth='.urlencode($search_date_create_endmonth);
732 }
733 if ($search_date_create_endyear) {
734  $param .= '&search_date_create_endyear='.urlencode($search_date_create_endyear);
735 }
736 if ($search_ref_supplier) {
737  $param .= "&search_ref_supplier=".urlencode($search_ref_supplier);
738 }
739 // Add $param from extra fields
740 if ($search_array_options) {
741  foreach ($search_array_options as $key => $val) {
742  $crit = $val;
743  $tmpkey = preg_replace('/search_options_/', '', $key);
744  if (is_array($val) && array_key_exists('start', $val) && array_key_exists('end', $val)) {
745  // date range from list filters is stored as array('start' => <timestamp>, 'end' => <timestamp>)
746  // start date
747  $param .= '&search_options_'.$tmpkey.'_startyear='.dol_print_date($val['start'], '%Y');
748  $param .= '&search_options_'.$tmpkey.'_startmonth='.dol_print_date($val['start'], '%m');
749  $param .= '&search_options_'.$tmpkey.'_startday='.dol_print_date($val['start'], '%d');
750  $param .= '&search_options_'.$tmpkey.'_starthour='.dol_print_date($val['start'], '%H');
751  $param .= '&search_options_'.$tmpkey.'_startmin='.dol_print_date($val['start'], '%M');
752  // end date
753  $param .= '&search_options_'.$tmpkey.'_endyear='.dol_print_date($val['end'], '%Y');
754  $param .= '&search_options_'.$tmpkey.'_endmonth='.dol_print_date($val['end'], '%m');
755  $param .= '&search_options_'.$tmpkey.'_endday='.dol_print_date($val['end'], '%d');
756  $param .= '&search_options_'.$tmpkey.'_endhour='.dol_print_date($val['end'], '%H');
757  $param .= '&search_options_'.$tmpkey.'_endmin='.dol_print_date($val['end'], '%M');
758  $val = '';
759  }
760  if ($val != '') {
761  $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
762  }
763  }
764 }
765 
766 
767 $arrayofmassactions = array(
768  // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
769 );
770 
771 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
772  $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisReceptions");
773 }
774 if ($massaction == 'createbills') {
775  $arrayofmassactions = array();
776 }
777 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
778 //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
779 
780 $i = 0;
781 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
782 if ($optioncss != '') {
783  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
784 }
785 print '<input type="hidden" name="token" value="'.newToken().'">';
786 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
787 print '<input type="hidden" name="action" value="list">';
788 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
789 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
790 
791 print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dollyrevert', 0, '', '', $limit, 0, 0, 1);
792 
793 if ($massaction == 'createbills') {
794  //var_dump($_REQUEST);
795  print '<input type="hidden" name="massaction" value="confirm_createbills">';
796 
797  print '<table class="noborder" width="100%" >';
798  print '<tr>';
799  print '<td class="titlefieldmiddle">';
800  print $langs->trans('DateInvoice');
801  print '</td>';
802  print '<td>';
803  print $form->selectDate('', '', '', '', '', '', 1, 1);
804  print '</td>';
805  print '</tr>';
806  print '<tr>';
807  print '<td>';
808  print $langs->trans('CreateOneBillByThird');
809  print '</td>';
810  print '<td>';
811  print $form->selectyesno('createbills_onebythird', '', 1);
812  print '</td>';
813  print '</tr>';
814  print '<tr>';
815  print '<td>';
816  print $langs->trans('ValidateInvoices');
817  print '</td>';
818  print '<td>';
819  if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
820  print $form->selectyesno('validate_invoices', 0, 1, 1);
821  print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
822  } else {
823  print $form->selectyesno('validate_invoices', 0, 1);
824  }
825  print '</td>';
826  print '</tr>';
827  print '</table>';
828 
829  print '<br>';
830  print '<div class="center">';
831  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisReceptions').'"> ';
832  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
833  print '</div>';
834  print '<br>';
835 }
836 
837 if ($sall) {
838  foreach ($fieldstosearchall as $key => $val) {
839  $fieldstosearchall[$key] = $langs->trans($val);
840  }
841  print $langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall);
842 }
843 
844 $moreforfilter = '';
845 if (!empty($moreforfilter)) {
846  print '<div class="liste_titre liste_titre_bydiv centpercent">';
847  print $moreforfilter;
848  $parameters = array('type'=>$type);
849  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
850  print $hookmanager->resPrint;
851  print '</div>';
852 }
853 
854 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
855 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
856 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
857 
858 
859 print '<div class="div-table-responsive">';
860 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
861 
862 // Fields title search
863 // --------------------------------------------------------------------
864 print '<tr class="liste_titre_filter">';
865 // Action column
866 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
867  print '<td class="liste_titre middle">';
868  $searchpicto = $form->showFilterButtons('left');
869  print $searchpicto;
870  print '</td>';
871 }
872 // Ref
873 if (!empty($arrayfields['e.ref']['checked'])) {
874  print '<td class="liste_titre">';
875  print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
876  print '</td>';
877 }
878 // Ref customer
879 if (!empty($arrayfields['e.ref_supplier']['checked'])) {
880  print '<td class="liste_titre">';
881  print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
882  print '</td>';
883 }
884 // Thirdparty
885 if (!empty($arrayfields['s.nom']['checked'])) {
886  print '<td class="liste_titre left">';
887  print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
888  print '</td>';
889 }
890 // Town
891 if (!empty($arrayfields['s.town']['checked'])) {
892  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
893 }
894 // Zip
895 if (!empty($arrayfields['s.zip']['checked'])) {
896  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
897 }
898 // State
899 if (!empty($arrayfields['state.nom']['checked'])) {
900  print '<td class="liste_titre">';
901  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
902  print '</td>';
903 }
904 // Country
905 if (!empty($arrayfields['country.code_iso']['checked'])) {
906  print '<td class="liste_titre center">';
907  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
908  print '</td>';
909 }
910 // Company type
911 if (!empty($arrayfields['typent.code']['checked'])) {
912  print '<td class="liste_titre maxwidthonsmartphone center">';
913  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
914  print '</td>';
915 }
916 // Date delivery planned
917 if (!empty($arrayfields['e.date_delivery']['checked'])) {
918  print '<td class="liste_titre center">';
919  print '<div class="nowrap">';
920  print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
921  print '</div>';
922  print '<div class="nowrap">';
923  print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
924  print '</div>';
925  print '</td>';
926 }
927 if (!empty($arrayfields['l.ref']['checked'])) {
928  // Delivery ref
929  print '<td class="liste_titre">';
930  print '<input class="flat" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';
931  print '</td>';
932 }
933 if (!empty($arrayfields['l.date_delivery']['checked'])) {
934  // Date received
935  print '<td class="liste_titre">&nbsp;</td>';
936 }
937 // Extra fields
938 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
939 
940 // Fields from hook
941 $parameters = array('arrayfields'=>$arrayfields);
942 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
943 print $hookmanager->resPrint;
944 // Date creation
945 if (!empty($arrayfields['e.datec']['checked'])) {
946  print '<td class="liste_titre center">';
947  print '<div class="nowrap">';
948  print $form->selectDate($search_date_create_start ? $search_date_create_start : -1, 'search_date_create_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
949  print '</div>';
950  print '<div class="nowrap">';
951  print $form->selectDate($search_date_create_end ? $search_date_create_end : -1, 'search_date_create_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
952  print '</div>';
953  print '</td>';
954 }
955 // Date modification
956 if (!empty($arrayfields['e.tms']['checked'])) {
957  print '<td class="liste_titre">';
958  print '</td>';
959 }
960 // Status
961 if (!empty($arrayfields['e.fk_statut']['checked'])) {
962  print '<td class="liste_titre maxwidthonsmartphone right">';
963  print $form->selectarray('search_status', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status onrightofpage');
964  print '</td>';
965 }
966 // Status billed
967 if (!empty($arrayfields['e.billed']['checked'])) {
968  print '<td class="liste_titre maxwidthonsmartphone center">';
969  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
970  print '</td>';
971 }
972 // Action column
973 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
974  print '<td class="liste_titre middle">';
975  $searchpicto = $form->showFilterAndCheckAddButtons(0);
976  print $searchpicto;
977  print '</td>';
978 }
979 print "</tr>\n";
980 
981 print '<tr class="liste_titre">';
982 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
983  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
984 }
985 if (!empty($arrayfields['e.ref']['checked'])) {
986  print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
987 }
988 if (!empty($arrayfields['e.ref_supplier']['checked'])) {
989  print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
990 }
991 if (!empty($arrayfields['s.nom']['checked'])) {
992  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
993 }
994 if (!empty($arrayfields['s.town']['checked'])) {
995  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
996 }
997 if (!empty($arrayfields['s.zip']['checked'])) {
998  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
999 }
1000 if (!empty($arrayfields['state.nom']['checked'])) {
1001  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1002 }
1003 if (!empty($arrayfields['country.code_iso']['checked'])) {
1004  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1005 }
1006 if (!empty($arrayfields['typent.code']['checked'])) {
1007  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1008 }
1009 if (!empty($arrayfields['e.date_delivery']['checked'])) {
1010  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1011 }
1012 if (!empty($arrayfields['l.ref']['checked'])) {
1013  print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
1014 }
1015 if (!empty($arrayfields['l.date_delivery']['checked'])) {
1016  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1017 }
1018 // Extra fields
1019 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1020 // Hook fields
1021 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1022 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1023 print $hookmanager->resPrint;
1024 if (!empty($arrayfields['e.datec']['checked'])) {
1025  print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1026 }
1027 if (!empty($arrayfields['e.tms']['checked'])) {
1028  print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1029 }
1030 if (!empty($arrayfields['e.fk_statut']['checked'])) {
1031  print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1032 }
1033 if (!empty($arrayfields['e.billed']['checked'])) {
1034  print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
1035 }
1036 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1037  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1038 }
1039 print "</tr>\n";
1040 
1041 $i = 0;
1042 $totalarray = array();
1043 $totalarray['nbfield'] = 0;
1044 while ($i < min($num, $limit)) {
1045  $obj = $db->fetch_object($resql);
1046 
1047  $reception->id = $obj->rowid;
1048  $reception->ref = $obj->ref;
1049 
1050  $companystatic->id = $obj->socid;
1051  $companystatic->ref = $obj->name;
1052  $companystatic->name = $obj->name;
1053 
1054 
1055  print '<tr class="oddeven">';
1056 
1057  // Action column
1058  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1059  print '<td class="center">';
1060  if ($massactionbutton || $massaction) {
1061  // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1062  $selected = 0;
1063  if (in_array($obj->rowid, $arrayofselected)) {
1064  $selected = 1;
1065  }
1066  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1067  }
1068  print '</td>';
1069  }
1070  // Ref
1071  if (!empty($arrayfields['e.ref']['checked'])) {
1072  print '<td class="nowraponall">';
1073  print $reception->getNomUrl(1);
1074  $filename = dol_sanitizeFileName($reception->ref);
1075  $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
1076  $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->id;
1077  print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
1078  print "</td>\n";
1079 
1080  if (!$i) {
1081  $totalarray['nbfield']++;
1082  }
1083  }
1084 
1085  // Ref supplier
1086  if (!empty($arrayfields['e.ref_supplier']['checked'])) {
1087  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
1088  print dol_escape_htmltag($obj->ref_supplier);
1089  print "</td>\n";
1090  if (!$i) {
1091  $totalarray['nbfield']++;
1092  }
1093  }
1094 
1095  // Third party
1096  if (!empty($arrayfields['s.nom']['checked'])) {
1097  print '<td class="tdoverflowmax150">';
1098  print $companystatic->getNomUrl(1);
1099  print '</td>';
1100  if (!$i) {
1101  $totalarray['nbfield']++;
1102  }
1103  }
1104  // Town
1105  if (!empty($arrayfields['s.town']['checked'])) {
1106  print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">';
1107  print dol_escape_htmltag($obj->town);
1108  print '</td>';
1109  if (!$i) {
1110  $totalarray['nbfield']++;
1111  }
1112  }
1113  // Zip
1114  if (!empty($arrayfields['s.zip']['checked'])) {
1115  print '<td class="nocellnopadd center"">';
1116  print dol_escape_htmltag($obj->zip);
1117  print '</td>';
1118  if (!$i) {
1119  $totalarray['nbfield']++;
1120  }
1121  }
1122  // State
1123  if (!empty($arrayfields['state.nom']['checked'])) {
1124  print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
1125  if (!$i) {
1126  $totalarray['nbfield']++;
1127  }
1128  }
1129  // Country
1130  if (!empty($arrayfields['country.code_iso']['checked'])) {
1131  print '<td class="center">';
1132  $tmparray = getCountry($obj->fk_pays, 'all');
1133  print dol_escape_htmltag($tmparray['label']);
1134  print '</td>';
1135  if (!$i) {
1136  $totalarray['nbfield']++;
1137  }
1138  }
1139  // Type ent
1140  if (!empty($arrayfields['typent.code']['checked'])) {
1141  print '<td class="center">';
1142  if (!isset($typenArray) || empty($typenArray)) {
1143  $typenArray = $formcompany->typent_array(1);
1144  }
1145  if (isset($typenArray[$obj->typent_code])) {
1146  print $typenArray[$obj->typent_code];
1147  }
1148  print '</td>';
1149  if (!$i) {
1150  $totalarray['nbfield']++;
1151  }
1152  }
1153 
1154  // Date delivery planed
1155  if (!empty($arrayfields['e.date_delivery']['checked'])) {
1156  print '<td class="center">';
1157  print dol_print_date($db->jdate($obj->delivery_date), "day");
1158  /*$now = time();
1159  if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
1160  {
1161  }*/
1162  print "</td>\n";
1163  if (!$i) {
1164  $totalarray['nbfield']++;
1165  }
1166  }
1167 
1168  if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
1169  $reception->fetchObjectLinked($reception->id, $reception->element);
1170  $receiving = '';
1171  if (count($reception->linkedObjects['delivery']) > 0) {
1172  $receiving = reset($reception->linkedObjects['delivery']);
1173  }
1174 
1175  if (!empty($arrayfields['l.ref']['checked'])) {
1176  // Ref
1177  print '<td>';
1178  print !empty($receiving) ? $receiving->getNomUrl($db) : '';
1179  print '</td>';
1180  }
1181 
1182  if (!empty($arrayfields['l.date_delivery']['checked'])) {
1183  // Date received
1184  print '<td class="center">';
1185  print dol_print_date($db->jdate($obj->date_reception), "day");
1186  print '</td>'."\n";
1187  }
1188  }
1189 
1190  // Extra fields
1191  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1192 
1193  // Fields from hook
1194  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1195  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1196  print $hookmanager->resPrint;
1197  // Date creation
1198  if (!empty($arrayfields['e.datec']['checked'])) {
1199  print '<td class="center nowrap">';
1200  print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
1201  print '</td>';
1202  if (!$i) {
1203  $totalarray['nbfield']++;
1204  }
1205  }
1206  // Date modification
1207  if (!empty($arrayfields['e.tms']['checked'])) {
1208  print '<td class="center nowrap">';
1209  print dol_print_date($db->jdate($obj->date_update), 'dayhour');
1210  print '</td>';
1211  if (!$i) {
1212  $totalarray['nbfield']++;
1213  }
1214  }
1215  // Status
1216  if (!empty($arrayfields['e.fk_statut']['checked'])) {
1217  print '<td class="right nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>';
1218  if (!$i) {
1219  $totalarray['nbfield']++;
1220  }
1221  }
1222  // Billed
1223  if (!empty($arrayfields['e.billed']['checked'])) {
1224  print '<td class="center">'.yn($obj->billed).'</td>';
1225  if (!$i) {
1226  $totalarray['nbfield']++;
1227  }
1228  }
1229 
1230  // Action column
1231  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1232  print '<td class="center">';
1233  if ($massactionbutton || $massaction) {
1234  // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1235  $selected = 0;
1236  if (in_array($obj->rowid, $arrayofselected)) {
1237  $selected = 1;
1238  }
1239  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1240  }
1241  print '</td>';
1242  }
1243  if (!$i) {
1244  $totalarray['nbfield']++;
1245  }
1246 
1247  print "</tr>\n";
1248 
1249  $i++;
1250 }
1251 
1252 // If no record found
1253 if ($num == 0) {
1254  $colspan = 1;
1255  foreach ($arrayfields as $key => $val) {
1256  if (!empty($val['checked'])) {
1257  $colspan++;
1258  }
1259  }
1260  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1261 }
1262 
1263 // Show total line
1264 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1265 
1266 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1267 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1268 print $hookmanager->resPrint;
1269 
1270 print "</table>";
1271 print "</div>";
1272 print '</form>';
1273 $db->free($resql);
1274 
1275 llxFooter();
1276 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage suppliers invoices.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.