36require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
38require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
39if (isModEnabled(
"propal")) {
40 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
42if (isModEnabled(
'commande')) {
43 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
62 public $element =
"reception";
67 public $fk_element =
"fk_reception";
68 public $table_element =
"reception";
69 public $table_element_line =
"commande_fournisseur_dispatch";
70 public $ismultientitymanaged = 1;
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 $commandeFournisseur;
135 public $lines = array();
140 public $detail_batch;
142 const STATUS_DRAFT = 0;
143 const STATUS_VALIDATED = 1;
144 const STATUS_CLOSED = 2;
166 global $langs, $conf;
167 $langs->load(
"receptions");
173 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
176 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
178 foreach ($dirmodels as $reldir) {
182 $mybool |= @include_once $dir.$file;
190 $obj =
new $classname();
193 $numref = $obj->getNextValue($soc, $this);
198 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
202 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
214 public function create($user, $notrigger = 0)
220 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
225 if (empty($this->fk_project)) {
226 $this->fk_project = 0;
228 if (empty($this->weight_units)) {
229 $this->weight_units = 0;
231 if (empty($this->size_units)) {
232 $this->size_units = 0;
239 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
242 $sql .=
", ref_supplier";
243 $sql .=
", date_creation";
244 $sql .=
", fk_user_author";
245 $sql .=
", date_reception";
246 $sql .=
", date_delivery";
248 $sql .=
", fk_projet";
249 $sql .=
", fk_shipping_method";
250 $sql .=
", tracking_number";
255 $sql .=
", weight_units";
256 $sql .=
", size_units";
257 $sql .=
", note_private";
258 $sql .=
", note_public";
259 $sql .=
", model_pdf";
260 $sql .=
", fk_incoterms, location_incoterms";
261 $sql .=
") VALUES (";
263 $sql .=
", ".((int) $conf->entity);
264 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
265 $sql .=
", '".$this->db->idate($now).
"'";
266 $sql .=
", ".((int) $user->id);
267 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
268 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
269 $sql .=
", ".((int) $this->socid);
270 $sql .=
", ".((int) $this->fk_project);
271 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
272 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
273 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
274 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
275 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
276 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
277 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((float) $this->weight_units));
278 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((float) $this->size_units));
279 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
280 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
281 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
282 $sql .=
", ".(int) $this->fk_incoterms;
283 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
286 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
288 $resql = $this->db->query($sql);
291 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
293 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
294 $sql .=
" SET ref = '(PROV".$this->id.
")'";
295 $sql .=
" WHERE rowid = ".((int) $this->
id);
297 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
298 if ($this->db->query($sql)) {
300 $num = count($this->lines);
301 for ($i = 0; $i < $num; $i++) {
302 $this->lines[$i]->fk_reception = $this->id;
304 if (!$this->lines[$i]->
create($user) > 0) {
309 if (!$error && $this->
id && $this->origin_id) {
324 if (!$error && !$notrigger) {
326 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
337 foreach ($this->errors as $errmsg) {
338 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
339 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
341 $this->db->rollback();
346 $this->error = $this->db->lasterror().
" - sql=$sql";
347 $this->db->rollback();
352 $this->error = $this->db->error().
" - sql=$sql";
353 $this->db->rollback();
368 public function fetch($id, $ref =
'', $ref_ext =
'')
371 if (empty($id) && empty($ref) && empty($ref_ext)) {
375 $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";
376 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
377 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
378 $sql .=
", e.fk_shipping_method, e.tracking_number";
379 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
380 $sql .=
", e.note_private, e.note_public";
381 $sql .=
', e.fk_incoterms, e.location_incoterms';
382 $sql .=
', i.libelle as label_incoterms';
383 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
384 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
385 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
386 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
388 $sql .=
" AND e.rowid = ".((int) $id);
391 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
394 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
397 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
398 $result = $this->db->query($sql);
400 if ($this->db->num_rows($result)) {
401 $obj = $this->db->fetch_object($result);
403 $this->
id = $obj->rowid;
404 $this->entity = $obj->entity;
405 $this->
ref = $obj->ref;
406 $this->socid = $obj->socid;
407 $this->ref_supplier = $obj->ref_supplier;
408 $this->ref_ext = $obj->ref_ext;
409 $this->
statut = $obj->status;
410 $this->
status = $obj->status;
411 $this->billed = $obj->billed;
413 $this->user_author_id = $obj->fk_user_author;
414 $this->date_creation = $this->db->jdate($obj->date_creation);
415 $this->date = $this->db->jdate($obj->date_reception);
416 $this->date_reception = $this->db->jdate($obj->date_reception);
417 $this->date_delivery = $this->db->jdate($obj->date_delivery);
418 $this->model_pdf = $obj->model_pdf;
419 $this->shipping_method_id = $obj->fk_shipping_method;
420 $this->tracking_number = $obj->tracking_number;
421 $this->origin = ($obj->origin ? $obj->origin :
'commande');
422 $this->origin_id = $obj->origin_id;
424 $this->trueWeight = $obj->weight;
425 $this->weight_units = $obj->weight_units;
427 $this->trueWidth = $obj->width;
428 $this->width_units = $obj->size_units;
429 $this->trueHeight = $obj->height;
430 $this->height_units = $obj->size_units;
431 $this->trueDepth = $obj->size;
432 $this->depth_units = $obj->size_units;
434 $this->note_public = $obj->note_public;
435 $this->note_private = $obj->note_private;
438 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
439 $this->size_units = $obj->size_units;
442 $this->fk_incoterms = $obj->fk_incoterms;
443 $this->location_incoterms = $obj->location_incoterms;
444 $this->label_incoterms = $obj->label_incoterms;
446 $this->db->free($result);
462 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
464 $extrafields->fetch_name_optionals_label($this->table_element,
true);
477 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
478 $this->error =
'Reception with id '.$id.
' not found';
482 $this->error = $this->db->error();
494 public function valid($user, $notrigger = 0)
496 global $conf, $langs;
498 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
504 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
508 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
509 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
510 $this->error =
'Permission denied';
511 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
521 $soc->fetch($this->socid);
525 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
528 $numref = $this->ref;
536 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
537 $sql .=
" ref='".$this->db->escape($numref).
"'";
538 $sql .=
", fk_statut = 1";
539 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
540 $sql .=
", fk_user_valid = ".$user->id;
541 $sql .=
" WHERE rowid = ".((int) $this->
id);
542 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
543 $resql = $this->db->query($sql);
545 $this->error = $this->db->lasterror();
550 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
551 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
553 $langs->load(
"agenda");
557 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
558 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
559 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
560 $sql .=
" ed.cost_price";
561 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
562 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
563 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
564 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
566 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
567 $resql = $this->db->query($sql);
569 $cpt = $this->db->num_rows($resql);
570 for ($i = 0; $i < $cpt; $i++) {
571 $obj = $this->db->fetch_object($resql);
575 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
578 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
582 $mouvS->origin = &$this;
583 $mouvS->setOrigin($this->element, $this->
id);
585 if (empty($obj->batch)) {
590 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
592 if (intval($result) < 0) {
594 $this->errors[] = $mouvS->error;
595 $this->errors = array_merge($this->errors, $mouvS->errors);
604 $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);
606 if (intval($result) < 0) {
608 $this->errors[] = $mouvS->error;
609 $this->errors = array_merge($this->errors, $mouvS->errors);
615 $this->db->rollback();
616 $this->error = $this->db->error();
628 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
631 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
634 $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 (empty($this->origin_object->lines)) {
731 $res = $this->origin_object->fetch_lines();
732 $this->commandeFournisseur = $this->origin_object;
739 $qty_received = array();
740 $qty_wished = array();
743 $filter = array(
't.fk_commande'=>$this->origin_id);
745 $filter[
't.status'] = 1;
748 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
750 $this->error = $supplierorderdispatch->error;
751 $this->errors = $supplierorderdispatch->errors;
755 foreach ($supplierorderdispatch->lines as $dispatch_line) {
756 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
757 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
759 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
764 foreach ($this->commandeFournisseur->lines as $origin_line) {
766 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
770 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
774 $diff_array = array_diff_assoc($qty_received, $qty_wished);
775 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
776 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
778 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
784 if (count($diff_array) > 0) {
787 foreach ($diff_array as $key => $value) {
789 if ($qty_received[$key] >= $qty_wished[$key]) {
795 if ($close == count($diff_array)) {
822 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
824 global $conf, $langs, $user;
826 $num = count($this->lines);
829 $line->fk_entrepot = $entrepot_id;
830 $line->fk_commandefourndet = $id;
834 $result = $supplierorderline->fetch($id);
836 $this->error = $supplierorderline->error;
837 $this->errors = $supplierorderline->errors;
842 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
843 $fk_product = $supplierorderline->fk_product;
845 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
846 $langs->load(
"errors");
847 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
853 $product =
new Product($this->db);
854 $product->fetch($fk_product);
855 if (isModEnabled(
'productbatch')) {
856 $langs->load(
"errors");
857 if (!empty($product->status_batch) && empty($batch)) {
858 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
860 } elseif (empty($product->status_batch) && !empty($batch)) {
861 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
868 $line->array_options = $supplierorderline->array_options;
869 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
870 foreach ($array_options as $key => $value) {
871 $line->array_options[$key] = $value;
875 $line->fk_product = $fk_product;
876 $line->fk_commande = $supplierorderline->fk_commande;
877 $line->fk_user = $user->id;
878 $line->comment = $comment;
879 $line->batch = $batch;
880 $line->eatby = $eatby;
881 $line->sellby = $sellby;
883 $line->cost_price = $cost_price;
884 $line->fk_reception = $this->id;
886 $this->lines[$num] = $line;
899 public function update($user =
null, $notrigger = 0)
906 if (isset($this->
ref)) {
907 $this->
ref = trim($this->
ref);
909 if (isset($this->entity)) {
910 $this->entity = trim($this->entity);
912 if (isset($this->ref_supplier)) {
913 $this->ref_supplier = trim($this->ref_supplier);
915 if (isset($this->socid)) {
916 $this->socid = trim($this->socid);
918 if (isset($this->fk_user_author)) {
919 $this->fk_user_author = trim($this->fk_user_author);
921 if (isset($this->fk_user_valid)) {
922 $this->fk_user_valid = trim($this->fk_user_valid);
924 if (isset($this->shipping_method_id)) {
925 $this->shipping_method_id = trim($this->shipping_method_id);
927 if (isset($this->tracking_number)) {
928 $this->tracking_number = trim($this->tracking_number);
930 if (isset($this->
statut)) {
933 if (isset($this->trueDepth)) {
934 $this->trueDepth = trim($this->trueDepth);
936 if (isset($this->trueWidth)) {
937 $this->trueWidth = trim($this->trueWidth);
939 if (isset($this->trueHeight)) {
940 $this->trueHeight = trim($this->trueHeight);
942 if (isset($this->size_units)) {
943 $this->size_units = trim($this->size_units);
945 if (isset($this->weight_units)) {
946 $this->weight_units = trim($this->weight_units);
948 if (isset($this->trueWeight)) {
949 $this->weight = trim($this->trueWeight);
951 if (isset($this->note_private)) {
952 $this->note_private = trim($this->note_private);
954 if (isset($this->note_public)) {
955 $this->note_public = trim($this->note_public);
957 if (isset($this->model_pdf)) {
958 $this->model_pdf = trim($this->model_pdf);
966 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
968 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
969 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
970 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
971 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
972 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
973 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
974 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
975 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
976 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
977 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
978 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
979 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
980 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
981 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
982 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
983 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
984 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
985 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
986 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
987 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
988 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
989 $sql .=
" entity = ".((int) $conf->entity);
990 $sql .=
" WHERE rowid=".((int) $this->
id);
994 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
995 $resql = $this->db->query($sql);
998 $this->errors[] =
"Error ".$this->db->lasterror();
1004 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1014 foreach ($this->errors as $errmsg) {
1015 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1016 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1018 $this->db->rollback();
1021 $this->db->commit();
1034 global $conf, $langs, $user;
1035 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1044 if (isModEnabled(
'stock') && !
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION') && $this->
statut > 0) {
1045 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1047 $langs->load(
"agenda");
1050 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as commande_fournisseur_dispatch_id";
1051 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1052 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1053 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1054 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1056 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1057 $resql = $this->db->query($sql);
1059 $cpt = $this->db->num_rows($resql);
1060 for ($i = 0; $i < $cpt; $i++) {
1061 dol_syslog(get_class($this).
"::delete movement index ".$i);
1062 $obj = $this->db->fetch_object($resql);
1066 $mouvS->origin =
null;
1068 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1071 $this->error = $mouvS->error;
1072 $this->errors = $mouvS->errors;
1077 $this->errors[] =
"Error ".$this->db->lasterror();
1082 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1083 $ef = $main.
"_extrafields";
1085 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1087 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1088 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1090 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1098 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1099 $sql .=
" WHERE rowid = ".((int) $this->
id);
1101 if ($this->db->query($sql)) {
1103 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1109 if (!empty($this->origin) && $this->origin_id > 0) {
1111 $origin = $this->origin;
1112 if ($this->$origin->statut == 4) {
1114 $this->$origin->loadReceptions();
1116 if (count($this->$origin->receptions) <= 0) {
1117 $this->$origin->setStatut(3);
1123 $this->db->commit();
1127 if (!empty($conf->reception->dir_output)) {
1128 $dir = $conf->reception->dir_output.
'/'.$ref;
1129 $file = $dir.
'/'.$ref.
'.pdf';
1130 if (file_exists($file)) {
1135 if (file_exists($dir)) {
1137 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1145 $this->db->rollback();
1149 $this->error = $this->db->lasterror().
" - sql=$sql";
1150 $this->db->rollback();
1154 $this->error = $this->db->lasterror().
" - sql=$sql";
1155 $this->db->rollback();
1159 $this->error = $this->db->lasterror().
" - sql=$sql";
1160 $this->db->rollback();
1164 $this->db->rollback();
1178 $this->lines = array();
1180 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1182 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1183 $resql = $this->db->query($sql);
1185 if (!empty($resql)) {
1186 while ($obj = $this->db->fetch_object($resql)) {
1189 $line->fetch($obj->rowid);
1192 $line->fetch_product();
1194 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1195 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1196 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1197 $sql_commfourndet .=
' ORDER BY rang';
1199 $resql_commfourndet = $this->db->query($sql_commfourndet);
1200 if (!empty($resql_commfourndet)) {
1201 $obj = $this->db->fetch_object($resql_commfourndet);
1202 $line->qty_asked = $obj->qty;
1203 $line->description = $obj->description;
1204 $line->desc = $obj->description;
1205 $line->tva_tx = $obj->tva_tx;
1206 $line->vat_src_code = $obj->vat_src_code;
1207 $line->subprice = $obj->subprice;
1208 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1209 $line->remise_percent = $obj->remise_percent;
1210 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1211 $line->ref_supplier = $obj->ref;
1212 $line->total_ht = $obj->total_ht;
1213 $line->total_ttc = $obj->total_ttc;
1214 $line->total_tva = $obj->total_tva;
1216 $line->qty_asked = 0;
1217 $line->description =
'';
1219 $line->label = $obj->label;
1222 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1223 $tva = $pu_ht * $line->tva_tx / 100;
1224 $this->total_ht += $pu_ht;
1225 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1227 $this->total_ttc += $pu_ht + $tva;
1229 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1231 $detail_batch->eatby = $line->eatby;
1232 $detail_batch->sellby = $line->sellby;
1233 $detail_batch->batch = $line->batch;
1234 $detail_batch->qty = $line->qty;
1235 $line->detail_batch[] = $detail_batch;
1238 $this->lines[] = $line;
1257 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1259 global $langs, $hookmanager;
1262 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1263 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1264 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1266 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1273 if (empty($notooltip)) {
1275 $label = $langs->trans(
"Reception");
1276 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1278 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1279 $linkclose .=
' class="classfortooltip"';
1282 $linkstart =
'<a href="'.$url.
'"';
1283 $linkstart .= $linkclose.
'>';
1286 $result .= $linkstart;
1288 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1290 if ($withpicto != 2) {
1291 $result .= $this->ref;
1294 $result .= $linkend;
1297 $hookmanager->initHooks(array($this->element .
'dao'));
1298 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1299 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1301 $result = $hookmanager->resPrint;
1303 $result .= $hookmanager->resPrint;
1333 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1334 $this->labelStatus[0] =
'StatusReceptionDraft';
1336 $this->labelStatus[1] =
'StatusReceptionValidated';
1338 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1341 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1343 $this->labelStatus[2] =
'StatusReceptionProcessed';
1346 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1347 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1348 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1349 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1351 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1352 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1354 $statusType =
'status'.$status;
1355 if ($status == self::STATUS_VALIDATED) {
1356 $statusType =
'status4';
1358 if ($status == self::STATUS_CLOSED) {
1359 $statusType =
'status6';
1362 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1374 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1376 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1377 $return .=
'<div class="info-box info-box-sm">';
1378 $return .=
'<div class="info-box-icon bg-infobox-action">';
1380 $return .=
'</div>';
1381 $return .=
'<div class="info-box-content">';
1382 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1383 if ($selected >= 0) {
1384 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1386 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1387 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1392 if (method_exists($this,
'getLibStatut')) {
1393 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1395 $return .=
'</div>';
1396 $return .=
'</div>';
1397 $return .=
'</div>';
1413 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1414 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1417 dol_syslog(get_class($this).
"::initAsSpecimen");
1420 $order->initAsSpecimen();
1424 $this->
ref =
'SPECIMEN';
1425 $this->specimen = 1;
1428 $this->date_creation = $now;
1429 $this->date_valid = $now;
1430 $this->date_delivery = $now;
1431 $this->date_reception = $now + 24 * 3600;
1433 $this->entrepot_id = 0;
1436 $this->origin_id = 1;
1437 $this->origin =
'commande';
1438 $this->origin_object = $order;
1439 $this->commandeFournisseur = $order;
1441 $this->note_private =
'Private note';
1442 $this->note_public =
'Public note';
1446 while ($xnbp < $nbp) {
1448 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1449 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1450 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1453 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1455 $this->lines[] = $line;
1470 if ($user->hasRight(
'reception',
'creer')) {
1471 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1472 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1473 $sql .=
" WHERE rowid = ".((int) $this->
id);
1475 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1476 $resql = $this->db->query($sql);
1478 $this->date_delivery = $delivery_date;
1481 $this->error = $this->db->error();
1499 $this->meths = array();
1501 $sql =
"SELECT em.rowid, em.code, em.libelle";
1502 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1503 $sql .=
" WHERE em.active = 1";
1504 $sql .=
" ORDER BY em.libelle ASC";
1506 $resql = $this->db->query($sql);
1508 while ($obj = $this->db->fetch_object($resql)) {
1509 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1510 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1527 $this->listmeths = array();
1530 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1531 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1533 $sql .=
" WHERE em.rowid = ".((int) $id);
1536 $resql = $this->db->query($sql);
1538 while ($obj = $this->db->fetch_object($resql)) {
1539 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1540 $this->listmeths[$i][
'code'] = $obj->code;
1541 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1542 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1543 $this->listmeths[$i][
'description'] = $obj->description;
1544 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1545 $this->listmeths[$i][
'active'] = $obj->active;
1559 if (!empty($this->shipping_method_id)) {
1560 $sql =
"SELECT em.code, em.tracking";
1561 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1562 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1564 $resql = $this->db->query($sql);
1566 if ($obj = $this->db->fetch_object($resql)) {
1567 $tracking = $obj->tracking;
1572 if (!empty($tracking) && !empty($value)) {
1573 $url = str_replace(
'{TRACKID}', $value, $tracking);
1574 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1576 $this->tracking_url = $value;
1587 global $conf, $langs, $user;
1592 if ($this->
statut == Reception::STATUS_CLOSED) {
1593 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1599 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1600 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1602 $resql = $this->db->query($sql);
1605 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1607 $order->fetch($this->origin_id);
1609 $order->loadReceptions(self::STATUS_CLOSED);
1611 $receptions_match_order = 1;
1612 foreach ($order->lines as $line) {
1613 $lineid = $line->id;
1615 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1616 $receptions_match_order = 0;
1617 $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';
1622 if ($receptions_match_order) {
1623 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');
1624 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1628 $this->
statut = self::STATUS_CLOSED;
1629 $this->
status = self::STATUS_CLOSED;
1632 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1633 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1635 $langs->load(
"agenda");
1639 $sql =
"SELECT cd.fk_product, cd.subprice,";
1640 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1641 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1642 $sql .=
" ed.cost_price";
1643 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1644 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1645 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1646 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1648 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1649 $resql = $this->db->query($sql);
1652 $cpt = $this->db->num_rows($resql);
1653 for ($i = 0; $i < $cpt; $i++) {
1654 $obj = $this->db->fetch_object($resql);
1661 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1664 $mouvS->origin = &$this;
1665 $mouvS->setOrigin($this->element, $this->
id);
1667 if (empty($obj->batch)) {
1671 $inventorycode =
'';
1672 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1674 $this->error = $mouvS->error;
1675 $this->errors = $mouvS->errors;
1683 $inventorycode =
'';
1684 $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);
1687 $this->error = $mouvS->error;
1688 $this->errors = $mouvS->errors;
1695 $this->error = $this->db->lasterror();
1702 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1713 $this->db->commit();
1716 $this->db->rollback();
1733 if ($this->
statut == Reception::STATUS_VALIDATED) {
1738 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1739 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1741 $resql = $this->db->query($sql);
1746 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1753 $this->errors[] = $this->db->lasterror;
1756 if (empty($error)) {
1757 $this->db->commit();
1760 $this->db->rollback();
1772 global $conf, $langs, $user;
1778 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1779 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1781 $resql = $this->db->query($sql);
1783 $this->
statut = self::STATUS_VALIDATED;
1784 $this->
status = self::STATUS_VALIDATED;
1788 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1789 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1790 $numref = $this->ref;
1791 $langs->load(
"agenda");
1795 $sql =
"SELECT ed.fk_product, cd.subprice,";
1796 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1797 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1798 $sql .=
" ed.cost_price";
1799 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1800 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1801 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1802 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1804 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1805 $resql = $this->db->query($sql);
1807 $cpt = $this->db->num_rows($resql);
1808 for ($i = 0; $i < $cpt; $i++) {
1809 $obj = $this->db->fetch_object($resql);
1817 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1821 $mouvS->origin = &$this;
1822 $mouvS->setOrigin($this->element, $this->
id);
1824 if (empty($obj->batch)) {
1828 $inventorycode =
'';
1829 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1832 $this->error = $mouvS->error;
1833 $this->errors = $mouvS->errors;
1841 $inventorycode =
'';
1842 $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);
1844 $this->error = $mouvS->error;
1845 $this->errors = $mouvS->errors;
1852 $this->error = $this->db->lasterror();
1859 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1865 if (!$error && $this->origin ==
'order_supplier') {
1867 $commande->fetch($this->origin_id);
1868 $result = $commande->setStatus($user, 4);
1871 $this->error = $commande->error;
1872 $this->errors = $commande->errors;
1877 $this->errors[] = $this->db->lasterror();
1881 $this->db->commit();
1884 $this->db->rollback();
1898 global $conf, $langs;
1903 if ($this->
statut <= self::STATUS_DRAFT) {
1907 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
1908 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
1909 $this->error =
'Permission denied';
1915 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1916 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1917 $sql .=
" WHERE rowid = ".((int) $this->
id);
1920 if ($this->db->query($sql)) {
1922 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
1923 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1925 $langs->load(
"agenda");
1929 $sql =
"SELECT cd.fk_product, cd.subprice,";
1930 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1931 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1932 $sql .=
" ed.cost_price";
1933 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1934 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1935 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1936 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1938 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1939 $resql = $this->db->query($sql);
1941 $cpt = $this->db->num_rows($resql);
1942 for ($i = 0; $i < $cpt; $i++) {
1943 $obj = $this->db->fetch_object($resql);
1951 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1955 $mouvS->origin = &$this;
1956 $mouvS->setOrigin($this->element, $this->
id);
1958 if (empty($obj->batch)) {
1962 $inventorycode =
'';
1963 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1965 $this->error = $mouvS->error;
1966 $this->errors = $mouvS->errors;
1974 $inventorycode =
'';
1975 $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);
1977 $this->error = $mouvS->error;
1978 $this->errors = $mouvS->errors;
1985 $this->error = $this->db->lasterror();
1992 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1997 if ($this->origin ==
'order_supplier') {
1998 if (!empty($this->origin) && $this->origin_id > 0) {
2000 $origin = $this->origin;
2001 if ($this->$origin->statut == 4) {
2003 $this->$origin->fetchObjectLinked();
2005 if (!empty($this->$origin->linkedObjects[
'reception'])) {
2006 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
2007 if ($rcption->statut > 0) {
2014 $this->$origin->setStatut(3);
2022 $this->
statut = self::STATUS_DRAFT;
2023 $this->
status = self::STATUS_DRAFT;
2024 $this->db->commit();
2027 $this->db->rollback();
2031 $this->error = $this->db->error();
2032 $this->db->rollback();
2047 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2049 global $conf, $langs;
2051 $langs->load(
"receptions");
2054 $modele =
'squille';
2056 if ($this->model_pdf) {
2057 $modele = $this->model_pdf;
2059 $modele = $conf->global->RECEPTION_ADDON_PDF;
2063 $modelpath =
"core/modules/reception/doc/";
2067 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2080 $tables = array(
'reception');
2096 'commande_fournisseur_dispatch'
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Class to manage table commandefournisseurdispatch.
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.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for exemple 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 record 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.
addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='', $cost_price=0)
Add an reception line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
list_delivery_methods($id='')
Fetch all deliveries method and return an array.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
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.
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($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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut