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