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 $draft_lines = array();
893 $sql =
"SELECT rb.rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as rb";
894 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"reception as r ON r.rowid = rb.fk_reception";
895 $sql .=
" WHERE rb.fk_element = ".((int) $this->origin_id);
896 $sql .=
" AND r.fk_statut = ".self::STATUS_DRAFT;
897 $resql = $this->db->query($sql);
899 $this->error = $this->db->lasterror();
902 while ($obj = $this->db->fetch_object($resql)) {
903 $draft_lines[(int) $obj->rowid] = (
int) $obj->rowid;
905 $this->db->free($resql);
908 foreach ($supplierorderdispatch->lines as $dispatch_line) {
909 if (isset($draft_lines[(
int) $dispatch_line->id])) {
912 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
913 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
915 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
920 foreach ($this->origin_object->lines as $origin_line) {
922 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
925 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
926 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
928 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
933 $diff_array = array_diff_assoc($qty_received, $qty_wished);
934 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
935 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
937 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
943 if (count($diff_array) > 0) {
946 foreach ($diff_array as $key => $value) {
948 if ($qty_received[$key] >= $qty_wished[$key]) {
954 if ($close == count($diff_array)) {
981 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
983 global $conf, $langs, $user;
985 $num = count($this->lines);
988 $line->fk_entrepot = $entrepot_id;
989 $line->fk_commandefourndet = $id;
993 $result = $supplierorderline->fetch($id);
1000 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
1001 $fk_product = $supplierorderline->fk_product;
1003 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
1004 $langs->load(
"errors");
1005 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
1011 $product =
new Product($this->db);
1012 $product->fetch($fk_product);
1014 $langs->load(
"errors");
1015 if (!empty($product->status_batch) && empty($batch)) {
1016 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
1018 } elseif (empty($product->status_batch) && !empty($batch)) {
1019 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
1025 if (!empty($errorMsgArr)) {
1026 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
1027 $errorMessage .=
'<ul>';
1028 foreach ($errorMsgArr as $errorMsg) {
1029 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
1031 $errorMessage .=
'</ul>';
1032 $this->error = $errorMessage;
1039 $line->array_options = $supplierorderline->array_options;
1040 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1041 foreach ($array_options as $key => $value) {
1042 $line->array_options[$key] = $value;
1046 $line->fk_product = $fk_product;
1047 $line->fk_commande = $supplierorderline->fk_commande;
1048 $line->fk_user = $user->id;
1049 $line->comment = $comment;
1050 $line->batch = $batch;
1051 $line->eatby = $eatby;
1052 $line->sellby = $sellby;
1054 $line->cost_price = $cost_price;
1055 $line->fk_reception = $this->id;
1057 $this->lines[$num] = $line;
1074 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options = [])
1076 global
$mysoc, $langs, $user;
1078 if ($this->
status == self::STATUS_DRAFT) {
1088 $ranktouse = $this->rang;
1089 if ($ranktouse == -1) {
1090 $rangmax = $this->
line_max($this->fk_reception);
1091 $ranktouse = $rangmax + 1;
1096 $this->line->fk_reception = $this->id;
1097 $this->line->element_type = $element_type;
1098 $this->line->fk_product = $fk_product;
1099 $this->line->description = $description;
1101 $this->line->qty = (float) $qty;
1102 $this->line->fk_unit = $fk_unit;
1103 $this->line->rang = $ranktouse;
1105 if (is_array($array_options) && count($array_options) > 0) {
1106 $this->line->array_options = $array_options;
1109 $result = $this->line->insert($user);
1111 if (!isset($this->context[
'createfromclone'])) {
1112 if ($this->fk_reception) {
1114 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1115 $linecount = count($this->lines);
1116 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1120 $this->lines[] = $this->line;
1123 $this->db->commit();
1124 return $this->line->id;
1126 $this->error = $this->line->error;
1127 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1128 $this->db->rollback();
1132 dol_syslog(get_class($this).
"::addlinefree status of reception must be Draft to allow use of ->addlinefree()", LOG_ERR);
1151 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options = array())
1153 global
$mysoc, $langs, $user;
1155 if ($this->statut == self::STATUS_DRAFT) {
1165 $qty = (float) $qty;
1166 $description = trim((
string) $description);
1171 $line->fetch($rowid);
1172 $line->fetch_optionals();
1174 if (!empty($line->fk_product)) {
1175 $product =
new Product($this->db);
1176 $result = $product->fetch($line->fk_product);
1177 $product_type = $product->type;
1180 $staticline = clone $line;
1182 $line->oldline = $staticline;
1183 $this->line = $line;
1184 $this->line->context = $this->context;
1185 $this->line->rang = $rang;
1186 $this->line->fk_reception = $this->id;
1187 $this->line->element_type = $element_type;
1188 $this->line->fk_product = $line->fk_product;
1189 $this->line->qty = $qty;
1190 $this->line->fk_unit = $fk_unit;
1191 $this->line->description = $description;
1193 if (is_array($array_options) && count($array_options) > 0) {
1195 foreach ($array_options as $key => $value) {
1196 $this->line->array_options[$key] = $array_options[$key];
1201 $result = $this->line->update($user, $notrigger);
1206 $this->db->commit();
1209 $this->error = $this->line->error;
1211 $this->db->rollback();
1215 $this->error = get_class($this).
"::updatelinefree reception status makes operation forbidden";
1216 $this->errors = array(
'ReceptionStatusMakeOperationForbidden');
1232 $this->lines = array();
1234 $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';
1235 $sql .=
' FROM '.MAIN_DB_PREFIX.
'receptiondet_batch as rc';
1236 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = rc.fk_product)';
1237 $sql .=
' WHERE rc.fk_reception = '.((int) $this->
id);
1239 $sql .=
' ORDER BY rc.rang, rc.rowid';
1241 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
1242 $result = $this->db->query($sql);
1244 $num = $this->db->num_rows($result);
1248 $objp = $this->db->fetch_object($result);
1252 $line->rowid = $objp->rowid;
1253 $line->id = $objp->rowid;
1254 $line->fk_reception = $this->id;
1256 $line->description = $objp->description;
1257 $line->qty = $objp->qty;
1258 $line->fk_entrepot = $objp->fk_entrepot;
1259 $line->fk_product = $objp->fk_product;
1261 $line->rang = $objp->rang;
1264 $line->fk_element = $objp->fk_element;
1265 $line->fk_unit = $objp->fk_unit;
1266 $line->fk_elementdet = $objp->fk_elementdet;
1267 $line->fk_element_type = $objp->element_type;
1268 $line->fetch_optionals();
1272 $this->lines[$i] = $line;
1277 $this->db->free($result);
1281 $this->error = $this->db->error();
1303 public function update($user =
null, $notrigger = 0)
1310 if (isset($this->
ref)) {
1311 $this->
ref = trim($this->
ref);
1313 if (isset($this->entity)) {
1314 $this->entity = (int) $this->entity;
1316 if (isset($this->ref_supplier)) {
1317 $this->ref_supplier = trim($this->ref_supplier);
1319 if (isset($this->socid)) {
1320 $this->socid = (int) trim((
string) $this->socid);
1322 if (isset($this->fk_user_author)) {
1323 $this->fk_user_author = (int) $this->fk_user_author;
1325 if (isset($this->fk_user_valid)) {
1326 $this->fk_user_valid = (int) $this->fk_user_valid;
1328 if (isset($this->shipping_method_id)) {
1329 $this->shipping_method_id = (int) $this->shipping_method_id;
1331 if (isset($this->tracking_number)) {
1332 $this->tracking_number = trim($this->tracking_number);
1334 if (isset($this->statut)) {
1335 $this->statut = (int) $this->statut;
1337 if (isset($this->trueDepth)) {
1338 $this->trueDepth =
price2num($this->trueDepth);
1340 if (isset($this->trueWidth)) {
1341 $this->trueWidth =
price2num($this->trueWidth);
1343 if (isset($this->trueHeight)) {
1344 $this->trueHeight =
price2num($this->trueHeight);
1346 $this->size_units = (int) $this->size_units;
1348 if (isset($this->trueWeight)) {
1349 $this->weight =
price2num($this->trueWeight);
1351 $this->weight_units = (int) $this->weight_units;
1353 if (isset($this->note_private)) {
1354 $this->note_private = trim($this->note_private);
1356 if (isset($this->note_public)) {
1357 $this->note_public = trim($this->note_public);
1359 if (isset($this->model_pdf)) {
1360 $this->model_pdf = trim($this->model_pdf);
1368 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1370 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1371 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1372 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1373 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1374 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1375 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1376 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1377 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1378 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1379 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1380 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1381 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1382 $sql .=
" height=".(($this->trueHeight !=
'') ? (
float) $this->trueHeight :
"null").
",";
1383 $sql .=
" width=".(($this->trueWidth !=
'') ? (
float) $this->trueWidth :
"null").
",";
1384 $sql .=
" size_units=".((int) $this->size_units).
",";
1385 $sql .=
" size=".(($this->trueDepth !=
'') ? (
float) $this->trueDepth :
"null").
",";
1386 $sql .=
" weight_units=".((int) $this->weight_units).
",";
1387 $sql .=
" weight=".(($this->trueWeight !=
'') ? (
float) $this->trueWeight :
"null").
",";
1388 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1389 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1390 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1391 $sql .=
" fk_projet=".((isset($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1392 $sql .=
" entity = ".((int) $conf->entity);
1393 $sql .=
" WHERE rowid=".((int) $this->
id);
1397 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1398 $resql = $this->db->query($sql);
1401 $this->errors[] =
"Error ".$this->db->lasterror();
1407 $result = $this->call_trigger(
'RECEPTION_MODIFY', $user);
1417 foreach ($this->errors as $errmsg) {
1418 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1419 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1421 $this->db->rollback();
1424 $this->db->commit();
1435 public function delete(
User $user)
1437 global $conf, $langs, $user;
1438 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1448 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1450 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1452 $langs->load(
"agenda");
1455 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1456 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1457 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1458 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1459 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1461 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1462 $resql = $this->db->query($sql);
1464 $cpt = $this->db->num_rows($resql);
1465 for ($i = 0; $i < $cpt; $i++) {
1466 dol_syslog(get_class($this).
"::delete movement index ".$i);
1467 $obj = $this->db->fetch_object($resql);
1471 $mouvS->origin =
null;
1473 $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);
1476 $this->error = $mouvS->error;
1477 $this->errors = $mouvS->errors;
1482 $this->errors[] =
"Error ".$this->db->lasterror();
1487 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1488 $ef = $main.
"_extrafields";
1490 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1492 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1493 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1495 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1503 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1504 $sql .=
" WHERE rowid = ".((int) $this->
id);
1506 if ($this->db->query($sql)) {
1508 $result = $this->call_trigger(
'RECEPTION_DELETE', $user);
1514 if (!empty($this->origin) && $this->origin_id > 0) {
1517 '@phan-var-force CommandeFournisseur $origin_object';
1530 $this->db->commit();
1534 if (!empty($conf->reception->dir_output)) {
1535 $dir = $conf->reception->dir_output.
'/'.$ref;
1536 $file = $dir.
'/'.$ref.
'.pdf';
1537 if (file_exists($file)) {
1542 if (file_exists($dir)) {
1544 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1552 $this->db->rollback();
1556 $this->error = $this->db->lasterror().
" - sql=$sql";
1557 $this->db->rollback();
1561 $this->error = $this->db->lasterror().
" - sql=$sql";
1562 $this->db->rollback();
1566 $this->error = $this->db->lasterror().
" - sql=$sql";
1567 $this->db->rollback();
1571 $this->db->rollback();
1585 if ($this->
status != self::STATUS_DRAFT) {
1586 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1591 if ($line->fetch($lineid) <= 0) {
1592 $this->error =
'ErrorRecordNotFound';
1595 if ($line->fk_reception != $this->id) {
1596 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1601 if ($line->delete($user) > 0) {
1602 $this->db->commit();
1605 $this->error = $line->error;
1606 $this->db->rollback();
1619 $this->lines = array();
1621 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1623 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1624 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1626 $resql = $this->db->query($sql);
1628 if (!empty($resql)) {
1629 while ($obj = $this->db->fetch_object($resql)) {
1632 $line->fetch($obj->rowid);
1635 $line->fetch_product();
1637 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, localtax1_tx, localtax2_tx, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva, date_start, date_end, product_type';
1638 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1639 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1640 $sql_commfourndet .=
' ORDER BY rang';
1642 $resql_commfourndet = $this->db->query($sql_commfourndet);
1643 if (!empty($resql_commfourndet)) {
1644 $obj = $this->db->fetch_object($resql_commfourndet);
1645 $line->qty_asked = $obj->qty;
1646 $line->description = $obj->description;
1647 $line->desc = $obj->description;
1648 $line->tva_tx = $obj->tva_tx;
1649 $line->vat_src_code = $obj->vat_src_code;
1650 $line->localtax1_tx = $obj->localtax1_tx;
1651 $line->localtax2_tx = $obj->localtax2_tx;
1652 $line->subprice = $obj->subprice;
1653 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1654 $line->remise_percent = $obj->remise_percent;
1655 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1656 $line->ref_supplier = $obj->ref;
1657 $line->total_ht = $obj->total_ht;
1658 $line->total_ttc = $obj->total_ttc;
1659 $line->total_tva = $obj->total_tva;
1660 $line->date_start = $this->db->jdate($obj->date_start);
1661 $line->date_end = $this->db->jdate($obj->date_end);
1662 $line->product_type = $obj->product_type;
1664 $line->qty_asked = 0;
1665 $line->description =
'';
1667 $line->label = $obj->label;
1670 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1671 $tva = $pu_ht * $line->tva_tx / 100;
1672 $this->total_ht += $pu_ht;
1673 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1675 $this->total_ttc += $pu_ht + $tva;
1677 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1679 $detail_batch->eatby = $line->eatby;
1680 $detail_batch->sellby = $line->sellby;
1681 $detail_batch->batch = $line->batch;
1682 $detail_batch->qty = $line->qty;
1684 $line->detail_batch[] = $detail_batch;
1687 $this->lines[] = $line;
1706 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0)
1708 global $langs, $hookmanager;
1711 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1712 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1713 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1715 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1722 if (empty($notooltip)) {
1724 $label = $langs->trans(
"Reception");
1725 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1727 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1728 $linkclose .=
' class="classfortooltip"';
1731 $linkstart =
'<a href="'.$url.
'"';
1732 $linkstart .= $linkclose.
'>';
1735 $result .= $linkstart;
1737 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1739 if ($withpicto != 2) {
1740 $result .= $this->ref;
1743 $result .= $linkend;
1746 $hookmanager->initHooks(array($this->element .
'dao'));
1747 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1748 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1750 $result = $hookmanager->resPrint;
1752 $result .= $hookmanager->resPrint;
1765 return $this->
LibStatut($this->statut, $mode);
1782 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1783 $this->labelStatus[0] =
'StatusReceptionDraft';
1785 $this->labelStatus[1] =
'StatusReceptionValidated';
1787 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1790 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1792 $this->labelStatus[2] =
'StatusReceptionProcessed';
1795 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1796 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1797 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1798 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1800 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1801 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1803 $statusType =
'status'.$status;
1804 if ($status == self::STATUS_VALIDATED) {
1805 $statusType =
'status4';
1807 if ($status == self::STATUS_CLOSED) {
1808 $statusType =
'status6';
1811 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1823 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1825 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1826 $return .=
'<div class="info-box info-box-sm">';
1827 $return .=
'<div class="info-box-icon bg-infobox-action">';
1829 $return .=
'</div>';
1830 $return .=
'<div class="info-box-content">';
1831 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1832 if ($selected >= 0) {
1833 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1835 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1836 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1841 if (method_exists($this,
'getLibStatut')) {
1842 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1844 $return .=
'</div>';
1845 $return .=
'</div>';
1846 $return .=
'</div>';
1862 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1863 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1866 dol_syslog(get_class($this).
"::initAsSpecimen");
1869 $order->initAsSpecimen();
1873 $this->
ref =
'SPECIMEN';
1874 $this->specimen = 1;
1878 $this->date_creation = $now;
1879 $this->date_valid = $now;
1880 $this->date_delivery = $now;
1881 $this->date_reception = $now + 24 * 3600;
1882 $this->entrepot_id = 0;
1884 $this->origin_id = 1;
1885 $this->origin_type =
'supplier_order';
1886 $this->origin_object = $order;
1887 $this->note_private =
'Private note';
1888 $this->note_public =
'Public note';
1889 $this->tracking_number =
'TRACKID-ABC123';
1890 $this->fk_incoterms = 1;
1893 while ($xnbp < $nbp) {
1895 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1896 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1897 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1900 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1902 $this->lines[] = $line;
1919 if ($user->hasRight(
'reception',
'creer')) {
1920 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1921 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1922 $sql .=
" WHERE rowid = ".((int) $this->
id);
1924 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1925 $resql = $this->db->query($sql);
1927 $this->date_delivery = $delivery_date;
1930 $this->error = $this->db->error();
1947 if ($user->hasRight(
'reception',
'creer')) {
1948 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1949 $sql .=
" SET date_reception = ".($reception_date ?
"'".$this->db->idate($reception_date).
"'" :
'null');
1950 $sql .=
" WHERE rowid = ".((int) $this->
id);
1952 dol_syslog(get_class($this).
"::setReceptionDate", LOG_DEBUG);
1953 $resql = $this->db->query($sql);
1955 $this->date_reception = $reception_date;
1958 $this->error = $this->db->error();
1976 $this->meths = array();
1978 $sql =
"SELECT em.rowid, em.code, em.libelle";
1979 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1980 $sql .=
" WHERE em.active = 1";
1981 $sql .=
" ORDER BY em.libelle ASC";
1983 $resql = $this->db->query($sql);
1985 while ($obj = $this->db->fetch_object($resql)) {
1986 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1987 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
2004 $this->listmeths = array();
2007 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
2008 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2010 $sql .=
" WHERE em.rowid = ".((int) $id);
2013 $resql = $this->db->query($sql);
2015 while ($obj = $this->db->fetch_object($resql)) {
2016 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2017 $this->listmeths[$i][
'code'] = $obj->code;
2018 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
2019 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
2020 $this->listmeths[$i][
'description'] = $obj->description;
2021 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2022 $this->listmeths[$i][
'active'] = $obj->active;
2036 if (!empty($this->shipping_method_id)) {
2037 $sql =
"SELECT em.code, em.tracking";
2038 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2039 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2041 $resql = $this->db->query($sql);
2043 if ($obj = $this->db->fetch_object($resql)) {
2044 $tracking = $obj->tracking;
2049 if (!empty($tracking) && !empty($value)) {
2050 $url = str_replace(
'{TRACKID}', $value, $tracking);
2051 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
2053 $this->tracking_url = $value;
2064 global $conf, $langs, $user;
2069 if ($this->statut == Reception::STATUS_CLOSED) {
2070 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
2076 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
2077 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2079 $resql = $this->db->query($sql);
2082 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
2083 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2086 $order->fetch($this->origin_id);
2088 $order->loadReceptions(self::STATUS_CLOSED);
2090 $receptions_match_order = 1;
2091 foreach ($order->lines as $line) {
2092 $lineid = $line->id;
2094 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
2095 $receptions_match_order = 0;
2096 $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';
2101 if ($receptions_match_order) {
2102 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');
2103 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
2107 $this->statut = self::STATUS_CLOSED;
2108 $this->
status = self::STATUS_CLOSED;
2112 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2114 $langs->load(
"agenda");
2118 $sql =
"SELECT cd.fk_product, cd.subprice,";
2119 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2120 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2121 $sql .=
" ed.fk_elementdet, ed.cost_price";
2122 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2123 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2124 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2125 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2127 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2128 $resql = $this->db->query($sql);
2131 $cpt = $this->db->num_rows($resql);
2132 for ($i = 0; $i < $cpt; $i++) {
2133 $obj = $this->db->fetch_object($resql);
2137 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2141 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
2144 $mouvS->origin = &$this;
2145 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2147 if (empty($obj->batch)) {
2151 $inventorycode =
'';
2152 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2154 $this->error = $mouvS->error;
2155 $this->errors = $mouvS->errors;
2163 $inventorycode =
'';
2164 $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);
2167 $this->error = $mouvS->error;
2168 $this->errors = $mouvS->errors;
2175 $this->error = $this->db->lasterror();
2182 $result = $this->call_trigger(
'RECEPTION_CLOSED', $user);
2193 $this->db->commit();
2196 $this->statut = self::STATUS_VALIDATED;
2197 $this->
status = self::STATUS_VALIDATED;
2198 $this->db->rollback();
2215 if ($this->statut == Reception::STATUS_VALIDATED) {
2220 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
2221 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2223 $resql = $this->db->query($sql);
2228 $result = $this->call_trigger(
'RECEPTION_BILLED', $user);
2235 $this->errors[] = $this->db->lasterror;
2238 if (empty($error)) {
2239 $this->db->commit();
2242 $this->db->rollback();
2254 global $langs, $user;
2260 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
2261 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2263 $resql = $this->db->query($sql);
2264 $rollbackStatus = $this->status;
2265 $rollbackBilled = $this->billed;
2267 $this->statut = self::STATUS_VALIDATED;
2268 $this->
status = self::STATUS_VALIDATED;
2273 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2274 $numref = (string) $this->
ref;
2275 $langs->load(
"agenda");
2279 $sql =
"SELECT ed.fk_product, cd.subprice,";
2280 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2281 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2282 $sql .=
" ed.fk_elementdet, ed.cost_price";
2283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2284 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2285 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2286 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2288 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2289 $resql = $this->db->query($sql);
2291 $cpt = $this->db->num_rows($resql);
2292 for ($i = 0; $i < $cpt; $i++) {
2293 $obj = $this->db->fetch_object($resql);
2297 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2300 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2304 $mouvS->origin = &$this;
2305 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2307 if (empty($obj->batch)) {
2311 $inventorycode =
'';
2312 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
2315 $this->error = $mouvS->error;
2316 $this->errors = $mouvS->errors;
2324 $inventorycode =
'';
2325 $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);
2327 $this->error = $mouvS->error;
2328 $this->errors = $mouvS->errors;
2335 $this->error = $this->db->lasterror();
2342 $result = $this->call_trigger(
'RECEPTION_REOPEN', $user);
2348 if (!$error && $this->origin ==
'order_supplier') {
2349 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2352 $commande->fetch($this->origin_id);
2353 $result = $commande->setStatus($user, 4);
2356 $this->error = $commande->error;
2357 $this->errors = $commande->errors;
2362 $this->errors[] = $this->db->lasterror();
2366 $this->db->commit();
2369 $this->statut = $this->
status = $rollbackStatus;
2370 $this->billed = $rollbackBilled;
2371 $this->db->rollback();
2385 global $conf, $langs;
2390 if ($this->statut <= self::STATUS_DRAFT) {
2394 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2395 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2396 $this->error =
'Permission denied';
2402 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2403 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2404 $sql .=
" WHERE rowid = ".((int) $this->
id);
2407 if ($this->db->query($sql)) {
2410 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2412 $langs->load(
"agenda");
2416 $sql =
"SELECT cd.fk_product, cd.subprice,";
2417 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2418 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2419 $sql .=
" ed.fk_elementdet, ed.cost_price";
2420 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2421 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2422 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2423 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2425 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2426 $resql = $this->db->query($sql);
2428 $cpt = $this->db->num_rows($resql);
2429 for ($i = 0; $i < $cpt; $i++) {
2430 $obj = $this->db->fetch_object($resql);
2434 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2438 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2442 $mouvS->origin = &$this;
2443 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2445 if (empty($obj->batch)) {
2449 $inventorycode =
'';
2450 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2452 $this->error = $mouvS->error;
2453 $this->errors = $mouvS->errors;
2461 $inventorycode =
'';
2462 $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);
2464 $this->error = $mouvS->error;
2465 $this->errors = $mouvS->errors;
2472 $this->error = $this->db->lasterror();
2479 $result = $this->call_trigger(
'RECEPTION_UNVALIDATE', $user);
2484 if ($this->origin ==
'order_supplier') {
2485 if (!empty($this->origin) && $this->origin_id > 0) {
2487 if ($this->origin_object->statut == 4) {
2489 $this->origin_object->fetchObjectLinked();
2491 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2492 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2493 if ($rcption->statut > 0) {
2500 $this->origin_object->setStatut(3);
2508 $this->statut = self::STATUS_DRAFT;
2509 $this->
status = self::STATUS_DRAFT;
2510 $this->db->commit();
2513 $this->db->rollback();
2517 $this->error = $this->db->error();
2518 $this->db->rollback();
2533 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2535 global $conf, $langs;
2537 $langs->load(
"receptions");
2540 $modele =
'squille';
2542 if ($this->model_pdf) {
2543 $modele = $this->model_pdf;
2549 $modelpath =
"core/modules/reception/doc/";
2553 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2566 $tables = array(
'reception');
2582 '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.
deleteLine($user, $lineid)
Delete a line of the reception.
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.