37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40if (isModEnabled(
"propal")) {
41 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
43if (isModEnabled(
'order')) {
44 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
63 public $element =
"reception";
68 public $fk_element =
"fk_reception";
69 public $table_element =
"reception";
70 public $table_element_line =
"receptiondet_batch";
75 public $picto =
'dollyrevert';
93 public $tracking_number;
114 public $weight_units;
130 public $height_units;
150 public $user_author_id;
155 public $date_delivery;
167 public $date_reception;
186 public $lines = array();
193 public $detail_batch;
195 const STATUS_DRAFT = 0;
196 const STATUS_VALIDATED = 1;
197 const STATUS_CLOSED = 2;
209 $this->ismultientitymanaged = 1;
220 global $langs,
$conf;
221 $langs->load(
"receptions");
230 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
232 foreach ($dirmodels as $reldir) {
236 $mybool = ((bool) @include_once $dir.$file) || $mybool;
244 $obj =
new $classname();
245 '@phan-var-force ModelNumRefReception $obj';
247 $numref = $obj->getNextValue($soc, $this);
252 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
256 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
268 public function create($user, $notrigger = 0)
274 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
279 if (empty($this->fk_project)) {
280 $this->fk_project = 0;
282 if (empty($this->weight_units)) {
283 $this->weight_units = 0;
285 if (empty($this->size_units)) {
286 $this->size_units = 0;
293 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
296 $sql .=
", ref_supplier";
297 $sql .=
", date_creation";
298 $sql .=
", fk_user_author";
299 $sql .=
", date_reception";
300 $sql .=
", date_delivery";
302 $sql .=
", fk_projet";
303 $sql .=
", fk_shipping_method";
304 $sql .=
", tracking_number";
309 $sql .=
", weight_units";
310 $sql .=
", size_units";
311 $sql .=
", note_private";
312 $sql .=
", note_public";
313 $sql .=
", model_pdf";
314 $sql .=
", fk_incoterms, location_incoterms";
315 $sql .=
") VALUES (";
317 $sql .=
", ".((int)
$conf->entity);
318 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
319 $sql .=
", '".$this->db->idate($now).
"'";
320 $sql .=
", ".((int) $user->id);
321 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
322 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
323 $sql .=
", ".((int) $this->socid);
324 $sql .=
", ".((int) $this->fk_project);
325 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
326 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
327 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
328 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
329 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
330 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
331 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((float) $this->weight_units));
332 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((float) $this->size_units));
333 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
334 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
335 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
336 $sql .=
", ".(int) $this->fk_incoterms;
337 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
340 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
342 $resql = $this->db->query($sql);
345 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
347 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
348 $sql .=
" SET ref = '(PROV".((int) $this->
id).
")'";
349 $sql .=
" WHERE rowid = ".((int) $this->
id);
351 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
352 if ($this->db->query($sql)) {
354 $num = count($this->lines);
355 for ($i = 0; $i < $num; $i++) {
356 $this->lines[$i]->fk_reception = $this->id;
358 if (!$this->lines[$i]->
create($user) > 0) {
363 if (!$error && $this->
id && $this->origin_id) {
378 if (!$error && !$notrigger) {
380 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
391 foreach ($this->errors as $errmsg) {
392 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
393 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
395 $this->db->rollback();
400 $this->error = $this->db->lasterror().
" - sql=$sql";
401 $this->db->rollback();
406 $this->error = $this->db->error().
" - sql=$sql";
407 $this->db->rollback();
422 public function fetch($id, $ref =
'', $ref_ext =
'')
425 if (empty($id) && empty($ref) && empty($ref_ext)) {
429 $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";
430 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
431 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
432 $sql .=
", e.fk_shipping_method, e.tracking_number";
433 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
434 $sql .=
", e.note_private, e.note_public";
435 $sql .=
', e.fk_incoterms, e.location_incoterms';
436 $sql .=
', i.libelle as label_incoterms';
437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
438 $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'";
439 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
440 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
442 $sql .=
" AND e.rowid = ".((int) $id);
445 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
448 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
451 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
452 $result = $this->db->query($sql);
454 if ($this->db->num_rows($result)) {
455 $obj = $this->db->fetch_object($result);
457 $this->
id = $obj->rowid;
458 $this->entity = $obj->entity;
459 $this->
ref = $obj->ref;
460 $this->socid = $obj->socid;
461 $this->ref_supplier = $obj->ref_supplier;
462 $this->ref_ext = $obj->ref_ext;
463 $this->statut = $obj->status;
464 $this->
status = $obj->status;
465 $this->billed = $obj->billed;
467 $this->user_author_id = $obj->fk_user_author;
468 $this->date_creation = $this->db->jdate($obj->date_creation);
469 $this->date = $this->db->jdate($obj->date_reception);
470 $this->date_reception = $this->db->jdate($obj->date_reception);
471 $this->date_delivery = $this->db->jdate($obj->date_delivery);
472 $this->date_valid = $this->db->jdate($obj->date_valid);
473 $this->model_pdf = $obj->model_pdf;
474 $this->shipping_method_id = $obj->fk_shipping_method;
475 $this->tracking_number = $obj->tracking_number;
476 $this->origin = ($obj->origin ? $obj->origin :
'commande');
477 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
478 $this->origin_id = $obj->origin_id;
480 $this->trueWeight = $obj->weight;
481 $this->weight_units = $obj->weight_units;
483 $this->trueWidth = $obj->width;
484 $this->width_units = $obj->size_units;
485 $this->trueHeight = $obj->height;
486 $this->height_units = $obj->size_units;
487 $this->trueDepth = $obj->size;
488 $this->depth_units = $obj->size_units;
490 $this->note_public = $obj->note_public;
491 $this->note_private = $obj->note_private;
494 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
495 $this->size_units = $obj->size_units;
498 $this->fk_incoterms = $obj->fk_incoterms;
499 $this->location_incoterms = $obj->location_incoterms;
500 $this->label_incoterms = $obj->label_incoterms;
502 $this->db->free($result);
518 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
520 $extrafields->fetch_name_optionals_label($this->table_element,
true);
533 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
534 $this->error =
'Reception with id '.$id.
' not found';
538 $this->error = $this->db->error();
550 public function valid($user, $notrigger = 0)
552 global
$conf, $langs;
554 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
560 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
564 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
565 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
566 $this->error =
'Permission denied';
567 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
577 $soc->fetch($this->socid);
581 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
584 $numref = $this->ref;
592 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
593 $sql .=
" ref='".$this->db->escape($numref).
"'";
594 $sql .=
", fk_statut = 1";
595 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
596 $sql .=
", fk_user_valid = ".((int) $user->id);
597 $sql .=
" WHERE rowid = ".((int) $this->
id);
598 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
599 $resql = $this->db->query($sql);
601 $this->error = $this->db->lasterror();
606 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
607 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
609 $langs->load(
"agenda");
613 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
614 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
615 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
616 $sql .=
" ed.cost_price";
617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
618 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
619 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
620 $sql .=
" AND cd.rowid = ed.fk_elementdet";
622 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
623 $resql = $this->db->query($sql);
625 $cpt = $this->db->num_rows($resql);
626 for ($i = 0; $i < $cpt; $i++) {
627 $obj = $this->db->fetch_object($resql);
631 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
635 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
639 $mouvS->origin = &$this;
640 $mouvS->setOrigin($this->element, $this->
id);
642 if (empty($obj->batch)) {
647 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
649 if (intval($result) < 0) {
660 $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);
662 if (intval($result) < 0) {
670 $this->db->rollback();
671 $this->error = $this->db->error();
684 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
687 $this->errors = array_merge($this->errors, $this->origin_object->errors);
690 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
698 if (!$error && !$notrigger) {
700 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
708 $this->oldref = $this->ref;
711 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
713 $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).
"'";
714 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
715 $resql = $this->db->query($sql);
718 $this->error = $this->db->lasterror();
720 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
721 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
722 $resql = $this->db->query($sql);
725 $this->error = $this->db->lasterror();
731 $dirsource =
$conf->reception->dir_output.
'/'.$oldref;
732 $dirdest =
$conf->reception->dir_output.
'/'.$newref;
733 if (!$error && file_exists($dirsource)) {
734 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
736 if (@rename($dirsource, $dirdest)) {
739 $listoffiles =
dol_dir_list(
$conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
740 foreach ($listoffiles as $fileentry) {
741 $dirsource = $fileentry[
'name'];
742 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
743 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
744 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
745 @rename($dirsource, $dirdest);
754 $this->
ref = $numref;
755 $this->statut = self::STATUS_VALIDATED;
756 $this->
status = self::STATUS_VALIDATED;
763 foreach ($this->errors as $errmsg) {
764 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
765 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
767 $this->db->rollback();
779 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
780 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
784 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
785 if (empty($this->origin_object)) {
787 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
788 $res = $this->origin_object->fetch_lines();
789 $this->commandeFournisseur =
null;
793 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
794 $res = $this->origin_object->fetch_lines();
802 $qty_received = array();
803 $qty_wished = array();
806 $filter = array(
't.fk_element' => $this->origin_id);
808 $filter[
't.status'] = 1;
811 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
817 foreach ($supplierorderdispatch->lines as $dispatch_line) {
818 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
819 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
821 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
826 foreach ($this->origin_object->lines as $origin_line) {
828 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
831 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
832 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
834 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
839 $diff_array = array_diff_assoc($qty_received, $qty_wished);
840 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
841 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
843 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
849 if (count($diff_array) > 0) {
852 foreach ($diff_array as $key => $value) {
854 if ($qty_received[$key] >= $qty_wished[$key]) {
860 if ($close == count($diff_array)) {
887 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
889 global
$conf, $langs, $user;
891 $num = count($this->lines);
894 $line->fk_entrepot = $entrepot_id;
895 $line->fk_commandefourndet = $id;
899 $result = $supplierorderline->fetch($id);
906 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
907 $fk_product = $supplierorderline->fk_product;
909 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
910 $langs->load(
"errors");
911 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
917 $product =
new Product($this->db);
918 $product->fetch($fk_product);
919 if (isModEnabled(
'productbatch')) {
920 $langs->load(
"errors");
921 if (!empty($product->status_batch) && empty($batch)) {
922 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
924 } elseif (empty($product->status_batch) && !empty($batch)) {
925 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
931 if (!empty($errorMsgArr)) {
932 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
933 $errorMessage .=
'<ul>';
934 foreach ($errorMsgArr as $errorMsg) {
935 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
937 $errorMessage .=
'</ul>';
938 $this->error = $errorMessage;
945 $line->array_options = $supplierorderline->array_options;
946 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
947 foreach ($array_options as $key => $value) {
948 $line->array_options[$key] = $value;
952 $line->fk_product = $fk_product;
953 $line->fk_commande = $supplierorderline->fk_commande;
954 $line->fk_user = $user->id;
955 $line->comment = $comment;
956 $line->batch = $batch;
957 $line->eatby = $eatby;
958 $line->sellby = $sellby;
960 $line->cost_price = $cost_price;
961 $line->fk_reception = $this->id;
963 $this->lines[$num] = $line;
976 public function update($user =
null, $notrigger = 0)
983 if (isset($this->
ref)) {
984 $this->
ref = trim($this->
ref);
986 if (isset($this->entity)) {
987 $this->entity = (int) $this->entity;
989 if (isset($this->ref_supplier)) {
990 $this->ref_supplier = trim($this->ref_supplier);
992 if (isset($this->socid)) {
993 $this->socid = (int) trim((
string) $this->socid);
995 if (isset($this->fk_user_author)) {
996 $this->fk_user_author = (int) $this->fk_user_author;
998 if (isset($this->fk_user_valid)) {
999 $this->fk_user_valid = (int) $this->fk_user_valid;
1001 if (isset($this->shipping_method_id)) {
1002 $this->shipping_method_id = (int) $this->shipping_method_id;
1004 if (isset($this->tracking_number)) {
1005 $this->tracking_number = trim($this->tracking_number);
1007 if (isset($this->statut)) {
1008 $this->statut = (int) $this->statut;
1010 if (isset($this->trueDepth)) {
1011 $this->trueDepth = (float) trim((
string) $this->trueDepth);
1013 if (isset($this->trueWidth)) {
1014 $this->trueWidth = (float) trim((
string) $this->trueWidth);
1016 if (isset($this->trueHeight)) {
1017 $this->trueHeight = (float) trim((
string) $this->trueHeight);
1019 if (isset($this->size_units)) {
1020 $this->size_units = trim((
string) $this->size_units);
1022 if (isset($this->weight_units)) {
1023 $this->weight_units = (float) trim((
string) $this->weight_units);
1025 if (isset($this->trueWeight)) {
1026 $this->weight = (float) trim((
string) $this->trueWeight);
1028 if (isset($this->note_private)) {
1029 $this->note_private = trim($this->note_private);
1031 if (isset($this->note_public)) {
1032 $this->note_public = trim($this->note_public);
1034 if (isset($this->model_pdf)) {
1035 $this->model_pdf = trim($this->model_pdf);
1043 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1045 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1046 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1047 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1048 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1049 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1050 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1051 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1052 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1053 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1054 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1055 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1056 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1057 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1058 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1059 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1060 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1061 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1062 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1063 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1064 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1065 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1066 $sql .=
" entity = ".((int)
$conf->entity);
1067 $sql .=
" WHERE rowid=".((int) $this->
id);
1071 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1072 $resql = $this->db->query($sql);
1075 $this->errors[] =
"Error ".$this->db->lasterror();
1081 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1091 foreach ($this->errors as $errmsg) {
1092 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1093 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1095 $this->db->rollback();
1098 $this->db->commit();
1111 global
$conf, $langs, $user;
1112 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1121 if (isModEnabled(
'stock') && ((
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') && $this->
status > Reception::STATUS_DRAFT)
1122 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1124 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1126 $langs->load(
"agenda");
1129 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1131 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1132 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1133 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1135 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1136 $resql = $this->db->query($sql);
1138 $cpt = $this->db->num_rows($resql);
1139 for ($i = 0; $i < $cpt; $i++) {
1140 dol_syslog(get_class($this).
"::delete movement index ".$i);
1141 $obj = $this->db->fetch_object($resql);
1145 $mouvS->origin =
null;
1147 $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);
1150 $this->error = $mouvS->error;
1151 $this->errors = $mouvS->errors;
1156 $this->errors[] =
"Error ".$this->db->lasterror();
1161 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1162 $ef = $main.
"_extrafields";
1164 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1166 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1167 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1169 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1177 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1178 $sql .=
" WHERE rowid = ".((int) $this->
id);
1180 if ($this->db->query($sql)) {
1182 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1188 if (!empty($this->origin) && $this->origin_id > 0) {
1191 '@phan-var-force CommandeFournisseur $origin_object';
1203 $this->db->commit();
1207 if (!empty(
$conf->reception->dir_output)) {
1208 $dir =
$conf->reception->dir_output.
'/'.$ref;
1209 $file = $dir.
'/'.$ref.
'.pdf';
1210 if (file_exists($file)) {
1215 if (file_exists($dir)) {
1217 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1225 $this->db->rollback();
1229 $this->error = $this->db->lasterror().
" - sql=$sql";
1230 $this->db->rollback();
1234 $this->error = $this->db->lasterror().
" - sql=$sql";
1235 $this->db->rollback();
1239 $this->error = $this->db->lasterror().
" - sql=$sql";
1240 $this->db->rollback();
1244 $this->db->rollback();
1258 $this->lines = array();
1260 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1262 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1263 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1265 $resql = $this->db->query($sql);
1267 if (!empty($resql)) {
1268 while ($obj = $this->db->fetch_object($resql)) {
1271 $line->fetch($obj->rowid);
1274 $line->fetch_product();
1276 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1277 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1278 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1279 $sql_commfourndet .=
' ORDER BY rang';
1281 $resql_commfourndet = $this->db->query($sql_commfourndet);
1282 if (!empty($resql_commfourndet)) {
1283 $obj = $this->db->fetch_object($resql_commfourndet);
1284 $line->qty_asked = $obj->qty;
1285 $line->description = $obj->description;
1286 $line->desc = $obj->description;
1287 $line->tva_tx = $obj->tva_tx;
1288 $line->vat_src_code = $obj->vat_src_code;
1289 $line->subprice = $obj->subprice;
1290 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1291 $line->remise_percent = $obj->remise_percent;
1292 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1293 $line->ref_supplier = $obj->ref;
1294 $line->total_ht = $obj->total_ht;
1295 $line->total_ttc = $obj->total_ttc;
1296 $line->total_tva = $obj->total_tva;
1298 $line->qty_asked = 0;
1299 $line->description =
'';
1301 $line->label = $obj->label;
1304 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1305 $tva = $pu_ht * $line->tva_tx / 100;
1306 $this->total_ht += $pu_ht;
1307 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1309 $this->total_ttc += $pu_ht + $tva;
1311 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1313 $detail_batch->eatby = $line->eatby;
1314 $detail_batch->sellby = $line->sellby;
1315 $detail_batch->batch = $line->batch;
1316 $detail_batch->qty = $line->qty;
1318 $line->detail_batch[] = $detail_batch;
1321 $this->lines[] = $line;
1340 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1342 global $langs, $hookmanager;
1345 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1346 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1347 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1349 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1356 if (empty($notooltip)) {
1358 $label = $langs->trans(
"Reception");
1359 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1361 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1362 $linkclose .=
' class="classfortooltip"';
1365 $linkstart =
'<a href="'.$url.
'"';
1366 $linkstart .= $linkclose.
'>';
1369 $result .= $linkstart;
1371 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1373 if ($withpicto != 2) {
1374 $result .= $this->ref;
1377 $result .= $linkend;
1380 $hookmanager->initHooks(array($this->element .
'dao'));
1381 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1382 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1384 $result = $hookmanager->resPrint;
1386 $result .= $hookmanager->resPrint;
1399 return $this->
LibStatut($this->statut, $mode);
1416 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1417 $this->labelStatus[0] =
'StatusReceptionDraft';
1419 $this->labelStatus[1] =
'StatusReceptionValidated';
1421 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1424 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1426 $this->labelStatus[2] =
'StatusReceptionProcessed';
1429 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1430 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1431 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1432 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1434 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1435 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1437 $statusType =
'status'.$status;
1438 if ($status == self::STATUS_VALIDATED) {
1439 $statusType =
'status4';
1441 if ($status == self::STATUS_CLOSED) {
1442 $statusType =
'status6';
1445 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1457 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1459 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1460 $return .=
'<div class="info-box info-box-sm">';
1461 $return .=
'<div class="info-box-icon bg-infobox-action">';
1463 $return .=
'</div>';
1464 $return .=
'<div class="info-box-content">';
1465 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1466 if ($selected >= 0) {
1467 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1469 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1470 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1475 if (method_exists($this,
'getLibStatut')) {
1476 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1478 $return .=
'</div>';
1479 $return .=
'</div>';
1480 $return .=
'</div>';
1496 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1497 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1500 dol_syslog(get_class($this).
"::initAsSpecimen");
1503 $order->initAsSpecimen();
1507 $this->
ref =
'SPECIMEN';
1508 $this->specimen = 1;
1512 $this->date_creation = $now;
1513 $this->date_valid = $now;
1514 $this->date_delivery = $now;
1515 $this->date_reception = $now + 24 * 3600;
1517 $this->entrepot_id = 0;
1520 $this->origin_id = 1;
1521 $this->origin_type =
'supplier_order';
1522 $this->origin_object = $order;
1524 $this->note_private =
'Private note';
1525 $this->note_public =
'Public note';
1527 $this->tracking_number =
'TRACKID-ABC123';
1529 $this->fk_incoterms = 1;
1533 while ($xnbp < $nbp) {
1535 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1536 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1537 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1540 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1542 $this->lines[] = $line;
1559 if ($user->hasRight(
'reception',
'creer')) {
1560 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1561 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1562 $sql .=
" WHERE rowid = ".((int) $this->
id);
1564 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1565 $resql = $this->db->query($sql);
1567 $this->date_delivery = $delivery_date;
1570 $this->error = $this->db->error();
1588 $this->meths = array();
1590 $sql =
"SELECT em.rowid, em.code, em.libelle";
1591 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1592 $sql .=
" WHERE em.active = 1";
1593 $sql .=
" ORDER BY em.libelle ASC";
1595 $resql = $this->db->query($sql);
1597 while ($obj = $this->db->fetch_object($resql)) {
1598 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1599 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1616 $this->listmeths = array();
1619 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1620 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1622 $sql .=
" WHERE em.rowid = ".((int) $id);
1625 $resql = $this->db->query($sql);
1627 while ($obj = $this->db->fetch_object($resql)) {
1628 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1629 $this->listmeths[$i][
'code'] = $obj->code;
1630 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1631 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1632 $this->listmeths[$i][
'description'] = $obj->description;
1633 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1634 $this->listmeths[$i][
'active'] = $obj->active;
1648 if (!empty($this->shipping_method_id)) {
1649 $sql =
"SELECT em.code, em.tracking";
1650 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1651 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1653 $resql = $this->db->query($sql);
1655 if ($obj = $this->db->fetch_object($resql)) {
1656 $tracking = $obj->tracking;
1661 if (!empty($tracking) && !empty($value)) {
1662 $url = str_replace(
'{TRACKID}', $value, $tracking);
1663 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1665 $this->tracking_url = $value;
1676 global
$conf, $langs, $user;
1681 if ($this->statut == Reception::STATUS_CLOSED) {
1682 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1688 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1689 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1691 $resql = $this->db->query($sql);
1694 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1695 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1698 $order->fetch($this->origin_id);
1700 $order->loadReceptions(self::STATUS_CLOSED);
1702 $receptions_match_order = 1;
1703 foreach ($order->lines as $line) {
1704 $lineid = $line->id;
1706 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1707 $receptions_match_order = 0;
1708 $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';
1713 if ($receptions_match_order) {
1714 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');
1715 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1719 $this->statut = self::STATUS_CLOSED;
1720 $this->
status = self::STATUS_CLOSED;
1723 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1724 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1726 $langs->load(
"agenda");
1730 $sql =
"SELECT cd.fk_product, cd.subprice,";
1731 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1732 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1733 $sql .=
" ed.cost_price";
1734 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1735 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1736 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1737 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1739 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1740 $resql = $this->db->query($sql);
1743 $cpt = $this->db->num_rows($resql);
1744 for ($i = 0; $i < $cpt; $i++) {
1745 $obj = $this->db->fetch_object($resql);
1753 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
1756 $mouvS->origin = &$this;
1757 $mouvS->setOrigin($this->element, $this->
id);
1759 if (empty($obj->batch)) {
1763 $inventorycode =
'';
1764 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1766 $this->error = $mouvS->error;
1767 $this->errors = $mouvS->errors;
1775 $inventorycode =
'';
1776 $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);
1779 $this->error = $mouvS->error;
1780 $this->errors = $mouvS->errors;
1787 $this->error = $this->db->lasterror();
1794 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1805 $this->db->commit();
1808 $this->statut = self::STATUS_VALIDATED;
1809 $this->
status = self::STATUS_VALIDATED;
1810 $this->db->rollback();
1827 if ($this->statut == Reception::STATUS_VALIDATED) {
1832 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1833 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1835 $resql = $this->db->query($sql);
1840 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1847 $this->errors[] = $this->db->lasterror;
1850 if (empty($error)) {
1851 $this->db->commit();
1854 $this->db->rollback();
1866 global
$conf, $langs, $user;
1872 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1873 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1875 $resql = $this->db->query($sql);
1877 $this->statut = self::STATUS_VALIDATED;
1878 $this->
status = self::STATUS_VALIDATED;
1882 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1883 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1884 $numref = $this->ref;
1885 $langs->load(
"agenda");
1889 $sql =
"SELECT ed.fk_product, cd.subprice,";
1890 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1891 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1892 $sql .=
" ed.cost_price";
1893 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1894 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1895 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1896 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1898 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1899 $resql = $this->db->query($sql);
1901 $cpt = $this->db->num_rows($resql);
1902 for ($i = 0; $i < $cpt; $i++) {
1903 $obj = $this->db->fetch_object($resql);
1910 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1914 $mouvS->origin = &$this;
1915 $mouvS->setOrigin($this->element, $this->
id);
1917 if (empty($obj->batch)) {
1921 $inventorycode =
'';
1922 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1925 $this->error = $mouvS->error;
1926 $this->errors = $mouvS->errors;
1934 $inventorycode =
'';
1935 $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);
1937 $this->error = $mouvS->error;
1938 $this->errors = $mouvS->errors;
1945 $this->error = $this->db->lasterror();
1952 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1958 if (!$error && $this->origin ==
'order_supplier') {
1959 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1962 $commande->fetch($this->origin_id);
1963 $result = $commande->setStatus($user, 4);
1966 $this->error = $commande->error;
1967 $this->errors = $commande->errors;
1972 $this->errors[] = $this->db->lasterror();
1976 $this->db->commit();
1979 $this->db->rollback();
1993 global
$conf, $langs;
1998 if ($this->statut <= self::STATUS_DRAFT) {
2002 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2003 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2004 $this->error =
'Permission denied';
2010 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2011 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2012 $sql .=
" WHERE rowid = ".((int) $this->
id);
2015 if ($this->db->query($sql)) {
2017 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
2018 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2020 $langs->load(
"agenda");
2024 $sql =
"SELECT cd.fk_product, cd.subprice,";
2025 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2026 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2027 $sql .=
" ed.cost_price";
2028 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2029 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2030 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2031 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2033 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2034 $resql = $this->db->query($sql);
2036 $cpt = $this->db->num_rows($resql);
2037 for ($i = 0; $i < $cpt; $i++) {
2038 $obj = $this->db->fetch_object($resql);
2046 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2050 $mouvS->origin = &$this;
2051 $mouvS->setOrigin($this->element, $this->
id);
2053 if (empty($obj->batch)) {
2057 $inventorycode =
'';
2058 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2060 $this->error = $mouvS->error;
2061 $this->errors = $mouvS->errors;
2069 $inventorycode =
'';
2070 $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);
2072 $this->error = $mouvS->error;
2073 $this->errors = $mouvS->errors;
2080 $this->error = $this->db->lasterror();
2087 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
2092 if ($this->origin ==
'order_supplier') {
2093 if (!empty($this->origin) && $this->origin_id > 0) {
2095 if ($this->origin_object->statut == 4) {
2097 $this->origin_object->fetchObjectLinked();
2099 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2100 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2101 if ($rcption->statut > 0) {
2108 $this->origin_object->setStatut(3);
2116 $this->statut = self::STATUS_DRAFT;
2117 $this->
status = self::STATUS_DRAFT;
2118 $this->db->commit();
2121 $this->db->rollback();
2125 $this->error = $this->db->error();
2126 $this->db->rollback();
2141 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2143 global
$conf, $langs;
2145 $langs->load(
"receptions");
2148 $modele =
'squille';
2150 if ($this->model_pdf) {
2151 $modele = $this->model_pdf;
2157 $modelpath =
"core/modules/reception/doc/";
2161 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2174 $tables = array(
'reception');
2190 '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.