39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/reception/class/receptionlinebatch.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
62 public $TRIGGER_PREFIX =
'RECEPTION';
72 public $element =
"reception";
77 public $fk_element =
"fk_reception";
82 public $table_element =
"reception";
87 public $table_element_line =
"receptiondet_batch";
92 public $picto =
'dollyrevert';
101 public $ref_supplier;
110 public $tracking_number;
114 public $tracking_url;
131 public $weight_units;
147 public $height_units;
167 public $user_author_id;
172 public $date_delivery;
184 public $date_reception;
203 public $lines = array();
210 public $detail_batch;
212 const STATUS_CANCELED = -1;
213 const STATUS_DRAFT = 0;
214 const STATUS_VALIDATED = 1;
215 const STATUS_CLOSED = 2;
227 $this->ismultientitymanaged = 1;
228 $this->isextrafieldmanaged = 1;
237 public function getNextNumRef($soc)
239 global $langs,
$conf;
240 $langs->load(
"receptions");
249 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
251 foreach ($dirmodels as $reldir) {
255 $mybool = ((bool) @include_once $dir.$file) || $mybool;
263 $obj =
new $classname();
264 '@phan-var-force ModelNumRefReception $obj';
267 $numref = $obj->getNextValue($soc, $this);
272 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
276 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
288 public function create($user, $notrigger = 0)
294 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
299 if (empty($this->fk_project)) {
300 $this->fk_project = 0;
302 if (empty($this->weight_units)) {
303 $this->weight_units = 0;
305 if (empty($this->size_units)) {
306 $this->size_units = 0;
308 if (empty($this->date_creation)) {
309 $this->date_creation = $now;
318 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
321 $sql .=
", ref_supplier";
322 $sql .=
", date_creation";
323 $sql .=
", fk_user_author";
324 $sql .=
", date_reception";
325 $sql .=
", date_delivery";
327 $sql .=
", fk_projet";
328 $sql .=
", fk_shipping_method";
329 $sql .=
", tracking_number";
334 $sql .=
", weight_units";
335 $sql .=
", size_units";
336 $sql .=
", note_private";
337 $sql .=
", note_public";
338 $sql .=
", model_pdf";
339 $sql .=
", fk_incoterms, location_incoterms";
340 $sql .=
") VALUES (";
342 $sql .=
", ".((int) $this->entity);
343 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
344 $sql .=
", '".$this->db->idate($this->date_creation).
"'";
345 $sql .=
", ".((int) $user->id);
346 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
347 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
348 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
349 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
350 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
351 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
352 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
353 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
354 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
355 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
356 $sql .=
", ".((int) $this->weight_units);
357 $sql .=
", ".((int) $this->size_units);
358 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
359 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
360 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
361 $sql .=
", ".(int) $this->fk_incoterms;
362 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
365 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
367 $resql = $this->db->query($sql);
370 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
373 $initialref =
'(PROV'.$this->id.
')';
374 if (!empty($this->
ref)) {
375 $initialref = $this->ref;
378 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
379 $sql .=
" SET ref = '".$this->db->escape($initialref).
"'";
380 $sql .=
" WHERE rowid = ".((int) $this->
id);
382 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
383 if ($this->db->query($sql)) {
385 $num = count($this->lines);
386 for ($i = 0; $i < $num; $i++) {
387 $this->lines[$i]->fk_reception = $this->id;
389 if ($this->lines[$i]->
create($user) <= 0) {
395 if (!$error && $this->
id && $this->origin_id) {
410 if (!$error && !$notrigger) {
412 $result = $this->call_trigger(
'RECEPTION_CREATE', $user);
423 foreach ($this->errors as $errmsg) {
424 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
425 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
427 $this->db->rollback();
432 $this->error = $this->db->lasterror().
" - sql=$sql";
433 $this->db->rollback();
438 $this->error = $this->db->error().
" - sql=$sql";
439 $this->db->rollback();
457 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
463 $receptionline->fk_reception = $this->id;
464 $receptionline->entrepot_id = $entrepot_id;
465 $receptionline->fk_elementdet = $origin_line_id;
466 $receptionline->element_type = $this->origin;
467 $receptionline->fk_parent = $parent_line_id;
468 $receptionline->fk_product = $product_id;
469 $receptionline->qty = $qty;
470 $receptionline->rang = $rang;
471 $receptionline->array_options = $array_options;
473 if (!($receptionline->fk_product > 0)) {
475 $order_line->fetch($receptionline->fk_elementdet);
476 $receptionline->fk_product = $order_line->fk_product;
479 if (($lineId = $receptionline->insert($user)) < 0) {
480 $this->errors[] = $receptionline->error;
493 public function fetch($id, $ref =
'', $ref_ext =
'')
496 if (empty($id) && empty($ref) && empty($ref_ext)) {
500 $sql =
"SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut as status, e.fk_projet as fk_project, e.billed";
501 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
502 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
503 $sql .=
", e.fk_shipping_method, e.tracking_number";
504 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
505 $sql .=
", e.note_private, e.note_public";
506 $sql .=
', e.fk_incoterms, e.location_incoterms';
507 $sql .=
', i.libelle as label_incoterms';
508 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
509 $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'";
510 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
513 $sql .=
" WHERE e.rowid = ".((int) $id);
515 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
517 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
518 } elseif ($ref_ext) {
519 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
523 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
524 $result = $this->db->query($sql);
526 if ($this->db->num_rows($result)) {
527 $obj = $this->db->fetch_object($result);
529 $this->
id = $obj->rowid;
530 $this->entity = $obj->entity;
531 $this->
ref = $obj->ref;
532 $this->socid = $obj->socid;
533 $this->ref_supplier = $obj->ref_supplier;
534 $this->ref_ext = $obj->ref_ext;
535 $this->statut = $obj->status;
536 $this->
status = $obj->status;
537 $this->billed = $obj->billed;
538 $this->fk_project = $obj->fk_project;
539 $this->user_author_id = $obj->fk_user_author;
540 $this->date_creation = $this->db->jdate($obj->date_creation);
541 $this->
date = $this->db->jdate($obj->date_reception);
542 $this->date_reception = $this->db->jdate($obj->date_reception);
543 $this->date_delivery = $this->db->jdate($obj->date_delivery);
544 $this->date_valid = $this->db->jdate($obj->date_valid);
545 $this->model_pdf = $obj->model_pdf;
546 $this->shipping_method_id = $obj->fk_shipping_method;
547 $this->tracking_number = $obj->tracking_number;
548 $this->origin = ($obj->origin ? $obj->origin :
'commande');
549 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
550 $this->origin_id = $obj->origin_id;
552 $this->trueWeight = $obj->weight;
553 $this->weight_units = $obj->weight_units;
555 $this->trueWidth = $obj->width;
556 $this->width_units = $obj->size_units;
557 $this->trueHeight = $obj->height;
558 $this->height_units = $obj->size_units;
559 $this->trueDepth = $obj->size;
560 $this->depth_units = $obj->size_units;
562 $this->note_public = $obj->note_public;
563 $this->note_private = $obj->note_private;
566 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
567 $this->size_units = $obj->size_units;
570 $this->fk_incoterms = $obj->fk_incoterms;
571 $this->location_incoterms = $obj->location_incoterms;
572 $this->label_incoterms = $obj->label_incoterms;
574 $this->db->free($result);
590 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
592 $extrafields->fetch_name_optionals_label($this->table_element,
true);
598 if (empty($obj->origin_id)) {
609 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
610 $this->error =
'Reception with id '.$id.
' not found';
614 $this->error = $this->db->error();
626 public function valid($user, $notrigger = 0)
628 global
$conf, $langs;
630 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
636 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
640 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
641 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
642 $this->error =
'Permission denied';
643 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
653 $soc->fetch($this->socid);
657 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
658 $numref = $this->getNextNumRef($soc);
668 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
669 $sql .=
" ref='".$this->db->escape($numref).
"'";
670 $sql .=
", fk_statut = 1";
671 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
672 $sql .=
", fk_user_valid = ".((int) $user->id);
673 $sql .=
" WHERE rowid = ".((int) $this->
id);
674 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
675 $resql = $this->db->query($sql);
677 $this->error = $this->db->lasterror();
683 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
685 $langs->load(
"agenda");
689 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
690 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
691 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
692 $sql .=
" ed.fk_elementdet, ed.cost_price";
693 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
694 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
695 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
696 $sql .=
" AND cd.rowid = ed.fk_elementdet";
698 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
699 $resql = $this->db->query($sql);
701 $cpt = $this->db->num_rows($resql);
702 for ($i = 0; $i < $cpt; $i++) {
703 $obj = $this->db->fetch_object($resql);
707 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
711 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
715 $mouvS->origin = &$this;
716 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
718 if (empty($obj->batch)) {
723 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
725 if (intval($result) < 0) {
736 $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);
738 if (intval($result) < 0) {
746 $this->db->rollback();
747 $this->error = $this->db->error();
752 if (!$error && $this->origin_id > 0) {
760 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
763 $this->errors = array_merge($this->errors, $this->origin_object->errors);
766 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
774 if (!$error && !$notrigger) {
776 $result = $this->call_trigger(
'RECEPTION_VALIDATE', $user);
784 $this->oldref = $this->ref;
787 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
789 $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).
"'";
790 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
791 $resql = $this->db->query($sql);
794 $this->error = $this->db->lasterror();
796 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
797 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
798 $resql = $this->db->query($sql);
801 $this->error = $this->db->lasterror();
807 $dirsource =
$conf->reception->dir_output.
'/'.$oldref;
808 $dirdest =
$conf->reception->dir_output.
'/'.$newref;
809 if (!$error && file_exists($dirsource)) {
810 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
812 if (@rename($dirsource, $dirdest)) {
815 $listoffiles =
dol_dir_list(
$conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
816 foreach ($listoffiles as $fileentry) {
817 $dirsource = $fileentry[
'name'];
818 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
819 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
820 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
821 @rename($dirsource, $dirdest);
830 $this->
ref = $numref;
831 $this->statut = self::STATUS_VALIDATED;
832 $this->
status = self::STATUS_VALIDATED;
839 foreach ($this->errors as $errmsg) {
840 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
841 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
843 $this->db->rollback();
855 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
856 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
860 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
861 if (empty($this->origin_object)) {
863 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
864 $res = $this->origin_object->fetch_lines();
865 $this->commandeFournisseur =
null;
869 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
870 $res = $this->origin_object->fetch_lines();
878 $qty_received = array();
879 $qty_wished = array();
882 $filter = array(
't.fk_element' => $this->origin_id);
884 $filter[
't.status'] = 1;
887 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
893 foreach ($supplierorderdispatch->lines as $dispatch_line) {
894 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
895 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
897 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
902 foreach ($this->origin_object->lines as $origin_line) {
904 if (($origin_line->product_type > 0 && (!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') || empty($origin_line->stockable_product))) || $origin_line->product_type > 1) {
907 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
908 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
910 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
915 $diff_array = array_diff_assoc($qty_received, $qty_wished);
916 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
917 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
919 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
925 if (count($diff_array) > 0) {
928 foreach ($diff_array as $key => $value) {
930 if ($qty_received[$key] >= $qty_wished[$key]) {
936 if ($close == count($diff_array)) {
963 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
965 global
$conf, $langs, $user;
967 $num = count($this->lines);
970 $line->fk_entrepot = $entrepot_id;
971 $line->fk_commandefourndet = $id;
975 $result = $supplierorderline->fetch($id);
982 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
983 $fk_product = $supplierorderline->fk_product;
985 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
986 $langs->load(
"errors");
987 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
993 $product =
new Product($this->db);
994 $product->fetch($fk_product);
996 $langs->load(
"errors");
997 if (!empty($product->status_batch) && empty($batch)) {
998 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
1000 } elseif (empty($product->status_batch) && !empty($batch)) {
1001 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
1007 if (!empty($errorMsgArr)) {
1008 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
1009 $errorMessage .=
'<ul>';
1010 foreach ($errorMsgArr as $errorMsg) {
1011 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
1013 $errorMessage .=
'</ul>';
1014 $this->error = $errorMessage;
1021 $line->array_options = $supplierorderline->array_options;
1022 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1023 foreach ($array_options as $key => $value) {
1024 $line->array_options[$key] = $value;
1028 $line->fk_product = $fk_product;
1029 $line->fk_commande = $supplierorderline->fk_commande;
1030 $line->fk_user = $user->id;
1031 $line->comment = $comment;
1032 $line->batch = $batch;
1033 $line->eatby = $eatby;
1034 $line->sellby = $sellby;
1036 $line->cost_price = $cost_price;
1037 $line->fk_reception = $this->id;
1039 $this->lines[$num] = $line;
1056 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options = [])
1058 global
$mysoc, $langs, $user;
1060 if ($this->
status == self::STATUS_DRAFT) {
1070 $ranktouse = $this->rang;
1071 if ($ranktouse == -1) {
1072 $rangmax = $this->
line_max($this->fk_reception);
1073 $ranktouse = $rangmax + 1;
1078 $this->line->fk_reception = $this->id;
1079 $this->line->element_type = $element_type;
1080 $this->line->fk_product = $fk_product;
1081 $this->line->description = $description;
1083 $this->line->qty = (float) $qty;
1084 $this->line->fk_unit = $fk_unit;
1085 $this->line->rang = $ranktouse;
1087 if (is_array($array_options) && count($array_options) > 0) {
1088 $this->line->array_options = $array_options;
1091 $result = $this->line->insert($user);
1093 if (!isset($this->context[
'createfromclone'])) {
1094 if ($this->fk_reception) {
1096 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1097 $linecount = count($this->lines);
1098 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1102 $this->lines[] = $this->line;
1105 $this->db->commit();
1106 return $this->line->id;
1108 $this->error = $this->line->error;
1109 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1110 $this->db->rollback();
1114 dol_syslog(get_class($this).
"::addlinefree status of reception must be Draft to allow use of ->addlinefree()", LOG_ERR);
1133 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options = array())
1135 global
$mysoc, $langs, $user;
1137 if ($this->statut == self::STATUS_DRAFT) {
1147 $qty = (float) $qty;
1148 $description = trim($description);
1153 $line->fetch($rowid);
1154 $line->fetch_optionals();
1156 if (!empty($line->fk_product)) {
1157 $product =
new Product($this->db);
1158 $result = $product->fetch($line->fk_product);
1159 $product_type = $product->type;
1162 $staticline = clone $line;
1164 $line->oldline = $staticline;
1165 $this->line = $line;
1166 $this->line->context = $this->context;
1167 $this->line->rang = $rang;
1168 $this->line->fk_reception = $this->id;
1169 $this->line->element_type = $element_type;
1170 $this->line->fk_product = $line->fk_product;
1171 $this->line->qty = $qty;
1172 $this->line->fk_unit = $fk_unit;
1173 $this->line->description = $description;
1175 if (is_array($array_options) && count($array_options) > 0) {
1177 foreach ($array_options as $key => $value) {
1178 $this->line->array_options[$key] = $array_options[$key];
1183 $result = $this->line->update($user, $notrigger);
1188 $this->db->commit();
1191 $this->error = $this->line->error;
1193 $this->db->rollback();
1197 $this->error = get_class($this).
"::updatelinefree reception status makes operation forbidden";
1198 $this->errors = array(
'ReceptionStatusMakeOperationForbidden');
1214 $this->lines = array();
1216 $sql =
'SELECT rc.rowid, rc.fk_reception, rc.fk_entrepot, rc.fk_product, rc.fk_unit, rc.description, rc.fk_elementdet, rc.fk_element, rc.element_type, rc.qty, rc.rang';
1217 $sql .=
' FROM '.MAIN_DB_PREFIX.
'receptiondet_batch as rc';
1218 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = rc.fk_product)';
1219 $sql .=
' WHERE rc.fk_reception = '.((int) $this->
id);
1221 $sql .=
' ORDER BY rc.rang, rc.rowid';
1223 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
1224 $result = $this->db->query($sql);
1226 $num = $this->db->num_rows($result);
1230 $objp = $this->db->fetch_object($result);
1234 $line->rowid = $objp->rowid;
1235 $line->id = $objp->rowid;
1236 $line->fk_reception = $this->id;
1238 $line->description = $objp->description;
1239 $line->qty = $objp->qty;
1240 $line->fk_entrepot = $objp->fk_entrepot;
1241 $line->fk_product = $objp->fk_product;
1243 $line->rang = $objp->rang;
1246 $line->fk_element = $objp->fk_element;
1247 $line->fk_unit = $objp->fk_unit;
1248 $line->fk_elementdet = $objp->fk_elementdet;
1249 $line->fk_element_type = $objp->element_type;
1250 $line->fetch_optionals();
1254 $this->lines[$i] = $line;
1259 $this->db->free($result);
1263 $this->error = $this->db->error();
1285 public function update($user =
null, $notrigger = 0)
1292 if (isset($this->
ref)) {
1293 $this->
ref = trim($this->
ref);
1295 if (isset($this->entity)) {
1296 $this->entity = (int) $this->entity;
1298 if (isset($this->ref_supplier)) {
1299 $this->ref_supplier = trim($this->ref_supplier);
1301 if (isset($this->socid)) {
1302 $this->socid = (int) trim((
string) $this->socid);
1304 if (isset($this->fk_user_author)) {
1305 $this->fk_user_author = (int) $this->fk_user_author;
1307 if (isset($this->fk_user_valid)) {
1308 $this->fk_user_valid = (int) $this->fk_user_valid;
1310 if (isset($this->shipping_method_id)) {
1311 $this->shipping_method_id = (int) $this->shipping_method_id;
1313 if (isset($this->tracking_number)) {
1314 $this->tracking_number = trim($this->tracking_number);
1316 if (isset($this->statut)) {
1317 $this->statut = (int) $this->statut;
1319 if (isset($this->trueDepth)) {
1320 $this->trueDepth =
price2num($this->trueDepth);
1322 if (isset($this->trueWidth)) {
1323 $this->trueWidth =
price2num($this->trueWidth);
1325 if (isset($this->trueHeight)) {
1326 $this->trueHeight =
price2num($this->trueHeight);
1328 $this->size_units = (int) $this->size_units;
1330 if (isset($this->trueWeight)) {
1331 $this->weight =
price2num($this->trueWeight);
1333 $this->weight_units = (int) $this->weight_units;
1335 if (isset($this->note_private)) {
1336 $this->note_private = trim($this->note_private);
1338 if (isset($this->note_public)) {
1339 $this->note_public = trim($this->note_public);
1341 if (isset($this->model_pdf)) {
1342 $this->model_pdf = trim($this->model_pdf);
1350 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1352 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1353 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1354 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1355 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1356 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1357 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1358 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1359 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1360 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1361 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1362 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1363 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1364 $sql .=
" height=".(($this->trueHeight !=
'') ? (
float) $this->trueHeight :
"null").
",";
1365 $sql .=
" width=".(($this->trueWidth !=
'') ? (
float) $this->trueWidth :
"null").
",";
1366 $sql .=
" size_units=".((int) $this->size_units).
",";
1367 $sql .=
" size=".(($this->trueDepth !=
'') ? (
float) $this->trueDepth :
"null").
",";
1368 $sql .=
" weight_units=".((int) $this->weight_units).
",";
1369 $sql .=
" weight=".(($this->trueWeight !=
'') ? (
float) $this->trueWeight :
"null").
",";
1370 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1371 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1372 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1373 $sql .=
" fk_projet=".((isset($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1374 $sql .=
" entity = ".((int)
$conf->entity);
1375 $sql .=
" WHERE rowid=".((int) $this->
id);
1379 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1380 $resql = $this->db->query($sql);
1383 $this->errors[] =
"Error ".$this->db->lasterror();
1389 $result = $this->call_trigger(
'RECEPTION_MODIFY', $user);
1399 foreach ($this->errors as $errmsg) {
1400 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1401 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1403 $this->db->rollback();
1406 $this->db->commit();
1417 public function delete(
User $user)
1419 global
$conf, $langs, $user;
1420 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1430 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1432 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1434 $langs->load(
"agenda");
1437 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1439 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1440 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1441 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1443 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1444 $resql = $this->db->query($sql);
1446 $cpt = $this->db->num_rows($resql);
1447 for ($i = 0; $i < $cpt; $i++) {
1448 dol_syslog(get_class($this).
"::delete movement index ".$i);
1449 $obj = $this->db->fetch_object($resql);
1453 $mouvS->origin =
null;
1455 $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);
1458 $this->error = $mouvS->error;
1459 $this->errors = $mouvS->errors;
1464 $this->errors[] =
"Error ".$this->db->lasterror();
1469 $main = MAIN_DB_PREFIX.
'receptiondet_batch';
1470 $ef = $main.
"_extrafields";
1472 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1474 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1475 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1477 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1485 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1486 $sql .=
" WHERE rowid = ".((int) $this->
id);
1488 if ($this->db->query($sql)) {
1490 $result = $this->call_trigger(
'RECEPTION_DELETE', $user);
1496 if (!empty($this->origin) && $this->origin_id > 0) {
1499 '@phan-var-force CommandeFournisseur $origin_object';
1512 $this->db->commit();
1516 if (!empty(
$conf->reception->dir_output)) {
1517 $dir =
$conf->reception->dir_output.
'/'.$ref;
1518 $file = $dir.
'/'.$ref.
'.pdf';
1519 if (file_exists($file)) {
1524 if (file_exists($dir)) {
1526 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1534 $this->db->rollback();
1538 $this->error = $this->db->lasterror().
" - sql=$sql";
1539 $this->db->rollback();
1543 $this->error = $this->db->lasterror().
" - sql=$sql";
1544 $this->db->rollback();
1548 $this->error = $this->db->lasterror().
" - sql=$sql";
1549 $this->db->rollback();
1553 $this->db->rollback();
1567 $this->lines = array();
1569 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1571 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1572 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1574 $resql = $this->db->query($sql);
1576 if (!empty($resql)) {
1577 while ($obj = $this->db->fetch_object($resql)) {
1580 $line->fetch($obj->rowid);
1583 $line->fetch_product();
1585 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1586 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1587 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1588 $sql_commfourndet .=
' ORDER BY rang';
1590 $resql_commfourndet = $this->db->query($sql_commfourndet);
1591 if (!empty($resql_commfourndet)) {
1592 $obj = $this->db->fetch_object($resql_commfourndet);
1593 $line->qty_asked = $obj->qty;
1594 $line->description = $obj->description;
1595 $line->desc = $obj->description;
1596 $line->tva_tx = $obj->tva_tx;
1597 $line->vat_src_code = $obj->vat_src_code;
1598 $line->subprice = $obj->subprice;
1599 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1600 $line->remise_percent = $obj->remise_percent;
1601 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1602 $line->ref_supplier = $obj->ref;
1603 $line->total_ht = $obj->total_ht;
1604 $line->total_ttc = $obj->total_ttc;
1605 $line->total_tva = $obj->total_tva;
1607 $line->qty_asked = 0;
1608 $line->description =
'';
1610 $line->label = $obj->label;
1613 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1614 $tva = $pu_ht * $line->tva_tx / 100;
1615 $this->total_ht += $pu_ht;
1616 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1618 $this->total_ttc += $pu_ht + $tva;
1620 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1622 $detail_batch->eatby = $line->eatby;
1623 $detail_batch->sellby = $line->sellby;
1624 $detail_batch->batch = $line->batch;
1625 $detail_batch->qty = $line->qty;
1627 $line->detail_batch[] = $detail_batch;
1630 $this->lines[] = $line;
1649 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0)
1651 global $langs, $hookmanager;
1654 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1655 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1656 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1658 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1665 if (empty($notooltip)) {
1667 $label = $langs->trans(
"Reception");
1668 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1670 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1671 $linkclose .=
' class="classfortooltip"';
1674 $linkstart =
'<a href="'.$url.
'"';
1675 $linkstart .= $linkclose.
'>';
1678 $result .= $linkstart;
1680 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1682 if ($withpicto != 2) {
1683 $result .= $this->ref;
1686 $result .= $linkend;
1689 $hookmanager->initHooks(array($this->element .
'dao'));
1690 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1691 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1693 $result = $hookmanager->resPrint;
1695 $result .= $hookmanager->resPrint;
1708 return $this->
LibStatut($this->statut, $mode);
1725 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1726 $this->labelStatus[0] =
'StatusReceptionDraft';
1728 $this->labelStatus[1] =
'StatusReceptionValidated';
1730 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1733 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1735 $this->labelStatus[2] =
'StatusReceptionProcessed';
1738 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1739 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1740 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1741 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1743 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1744 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1746 $statusType =
'status'.$status;
1747 if ($status == self::STATUS_VALIDATED) {
1748 $statusType =
'status4';
1750 if ($status == self::STATUS_CLOSED) {
1751 $statusType =
'status6';
1754 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1766 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1768 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1769 $return .=
'<div class="info-box info-box-sm">';
1770 $return .=
'<div class="info-box-icon bg-infobox-action">';
1772 $return .=
'</div>';
1773 $return .=
'<div class="info-box-content">';
1774 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1775 if ($selected >= 0) {
1776 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1778 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1779 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1784 if (method_exists($this,
'getLibStatut')) {
1785 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1787 $return .=
'</div>';
1788 $return .=
'</div>';
1789 $return .=
'</div>';
1805 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1806 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1809 dol_syslog(get_class($this).
"::initAsSpecimen");
1812 $order->initAsSpecimen();
1816 $this->
ref =
'SPECIMEN';
1817 $this->specimen = 1;
1821 $this->date_creation = $now;
1822 $this->date_valid = $now;
1823 $this->date_delivery = $now;
1824 $this->date_reception = $now + 24 * 3600;
1825 $this->entrepot_id = 0;
1827 $this->origin_id = 1;
1828 $this->origin_type =
'supplier_order';
1829 $this->origin_object = $order;
1830 $this->note_private =
'Private note';
1831 $this->note_public =
'Public note';
1832 $this->tracking_number =
'TRACKID-ABC123';
1833 $this->fk_incoterms = 1;
1836 while ($xnbp < $nbp) {
1838 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1839 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1840 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1843 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1845 $this->lines[] = $line;
1862 if ($user->hasRight(
'reception',
'creer')) {
1863 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1864 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1865 $sql .=
" WHERE rowid = ".((int) $this->
id);
1867 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1868 $resql = $this->db->query($sql);
1870 $this->date_delivery = $delivery_date;
1873 $this->error = $this->db->error();
1890 if ($user->hasRight(
'reception',
'creer')) {
1891 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1892 $sql .=
" SET date_reception = ".($reception_date ?
"'".$this->db->idate($reception_date).
"'" :
'null');
1893 $sql .=
" WHERE rowid = ".((int) $this->
id);
1895 dol_syslog(get_class($this).
"::setReceptionDate", LOG_DEBUG);
1896 $resql = $this->db->query($sql);
1898 $this->date_reception = $reception_date;
1901 $this->error = $this->db->error();
1919 $this->meths = array();
1921 $sql =
"SELECT em.rowid, em.code, em.libelle";
1922 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1923 $sql .=
" WHERE em.active = 1";
1924 $sql .=
" ORDER BY em.libelle ASC";
1926 $resql = $this->db->query($sql);
1928 while ($obj = $this->db->fetch_object($resql)) {
1929 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1930 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1947 $this->listmeths = array();
1950 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1951 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1953 $sql .=
" WHERE em.rowid = ".((int) $id);
1956 $resql = $this->db->query($sql);
1958 while ($obj = $this->db->fetch_object($resql)) {
1959 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1960 $this->listmeths[$i][
'code'] = $obj->code;
1961 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1962 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1963 $this->listmeths[$i][
'description'] = $obj->description;
1964 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1965 $this->listmeths[$i][
'active'] = $obj->active;
1979 if (!empty($this->shipping_method_id)) {
1980 $sql =
"SELECT em.code, em.tracking";
1981 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1982 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1984 $resql = $this->db->query($sql);
1986 if ($obj = $this->db->fetch_object($resql)) {
1987 $tracking = $obj->tracking;
1992 if (!empty($tracking) && !empty($value)) {
1993 $url = str_replace(
'{TRACKID}', $value, $tracking);
1994 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1996 $this->tracking_url = $value;
2007 global
$conf, $langs, $user;
2012 if ($this->statut == Reception::STATUS_CLOSED) {
2013 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
2019 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
2020 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2022 $resql = $this->db->query($sql);
2025 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
2026 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2029 $order->fetch($this->origin_id);
2031 $order->loadReceptions(self::STATUS_CLOSED);
2033 $receptions_match_order = 1;
2034 foreach ($order->lines as $line) {
2035 $lineid = $line->id;
2037 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
2038 $receptions_match_order = 0;
2039 $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';
2044 if ($receptions_match_order) {
2045 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');
2046 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
2050 $this->statut = self::STATUS_CLOSED;
2051 $this->
status = self::STATUS_CLOSED;
2055 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2057 $langs->load(
"agenda");
2061 $sql =
"SELECT cd.fk_product, cd.subprice,";
2062 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2063 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2064 $sql .=
" ed.fk_elementdet, ed.cost_price";
2065 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2066 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2067 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2068 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2070 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2071 $resql = $this->db->query($sql);
2074 $cpt = $this->db->num_rows($resql);
2075 for ($i = 0; $i < $cpt; $i++) {
2076 $obj = $this->db->fetch_object($resql);
2084 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
2087 $mouvS->origin = &$this;
2088 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2090 if (empty($obj->batch)) {
2094 $inventorycode =
'';
2095 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2097 $this->error = $mouvS->error;
2098 $this->errors = $mouvS->errors;
2106 $inventorycode =
'';
2107 $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);
2110 $this->error = $mouvS->error;
2111 $this->errors = $mouvS->errors;
2118 $this->error = $this->db->lasterror();
2125 $result = $this->call_trigger(
'RECEPTION_CLOSED', $user);
2136 $this->db->commit();
2139 $this->statut = self::STATUS_VALIDATED;
2140 $this->
status = self::STATUS_VALIDATED;
2141 $this->db->rollback();
2158 if ($this->statut == Reception::STATUS_VALIDATED) {
2163 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
2164 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2166 $resql = $this->db->query($sql);
2171 $result = $this->call_trigger(
'RECEPTION_BILLED', $user);
2178 $this->errors[] = $this->db->lasterror;
2181 if (empty($error)) {
2182 $this->db->commit();
2185 $this->db->rollback();
2197 global $langs, $user;
2203 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
2204 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2206 $resql = $this->db->query($sql);
2207 $rollbackStatus = $this->status;
2208 $rollbackBilled = $this->billed;
2210 $this->statut = self::STATUS_VALIDATED;
2211 $this->
status = self::STATUS_VALIDATED;
2216 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2218 $langs->load(
"agenda");
2222 $sql =
"SELECT ed.fk_product, cd.subprice,";
2223 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2224 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2225 $sql .=
" ed.fk_elementdet, ed.cost_price";
2226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2227 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2228 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2229 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2231 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2232 $resql = $this->db->query($sql);
2234 $cpt = $this->db->num_rows($resql);
2235 for ($i = 0; $i < $cpt; $i++) {
2236 $obj = $this->db->fetch_object($resql);
2243 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2247 $mouvS->origin = &$this;
2248 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2250 if (empty($obj->batch)) {
2254 $inventorycode =
'';
2255 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
2258 $this->error = $mouvS->error;
2259 $this->errors = $mouvS->errors;
2267 $inventorycode =
'';
2268 $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);
2270 $this->error = $mouvS->error;
2271 $this->errors = $mouvS->errors;
2278 $this->error = $this->db->lasterror();
2285 $result = $this->call_trigger(
'RECEPTION_REOPEN', $user);
2291 if (!$error && $this->origin ==
'order_supplier') {
2292 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2295 $commande->fetch($this->origin_id);
2296 $result = $commande->setStatus($user, 4);
2299 $this->error = $commande->error;
2300 $this->errors = $commande->errors;
2305 $this->errors[] = $this->db->lasterror();
2309 $this->db->commit();
2312 $this->statut = $this->
status = $rollbackStatus;
2313 $this->billed = $rollbackBilled;
2314 $this->db->rollback();
2328 global
$conf, $langs;
2333 if ($this->statut <= self::STATUS_DRAFT) {
2337 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2338 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2339 $this->error =
'Permission denied';
2345 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2346 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2347 $sql .=
" WHERE rowid = ".((int) $this->
id);
2350 if ($this->db->query($sql)) {
2353 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2355 $langs->load(
"agenda");
2359 $sql =
"SELECT cd.fk_product, cd.subprice,";
2360 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2361 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2362 $sql .=
" ed.fk_elementdet, ed.cost_price";
2363 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2364 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2365 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2366 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2368 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2369 $resql = $this->db->query($sql);
2371 $cpt = $this->db->num_rows($resql);
2372 for ($i = 0; $i < $cpt; $i++) {
2373 $obj = $this->db->fetch_object($resql);
2381 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2385 $mouvS->origin = &$this;
2386 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2388 if (empty($obj->batch)) {
2392 $inventorycode =
'';
2393 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2395 $this->error = $mouvS->error;
2396 $this->errors = $mouvS->errors;
2404 $inventorycode =
'';
2405 $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);
2407 $this->error = $mouvS->error;
2408 $this->errors = $mouvS->errors;
2415 $this->error = $this->db->lasterror();
2422 $result = $this->call_trigger(
'RECEPTION_UNVALIDATE', $user);
2427 if ($this->origin ==
'order_supplier') {
2428 if (!empty($this->origin) && $this->origin_id > 0) {
2430 if ($this->origin_object->statut == 4) {
2432 $this->origin_object->fetchObjectLinked();
2434 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2435 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2436 if ($rcption->statut > 0) {
2443 $this->origin_object->setStatut(3);
2451 $this->statut = self::STATUS_DRAFT;
2452 $this->
status = self::STATUS_DRAFT;
2453 $this->db->commit();
2456 $this->db->rollback();
2460 $this->error = $this->db->error();
2461 $this->db->rollback();
2476 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2478 global
$conf, $langs;
2480 $langs->load(
"receptions");
2483 $modele =
'squille';
2485 if ($this->model_pdf) {
2486 $modele = $this->model_pdf;
2492 $modelpath =
"core/modules/reception/doc/";
2496 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2509 $tables = array(
'reception');
2525 '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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options=array())
Update a simple reception line.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLinesArray()
Create an array of reception lines.
fetch_lines_free()
Load lines of simple reception.
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this records also the stock movement)
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0)
Return clickable link of object (with eventually picto)
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a reception line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
__construct($db)
Constructor.
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options=[])
Add a simple reception line.
initAsSpecimen()
Initialise an instance with random values.
setReceptionDate($user, $reception_date)
Set the reception date.
create($user, $notrigger=0)
Create reception.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
addline($entrepot_id, $id, $qty, $array_options=[], $comment='', $eatby=null, $sellby=null, $batch='', $cost_price=0)
Add an reception line.
setDraft($user)
Set draft status.
Class to manage table commandefournisseurdispatch.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
$conf db user
Active Directory does not allow anonymous connections.