39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/reception/class/receptionlinebatch.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
62 public $TRIGGER_PREFIX =
'RECEPTION';
72 public $element =
"reception";
77 public $fk_element =
"fk_reception";
82 public $table_element =
"reception";
87 public $table_element_line =
"receptiondet_batch";
92 public $picto =
'dollyrevert';
101 public $ref_supplier;
110 public $tracking_number;
114 public $tracking_url;
131 public $weight_units;
147 public $height_units;
167 public $user_author_id;
172 public $date_delivery;
184 public $date_reception;
203 public $lines = array();
210 public $detail_batch;
212 const STATUS_DRAFT = 0;
213 const STATUS_VALIDATED = 1;
214 const STATUS_CLOSED = 2;
226 $this->ismultientitymanaged = 1;
227 $this->isextrafieldmanaged = 1;
236 public function getNextNumRef($soc)
238 global $langs, $conf;
239 $langs->load(
"receptions");
248 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
250 foreach ($dirmodels as $reldir) {
254 $mybool = ((bool) @include_once $dir.$file) || $mybool;
262 $obj =
new $classname();
263 '@phan-var-force ModelNumRefReception $obj';
266 $numref = $obj->getNextValue($soc, $this);
271 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
275 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
287 public function create($user, $notrigger = 0)
293 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
298 if (empty($this->fk_project)) {
299 $this->fk_project = 0;
301 if (empty($this->weight_units)) {
302 $this->weight_units = 0;
304 if (empty($this->size_units)) {
305 $this->size_units = 0;
307 if (empty($this->date_creation)) {
308 $this->date_creation = $now;
317 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
320 $sql .=
", ref_supplier";
321 $sql .=
", date_creation";
322 $sql .=
", fk_user_author";
323 $sql .=
", date_reception";
324 $sql .=
", date_delivery";
326 $sql .=
", fk_projet";
327 $sql .=
", fk_shipping_method";
328 $sql .=
", tracking_number";
333 $sql .=
", weight_units";
334 $sql .=
", size_units";
335 $sql .=
", note_private";
336 $sql .=
", note_public";
337 $sql .=
", model_pdf";
338 $sql .=
", fk_incoterms, location_incoterms";
339 $sql .=
") VALUES (";
341 $sql .=
", ".((int) $this->entity);
342 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
343 $sql .=
", '".$this->db->idate($this->date_creation).
"'";
344 $sql .=
", ".((int) $user->id);
345 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
346 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
347 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
348 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
349 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
350 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
351 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
352 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
353 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
354 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
355 $sql .=
", ".((int) $this->weight_units);
356 $sql .=
", ".((int) $this->size_units);
357 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
358 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
359 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
360 $sql .=
", ".(int) $this->fk_incoterms;
361 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
364 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
366 $resql = $this->db->query($sql);
369 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
372 $initialref =
'(PROV'.$this->id.
')';
373 if (!empty($this->
ref)) {
374 $initialref = $this->ref;
377 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
378 $sql .=
" SET ref = '".$this->db->escape($initialref).
"'";
379 $sql .=
" WHERE rowid = ".((int) $this->
id);
381 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
382 if ($this->db->query($sql)) {
384 $num = count($this->lines);
385 for ($i = 0; $i < $num; $i++) {
386 $this->lines[$i]->fk_reception = $this->id;
388 if ($this->lines[$i]->
create($user) <= 0) {
394 if (!$error && $this->
id && $this->origin_id) {
409 if (!$error && !$notrigger) {
411 $result = $this->call_trigger(
'RECEPTION_CREATE', $user);
422 foreach ($this->errors as $errmsg) {
423 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
424 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
426 $this->db->rollback();
431 $this->error = $this->db->lasterror().
" - sql=$sql";
432 $this->db->rollback();
437 $this->error = $this->db->error().
" - sql=$sql";
438 $this->db->rollback();
456 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
462 $receptionline->fk_reception = $this->id;
463 $receptionline->entrepot_id = $entrepot_id;
464 $receptionline->fk_elementdet = $origin_line_id;
465 $receptionline->element_type = $this->origin;
466 $receptionline->fk_parent = $parent_line_id;
467 $receptionline->fk_product = $product_id;
468 $receptionline->qty = $qty;
469 $receptionline->rang = $rang;
470 $receptionline->array_options = $array_options;
472 if (!($receptionline->fk_product > 0)) {
474 $order_line->fetch($receptionline->fk_elementdet);
475 $receptionline->fk_product = $order_line->fk_product;
478 if (($lineId = $receptionline->insert($user)) < 0) {
479 $this->errors[] = $receptionline->error;
492 public function fetch($id, $ref =
'', $ref_ext =
'')
495 if (empty($id) && empty($ref) && empty($ref_ext)) {
499 $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 as status, e.fk_projet as fk_project, e.billed";
500 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
501 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
502 $sql .=
", e.fk_shipping_method, e.tracking_number";
503 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
504 $sql .=
", e.note_private, e.note_public";
505 $sql .=
', e.fk_incoterms, e.location_incoterms';
506 $sql .=
', i.libelle as label_incoterms';
507 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
508 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"' AND el.sourcetype = 'order_supplier'";
509 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
512 $sql .=
" WHERE e.rowid = ".((int) $id);
514 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
516 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
517 } elseif ($ref_ext) {
518 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
522 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
523 $result = $this->db->query($sql);
525 if ($this->db->num_rows($result)) {
526 $obj = $this->db->fetch_object($result);
528 $this->
id = $obj->rowid;
529 $this->entity = $obj->entity;
530 $this->
ref = $obj->ref;
531 $this->socid = $obj->socid;
532 $this->ref_supplier = $obj->ref_supplier;
533 $this->ref_ext = $obj->ref_ext;
534 $this->statut = $obj->status;
535 $this->
status = $obj->status;
536 $this->billed = $obj->billed;
537 $this->fk_project = $obj->fk_project;
538 $this->user_author_id = $obj->fk_user_author;
539 $this->date_creation = $this->db->jdate($obj->date_creation);
540 $this->
date = $this->db->jdate($obj->date_reception);
541 $this->date_reception = $this->db->jdate($obj->date_reception);
542 $this->date_delivery = $this->db->jdate($obj->date_delivery);
543 $this->date_valid = $this->db->jdate($obj->date_valid);
544 $this->model_pdf = $obj->model_pdf;
545 $this->shipping_method_id = $obj->fk_shipping_method;
546 $this->tracking_number = $obj->tracking_number;
547 $this->origin = ($obj->origin ? $obj->origin :
'commande');
548 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
549 $this->origin_id = $obj->origin_id;
551 $this->trueWeight = $obj->weight;
552 $this->weight_units = $obj->weight_units;
554 $this->trueWidth = $obj->width;
555 $this->width_units = $obj->size_units;
556 $this->trueHeight = $obj->height;
557 $this->height_units = $obj->size_units;
558 $this->trueDepth = $obj->size;
559 $this->depth_units = $obj->size_units;
561 $this->note_public = $obj->note_public;
562 $this->note_private = $obj->note_private;
565 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
566 $this->size_units = $obj->size_units;
569 $this->fk_incoterms = $obj->fk_incoterms;
570 $this->location_incoterms = $obj->location_incoterms;
571 $this->label_incoterms = $obj->label_incoterms;
573 $this->db->free($result);
589 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
591 $extrafields->fetch_name_optionals_label($this->table_element,
true);
597 if (empty($obj->origin_id)) {
608 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
609 $this->error =
'Reception with id '.$id.
' not found';
613 $this->error = $this->db->error();
625 public function valid($user, $notrigger = 0)
627 global $conf, $langs;
629 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
635 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
639 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
640 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
641 $this->error =
'Permission denied';
642 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
652 $soc->fetch($this->socid);
656 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
657 $numref = $this->getNextNumRef($soc);
659 $numref = (string) $this->
ref;
667 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
668 $sql .=
" ref='".$this->db->escape($numref).
"'";
669 $sql .=
", fk_statut = 1";
670 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
671 $sql .=
", fk_user_valid = ".((int) $user->id);
672 $sql .=
" WHERE rowid = ".((int) $this->
id);
673 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
674 $resql = $this->db->query($sql);
676 $this->error = $this->db->lasterror();
682 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
684 $langs->load(
"agenda");
688 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
689 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
690 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
691 $sql .=
" ed.fk_elementdet, ed.cost_price";
692 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
693 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
694 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
695 $sql .=
" AND cd.rowid = ed.fk_elementdet";
697 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
698 $resql = $this->db->query($sql);
700 $cpt = $this->db->num_rows($resql);
701 for ($i = 0; $i < $cpt; $i++) {
702 $obj = $this->db->fetch_object($resql);
706 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
710 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
714 $mouvS->origin = &$this;
715 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
717 if (empty($obj->batch)) {
722 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
724 if (intval($result) < 0) {
735 $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);
737 if (intval($result) < 0) {
745 $this->db->rollback();
746 $this->error = $this->db->error();
751 if (!$error && $this->origin_id > 0) {
759 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
762 $this->errors = array_merge($this->errors, $this->origin_object->errors);
765 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
773 if (!$error && !$notrigger) {
775 $result = $this->call_trigger(
'RECEPTION_VALIDATE', $user);
783 $this->oldref = $this->ref;
786 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
788 $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).
"'";
789 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
790 $resql = $this->db->query($sql);
793 $this->error = $this->db->lasterror();
795 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
796 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
797 $resql = $this->db->query($sql);
800 $this->error = $this->db->lasterror();
806 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
807 $dirdest = $conf->reception->dir_output.
'/'.$newref;
808 if (!$error && file_exists($dirsource)) {
809 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
811 if (@rename($dirsource, $dirdest)) {
814 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
815 foreach ($listoffiles as $fileentry) {
816 $dirsource = $fileentry[
'name'];
817 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
818 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
819 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
820 @rename($dirsource, $dirdest);
829 $this->
ref = $numref;
830 $this->statut = self::STATUS_VALIDATED;
831 $this->
status = self::STATUS_VALIDATED;
838 foreach ($this->errors as $errmsg) {
839 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
840 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
842 $this->db->rollback();
854 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
855 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
859 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
860 if (empty($this->origin_object)) {
862 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
863 $res = $this->origin_object->fetch_lines();
864 $this->commandeFournisseur =
null;
868 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
869 $res = $this->origin_object->fetch_lines();
877 $qty_received = array();
878 $qty_wished = array();
881 $filter = array(
't.fk_element' => $this->origin_id);
883 $filter[
't.status'] = 1;
886 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
892 foreach ($supplierorderdispatch->lines as $dispatch_line) {
893 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
894 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
896 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
901 foreach ($this->origin_object->lines as $origin_line) {
903 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
906 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
907 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
909 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
914 $diff_array = array_diff_assoc($qty_received, $qty_wished);
915 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
916 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
918 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
924 if (count($diff_array) > 0) {
927 foreach ($diff_array as $key => $value) {
929 if ($qty_received[$key] >= $qty_wished[$key]) {
935 if ($close == count($diff_array)) {
962 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
964 global $conf, $langs, $user;
966 $num = count($this->lines);
969 $line->fk_entrepot = $entrepot_id;
970 $line->fk_commandefourndet = $id;
974 $result = $supplierorderline->fetch($id);
981 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
982 $fk_product = $supplierorderline->fk_product;
984 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
985 $langs->load(
"errors");
986 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
992 $product =
new Product($this->db);
993 $product->fetch($fk_product);
995 $langs->load(
"errors");
996 if (!empty($product->status_batch) && empty($batch)) {
997 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
999 } elseif (empty($product->status_batch) && !empty($batch)) {
1000 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
1006 if (!empty($errorMsgArr)) {
1007 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
1008 $errorMessage .=
'<ul>';
1009 foreach ($errorMsgArr as $errorMsg) {
1010 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
1012 $errorMessage .=
'</ul>';
1013 $this->error = $errorMessage;
1020 $line->array_options = $supplierorderline->array_options;
1021 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1022 foreach ($array_options as $key => $value) {
1023 $line->array_options[$key] = $value;
1027 $line->fk_product = $fk_product;
1028 $line->fk_commande = $supplierorderline->fk_commande;
1029 $line->fk_user = $user->id;
1030 $line->comment = $comment;
1031 $line->batch = $batch;
1032 $line->eatby = $eatby;
1033 $line->sellby = $sellby;
1035 $line->cost_price = $cost_price;
1036 $line->fk_reception = $this->id;
1038 $this->lines[$num] = $line;
1055 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options = [])
1057 global
$mysoc, $langs, $user;
1059 if ($this->
status == self::STATUS_DRAFT) {
1069 $ranktouse = $this->rang;
1070 if ($ranktouse == -1) {
1071 $rangmax = $this->
line_max($this->fk_reception);
1072 $ranktouse = $rangmax + 1;
1077 $this->line->fk_reception = $this->id;
1078 $this->line->element_type = $element_type;
1079 $this->line->fk_product = $fk_product;
1080 $this->line->description = $description;
1082 $this->line->qty = (float) $qty;
1083 $this->line->fk_unit = $fk_unit;
1084 $this->line->rang = $ranktouse;
1086 if (is_array($array_options) && count($array_options) > 0) {
1087 $this->line->array_options = $array_options;
1090 $result = $this->line->insert($user);
1092 if (!isset($this->context[
'createfromclone'])) {
1093 if ($this->fk_reception) {
1095 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1096 $linecount = count($this->lines);
1097 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1101 $this->lines[] = $this->line;
1104 $this->db->commit();
1105 return $this->line->id;
1107 $this->error = $this->line->error;
1108 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1109 $this->db->rollback();
1113 dol_syslog(get_class($this).
"::addlinefree status of reception must be Draft to allow use of ->addlinefree()", LOG_ERR);
1132 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options = array())
1134 global
$mysoc, $langs, $user;
1136 if ($this->statut == self::STATUS_DRAFT) {
1146 $qty = (float) $qty;
1147 $description = trim($description);
1152 $line->fetch($rowid);
1153 $line->fetch_optionals();
1155 if (!empty($line->fk_product)) {
1156 $product =
new Product($this->db);
1157 $result = $product->fetch($line->fk_product);
1158 $product_type = $product->type;
1161 $staticline = clone $line;
1163 $line->oldline = $staticline;
1164 $this->line = $line;
1165 $this->line->context = $this->context;
1166 $this->line->rang = $rang;
1167 $this->line->fk_reception = $this->id;
1168 $this->line->element_type = $element_type;
1169 $this->line->fk_product = $line->fk_product;
1170 $this->line->qty = $qty;
1171 $this->line->fk_unit = $fk_unit;
1172 $this->line->description = $description;
1174 if (is_array($array_options) && count($array_options) > 0) {
1176 foreach ($array_options as $key => $value) {
1177 $this->line->array_options[$key] = $array_options[$key];
1182 $result = $this->line->update($user, $notrigger);
1187 $this->db->commit();
1190 $this->error = $this->line->error;
1192 $this->db->rollback();
1196 $this->error = get_class($this).
"::updatelinefree reception status makes operation forbidden";
1197 $this->errors = array(
'ReceptionStatusMakeOperationForbidden');
1213 $this->lines = array();
1215 $sql =
'SELECT rc.rowid, rc.fk_reception, rc.fk_entrepot, rc.fk_product, rc.fk_unit, rc.description, rc.fk_elementdet, rc.fk_element, rc.element_type, rc.qty, rc.rang';
1216 $sql .=
' FROM '.MAIN_DB_PREFIX.
'receptiondet_batch as rc';
1217 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = rc.fk_product)';
1218 $sql .=
' WHERE rc.fk_reception = '.((int) $this->
id);
1220 $sql .=
' ORDER BY rc.rang, rc.rowid';
1222 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
1223 $result = $this->db->query($sql);
1225 $num = $this->db->num_rows($result);
1229 $objp = $this->db->fetch_object($result);
1233 $line->rowid = $objp->rowid;
1234 $line->id = $objp->rowid;
1235 $line->fk_reception = $this->id;
1237 $line->description = $objp->description;
1238 $line->qty = $objp->qty;
1239 $line->fk_entrepot = $objp->fk_entrepot;
1240 $line->fk_product = $objp->fk_product;
1242 $line->rang = $objp->rang;
1245 $line->fk_element = $objp->fk_element;
1246 $line->fk_unit = $objp->fk_unit;
1247 $line->fk_elementdet = $objp->fk_elementdet;
1248 $line->fk_element_type = $objp->element_type;
1249 $line->fetch_optionals();
1253 $this->lines[$i] = $line;
1258 $this->db->free($result);
1262 $this->error = $this->db->error();
1284 public function update($user =
null, $notrigger = 0)
1291 if (isset($this->
ref)) {
1292 $this->
ref = trim($this->
ref);
1294 if (isset($this->entity)) {
1295 $this->entity = (int) $this->entity;
1297 if (isset($this->ref_supplier)) {
1298 $this->ref_supplier = trim($this->ref_supplier);
1300 if (isset($this->socid)) {
1301 $this->socid = (int) trim((
string) $this->socid);
1303 if (isset($this->fk_user_author)) {
1304 $this->fk_user_author = (int) $this->fk_user_author;
1306 if (isset($this->fk_user_valid)) {
1307 $this->fk_user_valid = (int) $this->fk_user_valid;
1309 if (isset($this->shipping_method_id)) {
1310 $this->shipping_method_id = (int) $this->shipping_method_id;
1312 if (isset($this->tracking_number)) {
1313 $this->tracking_number = trim($this->tracking_number);
1315 if (isset($this->statut)) {
1316 $this->statut = (int) $this->statut;
1318 if (isset($this->trueDepth)) {
1319 $this->trueDepth =
price2num($this->trueDepth);
1321 if (isset($this->trueWidth)) {
1322 $this->trueWidth =
price2num($this->trueWidth);
1324 if (isset($this->trueHeight)) {
1325 $this->trueHeight =
price2num($this->trueHeight);
1327 $this->size_units = (int) $this->size_units;
1329 if (isset($this->trueWeight)) {
1330 $this->weight =
price2num($this->trueWeight);
1332 $this->weight_units = (int) $this->weight_units;
1334 if (isset($this->note_private)) {
1335 $this->note_private = trim($this->note_private);
1337 if (isset($this->note_public)) {
1338 $this->note_public = trim($this->note_public);
1340 if (isset($this->model_pdf)) {
1341 $this->model_pdf = trim($this->model_pdf);
1349 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1351 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1352 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1353 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1354 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1355 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1356 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1357 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1358 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1359 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1360 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1361 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1362 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1363 $sql .=
" height=".(($this->trueHeight !=
'') ? (
float) $this->trueHeight :
"null").
",";
1364 $sql .=
" width=".(($this->trueWidth !=
'') ? (
float) $this->trueWidth :
"null").
",";
1365 $sql .=
" size_units=".((int) $this->size_units).
",";
1366 $sql .=
" size=".(($this->trueDepth !=
'') ? (
float) $this->trueDepth :
"null").
",";
1367 $sql .=
" weight_units=".((int) $this->weight_units).
",";
1368 $sql .=
" weight=".(($this->trueWeight !=
'') ? (
float) $this->trueWeight :
"null").
",";
1369 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1370 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1371 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1372 $sql .=
" fk_projet=".((isset($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1373 $sql .=
" entity = ".((int) $conf->entity);
1374 $sql .=
" WHERE rowid=".((int) $this->
id);
1378 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1379 $resql = $this->db->query($sql);
1382 $this->errors[] =
"Error ".$this->db->lasterror();
1388 $result = $this->call_trigger(
'RECEPTION_MODIFY', $user);
1398 foreach ($this->errors as $errmsg) {
1399 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1400 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1402 $this->db->rollback();
1405 $this->db->commit();
1416 public function delete(
User $user)
1418 global $conf, $langs, $user;
1419 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1429 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1431 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1433 $langs->load(
"agenda");
1436 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1438 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1439 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1440 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1442 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1443 $resql = $this->db->query($sql);
1445 $cpt = $this->db->num_rows($resql);
1446 for ($i = 0; $i < $cpt; $i++) {
1447 dol_syslog(get_class($this).
"::delete movement index ".$i);
1448 $obj = $this->db->fetch_object($resql);
1452 $mouvS->origin =
null;
1454 $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);
1457 $this->error = $mouvS->error;
1458 $this->errors = $mouvS->errors;
1463 $this->errors[] =
"Error ".$this->db->lasterror();
1468 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1469 $ef = $main.
"_extrafields";
1471 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1473 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1474 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1476 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1484 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1485 $sql .=
" WHERE rowid = ".((int) $this->
id);
1487 if ($this->db->query($sql)) {
1489 $result = $this->call_trigger(
'RECEPTION_DELETE', $user);
1495 if (!empty($this->origin) && $this->origin_id > 0) {
1498 '@phan-var-force CommandeFournisseur $origin_object';
1511 $this->db->commit();
1515 if (!empty($conf->reception->dir_output)) {
1516 $dir = $conf->reception->dir_output.
'/'.$ref;
1517 $file = $dir.
'/'.$ref.
'.pdf';
1518 if (file_exists($file)) {
1523 if (file_exists($dir)) {
1525 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1533 $this->db->rollback();
1537 $this->error = $this->db->lasterror().
" - sql=$sql";
1538 $this->db->rollback();
1542 $this->error = $this->db->lasterror().
" - sql=$sql";
1543 $this->db->rollback();
1547 $this->error = $this->db->lasterror().
" - sql=$sql";
1548 $this->db->rollback();
1552 $this->db->rollback();
1566 $this->lines = array();
1568 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1570 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1571 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1573 $resql = $this->db->query($sql);
1575 if (!empty($resql)) {
1576 while ($obj = $this->db->fetch_object($resql)) {
1579 $line->fetch($obj->rowid);
1582 $line->fetch_product();
1584 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1585 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1586 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1587 $sql_commfourndet .=
' ORDER BY rang';
1589 $resql_commfourndet = $this->db->query($sql_commfourndet);
1590 if (!empty($resql_commfourndet)) {
1591 $obj = $this->db->fetch_object($resql_commfourndet);
1592 $line->qty_asked = $obj->qty;
1593 $line->description = $obj->description;
1594 $line->desc = $obj->description;
1595 $line->tva_tx = $obj->tva_tx;
1596 $line->vat_src_code = $obj->vat_src_code;
1597 $line->subprice = $obj->subprice;
1598 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1599 $line->remise_percent = $obj->remise_percent;
1600 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1601 $line->ref_supplier = $obj->ref;
1602 $line->total_ht = $obj->total_ht;
1603 $line->total_ttc = $obj->total_ttc;
1604 $line->total_tva = $obj->total_tva;
1606 $line->qty_asked = 0;
1607 $line->description =
'';
1609 $line->label = $obj->label;
1612 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1613 $tva = $pu_ht * $line->tva_tx / 100;
1614 $this->total_ht += $pu_ht;
1615 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1617 $this->total_ttc += $pu_ht + $tva;
1619 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1621 $detail_batch->eatby = $line->eatby;
1622 $detail_batch->sellby = $line->sellby;
1623 $detail_batch->batch = $line->batch;
1624 $detail_batch->qty = $line->qty;
1626 $line->detail_batch[] = $detail_batch;
1629 $this->lines[] = $line;
1648 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0)
1650 global $langs, $hookmanager;
1653 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1654 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1655 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1657 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1664 if (empty($notooltip)) {
1666 $label = $langs->trans(
"Reception");
1667 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1669 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1670 $linkclose .=
' class="classfortooltip"';
1673 $linkstart =
'<a href="'.$url.
'"';
1674 $linkstart .= $linkclose.
'>';
1677 $result .= $linkstart;
1679 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1681 if ($withpicto != 2) {
1682 $result .= $this->ref;
1685 $result .= $linkend;
1688 $hookmanager->initHooks(array($this->element .
'dao'));
1689 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1690 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1692 $result = $hookmanager->resPrint;
1694 $result .= $hookmanager->resPrint;
1707 return $this->
LibStatut($this->statut, $mode);
1724 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1725 $this->labelStatus[0] =
'StatusReceptionDraft';
1727 $this->labelStatus[1] =
'StatusReceptionValidated';
1729 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1732 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1734 $this->labelStatus[2] =
'StatusReceptionProcessed';
1737 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1738 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1739 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1740 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1742 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1743 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1745 $statusType =
'status'.$status;
1746 if ($status == self::STATUS_VALIDATED) {
1747 $statusType =
'status4';
1749 if ($status == self::STATUS_CLOSED) {
1750 $statusType =
'status6';
1753 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1765 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1767 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1768 $return .=
'<div class="info-box info-box-sm">';
1769 $return .=
'<div class="info-box-icon bg-infobox-action">';
1771 $return .=
'</div>';
1772 $return .=
'<div class="info-box-content">';
1773 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1774 if ($selected >= 0) {
1775 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1777 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1778 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1783 if (method_exists($this,
'getLibStatut')) {
1784 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1786 $return .=
'</div>';
1787 $return .=
'</div>';
1788 $return .=
'</div>';
1804 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1805 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1808 dol_syslog(get_class($this).
"::initAsSpecimen");
1811 $order->initAsSpecimen();
1815 $this->
ref =
'SPECIMEN';
1816 $this->specimen = 1;
1820 $this->date_creation = $now;
1821 $this->date_valid = $now;
1822 $this->date_delivery = $now;
1823 $this->date_reception = $now + 24 * 3600;
1824 $this->entrepot_id = 0;
1826 $this->origin_id = 1;
1827 $this->origin_type =
'supplier_order';
1828 $this->origin_object = $order;
1829 $this->note_private =
'Private note';
1830 $this->note_public =
'Public note';
1831 $this->tracking_number =
'TRACKID-ABC123';
1832 $this->fk_incoterms = 1;
1835 while ($xnbp < $nbp) {
1837 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1838 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1839 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1842 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1844 $this->lines[] = $line;
1861 if ($user->hasRight(
'reception',
'creer')) {
1862 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1863 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1864 $sql .=
" WHERE rowid = ".((int) $this->
id);
1866 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1867 $resql = $this->db->query($sql);
1869 $this->date_delivery = $delivery_date;
1872 $this->error = $this->db->error();
1889 if ($user->hasRight(
'reception',
'creer')) {
1890 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1891 $sql .=
" SET date_reception = ".($reception_date ?
"'".$this->db->idate($reception_date).
"'" :
'null');
1892 $sql .=
" WHERE rowid = ".((int) $this->
id);
1894 dol_syslog(get_class($this).
"::setReceptionDate", LOG_DEBUG);
1895 $resql = $this->db->query($sql);
1897 $this->date_reception = $reception_date;
1900 $this->error = $this->db->error();
1918 $this->meths = array();
1920 $sql =
"SELECT em.rowid, em.code, em.libelle";
1921 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1922 $sql .=
" WHERE em.active = 1";
1923 $sql .=
" ORDER BY em.libelle ASC";
1925 $resql = $this->db->query($sql);
1927 while ($obj = $this->db->fetch_object($resql)) {
1928 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1929 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1946 $this->listmeths = array();
1949 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1950 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1952 $sql .=
" WHERE em.rowid = ".((int) $id);
1955 $resql = $this->db->query($sql);
1957 while ($obj = $this->db->fetch_object($resql)) {
1958 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1959 $this->listmeths[$i][
'code'] = $obj->code;
1960 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1961 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1962 $this->listmeths[$i][
'description'] = $obj->description;
1963 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1964 $this->listmeths[$i][
'active'] = $obj->active;
1978 if (!empty($this->shipping_method_id)) {
1979 $sql =
"SELECT em.code, em.tracking";
1980 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1981 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1983 $resql = $this->db->query($sql);
1985 if ($obj = $this->db->fetch_object($resql)) {
1986 $tracking = $obj->tracking;
1991 if (!empty($tracking) && !empty($value)) {
1992 $url = str_replace(
'{TRACKID}', $value, $tracking);
1993 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1995 $this->tracking_url = $value;
2006 global $conf, $langs, $user;
2011 if ($this->statut == Reception::STATUS_CLOSED) {
2012 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
2018 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
2019 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2021 $resql = $this->db->query($sql);
2024 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
2025 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2028 $order->fetch($this->origin_id);
2030 $order->loadReceptions(self::STATUS_CLOSED);
2032 $receptions_match_order = 1;
2033 foreach ($order->lines as $line) {
2034 $lineid = $line->id;
2036 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
2037 $receptions_match_order = 0;
2038 $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';
2043 if ($receptions_match_order) {
2044 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');
2045 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
2049 $this->statut = self::STATUS_CLOSED;
2050 $this->
status = self::STATUS_CLOSED;
2054 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2056 $langs->load(
"agenda");
2060 $sql =
"SELECT cd.fk_product, cd.subprice,";
2061 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2062 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2063 $sql .=
" ed.fk_elementdet, ed.cost_price";
2064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2065 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2066 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2067 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2069 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2070 $resql = $this->db->query($sql);
2073 $cpt = $this->db->num_rows($resql);
2074 for ($i = 0; $i < $cpt; $i++) {
2075 $obj = $this->db->fetch_object($resql);
2083 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
2086 $mouvS->origin = &$this;
2087 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2089 if (empty($obj->batch)) {
2093 $inventorycode =
'';
2094 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2096 $this->error = $mouvS->error;
2097 $this->errors = $mouvS->errors;
2105 $inventorycode =
'';
2106 $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);
2109 $this->error = $mouvS->error;
2110 $this->errors = $mouvS->errors;
2117 $this->error = $this->db->lasterror();
2124 $result = $this->call_trigger(
'RECEPTION_CLOSED', $user);
2135 $this->db->commit();
2138 $this->statut = self::STATUS_VALIDATED;
2139 $this->
status = self::STATUS_VALIDATED;
2140 $this->db->rollback();
2157 if ($this->statut == Reception::STATUS_VALIDATED) {
2162 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
2163 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2165 $resql = $this->db->query($sql);
2170 $result = $this->call_trigger(
'RECEPTION_BILLED', $user);
2177 $this->errors[] = $this->db->lasterror;
2180 if (empty($error)) {
2181 $this->db->commit();
2184 $this->db->rollback();
2196 global $langs, $user;
2202 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
2203 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2205 $resql = $this->db->query($sql);
2206 $rollbackStatus = $this->status;
2207 $rollbackBilled = $this->billed;
2209 $this->statut = self::STATUS_VALIDATED;
2210 $this->
status = self::STATUS_VALIDATED;
2215 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2216 $numref = (string) $this->
ref;
2217 $langs->load(
"agenda");
2221 $sql =
"SELECT ed.fk_product, cd.subprice,";
2222 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2223 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2224 $sql .=
" ed.fk_elementdet, ed.cost_price";
2225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2226 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2227 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2228 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2230 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2231 $resql = $this->db->query($sql);
2233 $cpt = $this->db->num_rows($resql);
2234 for ($i = 0; $i < $cpt; $i++) {
2235 $obj = $this->db->fetch_object($resql);
2242 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2246 $mouvS->origin = &$this;
2247 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2249 if (empty($obj->batch)) {
2253 $inventorycode =
'';
2254 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
2257 $this->error = $mouvS->error;
2258 $this->errors = $mouvS->errors;
2266 $inventorycode =
'';
2267 $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);
2269 $this->error = $mouvS->error;
2270 $this->errors = $mouvS->errors;
2277 $this->error = $this->db->lasterror();
2284 $result = $this->call_trigger(
'RECEPTION_REOPEN', $user);
2290 if (!$error && $this->origin ==
'order_supplier') {
2291 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2294 $commande->fetch($this->origin_id);
2295 $result = $commande->setStatus($user, 4);
2298 $this->error = $commande->error;
2299 $this->errors = $commande->errors;
2304 $this->errors[] = $this->db->lasterror();
2308 $this->db->commit();
2311 $this->statut = $this->
status = $rollbackStatus;
2312 $this->billed = $rollbackBilled;
2313 $this->db->rollback();
2327 global $conf, $langs;
2332 if ($this->statut <= self::STATUS_DRAFT) {
2336 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2337 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2338 $this->error =
'Permission denied';
2344 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2345 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2346 $sql .=
" WHERE rowid = ".((int) $this->
id);
2349 if ($this->db->query($sql)) {
2352 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2354 $langs->load(
"agenda");
2358 $sql =
"SELECT cd.fk_product, cd.subprice,";
2359 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2360 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2361 $sql .=
" ed.fk_elementdet, ed.cost_price";
2362 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2363 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2364 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2365 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2367 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2368 $resql = $this->db->query($sql);
2370 $cpt = $this->db->num_rows($resql);
2371 for ($i = 0; $i < $cpt; $i++) {
2372 $obj = $this->db->fetch_object($resql);
2380 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2384 $mouvS->origin = &$this;
2385 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2387 if (empty($obj->batch)) {
2391 $inventorycode =
'';
2392 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2394 $this->error = $mouvS->error;
2395 $this->errors = $mouvS->errors;
2403 $inventorycode =
'';
2404 $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);
2406 $this->error = $mouvS->error;
2407 $this->errors = $mouvS->errors;
2414 $this->error = $this->db->lasterror();
2421 $result = $this->call_trigger(
'RECEPTION_UNVALIDATE', $user);
2426 if ($this->origin ==
'order_supplier') {
2427 if (!empty($this->origin) && $this->origin_id > 0) {
2429 if ($this->origin_object->statut == 4) {
2431 $this->origin_object->fetchObjectLinked();
2433 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2434 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2435 if ($rcption->statut > 0) {
2442 $this->origin_object->setStatut(3);
2450 $this->statut = self::STATUS_DRAFT;
2451 $this->
status = self::STATUS_DRAFT;
2452 $this->db->commit();
2455 $this->db->rollback();
2459 $this->error = $this->db->error();
2460 $this->db->rollback();
2475 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2477 global $conf, $langs;
2479 $langs->load(
"receptions");
2482 $modele =
'squille';
2484 if ($this->model_pdf) {
2485 $modele = $this->model_pdf;
2491 $modelpath =
"core/modules/reception/doc/";
2495 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2508 $tables = array(
'reception');
2524 'receptiondet_batch'
Class to manage table ReceptionLineBatch.
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
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=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
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.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
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.
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options=array())
Update a simple reception line.
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.
getLinesArray()
Create an array of reception lines.
fetch_lines_free()
Load lines of simple reception.
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this records also the stock movement)
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.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0)
Return clickable link of object (with eventually picto)
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a reception line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
__construct($db)
Constructor.
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options=[])
Add a simple reception line.
initAsSpecimen()
Initialise an instance with random values.
setReceptionDate($user, $reception_date)
Set the reception date.
create($user, $notrigger=0)
Create reception.
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.
addline($entrepot_id, $id, $qty, $array_options=[], $comment='', $eatby=null, $sellby=null, $batch='', $cost_price=0)
Add an reception line.
setDraft($user)
Set draft status.
Class to manage table commandefournisseurdispatch.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_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_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
$conf db user
Active Directory does not allow anonymous connections.