38require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
41if (isModEnabled(
"propal")) {
42 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
44if (isModEnabled(
'order')) {
45 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
64 public $element =
"reception";
69 public $fk_element =
"fk_reception";
70 public $table_element =
"reception";
71 public $table_element_line =
"receptiondet_batch";
76 public $picto =
'dollyrevert';
94 public $tracking_number;
115 public $weight_units;
131 public $height_units;
151 public $user_author_id;
156 public $date_delivery;
168 public $date_reception;
178 public $fk_user_author;
183 public $fk_user_valid;
197 public $lines = array();
204 public $detail_batch;
206 const STATUS_DRAFT = 0;
207 const STATUS_VALIDATED = 1;
208 const STATUS_CLOSED = 2;
220 $this->ismultientitymanaged = 1;
231 global $langs,
$conf;
232 $langs->load(
"receptions");
241 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
243 foreach ($dirmodels as $reldir) {
247 $mybool = ((bool) @include_once $dir.$file) || $mybool;
255 $obj =
new $classname();
256 '@phan-var-force ModelNumRefReception $obj';
258 $numref = $obj->getNextValue($soc, $this);
263 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
267 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
279 public function create($user, $notrigger = 0)
285 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
290 if (empty($this->fk_project)) {
291 $this->fk_project = 0;
293 if (empty($this->weight_units)) {
294 $this->weight_units = 0;
296 if (empty($this->size_units)) {
297 $this->size_units = 0;
304 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
307 $sql .=
", ref_supplier";
308 $sql .=
", date_creation";
309 $sql .=
", fk_user_author";
310 $sql .=
", date_reception";
311 $sql .=
", date_delivery";
313 $sql .=
", fk_projet";
314 $sql .=
", fk_shipping_method";
315 $sql .=
", tracking_number";
320 $sql .=
", weight_units";
321 $sql .=
", size_units";
322 $sql .=
", note_private";
323 $sql .=
", note_public";
324 $sql .=
", model_pdf";
325 $sql .=
", fk_incoterms, location_incoterms";
326 $sql .=
") VALUES (";
328 $sql .=
", ".((int)
$conf->entity);
329 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
330 $sql .=
", '".$this->db->idate($now).
"'";
331 $sql .=
", ".((int) $user->id);
332 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
333 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
334 $sql .=
", ".((int) $this->socid);
335 $sql .=
", ".((int) $this->fk_project);
336 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
337 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
338 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
339 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
340 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
341 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
342 $sql .=
", ".((int) $this->weight_units);
343 $sql .=
", ".((int) $this->size_units);
344 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
345 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
346 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
347 $sql .=
", ".(int) $this->fk_incoterms;
348 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
351 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
353 $resql = $this->db->query($sql);
356 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
358 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
359 $sql .=
" SET ref = '(PROV".((int) $this->
id).
")'";
360 $sql .=
" WHERE rowid = ".((int) $this->
id);
362 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
363 if ($this->db->query($sql)) {
365 $num = count($this->lines);
366 for ($i = 0; $i < $num; $i++) {
367 $this->lines[$i]->fk_reception = $this->id;
369 if (!$this->lines[$i]->
create($user) > 0) {
374 if (!$error && $this->
id && $this->origin_id) {
389 if (!$error && !$notrigger) {
391 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
402 foreach ($this->errors as $errmsg) {
403 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
404 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
406 $this->db->rollback();
411 $this->error = $this->db->lasterror().
" - sql=$sql";
412 $this->db->rollback();
417 $this->error = $this->db->error().
" - sql=$sql";
418 $this->db->rollback();
433 public function fetch($id, $ref =
'', $ref_ext =
'')
436 if (empty($id) && empty($ref) && empty($ref_ext)) {
440 $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";
441 $sql .=
", e.fk_user_valid";
442 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
443 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
444 $sql .=
", e.fk_shipping_method, e.tracking_number";
445 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
446 $sql .=
", e.note_private, e.note_public";
447 $sql .=
', e.fk_incoterms, e.location_incoterms';
448 $sql .=
', i.libelle as label_incoterms';
449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
450 $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'";
451 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
454 $sql .=
" WHERE e.rowid = ".((int) $id);
456 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
458 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
459 } elseif ($ref_ext) {
460 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
464 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
465 $result = $this->db->query($sql);
467 if ($this->db->num_rows($result)) {
468 $obj = $this->db->fetch_object($result);
470 $this->
id = $obj->rowid;
471 $this->entity = $obj->entity;
472 $this->
ref = $obj->ref;
473 $this->socid = $obj->socid;
474 $this->ref_supplier = $obj->ref_supplier;
475 $this->ref_ext = $obj->ref_ext;
476 $this->statut = $obj->status;
477 $this->
status = $obj->status;
478 $this->billed = $obj->billed;
480 $this->user_author_id = $obj->fk_user_author;
481 $this->fk_user_author = $obj->fk_user_author;
482 $this->fk_user_valid = $obj->fk_user_valid;
483 $this->date_valid = $this->db->jdate($obj->date_valid);
484 $this->date_creation = $this->db->jdate($obj->date_creation);
485 $this->date = $this->db->jdate($obj->date_reception);
486 $this->date_reception = $this->db->jdate($obj->date_reception);
487 $this->date_delivery = $this->db->jdate($obj->date_delivery);
488 $this->date_valid = $this->db->jdate($obj->date_valid);
489 $this->model_pdf = $obj->model_pdf;
490 $this->shipping_method_id = $obj->fk_shipping_method;
491 $this->tracking_number = $obj->tracking_number;
492 $this->origin = ($obj->origin ? $obj->origin :
'commande');
493 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
494 $this->origin_id = $obj->origin_id;
496 $this->trueWeight = $obj->weight;
497 $this->weight_units = $obj->weight_units;
499 $this->trueWidth = $obj->width;
500 $this->width_units = $obj->size_units;
501 $this->trueHeight = $obj->height;
502 $this->height_units = $obj->size_units;
503 $this->trueDepth = $obj->size;
504 $this->depth_units = $obj->size_units;
506 $this->note_public = $obj->note_public;
507 $this->note_private = $obj->note_private;
510 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
511 $this->size_units = $obj->size_units;
514 $this->fk_incoterms = $obj->fk_incoterms;
515 $this->location_incoterms = $obj->location_incoterms;
516 $this->label_incoterms = $obj->label_incoterms;
518 $this->db->free($result);
534 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
536 $extrafields->fetch_name_optionals_label($this->table_element,
true);
549 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
550 $this->error =
'Reception with id '.$id.
' not found';
554 $this->error = $this->db->error();
566 public function valid($user, $notrigger = 0)
568 global
$conf, $langs;
570 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
576 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
580 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
581 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
582 $this->error =
'Permission denied';
583 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
593 $soc->fetch($this->socid);
597 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
600 $numref = $this->ref;
608 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
609 $sql .=
" ref='".$this->db->escape($numref).
"'";
610 $sql .=
", fk_statut = 1";
611 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
612 $sql .=
", fk_user_valid = ".((int) $user->id);
613 $sql .=
" WHERE rowid = ".((int) $this->
id);
614 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
615 $resql = $this->db->query($sql);
617 $this->error = $this->db->lasterror();
622 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
623 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
625 $langs->load(
"agenda");
629 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
630 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
631 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
632 $sql .=
" ed.cost_price";
633 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
634 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
635 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
636 $sql .=
" AND cd.rowid = ed.fk_elementdet";
638 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
639 $resql = $this->db->query($sql);
641 $cpt = $this->db->num_rows($resql);
642 for ($i = 0; $i < $cpt; $i++) {
643 $obj = $this->db->fetch_object($resql);
647 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
651 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
655 $mouvS->origin = &$this;
656 $mouvS->setOrigin($this->element, $this->
id);
658 if (empty($obj->batch)) {
663 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
665 if (intval($result) < 0) {
676 $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);
678 if (intval($result) < 0) {
686 $this->db->rollback();
687 $this->error = $this->db->error();
700 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
703 $this->errors = array_merge($this->errors, $this->origin_object->errors);
706 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
714 if (!$error && !$notrigger) {
716 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
724 $this->oldref = $this->ref;
727 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
729 $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).
"'";
730 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
731 $resql = $this->db->query($sql);
734 $this->error = $this->db->lasterror();
736 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
737 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
738 $resql = $this->db->query($sql);
741 $this->error = $this->db->lasterror();
747 $dirsource =
$conf->reception->dir_output.
'/'.$oldref;
748 $dirdest =
$conf->reception->dir_output.
'/'.$newref;
749 if (!$error && file_exists($dirsource)) {
750 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
752 if (@rename($dirsource, $dirdest)) {
755 $listoffiles =
dol_dir_list(
$conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
756 foreach ($listoffiles as $fileentry) {
757 $dirsource = $fileentry[
'name'];
758 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
759 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
760 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
761 @rename($dirsource, $dirdest);
770 $this->
ref = $numref;
771 $this->statut = self::STATUS_VALIDATED;
772 $this->
status = self::STATUS_VALIDATED;
779 foreach ($this->errors as $errmsg) {
780 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
781 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
783 $this->db->rollback();
795 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
796 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
800 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
801 if (empty($this->origin_object)) {
803 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
804 $res = $this->origin_object->fetch_lines();
805 $this->commandeFournisseur =
null;
809 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
810 $res = $this->origin_object->fetch_lines();
818 $qty_received = array();
819 $qty_wished = array();
822 $filter = array(
't.fk_element' => $this->origin_id);
824 $filter[
't.status'] = 1;
827 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
833 $draft_lines = array();
834 $sql =
"SELECT rb.rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch as rb";
835 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"reception as r ON r.rowid = rb.fk_reception";
836 $sql .=
" WHERE rb.fk_element = ".((int) $this->origin_id);
837 $sql .=
" AND r.fk_statut = ".self::STATUS_DRAFT;
838 $resql = $this->db->query($sql);
840 $this->error = $this->db->lasterror();
843 while ($obj = $this->db->fetch_object($resql)) {
844 $draft_lines[(int) $obj->rowid] = (
int) $obj->rowid;
846 $this->db->free($resql);
849 foreach ($supplierorderdispatch->lines as $dispatch_line) {
850 if (isset($draft_lines[(
int) $dispatch_line->id])) {
853 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
854 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
856 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
861 foreach ($this->origin_object->lines as $origin_line) {
863 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
866 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
867 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
869 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
874 $diff_array = array_diff_assoc($qty_received, $qty_wished);
875 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
876 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
878 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
884 if (count($diff_array) > 0) {
887 foreach ($diff_array as $key => $value) {
889 if ($qty_received[$key] >= $qty_wished[$key]) {
895 if ($close == count($diff_array)) {
922 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
924 global
$conf, $langs, $user;
926 $num = count($this->lines);
929 $line->fk_entrepot = $entrepot_id;
930 $line->fk_commandefourndet = $id;
934 $result = $supplierorderline->fetch($id);
941 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
942 $fk_product = $supplierorderline->fk_product;
944 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
945 $langs->load(
"errors");
946 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
952 $product =
new Product($this->db);
953 $product->fetch($fk_product);
954 if (isModEnabled(
'productbatch')) {
955 $langs->load(
"errors");
956 if (!empty($product->status_batch) && empty($batch)) {
957 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
959 } elseif (empty($product->status_batch) && !empty($batch)) {
960 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
966 if (!empty($errorMsgArr)) {
967 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
968 $errorMessage .=
'<ul>';
969 foreach ($errorMsgArr as $errorMsg) {
970 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
972 $errorMessage .=
'</ul>';
973 $this->error = $errorMessage;
980 $line->array_options = $supplierorderline->array_options;
981 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
982 foreach ($array_options as $key => $value) {
983 $line->array_options[$key] = $value;
987 $line->fk_product = $fk_product;
988 $line->fk_commande = $supplierorderline->fk_commande;
989 $line->fk_user = $user->id;
990 $line->comment = $comment;
991 $line->batch = $batch;
992 $line->eatby = $eatby;
993 $line->sellby = $sellby;
995 $line->cost_price = $cost_price;
996 $line->fk_reception = $this->id;
998 $this->lines[$num] = $line;
1011 public function update($user =
null, $notrigger = 0)
1018 if (isset($this->
ref)) {
1019 $this->
ref = trim($this->
ref);
1021 if (isset($this->entity)) {
1022 $this->entity = (int) $this->entity;
1024 if (isset($this->ref_supplier)) {
1025 $this->ref_supplier = trim($this->ref_supplier);
1027 if (isset($this->socid)) {
1028 $this->socid = (int) trim((
string) $this->socid);
1030 if (isset($this->fk_user_author)) {
1031 $this->fk_user_author = (int) $this->fk_user_author;
1033 if (isset($this->fk_user_valid)) {
1034 $this->fk_user_valid = (int) $this->fk_user_valid;
1036 if (isset($this->shipping_method_id)) {
1037 $this->shipping_method_id = (int) $this->shipping_method_id;
1039 if (isset($this->tracking_number)) {
1040 $this->tracking_number = trim($this->tracking_number);
1042 if (isset($this->statut)) {
1043 $this->statut = (int) $this->statut;
1045 if (isset($this->trueDepth)) {
1046 $this->trueDepth =
price2num($this->trueDepth);
1048 if (isset($this->trueWidth)) {
1049 $this->trueWidth =
price2num($this->trueWidth);
1051 if (isset($this->trueHeight)) {
1052 $this->trueHeight =
price2num($this->trueHeight);
1054 $this->size_units = (int) $this->size_units;
1056 if (isset($this->trueWeight)) {
1057 $this->weight =
price2num($this->trueWeight);
1059 $this->weight_units = (int) $this->weight_units;
1061 if (isset($this->note_private)) {
1062 $this->note_private = trim($this->note_private);
1064 if (isset($this->note_public)) {
1065 $this->note_public = trim($this->note_public);
1067 if (isset($this->model_pdf)) {
1068 $this->model_pdf = trim($this->model_pdf);
1076 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1078 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1079 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1080 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1081 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1082 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1083 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1084 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1085 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1086 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1087 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1088 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1089 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1090 $sql .=
" height=".(($this->trueHeight !=
'') ? (
float) $this->trueHeight :
"null").
",";
1091 $sql .=
" width=".(($this->trueWidth !=
'') ? (
float) $this->trueWidth :
"null").
",";
1092 $sql .=
" size_units=".((int) $this->size_units).
",";
1093 $sql .=
" size=".(($this->trueDepth !=
'') ? (
float) $this->trueDepth :
"null").
",";
1094 $sql .=
" weight_units=".((int) $this->weight_units).
",";
1095 $sql .=
" weight=".(($this->trueWeight !=
'') ? (
float) $this->trueWeight :
"null").
",";
1096 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1097 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1098 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1099 $sql .=
" entity = ".((int)
$conf->entity);
1100 $sql .=
" WHERE rowid=".((int) $this->
id);
1104 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1105 $resql = $this->db->query($sql);
1108 $this->errors[] =
"Error ".$this->db->lasterror();
1114 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1124 foreach ($this->errors as $errmsg) {
1125 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1126 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1128 $this->db->rollback();
1131 $this->db->commit();
1144 global
$conf, $langs, $user;
1145 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1154 if (isModEnabled(
'stock') && ((
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') && $this->
status > Reception::STATUS_DRAFT)
1155 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1157 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1159 $langs->load(
"agenda");
1162 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1163 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1164 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1165 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1166 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1168 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1169 $resql = $this->db->query($sql);
1171 $cpt = $this->db->num_rows($resql);
1172 for ($i = 0; $i < $cpt; $i++) {
1173 dol_syslog(get_class($this).
"::delete movement index ".$i);
1174 $obj = $this->db->fetch_object($resql);
1177 if ($obj->qty == 0 || ($obj->qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
1183 $mouvS->origin =
null;
1185 $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);
1188 $this->error = $mouvS->error;
1189 $this->errors = $mouvS->errors;
1194 $this->errors[] =
"Error ".$this->db->lasterror();
1199 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1200 $ef = $main.
"_extrafields";
1202 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1204 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1205 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1207 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1215 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1216 $sql .=
" WHERE rowid = ".((int) $this->
id);
1218 if ($this->db->query($sql)) {
1220 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1226 if (!empty($this->origin) && $this->origin_id > 0) {
1229 '@phan-var-force CommandeFournisseur $origin_object';
1241 $this->db->commit();
1245 if (!empty(
$conf->reception->dir_output)) {
1246 $dir =
$conf->reception->dir_output.
'/'.$ref;
1247 $file = $dir.
'/'.$ref.
'.pdf';
1248 if (file_exists($file)) {
1253 if (file_exists($dir)) {
1255 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1263 $this->db->rollback();
1267 $this->error = $this->db->lasterror().
" - sql=$sql";
1268 $this->db->rollback();
1272 $this->error = $this->db->lasterror().
" - sql=$sql";
1273 $this->db->rollback();
1277 $this->error = $this->db->lasterror().
" - sql=$sql";
1278 $this->db->rollback();
1282 $this->db->rollback();
1296 $this->lines = array();
1298 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1300 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1301 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1303 $resql = $this->db->query($sql);
1305 if (!empty($resql)) {
1306 while ($obj = $this->db->fetch_object($resql)) {
1309 $line->fetch($obj->rowid);
1312 $line->fetch_product();
1314 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, localtax1_tx, localtax2_tx, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva, date_start, date_end, product_type';
1315 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1316 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1317 $sql_commfourndet .=
' ORDER BY rang';
1319 $resql_commfourndet = $this->db->query($sql_commfourndet);
1320 if (!empty($resql_commfourndet)) {
1321 $obj = $this->db->fetch_object($resql_commfourndet);
1322 $line->qty_asked = $obj->qty;
1323 $line->description = $obj->description;
1324 $line->desc = $obj->description;
1325 $line->tva_tx = $obj->tva_tx;
1326 $line->vat_src_code = $obj->vat_src_code;
1327 $line->localtax1_tx = $obj->localtax1_tx;
1328 $line->localtax2_tx = $obj->localtax2_tx;
1329 $line->subprice = $obj->subprice;
1330 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1331 $line->remise_percent = $obj->remise_percent;
1332 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1333 $line->ref_supplier = $obj->ref;
1334 $line->total_ht = $obj->total_ht;
1335 $line->total_ttc = $obj->total_ttc;
1336 $line->total_tva = $obj->total_tva;
1337 $line->date_start = $this->db->jdate($obj->date_start);
1338 $line->date_end = $this->db->jdate($obj->date_end);
1339 $line->product_type = $obj->product_type;
1341 $line->qty_asked = 0;
1342 $line->description =
'';
1344 $line->label = $obj->label;
1347 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1348 $tva = $pu_ht * $line->tva_tx / 100;
1349 $this->total_ht += $pu_ht;
1350 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1352 $this->total_ttc += $pu_ht + $tva;
1354 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1356 $detail_batch->eatby = $line->eatby;
1357 $detail_batch->sellby = $line->sellby;
1358 $detail_batch->batch = $line->batch;
1359 $detail_batch->qty = $line->qty;
1361 $line->detail_batch[] = $detail_batch;
1364 $this->lines[] = $line;
1383 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1385 global $langs, $hookmanager;
1388 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1389 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1390 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1392 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1399 if (empty($notooltip)) {
1401 $label = $langs->trans(
"Reception");
1402 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1404 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1405 $linkclose .=
' class="classfortooltip"';
1408 $linkstart =
'<a href="'.$url.
'"';
1409 $linkstart .= $linkclose.
'>';
1412 $result .= $linkstart;
1414 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1416 if ($withpicto != 2) {
1417 $result .= $this->ref;
1420 $result .= $linkend;
1423 $hookmanager->initHooks(array($this->element .
'dao'));
1424 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1425 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1427 $result = $hookmanager->resPrint;
1429 $result .= $hookmanager->resPrint;
1442 return $this->
LibStatut($this->statut, $mode);
1459 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1460 $this->labelStatus[0] =
'StatusReceptionDraft';
1462 $this->labelStatus[1] =
'StatusReceptionValidated';
1464 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1467 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1469 $this->labelStatus[2] =
'StatusReceptionProcessed';
1472 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1473 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1474 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1475 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1477 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1478 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1480 $statusType =
'status'.$status;
1481 if ($status == self::STATUS_VALIDATED) {
1482 $statusType =
'status4';
1484 if ($status == self::STATUS_CLOSED) {
1485 $statusType =
'status6';
1488 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1500 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1502 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1503 $return .=
'<div class="info-box info-box-sm">';
1504 $return .=
'<div class="info-box-icon bg-infobox-action">';
1506 $return .=
'</div>';
1507 $return .=
'<div class="info-box-content">';
1508 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1509 if ($selected >= 0) {
1510 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1512 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1513 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1518 if (method_exists($this,
'getLibStatut')) {
1519 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1521 $return .=
'</div>';
1522 $return .=
'</div>';
1523 $return .=
'</div>';
1539 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1540 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1543 dol_syslog(get_class($this).
"::initAsSpecimen");
1546 $order->initAsSpecimen();
1550 $this->
ref =
'SPECIMEN';
1551 $this->specimen = 1;
1555 $this->date_creation = $now;
1556 $this->date_valid = $now;
1557 $this->date_delivery = $now;
1558 $this->date_reception = $now + 24 * 3600;
1560 $this->entrepot_id = 0;
1563 $this->origin_id = 1;
1564 $this->origin_type =
'supplier_order';
1565 $this->origin_object = $order;
1567 $this->note_private =
'Private note';
1568 $this->note_public =
'Public note';
1570 $this->tracking_number =
'TRACKID-ABC123';
1572 $this->fk_incoterms = 1;
1576 while ($xnbp < $nbp) {
1578 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1579 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1580 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1583 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1585 $this->lines[] = $line;
1602 if ($user->hasRight(
'reception',
'creer')) {
1603 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1604 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1605 $sql .=
" WHERE rowid = ".((int) $this->
id);
1607 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1608 $resql = $this->db->query($sql);
1610 $this->date_delivery = $delivery_date;
1613 $this->error = $this->db->error();
1631 $this->meths = array();
1633 $sql =
"SELECT em.rowid, em.code, em.libelle";
1634 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1635 $sql .=
" WHERE em.active = 1";
1636 $sql .=
" ORDER BY em.libelle ASC";
1638 $resql = $this->db->query($sql);
1640 while ($obj = $this->db->fetch_object($resql)) {
1641 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1642 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1659 $this->listmeths = array();
1662 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1663 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1665 $sql .=
" WHERE em.rowid = ".((int) $id);
1668 $resql = $this->db->query($sql);
1670 while ($obj = $this->db->fetch_object($resql)) {
1671 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1672 $this->listmeths[$i][
'code'] = $obj->code;
1673 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1674 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1675 $this->listmeths[$i][
'description'] = $obj->description;
1676 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1677 $this->listmeths[$i][
'active'] = $obj->active;
1691 if (!empty($this->shipping_method_id)) {
1692 $sql =
"SELECT em.code, em.tracking";
1693 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1694 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1696 $resql = $this->db->query($sql);
1698 if ($obj = $this->db->fetch_object($resql)) {
1699 $tracking = $obj->tracking;
1704 if (!empty($tracking) && !empty($value)) {
1705 $url = str_replace(
'{TRACKID}', $value, $tracking);
1706 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1708 $this->tracking_url = $value;
1719 global
$conf, $langs, $user;
1724 if ($this->statut == Reception::STATUS_CLOSED) {
1725 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1729 if ($this->statut != Reception::STATUS_VALIDATED) {
1730 $langs->load(
"receptions");
1731 $this->error = $langs->trans(
'StatusOfRefMustBe', $this->
ref, $langs->transnoentitiesnoconv(
'StatusReceptionValidatedShort'));
1732 dol_syslog(get_class($this).
"::setClosed reception is not validated", LOG_WARNING);
1738 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1739 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut = '.self::STATUS_VALIDATED;
1741 $resql = $this->db->query($sql);
1742 if ($resql && $this->db->affected_rows($resql) <= 0) {
1744 $this->db->rollback();
1745 $langs->load(
"receptions");
1746 $this->error = $langs->trans(
'StatusOfRefMustBe', $this->
ref, $langs->transnoentitiesnoconv(
'StatusReceptionValidatedShort'));
1747 dol_syslog(get_class($this).
"::setClosed reception is not validated in database", LOG_WARNING);
1752 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1753 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1756 $order->fetch($this->origin_id);
1758 $order->loadReceptions(self::STATUS_CLOSED);
1760 $receptions_match_order = 1;
1761 foreach ($order->lines as $line) {
1762 $lineid = $line->id;
1764 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1765 $receptions_match_order = 0;
1766 $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';
1771 if ($receptions_match_order) {
1772 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');
1773 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1777 $this->statut = self::STATUS_CLOSED;
1778 $this->
status = self::STATUS_CLOSED;
1781 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1782 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1784 $langs->load(
"agenda");
1788 $sql =
"SELECT cd.fk_product, cd.subprice,";
1789 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1790 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1791 $sql .=
" ed.cost_price";
1792 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1793 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1794 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1795 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1797 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1798 $resql = $this->db->query($sql);
1801 $cpt = $this->db->num_rows($resql);
1802 for ($i = 0; $i < $cpt; $i++) {
1803 $obj = $this->db->fetch_object($resql);
1807 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
1811 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
1814 $mouvS->origin = &$this;
1815 $mouvS->setOrigin($this->element, $this->
id);
1817 if (empty($obj->batch)) {
1821 $inventorycode =
'';
1822 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1824 $this->error = $mouvS->error;
1825 $this->errors = $mouvS->errors;
1833 $inventorycode =
'';
1834 $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);
1837 $this->error = $mouvS->error;
1838 $this->errors = $mouvS->errors;
1845 $this->error = $this->db->lasterror();
1852 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1863 $this->db->commit();
1866 $this->statut = self::STATUS_VALIDATED;
1867 $this->
status = self::STATUS_VALIDATED;
1868 $this->db->rollback();
1885 if ($this->statut == Reception::STATUS_VALIDATED) {
1890 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1891 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1893 $resql = $this->db->query($sql);
1898 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1905 $this->errors[] = $this->db->lasterror;
1908 if (empty($error)) {
1909 $this->db->commit();
1912 $this->db->rollback();
1924 global
$conf, $langs, $user;
1929 if ($this->statut != self::STATUS_CLOSED) {
1930 $langs->load(
"receptions");
1931 $this->error = $langs->trans(
'StatusOfRefMustBe', $this->
ref, $langs->transnoentitiesnoconv(
'StatusReceptionProcessedShort'));
1937 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1938 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut = '.self::STATUS_CLOSED;
1940 $resql = $this->db->query($sql);
1942 if ($this->db->affected_rows($resql) <= 0) {
1944 $this->db->rollback();
1945 $langs->load(
"receptions");
1946 $this->error = $langs->trans(
'StatusOfRefMustBe', $this->
ref, $langs->transnoentitiesnoconv(
'StatusReceptionProcessedShort'));
1949 $this->statut = self::STATUS_VALIDATED;
1950 $this->
status = self::STATUS_VALIDATED;
1954 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1955 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1956 $numref = $this->ref;
1957 $langs->load(
"agenda");
1961 $sql =
"SELECT ed.fk_product, cd.subprice,";
1962 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1963 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1964 $sql .=
" ed.cost_price";
1965 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1966 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1967 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1968 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1970 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1971 $resql = $this->db->query($sql);
1973 $cpt = $this->db->num_rows($resql);
1974 for ($i = 0; $i < $cpt; $i++) {
1975 $obj = $this->db->fetch_object($resql);
1979 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
1982 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1986 $mouvS->origin = &$this;
1987 $mouvS->setOrigin($this->element, $this->
id);
1989 if (empty($obj->batch)) {
1993 $inventorycode =
'';
1994 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1997 $this->error = $mouvS->error;
1998 $this->errors = $mouvS->errors;
2006 $inventorycode =
'';
2007 $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, 0, $inventorycode);
2009 $this->error = $mouvS->error;
2010 $this->errors = $mouvS->errors;
2017 $this->error = $this->db->lasterror();
2024 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
2030 if (!$error && $this->origin ==
'order_supplier') {
2031 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2034 $commande->fetch($this->origin_id);
2035 $result = $commande->setStatus($user, 4);
2038 $this->error = $commande->error;
2039 $this->errors = $commande->errors;
2044 $this->errors[] = $this->db->lasterror();
2048 $this->db->commit();
2051 $this->db->rollback();
2065 global
$conf, $langs;
2070 if ($this->statut <= self::STATUS_DRAFT) {
2074 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2075 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2076 $this->error =
'Permission denied';
2082 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2083 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2084 $sql .=
" WHERE rowid = ".((int) $this->
id);
2085 $sql .=
" AND fk_statut = ".((int) $this->statut);
2088 $resql = $this->db->query($sql);
2089 if ($resql && $this->db->affected_rows($resql) <= 0) {
2091 $this->db->rollback();
2092 $langs->load(
"receptions");
2093 $this->error = $langs->trans(
'StatusOfRefMustBe', $this->
ref, $langs->transnoentitiesnoconv($this->statut == self::STATUS_CLOSED ?
'StatusReceptionProcessedShort' :
'StatusReceptionValidatedShort'));
2098 if (!$error && isModEnabled(
'stock') && (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->statut == self::STATUS_CLOSED))) {
2099 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2101 $langs->load(
"agenda");
2105 $sql =
"SELECT cd.fk_product, cd.subprice,";
2106 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2107 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2108 $sql .=
" ed.cost_price";
2109 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2110 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2111 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2112 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2114 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2115 $resql = $this->db->query($sql);
2117 $cpt = $this->db->num_rows($resql);
2118 for ($i = 0; $i < $cpt; $i++) {
2119 $obj = $this->db->fetch_object($resql);
2123 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2127 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2131 $mouvS->origin = &$this;
2132 $mouvS->setOrigin($this->element, $this->
id);
2134 if (empty($obj->batch)) {
2138 $inventorycode =
'';
2139 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2141 $this->error = $mouvS->error;
2142 $this->errors = $mouvS->errors;
2150 $inventorycode =
'';
2151 $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);
2153 $this->error = $mouvS->error;
2154 $this->errors = $mouvS->errors;
2161 $this->error = $this->db->lasterror();
2168 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
2173 if ($this->origin ==
'order_supplier') {
2174 if (!empty($this->origin) && $this->origin_id > 0) {
2176 if ($this->origin_object->statut == 4) {
2178 $this->origin_object->fetchObjectLinked();
2180 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2181 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2182 if ($rcption->statut > 0) {
2189 $this->origin_object->setStatut(3);
2197 $this->statut = self::STATUS_DRAFT;
2198 $this->
status = self::STATUS_DRAFT;
2199 $this->db->commit();
2202 $this->db->rollback();
2206 $this->error = $this->db->error();
2207 $this->db->rollback();
2222 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2224 global
$conf, $langs;
2226 $langs->load(
"receptions");
2229 $modele =
'squille';
2231 if ($this->model_pdf) {
2232 $modele = $this->model_pdf;
2238 $modelpath =
"core/modules/reception/doc/";
2242 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2255 $tables = array(
'reception');
2271 '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.
setErrorsFromObject($object)
setErrorsFromObject
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_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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db user
Active Directory does not allow anonymous connections.