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;
187 public $lines = array();
194 public $detail_batch;
196 const STATUS_DRAFT = 0;
197 const STATUS_VALIDATED = 1;
198 const STATUS_CLOSED = 2;
210 $this->ismultientitymanaged = 1;
221 global $langs,
$conf;
222 $langs->load(
"receptions");
231 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
233 foreach ($dirmodels as $reldir) {
237 $mybool = ((bool) @include_once $dir.$file) || $mybool;
245 $obj =
new $classname();
246 '@phan-var-force ModelNumRefReception $obj';
248 $numref = $obj->getNextValue($soc, $this);
253 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
257 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
269 public function create($user, $notrigger = 0)
275 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
280 if (empty($this->fk_project)) {
281 $this->fk_project = 0;
283 if (empty($this->weight_units)) {
284 $this->weight_units = 0;
286 if (empty($this->size_units)) {
287 $this->size_units = 0;
294 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
297 $sql .=
", ref_supplier";
298 $sql .=
", date_creation";
299 $sql .=
", fk_user_author";
300 $sql .=
", date_reception";
301 $sql .=
", date_delivery";
303 $sql .=
", fk_projet";
304 $sql .=
", fk_shipping_method";
305 $sql .=
", tracking_number";
310 $sql .=
", weight_units";
311 $sql .=
", size_units";
312 $sql .=
", note_private";
313 $sql .=
", note_public";
314 $sql .=
", model_pdf";
315 $sql .=
", fk_incoterms, location_incoterms";
316 $sql .=
") VALUES (";
318 $sql .=
", ".((int)
$conf->entity);
319 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
320 $sql .=
", '".$this->db->idate($now).
"'";
321 $sql .=
", ".((int) $user->id);
322 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
323 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
324 $sql .=
", ".((int) $this->socid);
325 $sql .=
", ".((int) $this->fk_project);
326 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
327 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
328 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
329 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
330 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
331 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
332 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((float) $this->weight_units));
333 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((float) $this->size_units));
334 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
335 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
336 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
337 $sql .=
", ".(int) $this->fk_incoterms;
338 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
341 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
343 $resql = $this->db->query($sql);
346 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
348 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
349 $sql .=
" SET ref = '(PROV".((int) $this->
id).
")'";
350 $sql .=
" WHERE rowid = ".((int) $this->
id);
352 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
353 if ($this->db->query($sql)) {
355 $num = count($this->lines);
356 for ($i = 0; $i < $num; $i++) {
357 $this->lines[$i]->fk_reception = $this->id;
359 if (!$this->lines[$i]->
create($user) > 0) {
364 if (!$error && $this->
id && $this->origin_id) {
379 if (!$error && !$notrigger) {
381 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
392 foreach ($this->errors as $errmsg) {
393 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
394 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
396 $this->db->rollback();
401 $this->error = $this->db->lasterror().
" - sql=$sql";
402 $this->db->rollback();
407 $this->error = $this->db->error().
" - sql=$sql";
408 $this->db->rollback();
423 public function fetch($id, $ref =
'', $ref_ext =
'')
426 if (empty($id) && empty($ref) && empty($ref_ext)) {
430 $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";
431 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
432 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
433 $sql .=
", e.fk_shipping_method, e.tracking_number";
434 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
435 $sql .=
", e.note_private, e.note_public";
436 $sql .=
', e.fk_incoterms, e.location_incoterms';
437 $sql .=
', i.libelle as label_incoterms';
438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
439 $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'";
440 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
443 $sql .=
" WHERE e.rowid = ".((int) $id);
445 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
447 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
448 } elseif ($ref_ext) {
449 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
453 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
454 $result = $this->db->query($sql);
456 if ($this->db->num_rows($result)) {
457 $obj = $this->db->fetch_object($result);
459 $this->
id = $obj->rowid;
460 $this->entity = $obj->entity;
461 $this->
ref = $obj->ref;
462 $this->socid = $obj->socid;
463 $this->ref_supplier = $obj->ref_supplier;
464 $this->ref_ext = $obj->ref_ext;
465 $this->statut = $obj->status;
466 $this->
status = $obj->status;
467 $this->billed = $obj->billed;
469 $this->user_author_id = $obj->fk_user_author;
470 $this->date_creation = $this->db->jdate($obj->date_creation);
471 $this->date = $this->db->jdate($obj->date_reception);
472 $this->date_reception = $this->db->jdate($obj->date_reception);
473 $this->date_delivery = $this->db->jdate($obj->date_delivery);
474 $this->date_valid = $this->db->jdate($obj->date_valid);
475 $this->model_pdf = $obj->model_pdf;
476 $this->shipping_method_id = $obj->fk_shipping_method;
477 $this->tracking_number = $obj->tracking_number;
478 $this->origin = ($obj->origin ? $obj->origin :
'commande');
479 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
480 $this->origin_id = $obj->origin_id;
482 $this->trueWeight = $obj->weight;
483 $this->weight_units = $obj->weight_units;
485 $this->trueWidth = $obj->width;
486 $this->width_units = $obj->size_units;
487 $this->trueHeight = $obj->height;
488 $this->height_units = $obj->size_units;
489 $this->trueDepth = $obj->size;
490 $this->depth_units = $obj->size_units;
492 $this->note_public = $obj->note_public;
493 $this->note_private = $obj->note_private;
496 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
497 $this->size_units = $obj->size_units;
500 $this->fk_incoterms = $obj->fk_incoterms;
501 $this->location_incoterms = $obj->location_incoterms;
502 $this->label_incoterms = $obj->label_incoterms;
504 $this->db->free($result);
520 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
522 $extrafields->fetch_name_optionals_label($this->table_element,
true);
535 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
536 $this->error =
'Reception with id '.$id.
' not found';
540 $this->error = $this->db->error();
552 public function valid($user, $notrigger = 0)
554 global
$conf, $langs;
556 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
562 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
566 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
567 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
568 $this->error =
'Permission denied';
569 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
579 $soc->fetch($this->socid);
583 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
586 $numref = $this->ref;
594 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
595 $sql .=
" ref='".$this->db->escape($numref).
"'";
596 $sql .=
", fk_statut = 1";
597 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
598 $sql .=
", fk_user_valid = ".((int) $user->id);
599 $sql .=
" WHERE rowid = ".((int) $this->
id);
600 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
601 $resql = $this->db->query($sql);
603 $this->error = $this->db->lasterror();
608 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
609 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
611 $langs->load(
"agenda");
615 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
616 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
617 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
618 $sql .=
" ed.cost_price";
619 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
620 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
621 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
622 $sql .=
" AND cd.rowid = ed.fk_elementdet";
624 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
625 $resql = $this->db->query($sql);
627 $cpt = $this->db->num_rows($resql);
628 for ($i = 0; $i < $cpt; $i++) {
629 $obj = $this->db->fetch_object($resql);
633 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
637 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
641 $mouvS->origin = &$this;
642 $mouvS->setOrigin($this->element, $this->
id);
644 if (empty($obj->batch)) {
649 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
651 if (intval($result) < 0) {
662 $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);
664 if (intval($result) < 0) {
672 $this->db->rollback();
673 $this->error = $this->db->error();
686 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
689 $this->errors = array_merge($this->errors, $this->origin_object->errors);
692 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
700 if (!$error && !$notrigger) {
702 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
710 $this->oldref = $this->ref;
713 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
715 $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).
"'";
716 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
717 $resql = $this->db->query($sql);
720 $this->error = $this->db->lasterror();
722 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
723 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
724 $resql = $this->db->query($sql);
727 $this->error = $this->db->lasterror();
733 $dirsource =
$conf->reception->dir_output.
'/'.$oldref;
734 $dirdest =
$conf->reception->dir_output.
'/'.$newref;
735 if (!$error && file_exists($dirsource)) {
736 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
738 if (@rename($dirsource, $dirdest)) {
741 $listoffiles =
dol_dir_list(
$conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
742 foreach ($listoffiles as $fileentry) {
743 $dirsource = $fileentry[
'name'];
744 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
745 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
746 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
747 @rename($dirsource, $dirdest);
756 $this->
ref = $numref;
757 $this->statut = self::STATUS_VALIDATED;
758 $this->
status = self::STATUS_VALIDATED;
765 foreach ($this->errors as $errmsg) {
766 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
767 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
769 $this->db->rollback();
781 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
782 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
786 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
787 if (empty($this->origin_object)) {
789 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
790 $res = $this->origin_object->fetch_lines();
791 $this->commandeFournisseur =
null;
795 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
796 $res = $this->origin_object->fetch_lines();
804 $qty_received = array();
805 $qty_wished = array();
808 $filter = array(
't.fk_element' => $this->origin_id);
810 $filter[
't.status'] = 1;
813 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
819 foreach ($supplierorderdispatch->lines as $dispatch_line) {
820 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
821 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
823 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
828 foreach ($this->origin_object->lines as $origin_line) {
830 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
833 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
834 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
836 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
841 $diff_array = array_diff_assoc($qty_received, $qty_wished);
842 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
843 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
845 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
851 if (count($diff_array) > 0) {
854 foreach ($diff_array as $key => $value) {
856 if ($qty_received[$key] >= $qty_wished[$key]) {
862 if ($close == count($diff_array)) {
889 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
891 global
$conf, $langs, $user;
893 $num = count($this->lines);
896 $line->fk_entrepot = $entrepot_id;
897 $line->fk_commandefourndet = $id;
901 $result = $supplierorderline->fetch($id);
908 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
909 $fk_product = $supplierorderline->fk_product;
911 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
912 $langs->load(
"errors");
913 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
919 $product =
new Product($this->db);
920 $product->fetch($fk_product);
921 if (isModEnabled(
'productbatch')) {
922 $langs->load(
"errors");
923 if (!empty($product->status_batch) && empty($batch)) {
924 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
926 } elseif (empty($product->status_batch) && !empty($batch)) {
927 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
933 if (!empty($errorMsgArr)) {
934 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
935 $errorMessage .=
'<ul>';
936 foreach ($errorMsgArr as $errorMsg) {
937 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
939 $errorMessage .=
'</ul>';
940 $this->error = $errorMessage;
947 $line->array_options = $supplierorderline->array_options;
948 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
949 foreach ($array_options as $key => $value) {
950 $line->array_options[$key] = $value;
954 $line->fk_product = $fk_product;
955 $line->fk_commande = $supplierorderline->fk_commande;
956 $line->fk_user = $user->id;
957 $line->comment = $comment;
958 $line->batch = $batch;
959 $line->eatby = $eatby;
960 $line->sellby = $sellby;
962 $line->cost_price = $cost_price;
963 $line->fk_reception = $this->id;
965 $this->lines[$num] = $line;
978 public function update($user =
null, $notrigger = 0)
985 if (isset($this->
ref)) {
986 $this->
ref = trim($this->
ref);
988 if (isset($this->entity)) {
989 $this->entity = (int) $this->entity;
991 if (isset($this->ref_supplier)) {
992 $this->ref_supplier = trim($this->ref_supplier);
994 if (isset($this->socid)) {
995 $this->socid = (int) trim((
string) $this->socid);
997 if (isset($this->fk_user_author)) {
998 $this->fk_user_author = (int) $this->fk_user_author;
1000 if (isset($this->fk_user_valid)) {
1001 $this->fk_user_valid = (int) $this->fk_user_valid;
1003 if (isset($this->shipping_method_id)) {
1004 $this->shipping_method_id = (int) $this->shipping_method_id;
1006 if (isset($this->tracking_number)) {
1007 $this->tracking_number = trim($this->tracking_number);
1009 if (isset($this->statut)) {
1010 $this->statut = (int) $this->statut;
1012 if (isset($this->trueDepth)) {
1013 $this->trueDepth = (float) trim((
string) $this->trueDepth);
1015 if (isset($this->trueWidth)) {
1016 $this->trueWidth = (float) trim((
string) $this->trueWidth);
1018 if (isset($this->trueHeight)) {
1019 $this->trueHeight = (float) trim((
string) $this->trueHeight);
1021 if (isset($this->size_units)) {
1022 $this->size_units = trim((
string) $this->size_units);
1024 if (isset($this->weight_units)) {
1025 $this->weight_units = (float) trim((
string) $this->weight_units);
1027 if (isset($this->trueWeight)) {
1028 $this->weight = (float) trim((
string) $this->trueWeight);
1030 if (isset($this->note_private)) {
1031 $this->note_private = trim($this->note_private);
1033 if (isset($this->note_public)) {
1034 $this->note_public = trim($this->note_public);
1036 if (isset($this->model_pdf)) {
1037 $this->model_pdf = trim($this->model_pdf);
1045 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1047 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1048 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1049 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1050 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1051 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1052 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1053 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1054 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1055 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1056 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1057 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1058 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1059 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1060 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1061 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1062 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1063 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1064 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1065 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1066 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1067 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1068 $sql .=
" entity = ".((int)
$conf->entity);
1069 $sql .=
" WHERE rowid=".((int) $this->
id);
1073 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1074 $resql = $this->db->query($sql);
1077 $this->errors[] =
"Error ".$this->db->lasterror();
1083 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1093 foreach ($this->errors as $errmsg) {
1094 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1095 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1097 $this->db->rollback();
1100 $this->db->commit();
1113 global
$conf, $langs, $user;
1114 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1123 if (isModEnabled(
'stock') && ((
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') && $this->
status > Reception::STATUS_DRAFT)
1124 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1126 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1128 $langs->load(
"agenda");
1131 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1133 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1134 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1135 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1137 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1138 $resql = $this->db->query($sql);
1140 $cpt = $this->db->num_rows($resql);
1141 for ($i = 0; $i < $cpt; $i++) {
1142 dol_syslog(get_class($this).
"::delete movement index ".$i);
1143 $obj = $this->db->fetch_object($resql);
1147 $mouvS->origin =
null;
1149 $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);
1152 $this->error = $mouvS->error;
1153 $this->errors = $mouvS->errors;
1158 $this->errors[] =
"Error ".$this->db->lasterror();
1163 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1164 $ef = $main.
"_extrafields";
1166 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1168 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1169 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1171 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1179 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1180 $sql .=
" WHERE rowid = ".((int) $this->
id);
1182 if ($this->db->query($sql)) {
1184 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1190 if (!empty($this->origin) && $this->origin_id > 0) {
1193 '@phan-var-force CommandeFournisseur $origin_object';
1205 $this->db->commit();
1209 if (!empty(
$conf->reception->dir_output)) {
1210 $dir =
$conf->reception->dir_output.
'/'.$ref;
1211 $file = $dir.
'/'.$ref.
'.pdf';
1212 if (file_exists($file)) {
1217 if (file_exists($dir)) {
1219 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1227 $this->db->rollback();
1231 $this->error = $this->db->lasterror().
" - sql=$sql";
1232 $this->db->rollback();
1236 $this->error = $this->db->lasterror().
" - sql=$sql";
1237 $this->db->rollback();
1241 $this->error = $this->db->lasterror().
" - sql=$sql";
1242 $this->db->rollback();
1246 $this->db->rollback();
1260 $this->lines = array();
1262 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1264 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1265 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1267 $resql = $this->db->query($sql);
1269 if (!empty($resql)) {
1270 while ($obj = $this->db->fetch_object($resql)) {
1273 $line->fetch($obj->rowid);
1276 $line->fetch_product();
1278 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1279 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1280 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1281 $sql_commfourndet .=
' ORDER BY rang';
1283 $resql_commfourndet = $this->db->query($sql_commfourndet);
1284 if (!empty($resql_commfourndet)) {
1285 $obj = $this->db->fetch_object($resql_commfourndet);
1286 $line->qty_asked = $obj->qty;
1287 $line->description = $obj->description;
1288 $line->desc = $obj->description;
1289 $line->tva_tx = $obj->tva_tx;
1290 $line->vat_src_code = $obj->vat_src_code;
1291 $line->subprice = $obj->subprice;
1292 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1293 $line->remise_percent = $obj->remise_percent;
1294 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1295 $line->ref_supplier = $obj->ref;
1296 $line->total_ht = $obj->total_ht;
1297 $line->total_ttc = $obj->total_ttc;
1298 $line->total_tva = $obj->total_tva;
1300 $line->qty_asked = 0;
1301 $line->description =
'';
1303 $line->label = $obj->label;
1306 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1307 $tva = $pu_ht * $line->tva_tx / 100;
1308 $this->total_ht += $pu_ht;
1309 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1311 $this->total_ttc += $pu_ht + $tva;
1313 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1315 $detail_batch->eatby = $line->eatby;
1316 $detail_batch->sellby = $line->sellby;
1317 $detail_batch->batch = $line->batch;
1318 $detail_batch->qty = $line->qty;
1320 $line->detail_batch[] = $detail_batch;
1323 $this->lines[] = $line;
1342 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1344 global $langs, $hookmanager;
1347 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1348 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1349 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1351 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1358 if (empty($notooltip)) {
1360 $label = $langs->trans(
"Reception");
1361 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1363 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1364 $linkclose .=
' class="classfortooltip"';
1367 $linkstart =
'<a href="'.$url.
'"';
1368 $linkstart .= $linkclose.
'>';
1371 $result .= $linkstart;
1373 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1375 if ($withpicto != 2) {
1376 $result .= $this->ref;
1379 $result .= $linkend;
1382 $hookmanager->initHooks(array($this->element .
'dao'));
1383 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1384 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1386 $result = $hookmanager->resPrint;
1388 $result .= $hookmanager->resPrint;
1401 return $this->
LibStatut($this->statut, $mode);
1418 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1419 $this->labelStatus[0] =
'StatusReceptionDraft';
1421 $this->labelStatus[1] =
'StatusReceptionValidated';
1423 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1426 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1428 $this->labelStatus[2] =
'StatusReceptionProcessed';
1431 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1432 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1433 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1434 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1436 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1437 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1439 $statusType =
'status'.$status;
1440 if ($status == self::STATUS_VALIDATED) {
1441 $statusType =
'status4';
1443 if ($status == self::STATUS_CLOSED) {
1444 $statusType =
'status6';
1447 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1459 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1461 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1462 $return .=
'<div class="info-box info-box-sm">';
1463 $return .=
'<div class="info-box-icon bg-infobox-action">';
1465 $return .=
'</div>';
1466 $return .=
'<div class="info-box-content">';
1467 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1468 if ($selected >= 0) {
1469 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1471 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1472 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1477 if (method_exists($this,
'getLibStatut')) {
1478 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1480 $return .=
'</div>';
1481 $return .=
'</div>';
1482 $return .=
'</div>';
1498 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1499 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1502 dol_syslog(get_class($this).
"::initAsSpecimen");
1505 $order->initAsSpecimen();
1509 $this->
ref =
'SPECIMEN';
1510 $this->specimen = 1;
1514 $this->date_creation = $now;
1515 $this->date_valid = $now;
1516 $this->date_delivery = $now;
1517 $this->date_reception = $now + 24 * 3600;
1519 $this->entrepot_id = 0;
1522 $this->origin_id = 1;
1523 $this->origin_type =
'supplier_order';
1524 $this->origin_object = $order;
1526 $this->note_private =
'Private note';
1527 $this->note_public =
'Public note';
1529 $this->tracking_number =
'TRACKID-ABC123';
1531 $this->fk_incoterms = 1;
1535 while ($xnbp < $nbp) {
1537 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1538 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1539 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1542 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1544 $this->lines[] = $line;
1561 if ($user->hasRight(
'reception',
'creer')) {
1562 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1563 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1564 $sql .=
" WHERE rowid = ".((int) $this->
id);
1566 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1567 $resql = $this->db->query($sql);
1569 $this->date_delivery = $delivery_date;
1572 $this->error = $this->db->error();
1590 $this->meths = array();
1592 $sql =
"SELECT em.rowid, em.code, em.libelle";
1593 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1594 $sql .=
" WHERE em.active = 1";
1595 $sql .=
" ORDER BY em.libelle ASC";
1597 $resql = $this->db->query($sql);
1599 while ($obj = $this->db->fetch_object($resql)) {
1600 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1601 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1618 $this->listmeths = array();
1621 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1622 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1624 $sql .=
" WHERE em.rowid = ".((int) $id);
1627 $resql = $this->db->query($sql);
1629 while ($obj = $this->db->fetch_object($resql)) {
1630 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1631 $this->listmeths[$i][
'code'] = $obj->code;
1632 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1633 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1634 $this->listmeths[$i][
'description'] = $obj->description;
1635 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1636 $this->listmeths[$i][
'active'] = $obj->active;
1650 if (!empty($this->shipping_method_id)) {
1651 $sql =
"SELECT em.code, em.tracking";
1652 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1653 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1655 $resql = $this->db->query($sql);
1657 if ($obj = $this->db->fetch_object($resql)) {
1658 $tracking = $obj->tracking;
1663 if (!empty($tracking) && !empty($value)) {
1664 $url = str_replace(
'{TRACKID}', $value, $tracking);
1665 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1667 $this->tracking_url = $value;
1678 global
$conf, $langs, $user;
1683 if ($this->statut == Reception::STATUS_CLOSED) {
1684 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1690 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1691 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1693 $resql = $this->db->query($sql);
1696 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1697 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1700 $order->fetch($this->origin_id);
1702 $order->loadReceptions(self::STATUS_CLOSED);
1704 $receptions_match_order = 1;
1705 foreach ($order->lines as $line) {
1706 $lineid = $line->id;
1708 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1709 $receptions_match_order = 0;
1710 $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';
1715 if ($receptions_match_order) {
1716 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');
1717 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1721 $this->statut = self::STATUS_CLOSED;
1722 $this->
status = self::STATUS_CLOSED;
1725 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1726 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1728 $langs->load(
"agenda");
1732 $sql =
"SELECT cd.fk_product, cd.subprice,";
1733 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1734 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1735 $sql .=
" ed.cost_price";
1736 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1737 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1738 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1739 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1741 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1742 $resql = $this->db->query($sql);
1745 $cpt = $this->db->num_rows($resql);
1746 for ($i = 0; $i < $cpt; $i++) {
1747 $obj = $this->db->fetch_object($resql);
1755 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
1758 $mouvS->origin = &$this;
1759 $mouvS->setOrigin($this->element, $this->
id);
1761 if (empty($obj->batch)) {
1765 $inventorycode =
'';
1766 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1768 $this->error = $mouvS->error;
1769 $this->errors = $mouvS->errors;
1777 $inventorycode =
'';
1778 $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);
1781 $this->error = $mouvS->error;
1782 $this->errors = $mouvS->errors;
1789 $this->error = $this->db->lasterror();
1796 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1807 $this->db->commit();
1810 $this->statut = self::STATUS_VALIDATED;
1811 $this->
status = self::STATUS_VALIDATED;
1812 $this->db->rollback();
1829 if ($this->statut == Reception::STATUS_VALIDATED) {
1834 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1835 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1837 $resql = $this->db->query($sql);
1842 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1849 $this->errors[] = $this->db->lasterror;
1852 if (empty($error)) {
1853 $this->db->commit();
1856 $this->db->rollback();
1868 global
$conf, $langs, $user;
1874 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1875 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1877 $resql = $this->db->query($sql);
1879 $this->statut = self::STATUS_VALIDATED;
1880 $this->
status = self::STATUS_VALIDATED;
1884 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1885 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1886 $numref = $this->ref;
1887 $langs->load(
"agenda");
1891 $sql =
"SELECT ed.fk_product, cd.subprice,";
1892 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1893 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1894 $sql .=
" ed.cost_price";
1895 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1896 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1897 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1898 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1900 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1901 $resql = $this->db->query($sql);
1903 $cpt = $this->db->num_rows($resql);
1904 for ($i = 0; $i < $cpt; $i++) {
1905 $obj = $this->db->fetch_object($resql);
1912 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1916 $mouvS->origin = &$this;
1917 $mouvS->setOrigin($this->element, $this->
id);
1919 if (empty($obj->batch)) {
1923 $inventorycode =
'';
1924 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1927 $this->error = $mouvS->error;
1928 $this->errors = $mouvS->errors;
1936 $inventorycode =
'';
1937 $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);
1939 $this->error = $mouvS->error;
1940 $this->errors = $mouvS->errors;
1947 $this->error = $this->db->lasterror();
1954 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1960 if (!$error && $this->origin ==
'order_supplier') {
1961 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1964 $commande->fetch($this->origin_id);
1965 $result = $commande->setStatus($user, 4);
1968 $this->error = $commande->error;
1969 $this->errors = $commande->errors;
1974 $this->errors[] = $this->db->lasterror();
1978 $this->db->commit();
1981 $this->db->rollback();
1995 global
$conf, $langs;
2000 if ($this->statut <= self::STATUS_DRAFT) {
2004 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2005 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2006 $this->error =
'Permission denied';
2012 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2013 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2014 $sql .=
" WHERE rowid = ".((int) $this->
id);
2017 if ($this->db->query($sql)) {
2019 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
2020 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2022 $langs->load(
"agenda");
2026 $sql =
"SELECT cd.fk_product, cd.subprice,";
2027 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2028 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2029 $sql .=
" ed.cost_price";
2030 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2031 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2032 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2033 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2035 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2036 $resql = $this->db->query($sql);
2038 $cpt = $this->db->num_rows($resql);
2039 for ($i = 0; $i < $cpt; $i++) {
2040 $obj = $this->db->fetch_object($resql);
2048 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2052 $mouvS->origin = &$this;
2053 $mouvS->setOrigin($this->element, $this->
id);
2055 if (empty($obj->batch)) {
2059 $inventorycode =
'';
2060 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2062 $this->error = $mouvS->error;
2063 $this->errors = $mouvS->errors;
2071 $inventorycode =
'';
2072 $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);
2074 $this->error = $mouvS->error;
2075 $this->errors = $mouvS->errors;
2082 $this->error = $this->db->lasterror();
2089 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
2094 if ($this->origin ==
'order_supplier') {
2095 if (!empty($this->origin) && $this->origin_id > 0) {
2097 if ($this->origin_object->statut == 4) {
2099 $this->origin_object->fetchObjectLinked();
2101 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2102 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2103 if ($rcption->statut > 0) {
2110 $this->origin_object->setStatut(3);
2118 $this->statut = self::STATUS_DRAFT;
2119 $this->
status = self::STATUS_DRAFT;
2120 $this->db->commit();
2123 $this->db->rollback();
2127 $this->error = $this->db->error();
2128 $this->db->rollback();
2143 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2145 global
$conf, $langs;
2147 $langs->load(
"receptions");
2150 $modele =
'squille';
2152 if ($this->model_pdf) {
2153 $modele = $this->model_pdf;
2159 $modelpath =
"core/modules/reception/doc/";
2163 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2176 $tables = array(
'reception');
2192 '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.
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.