dolibarr  13.0.2
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 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36 
37 $langs->loadLangs(array("sendings", "receptions", "deliveries", 'companies', 'bills', 'orders'));
38 
39 $socid = GETPOST('socid', 'int');
40 $massaction = GETPOST('massaction', 'alpha');
41 $toselect = GETPOST('toselect', 'array');
42 
43 // Security check
44 $receptionid = GETPOST('id', 'int');
45 if ($user->socid) $socid = $user->socid;
46 $result = restrictedArea($user, 'reception', $receptionid, '');
47 
48 $diroutputmassaction = $conf->reception->dir_output.'/temp/massgeneration/'.$user->id;
49 
50 $search_ref_rcp = GETPOST("search_ref_rcp");
51 $search_ref_liv = GETPOST('search_ref_liv');
52 $search_ref_supplier = GETPOST('search_ref_supplier');
53 $search_company = GETPOST("search_company");
54 $search_town = GETPOST('search_town', 'alpha');
55 $search_zip = GETPOST('search_zip', 'alpha');
56 $search_state = GETPOST("search_state");
57 $search_country = GETPOST("search_country", 'int');
58 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
59 $search_billed = GETPOST("search_billed", 'int');
60 $sall = GETPOST('sall', 'alphanohtml');
61 $optioncss = GETPOST('optioncss', 'alpha');
62 
63 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
64 $sortfield = GETPOST('sortfield', 'aZ09comma');
65 $sortorder = GETPOST('sortorder', 'aZ09comma');
66 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
67 if (!$sortfield) $sortfield = "e.ref";
68 if (!$sortorder) $sortorder = "DESC";
69 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
70 $offset = $limit * $page;
71 $pageprev = $page - 1;
72 $pagenext = $page + 1;
73 
74 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
75 $contextpage = 'receptionlist';
76 
77 $search_status = GETPOST('search_status');
78 
79 $object = new Reception($db);
80 
81 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
82 $hookmanager->initHooks(array('receptionlist'));
83 $extrafields = new ExtraFields($db);
84 
85 // fetch optionals attributes and labels
86 $extrafields->fetch_name_optionals_label($object->table_element);
87 $search_array_options = (array) $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
88 
89 // List of fields to search into when doing a "search in all"
90 $fieldstosearchall = array(
91  'e.ref'=>"Ref",
92  's.nom'=>"ThirdParty",
93  'e.note_public'=>'NotePublic',
94 );
95 if (empty($user->socid)) $fieldstosearchall["e.note_private"] = "NotePrivate";
96 
97 $checkedtypetiers = 0;
98 $arrayfields = array(
99  'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
100  'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
101  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
102  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
103  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
104  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
105  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
106  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
107  'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
108  'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
109  'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
110  'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
111  'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)))
112 );
113 
114 // Extra fields
115 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
116 
117 $object->fields = dol_sort_array($object->fields, 'position');
118 $arrayfields = dol_sort_array($arrayfields, 'position');
119 
120 
121 /*
122  * Actions
123  */
124 
125 if (GETPOST('cancel')) { $action = 'list'; $massaction = ''; }
126 if (!GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') { $massaction = ''; }
127 
128 $parameters = array('socid'=>$socid);
129 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
130 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
131 
132 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
133 
134 // Purge search criteria
135 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
136 {
137  $search_ref_supplier = '';
138  $search_ref_rcp = '';
139  $search_ref_liv = '';
140  $search_company = '';
141  $search_town = '';
142  $search_zip = "";
143  $search_state = "";
144  $search_country = '';
145  $search_type_thirdparty = '';
146  $search_billed = '';
147  $search_status = '';
148  $search_array_options = array();
149 }
150 
151 if (empty($reshook))
152 {
153  if ($massaction == 'confirm_createbills') {
154  $receptions = GETPOST('toselect', 'array');
155  $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
156  $validate_invoices = GETPOST('validate_invoices', 'int');
157 
158  $TFact = array();
159  $TFactThird = array();
160 
161  $nb_bills_created = 0;
162 
163  $db->begin();
164  $errors = array();
165  foreach ($receptions as $id_reception)
166  {
167  $rcp = new Reception($db);
168  // On ne facture que les réceptions validées
169  if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1) {
170  $errors[] = $langs->trans('StatusOfRefMustBe', $rcp->ref, $langs->transnoentities("StatusSupplierOrderValidatedShort"));
171  $error++;
172  continue;
173  }
174 
175  $object = new FactureFournisseur($db);
176  if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
177  $object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
178  if (empty($object->rowid) && $object->id != null)$object->rowid = $object->id;
179  if (!empty($object->rowid))$object->fetchObjectLinked();
180  $rcp->fetchObjectLinked();
181 
182  if (count($rcp->linkedObjectsIds['reception']) > 0)
183  {
184  foreach ($rcp->linkedObjectsIds['reception'] as $key => $value)
185  {
186  if (empty($object->linkedObjectsIds['reception']) || !in_array($value, $object->linkedObjectsIds['reception']))//Dont try to link if already linked
187  $object->add_object_linked('reception', $value); // add supplier order linked object
188  }
189  }
190  } else {
191  $object->socid = $rcp->socid;
192  $object->type = FactureFournisseur::TYPE_STANDARD;
193  $object->cond_reglement_id = $rcp->thirdparty->cond_reglement_supplier_id;
194  $object->mode_reglement_id = $rcp->thirdparty->mode_reglement_supplier_id;
195  $object->fk_account = !empty($rcp->thirdparty->fk_account) ? $rcp->thirdparty->fk_account : 0;
196  $object->remise_percent = !empty($rcp->thirdparty->remise_percent) ? $rcp->thirdparty->remise_percent : 0;
197  $object->remise_absolue = !empty($rcp->thirdparty->remise_absolue) ? $rcp->thirdparty->remise_absolue : 0;
198 
199  $object->fk_project = $rcp->fk_project;
200  $object->ref_supplier = $rcp->ref_supplier;
201 
202  $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
203  if (empty($datefacture))
204  {
205  $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
206  }
207 
208  $object->date = $datefacture;
209  $object->origin = 'reception';
210  $object->origin_id = $id_reception;
211 
212  $rcp->fetchObjectLinked();
213  if (count($rcp->linkedObjectsIds['reception']) > 0)
214  {
215  foreach ($rcp->linkedObjectsIds['reception'] as $key => $value)
216  {
217  $object->linked_objects['reception'] = $value;
218  }
219  }
220 
221  $res = $object->create($user);
222  //var_dump($object->error);exit;
223  if ($res > 0) {
224  $nb_bills_created++;
225  $object->id = $res;
226  } else {
227  $errors[] = $rcp->ref.' : '.$langs->trans($object->error);
228  $error++;
229  }
230  }
231 
232  if ($object->id > 0)
233  {
234  if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) { //cause function create already add object linked for facturefournisseur
235  $res = $object->add_object_linked($object->origin, $id_reception);
236 
237  if ($res == 0)
238  {
239  $errors[] = $object->error;
240  $error++;
241  }
242  }
243 
244  if (!$error)
245  {
246  $lines = $rcp->lines;
247  if (empty($lines) && method_exists($rcp, 'fetch_lines'))
248  {
249  $rcp->fetch_lines();
250  $lines = $rcp->lines;
251  }
252 
253  $fk_parent_line = 0;
254  $num = count($lines);
255 
256  for ($i = 0; $i < $num; $i++)
257  {
258  $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
259  if ($lines[$i]->subprice < 0)
260  {
261  // Negative line, we create a discount line
262  $discount = new DiscountAbsolute($db);
263  $discount->fk_soc = $object->socid;
264  $discount->amount_ht = abs($lines[$i]->total_ht);
265  $discount->amount_tva = abs($lines[$i]->total_tva);
266  $discount->amount_ttc = abs($lines[$i]->total_ttc);
267  $discount->tva_tx = $lines[$i]->tva_tx;
268  $discount->fk_user = $user->id;
269  $discount->description = $desc;
270  $discountid = $discount->create($user);
271  if ($discountid > 0)
272  {
273  $result = $object->insert_discount($discountid);
274  //$result=$discount->link_to_invoice($lineid,$id);
275  } else {
276  setEventMessages($discount->error, $discount->errors, 'errors');
277  $error++;
278  break;
279  }
280  } else {
281  // Positive line
282  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
283  // Date start
284  $date_start = false;
285  if ($lines[$i]->date_debut_prevue) $date_start = $lines[$i]->date_debut_prevue;
286  if ($lines[$i]->date_debut_reel) $date_start = $lines[$i]->date_debut_reel;
287  if ($lines[$i]->date_start) $date_start = $lines[$i]->date_start;
288  //Date end
289  $date_end = false;
290  if ($lines[$i]->date_fin_prevue) $date_end = $lines[$i]->date_fin_prevue;
291  if ($lines[$i]->date_fin_reel) $date_end = $lines[$i]->date_fin_reel;
292  if ($lines[$i]->date_end) $date_end = $lines[$i]->date_end;
293  // Reset fk_parent_line for no child products and special product
294  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
295  {
296  $fk_parent_line = 0;
297  }
298  $result = $object->addline(
299  $desc,
300  $lines[$i]->subprice,
301  $lines[$i]->tva_tx,
302  $lines[$i]->localtax1_tx,
303  $lines[$i]->localtax2_tx,
304  $lines[$i]->qty,
305  $lines[$i]->fk_product,
306  $lines[$i]->remise_percent,
307  $date_start,
308  $date_end,
309  0,
310  $lines[$i]->info_bits,
311  'HT',
312  $product_type,
313  $i,
314  false,
315  0,
316  null,
317  $lines[$i]->rowid,
318  0,
319  $lines[$i]->ref_supplier
320  );
321 
322  $rcp->add_object_linked('facture_fourn_det', $result);
323 
324  if ($result > 0)
325  {
326  $lineid = $result;
327  } else {
328  $lineid = 0;
329  $error++;
330  break;
331  }
332  // Defined the new fk_parent_line
333  if ($result > 0 && $lines[$i]->product_type == 9)
334  {
335  $fk_parent_line = $result;
336  }
337  }
338  }
339  }
340  }
341 
342  //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
343 
344  if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) $TFactThird[$rcp->socid] = $object;
345  else $TFact[$object->id] = $object;
346  }
347 
348  // Build doc with all invoices
349  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
350  $toselect = array();
351 
352  if (!$error && $validate_invoices)
353  {
354  $massaction = $action = 'builddoc';
355  foreach ($TAllFact as &$object)
356  {
357  $result = $object->validate($user);
358  if ($result <= 0)
359  {
360  $error++;
361  setEventMessages($object->error, $object->errors, 'errors');
362  break;
363  }
364 
365  $id = $object->id; // For builddoc action
366 
367  // Fac builddoc
368  $donotredirect = 1;
369  $upload_dir = $conf->fournisseur->facture->dir_output;
370  $permissiontoadd = $user->rights->fournisseur->facture->creer;
371  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
372  }
373 
374  $massaction = $action = 'confirm_createbills';
375  }
376 
377  if (!$error)
378  {
379  $db->commit();
380  setEventMessage($langs->trans('BillCreated', $nb_bills_created));
381  } else {
382  $db->rollback();
383  $action = 'create';
384  $_GET["origin"] = $_POST["origin"];
385  $_GET["originid"] = $_POST["originid"];
386  setEventMessages($object->error, $errors, 'errors');
387  $error++;
388  }
389  }
390 }
391 
392 
393 /*
394  * View
395  */
396 
397 $form = new Form($db);
398 $companystatic = new Societe($db);
399 $reception = new Reception($db);
400 $formcompany = new FormCompany($db);
401 $formfile = new FormFile($db);
402 
403 
404 $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
405 llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
406 
407 $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,";
408 $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
409 $sql .= " typent.code as typent_code,";
410 $sql .= " state.code_departement as state_code, state.nom as state_name,";
411 $sql .= ' e.date_creation as date_creation, e.tms as date_update';
412 // Add fields from extrafields
413 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
414  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
415 }
416 // Add fields from hooks
417 $parameters = array();
418 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
419 $sql .= $hookmanager->resPrint;
420 $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
421 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
422 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
423 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
424 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
425 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
426 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
427 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
428 if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
429 {
430  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
431 }
432 $sql .= " WHERE e.entity IN (".getEntity('reception').")";
433 if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
434 {
435  $sql .= " AND e.fk_soc = sc.fk_soc";
436  $sql .= " AND sc.fk_user = ".$user->id;
437 }
438 if ($socid)
439 {
440  $sql .= " AND e.fk_soc = ".$socid;
441 }
442 if ($search_status <> '' && $search_status >= 0) {
443  $sql .= " AND e.fk_statut = ".$search_status;
444 }
445 if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND e.billed = '.$search_billed;
446 if ($search_town) $sql .= natural_search('s.town', $search_town);
447 if ($search_zip) $sql .= natural_search("s.zip", $search_zip);
448 if ($search_state) $sql .= natural_search("state.nom", $search_state);
449 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
450 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
451 if ($search_ref_rcp) $sql .= natural_search('e.ref', $search_ref_rcp);
452 if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv);
453 if ($search_company) $sql .= natural_search('s.nom', $search_company);
454 if ($search_ref_supplier) $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
455 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
456 
457 // Add where from extra fields
458 foreach ($search_array_options as $key => $val)
459 {
460  $crit = $val;
461  $tmpkey = preg_replace('/search_options_/', '', $key);
462  $typ = $extrafields->attributes[$object->table_element]['type'][$tmpkey];
463  $mode = 0;
464  if (in_array($typ, array('int', 'double', 'real'))) $mode = 1; // Search on a numeric
465  if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode = 2; // Search on a foreign key int
466  if ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0'))
467  {
468  $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
469  }
470 }
471 // Add where from hooks
472 $parameters = array();
473 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
474 $sql .= $hookmanager->resPrint;
475 
476 $nbtotalofrecords = '';
477 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
478 {
479  $result = $db->query($sql);
480  $nbtotalofrecords = $db->num_rows($result);
481 }
482 
483 $sql .= $db->order($sortfield, $sortorder);
484 $sql .= $db->plimit($limit + 1, $offset);
485 
486 //print $sql;
487 $resql = $db->query($sql);
488 if ($resql)
489 {
490  $num = $db->num_rows($resql);
491 
492  $reception = new Reception($db);
493 
494  $arrayofselected = is_array($toselect) ? $toselect : array();
495 
496  $param = '';
497  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
498  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
499  if ($sall) $param .= "&amp;sall=".urlencode($sall);
500  if ($search_ref_rcp) $param .= "&amp;search_ref_rcp=".urlencode($search_ref_rcp);
501  if ($search_ref_liv) $param .= "&amp;search_ref_liv=".urlencode($search_ref_liv);
502  if ($search_company) $param .= "&amp;search_company=".urlencode($search_company);
503  if ($optioncss != '') $param .= '&amp;optioncss='.urlencode($optioncss);
504  if ($search_billed != '' && $search_billed >= 0) $param .= "&amp;search_billed=".urlencode($search_billed);
505  if ($search_town) $param .= "&amp;search_town=".urlencode($search_town);
506  if ($search_zip) $param .= "&amp;search_zip=".urlencode($search_zip);
507  if ($search_state) $param .= "&amp;search_state=".urlencode($search_state);
508  if ($search_status != '') $param .= "&amp;search_status=".urlencode($search_status);
509  if ($search_country) $param .= "&amp;search_country=".urlencode($search_country);
510  if ($search_type_thirdparty) $param .= "&amp;search_type_thirdparty=".urlencode($search_type_thirdparty);
511  if ($search_ref_supplier) $param .= "&amp;search_ref_supplier=".urlencode($search_ref_supplier);
512  // Add $param from extra fields
513  foreach ($search_array_options as $key => $val)
514  {
515  $crit = $val;
516  $tmpkey = preg_replace('/search_options_/', '', $key);
517  if ($val != '') $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
518  }
519 
520 
521  $arrayofmassactions = array(
522  // 'presend'=>$langs->trans("SendByMail"),
523  );
524 
525  if ($user->rights->fournisseur->facture->creer)$arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisSupplier");
526  if ($massaction == 'createbills') $arrayofmassactions = array();
527  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
528  //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
529 
530  $i = 0;
531  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
532  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
533  print '<input type="hidden" name="token" value="'.newToken().'">';
534  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
535  print '<input type="hidden" name="action" value="list">';
536  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
537  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
538 
539  print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dollyrevert', 0, '', '', $limit, 0, 0, 1);
540 
541 
542  if ($massaction == 'createbills')
543  {
544  //var_dump($_REQUEST);
545  print '<input type="hidden" name="massaction" value="confirm_createbills">';
546 
547  print '<table class="noborder" width="100%" >';
548  print '<tr>';
549  print '<td class="titlefieldmiddle">';
550  print $langs->trans('DateInvoice');
551  print '</td>';
552  print '<td>';
553  print $form->selectDate('', '', '', '', '', '', 1, 1);
554  print '</td>';
555  print '</tr>';
556  print '<tr>';
557  print '<td>';
558  print $langs->trans('CreateOneBillByThird');
559  print '</td>';
560  print '<td>';
561  print $form->selectyesno('createbills_onebythird', '', 1);
562  print '</td>';
563  print '</tr>';
564  print '<tr>';
565  print '<td>';
566  print $langs->trans('ValidateInvoices');
567  print '</td>';
568  print '<td>';
569  if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL))
570  {
571  print $form->selectyesno('validate_invoices', 0, 1, 1);
572  print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
573  } else {
574  print $form->selectyesno('validate_invoices', 0, 1);
575  }
576  print '</td>';
577  print '</tr>';
578  print '</table>';
579 
580  print '<br>';
581  print '<div class="center">';
582  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisSupplier').'"> ';
583  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
584  print '</div>';
585  print '<br>';
586  }
587 
588  if ($sall)
589  {
590  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
591  print $langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall);
592  }
593 
594  $moreforfilter = '';
595  if (!empty($moreforfilter))
596  {
597  print '<div class="liste_titre liste_titre_bydiv centpercent">';
598  print $moreforfilter;
599  $parameters = array('type'=>$type);
600  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
601  print $hookmanager->resPrint;
602  print '</div>';
603  }
604 
605  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
606  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
607  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
608 
609 
610  print '<div class="div-table-responsive">';
611  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
612 
613  // Fields title search
614  // --------------------------------------------------------------------
615  print '<tr class="liste_titre_filter">';
616  // Ref
617  if (!empty($arrayfields['e.ref']['checked']))
618  {
619  print '<td class="liste_titre">';
620  print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
621  print '</td>';
622  }
623  // Ref customer
624  if (!empty($arrayfields['e.ref_supplier']['checked']))
625  {
626  print '<td class="liste_titre">';
627  print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
628  print '</td>';
629  }
630  // Thirdparty
631  if (!empty($arrayfields['s.nom']['checked']))
632  {
633  print '<td class="liste_titre left">';
634  print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
635  print '</td>';
636  }
637  // Town
638  if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
639  // Zip
640  if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
641  // State
642  if (!empty($arrayfields['state.nom']['checked']))
643  {
644  print '<td class="liste_titre">';
645  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
646  print '</td>';
647  }
648  // Country
649  if (!empty($arrayfields['country.code_iso']['checked']))
650  {
651  print '<td class="liste_titre center">';
652  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
653  print '</td>';
654  }
655  // Company type
656  if (!empty($arrayfields['typent.code']['checked']))
657  {
658  print '<td class="liste_titre maxwidthonsmartphone center">';
659  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
660  print '</td>';
661  }
662  // Date delivery planned
663  if (!empty($arrayfields['e.date_delivery']['checked']))
664  {
665  print '<td class="liste_titre">&nbsp;</td>';
666  }
667  if (!empty($arrayfields['l.ref']['checked']))
668  {
669  // Delivery ref
670  print '<td class="liste_titre">';
671  print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
672  print '</td>';
673  }
674  if (!empty($arrayfields['l.date_delivery']['checked']))
675  {
676  // Date received
677  print '<td class="liste_titre">&nbsp;</td>';
678  }
679  // Extra fields
680  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
681 
682  // Fields from hook
683  $parameters = array('arrayfields'=>$arrayfields);
684  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
685  print $hookmanager->resPrint;
686  // Date creation
687  if (!empty($arrayfields['e.datec']['checked']))
688  {
689  print '<td class="liste_titre">';
690  print '</td>';
691  }
692  // Date modification
693  if (!empty($arrayfields['e.tms']['checked']))
694  {
695  print '<td class="liste_titre">';
696  print '</td>';
697  }
698  // Status
699  if (!empty($arrayfields['e.fk_statut']['checked']))
700  {
701  print '<td class="liste_titre maxwidthonsmartphone right">';
702  print $form->selectarray('search_status', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $search_status, 1);
703  print '</td>';
704  }
705  // Status billed
706  if (!empty($arrayfields['e.billed']['checked']))
707  {
708  print '<td class="liste_titre maxwidthonsmartphone center">';
709  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
710  print '</td>';
711  }
712  // Action column
713  print '<td class="liste_titre middle">';
714  $searchpicto = $form->showFilterAndCheckAddButtons(0);
715  print $searchpicto;
716  print '</td>';
717  print "</tr>\n";
718 
719  print '<tr class="liste_titre">';
720  if (!empty($arrayfields['e.ref']['checked'])) print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
721  if (!empty($arrayfields['e.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
722  if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
723  if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
724  if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
725  if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
726  if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
727  if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
728  if (!empty($arrayfields['e.date_delivery']['checked'])) print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
729  if (!empty($arrayfields['l.ref']['checked'])) print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
730  if (!empty($arrayfields['l.date_delivery']['checked'])) print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
731  // Extra fields
732  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
733  // Hook fields
734  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
735  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
736  print $hookmanager->resPrint;
737  if (!empty($arrayfields['e.datec']['checked'])) print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
738  if (!empty($arrayfields['e.tms']['checked'])) print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
739  if (!empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
740  if (!empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
741  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
742  print "</tr>\n";
743 
744  $i = 0;
745  $totalarray = array();
746  while ($i < min($num, $limit))
747  {
748  $obj = $db->fetch_object($resql);
749 
750  $reception->id = $obj->rowid;
751  $reception->ref = $obj->ref;
752 
753  $companystatic->id = $obj->socid;
754  $companystatic->ref = $obj->name;
755  $companystatic->name = $obj->name;
756 
757 
758  print '<tr class="oddeven">';
759 
760  // Ref
761  if (!empty($arrayfields['e.ref']['checked']))
762  {
763  print "<td>";
764  print $reception->getNomUrl(1);
765  $filename = dol_sanitizeFileName($reception->ref);
766  $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
767  $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->id;
768  print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
769  print "</td>\n";
770 
771  if (!$i) $totalarray['nbfield']++;
772  }
773 
774  // Ref customer
775  if (!empty($arrayfields['e.ref_supplier']['checked']))
776  {
777  print "<td>";
778  print $obj->ref_supplier;
779  print "</td>\n";
780  if (!$i) $totalarray['nbfield']++;
781  }
782 
783  // Third party
784  if (!empty($arrayfields['s.nom']['checked']))
785  {
786  print '<td>';
787  print $companystatic->getNomUrl(1);
788  print '</td>';
789  if (!$i) $totalarray['nbfield']++;
790  }
791  // Town
792  if (!empty($arrayfields['s.town']['checked']))
793  {
794  print '<td class="nocellnopadd">';
795  print $obj->town;
796  print '</td>';
797  if (!$i) $totalarray['nbfield']++;
798  }
799  // Zip
800  if (!empty($arrayfields['s.zip']['checked']))
801  {
802  print '<td class="nocellnopadd">';
803  print $obj->zip;
804  print '</td>';
805  if (!$i) $totalarray['nbfield']++;
806  }
807  // State
808  if (!empty($arrayfields['state.nom']['checked']))
809  {
810  print "<td>".$obj->state_name."</td>\n";
811  if (!$i) $totalarray['nbfield']++;
812  }
813  // Country
814  if (!empty($arrayfields['country.code_iso']['checked']))
815  {
816  print '<td class="center">';
817  $tmparray = getCountry($obj->fk_pays, 'all');
818  print $tmparray['label'];
819  print '</td>';
820  if (!$i) $totalarray['nbfield']++;
821  }
822  // Type ent
823  if (!empty($arrayfields['typent.code']['checked']))
824  {
825  print '<td class="center">';
826  if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
827  print $typenArray[$obj->typent_code];
828  print '</td>';
829  if (!$i) $totalarray['nbfield']++;
830  }
831 
832  // Date delivery planed
833  if (!empty($arrayfields['e.date_delivery']['checked']))
834  {
835  print '<td class="center">';
836  print dol_print_date($db->jdate($obj->delivery_date), "day");
837  /*$now = time();
838  if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
839  {
840  }*/
841  print "</td>\n";
842  }
843 
844  if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked']))
845  {
846  $reception->fetchObjectLinked($reception->id, $reception->element);
847  $receiving = '';
848  if (count($reception->linkedObjects['delivery']) > 0) $receiving = reset($reception->linkedObjects['delivery']);
849 
850  if (!empty($arrayfields['l.ref']['checked']))
851  {
852  // Ref
853  print '<td>';
854  print !empty($receiving) ? $receiving->getNomUrl($db) : '';
855  print '</td>';
856  }
857 
858  if (!empty($arrayfields['l.date_delivery']['checked']))
859  {
860  // Date received
861  print '<td class="center">';
862  print dol_print_date($db->jdate($obj->date_reception), "day");
863  print '</td>'."\n";
864  }
865  }
866 
867  // Extra fields
868  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
869 
870  // Fields from hook
871  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
872  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
873  print $hookmanager->resPrint;
874  // Date creation
875  if (!empty($arrayfields['e.datec']['checked']))
876  {
877  print '<td class="center nowrap">';
878  print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
879  print '</td>';
880  if (!$i) $totalarray['nbfield']++;
881  }
882  // Date modification
883  if (!empty($arrayfields['e.tms']['checked']))
884  {
885  print '<td class="center nowrap">';
886  print dol_print_date($db->jdate($obj->date_update), 'dayhour');
887  print '</td>';
888  if (!$i) $totalarray['nbfield']++;
889  }
890  // Status
891  if (!empty($arrayfields['e.fk_statut']['checked']))
892  {
893  print '<td class="right nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>';
894  if (!$i) $totalarray['nbfield']++;
895  }
896  // Billed
897  if (!empty($arrayfields['e.billed']['checked']))
898  {
899  print '<td class="center">'.yn($obj->billed).'</td>';
900  if (!$i) $totalarray['nbfield']++;
901  }
902 
903  // Action column
904  print '<td class="center">';
905  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
906  {
907  $selected = 0;
908  if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
909  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
910  }
911  print '</td>';
912  if (!$i) $totalarray['nbfield']++;
913 
914  print "</tr>\n";
915 
916  $i++;
917  }
918 
919  print "</table>";
920  print "</div>";
921  print '</form>';
922  $db->free($resql);
923 } else {
924  dol_print_error($db);
925 }
926 
927 llxFooter();
928 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const TYPE_STANDARD
Standard invoice.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
Class to manage suppliers invoices.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage receptions.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage absolute discounts.
llxFooter()
Empty footer.
Definition: wrapper.php:59
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.