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';
82 public $tracking_number;
98 public $date_delivery;
110 public $date_reception;
115 public $date_creation;
128 public $lines = array();
133 public $detail_batch;
135 const STATUS_DRAFT = 0;
136 const STATUS_VALIDATED = 1;
137 const STATUS_CLOSED = 2;
159 global $langs, $conf;
160 $langs->load(
"receptions");
162 if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) {
165 $file = $conf->global->RECEPTION_ADDON_NUMBER.
".php";
166 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
169 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
171 foreach ($dirmodels as $reldir) {
175 $mybool |= @include_once $dir.$file;
183 $obj =
new $classname();
186 $numref = $obj->getNextValue($soc, $this);
191 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
195 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
207 public function create($user, $notrigger = 0)
209 global $conf, $hookmanager;
213 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
217 $this->brouillon = 1;
219 if (empty($this->fk_project)) {
220 $this->fk_project = 0;
222 if (empty($this->weight_units)) {
223 $this->weight_units = 0;
225 if (empty($this->size_units)) {
226 $this->size_units = 0;
233 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
236 $sql .=
", ref_supplier";
237 $sql .=
", date_creation";
238 $sql .=
", fk_user_author";
239 $sql .=
", date_reception";
240 $sql .=
", date_delivery";
242 $sql .=
", fk_projet";
243 $sql .=
", fk_shipping_method";
244 $sql .=
", tracking_number";
249 $sql .=
", weight_units";
250 $sql .=
", size_units";
251 $sql .=
", note_private";
252 $sql .=
", note_public";
253 $sql .=
", model_pdf";
254 $sql .=
", fk_incoterms, location_incoterms";
255 $sql .=
") VALUES (";
257 $sql .=
", ".((int) $conf->entity);
258 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
259 $sql .=
", '".$this->db->idate($now).
"'";
260 $sql .=
", ".((int) $user->id);
261 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
262 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
263 $sql .=
", ".((int) $this->socid);
264 $sql .=
", ".((int) $this->fk_project);
265 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
266 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
267 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((double) $this->weight));
268 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((double) $this->trueDepth));
269 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((double) $this->trueWidth));
270 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((double) $this->trueHeight));
271 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((double) $this->weight_units));
272 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((double) $this->size_units));
273 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
274 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
275 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
276 $sql .=
", ".(int) $this->fk_incoterms;
277 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
280 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
282 $resql = $this->db->query($sql);
285 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
287 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
288 $sql .=
" SET ref = '(PROV".$this->id.
")'";
289 $sql .=
" WHERE rowid = ".((int) $this->
id);
291 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
292 if ($this->db->query($sql)) {
294 $num = count($this->lines);
295 for ($i = 0; $i < $num; $i++) {
296 $this->lines[$i]->fk_reception = $this->id;
298 if (!$this->lines[$i]->
create($user) > 0) {
303 if (!$error && $this->
id && $this->origin_id) {
318 if (!$error && !$notrigger) {
320 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
331 foreach ($this->errors as $errmsg) {
332 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
333 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
335 $this->db->rollback();
340 $this->error = $this->db->lasterror().
" - sql=$sql";
341 $this->db->rollback();
346 $this->error = $this->db->error().
" - sql=$sql";
347 $this->db->rollback();
362 public function fetch($id, $ref =
'', $ref_ext =
'')
365 if (empty($id) && empty($ref) && empty($ref_ext)) {
369 $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";
370 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
371 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
372 $sql .=
", e.fk_shipping_method, e.tracking_number";
373 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
374 $sql .=
", e.note_private, e.note_public";
375 $sql .=
', e.fk_incoterms, e.location_incoterms';
376 $sql .=
', i.libelle as label_incoterms';
377 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
378 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
379 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
380 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
382 $sql .=
" AND e.rowid=".((int) $id);
385 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
388 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
391 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
392 $result = $this->db->query($sql);
394 if ($this->db->num_rows($result)) {
395 $obj = $this->db->fetch_object($result);
397 $this->
id = $obj->rowid;
398 $this->entity = $obj->entity;
399 $this->
ref = $obj->ref;
400 $this->socid = $obj->socid;
401 $this->ref_supplier = $obj->ref_supplier;
402 $this->ref_ext = $obj->ref_ext;
403 $this->
statut = $obj->fk_statut;
404 $this->user_author_id = $obj->fk_user_author;
405 $this->date_creation = $this->db->jdate($obj->date_creation);
406 $this->date = $this->db->jdate($obj->date_reception);
407 $this->date_reception = $this->db->jdate($obj->date_reception);
408 $this->date_delivery = $this->db->jdate($obj->date_delivery);
409 $this->model_pdf = $obj->model_pdf;
410 $this->modelpdf = $obj->model_pdf;
411 $this->shipping_method_id = $obj->fk_shipping_method;
412 $this->tracking_number = $obj->tracking_number;
413 $this->origin = ($obj->origin ? $obj->origin :
'commande');
414 $this->origin_id = $obj->origin_id;
415 $this->billed = ($obj->fk_statut == 2 ? 1 : 0);
417 $this->trueWeight = $obj->weight;
418 $this->weight_units = $obj->weight_units;
420 $this->trueWidth = $obj->width;
421 $this->width_units = $obj->size_units;
422 $this->trueHeight = $obj->height;
423 $this->height_units = $obj->size_units;
424 $this->trueDepth = $obj->size;
425 $this->depth_units = $obj->size_units;
427 $this->note_public = $obj->note_public;
428 $this->note_private = $obj->note_private;
431 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
432 $this->size_units = $obj->size_units;
435 $this->fk_incoterms = $obj->fk_incoterms;
436 $this->location_incoterms = $obj->location_incoterms;
437 $this->label_incoterms = $obj->label_incoterms;
439 $this->db->free($result);
442 $this->brouillon = 1;
459 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
461 $extrafields->fetch_name_optionals_label($this->table_element,
true);
474 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
475 $this->error =
'Reception with id '.$id.
' not found';
479 $this->error = $this->db->error();
491 public function valid($user, $notrigger = 0)
493 global $conf, $langs;
495 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
501 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
505 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
506 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
507 $this->error =
'Permission denied';
508 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
518 $soc->fetch($this->socid);
522 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
525 $numref = $this->ref;
533 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
534 $sql .=
" ref='".$this->db->escape($numref).
"'";
535 $sql .=
", fk_statut = 1";
536 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
537 $sql .=
", fk_user_valid = ".$user->id;
538 $sql .=
" WHERE rowid = ".((int) $this->
id);
539 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
540 $resql = $this->db->query($sql);
542 $this->error = $this->db->lasterror();
547 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
548 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
550 $langs->load(
"agenda");
554 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
555 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
556 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
557 $sql .=
" ed.cost_price";
558 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
559 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
560 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
561 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
563 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
564 $resql = $this->db->query($sql);
566 $cpt = $this->db->num_rows($resql);
567 for ($i = 0; $i < $cpt; $i++) {
568 $obj = $this->db->fetch_object($resql);
572 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
575 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
579 $mouvS->origin = &$this;
580 $mouvS->setOrigin($this->element, $this->
id);
582 if (empty($obj->batch)) {
587 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
589 if (intval($result) < 0) {
591 $this->errors[] = $mouvS->error;
592 $this->errors = array_merge($this->errors, $mouvS->errors);
601 $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);
603 if (intval($result) < 0) {
605 $this->errors[] = $mouvS->error;
606 $this->errors = array_merge($this->errors, $mouvS->errors);
612 $this->db->rollback();
613 $this->error = $this->db->error();
625 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
628 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
631 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
638 if (!$error && !$notrigger) {
640 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
648 $this->oldref = $this->ref;
651 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
653 $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).
"'";
654 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
655 $resql = $this->db->query($sql);
657 $error++; $this->error = $this->db->lasterror();
659 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
660 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
661 $resql = $this->db->query($sql);
663 $error++; $this->error = $this->db->lasterror();
669 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
670 $dirdest = $conf->reception->dir_output.
'/'.$newref;
671 if (!$error && file_exists($dirsource)) {
672 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
674 if (@rename($dirsource, $dirdest)) {
677 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
678 foreach ($listoffiles as $fileentry) {
679 $dirsource = $fileentry[
'name'];
680 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
681 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
682 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
683 @rename($dirsource, $dirdest);
692 $this->
ref = $numref;
700 foreach ($this->errors as $errmsg) {
701 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
702 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
704 $this->db->rollback();
718 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
719 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
723 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
724 if (empty($this->commandeFournisseur)) {
726 if (empty($this->commandeFournisseur->lines)) {
727 $res = $this->commandeFournisseur->fetch_lines();
728 if ($res < 0)
return $res;
732 $qty_received = array();
733 $qty_wished = array();
736 $filter = array(
't.fk_commande'=>$this->origin_id);
737 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
738 $filter[
't.status'] = 1;
741 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
743 $this->error = $supplierorderdispatch->error;
744 $this->errors = $supplierorderdispatch->errors;
748 foreach ($supplierorderdispatch->lines as $dispatch_line) {
749 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
750 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
752 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
757 foreach ($this->commandeFournisseur->lines as $origin_line) {
759 if ((!
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
763 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
767 $diff_array = array_diff_assoc($qty_received, $qty_wished);
768 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
769 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
771 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
773 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
777 if (count($diff_array) > 0) {
780 foreach ($diff_array as $key => $value) {
782 if ($qty_received[$key] >= $qty_wished[$key]) {
788 if ($close == count($diff_array)) {
815 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
817 global $conf, $langs, $user;
819 $num = count($this->lines);
822 $line->fk_entrepot = $entrepot_id;
823 $line->fk_commandefourndet = $id;
827 $result = $supplierorderline->fetch($id);
829 $this->error = $supplierorderline->error;
830 $this->errors = $supplierorderline->errors;
835 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
836 $fk_product = $supplierorderline->fk_product;
838 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
839 $langs->load(
"errors");
840 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
846 $product =
new Product($this->db);
847 $product->fetch($fk_product);
848 if (isModEnabled(
'productbatch')) {
849 $langs->load(
"errors");
850 if (!empty($product->status_batch) && empty($batch)) {
851 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
853 } elseif (empty($product->status_batch) && !empty($batch)) {
854 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
861 $line->array_options = $supplierorderline->array_options;
862 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
863 foreach ($array_options as $key => $value) {
864 $line->array_options[$key] = $value;
868 $line->fk_product = $fk_product;
869 $line->fk_commande = $supplierorderline->fk_commande;
870 $line->fk_user = $user->id;
871 $line->comment = $comment;
872 $line->batch = $batch;
873 $line->eatby = $eatby;
874 $line->sellby = $sellby;
876 $line->cost_price = $cost_price;
877 $line->fk_reception = $this->id;
879 $this->lines[$num] = $line;
892 public function update($user =
null, $notrigger = 0)
899 if (isset($this->
ref)) {
900 $this->
ref = trim($this->
ref);
902 if (isset($this->entity)) {
903 $this->entity = trim($this->entity);
905 if (isset($this->ref_supplier)) {
906 $this->ref_supplier = trim($this->ref_supplier);
908 if (isset($this->socid)) {
909 $this->socid = trim($this->socid);
911 if (isset($this->fk_user_author)) {
912 $this->fk_user_author = trim($this->fk_user_author);
914 if (isset($this->fk_user_valid)) {
915 $this->fk_user_valid = trim($this->fk_user_valid);
917 if (isset($this->shipping_method_id)) {
918 $this->shipping_method_id = trim($this->shipping_method_id);
920 if (isset($this->tracking_number)) {
921 $this->tracking_number = trim($this->tracking_number);
923 if (isset($this->
statut)) {
926 if (isset($this->trueDepth)) {
927 $this->trueDepth = trim($this->trueDepth);
929 if (isset($this->trueWidth)) {
930 $this->trueWidth = trim($this->trueWidth);
932 if (isset($this->trueHeight)) {
933 $this->trueHeight = trim($this->trueHeight);
935 if (isset($this->size_units)) {
936 $this->size_units = trim($this->size_units);
938 if (isset($this->weight_units)) {
939 $this->weight_units = trim($this->weight_units);
941 if (isset($this->trueWeight)) {
942 $this->weight = trim($this->trueWeight);
944 if (isset($this->note_private)) {
945 $this->note_private = trim($this->note_private);
947 if (isset($this->note_public)) {
948 $this->note_public = trim($this->note_public);
950 if (isset($this->model_pdf)) {
951 $this->model_pdf = trim($this->model_pdf);
959 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
961 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
962 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
963 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
964 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
965 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
966 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
967 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
968 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
969 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
970 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
971 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
972 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
973 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
974 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
975 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
976 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
977 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
978 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
979 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
980 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
981 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
982 $sql .=
" entity = ".((int) $conf->entity);
983 $sql .=
" WHERE rowid=".((int) $this->
id);
987 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
988 $resql = $this->db->query($sql);
990 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
996 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1006 foreach ($this->errors as $errmsg) {
1007 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1008 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1010 $this->db->rollback();
1013 $this->db->commit();
1026 global $conf, $langs, $user;
1027 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1036 if (isModEnabled(
'stock') && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0) {
1037 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1039 $langs->load(
"agenda");
1042 $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";
1043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1044 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1045 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1046 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1048 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1049 $resql = $this->db->query($sql);
1051 $cpt = $this->db->num_rows($resql);
1052 for ($i = 0; $i < $cpt; $i++) {
1053 dol_syslog(get_class($this).
"::delete movement index ".$i);
1054 $obj = $this->db->fetch_object($resql);
1058 $mouvS->origin =
null;
1060 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1063 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1068 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1069 $ef = $main.
"_extrafields";
1071 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1073 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1074 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1076 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1084 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1085 $sql .=
" WHERE rowid = ".((int) $this->
id);
1087 if ($this->db->query($sql)) {
1089 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1095 if (!empty($this->origin) && $this->origin_id > 0) {
1097 $origin = $this->origin;
1098 if ($this->$origin->statut == 4) {
1100 $this->$origin->loadReceptions();
1102 if (count($this->$origin->receptions) <= 0) {
1103 $this->$origin->setStatut(3);
1109 $this->db->commit();
1113 if (!empty($conf->reception->dir_output)) {
1114 $dir = $conf->reception->dir_output.
'/'.$ref;
1115 $file = $dir.
'/'.$ref.
'.pdf';
1116 if (file_exists($file)) {
1121 if (file_exists($dir)) {
1123 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1131 $this->db->rollback();
1135 $this->error = $this->db->lasterror().
" - sql=$sql";
1136 $this->db->rollback();
1140 $this->error = $this->db->lasterror().
" - sql=$sql";
1141 $this->db->rollback();
1145 $this->error = $this->db->lasterror().
" - sql=$sql";
1146 $this->db->rollback();
1150 $this->db->rollback();
1164 $this->lines = array();
1166 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1168 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1169 $resql = $this->db->query($sql);
1171 if (!empty($resql)) {
1172 while ($obj = $this->db->fetch_object($resql)) {
1175 $line->fetch($obj->rowid);
1178 $line->fetch_product();
1180 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1181 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1182 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1183 $sql_commfourndet .=
' ORDER BY rang';
1185 $resql_commfourndet = $this->db->query($sql_commfourndet);
1186 if (!empty($resql_commfourndet)) {
1187 $obj = $this->db->fetch_object($resql_commfourndet);
1188 $line->qty_asked = $obj->qty;
1189 $line->description = $obj->description;
1190 $line->desc = $obj->description;
1191 $line->tva_tx = $obj->tva_tx;
1192 $line->vat_src_code = $obj->vat_src_code;
1193 $line->subprice = $obj->subprice;
1194 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1195 $line->remise_percent = $obj->remise_percent;
1196 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1197 $line->ref_supplier = $obj->ref;
1198 $line->total_ht = $obj->total_ht;
1199 $line->total_ttc = $obj->total_ttc;
1200 $line->total_tva = $obj->total_tva;
1202 $line->qty_asked = 0;
1203 $line->description =
'';
1205 $line->label = $obj->label;
1208 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1209 $tva = $pu_ht * $line->tva_tx / 100;
1210 $this->total_ht += $pu_ht;
1211 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1213 $this->total_ttc += $pu_ht + $tva;
1215 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1216 $detail_batch =
new stdClass();
1217 $detail_batch->eatby = $line->eatby;
1218 $detail_batch->sellby = $line->sellby;
1219 $detail_batch->batch = $line->batch;
1220 $detail_batch->qty = $line->qty;
1221 $line->detail_batch[] = $detail_batch;
1224 $this->lines[] = $line;
1243 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1245 global $conf, $langs, $hookmanager;
1247 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1248 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1249 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1251 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1258 if (empty($notooltip)) {
1259 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1260 $label = $langs->trans(
"Reception");
1261 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1263 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1264 $linkclose .=
' class="classfortooltip"';
1267 $linkstart =
'<a href="'.$url.
'"';
1268 $linkstart .= $linkclose.
'>';
1271 $result .= $linkstart;
1273 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1275 if ($withpicto != 2) {
1276 $result .= $this->ref;
1279 $result .= $linkend;
1282 $hookmanager->initHooks(array($this->element .
'dao'));
1283 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1284 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1286 $result = $hookmanager->resPrint;
1288 $result .= $hookmanager->resPrint;
1318 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1319 $this->labelStatus[0] =
'StatusReceptionDraft';
1321 $this->labelStatus[1] =
'StatusReceptionValidated';
1323 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1326 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1328 $this->labelStatus[2] =
'StatusReceptionProcessed';
1331 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1332 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1333 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1334 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1336 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1337 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1339 $statusType =
'status'.$status;
1340 if ($status == self::STATUS_VALIDATED) {
1341 $statusType =
'status4';
1343 if ($status == self::STATUS_CLOSED) {
1344 $statusType =
'status6';
1347 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1361 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1362 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1365 dol_syslog(get_class($this).
"::initAsSpecimen");
1368 $order->initAsSpecimen();
1372 $this->
ref =
'SPECIMEN';
1373 $this->specimen = 1;
1375 $this->livraison_id = 0;
1377 $this->date_creation = $now;
1378 $this->date_valid = $now;
1379 $this->date_delivery = $now;
1380 $this->date_reception = $now + 24 * 3600;
1382 $this->entrepot_id = 0;
1385 $this->commande_id = 0;
1386 $this->commande = $order;
1388 $this->origin_id = 1;
1389 $this->origin =
'commande';
1391 $this->note_private =
'Private note';
1392 $this->note_public =
'Public note';
1396 while ($xnbp < $nbp) {
1398 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1399 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1400 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1403 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1405 $this->lines[] = $line;
1420 if ($user->rights->reception->creer) {
1421 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1422 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1423 $sql .=
" WHERE rowid = ".((int) $this->
id);
1425 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1426 $resql = $this->db->query($sql);
1428 $this->date_delivery = $delivery_date;
1431 $this->error = $this->db->error();
1449 $this->meths = array();
1451 $sql =
"SELECT em.rowid, em.code, em.libelle";
1452 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1453 $sql .=
" WHERE em.active = 1";
1454 $sql .=
" ORDER BY em.libelle ASC";
1456 $resql = $this->db->query($sql);
1458 while ($obj = $this->db->fetch_object($resql)) {
1459 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1460 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1477 $this->listmeths = array();
1480 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1481 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1483 $sql .=
" WHERE em.rowid = ".((int) $id);
1486 $resql = $this->db->query($sql);
1488 while ($obj = $this->db->fetch_object($resql)) {
1489 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1490 $this->listmeths[$i][
'code'] = $obj->code;
1491 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1492 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1493 $this->listmeths[$i][
'description'] = $obj->description;
1494 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1495 $this->listmeths[$i][
'active'] = $obj->active;
1509 if (!empty($this->shipping_method_id)) {
1510 $sql =
"SELECT em.code, em.tracking";
1511 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1512 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1514 $resql = $this->db->query($sql);
1516 if ($obj = $this->db->fetch_object($resql)) {
1517 $tracking = $obj->tracking;
1522 if (!empty($tracking) && !empty($value)) {
1523 $url = str_replace(
'{TRACKID}', $value, $tracking);
1524 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1526 $this->tracking_url = $value;
1537 global $conf, $langs, $user;
1542 if ($this->
statut == Reception::STATUS_CLOSED) {
1543 dol_syslog(get_class($this).
"::Already in closed status", LOG_WARNING);
1549 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1550 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1552 $resql = $this->db->query($sql);
1555 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1557 $order->fetch($this->origin_id);
1559 $order->loadReceptions(self::STATUS_CLOSED);
1561 $receptions_match_order = 1;
1562 foreach ($order->lines as $line) {
1563 $lineid = $line->id;
1565 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1566 $receptions_match_order = 0;
1567 $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';
1572 if ($receptions_match_order) {
1573 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');
1574 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1578 $this->
statut = self::STATUS_CLOSED;
1582 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1583 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1585 $langs->load(
"agenda");
1589 $sql =
"SELECT cd.fk_product, cd.subprice,";
1590 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1591 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1592 $sql .=
" ed.cost_price";
1593 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1594 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1595 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1596 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1598 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1599 $resql = $this->db->query($sql);
1602 $cpt = $this->db->num_rows($resql);
1603 for ($i = 0; $i < $cpt; $i++) {
1604 $obj = $this->db->fetch_object($resql);
1611 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1614 $mouvS->origin = &$this;
1615 $mouvS->setOrigin($this->element, $this->
id);
1617 if (empty($obj->batch)) {
1621 $inventorycode =
'';
1622 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1624 $this->error = $mouvS->error;
1625 $this->errors = $mouvS->errors;
1632 $inventorycode =
'';
1633 $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);
1636 $this->error = $mouvS->error;
1637 $this->errors = $mouvS->errors;
1643 $this->error = $this->db->lasterror();
1650 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1661 $this->db->commit();
1664 $this->db->rollback();
1681 if ($this->
statut == Reception::STATUS_VALIDATED) {
1686 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1687 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1689 $resql = $this->db->query($sql);
1695 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1701 $this->errors[] = $this->db->lasterror;
1704 if (empty($error)) {
1705 $this->db->commit();
1708 $this->db->rollback();
1720 global $conf, $langs, $user;
1726 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1727 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1729 $resql = $this->db->query($sql);
1735 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1736 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1737 $numref = $this->ref;
1738 $langs->load(
"agenda");
1742 $sql =
"SELECT ed.fk_product, cd.subprice,";
1743 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1744 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1745 $sql .=
" ed.cost_price";
1746 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1747 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1748 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1749 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1751 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1752 $resql = $this->db->query($sql);
1754 $cpt = $this->db->num_rows($resql);
1755 for ($i = 0; $i < $cpt; $i++) {
1756 $obj = $this->db->fetch_object($resql);
1764 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1768 $mouvS->origin = &$this;
1769 $mouvS->setOrigin($this->element, $this->
id);
1771 if (empty($obj->batch)) {
1775 $inventorycode =
'';
1776 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1779 $this->error = $mouvS->error;
1780 $this->errors = $mouvS->errors;
1787 $inventorycode =
'';
1788 $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);
1790 $this->error = $mouvS->error;
1791 $this->errors = $mouvS->errors;
1797 $this->error = $this->db->lasterror();
1804 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1810 if (!$error && $this->origin ==
'order_supplier') {
1812 $commande->fetch($this->origin_id);
1813 $result = $commande->setStatus($user, 4);
1816 $this->error = $commande->error;
1817 $this->errors = $commande->errors;
1822 $this->errors[] = $this->db->lasterror();
1826 $this->db->commit();
1829 $this->db->rollback();
1843 global $conf, $langs;
1848 if ($this->
statut <= self::STATUS_DRAFT) {
1852 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1853 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1854 $this->error =
'Permission denied';
1860 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1861 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1862 $sql .=
" WHERE rowid = ".((int) $this->
id);
1865 if ($this->db->query($sql)) {
1867 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1868 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1870 $langs->load(
"agenda");
1874 $sql =
"SELECT cd.fk_product, cd.subprice,";
1875 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1876 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1877 $sql .=
" ed.cost_price";
1878 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1879 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1880 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1881 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1883 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1884 $resql = $this->db->query($sql);
1886 $cpt = $this->db->num_rows($resql);
1887 for ($i = 0; $i < $cpt; $i++) {
1888 $obj = $this->db->fetch_object($resql);
1896 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1900 $mouvS->origin = &$this;
1901 $mouvS->setOrigin($this->element, $this->
id);
1903 if (empty($obj->batch)) {
1907 $inventorycode =
'';
1908 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1910 $this->error = $mouvS->error;
1911 $this->errors = $mouvS->errors;
1919 $inventorycode =
'';
1920 $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);
1922 $this->error = $mouvS->error;
1923 $this->errors = $mouvS->errors;
1929 $this->error = $this->db->lasterror();
1936 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1941 if ($this->origin ==
'order_supplier') {
1942 if (!empty($this->origin) && $this->origin_id > 0) {
1944 $origin = $this->origin;
1945 if ($this->$origin->statut == 4) {
1947 $this->$origin->fetchObjectLinked();
1949 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1950 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1951 if ($rcption->statut > 0) {
1958 $this->$origin->setStatut(3);
1966 $this->
statut = self::STATUS_DRAFT;
1967 $this->db->commit();
1970 $this->db->rollback();
1974 $this->error = $this->db->error();
1975 $this->db->rollback();
1990 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1992 global $conf, $langs;
1994 $langs->load(
"receptions");
1997 $modele =
'squille';
1999 if ($this->model_pdf) {
2000 $modele = $this->model_pdf;
2001 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
2002 $modele = $conf->global->RECEPTION_ADDON_PDF;
2006 $modelpath =
"core/modules/reception/doc/";
2010 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2023 $tables = array(
'reception');
2039 'commande_fournisseur_dispatch'
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='', $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 when WORKFLOW_EXPEDITION_CLASSIFY_CLOSED_INVOICE is on)
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.
__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.
print $langs trans("Ref").' m m m statut
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 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.