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 $this->error = $mouvS->error;
1064 $this->errors = $mouvS->errors;
1068 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1073 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1074 $ef = $main.
"_extrafields";
1076 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1078 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1079 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1081 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1089 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1090 $sql .=
" WHERE rowid = ".((int) $this->
id);
1092 if ($this->db->query($sql)) {
1094 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1100 if (!empty($this->origin) && $this->origin_id > 0) {
1102 $origin = $this->origin;
1103 if ($this->$origin->statut == 4) {
1105 $this->$origin->loadReceptions();
1107 if (count($this->$origin->receptions) <= 0) {
1108 $this->$origin->setStatut(3);
1114 $this->db->commit();
1118 if (!empty($conf->reception->dir_output)) {
1119 $dir = $conf->reception->dir_output.
'/'.$ref;
1120 $file = $dir.
'/'.$ref.
'.pdf';
1121 if (file_exists($file)) {
1126 if (file_exists($dir)) {
1128 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
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->error = $this->db->lasterror().
" - sql=$sql";
1151 $this->db->rollback();
1155 $this->db->rollback();
1169 $this->lines = array();
1171 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1173 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1174 $resql = $this->db->query($sql);
1176 if (!empty($resql)) {
1177 while ($obj = $this->db->fetch_object($resql)) {
1180 $line->fetch($obj->rowid);
1183 $line->fetch_product();
1185 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1186 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1187 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1188 $sql_commfourndet .=
' ORDER BY rang';
1190 $resql_commfourndet = $this->db->query($sql_commfourndet);
1191 if (!empty($resql_commfourndet)) {
1192 $obj = $this->db->fetch_object($resql_commfourndet);
1193 $line->qty_asked = $obj->qty;
1194 $line->description = $obj->description;
1195 $line->desc = $obj->description;
1196 $line->tva_tx = $obj->tva_tx;
1197 $line->vat_src_code = $obj->vat_src_code;
1198 $line->subprice = $obj->subprice;
1199 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1200 $line->remise_percent = $obj->remise_percent;
1201 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1202 $line->ref_supplier = $obj->ref;
1203 $line->total_ht = $obj->total_ht;
1204 $line->total_ttc = $obj->total_ttc;
1205 $line->total_tva = $obj->total_tva;
1207 $line->qty_asked = 0;
1208 $line->description =
'';
1210 $line->label = $obj->label;
1213 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1214 $tva = $pu_ht * $line->tva_tx / 100;
1215 $this->total_ht += $pu_ht;
1216 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1218 $this->total_ttc += $pu_ht + $tva;
1220 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1221 $detail_batch =
new stdClass();
1222 $detail_batch->eatby = $line->eatby;
1223 $detail_batch->sellby = $line->sellby;
1224 $detail_batch->batch = $line->batch;
1225 $detail_batch->qty = $line->qty;
1226 $line->detail_batch[] = $detail_batch;
1229 $this->lines[] = $line;
1248 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1250 global $conf, $langs, $hookmanager;
1252 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1253 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1254 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1256 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1263 if (empty($notooltip)) {
1264 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1265 $label = $langs->trans(
"Reception");
1266 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1268 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1269 $linkclose .=
' class="classfortooltip"';
1272 $linkstart =
'<a href="'.$url.
'"';
1273 $linkstart .= $linkclose.
'>';
1276 $result .= $linkstart;
1278 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1280 if ($withpicto != 2) {
1281 $result .= $this->ref;
1284 $result .= $linkend;
1287 $hookmanager->initHooks(array($this->element .
'dao'));
1288 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1289 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1291 $result = $hookmanager->resPrint;
1293 $result .= $hookmanager->resPrint;
1323 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1324 $this->labelStatus[0] =
'StatusReceptionDraft';
1326 $this->labelStatus[1] =
'StatusReceptionValidated';
1328 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1331 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1333 $this->labelStatus[2] =
'StatusReceptionProcessed';
1336 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1337 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1338 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1339 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1341 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1342 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1344 $statusType =
'status'.$status;
1345 if ($status == self::STATUS_VALIDATED) {
1346 $statusType =
'status4';
1348 if ($status == self::STATUS_CLOSED) {
1349 $statusType =
'status6';
1352 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1366 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1367 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1370 dol_syslog(get_class($this).
"::initAsSpecimen");
1373 $order->initAsSpecimen();
1377 $this->
ref =
'SPECIMEN';
1378 $this->specimen = 1;
1380 $this->livraison_id = 0;
1382 $this->date_creation = $now;
1383 $this->date_valid = $now;
1384 $this->date_delivery = $now;
1385 $this->date_reception = $now + 24 * 3600;
1387 $this->entrepot_id = 0;
1390 $this->commande_id = 0;
1391 $this->commande = $order;
1393 $this->origin_id = 1;
1394 $this->origin =
'commande';
1396 $this->note_private =
'Private note';
1397 $this->note_public =
'Public note';
1401 while ($xnbp < $nbp) {
1403 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1404 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1405 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1408 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1410 $this->lines[] = $line;
1425 if ($user->rights->reception->creer) {
1426 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1427 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1428 $sql .=
" WHERE rowid = ".((int) $this->
id);
1430 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1431 $resql = $this->db->query($sql);
1433 $this->date_delivery = $delivery_date;
1436 $this->error = $this->db->error();
1454 $this->meths = array();
1456 $sql =
"SELECT em.rowid, em.code, em.libelle";
1457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1458 $sql .=
" WHERE em.active = 1";
1459 $sql .=
" ORDER BY em.libelle ASC";
1461 $resql = $this->db->query($sql);
1463 while ($obj = $this->db->fetch_object($resql)) {
1464 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1465 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1482 $this->listmeths = array();
1485 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1486 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1488 $sql .=
" WHERE em.rowid = ".((int) $id);
1491 $resql = $this->db->query($sql);
1493 while ($obj = $this->db->fetch_object($resql)) {
1494 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1495 $this->listmeths[$i][
'code'] = $obj->code;
1496 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1497 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1498 $this->listmeths[$i][
'description'] = $obj->description;
1499 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1500 $this->listmeths[$i][
'active'] = $obj->active;
1514 if (!empty($this->shipping_method_id)) {
1515 $sql =
"SELECT em.code, em.tracking";
1516 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1517 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1519 $resql = $this->db->query($sql);
1521 if ($obj = $this->db->fetch_object($resql)) {
1522 $tracking = $obj->tracking;
1527 if (!empty($tracking) && !empty($value)) {
1528 $url = str_replace(
'{TRACKID}', $value, $tracking);
1529 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1531 $this->tracking_url = $value;
1542 global $conf, $langs, $user;
1547 if ($this->
statut == Reception::STATUS_CLOSED) {
1548 dol_syslog(get_class($this).
"::Already in closed status", LOG_WARNING);
1554 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1555 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1557 $resql = $this->db->query($sql);
1560 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1562 $order->fetch($this->origin_id);
1564 $order->loadReceptions(self::STATUS_CLOSED);
1566 $receptions_match_order = 1;
1567 foreach ($order->lines as $line) {
1568 $lineid = $line->id;
1570 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1571 $receptions_match_order = 0;
1572 $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';
1577 if ($receptions_match_order) {
1578 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');
1579 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1583 $this->
statut = self::STATUS_CLOSED;
1587 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1588 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1590 $langs->load(
"agenda");
1594 $sql =
"SELECT cd.fk_product, cd.subprice,";
1595 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1596 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1597 $sql .=
" ed.cost_price";
1598 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1599 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1600 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1601 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1603 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1604 $resql = $this->db->query($sql);
1607 $cpt = $this->db->num_rows($resql);
1608 for ($i = 0; $i < $cpt; $i++) {
1609 $obj = $this->db->fetch_object($resql);
1616 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1619 $mouvS->origin = &$this;
1620 $mouvS->setOrigin($this->element, $this->
id);
1622 if (empty($obj->batch)) {
1626 $inventorycode =
'';
1627 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1629 $this->error = $mouvS->error;
1630 $this->errors = $mouvS->errors;
1637 $inventorycode =
'';
1638 $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);
1641 $this->error = $mouvS->error;
1642 $this->errors = $mouvS->errors;
1648 $this->error = $this->db->lasterror();
1655 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1666 $this->db->commit();
1669 $this->db->rollback();
1686 if ($this->
statut == Reception::STATUS_VALIDATED) {
1691 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1692 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1694 $resql = $this->db->query($sql);
1700 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1706 $this->errors[] = $this->db->lasterror;
1709 if (empty($error)) {
1710 $this->db->commit();
1713 $this->db->rollback();
1725 global $conf, $langs, $user;
1731 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1732 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1734 $resql = $this->db->query($sql);
1740 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1741 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1742 $numref = $this->ref;
1743 $langs->load(
"agenda");
1747 $sql =
"SELECT ed.fk_product, cd.subprice,";
1748 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1749 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1750 $sql .=
" ed.cost_price";
1751 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1752 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1753 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1754 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1756 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1757 $resql = $this->db->query($sql);
1759 $cpt = $this->db->num_rows($resql);
1760 for ($i = 0; $i < $cpt; $i++) {
1761 $obj = $this->db->fetch_object($resql);
1769 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1773 $mouvS->origin = &$this;
1774 $mouvS->setOrigin($this->element, $this->
id);
1776 if (empty($obj->batch)) {
1780 $inventorycode =
'';
1781 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1784 $this->error = $mouvS->error;
1785 $this->errors = $mouvS->errors;
1792 $inventorycode =
'';
1793 $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);
1795 $this->error = $mouvS->error;
1796 $this->errors = $mouvS->errors;
1802 $this->error = $this->db->lasterror();
1809 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1815 if (!$error && $this->origin ==
'order_supplier') {
1817 $commande->fetch($this->origin_id);
1818 $result = $commande->setStatus($user, 4);
1821 $this->error = $commande->error;
1822 $this->errors = $commande->errors;
1827 $this->errors[] = $this->db->lasterror();
1831 $this->db->commit();
1834 $this->db->rollback();
1848 global $conf, $langs;
1853 if ($this->
statut <= self::STATUS_DRAFT) {
1857 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1858 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1859 $this->error =
'Permission denied';
1865 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1866 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1867 $sql .=
" WHERE rowid = ".((int) $this->
id);
1870 if ($this->db->query($sql)) {
1872 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1873 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1875 $langs->load(
"agenda");
1879 $sql =
"SELECT cd.fk_product, cd.subprice,";
1880 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1881 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1882 $sql .=
" ed.cost_price";
1883 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1884 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1885 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1886 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1888 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1889 $resql = $this->db->query($sql);
1891 $cpt = $this->db->num_rows($resql);
1892 for ($i = 0; $i < $cpt; $i++) {
1893 $obj = $this->db->fetch_object($resql);
1901 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1905 $mouvS->origin = &$this;
1906 $mouvS->setOrigin($this->element, $this->
id);
1908 if (empty($obj->batch)) {
1912 $inventorycode =
'';
1913 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1915 $this->error = $mouvS->error;
1916 $this->errors = $mouvS->errors;
1924 $inventorycode =
'';
1925 $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);
1927 $this->error = $mouvS->error;
1928 $this->errors = $mouvS->errors;
1934 $this->error = $this->db->lasterror();
1941 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1946 if ($this->origin ==
'order_supplier') {
1947 if (!empty($this->origin) && $this->origin_id > 0) {
1949 $origin = $this->origin;
1950 if ($this->$origin->statut == 4) {
1952 $this->$origin->fetchObjectLinked();
1954 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1955 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1956 if ($rcption->statut > 0) {
1963 $this->$origin->setStatut(3);
1971 $this->
statut = self::STATUS_DRAFT;
1972 $this->db->commit();
1975 $this->db->rollback();
1979 $this->error = $this->db->error();
1980 $this->db->rollback();
1995 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1997 global $conf, $langs;
1999 $langs->load(
"receptions");
2002 $modele =
'squille';
2004 if ($this->model_pdf) {
2005 $modele = $this->model_pdf;
2006 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
2007 $modele = $conf->global->RECEPTION_ADDON_PDF;
2011 $modelpath =
"core/modules/reception/doc/";
2015 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2028 $tables = array(
'reception');
2044 '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_RECEPTION_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.