37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40if (isModEnabled(
"propal")) {
41 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
43if (isModEnabled(
'order')) {
44 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
63 public $element =
"reception";
68 public $fk_element =
"fk_reception";
69 public $table_element =
"reception";
70 public $table_element_line =
"receptiondet_batch";
75 public $picto =
'dollyrevert';
93 public $tracking_number;
118 public $weight_units;
134 public $height_units;
154 public $user_author_id;
159 public $date_delivery;
171 public $date_reception;
190 public $lines = array();
197 public $detail_batch;
199 const STATUS_DRAFT = 0;
200 const STATUS_VALIDATED = 1;
201 const STATUS_CLOSED = 2;
213 $this->ismultientitymanaged = 1;
224 global $langs, $conf;
225 $langs->load(
"receptions");
234 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
236 foreach ($dirmodels as $reldir) {
240 $mybool = ((bool) @include_once $dir.$file) || $mybool;
248 $obj =
new $classname();
249 '@phan-var-force ModelNumRefReception $obj';
251 $numref = $obj->getNextValue($soc, $this);
256 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
260 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
272 public function create($user, $notrigger = 0)
278 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
283 if (empty($this->fk_project)) {
284 $this->fk_project = 0;
286 if (empty($this->weight_units)) {
287 $this->weight_units = 0;
289 if (empty($this->size_units)) {
290 $this->size_units = 0;
297 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
300 $sql .=
", ref_supplier";
301 $sql .=
", date_creation";
302 $sql .=
", fk_user_author";
303 $sql .=
", date_reception";
304 $sql .=
", date_delivery";
306 $sql .=
", fk_projet";
307 $sql .=
", fk_shipping_method";
308 $sql .=
", tracking_number";
313 $sql .=
", weight_units";
314 $sql .=
", size_units";
315 $sql .=
", note_private";
316 $sql .=
", note_public";
317 $sql .=
", model_pdf";
318 $sql .=
", fk_incoterms, location_incoterms";
319 $sql .=
") VALUES (";
321 $sql .=
", ".((int) $conf->entity);
322 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
323 $sql .=
", '".$this->db->idate($now).
"'";
324 $sql .=
", ".((int) $user->id);
325 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
326 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
327 $sql .=
", ".((int) $this->socid);
328 $sql .=
", ".((int) $this->fk_project);
329 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
330 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
331 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
332 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
333 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
334 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
335 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((float) $this->weight_units));
336 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((float) $this->size_units));
337 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
338 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
339 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
340 $sql .=
", ".(int) $this->fk_incoterms;
341 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
344 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
346 $resql = $this->db->query($sql);
349 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
351 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
352 $sql .=
" SET ref = '(PROV".((int) $this->
id).
")'";
353 $sql .=
" WHERE rowid = ".((int) $this->
id);
355 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
356 if ($this->db->query($sql)) {
358 $num = count($this->lines);
359 for ($i = 0; $i < $num; $i++) {
360 $this->lines[$i]->fk_reception = $this->id;
362 if (!$this->lines[$i]->
create($user) > 0) {
367 if (!$error && $this->
id && $this->origin_id) {
382 if (!$error && !$notrigger) {
384 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
395 foreach ($this->errors as $errmsg) {
396 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
397 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
399 $this->db->rollback();
404 $this->error = $this->db->lasterror().
" - sql=$sql";
405 $this->db->rollback();
410 $this->error = $this->db->error().
" - sql=$sql";
411 $this->db->rollback();
426 public function fetch($id, $ref =
'', $ref_ext =
'')
429 if (empty($id) && empty($ref) && empty($ref_ext)) {
433 $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.billed";
434 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
435 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
436 $sql .=
", e.fk_shipping_method, e.tracking_number";
437 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
438 $sql .=
", e.note_private, e.note_public";
439 $sql .=
', e.fk_incoterms, e.location_incoterms';
440 $sql .=
', i.libelle as label_incoterms';
441 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
442 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
443 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
444 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
446 $sql .=
" AND e.rowid = ".((int) $id);
449 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
452 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
455 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
456 $result = $this->db->query($sql);
458 if ($this->db->num_rows($result)) {
459 $obj = $this->db->fetch_object($result);
461 $this->
id = $obj->rowid;
462 $this->entity = $obj->entity;
463 $this->
ref = $obj->ref;
464 $this->socid = $obj->socid;
465 $this->ref_supplier = $obj->ref_supplier;
466 $this->ref_ext = $obj->ref_ext;
467 $this->statut = $obj->status;
468 $this->
status = $obj->status;
469 $this->billed = $obj->billed;
471 $this->user_author_id = $obj->fk_user_author;
472 $this->date_creation = $this->db->jdate($obj->date_creation);
473 $this->date = $this->db->jdate($obj->date_reception);
474 $this->date_reception = $this->db->jdate($obj->date_reception);
475 $this->date_delivery = $this->db->jdate($obj->date_delivery);
476 $this->model_pdf = $obj->model_pdf;
477 $this->shipping_method_id = $obj->fk_shipping_method;
478 $this->tracking_number = $obj->tracking_number;
479 $this->origin = ($obj->origin ? $obj->origin :
'commande');
480 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
481 $this->origin_id = $obj->origin_id;
483 $this->trueWeight = $obj->weight;
484 $this->weight_units = $obj->weight_units;
486 $this->trueWidth = $obj->width;
487 $this->width_units = $obj->size_units;
488 $this->trueHeight = $obj->height;
489 $this->height_units = $obj->size_units;
490 $this->trueDepth = $obj->size;
491 $this->depth_units = $obj->size_units;
493 $this->note_public = $obj->note_public;
494 $this->note_private = $obj->note_private;
497 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
498 $this->size_units = $obj->size_units;
501 $this->fk_incoterms = $obj->fk_incoterms;
502 $this->location_incoterms = $obj->location_incoterms;
503 $this->label_incoterms = $obj->label_incoterms;
505 $this->db->free($result);
521 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
523 $extrafields->fetch_name_optionals_label($this->table_element,
true);
536 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
537 $this->error =
'Reception with id '.$id.
' not found';
541 $this->error = $this->db->error();
553 public function valid($user, $notrigger = 0)
555 global $conf, $langs;
557 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
563 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
567 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
568 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
569 $this->error =
'Permission denied';
570 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
580 $soc->fetch($this->socid);
584 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
587 $numref = $this->ref;
595 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
596 $sql .=
" ref='".$this->db->escape($numref).
"'";
597 $sql .=
", fk_statut = 1";
598 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
599 $sql .=
", fk_user_valid = ".((int) $user->id);
600 $sql .=
" WHERE rowid = ".((int) $this->
id);
601 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
602 $resql = $this->db->query($sql);
604 $this->error = $this->db->lasterror();
609 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
610 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
612 $langs->load(
"agenda");
616 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
617 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
618 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
619 $sql .=
" ed.cost_price";
620 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
621 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
622 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
623 $sql .=
" AND cd.rowid = ed.fk_elementdet";
625 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
626 $resql = $this->db->query($sql);
628 $cpt = $this->db->num_rows($resql);
629 for ($i = 0; $i < $cpt; $i++) {
630 $obj = $this->db->fetch_object($resql);
634 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
637 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
641 $mouvS->origin = &$this;
642 $mouvS->setOrigin($this->element, $this->
id);
644 if (empty($obj->batch)) {
649 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
651 if (intval($result) < 0) {
653 $this->errors[] = $mouvS->error;
654 $this->errors = array_merge($this->errors, $mouvS->errors);
663 $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);
665 if (intval($result) < 0) {
667 $this->errors[] = $mouvS->error;
668 $this->errors = array_merge($this->errors, $mouvS->errors);
674 $this->db->rollback();
675 $this->error = $this->db->error();
688 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
691 $this->errors = array_merge($this->errors, $this->origin_object->errors);
694 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
702 if (!$error && !$notrigger) {
704 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
712 $this->oldref = $this->ref;
715 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
717 $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).
"'";
718 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
719 $resql = $this->db->query($sql);
722 $this->error = $this->db->lasterror();
724 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
725 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
726 $resql = $this->db->query($sql);
729 $this->error = $this->db->lasterror();
735 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
736 $dirdest = $conf->reception->dir_output.
'/'.$newref;
737 if (!$error && file_exists($dirsource)) {
738 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
740 if (@rename($dirsource, $dirdest)) {
743 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
744 foreach ($listoffiles as $fileentry) {
745 $dirsource = $fileentry[
'name'];
746 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
747 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
748 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
749 @rename($dirsource, $dirdest);
758 $this->
ref = $numref;
759 $this->statut = self::STATUS_VALIDATED;
760 $this->
status = self::STATUS_VALIDATED;
767 foreach ($this->errors as $errmsg) {
768 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
769 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
771 $this->db->rollback();
783 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
784 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
788 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
789 if (empty($this->origin_object)) {
791 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
792 $res = $this->origin_object->fetch_lines();
796 $this->commandeFournisseur =
null;
804 $qty_received = array();
805 $qty_wished = array();
808 $filter = array(
't.fk_element' => $this->origin_id);
810 $filter[
't.status'] = 1;
813 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
815 $this->error = $supplierorderdispatch->error;
816 $this->errors = $supplierorderdispatch->errors;
820 foreach ($supplierorderdispatch->lines as $dispatch_line) {
821 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
822 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
824 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
829 foreach ($this->origin_object->lines as $origin_line) {
831 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
835 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
839 $diff_array = array_diff_assoc($qty_received, $qty_wished);
840 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
841 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
843 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
849 if (count($diff_array) > 0) {
852 foreach ($diff_array as $key => $value) {
854 if ($qty_received[$key] >= $qty_wished[$key]) {
860 if ($close == count($diff_array)) {
887 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
889 global $conf, $langs, $user;
891 $num = count($this->lines);
894 $line->fk_entrepot = $entrepot_id;
895 $line->fk_commandefourndet = $id;
899 $result = $supplierorderline->fetch($id);
901 $this->error = $supplierorderline->error;
902 $this->errors = $supplierorderline->errors;
907 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
908 $fk_product = $supplierorderline->fk_product;
910 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
911 $langs->load(
"errors");
912 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
918 $product =
new Product($this->db);
919 $product->fetch($fk_product);
920 if (isModEnabled(
'productbatch')) {
921 $langs->load(
"errors");
922 if (!empty($product->status_batch) && empty($batch)) {
923 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
925 } elseif (empty($product->status_batch) && !empty($batch)) {
926 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
932 if (!empty($errorMsgArr)) {
933 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
934 $errorMessage .=
'<ul>';
935 foreach ($errorMsgArr as $errorMsg) {
936 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
938 $errorMessage .=
'</ul>';
939 $this->error = $errorMessage;
946 $line->array_options = $supplierorderline->array_options;
947 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
948 foreach ($array_options as $key => $value) {
949 $line->array_options[$key] = $value;
953 $line->fk_product = $fk_product;
954 $line->fk_commande = $supplierorderline->fk_commande;
955 $line->fk_user = $user->id;
956 $line->comment = $comment;
957 $line->batch = $batch;
958 $line->eatby = $eatby;
959 $line->sellby = $sellby;
961 $line->cost_price = $cost_price;
962 $line->fk_reception = $this->id;
964 $this->lines[$num] = $line;
977 public function update($user =
null, $notrigger = 0)
984 if (isset($this->
ref)) {
985 $this->
ref = trim($this->
ref);
987 if (isset($this->entity)) {
988 $this->entity = (int) $this->entity;
990 if (isset($this->ref_supplier)) {
991 $this->ref_supplier = trim($this->ref_supplier);
993 if (isset($this->socid)) {
994 $this->socid = (int) trim((
string) $this->socid);
996 if (isset($this->fk_user_author)) {
997 $this->fk_user_author = (int) $this->fk_user_author;
999 if (isset($this->fk_user_valid)) {
1000 $this->fk_user_valid = (int) $this->fk_user_valid;
1002 if (isset($this->shipping_method_id)) {
1003 $this->shipping_method_id = (int) $this->shipping_method_id;
1005 if (isset($this->tracking_number)) {
1006 $this->tracking_number = trim($this->tracking_number);
1008 if (isset($this->statut)) {
1009 $this->statut = (int) $this->statut;
1011 if (isset($this->trueDepth)) {
1012 $this->trueDepth = (float) trim((
string) $this->trueDepth);
1014 if (isset($this->trueWidth)) {
1015 $this->trueWidth = (float) trim((
string) $this->trueWidth);
1017 if (isset($this->trueHeight)) {
1018 $this->trueHeight = (float) trim((
string) $this->trueHeight);
1020 if (isset($this->size_units)) {
1021 $this->size_units = trim((
string) $this->size_units);
1023 if (isset($this->weight_units)) {
1024 $this->weight_units = (float) trim((
string) $this->weight_units);
1026 if (isset($this->trueWeight)) {
1027 $this->weight = (float) trim((
string) $this->trueWeight);
1029 if (isset($this->note_private)) {
1030 $this->note_private = trim($this->note_private);
1032 if (isset($this->note_public)) {
1033 $this->note_public = trim($this->note_public);
1035 if (isset($this->model_pdf)) {
1036 $this->model_pdf = trim($this->model_pdf);
1044 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1046 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1047 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1048 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1049 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1050 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1051 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1052 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1053 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1054 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1055 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1056 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1057 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1058 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1059 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1060 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1061 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1062 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1063 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1064 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1065 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1066 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1067 $sql .=
" entity = ".((int) $conf->entity);
1068 $sql .=
" WHERE rowid=".((int) $this->
id);
1072 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1073 $resql = $this->db->query($sql);
1076 $this->errors[] =
"Error ".$this->db->lasterror();
1082 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1092 foreach ($this->errors as $errmsg) {
1093 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1094 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1096 $this->db->rollback();
1099 $this->db->commit();
1112 global $conf, $langs, $user;
1113 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1122 if (isModEnabled(
'stock') && !
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') && $this->statut > 0) {
1123 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1125 $langs->load(
"agenda");
1128 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1130 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1131 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1132 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1134 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1135 $resql = $this->db->query($sql);
1137 $cpt = $this->db->num_rows($resql);
1138 for ($i = 0; $i < $cpt; $i++) {
1139 dol_syslog(get_class($this).
"::delete movement index ".$i);
1140 $obj = $this->db->fetch_object($resql);
1144 $mouvS->origin =
null;
1146 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1149 $this->error = $mouvS->error;
1150 $this->errors = $mouvS->errors;
1155 $this->errors[] =
"Error ".$this->db->lasterror();
1160 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1161 $ef = $main.
"_extrafields";
1163 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1165 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1166 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1168 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1176 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1177 $sql .=
" WHERE rowid = ".((int) $this->
id);
1179 if ($this->db->query($sql)) {
1181 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1187 if (!empty($this->origin) && $this->origin_id > 0) {
1190 '@phan-var-force CommandeFournisseur $origin_object';
1202 $this->db->commit();
1206 if (!empty($conf->reception->dir_output)) {
1207 $dir = $conf->reception->dir_output.
'/'.$ref;
1208 $file = $dir.
'/'.$ref.
'.pdf';
1209 if (file_exists($file)) {
1214 if (file_exists($dir)) {
1216 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1224 $this->db->rollback();
1228 $this->error = $this->db->lasterror().
" - sql=$sql";
1229 $this->db->rollback();
1233 $this->error = $this->db->lasterror().
" - sql=$sql";
1234 $this->db->rollback();
1238 $this->error = $this->db->lasterror().
" - sql=$sql";
1239 $this->db->rollback();
1243 $this->db->rollback();
1257 $this->lines = array();
1259 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1261 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1262 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1264 $resql = $this->db->query($sql);
1266 if (!empty($resql)) {
1267 while ($obj = $this->db->fetch_object($resql)) {
1270 $line->fetch($obj->rowid);
1273 $line->fetch_product();
1275 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1276 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1277 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1278 $sql_commfourndet .=
' ORDER BY rang';
1280 $resql_commfourndet = $this->db->query($sql_commfourndet);
1281 if (!empty($resql_commfourndet)) {
1282 $obj = $this->db->fetch_object($resql_commfourndet);
1283 $line->qty_asked = $obj->qty;
1284 $line->description = $obj->description;
1285 $line->desc = $obj->description;
1286 $line->tva_tx = $obj->tva_tx;
1287 $line->vat_src_code = $obj->vat_src_code;
1288 $line->subprice = $obj->subprice;
1289 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1290 $line->remise_percent = $obj->remise_percent;
1291 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1292 $line->ref_supplier = $obj->ref;
1293 $line->total_ht = $obj->total_ht;
1294 $line->total_ttc = $obj->total_ttc;
1295 $line->total_tva = $obj->total_tva;
1297 $line->qty_asked = 0;
1298 $line->description =
'';
1300 $line->label = $obj->label;
1303 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1304 $tva = $pu_ht * $line->tva_tx / 100;
1305 $this->total_ht += $pu_ht;
1306 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1308 $this->total_ttc += $pu_ht + $tva;
1310 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1312 $detail_batch->eatby = $line->eatby;
1313 $detail_batch->sellby = $line->sellby;
1314 $detail_batch->batch = $line->batch;
1315 $detail_batch->qty = $line->qty;
1317 $line->detail_batch[] = $detail_batch;
1320 $this->lines[] = $line;
1339 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1341 global $langs, $hookmanager;
1344 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1345 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1346 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1348 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1355 if (empty($notooltip)) {
1357 $label = $langs->trans(
"Reception");
1358 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1360 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1361 $linkclose .=
' class="classfortooltip"';
1364 $linkstart =
'<a href="'.$url.
'"';
1365 $linkstart .= $linkclose.
'>';
1368 $result .= $linkstart;
1370 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1372 if ($withpicto != 2) {
1373 $result .= $this->ref;
1376 $result .= $linkend;
1379 $hookmanager->initHooks(array($this->element .
'dao'));
1380 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1381 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1383 $result = $hookmanager->resPrint;
1385 $result .= $hookmanager->resPrint;
1398 return $this->
LibStatut($this->statut, $mode);
1415 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1416 $this->labelStatus[0] =
'StatusReceptionDraft';
1418 $this->labelStatus[1] =
'StatusReceptionValidated';
1420 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1423 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1425 $this->labelStatus[2] =
'StatusReceptionProcessed';
1428 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1429 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1430 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1431 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1433 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1434 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1436 $statusType =
'status'.$status;
1437 if ($status == self::STATUS_VALIDATED) {
1438 $statusType =
'status4';
1440 if ($status == self::STATUS_CLOSED) {
1441 $statusType =
'status6';
1444 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1456 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1458 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1459 $return .=
'<div class="info-box info-box-sm">';
1460 $return .=
'<div class="info-box-icon bg-infobox-action">';
1462 $return .=
'</div>';
1463 $return .=
'<div class="info-box-content">';
1464 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1465 if ($selected >= 0) {
1466 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1468 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1469 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1474 if (method_exists($this,
'getLibStatut')) {
1475 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1477 $return .=
'</div>';
1478 $return .=
'</div>';
1479 $return .=
'</div>';
1495 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1496 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1499 dol_syslog(get_class($this).
"::initAsSpecimen");
1502 $order->initAsSpecimen();
1506 $this->
ref =
'SPECIMEN';
1507 $this->specimen = 1;
1511 $this->date_creation = $now;
1512 $this->date_valid = $now;
1513 $this->date_delivery = $now;
1514 $this->date_reception = $now + 24 * 3600;
1516 $this->entrepot_id = 0;
1519 $this->origin_id = 1;
1520 $this->origin_type =
'supplier_order';
1521 $this->origin_object = $order;
1523 $this->note_private =
'Private note';
1524 $this->note_public =
'Public note';
1526 $this->tracking_number =
'TRACKID-ABC123';
1528 $this->fk_incoterms = 1;
1532 while ($xnbp < $nbp) {
1534 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1535 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1536 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1539 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1541 $this->lines[] = $line;
1558 if ($user->hasRight(
'reception',
'creer')) {
1559 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1560 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1561 $sql .=
" WHERE rowid = ".((int) $this->
id);
1563 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1564 $resql = $this->db->query($sql);
1566 $this->date_delivery = $delivery_date;
1569 $this->error = $this->db->error();
1587 $this->meths = array();
1589 $sql =
"SELECT em.rowid, em.code, em.libelle";
1590 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1591 $sql .=
" WHERE em.active = 1";
1592 $sql .=
" ORDER BY em.libelle ASC";
1594 $resql = $this->db->query($sql);
1596 while ($obj = $this->db->fetch_object($resql)) {
1597 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1598 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1615 $this->listmeths = array();
1618 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1619 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1621 $sql .=
" WHERE em.rowid = ".((int) $id);
1624 $resql = $this->db->query($sql);
1626 while ($obj = $this->db->fetch_object($resql)) {
1627 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1628 $this->listmeths[$i][
'code'] = $obj->code;
1629 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1630 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1631 $this->listmeths[$i][
'description'] = $obj->description;
1632 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1633 $this->listmeths[$i][
'active'] = $obj->active;
1647 if (!empty($this->shipping_method_id)) {
1648 $sql =
"SELECT em.code, em.tracking";
1649 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1650 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1652 $resql = $this->db->query($sql);
1654 if ($obj = $this->db->fetch_object($resql)) {
1655 $tracking = $obj->tracking;
1660 if (!empty($tracking) && !empty($value)) {
1661 $url = str_replace(
'{TRACKID}', $value, $tracking);
1662 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1664 $this->tracking_url = $value;
1675 global $conf, $langs, $user;
1680 if ($this->statut == Reception::STATUS_CLOSED) {
1681 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1687 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1688 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1690 $resql = $this->db->query($sql);
1693 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1695 $order->fetch($this->origin_id);
1697 $order->loadReceptions(self::STATUS_CLOSED);
1699 $receptions_match_order = 1;
1700 foreach ($order->lines as $line) {
1701 $lineid = $line->id;
1703 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1704 $receptions_match_order = 0;
1705 $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';
1710 if ($receptions_match_order) {
1711 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');
1712 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1716 $this->statut = self::STATUS_CLOSED;
1717 $this->
status = self::STATUS_CLOSED;
1720 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1721 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1723 $langs->load(
"agenda");
1727 $sql =
"SELECT cd.fk_product, cd.subprice,";
1728 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1729 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1730 $sql .=
" ed.cost_price";
1731 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1732 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1733 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1734 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1736 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1737 $resql = $this->db->query($sql);
1740 $cpt = $this->db->num_rows($resql);
1741 for ($i = 0; $i < $cpt; $i++) {
1742 $obj = $this->db->fetch_object($resql);
1749 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1752 $mouvS->origin = &$this;
1753 $mouvS->setOrigin($this->element, $this->
id);
1755 if (empty($obj->batch)) {
1759 $inventorycode =
'';
1760 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1762 $this->error = $mouvS->error;
1763 $this->errors = $mouvS->errors;
1771 $inventorycode =
'';
1772 $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);
1775 $this->error = $mouvS->error;
1776 $this->errors = $mouvS->errors;
1783 $this->error = $this->db->lasterror();
1790 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1801 $this->db->commit();
1804 $this->statut = self::STATUS_VALIDATED;
1805 $this->
status = self::STATUS_VALIDATED;
1806 $this->db->rollback();
1823 if ($this->statut == Reception::STATUS_VALIDATED) {
1828 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1829 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1831 $resql = $this->db->query($sql);
1836 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1843 $this->errors[] = $this->db->lasterror;
1846 if (empty($error)) {
1847 $this->db->commit();
1850 $this->db->rollback();
1862 global $conf, $langs, $user;
1868 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1869 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1871 $resql = $this->db->query($sql);
1873 $this->statut = self::STATUS_VALIDATED;
1874 $this->
status = self::STATUS_VALIDATED;
1878 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1879 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1880 $numref = $this->ref;
1881 $langs->load(
"agenda");
1885 $sql =
"SELECT ed.fk_product, cd.subprice,";
1886 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1887 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1888 $sql .=
" ed.cost_price";
1889 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1890 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1891 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1892 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1894 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1895 $resql = $this->db->query($sql);
1897 $cpt = $this->db->num_rows($resql);
1898 for ($i = 0; $i < $cpt; $i++) {
1899 $obj = $this->db->fetch_object($resql);
1907 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1911 $mouvS->origin = &$this;
1912 $mouvS->setOrigin($this->element, $this->
id);
1914 if (empty($obj->batch)) {
1918 $inventorycode =
'';
1919 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1922 $this->error = $mouvS->error;
1923 $this->errors = $mouvS->errors;
1931 $inventorycode =
'';
1932 $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);
1934 $this->error = $mouvS->error;
1935 $this->errors = $mouvS->errors;
1942 $this->error = $this->db->lasterror();
1949 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1955 if (!$error && $this->origin ==
'order_supplier') {
1957 $commande->fetch($this->origin_id);
1958 $result = $commande->setStatus($user, 4);
1961 $this->error = $commande->error;
1962 $this->errors = $commande->errors;
1967 $this->errors[] = $this->db->lasterror();
1971 $this->db->commit();
1974 $this->db->rollback();
1988 global $conf, $langs;
1993 if ($this->statut <= self::STATUS_DRAFT) {
1997 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
1998 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
1999 $this->error =
'Permission denied';
2005 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2006 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2007 $sql .=
" WHERE rowid = ".((int) $this->
id);
2010 if ($this->db->query($sql)) {
2012 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
2013 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2015 $langs->load(
"agenda");
2019 $sql =
"SELECT cd.fk_product, cd.subprice,";
2020 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2021 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2022 $sql .=
" ed.cost_price";
2023 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2024 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2025 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2026 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2028 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2029 $resql = $this->db->query($sql);
2031 $cpt = $this->db->num_rows($resql);
2032 for ($i = 0; $i < $cpt; $i++) {
2033 $obj = $this->db->fetch_object($resql);
2041 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2045 $mouvS->origin = &$this;
2046 $mouvS->setOrigin($this->element, $this->
id);
2048 if (empty($obj->batch)) {
2052 $inventorycode =
'';
2053 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2055 $this->error = $mouvS->error;
2056 $this->errors = $mouvS->errors;
2064 $inventorycode =
'';
2065 $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);
2067 $this->error = $mouvS->error;
2068 $this->errors = $mouvS->errors;
2075 $this->error = $this->db->lasterror();
2082 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
2087 if ($this->origin ==
'order_supplier') {
2088 if (!empty($this->origin) && $this->origin_id > 0) {
2090 if ($this->origin_object->statut == 4) {
2092 $this->origin_object->fetchObjectLinked();
2094 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2095 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2096 if ($rcption->statut > 0) {
2103 $this->origin_object->setStatut(3);
2111 $this->statut = self::STATUS_DRAFT;
2112 $this->
status = self::STATUS_DRAFT;
2113 $this->db->commit();
2116 $this->db->rollback();
2120 $this->error = $this->db->error();
2121 $this->db->rollback();
2136 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2138 global $conf, $langs;
2140 $langs->load(
"receptions");
2143 $modele =
'squille';
2145 if ($this->model_pdf) {
2146 $modele = $this->model_pdf;
2152 $modelpath =
"core/modules/reception/doc/";
2156 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2169 $tables = array(
'reception');
2185 '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...
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.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
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.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0)
Return clickable link of object (with eventually picto)
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this records also the stock movement)
getNextNumRef($soc)
Return next contract ref.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
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.
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create reception en base.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
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 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_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db user
Active Directory does not allow anonymous connections.