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';
81 public $tracking_number;
98 public $user_author_id;
100 public $date_delivery;
112 public $date_reception;
117 public $date_creation;
130 public $lines = array();
135 public $detail_batch;
137 const STATUS_DRAFT = 0;
138 const STATUS_VALIDATED = 1;
139 const STATUS_CLOSED = 2;
152 $this->ismultientitymanaged = 1;
163 global $langs, $conf;
164 $langs->load(
"receptions");
173 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
175 foreach ($dirmodels as $reldir) {
179 $mybool = ((bool) @include_once $dir.$file) || $mybool;
187 $obj =
new $classname();
190 $numref = $obj->getNextValue($soc, $this);
195 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
199 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
211 public function create($user, $notrigger = 0)
217 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
222 if (empty($this->fk_project)) {
223 $this->fk_project = 0;
225 if (empty($this->weight_units)) {
226 $this->weight_units = 0;
228 if (empty($this->size_units)) {
229 $this->size_units = 0;
236 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
239 $sql .=
", ref_supplier";
240 $sql .=
", date_creation";
241 $sql .=
", fk_user_author";
242 $sql .=
", date_reception";
243 $sql .=
", date_delivery";
245 $sql .=
", fk_projet";
246 $sql .=
", fk_shipping_method";
247 $sql .=
", tracking_number";
252 $sql .=
", weight_units";
253 $sql .=
", size_units";
254 $sql .=
", note_private";
255 $sql .=
", note_public";
256 $sql .=
", model_pdf";
257 $sql .=
", fk_incoterms, location_incoterms";
258 $sql .=
") VALUES (";
260 $sql .=
", ".((int) $conf->entity);
261 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
262 $sql .=
", '".$this->db->idate($now).
"'";
263 $sql .=
", ".((int) $user->id);
264 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
265 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
266 $sql .=
", ".((int) $this->socid);
267 $sql .=
", ".((int) $this->fk_project);
268 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
269 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
270 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
271 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
272 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
273 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
274 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((float) $this->weight_units));
275 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((float) $this->size_units));
276 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
277 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
278 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
279 $sql .=
", ".(int) $this->fk_incoterms;
280 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
283 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
285 $resql = $this->db->query($sql);
288 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
290 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
291 $sql .=
" SET ref = '(PROV".((int) $this->
id).
")'";
292 $sql .=
" WHERE rowid = ".((int) $this->
id);
294 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
295 if ($this->db->query($sql)) {
297 $num = count($this->lines);
298 for ($i = 0; $i < $num; $i++) {
299 $this->lines[$i]->fk_reception = $this->id;
301 if (!$this->lines[$i]->
create($user) > 0) {
306 if (!$error && $this->
id && $this->origin_id) {
321 if (!$error && !$notrigger) {
323 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
334 foreach ($this->errors as $errmsg) {
335 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
336 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
338 $this->db->rollback();
343 $this->error = $this->db->lasterror().
" - sql=$sql";
344 $this->db->rollback();
349 $this->error = $this->db->error().
" - sql=$sql";
350 $this->db->rollback();
365 public function fetch($id, $ref =
'', $ref_ext =
'')
368 if (empty($id) && empty($ref) && empty($ref_ext)) {
372 $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";
373 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
374 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
375 $sql .=
", e.fk_shipping_method, e.tracking_number";
376 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
377 $sql .=
", e.note_private, e.note_public";
378 $sql .=
', e.fk_incoterms, e.location_incoterms';
379 $sql .=
', i.libelle as label_incoterms';
380 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
381 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
382 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
383 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
385 $sql .=
" AND e.rowid = ".((int) $id);
388 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
391 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
394 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
395 $result = $this->db->query($sql);
397 if ($this->db->num_rows($result)) {
398 $obj = $this->db->fetch_object($result);
400 $this->
id = $obj->rowid;
401 $this->entity = $obj->entity;
402 $this->
ref = $obj->ref;
403 $this->socid = $obj->socid;
404 $this->ref_supplier = $obj->ref_supplier;
405 $this->ref_ext = $obj->ref_ext;
406 $this->
statut = $obj->status;
407 $this->
status = $obj->status;
408 $this->billed = $obj->billed;
410 $this->user_author_id = $obj->fk_user_author;
411 $this->date_creation = $this->db->jdate($obj->date_creation);
412 $this->date = $this->db->jdate($obj->date_reception);
413 $this->date_reception = $this->db->jdate($obj->date_reception);
414 $this->date_delivery = $this->db->jdate($obj->date_delivery);
415 $this->model_pdf = $obj->model_pdf;
416 $this->shipping_method_id = $obj->fk_shipping_method;
417 $this->tracking_number = $obj->tracking_number;
418 $this->origin = ($obj->origin ? $obj->origin :
'commande');
419 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
420 $this->origin_id = $obj->origin_id;
422 $this->trueWeight = $obj->weight;
423 $this->weight_units = $obj->weight_units;
425 $this->trueWidth = $obj->width;
426 $this->width_units = $obj->size_units;
427 $this->trueHeight = $obj->height;
428 $this->height_units = $obj->size_units;
429 $this->trueDepth = $obj->size;
430 $this->depth_units = $obj->size_units;
432 $this->note_public = $obj->note_public;
433 $this->note_private = $obj->note_private;
436 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
437 $this->size_units = $obj->size_units;
440 $this->fk_incoterms = $obj->fk_incoterms;
441 $this->location_incoterms = $obj->location_incoterms;
442 $this->label_incoterms = $obj->label_incoterms;
444 $this->db->free($result);
460 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
462 $extrafields->fetch_name_optionals_label($this->table_element,
true);
475 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
476 $this->error =
'Reception with id '.$id.
' not found';
480 $this->error = $this->db->error();
492 public function valid($user, $notrigger = 0)
494 global $conf, $langs;
496 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
502 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
506 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
507 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
508 $this->error =
'Permission denied';
509 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
519 $soc->fetch($this->socid);
523 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
526 $numref = $this->ref;
534 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
535 $sql .=
" ref='".$this->db->escape($numref).
"'";
536 $sql .=
", fk_statut = 1";
537 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
538 $sql .=
", fk_user_valid = ".$user->id;
539 $sql .=
" WHERE rowid = ".((int) $this->
id);
540 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
541 $resql = $this->db->query($sql);
543 $this->error = $this->db->lasterror();
548 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
549 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
551 $langs->load(
"agenda");
555 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
556 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
557 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
558 $sql .=
" ed.cost_price";
559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
560 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
561 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
562 $sql .=
" AND cd.rowid = ed.fk_elementdet";
564 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
565 $resql = $this->db->query($sql);
567 $cpt = $this->db->num_rows($resql);
568 for ($i = 0; $i < $cpt; $i++) {
569 $obj = $this->db->fetch_object($resql);
573 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
576 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
580 $mouvS->origin = &$this;
581 $mouvS->setOrigin($this->element, $this->
id);
583 if (empty($obj->batch)) {
588 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
590 if (intval($result) < 0) {
592 $this->errors[] = $mouvS->error;
593 $this->errors = array_merge($this->errors, $mouvS->errors);
602 $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);
604 if (intval($result) < 0) {
606 $this->errors[] = $mouvS->error;
607 $this->errors = array_merge($this->errors, $mouvS->errors);
613 $this->db->rollback();
614 $this->error = $this->db->error();
627 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
630 $this->errors = array_merge($this->errors, $this->origin_object->errors);
633 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
641 if (!$error && !$notrigger) {
643 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
651 $this->oldref = $this->ref;
654 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
656 $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).
"'";
657 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
658 $resql = $this->db->query($sql);
661 $this->error = $this->db->lasterror();
663 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
664 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
665 $resql = $this->db->query($sql);
668 $this->error = $this->db->lasterror();
674 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
675 $dirdest = $conf->reception->dir_output.
'/'.$newref;
676 if (!$error && file_exists($dirsource)) {
677 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
679 if (@rename($dirsource, $dirdest)) {
682 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
683 foreach ($listoffiles as $fileentry) {
684 $dirsource = $fileentry[
'name'];
685 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
686 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
687 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
688 @rename($dirsource, $dirdest);
697 $this->
ref = $numref;
698 $this->
statut = self::STATUS_VALIDATED;
699 $this->
status = self::STATUS_VALIDATED;
706 foreach ($this->errors as $errmsg) {
707 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
708 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
710 $this->db->rollback();
722 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
723 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
727 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
728 if (empty($this->origin_object)) {
730 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
731 $res = $this->origin_object->fetch_lines();
735 $this->commandeFournisseur =
null;
743 $qty_received = array();
744 $qty_wished = array();
747 $filter = array(
't.fk_element' => $this->origin_id);
749 $filter[
't.status'] = 1;
752 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
754 $this->error = $supplierorderdispatch->error;
755 $this->errors = $supplierorderdispatch->errors;
759 foreach ($supplierorderdispatch->lines as $dispatch_line) {
760 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
761 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
763 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
768 foreach ($this->origin_object->lines as $origin_line) {
770 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
774 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
778 $diff_array = array_diff_assoc($qty_received, $qty_wished);
779 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
780 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
782 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
788 if (count($diff_array) > 0) {
791 foreach ($diff_array as $key => $value) {
793 if ($qty_received[$key] >= $qty_wished[$key]) {
799 if ($close == count($diff_array)) {
826 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
828 global $conf, $langs, $user;
830 $num = count($this->lines);
833 $line->fk_entrepot = $entrepot_id;
834 $line->fk_commandefourndet = $id;
838 $result = $supplierorderline->fetch($id);
840 $this->error = $supplierorderline->error;
841 $this->errors = $supplierorderline->errors;
846 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
847 $fk_product = $supplierorderline->fk_product;
849 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
850 $langs->load(
"errors");
851 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
857 $product =
new Product($this->db);
858 $product->fetch($fk_product);
859 if (isModEnabled(
'productbatch')) {
860 $langs->load(
"errors");
861 if (!empty($product->status_batch) && empty($batch)) {
862 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
864 } elseif (empty($product->status_batch) && !empty($batch)) {
865 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
871 if (!empty($errorMsgArr)) {
872 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
873 $errorMessage .=
'<ul>';
874 foreach ($errorMsgArr as $errorMsg) {
875 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
877 $errorMessage .=
'</ul>';
878 $this->error = $errorMessage;
885 $line->array_options = $supplierorderline->array_options;
886 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
887 foreach ($array_options as $key => $value) {
888 $line->array_options[$key] = $value;
892 $line->fk_product = $fk_product;
893 $line->fk_commande = $supplierorderline->fk_commande;
894 $line->fk_user = $user->id;
895 $line->comment = $comment;
896 $line->batch = $batch;
897 $line->eatby = $eatby;
898 $line->sellby = $sellby;
900 $line->cost_price = $cost_price;
901 $line->fk_reception = $this->id;
903 $this->lines[$num] = $line;
916 public function update($user =
null, $notrigger = 0)
923 if (isset($this->
ref)) {
924 $this->
ref = trim($this->
ref);
926 if (isset($this->entity)) {
927 $this->entity = (int) $this->entity;
929 if (isset($this->ref_supplier)) {
930 $this->ref_supplier = trim($this->ref_supplier);
932 if (isset($this->socid)) {
933 $this->socid = trim($this->socid);
935 if (isset($this->fk_user_author)) {
936 $this->fk_user_author = (int) $this->fk_user_author;
938 if (isset($this->fk_user_valid)) {
939 $this->fk_user_valid = (int) $this->fk_user_valid;
941 if (isset($this->shipping_method_id)) {
942 $this->shipping_method_id = (int) $this->shipping_method_id;
944 if (isset($this->tracking_number)) {
945 $this->tracking_number = trim($this->tracking_number);
947 if (isset($this->
statut)) {
950 if (isset($this->trueDepth)) {
951 $this->trueDepth = trim($this->trueDepth);
953 if (isset($this->trueWidth)) {
954 $this->trueWidth = trim($this->trueWidth);
956 if (isset($this->trueHeight)) {
957 $this->trueHeight = trim($this->trueHeight);
959 if (isset($this->size_units)) {
960 $this->size_units = trim((
string) $this->size_units);
962 if (isset($this->weight_units)) {
963 $this->weight_units = trim((
string) $this->weight_units);
965 if (isset($this->trueWeight)) {
966 $this->weight = trim((
string) $this->trueWeight);
968 if (isset($this->note_private)) {
969 $this->note_private = trim($this->note_private);
971 if (isset($this->note_public)) {
972 $this->note_public = trim($this->note_public);
974 if (isset($this->model_pdf)) {
975 $this->model_pdf = trim($this->model_pdf);
983 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
985 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
986 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
987 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
988 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
989 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
990 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
991 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
992 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
993 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
994 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
995 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
996 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
997 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
998 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
999 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1000 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1001 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1002 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1003 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1004 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1005 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1006 $sql .=
" entity = ".((int) $conf->entity);
1007 $sql .=
" WHERE rowid=".((int) $this->
id);
1011 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1012 $resql = $this->db->query($sql);
1015 $this->errors[] =
"Error ".$this->db->lasterror();
1021 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1031 foreach ($this->errors as $errmsg) {
1032 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1033 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1035 $this->db->rollback();
1038 $this->db->commit();
1051 global $conf, $langs, $user;
1052 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1061 if (isModEnabled(
'stock') && !
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') && $this->
statut > 0) {
1062 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1064 $langs->load(
"agenda");
1067 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1068 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1069 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1070 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1071 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1073 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1074 $resql = $this->db->query($sql);
1076 $cpt = $this->db->num_rows($resql);
1077 for ($i = 0; $i < $cpt; $i++) {
1078 dol_syslog(get_class($this).
"::delete movement index ".$i);
1079 $obj = $this->db->fetch_object($resql);
1083 $mouvS->origin =
null;
1085 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1089 $this->errors[] =
"Error ".$this->db->lasterror();
1094 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1095 $ef = $main.
"_extrafields";
1097 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1099 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1100 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1102 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1110 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1111 $sql .=
" WHERE rowid = ".((int) $this->
id);
1113 if ($this->db->query($sql)) {
1115 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1121 if (!empty($this->origin) && $this->origin_id > 0) {
1123 if ($this->origin_object->statut == 4) {
1125 $this->origin_object->loadReceptions();
1127 if (count($this->origin_object->receptions) <= 0) {
1128 $this->origin_object->setStatut(3);
1134 $this->db->commit();
1138 if (!empty($conf->reception->dir_output)) {
1139 $dir = $conf->reception->dir_output.
'/'.$ref;
1140 $file = $dir.
'/'.$ref.
'.pdf';
1141 if (file_exists($file)) {
1146 if (file_exists($dir)) {
1148 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1156 $this->db->rollback();
1160 $this->error = $this->db->lasterror().
" - sql=$sql";
1161 $this->db->rollback();
1165 $this->error = $this->db->lasterror().
" - sql=$sql";
1166 $this->db->rollback();
1170 $this->error = $this->db->lasterror().
" - sql=$sql";
1171 $this->db->rollback();
1175 $this->db->rollback();
1189 $this->lines = array();
1191 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1193 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1194 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1196 $resql = $this->db->query($sql);
1198 if (!empty($resql)) {
1199 while ($obj = $this->db->fetch_object($resql)) {
1202 $line->fetch($obj->rowid);
1205 $line->fetch_product();
1207 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1208 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1209 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1210 $sql_commfourndet .=
' ORDER BY rang';
1212 $resql_commfourndet = $this->db->query($sql_commfourndet);
1213 if (!empty($resql_commfourndet)) {
1214 $obj = $this->db->fetch_object($resql_commfourndet);
1215 $line->qty_asked = $obj->qty;
1216 $line->description = $obj->description;
1217 $line->desc = $obj->description;
1218 $line->tva_tx = $obj->tva_tx;
1219 $line->vat_src_code = $obj->vat_src_code;
1220 $line->subprice = $obj->subprice;
1221 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1222 $line->remise_percent = $obj->remise_percent;
1223 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1224 $line->ref_supplier = $obj->ref;
1225 $line->total_ht = $obj->total_ht;
1226 $line->total_ttc = $obj->total_ttc;
1227 $line->total_tva = $obj->total_tva;
1229 $line->qty_asked = 0;
1230 $line->description =
'';
1232 $line->label = $obj->label;
1235 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1236 $tva = $pu_ht * $line->tva_tx / 100;
1237 $this->total_ht += $pu_ht;
1238 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1240 $this->total_ttc += $pu_ht + $tva;
1242 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1244 $detail_batch->eatby = $line->eatby;
1245 $detail_batch->sellby = $line->sellby;
1246 $detail_batch->batch = $line->batch;
1247 $detail_batch->qty = $line->qty;
1249 $line->detail_batch[] = $detail_batch;
1252 $this->lines[] = $line;
1271 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1273 global $langs, $hookmanager;
1276 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1277 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1278 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1280 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1287 if (empty($notooltip)) {
1289 $label = $langs->trans(
"Reception");
1290 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1292 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1293 $linkclose .=
' class="classfortooltip"';
1296 $linkstart =
'<a href="'.$url.
'"';
1297 $linkstart .= $linkclose.
'>';
1300 $result .= $linkstart;
1302 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1304 if ($withpicto != 2) {
1305 $result .= $this->ref;
1308 $result .= $linkend;
1311 $hookmanager->initHooks(array($this->element .
'dao'));
1312 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1313 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1315 $result = $hookmanager->resPrint;
1317 $result .= $hookmanager->resPrint;
1347 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1348 $this->labelStatus[0] =
'StatusReceptionDraft';
1350 $this->labelStatus[1] =
'StatusReceptionValidated';
1352 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1355 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1357 $this->labelStatus[2] =
'StatusReceptionProcessed';
1360 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1361 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1362 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1363 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1365 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1366 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1368 $statusType =
'status'.$status;
1369 if ($status == self::STATUS_VALIDATED) {
1370 $statusType =
'status4';
1372 if ($status == self::STATUS_CLOSED) {
1373 $statusType =
'status6';
1376 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1388 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1390 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1391 $return .=
'<div class="info-box info-box-sm">';
1392 $return .=
'<div class="info-box-icon bg-infobox-action">';
1394 $return .=
'</div>';
1395 $return .=
'<div class="info-box-content">';
1396 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1397 if ($selected >= 0) {
1398 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1400 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1401 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1406 if (method_exists($this,
'getLibStatut')) {
1407 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1409 $return .=
'</div>';
1410 $return .=
'</div>';
1411 $return .=
'</div>';
1427 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1428 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1431 dol_syslog(get_class($this).
"::initAsSpecimen");
1434 $order->initAsSpecimen();
1438 $this->
ref =
'SPECIMEN';
1439 $this->specimen = 1;
1443 $this->date_creation = $now;
1444 $this->date_valid = $now;
1445 $this->date_delivery = $now;
1446 $this->date_reception = $now + 24 * 3600;
1448 $this->entrepot_id = 0;
1451 $this->origin_id = 1;
1452 $this->origin_type =
'supplier_order';
1453 $this->origin_object = $order;
1455 $this->note_private =
'Private note';
1456 $this->note_public =
'Public note';
1458 $this->tracking_number =
'TRACKID-ABC123';
1460 $this->fk_incoterms = 1;
1464 while ($xnbp < $nbp) {
1466 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1467 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1468 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1471 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1473 $this->lines[] = $line;
1490 if ($user->hasRight(
'reception',
'creer')) {
1491 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1492 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1493 $sql .=
" WHERE rowid = ".((int) $this->
id);
1495 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1496 $resql = $this->db->query($sql);
1498 $this->date_delivery = $delivery_date;
1501 $this->error = $this->db->error();
1519 $this->meths = array();
1521 $sql =
"SELECT em.rowid, em.code, em.libelle";
1522 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1523 $sql .=
" WHERE em.active = 1";
1524 $sql .=
" ORDER BY em.libelle ASC";
1526 $resql = $this->db->query($sql);
1528 while ($obj = $this->db->fetch_object($resql)) {
1529 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1530 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1547 $this->listmeths = array();
1550 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1553 $sql .=
" WHERE em.rowid = ".((int) $id);
1556 $resql = $this->db->query($sql);
1558 while ($obj = $this->db->fetch_object($resql)) {
1559 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1560 $this->listmeths[$i][
'code'] = $obj->code;
1561 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1562 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1563 $this->listmeths[$i][
'description'] = $obj->description;
1564 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1565 $this->listmeths[$i][
'active'] = $obj->active;
1579 if (!empty($this->shipping_method_id)) {
1580 $sql =
"SELECT em.code, em.tracking";
1581 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1582 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1584 $resql = $this->db->query($sql);
1586 if ($obj = $this->db->fetch_object($resql)) {
1587 $tracking = $obj->tracking;
1592 if (!empty($tracking) && !empty($value)) {
1593 $url = str_replace(
'{TRACKID}', $value, $tracking);
1594 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1596 $this->tracking_url = $value;
1607 global $conf, $langs, $user;
1612 if ($this->
statut == Reception::STATUS_CLOSED) {
1613 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1619 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1620 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1622 $resql = $this->db->query($sql);
1625 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1627 $order->fetch($this->origin_id);
1629 $order->loadReceptions(self::STATUS_CLOSED);
1631 $receptions_match_order = 1;
1632 foreach ($order->lines as $line) {
1633 $lineid = $line->id;
1635 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1636 $receptions_match_order = 0;
1637 $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';
1642 if ($receptions_match_order) {
1643 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');
1644 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1648 $this->
statut = self::STATUS_CLOSED;
1649 $this->
status = self::STATUS_CLOSED;
1652 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1653 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1655 $langs->load(
"agenda");
1659 $sql =
"SELECT cd.fk_product, cd.subprice,";
1660 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1661 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1662 $sql .=
" ed.cost_price";
1663 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1664 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1665 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1666 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1668 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1669 $resql = $this->db->query($sql);
1672 $cpt = $this->db->num_rows($resql);
1673 for ($i = 0; $i < $cpt; $i++) {
1674 $obj = $this->db->fetch_object($resql);
1681 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1684 $mouvS->origin = &$this;
1685 $mouvS->setOrigin($this->element, $this->
id);
1687 if (empty($obj->batch)) {
1691 $inventorycode =
'';
1692 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1694 $this->error = $mouvS->error;
1695 $this->errors = $mouvS->errors;
1703 $inventorycode =
'';
1704 $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);
1707 $this->error = $mouvS->error;
1708 $this->errors = $mouvS->errors;
1715 $this->error = $this->db->lasterror();
1722 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1733 $this->db->commit();
1736 $this->
statut = self::STATUS_VALIDATED;
1737 $this->
status = self::STATUS_VALIDATED;
1738 $this->db->rollback();
1755 if ($this->
statut == Reception::STATUS_VALIDATED) {
1760 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1761 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1763 $resql = $this->db->query($sql);
1768 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1775 $this->errors[] = $this->db->lasterror;
1778 if (empty($error)) {
1779 $this->db->commit();
1782 $this->db->rollback();
1794 global $conf, $langs, $user;
1800 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1801 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1803 $resql = $this->db->query($sql);
1805 $this->
statut = self::STATUS_VALIDATED;
1806 $this->
status = self::STATUS_VALIDATED;
1810 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1811 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1812 $numref = $this->ref;
1813 $langs->load(
"agenda");
1817 $sql =
"SELECT ed.fk_product, cd.subprice,";
1818 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1819 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1820 $sql .=
" ed.cost_price";
1821 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1822 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1823 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1824 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1826 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1827 $resql = $this->db->query($sql);
1829 $cpt = $this->db->num_rows($resql);
1830 for ($i = 0; $i < $cpt; $i++) {
1831 $obj = $this->db->fetch_object($resql);
1839 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1843 $mouvS->origin = &$this;
1844 $mouvS->setOrigin($this->element, $this->
id);
1846 if (empty($obj->batch)) {
1850 $inventorycode =
'';
1851 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1854 $this->error = $mouvS->error;
1855 $this->errors = $mouvS->errors;
1863 $inventorycode =
'';
1864 $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);
1866 $this->error = $mouvS->error;
1867 $this->errors = $mouvS->errors;
1874 $this->error = $this->db->lasterror();
1881 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1887 if (!$error && $this->origin ==
'order_supplier') {
1889 $commande->fetch($this->origin_id);
1890 $result = $commande->setStatus($user, 4);
1893 $this->error = $commande->error;
1894 $this->errors = $commande->errors;
1899 $this->errors[] = $this->db->lasterror();
1903 $this->db->commit();
1906 $this->db->rollback();
1920 global $conf, $langs;
1925 if ($this->
statut <= self::STATUS_DRAFT) {
1929 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
1930 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
1931 $this->error =
'Permission denied';
1937 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1938 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1939 $sql .=
" WHERE rowid = ".((int) $this->
id);
1942 if ($this->db->query($sql)) {
1944 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
1945 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1947 $langs->load(
"agenda");
1951 $sql =
"SELECT cd.fk_product, cd.subprice,";
1952 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1953 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1954 $sql .=
" ed.cost_price";
1955 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1956 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1957 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1958 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1960 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1961 $resql = $this->db->query($sql);
1963 $cpt = $this->db->num_rows($resql);
1964 for ($i = 0; $i < $cpt; $i++) {
1965 $obj = $this->db->fetch_object($resql);
1973 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1977 $mouvS->origin = &$this;
1978 $mouvS->setOrigin($this->element, $this->
id);
1980 if (empty($obj->batch)) {
1984 $inventorycode =
'';
1985 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1987 $this->error = $mouvS->error;
1988 $this->errors = $mouvS->errors;
1996 $inventorycode =
'';
1997 $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);
1999 $this->error = $mouvS->error;
2000 $this->errors = $mouvS->errors;
2007 $this->error = $this->db->lasterror();
2014 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
2019 if ($this->origin ==
'order_supplier') {
2020 if (!empty($this->origin) && $this->origin_id > 0) {
2022 if ($this->origin_object->statut == 4) {
2024 $this->origin_object->fetchObjectLinked();
2026 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2027 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2028 if ($rcption->statut > 0) {
2035 $this->origin_object->setStatut(3);
2043 $this->
statut = self::STATUS_DRAFT;
2044 $this->
status = self::STATUS_DRAFT;
2045 $this->db->commit();
2048 $this->db->rollback();
2052 $this->error = $this->db->error();
2053 $this->db->rollback();
2068 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2070 global $conf, $langs;
2072 $langs->load(
"receptions");
2075 $modele =
'squille';
2077 if ($this->model_pdf) {
2078 $modele = $this->model_pdf;
2084 $modelpath =
"core/modules/reception/doc/";
2088 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2101 $tables = array(
'reception');
2117 'receptiondet_batch'
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0)
Return clicable 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 clicable 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.
trait CommonIncoterm
Superclass for incoterm classes.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db user
Active Directory does not allow anonymous connections.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut