40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
42require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/reception/class/receptionlinebatch.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
63 public $TRIGGER_PREFIX =
'RECEPTION';
73 public $element =
"reception";
78 public $fk_element =
"fk_reception";
83 public $table_element =
"reception";
88 public $table_element_line =
"receptiondet_batch";
93 public $picto =
'dollyrevert';
102 public $ref_supplier;
111 public $tracking_number;
115 public $tracking_url;
132 public $weight_units;
148 public $height_units;
168 public $user_author_id;
173 public $date_delivery;
185 public $date_reception;
204 public $lines = array();
211 public $detail_batch;
213 const STATUS_CANCELED = -1;
214 const STATUS_DRAFT = 0;
215 const STATUS_VALIDATED = 1;
216 const STATUS_CLOSED = 2;
228 $this->ismultientitymanaged = 1;
229 $this->isextrafieldmanaged = 1;
238 public function getNextNumRef($soc)
240 global $langs,
$conf;
241 $langs->load(
"receptions");
250 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
252 foreach ($dirmodels as $reldir) {
256 $mybool = ((bool) @include_once $dir.$file) || $mybool;
264 $obj =
new $classname();
265 '@phan-var-force ModelNumRefReception $obj';
268 $numref = $obj->getNextValue($soc, $this);
273 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
277 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
289 public function create($user, $notrigger = 0)
295 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
300 if (empty($this->fk_project)) {
301 $this->fk_project = 0;
303 if (empty($this->weight_units)) {
304 $this->weight_units = 0;
306 if (empty($this->size_units)) {
307 $this->size_units = 0;
309 if (empty($this->date_creation)) {
310 $this->date_creation = $now;
319 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
322 $sql .=
", ref_supplier";
323 $sql .=
", date_creation";
324 $sql .=
", fk_user_author";
325 $sql .=
", date_reception";
326 $sql .=
", date_delivery";
328 $sql .=
", fk_projet";
329 $sql .=
", fk_shipping_method";
330 $sql .=
", tracking_number";
335 $sql .=
", weight_units";
336 $sql .=
", size_units";
337 $sql .=
", note_private";
338 $sql .=
", note_public";
339 $sql .=
", model_pdf";
340 $sql .=
", fk_incoterms, location_incoterms";
341 $sql .=
") VALUES (";
343 $sql .=
", ".((int) $this->entity);
344 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
345 $sql .=
", '".$this->db->idate($this->date_creation).
"'";
346 $sql .=
", ".((int) $user->id);
347 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
348 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
349 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
350 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
351 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
352 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
353 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
354 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
355 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
356 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
357 $sql .=
", ".((int) $this->weight_units);
358 $sql .=
", ".((int) $this->size_units);
359 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
360 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
361 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
362 $sql .=
", ".(int) $this->fk_incoterms;
363 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
366 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
368 $resql = $this->db->query($sql);
371 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
374 $initialref =
'(PROV'.$this->id.
')';
375 if (!empty($this->
ref)) {
376 $initialref = $this->ref;
379 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
380 $sql .=
" SET ref = '".$this->db->escape($initialref).
"'";
381 $sql .=
" WHERE rowid = ".((int) $this->
id);
383 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
384 if ($this->db->query($sql)) {
386 $num = count($this->lines);
387 for ($i = 0; $i < $num; $i++) {
388 $this->lines[$i]->fk_reception = $this->id;
390 if ($this->lines[$i]->
create($user) <= 0) {
396 if (!$error && $this->
id && $this->origin_id) {
411 if (!$error && !$notrigger) {
413 $result = $this->call_trigger(
'RECEPTION_CREATE', $user);
424 foreach ($this->errors as $errmsg) {
425 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
426 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
428 $this->db->rollback();
433 $this->error = $this->db->lasterror().
" - sql=$sql";
434 $this->db->rollback();
439 $this->error = $this->db->error().
" - sql=$sql";
440 $this->db->rollback();
458 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
464 $receptionline->fk_reception = $this->id;
465 $receptionline->entrepot_id = $entrepot_id;
466 $receptionline->fk_elementdet = $origin_line_id;
467 $receptionline->element_type = $this->origin;
468 $receptionline->fk_parent = $parent_line_id;
469 $receptionline->fk_product = $product_id;
470 $receptionline->qty = $qty;
471 $receptionline->rang = $rang;
472 $receptionline->array_options = $array_options;
474 if (!($receptionline->fk_product > 0)) {
476 $order_line->fetch($receptionline->fk_elementdet);
477 $receptionline->fk_product = $order_line->fk_product;
480 if (($lineId = $receptionline->insert($user)) < 0) {
481 $this->errors[] = $receptionline->error;
494 public function fetch($id, $ref =
'', $ref_ext =
'')
497 if (empty($id) && empty($ref) && empty($ref_ext)) {
501 $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";
502 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
503 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
504 $sql .=
", e.fk_shipping_method, e.tracking_number";
505 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
506 $sql .=
", e.note_private, e.note_public";
507 $sql .=
', e.fk_incoterms, e.location_incoterms';
508 $sql .=
', i.libelle as label_incoterms';
509 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
510 $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'";
511 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
514 $sql .=
" WHERE e.rowid = ".((int) $id);
516 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
518 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
519 } elseif ($ref_ext) {
520 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
524 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
525 $result = $this->db->query($sql);
527 if ($this->db->num_rows($result)) {
528 $obj = $this->db->fetch_object($result);
530 $this->
id = $obj->rowid;
531 $this->entity = $obj->entity;
532 $this->
ref = $obj->ref;
533 $this->socid = $obj->socid;
534 $this->ref_supplier = $obj->ref_supplier;
535 $this->ref_ext = $obj->ref_ext;
536 $this->statut = $obj->status;
537 $this->
status = $obj->status;
538 $this->billed = $obj->billed;
539 $this->fk_project = $obj->fk_project;
540 $this->user_author_id = $obj->fk_user_author;
541 $this->date_creation = $this->db->jdate($obj->date_creation);
542 $this->
date = $this->db->jdate($obj->date_reception);
543 $this->date_reception = $this->db->jdate($obj->date_reception);
544 $this->date_delivery = $this->db->jdate($obj->date_delivery);
545 $this->date_valid = $this->db->jdate($obj->date_valid);
546 $this->model_pdf = $obj->model_pdf;
547 $this->shipping_method_id = $obj->fk_shipping_method;
548 $this->tracking_number = $obj->tracking_number;
549 $this->origin = ($obj->origin ? $obj->origin :
'commande');
550 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
551 $this->origin_id = $obj->origin_id;
553 $this->trueWeight = $obj->weight;
554 $this->weight_units = $obj->weight_units;
556 $this->trueWidth = $obj->width;
557 $this->width_units = $obj->size_units;
558 $this->trueHeight = $obj->height;
559 $this->height_units = $obj->size_units;
560 $this->trueDepth = $obj->size;
561 $this->depth_units = $obj->size_units;
563 $this->note_public = $obj->note_public;
564 $this->note_private = $obj->note_private;
567 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
568 $this->size_units = $obj->size_units;
571 $this->fk_incoterms = $obj->fk_incoterms;
572 $this->location_incoterms = $obj->location_incoterms;
573 $this->label_incoterms = $obj->label_incoterms;
575 $this->db->free($result);
591 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
593 $extrafields->fetch_name_optionals_label($this->table_element,
true);
599 if (empty($obj->origin_id)) {
610 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
611 $this->error =
'Reception with id '.$id.
' not found';
615 $this->error = $this->db->error();
627 public function valid($user, $notrigger = 0)
629 global
$conf, $langs;
631 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
637 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
641 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
642 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
643 $this->error =
'Permission denied';
644 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
654 $soc->fetch($this->socid);
658 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
659 $numref = $this->getNextNumRef($soc);
669 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
670 $sql .=
" ref='".$this->db->escape($numref).
"'";
671 $sql .=
", fk_statut = 1";
672 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
673 $sql .=
", fk_user_valid = ".((int) $user->id);
674 $sql .=
" WHERE rowid = ".((int) $this->
id);
675 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
676 $resql = $this->db->query($sql);
678 $this->error = $this->db->lasterror();
684 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
686 $langs->load(
"agenda");
690 $sql =
"SELECT COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) as fk_product, cd.subprice, cd.remise_percent,";
691 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
692 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
693 $sql .=
" ed.fk_elementdet, ed.cost_price";
694 $sql .=
" FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
695 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd ON cd.rowid = ed.fk_elementdet";
696 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
697 $sql .=
" AND COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) IS NOT NULL";
698 $sql .=
" AND ed.fk_entrepot IS NOT NULL AND ed.fk_entrepot > 0";
700 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
701 $resql = $this->db->query($sql);
703 $cpt = $this->db->num_rows($resql);
704 for ($i = 0; $i < $cpt; $i++) {
705 $obj = $this->db->fetch_object($resql);
709 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
713 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
717 $mouvS->origin = &$this;
718 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
720 if (empty($obj->batch)) {
725 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
727 if (intval($result) < 0) {
738 $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);
740 if (intval($result) < 0) {
748 $this->db->rollback();
749 $this->error = $this->db->error();
754 if (!$error && $this->origin_id > 0) {
762 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
765 $this->errors = array_merge($this->errors, $this->origin_object->errors);
768 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
776 if (!$error && !$notrigger) {
778 $result = $this->call_trigger(
'RECEPTION_VALIDATE', $user);
786 $this->oldref = $this->ref;
789 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
791 $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).
"'";
792 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
793 $resql = $this->db->query($sql);
796 $this->error = $this->db->lasterror();
798 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
799 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
800 $resql = $this->db->query($sql);
803 $this->error = $this->db->lasterror();
809 $dirsource =
$conf->reception->dir_output.
'/'.$oldref;
810 $dirdest =
$conf->reception->dir_output.
'/'.$newref;
811 if (!$error && file_exists($dirsource)) {
812 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
814 if (@rename($dirsource, $dirdest)) {
817 $listoffiles =
dol_dir_list(
$conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
818 foreach ($listoffiles as $fileentry) {
819 $dirsource = $fileentry[
'name'];
820 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
821 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
822 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
823 @rename($dirsource, $dirdest);
832 $this->
ref = $numref;
833 $this->statut = self::STATUS_VALIDATED;
834 $this->
status = self::STATUS_VALIDATED;
841 foreach ($this->errors as $errmsg) {
842 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
843 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
845 $this->db->rollback();
857 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
858 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
862 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
863 if (empty($this->origin_object)) {
865 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
866 $res = $this->origin_object->fetch_lines();
867 $this->commandeFournisseur =
null;
871 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
872 $res = $this->origin_object->fetch_lines();
880 $qty_received = array();
881 $qty_wished = array();
884 $filter = array(
't.fk_element' => $this->origin_id);
886 $filter[
't.status'] = 1;
889 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
895 foreach ($supplierorderdispatch->lines as $dispatch_line) {
896 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
897 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
899 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
904 foreach ($this->origin_object->lines as $origin_line) {
906 if (($origin_line->product_type > 0 && (!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') || empty($origin_line->stockable_product))) || $origin_line->product_type > 1) {
909 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
910 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
912 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
917 $diff_array = array_diff_assoc($qty_received, $qty_wished);
918 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
919 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
921 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
927 if (count($diff_array) > 0) {
930 foreach ($diff_array as $key => $value) {
932 if ($qty_received[$key] >= $qty_wished[$key]) {
938 if ($close == count($diff_array)) {
965 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
967 global
$conf, $langs, $user;
969 $num = count($this->lines);
972 $line->fk_entrepot = $entrepot_id;
973 $line->fk_commandefourndet = $id;
977 $result = $supplierorderline->fetch($id);
984 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
985 $fk_product = $supplierorderline->fk_product;
987 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
988 $langs->load(
"errors");
989 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
995 $product =
new Product($this->db);
996 $product->fetch($fk_product);
998 $langs->load(
"errors");
999 if (!empty($product->status_batch) && empty($batch)) {
1000 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
1002 } elseif (empty($product->status_batch) && !empty($batch)) {
1003 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
1009 if (!empty($errorMsgArr)) {
1010 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
1011 $errorMessage .=
'<ul>';
1012 foreach ($errorMsgArr as $errorMsg) {
1013 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
1015 $errorMessage .=
'</ul>';
1016 $this->error = $errorMessage;
1023 $line->array_options = $supplierorderline->array_options;
1024 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1025 foreach ($array_options as $key => $value) {
1026 $line->array_options[$key] = $value;
1030 $line->fk_product = $fk_product;
1031 $line->fk_commande = $supplierorderline->fk_commande;
1032 $line->fk_user = $user->id;
1033 $line->comment = $comment;
1034 $line->batch = $batch;
1035 $line->eatby = $eatby;
1036 $line->sellby = $sellby;
1038 $line->cost_price = $cost_price;
1039 $line->fk_reception = $this->id;
1041 $this->lines[$num] = $line;
1062 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options = [], $cost_price = 0, $ref_fourn =
'', $fk_entrepot = 0, $batch =
'')
1064 global
$mysoc, $langs, $user;
1066 if ($this->
status == self::STATUS_DRAFT) {
1076 $ranktouse = $this->rang;
1077 if ($ranktouse == -1) {
1078 $rangmax = $this->
line_max($this->fk_reception);
1079 $ranktouse = $rangmax + 1;
1084 $this->line->fk_reception = $this->id;
1085 $this->line->element_type = $element_type;
1086 $this->line->fk_product = $fk_product;
1087 $this->line->description = $description;
1089 $this->line->qty = (float) $qty;
1090 $this->line->fk_unit = $fk_unit;
1091 $this->line->rang = $ranktouse;
1092 $this->line->cost_price = (float) $cost_price;
1093 $this->line->ref_fourn = trim((
string) $ref_fourn);
1094 if ((
int) $fk_entrepot > 0) {
1095 $this->line->fk_entrepot = (int) $fk_entrepot;
1097 if ((
string) $batch !==
'') {
1098 $this->line->batch = trim((
string) $batch);
1101 if (is_array($array_options) && count($array_options) > 0) {
1102 $this->line->array_options = $array_options;
1105 $result = $this->line->insert($user);
1107 if (!isset($this->context[
'createfromclone'])) {
1108 if ($this->fk_reception) {
1110 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1111 $linecount = count($this->lines);
1112 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1116 $this->lines[] = $this->line;
1119 $this->db->commit();
1120 return $this->line->id;
1122 $this->error = $this->line->error;
1123 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1124 $this->db->rollback();
1128 dol_syslog(get_class($this).
"::addlinefree status of reception must be Draft to allow use of ->addlinefree()", LOG_ERR);
1147 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options = array())
1149 global
$mysoc, $langs, $user;
1151 if ($this->statut == self::STATUS_DRAFT) {
1161 $qty = (float) $qty;
1162 $description = trim($description);
1167 $line->fetch($rowid);
1168 $line->fetch_optionals();
1170 if (!empty($line->fk_product)) {
1171 $product =
new Product($this->db);
1172 $result = $product->fetch($line->fk_product);
1173 $product_type = $product->type;
1176 $staticline = clone $line;
1178 $line->oldline = $staticline;
1179 $this->line = $line;
1180 $this->line->context = $this->context;
1181 $this->line->rang = $rang;
1182 $this->line->fk_reception = $this->id;
1183 $this->line->element_type = $element_type;
1184 $this->line->fk_product = $line->fk_product;
1185 $this->line->qty = $qty;
1186 $this->line->fk_unit = $fk_unit;
1187 $this->line->description = $description;
1189 if (is_array($array_options) && count($array_options) > 0) {
1191 foreach ($array_options as $key => $value) {
1192 $this->line->array_options[$key] = $array_options[$key];
1197 $result = $this->line->update($user, $notrigger);
1202 $this->db->commit();
1205 $this->error = $this->line->error;
1207 $this->db->rollback();
1211 $this->error = get_class($this).
"::updatelinefree reception status makes operation forbidden";
1212 $this->errors = array(
'ReceptionStatusMakeOperationForbidden');
1226 $this->lines = array();
1228 $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, rc.cost_price, rc.ref_fourn, rc.batch, rc.eatby, rc.sellby';
1229 $sql .=
' FROM '.MAIN_DB_PREFIX.
'receptiondet_batch as rc';
1230 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = rc.fk_product)';
1231 $sql .=
' WHERE rc.fk_reception = '.((int) $this->
id);
1233 $sql .=
' ORDER BY rc.rang, rc.rowid';
1235 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
1236 $result = $this->db->query($sql);
1238 $num = $this->db->num_rows($result);
1242 $objp = $this->db->fetch_object($result);
1246 $line->rowid = $objp->rowid;
1247 $line->id = $objp->rowid;
1248 $line->fk_reception = $this->id;
1250 $line->description = $objp->description;
1251 $line->qty = $objp->qty;
1252 $line->fk_entrepot = $objp->fk_entrepot;
1253 $line->cost_price = $objp->cost_price;
1254 $line->ref_fourn = $objp->ref_fourn;
1255 $line->batch = $objp->batch;
1256 $line->eatby = $objp->eatby;
1257 $line->sellby = $objp->sellby;
1258 $line->fk_product = $objp->fk_product;
1260 $line->rang = $objp->rang;
1263 $line->fk_element = $objp->fk_element;
1264 $line->fk_unit = $objp->fk_unit;
1265 $line->fk_elementdet = $objp->fk_elementdet;
1266 $line->fk_element_type = $objp->element_type;
1267 $line->fetch_optionals();
1269 $this->lines[$i] = $line;
1274 $this->db->free($result);
1278 $this->error = $this->db->error();
1300 public function update($user =
null, $notrigger = 0)
1307 if (isset($this->
ref)) {
1308 $this->
ref = trim($this->
ref);
1310 if (isset($this->entity)) {
1311 $this->entity = (int) $this->entity;
1313 if (isset($this->ref_supplier)) {
1314 $this->ref_supplier = trim($this->ref_supplier);
1316 if (isset($this->socid)) {
1317 $this->socid = (int) trim((
string) $this->socid);
1319 if (isset($this->fk_user_author)) {
1320 $this->fk_user_author = (int) $this->fk_user_author;
1322 if (isset($this->fk_user_valid)) {
1323 $this->fk_user_valid = (int) $this->fk_user_valid;
1325 if (isset($this->shipping_method_id)) {
1326 $this->shipping_method_id = (int) $this->shipping_method_id;
1328 if (isset($this->tracking_number)) {
1329 $this->tracking_number = trim($this->tracking_number);
1331 if (isset($this->statut)) {
1332 $this->statut = (int) $this->statut;
1334 if (isset($this->trueDepth)) {
1335 $this->trueDepth =
price2num($this->trueDepth);
1337 if (isset($this->trueWidth)) {
1338 $this->trueWidth =
price2num($this->trueWidth);
1340 if (isset($this->trueHeight)) {
1341 $this->trueHeight =
price2num($this->trueHeight);
1343 $this->size_units = (int) $this->size_units;
1345 if (isset($this->trueWeight)) {
1346 $this->weight =
price2num($this->trueWeight);
1348 $this->weight_units = (int) $this->weight_units;
1350 if (isset($this->note_private)) {
1351 $this->note_private = trim($this->note_private);
1353 if (isset($this->note_public)) {
1354 $this->note_public = trim($this->note_public);
1356 if (isset($this->model_pdf)) {
1357 $this->model_pdf = trim($this->model_pdf);
1365 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1367 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1368 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1369 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1370 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1371 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
1372 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1373 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1374 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1375 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1376 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? ((
int) $this->shipping_method_id) :
"null").
",";
1377 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1378 $sql .=
" fk_statut=".(isset($this->statut) ? ((int) $this->statut) :
"null").
",";
1379 $sql .=
" height=".(($this->trueHeight !=
'') ? (
float) $this->trueHeight :
"null").
",";
1380 $sql .=
" width=".(($this->trueWidth !=
'') ? (
float) $this->trueWidth :
"null").
",";
1381 $sql .=
" size_units=".((int) $this->size_units).
",";
1382 $sql .=
" size=".(($this->trueDepth !=
'') ? (
float) $this->trueDepth :
"null").
",";
1383 $sql .=
" weight_units=".((int) $this->weight_units).
",";
1384 $sql .=
" weight=".(($this->trueWeight !=
'') ? (
float) $this->trueWeight :
"null").
",";
1385 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1386 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1387 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1388 $sql .=
" fk_projet=".((isset($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1389 $sql .=
" entity = ".((int)
$conf->entity);
1390 $sql .=
" WHERE rowid=".((int) $this->
id);
1394 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1395 $resql = $this->db->query($sql);
1398 $this->errors[] =
"Error ".$this->db->lasterror();
1404 $result = $this->call_trigger(
'RECEPTION_MODIFY', $user);
1414 foreach ($this->errors as $errmsg) {
1415 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1416 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1418 $this->db->rollback();
1421 $this->db->commit();
1432 public function delete(
User $user)
1434 global
$conf, $langs, $user;
1435 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1445 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1447 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1449 $langs->load(
"agenda");
1452 $sql =
"SELECT COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) as fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1453 $sql .=
" FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1454 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd ON cd.rowid = ed.fk_elementdet";
1455 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1456 $sql .=
" AND COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) IS NOT NULL";
1457 $sql .=
" AND ed.fk_entrepot IS NOT NULL AND ed.fk_entrepot > 0";
1459 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1460 $resql = $this->db->query($sql);
1462 $cpt = $this->db->num_rows($resql);
1463 for ($i = 0; $i < $cpt; $i++) {
1464 dol_syslog(get_class($this).
"::delete movement index ".$i);
1465 $obj = $this->db->fetch_object($resql);
1469 $mouvS->origin =
null;
1471 $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);
1474 $this->error = $mouvS->error;
1475 $this->errors = $mouvS->errors;
1480 $this->errors[] =
"Error ".$this->db->lasterror();
1485 $sanitized_main = MAIN_DB_PREFIX.
'receptiondet_batch';
1486 $sanitized_ef = $sanitized_main.
"_extrafields";
1488 $sqlef =
"DELETE FROM ".$sanitized_ef.
" WHERE fk_object IN (SELECT rowid FROM ".$sanitized_main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1490 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1491 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1493 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1501 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1502 $sql .=
" WHERE rowid = ".((int) $this->
id);
1504 if ($this->db->query($sql)) {
1506 $result = $this->call_trigger(
'RECEPTION_DELETE', $user);
1512 if (!empty($this->origin) && $this->origin_id > 0) {
1515 '@phan-var-force CommandeFournisseur $origin_object';
1528 $this->db->commit();
1532 if (!empty(
$conf->reception->dir_output)) {
1533 $dir =
$conf->reception->dir_output.
'/'.$ref;
1534 $file = $dir.
'/'.$ref.
'.pdf';
1535 if (file_exists($file)) {
1540 if (file_exists($dir)) {
1542 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1550 $this->db->rollback();
1554 $this->error = $this->db->lasterror().
" - sql=$sql";
1555 $this->db->rollback();
1559 $this->error = $this->db->lasterror().
" - sql=$sql";
1560 $this->db->rollback();
1564 $this->error = $this->db->lasterror().
" - sql=$sql";
1565 $this->db->rollback();
1569 $this->db->rollback();
1583 $this->lines = array();
1585 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1587 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1588 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1590 $resql = $this->db->query($sql);
1592 if (!empty($resql)) {
1593 while ($obj = $this->db->fetch_object($resql)) {
1596 $line->fetch($obj->rowid);
1599 $line->fetch_product();
1601 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1602 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1603 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1604 $sql_commfourndet .=
' ORDER BY rang';
1606 $resql_commfourndet = $this->db->query($sql_commfourndet);
1607 if (!empty($resql_commfourndet)) {
1608 $obj = $this->db->fetch_object($resql_commfourndet);
1609 $line->qty_asked = $obj->qty;
1610 $line->description = $obj->description;
1611 $line->desc = $obj->description;
1612 $line->tva_tx = $obj->tva_tx;
1613 $line->vat_src_code = $obj->vat_src_code;
1614 $line->subprice = $obj->subprice;
1615 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1616 $line->remise_percent = $obj->remise_percent;
1617 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1618 $line->ref_supplier = $obj->ref;
1619 $line->total_ht = $obj->total_ht;
1620 $line->total_ttc = $obj->total_ttc;
1621 $line->total_tva = $obj->total_tva;
1623 $line->qty_asked = 0;
1624 $line->description =
'';
1626 $line->label = $obj->label;
1629 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1630 $tva = $pu_ht * $line->tva_tx / 100;
1631 $this->total_ht += $pu_ht;
1632 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1634 $this->total_ttc += $pu_ht + $tva;
1636 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1638 $detail_batch->eatby = $line->eatby;
1639 $detail_batch->sellby = $line->sellby;
1640 $detail_batch->batch = $line->batch;
1641 $detail_batch->qty = $line->qty;
1643 $line->detail_batch[] = $detail_batch;
1646 $this->lines[] = $line;
1665 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0)
1667 global $langs, $hookmanager;
1670 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1671 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1672 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1674 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1681 if (empty($notooltip)) {
1683 $label = $langs->trans(
"Reception");
1684 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1686 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1687 $linkclose .=
' class="classfortooltip"';
1690 $linkstart =
'<a href="'.$url.
'"';
1691 $linkstart .= $linkclose.
'>';
1694 $result .= $linkstart;
1696 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1698 if ($withpicto != 2) {
1699 $result .= $this->ref;
1702 $result .= $linkend;
1705 $hookmanager->initHooks(array($this->element .
'dao'));
1706 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1707 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1709 $result = $hookmanager->resPrint;
1711 $result .= $hookmanager->resPrint;
1724 return $this->
LibStatut($this->statut, $mode);
1741 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1742 $this->labelStatus[0] =
'StatusReceptionDraft';
1744 $this->labelStatus[1] =
'StatusReceptionValidated';
1746 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1749 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1751 $this->labelStatus[2] =
'StatusReceptionProcessed';
1754 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1755 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1756 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1757 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1759 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1760 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1762 $statusType =
'status'.$status;
1763 if ($status == self::STATUS_VALIDATED) {
1764 $statusType =
'status4';
1766 if ($status == self::STATUS_CLOSED) {
1767 $statusType =
'status6';
1770 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1782 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1784 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1785 $return .=
'<div class="info-box info-box-sm">';
1786 $return .=
'<div class="info-box-icon bg-infobox-action">';
1788 $return .=
'</div>';
1789 $return .=
'<div class="info-box-content">';
1790 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1791 if ($selected >= 0) {
1792 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1794 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1795 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1800 if (method_exists($this,
'getLibStatut')) {
1801 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1803 $return .=
'</div>';
1804 $return .=
'</div>';
1805 $return .=
'</div>';
1821 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1822 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1825 dol_syslog(get_class($this).
"::initAsSpecimen");
1828 $order->initAsSpecimen();
1832 $this->
ref =
'SPECIMEN';
1833 $this->specimen = 1;
1837 $this->date_creation = $now;
1838 $this->date_valid = $now;
1839 $this->date_delivery = $now;
1840 $this->date_reception = $now + 24 * 3600;
1841 $this->entrepot_id = 0;
1843 $this->origin_id = 1;
1844 $this->origin_type =
'supplier_order';
1845 $this->origin_object = $order;
1846 $this->note_private =
'Private note';
1847 $this->note_public =
'Public note';
1848 $this->tracking_number =
'TRACKID-ABC123';
1849 $this->fk_incoterms = 1;
1852 while ($xnbp < $nbp) {
1854 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1855 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1856 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1859 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1861 $this->lines[] = $line;
1878 if ($user->hasRight(
'reception',
'creer')) {
1879 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1880 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1881 $sql .=
" WHERE rowid = ".((int) $this->
id);
1883 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1884 $resql = $this->db->query($sql);
1886 $this->date_delivery = $delivery_date;
1889 $this->error = $this->db->error();
1906 if ($user->hasRight(
'reception',
'creer')) {
1907 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1908 $sql .=
" SET date_reception = ".($reception_date ?
"'".$this->db->idate($reception_date).
"'" :
'null');
1909 $sql .=
" WHERE rowid = ".((int) $this->
id);
1911 dol_syslog(get_class($this).
"::setReceptionDate", LOG_DEBUG);
1912 $resql = $this->db->query($sql);
1914 $this->date_reception = $reception_date;
1917 $this->error = $this->db->error();
1935 $this->meths = array();
1937 $sql =
"SELECT em.rowid, em.code, em.libelle";
1938 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1939 $sql .=
" WHERE em.active = 1";
1940 $sql .=
" ORDER BY em.libelle ASC";
1942 $resql = $this->db->query($sql);
1944 while ($obj = $this->db->fetch_object($resql)) {
1945 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1946 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1963 $this->listmeths = array();
1966 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1967 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1969 $sql .=
" WHERE em.rowid = ".((int) $id);
1972 $resql = $this->db->query($sql);
1974 while ($obj = $this->db->fetch_object($resql)) {
1975 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1976 $this->listmeths[$i][
'code'] = $obj->code;
1977 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1978 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1979 $this->listmeths[$i][
'description'] = $obj->description;
1980 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1981 $this->listmeths[$i][
'active'] = $obj->active;
1995 if (!empty($this->shipping_method_id)) {
1996 $sql =
"SELECT em.code, em.tracking";
1997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1998 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2000 $resql = $this->db->query($sql);
2002 if ($obj = $this->db->fetch_object($resql)) {
2003 $tracking = $obj->tracking;
2008 if (!empty($tracking) && !empty($value)) {
2009 $url = str_replace(
'{TRACKID}', $value, $tracking);
2010 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
2012 $this->tracking_url = $value;
2023 global
$conf, $langs, $user;
2028 if ($this->statut == Reception::STATUS_CLOSED) {
2029 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
2035 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
2036 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2038 $resql = $this->db->query($sql);
2041 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
2042 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2045 $order->fetch($this->origin_id);
2047 $order->loadReceptions(self::STATUS_CLOSED);
2049 $receptions_match_order = 1;
2050 foreach ($order->lines as $line) {
2051 $lineid = $line->id;
2053 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
2054 $receptions_match_order = 0;
2055 $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';
2060 if ($receptions_match_order) {
2061 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');
2062 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
2066 $this->statut = self::STATUS_CLOSED;
2067 $this->
status = self::STATUS_CLOSED;
2071 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2073 $langs->load(
"agenda");
2077 $sql =
"SELECT COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) as fk_product, cd.subprice,";
2078 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2079 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2080 $sql .=
" ed.fk_elementdet, ed.cost_price";
2081 $sql .=
" FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2082 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd ON cd.rowid = ed.fk_elementdet";
2083 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2084 $sql .=
" AND COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) IS NOT NULL";
2085 $sql .=
" AND ed.fk_entrepot IS NOT NULL AND ed.fk_entrepot > 0";
2087 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2088 $resql = $this->db->query($sql);
2091 $cpt = $this->db->num_rows($resql);
2092 for ($i = 0; $i < $cpt; $i++) {
2093 $obj = $this->db->fetch_object($resql);
2101 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
2104 $mouvS->origin = &$this;
2105 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2107 if (empty($obj->batch)) {
2111 $inventorycode =
'';
2112 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2114 $this->error = $mouvS->error;
2115 $this->errors = $mouvS->errors;
2123 $inventorycode =
'';
2124 $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);
2127 $this->error = $mouvS->error;
2128 $this->errors = $mouvS->errors;
2135 $this->error = $this->db->lasterror();
2142 $result = $this->call_trigger(
'RECEPTION_CLOSED', $user);
2153 $this->db->commit();
2156 $this->statut = self::STATUS_VALIDATED;
2157 $this->
status = self::STATUS_VALIDATED;
2158 $this->db->rollback();
2175 if ($this->statut == Reception::STATUS_VALIDATED) {
2180 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
2181 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2183 $resql = $this->db->query($sql);
2188 $result = $this->call_trigger(
'RECEPTION_BILLED', $user);
2195 $this->errors[] = $this->db->lasterror;
2198 if (empty($error)) {
2199 $this->db->commit();
2202 $this->db->rollback();
2214 global $langs, $user;
2220 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
2221 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2223 $resql = $this->db->query($sql);
2224 $rollbackStatus = $this->status;
2225 $rollbackBilled = $this->billed;
2227 $this->statut = self::STATUS_VALIDATED;
2228 $this->
status = self::STATUS_VALIDATED;
2233 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2235 $langs->load(
"agenda");
2239 $sql =
"SELECT COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) as fk_product, cd.subprice,";
2240 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2241 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2242 $sql .=
" ed.fk_elementdet, ed.cost_price";
2243 $sql .=
" FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2244 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd ON cd.rowid = ed.fk_elementdet";
2245 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2246 $sql .=
" AND COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) IS NOT NULL";
2247 $sql .=
" AND ed.fk_entrepot IS NOT NULL AND ed.fk_entrepot > 0";
2249 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2250 $resql = $this->db->query($sql);
2252 $cpt = $this->db->num_rows($resql);
2253 for ($i = 0; $i < $cpt; $i++) {
2254 $obj = $this->db->fetch_object($resql);
2261 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2265 $mouvS->origin = &$this;
2266 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2268 if (empty($obj->batch)) {
2272 $inventorycode =
'';
2273 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
2276 $this->error = $mouvS->error;
2277 $this->errors = $mouvS->errors;
2285 $inventorycode =
'';
2286 $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);
2288 $this->error = $mouvS->error;
2289 $this->errors = $mouvS->errors;
2296 $this->error = $this->db->lasterror();
2303 $result = $this->call_trigger(
'RECEPTION_REOPEN', $user);
2309 if (!$error && $this->origin ==
'order_supplier') {
2310 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2313 $commande->fetch($this->origin_id);
2314 $result = $commande->setStatus($user, 4);
2317 $this->error = $commande->error;
2318 $this->errors = $commande->errors;
2323 $this->errors[] = $this->db->lasterror();
2327 $this->db->commit();
2330 $this->statut = $this->
status = $rollbackStatus;
2331 $this->billed = $rollbackBilled;
2332 $this->db->rollback();
2351 if ($this->statut <= self::STATUS_DRAFT) {
2355 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2356 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2357 $this->error =
'Permission denied';
2363 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2364 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2365 $sql .=
" WHERE rowid = ".((int) $this->
id);
2368 if ($this->db->query($sql)) {
2371 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2373 $langs->load(
"agenda");
2377 $sql =
"SELECT COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) as fk_product, cd.subprice,";
2378 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2379 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2380 $sql .=
" ed.fk_elementdet, ed.cost_price";
2381 $sql .=
" FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2382 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd ON cd.rowid = ed.fk_elementdet";
2383 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2384 $sql .=
" AND COALESCE(NULLIF(ed.fk_product, 0), cd.fk_product) IS NOT NULL";
2385 $sql .=
" AND ed.fk_entrepot IS NOT NULL AND ed.fk_entrepot > 0";
2387 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2388 $resql = $this->db->query($sql);
2390 $cpt = $this->db->num_rows($resql);
2391 for ($i = 0; $i < $cpt; $i++) {
2392 $obj = $this->db->fetch_object($resql);
2400 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2404 $mouvS->origin = &$this;
2405 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2407 if (empty($obj->batch)) {
2411 $inventorycode =
'';
2412 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2414 $this->error = $mouvS->error;
2415 $this->errors = $mouvS->errors;
2423 $inventorycode =
'';
2424 $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);
2426 $this->error = $mouvS->error;
2427 $this->errors = $mouvS->errors;
2434 $this->error = $this->db->lasterror();
2441 $result = $this->call_trigger(
'RECEPTION_UNVALIDATE', $user);
2446 if ($this->origin ==
'order_supplier') {
2447 if (!empty($this->origin) && $this->origin_id > 0) {
2449 if ($this->origin_object->statut == 4) {
2451 $this->origin_object->fetchObjectLinked();
2453 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2454 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2455 if ($rcption->statut > 0) {
2462 $this->origin_object->setStatut(3);
2470 $this->statut = self::STATUS_DRAFT;
2471 $this->
status = self::STATUS_DRAFT;
2472 $this->db->commit();
2475 $this->db->rollback();
2479 $this->error = $this->db->error();
2480 $this->db->rollback();
2495 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2497 global
$conf, $langs;
2499 $langs->load(
"receptions");
2502 $modele =
'squille';
2504 if ($this->model_pdf) {
2505 $modele = $this->model_pdf;
2511 $modelpath =
"core/modules/reception/doc/";
2515 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2528 $tables = array(
'reception');
2544 '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.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options=array())
Update a simple reception line.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLinesArray()
Create an array of reception lines.
fetch_lines_free()
Load lines of simple reception.
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this records also the stock movement)
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0)
Return clickable link of object (with eventually picto)
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a reception line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
__construct($db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
setReceptionDate($user, $reception_date)
Set the reception date.
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options=[], $cost_price=0, $ref_fourn='', $fk_entrepot=0, $batch='')
Add a simple reception line.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
print $langs trans('Date')." left Ref 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 Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
$conf db user
Active Directory does not allow anonymous connections.