37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40if (isModEnabled(
"propal")) {
41 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
43if (isModEnabled(
'commande')) {
44 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
63 public $element =
"reception";
68 public $fk_element =
"fk_reception";
69 public $table_element =
"reception";
70 public $table_element_line =
"commande_fournisseur_dispatch";
71 public $ismultientitymanaged = 1;
76 public $picto =
'dollyrevert';
83 public $tracking_number;
99 public $date_delivery;
111 public $date_reception;
116 public $date_creation;
129 public $lines = array();
134 public $detail_batch;
136 const STATUS_DRAFT = 0;
137 const STATUS_VALIDATED = 1;
138 const STATUS_CLOSED = 2;
160 global $langs, $conf;
161 $langs->load(
"receptions");
163 if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) {
166 $file = $conf->global->RECEPTION_ADDON_NUMBER.
".php";
167 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
170 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
172 foreach ($dirmodels as $reldir) {
176 $mybool |= @include_once $dir.$file;
184 $obj =
new $classname();
187 $numref = $obj->getNextValue($soc, $this);
192 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
196 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
208 public function create($user, $notrigger = 0)
210 global $conf, $hookmanager;
214 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
218 $this->brouillon = 1;
220 if (empty($this->fk_project)) {
221 $this->fk_project = 0;
223 if (empty($this->weight_units)) {
224 $this->weight_units = 0;
226 if (empty($this->size_units)) {
227 $this->size_units = 0;
234 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
237 $sql .=
", ref_supplier";
238 $sql .=
", date_creation";
239 $sql .=
", fk_user_author";
240 $sql .=
", date_reception";
241 $sql .=
", date_delivery";
243 $sql .=
", fk_projet";
244 $sql .=
", fk_shipping_method";
245 $sql .=
", tracking_number";
250 $sql .=
", weight_units";
251 $sql .=
", size_units";
252 $sql .=
", note_private";
253 $sql .=
", note_public";
254 $sql .=
", model_pdf";
255 $sql .=
", fk_incoterms, location_incoterms";
256 $sql .=
") VALUES (";
258 $sql .=
", ".((int) $conf->entity);
259 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
260 $sql .=
", '".$this->db->idate($now).
"'";
261 $sql .=
", ".((int) $user->id);
262 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
263 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
264 $sql .=
", ".((int) $this->socid);
265 $sql .=
", ".((int) $this->fk_project);
266 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
267 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
268 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((double) $this->weight));
269 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((double) $this->trueDepth));
270 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((double) $this->trueWidth));
271 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((double) $this->trueHeight));
272 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((double) $this->weight_units));
273 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((double) $this->size_units));
274 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
275 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
276 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
277 $sql .=
", ".(int) $this->fk_incoterms;
278 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
281 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
283 $resql = $this->db->query($sql);
286 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
288 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
289 $sql .=
" SET ref = '(PROV".$this->id.
")'";
290 $sql .=
" WHERE rowid = ".((int) $this->
id);
292 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
293 if ($this->db->query($sql)) {
295 $num = count($this->lines);
296 for ($i = 0; $i < $num; $i++) {
297 $this->lines[$i]->fk_reception = $this->id;
299 if (!$this->lines[$i]->
create($user) > 0) {
304 if (!$error && $this->
id && $this->origin_id) {
319 if (!$error && !$notrigger) {
321 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
332 foreach ($this->errors as $errmsg) {
333 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
334 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
336 $this->db->rollback();
341 $this->error = $this->db->lasterror().
" - sql=$sql";
342 $this->db->rollback();
347 $this->error = $this->db->error().
" - sql=$sql";
348 $this->db->rollback();
363 public function fetch($id, $ref =
'', $ref_ext =
'')
366 if (empty($id) && empty($ref) && empty($ref_ext)) {
370 $sql =
"SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut";
371 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
372 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
373 $sql .=
", e.fk_shipping_method, e.tracking_number";
374 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
375 $sql .=
", e.note_private, e.note_public";
376 $sql .=
', e.fk_incoterms, e.location_incoterms';
377 $sql .=
', i.libelle as label_incoterms';
378 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
379 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
380 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
381 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
383 $sql .=
" AND e.rowid=".((int) $id);
386 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
389 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
392 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
393 $result = $this->db->query($sql);
395 if ($this->db->num_rows($result)) {
396 $obj = $this->db->fetch_object($result);
398 $this->
id = $obj->rowid;
399 $this->entity = $obj->entity;
400 $this->
ref = $obj->ref;
401 $this->socid = $obj->socid;
402 $this->ref_supplier = $obj->ref_supplier;
403 $this->ref_ext = $obj->ref_ext;
404 $this->
statut = $obj->fk_statut;
405 $this->user_author_id = $obj->fk_user_author;
406 $this->date_creation = $this->db->jdate($obj->date_creation);
407 $this->date = $this->db->jdate($obj->date_reception);
408 $this->date_reception = $this->db->jdate($obj->date_reception);
409 $this->date_delivery = $this->db->jdate($obj->date_delivery);
410 $this->model_pdf = $obj->model_pdf;
411 $this->modelpdf = $obj->model_pdf;
412 $this->shipping_method_id = $obj->fk_shipping_method;
413 $this->tracking_number = $obj->tracking_number;
414 $this->origin = ($obj->origin ? $obj->origin :
'commande');
415 $this->origin_id = $obj->origin_id;
416 $this->billed = ($obj->fk_statut == 2 ? 1 : 0);
418 $this->trueWeight = $obj->weight;
419 $this->weight_units = $obj->weight_units;
421 $this->trueWidth = $obj->width;
422 $this->width_units = $obj->size_units;
423 $this->trueHeight = $obj->height;
424 $this->height_units = $obj->size_units;
425 $this->trueDepth = $obj->size;
426 $this->depth_units = $obj->size_units;
428 $this->note_public = $obj->note_public;
429 $this->note_private = $obj->note_private;
432 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
433 $this->size_units = $obj->size_units;
436 $this->fk_incoterms = $obj->fk_incoterms;
437 $this->location_incoterms = $obj->location_incoterms;
438 $this->label_incoterms = $obj->label_incoterms;
440 $this->db->free($result);
443 $this->brouillon = 1;
460 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
462 $extrafields->fetch_name_optionals_label($this->table_element,
true);
475 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
476 $this->error =
'Reception with id '.$id.
' not found';
480 $this->error = $this->db->error();
492 public function valid($user, $notrigger = 0)
494 global $conf, $langs;
496 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
502 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
506 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
507 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
508 $this->error =
'Permission denied';
509 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
519 $soc->fetch($this->socid);
523 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
526 $numref = $this->ref;
534 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
535 $sql .=
" ref='".$this->db->escape($numref).
"'";
536 $sql .=
", fk_statut = 1";
537 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
538 $sql .=
", fk_user_valid = ".$user->id;
539 $sql .=
" WHERE rowid = ".((int) $this->
id);
540 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
541 $resql = $this->db->query($sql);
543 $this->error = $this->db->lasterror();
548 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
549 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
551 $langs->load(
"agenda");
555 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
556 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
557 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
558 $sql .=
" ed.cost_price";
559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
560 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
561 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
562 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
564 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
565 $resql = $this->db->query($sql);
567 $cpt = $this->db->num_rows($resql);
568 for ($i = 0; $i < $cpt; $i++) {
569 $obj = $this->db->fetch_object($resql);
573 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
576 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
580 $mouvS->origin = &$this;
581 $mouvS->setOrigin($this->element, $this->
id);
583 if (empty($obj->batch)) {
588 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
590 if (intval($result) < 0) {
592 $this->errors[] = $mouvS->error;
593 $this->errors = array_merge($this->errors, $mouvS->errors);
602 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch,
'', 0, $inventorycode);
604 if (intval($result) < 0) {
606 $this->errors[] = $mouvS->error;
607 $this->errors = array_merge($this->errors, $mouvS->errors);
613 $this->db->rollback();
614 $this->error = $this->db->error();
626 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
629 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
632 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
639 if (!$error && !$notrigger) {
641 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
649 $this->oldref = $this->ref;
652 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
654 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'reception/".$this->db->escape($this->newref).
"'";
655 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
656 $resql = $this->db->query($sql);
658 $error++; $this->error = $this->db->lasterror();
660 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
661 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
662 $resql = $this->db->query($sql);
664 $error++; $this->error = $this->db->lasterror();
670 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
671 $dirdest = $conf->reception->dir_output.
'/'.$newref;
672 if (!$error && file_exists($dirsource)) {
673 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
675 if (@rename($dirsource, $dirdest)) {
678 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
679 foreach ($listoffiles as $fileentry) {
680 $dirsource = $fileentry[
'name'];
681 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
682 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
683 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
684 @rename($dirsource, $dirdest);
693 $this->
ref = $numref;
701 foreach ($this->errors as $errmsg) {
702 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
703 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
705 $this->db->rollback();
719 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
720 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
724 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
725 if (empty($this->commandeFournisseur)) {
727 if (empty($this->commandeFournisseur->lines)) {
728 $res = $this->commandeFournisseur->fetch_lines();
729 if ($res < 0)
return $res;
733 $qty_received = array();
734 $qty_wished = array();
737 $filter = array(
't.fk_commande'=>$this->origin_id);
738 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
739 $filter[
't.status'] = 1;
742 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
744 $this->error = $supplierorderdispatch->error;
745 $this->errors = $supplierorderdispatch->errors;
749 foreach ($supplierorderdispatch->lines as $dispatch_line) {
750 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
751 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
753 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
758 foreach ($this->commandeFournisseur->lines as $origin_line) {
760 if ((!
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
764 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
768 $diff_array = array_diff_assoc($qty_received, $qty_wished);
769 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
770 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
772 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
774 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
778 if (count($diff_array) > 0) {
781 foreach ($diff_array as $key => $value) {
783 if ($qty_received[$key] >= $qty_wished[$key]) {
789 if ($close == count($diff_array)) {
816 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
818 global $conf, $langs, $user;
820 $num = count($this->lines);
823 $line->fk_entrepot = $entrepot_id;
824 $line->fk_commandefourndet = $id;
828 $result = $supplierorderline->fetch($id);
830 $this->error = $supplierorderline->error;
831 $this->errors = $supplierorderline->errors;
836 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
837 $fk_product = $supplierorderline->fk_product;
839 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
840 $langs->load(
"errors");
841 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
847 $product =
new Product($this->db);
848 $product->fetch($fk_product);
849 if (isModEnabled(
'productbatch')) {
850 $langs->load(
"errors");
851 if (!empty($product->status_batch) && empty($batch)) {
852 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
854 } elseif (empty($product->status_batch) && !empty($batch)) {
855 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
862 $line->array_options = $supplierorderline->array_options;
863 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
864 foreach ($array_options as $key => $value) {
865 $line->array_options[$key] = $value;
869 $line->fk_product = $fk_product;
870 $line->fk_commande = $supplierorderline->fk_commande;
871 $line->fk_user = $user->id;
872 $line->comment = $comment;
873 $line->batch = $batch;
874 $line->eatby = $eatby;
875 $line->sellby = $sellby;
877 $line->cost_price = $cost_price;
878 $line->fk_reception = $this->id;
880 $this->lines[$num] = $line;
893 public function update($user =
null, $notrigger = 0)
900 if (isset($this->
ref)) {
901 $this->
ref = trim($this->
ref);
903 if (isset($this->entity)) {
904 $this->entity = trim($this->entity);
906 if (isset($this->ref_supplier)) {
907 $this->ref_supplier = trim($this->ref_supplier);
909 if (isset($this->socid)) {
910 $this->socid = trim($this->socid);
912 if (isset($this->fk_user_author)) {
913 $this->fk_user_author = trim($this->fk_user_author);
915 if (isset($this->fk_user_valid)) {
916 $this->fk_user_valid = trim($this->fk_user_valid);
918 if (isset($this->shipping_method_id)) {
919 $this->shipping_method_id = trim($this->shipping_method_id);
921 if (isset($this->tracking_number)) {
922 $this->tracking_number = trim($this->tracking_number);
924 if (isset($this->
statut)) {
927 if (isset($this->trueDepth)) {
928 $this->trueDepth = trim($this->trueDepth);
930 if (isset($this->trueWidth)) {
931 $this->trueWidth = trim($this->trueWidth);
933 if (isset($this->trueHeight)) {
934 $this->trueHeight = trim($this->trueHeight);
936 if (isset($this->size_units)) {
937 $this->size_units = trim($this->size_units);
939 if (isset($this->weight_units)) {
940 $this->weight_units = trim($this->weight_units);
942 if (isset($this->trueWeight)) {
943 $this->weight = trim($this->trueWeight);
945 if (isset($this->note_private)) {
946 $this->note_private = trim($this->note_private);
948 if (isset($this->note_public)) {
949 $this->note_public = trim($this->note_public);
951 if (isset($this->model_pdf)) {
952 $this->model_pdf = trim($this->model_pdf);
960 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
962 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
963 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
964 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
965 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
966 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
967 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
968 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
969 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
970 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
971 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
972 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
973 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
974 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
975 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
976 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
977 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
978 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
979 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
980 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
981 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
982 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
983 $sql .=
" entity = ".((int) $conf->entity);
984 $sql .=
" WHERE rowid=".((int) $this->
id);
988 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
989 $resql = $this->db->query($sql);
991 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
997 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1007 foreach ($this->errors as $errmsg) {
1008 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1009 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1011 $this->db->rollback();
1014 $this->db->commit();
1027 global $conf, $langs, $user;
1028 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1037 if (isModEnabled(
'stock') &&
1041 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1043 $langs->load(
"agenda");
1046 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as commande_fournisseur_dispatch_id";
1047 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1048 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1049 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1050 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1052 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1053 $resql = $this->db->query($sql);
1055 $cpt = $this->db->num_rows($resql);
1056 for ($i = 0; $i < $cpt; $i++) {
1057 dol_syslog(get_class($this).
"::delete movement index ".$i);
1058 $obj = $this->db->fetch_object($resql);
1062 $mouvS->origin =
null;
1064 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby ? $this->db->jdate($obj->eatby) :
null, $obj->sellby ? $this->db->jdate($obj->sellby) :
null, $obj->batch);
1067 $this->error = $mouvS->error;
1068 $this->errors = $mouvS->errors;
1072 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1077 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1078 $ef = $main.
"_extrafields";
1080 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1082 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1083 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1085 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1093 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1094 $sql .=
" WHERE rowid = ".((int) $this->
id);
1096 if ($this->db->query($sql)) {
1098 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1104 if (!empty($this->origin) && $this->origin_id > 0) {
1106 $origin = $this->origin;
1107 if ($this->$origin->statut == 4) {
1109 $this->$origin->loadReceptions();
1111 if (count($this->$origin->receptions) <= 0) {
1112 $this->$origin->setStatut(3);
1118 $this->db->commit();
1122 if (!empty($conf->reception->dir_output)) {
1123 $dir = $conf->reception->dir_output.
'/'.$ref;
1124 $file = $dir.
'/'.$ref.
'.pdf';
1125 if (file_exists($file)) {
1130 if (file_exists($dir)) {
1132 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1140 $this->db->rollback();
1144 $this->error = $this->db->lasterror().
" - sql=$sql";
1145 $this->db->rollback();
1149 $this->error = $this->db->lasterror().
" - sql=$sql";
1150 $this->db->rollback();
1154 $this->error = $this->db->lasterror().
" - sql=$sql";
1155 $this->db->rollback();
1159 $this->db->rollback();
1173 $this->lines = array();
1175 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1177 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1178 $resql = $this->db->query($sql);
1180 if (!empty($resql)) {
1181 while ($obj = $this->db->fetch_object($resql)) {
1184 $line->fetch($obj->rowid);
1187 $line->fetch_product();
1189 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1190 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1191 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1192 $sql_commfourndet .=
' ORDER BY rang';
1194 $resql_commfourndet = $this->db->query($sql_commfourndet);
1195 if (!empty($resql_commfourndet)) {
1196 $obj = $this->db->fetch_object($resql_commfourndet);
1197 $line->qty_asked = $obj->qty;
1198 $line->description = $obj->description;
1199 $line->desc = $obj->description;
1200 $line->tva_tx = $obj->tva_tx;
1201 $line->vat_src_code = $obj->vat_src_code;
1202 $line->subprice = $obj->subprice;
1203 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1204 $line->remise_percent = $obj->remise_percent;
1205 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1206 $line->ref_supplier = $obj->ref;
1207 $line->total_ht = $obj->total_ht;
1208 $line->total_ttc = $obj->total_ttc;
1209 $line->total_tva = $obj->total_tva;
1211 $line->qty_asked = 0;
1212 $line->description =
'';
1214 $line->label = $obj->label;
1217 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1218 $tva = $pu_ht * $line->tva_tx / 100;
1219 $this->total_ht += $pu_ht;
1220 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1222 $this->total_ttc += $pu_ht + $tva;
1224 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1225 $detail_batch =
new stdClass();
1226 $detail_batch->eatby = $line->eatby;
1227 $detail_batch->sellby = $line->sellby;
1228 $detail_batch->batch = $line->batch;
1229 $detail_batch->qty = $line->qty;
1230 $line->detail_batch[] = $detail_batch;
1233 $this->lines[] = $line;
1252 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1254 global $conf, $langs, $hookmanager;
1256 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1257 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1258 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1260 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1267 if (empty($notooltip)) {
1268 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1269 $label = $langs->trans(
"Reception");
1270 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1272 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1273 $linkclose .=
' class="classfortooltip"';
1276 $linkstart =
'<a href="'.$url.
'"';
1277 $linkstart .= $linkclose.
'>';
1280 $result .= $linkstart;
1282 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1284 if ($withpicto != 2) {
1285 $result .= $this->ref;
1288 $result .= $linkend;
1291 $hookmanager->initHooks(array($this->element .
'dao'));
1292 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1293 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1295 $result = $hookmanager->resPrint;
1297 $result .= $hookmanager->resPrint;
1327 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1328 $this->labelStatus[0] =
'StatusReceptionDraft';
1330 $this->labelStatus[1] =
'StatusReceptionValidated';
1332 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1335 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1337 $this->labelStatus[2] =
'StatusReceptionProcessed';
1340 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1341 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1342 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1343 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1345 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1346 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1348 $statusType =
'status'.$status;
1349 if ($status == self::STATUS_VALIDATED) {
1350 $statusType =
'status4';
1352 if ($status == self::STATUS_CLOSED) {
1353 $statusType =
'status6';
1356 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1370 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1371 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1374 dol_syslog(get_class($this).
"::initAsSpecimen");
1377 $order->initAsSpecimen();
1381 $this->
ref =
'SPECIMEN';
1382 $this->specimen = 1;
1384 $this->livraison_id = 0;
1386 $this->date_creation = $now;
1387 $this->date_valid = $now;
1388 $this->date_delivery = $now;
1389 $this->date_reception = $now + 24 * 3600;
1391 $this->entrepot_id = 0;
1394 $this->commande_id = 0;
1395 $this->commande = $order;
1397 $this->origin_id = 1;
1398 $this->origin =
'commande';
1400 $this->note_private =
'Private note';
1401 $this->note_public =
'Public note';
1405 while ($xnbp < $nbp) {
1407 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1408 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1409 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1412 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1414 $this->lines[] = $line;
1429 if ($user->rights->reception->creer) {
1430 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1431 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1432 $sql .=
" WHERE rowid = ".((int) $this->
id);
1434 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1435 $resql = $this->db->query($sql);
1437 $this->date_delivery = $delivery_date;
1440 $this->error = $this->db->error();
1458 $this->meths = array();
1460 $sql =
"SELECT em.rowid, em.code, em.libelle";
1461 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1462 $sql .=
" WHERE em.active = 1";
1463 $sql .=
" ORDER BY em.libelle ASC";
1465 $resql = $this->db->query($sql);
1467 while ($obj = $this->db->fetch_object($resql)) {
1468 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1469 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1486 $this->listmeths = array();
1489 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1490 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1492 $sql .=
" WHERE em.rowid = ".((int) $id);
1495 $resql = $this->db->query($sql);
1497 while ($obj = $this->db->fetch_object($resql)) {
1498 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1499 $this->listmeths[$i][
'code'] = $obj->code;
1500 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1501 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1502 $this->listmeths[$i][
'description'] = $obj->description;
1503 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1504 $this->listmeths[$i][
'active'] = $obj->active;
1518 if (!empty($this->shipping_method_id)) {
1519 $sql =
"SELECT em.code, em.tracking";
1520 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1521 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1523 $resql = $this->db->query($sql);
1525 if ($obj = $this->db->fetch_object($resql)) {
1526 $tracking = $obj->tracking;
1531 if (!empty($tracking) && !empty($value)) {
1532 $url = str_replace(
'{TRACKID}', $value, $tracking);
1533 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1535 $this->tracking_url = $value;
1546 global $conf, $langs, $user;
1551 if ($this->
statut == Reception::STATUS_CLOSED) {
1552 dol_syslog(get_class($this).
"::Already in closed status", LOG_WARNING);
1558 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1559 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1561 $resql = $this->db->query($sql);
1564 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1565 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1568 $order->fetch($this->origin_id);
1570 $order->loadReceptions(self::STATUS_CLOSED);
1572 $receptions_match_order = 1;
1573 foreach ($order->lines as $line) {
1574 $lineid = $line->id;
1576 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1577 $receptions_match_order = 0;
1578 $text =
'Qty for order line id '.$lineid.
' is '.$qty.
'. However in the receptions with status Reception::STATUS_CLOSED='.self::STATUS_CLOSED.
' we have qty = '.$order->receptions[$lineid].
', so we can t close order';
1583 if ($receptions_match_order) {
1584 dol_syslog(
"Qty for the ".count($order->lines).
" lines of order have same value for receptions with status Reception::STATUS_CLOSED=".self::STATUS_CLOSED.
', so we close order');
1585 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1589 $this->
statut = self::STATUS_CLOSED;
1593 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1594 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1596 $langs->load(
"agenda");
1600 $sql =
"SELECT cd.fk_product, cd.subprice,";
1601 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1602 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1603 $sql .=
" ed.cost_price";
1604 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1605 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1606 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1607 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1609 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1610 $resql = $this->db->query($sql);
1613 $cpt = $this->db->num_rows($resql);
1614 for ($i = 0; $i < $cpt; $i++) {
1615 $obj = $this->db->fetch_object($resql);
1622 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1625 $mouvS->origin = &$this;
1626 $mouvS->setOrigin($this->element, $this->
id);
1628 if (empty($obj->batch)) {
1632 $inventorycode =
'';
1633 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1635 $this->error = $mouvS->error;
1636 $this->errors = $mouvS->errors;
1643 $inventorycode =
'';
1644 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch,
'', 0, $inventorycode);
1647 $this->error = $mouvS->error;
1648 $this->errors = $mouvS->errors;
1654 $this->error = $this->db->lasterror();
1661 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1672 $this->db->commit();
1675 $this->db->rollback();
1692 if ($this->
statut == Reception::STATUS_VALIDATED) {
1697 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1698 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1700 $resql = $this->db->query($sql);
1706 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1712 $this->errors[] = $this->db->lasterror;
1715 if (empty($error)) {
1716 $this->db->commit();
1719 $this->db->rollback();
1731 global $conf, $langs, $user;
1737 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1738 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1740 $resql = $this->db->query($sql);
1746 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1747 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1748 $numref = $this->ref;
1749 $langs->load(
"agenda");
1753 $sql =
"SELECT ed.fk_product, cd.subprice,";
1754 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1755 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1756 $sql .=
" ed.cost_price";
1757 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1758 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1759 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1760 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1762 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1763 $resql = $this->db->query($sql);
1765 $cpt = $this->db->num_rows($resql);
1766 for ($i = 0; $i < $cpt; $i++) {
1767 $obj = $this->db->fetch_object($resql);
1775 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1779 $mouvS->origin = &$this;
1780 $mouvS->setOrigin($this->element, $this->
id);
1782 if (empty($obj->batch)) {
1786 $inventorycode =
'';
1787 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1790 $this->error = $mouvS->error;
1791 $this->errors = $mouvS->errors;
1798 $inventorycode =
'';
1799 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock, $inventorycode);
1801 $this->error = $mouvS->error;
1802 $this->errors = $mouvS->errors;
1808 $this->error = $this->db->lasterror();
1815 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1821 if (!$error && $this->origin ==
'order_supplier') {
1822 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1825 $commande->fetch($this->origin_id);
1826 $result = $commande->setStatus($user, 4);
1829 $this->error = $commande->error;
1830 $this->errors = $commande->errors;
1835 $this->errors[] = $this->db->lasterror();
1839 $this->db->commit();
1842 $this->db->rollback();
1856 global $conf, $langs;
1861 if ($this->
statut <= self::STATUS_DRAFT) {
1865 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1866 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1867 $this->error =
'Permission denied';
1873 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1874 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1875 $sql .=
" WHERE rowid = ".((int) $this->
id);
1878 if ($this->db->query($sql)) {
1880 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1881 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1883 $langs->load(
"agenda");
1887 $sql =
"SELECT cd.fk_product, cd.subprice,";
1888 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1889 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1890 $sql .=
" ed.cost_price";
1891 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1892 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1893 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1894 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1896 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1897 $resql = $this->db->query($sql);
1899 $cpt = $this->db->num_rows($resql);
1900 for ($i = 0; $i < $cpt; $i++) {
1901 $obj = $this->db->fetch_object($resql);
1909 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1913 $mouvS->origin = &$this;
1914 $mouvS->setOrigin($this->element, $this->
id);
1916 if (empty($obj->batch)) {
1920 $inventorycode =
'';
1921 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1923 $this->error = $mouvS->error;
1924 $this->errors = $mouvS->errors;
1932 $inventorycode =
'';
1933 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, 0, $inventorycode);
1935 $this->error = $mouvS->error;
1936 $this->errors = $mouvS->errors;
1942 $this->error = $this->db->lasterror();
1949 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1954 if ($this->origin ==
'order_supplier') {
1955 if (!empty($this->origin) && $this->origin_id > 0) {
1957 $origin = $this->origin;
1958 if ($this->$origin->statut == 4) {
1960 $this->$origin->fetchObjectLinked();
1962 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1963 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1964 if ($rcption->statut > 0) {
1971 $this->$origin->setStatut(3);
1979 $this->
statut = self::STATUS_DRAFT;
1980 $this->db->commit();
1983 $this->db->rollback();
1987 $this->error = $this->db->error();
1988 $this->db->rollback();
2003 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2005 global $conf, $langs;
2007 $langs->load(
"receptions");
2010 $modele =
'squille';
2012 if ($this->model_pdf) {
2013 $modele = $this->model_pdf;
2014 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
2015 $modele = $conf->global->RECEPTION_ADDON_PDF;
2019 $modelpath =
"core/modules/reception/doc/";
2023 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2036 $tables = array(
'reception');
2052 'commande_fournisseur_dispatch'
Class to manage table commandefournisseurdispatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used when WORKFLOW_RECEPTION_CLASSIFY_CLOSED_INVOICE is on)
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0)
Return clicable link of object (with eventually picto)
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this record also the stock movement)
getNextNumRef($soc)
Return next contract ref.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='', $cost_price=0)
Add an reception line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
list_delivery_methods($id='')
Fetch all deliveries method and return an array.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
__construct($db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create reception en base.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
setDraft($user)
Set draft status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m m m statut
trait CommonIncoterm
Superclass for incoterm classes.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.