37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40if (isModEnabled(
"propal")) {
41 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
43if (isModEnabled(
'commande')) {
44 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
63 public $element =
"reception";
68 public $fk_element =
"fk_reception";
69 public $table_element =
"reception";
70 public $table_element_line =
"commande_fournisseur_dispatch";
71 public $ismultientitymanaged = 1;
76 public $picto =
'dollyrevert';
82 public $tracking_number;
99 public $user_author_id;
101 public $date_delivery;
113 public $date_reception;
118 public $date_creation;
131 public $commandeFournisseur;
136 public $lines = array();
141 public $detail_batch;
143 const STATUS_DRAFT = 0;
144 const STATUS_VALIDATED = 1;
145 const STATUS_CLOSED = 2;
167 global $langs, $conf;
168 $langs->load(
"receptions");
174 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
177 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
179 foreach ($dirmodels as $reldir) {
183 $mybool |= @include_once $dir.$file;
191 $obj =
new $classname();
194 $numref = $obj->getNextValue($soc, $this);
199 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
203 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
215 public function create($user, $notrigger = 0)
221 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
226 if (empty($this->fk_project)) {
227 $this->fk_project = 0;
229 if (empty($this->weight_units)) {
230 $this->weight_units = 0;
232 if (empty($this->size_units)) {
233 $this->size_units = 0;
240 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
243 $sql .=
", ref_supplier";
244 $sql .=
", date_creation";
245 $sql .=
", fk_user_author";
246 $sql .=
", date_reception";
247 $sql .=
", date_delivery";
249 $sql .=
", fk_projet";
250 $sql .=
", fk_shipping_method";
251 $sql .=
", tracking_number";
256 $sql .=
", weight_units";
257 $sql .=
", size_units";
258 $sql .=
", note_private";
259 $sql .=
", note_public";
260 $sql .=
", model_pdf";
261 $sql .=
", fk_incoterms, location_incoterms";
262 $sql .=
") VALUES (";
264 $sql .=
", ".((int) $conf->entity);
265 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
266 $sql .=
", '".$this->db->idate($now).
"'";
267 $sql .=
", ".((int) $user->id);
268 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
269 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
270 $sql .=
", ".((int) $this->socid);
271 $sql .=
", ".((int) $this->fk_project);
272 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
273 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
274 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
275 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
276 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
277 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
278 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((float) $this->weight_units));
279 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((float) $this->size_units));
280 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
281 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
282 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
283 $sql .=
", ".(int) $this->fk_incoterms;
284 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
287 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
289 $resql = $this->db->query($sql);
292 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
294 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
295 $sql .=
" SET ref = '(PROV".$this->id.
")'";
296 $sql .=
" WHERE rowid = ".((int) $this->
id);
298 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
299 if ($this->db->query($sql)) {
301 $num = count($this->lines);
302 for ($i = 0; $i < $num; $i++) {
303 $this->lines[$i]->fk_reception = $this->id;
305 if (!$this->lines[$i]->
create($user) > 0) {
310 if (!$error && $this->
id && $this->origin_id) {
325 if (!$error && !$notrigger) {
327 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
338 foreach ($this->errors as $errmsg) {
339 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
340 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
342 $this->db->rollback();
347 $this->error = $this->db->lasterror().
" - sql=$sql";
348 $this->db->rollback();
353 $this->error = $this->db->error().
" - sql=$sql";
354 $this->db->rollback();
369 public function fetch($id, $ref =
'', $ref_ext =
'')
372 if (empty($id) && empty($ref) && empty($ref_ext)) {
376 $sql =
"SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut as status, e.billed";
377 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
378 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
379 $sql .=
", e.fk_shipping_method, e.tracking_number";
380 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
381 $sql .=
", e.note_private, e.note_public";
382 $sql .=
', e.fk_incoterms, e.location_incoterms';
383 $sql .=
', i.libelle as label_incoterms';
384 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
385 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
386 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
387 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
389 $sql .=
" AND e.rowid = ".((int) $id);
392 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
395 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
398 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
399 $result = $this->db->query($sql);
401 if ($this->db->num_rows($result)) {
402 $obj = $this->db->fetch_object($result);
404 $this->
id = $obj->rowid;
405 $this->entity = $obj->entity;
406 $this->
ref = $obj->ref;
407 $this->socid = $obj->socid;
408 $this->ref_supplier = $obj->ref_supplier;
409 $this->ref_ext = $obj->ref_ext;
410 $this->
statut = $obj->status;
411 $this->
status = $obj->status;
412 $this->billed = $obj->billed;
414 $this->user_author_id = $obj->fk_user_author;
415 $this->date_creation = $this->db->jdate($obj->date_creation);
416 $this->date = $this->db->jdate($obj->date_reception);
417 $this->date_reception = $this->db->jdate($obj->date_reception);
418 $this->date_delivery = $this->db->jdate($obj->date_delivery);
419 $this->model_pdf = $obj->model_pdf;
420 $this->shipping_method_id = $obj->fk_shipping_method;
421 $this->tracking_number = $obj->tracking_number;
422 $this->origin = ($obj->origin ? $obj->origin :
'commande');
423 $this->origin_id = $obj->origin_id;
425 $this->trueWeight = $obj->weight;
426 $this->weight_units = $obj->weight_units;
428 $this->trueWidth = $obj->width;
429 $this->width_units = $obj->size_units;
430 $this->trueHeight = $obj->height;
431 $this->height_units = $obj->size_units;
432 $this->trueDepth = $obj->size;
433 $this->depth_units = $obj->size_units;
435 $this->note_public = $obj->note_public;
436 $this->note_private = $obj->note_private;
439 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
440 $this->size_units = $obj->size_units;
443 $this->fk_incoterms = $obj->fk_incoterms;
444 $this->location_incoterms = $obj->location_incoterms;
445 $this->label_incoterms = $obj->label_incoterms;
447 $this->db->free($result);
463 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
465 $extrafields->fetch_name_optionals_label($this->table_element,
true);
478 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
479 $this->error =
'Reception with id '.$id.
' not found';
483 $this->error = $this->db->error();
495 public function valid($user, $notrigger = 0)
497 global $conf, $langs;
499 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
505 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
509 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
510 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
511 $this->error =
'Permission denied';
512 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
522 $soc->fetch($this->socid);
526 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
529 $numref = $this->ref;
537 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
538 $sql .=
" ref='".$this->db->escape($numref).
"'";
539 $sql .=
", fk_statut = 1";
540 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
541 $sql .=
", fk_user_valid = ".$user->id;
542 $sql .=
" WHERE rowid = ".((int) $this->
id);
543 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
544 $resql = $this->db->query($sql);
546 $this->error = $this->db->lasterror();
551 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
552 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
554 $langs->load(
"agenda");
558 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
559 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
560 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
561 $sql .=
" ed.cost_price";
562 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
563 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
564 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
565 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
567 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
568 $resql = $this->db->query($sql);
570 $cpt = $this->db->num_rows($resql);
571 for ($i = 0; $i < $cpt; $i++) {
572 $obj = $this->db->fetch_object($resql);
576 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
579 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
583 $mouvS->origin = &$this;
584 $mouvS->setOrigin($this->element, $this->
id);
586 if (empty($obj->batch)) {
591 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
593 if (intval($result) < 0) {
595 $this->errors[] = $mouvS->error;
596 $this->errors = array_merge($this->errors, $mouvS->errors);
605 $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);
607 if (intval($result) < 0) {
609 $this->errors[] = $mouvS->error;
610 $this->errors = array_merge($this->errors, $mouvS->errors);
616 $this->db->rollback();
617 $this->error = $this->db->error();
629 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
632 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
635 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
642 if (!$error && !$notrigger) {
644 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
652 $this->oldref = $this->ref;
655 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
657 $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).
"'";
658 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
659 $resql = $this->db->query($sql);
662 $this->error = $this->db->lasterror();
664 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
665 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
666 $resql = $this->db->query($sql);
669 $this->error = $this->db->lasterror();
675 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
676 $dirdest = $conf->reception->dir_output.
'/'.$newref;
677 if (!$error && file_exists($dirsource)) {
678 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
680 if (@rename($dirsource, $dirdest)) {
683 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
684 foreach ($listoffiles as $fileentry) {
685 $dirsource = $fileentry[
'name'];
686 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
687 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
688 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
689 @rename($dirsource, $dirdest);
698 $this->
ref = $numref;
699 $this->
statut = self::STATUS_VALIDATED;
700 $this->
status = self::STATUS_VALIDATED;
707 foreach ($this->errors as $errmsg) {
708 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
709 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
711 $this->db->rollback();
723 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
724 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
728 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
729 if (empty($this->origin_object)) {
731 if (empty($this->origin_object->lines)) {
732 $res = $this->origin_object->fetch_lines();
733 $this->commandeFournisseur = $this->origin_object;
740 $qty_received = array();
741 $qty_wished = array();
744 $filter = array(
't.fk_commande'=>$this->origin_id);
746 $filter[
't.status'] = 1;
749 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
751 $this->error = $supplierorderdispatch->error;
752 $this->errors = $supplierorderdispatch->errors;
756 foreach ($supplierorderdispatch->lines as $dispatch_line) {
757 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
758 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
760 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
765 foreach ($this->commandeFournisseur->lines as $origin_line) {
767 if ((!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') && $origin_line->product_type > 0) || $origin_line->product_type > 1) {
771 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
775 $diff_array = array_diff_assoc($qty_received, $qty_wished);
776 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
777 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
779 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
785 if (count($diff_array) > 0) {
788 foreach ($diff_array as $key => $value) {
790 if ($qty_received[$key] >= $qty_wished[$key]) {
796 if ($close == count($diff_array)) {
823 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
825 global $conf, $langs, $user;
827 $num = count($this->lines);
830 $line->fk_entrepot = $entrepot_id;
831 $line->fk_commandefourndet = $id;
835 $result = $supplierorderline->fetch($id);
837 $this->error = $supplierorderline->error;
838 $this->errors = $supplierorderline->errors;
843 if (isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
844 $fk_product = $supplierorderline->fk_product;
846 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
847 $langs->load(
"errors");
848 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
854 $product =
new Product($this->db);
855 $product->fetch($fk_product);
856 if (isModEnabled(
'productbatch')) {
857 $langs->load(
"errors");
858 if (!empty($product->status_batch) && empty($batch)) {
859 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
861 } elseif (empty($product->status_batch) && !empty($batch)) {
862 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
869 $line->array_options = $supplierorderline->array_options;
870 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
871 foreach ($array_options as $key => $value) {
872 $line->array_options[$key] = $value;
876 $line->fk_product = $fk_product;
877 $line->fk_commande = $supplierorderline->fk_commande;
878 $line->fk_user = $user->id;
879 $line->comment = $comment;
880 $line->batch = $batch;
881 $line->eatby = $eatby;
882 $line->sellby = $sellby;
884 $line->cost_price = $cost_price;
885 $line->fk_reception = $this->id;
887 $this->lines[$num] = $line;
900 public function update($user =
null, $notrigger = 0)
907 if (isset($this->
ref)) {
908 $this->
ref = trim($this->
ref);
910 if (isset($this->entity)) {
911 $this->entity = trim($this->entity);
913 if (isset($this->ref_supplier)) {
914 $this->ref_supplier = trim($this->ref_supplier);
916 if (isset($this->socid)) {
917 $this->socid = trim($this->socid);
919 if (isset($this->fk_user_author)) {
920 $this->fk_user_author = trim($this->fk_user_author);
922 if (isset($this->fk_user_valid)) {
923 $this->fk_user_valid = trim($this->fk_user_valid);
925 if (isset($this->shipping_method_id)) {
926 $this->shipping_method_id = trim($this->shipping_method_id);
928 if (isset($this->tracking_number)) {
929 $this->tracking_number = trim($this->tracking_number);
931 if (isset($this->
statut)) {
934 if (isset($this->trueDepth)) {
935 $this->trueDepth = trim($this->trueDepth);
937 if (isset($this->trueWidth)) {
938 $this->trueWidth = trim($this->trueWidth);
940 if (isset($this->trueHeight)) {
941 $this->trueHeight = trim($this->trueHeight);
943 if (isset($this->size_units)) {
944 $this->size_units = trim($this->size_units);
946 if (isset($this->weight_units)) {
947 $this->weight_units = trim($this->weight_units);
949 if (isset($this->trueWeight)) {
950 $this->weight = trim($this->trueWeight);
952 if (isset($this->note_private)) {
953 $this->note_private = trim($this->note_private);
955 if (isset($this->note_public)) {
956 $this->note_public = trim($this->note_public);
958 if (isset($this->model_pdf)) {
959 $this->model_pdf = trim($this->model_pdf);
967 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
969 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
970 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
971 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
972 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
973 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
974 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
975 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
976 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
977 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
978 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
979 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
980 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
981 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
982 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
983 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
984 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
985 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
986 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
987 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
988 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
989 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
990 $sql .=
" entity = ".((int) $conf->entity);
991 $sql .=
" WHERE rowid=".((int) $this->
id);
995 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
996 $resql = $this->db->query($sql);
999 $this->errors[] =
"Error ".$this->db->lasterror();
1005 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1015 foreach ($this->errors as $errmsg) {
1016 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1017 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1019 $this->db->rollback();
1022 $this->db->commit();
1035 global $conf, $langs, $user;
1036 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1045 if (isModEnabled(
'stock') &&
1049 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1051 $langs->load(
"agenda");
1054 $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";
1055 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1056 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1057 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1058 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1060 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1061 $resql = $this->db->query($sql);
1063 $cpt = $this->db->num_rows($resql);
1064 for ($i = 0; $i < $cpt; $i++) {
1065 dol_syslog(get_class($this).
"::delete movement index ".$i);
1066 $obj = $this->db->fetch_object($resql);
1070 $mouvS->origin =
null;
1072 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby ? $this->db->jdate($obj->eatby) :
null, $obj->sellby ? $this->db->jdate($obj->sellby) :
null, $obj->batch);
1075 $this->error = $mouvS->error;
1076 $this->errors = $mouvS->errors;
1081 $this->errors[] =
"Error ".$this->db->lasterror();
1086 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1087 $ef = $main.
"_extrafields";
1089 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1091 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1092 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1094 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1102 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1103 $sql .=
" WHERE rowid = ".((int) $this->
id);
1105 if ($this->db->query($sql)) {
1107 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1113 if (!empty($this->origin) && $this->origin_id > 0) {
1115 $origin = $this->origin;
1116 if ($this->$origin->statut == 4) {
1118 $this->$origin->loadReceptions();
1120 if (count($this->$origin->receptions) <= 0) {
1121 $this->$origin->setStatut(3);
1127 $this->db->commit();
1131 if (!empty($conf->reception->dir_output)) {
1132 $dir = $conf->reception->dir_output.
'/'.$ref;
1133 $file = $dir.
'/'.$ref.
'.pdf';
1134 if (file_exists($file)) {
1139 if (file_exists($dir)) {
1141 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1149 $this->db->rollback();
1153 $this->error = $this->db->lasterror().
" - sql=$sql";
1154 $this->db->rollback();
1158 $this->error = $this->db->lasterror().
" - sql=$sql";
1159 $this->db->rollback();
1163 $this->error = $this->db->lasterror().
" - sql=$sql";
1164 $this->db->rollback();
1168 $this->db->rollback();
1182 $this->lines = array();
1184 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1186 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1187 $resql = $this->db->query($sql);
1189 if (!empty($resql)) {
1190 while ($obj = $this->db->fetch_object($resql)) {
1193 $line->fetch($obj->rowid);
1196 $line->fetch_product();
1198 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1199 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1200 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1201 $sql_commfourndet .=
' ORDER BY rang';
1203 $resql_commfourndet = $this->db->query($sql_commfourndet);
1204 if (!empty($resql_commfourndet)) {
1205 $obj = $this->db->fetch_object($resql_commfourndet);
1206 $line->qty_asked = $obj->qty;
1207 $line->description = $obj->description;
1208 $line->desc = $obj->description;
1209 $line->tva_tx = $obj->tva_tx;
1210 $line->vat_src_code = $obj->vat_src_code;
1211 $line->subprice = $obj->subprice;
1212 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1213 $line->remise_percent = $obj->remise_percent;
1214 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1215 $line->ref_supplier = $obj->ref;
1216 $line->total_ht = $obj->total_ht;
1217 $line->total_ttc = $obj->total_ttc;
1218 $line->total_tva = $obj->total_tva;
1220 $line->qty_asked = 0;
1221 $line->description =
'';
1223 $line->label = $obj->label;
1226 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1227 $tva = $pu_ht * $line->tva_tx / 100;
1228 $this->total_ht += $pu_ht;
1229 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1231 $this->total_ttc += $pu_ht + $tva;
1233 if (isModEnabled(
'productbatch') && !empty($line->batch)) {
1235 $detail_batch->eatby = $line->eatby;
1236 $detail_batch->sellby = $line->sellby;
1237 $detail_batch->batch = $line->batch;
1238 $detail_batch->qty = $line->qty;
1239 $line->detail_batch[] = $detail_batch;
1242 $this->lines[] = $line;
1261 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1263 global $langs, $hookmanager;
1266 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1267 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1268 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1270 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1277 if (empty($notooltip)) {
1279 $label = $langs->trans(
"Reception");
1280 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1282 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1283 $linkclose .=
' class="classfortooltip"';
1286 $linkstart =
'<a href="'.$url.
'"';
1287 $linkstart .= $linkclose.
'>';
1290 $result .= $linkstart;
1292 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1294 if ($withpicto != 2) {
1295 $result .= $this->ref;
1298 $result .= $linkend;
1301 $hookmanager->initHooks(array($this->element .
'dao'));
1302 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1303 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1305 $result = $hookmanager->resPrint;
1307 $result .= $hookmanager->resPrint;
1337 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1338 $this->labelStatus[0] =
'StatusReceptionDraft';
1340 $this->labelStatus[1] =
'StatusReceptionValidated';
1342 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1345 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1347 $this->labelStatus[2] =
'StatusReceptionProcessed';
1350 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1351 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1352 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1353 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1355 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1356 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1358 $statusType =
'status'.$status;
1359 if ($status == self::STATUS_VALIDATED) {
1360 $statusType =
'status4';
1362 if ($status == self::STATUS_CLOSED) {
1363 $statusType =
'status6';
1366 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1378 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1380 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1381 $return .=
'<div class="info-box info-box-sm">';
1382 $return .=
'<div class="info-box-icon bg-infobox-action">';
1384 $return .=
'</div>';
1385 $return .=
'<div class="info-box-content">';
1386 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1387 if ($selected >= 0) {
1388 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1390 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1391 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1396 if (method_exists($this,
'getLibStatut')) {
1397 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1399 $return .=
'</div>';
1400 $return .=
'</div>';
1401 $return .=
'</div>';
1417 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1418 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1421 dol_syslog(get_class($this).
"::initAsSpecimen");
1424 $order->initAsSpecimen();
1428 $this->
ref =
'SPECIMEN';
1429 $this->specimen = 1;
1432 $this->date_creation = $now;
1433 $this->date_valid = $now;
1434 $this->date_delivery = $now;
1435 $this->date_reception = $now + 24 * 3600;
1437 $this->entrepot_id = 0;
1440 $this->origin_id = 1;
1441 $this->origin =
'commande';
1442 $this->origin_object = $order;
1443 $this->commandeFournisseur = $order;
1445 $this->note_private =
'Private note';
1446 $this->note_public =
'Public note';
1450 while ($xnbp < $nbp) {
1452 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1453 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1454 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1457 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1459 $this->lines[] = $line;
1474 if ($user->hasRight(
'reception',
'creer')) {
1475 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1476 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1477 $sql .=
" WHERE rowid = ".((int) $this->
id);
1479 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1480 $resql = $this->db->query($sql);
1482 $this->date_delivery = $delivery_date;
1485 $this->error = $this->db->error();
1503 $this->meths = array();
1505 $sql =
"SELECT em.rowid, em.code, em.libelle";
1506 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1507 $sql .=
" WHERE em.active = 1";
1508 $sql .=
" ORDER BY em.libelle ASC";
1510 $resql = $this->db->query($sql);
1512 while ($obj = $this->db->fetch_object($resql)) {
1513 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1514 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1531 $this->listmeths = array();
1534 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1535 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1537 $sql .=
" WHERE em.rowid = ".((int) $id);
1540 $resql = $this->db->query($sql);
1542 while ($obj = $this->db->fetch_object($resql)) {
1543 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1544 $this->listmeths[$i][
'code'] = $obj->code;
1545 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1546 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1547 $this->listmeths[$i][
'description'] = $obj->description;
1548 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1549 $this->listmeths[$i][
'active'] = $obj->active;
1563 if (!empty($this->shipping_method_id)) {
1564 $sql =
"SELECT em.code, em.tracking";
1565 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1566 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1568 $resql = $this->db->query($sql);
1570 if ($obj = $this->db->fetch_object($resql)) {
1571 $tracking = $obj->tracking;
1576 if (!empty($tracking) && !empty($value)) {
1577 $url = str_replace(
'{TRACKID}', $value, $tracking);
1578 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1580 $this->tracking_url = $value;
1591 global $conf, $langs, $user;
1596 if ($this->
statut == Reception::STATUS_CLOSED) {
1597 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
1603 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
1604 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1606 $resql = $this->db->query($sql);
1609 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1610 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1613 $order->fetch($this->origin_id);
1615 $order->loadReceptions(self::STATUS_CLOSED);
1617 $receptions_match_order = 1;
1618 foreach ($order->lines as $line) {
1619 $lineid = $line->id;
1621 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
1622 $receptions_match_order = 0;
1623 $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';
1628 if ($receptions_match_order) {
1629 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');
1630 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1634 $this->
statut = self::STATUS_CLOSED;
1635 $this->
status = self::STATUS_CLOSED;
1638 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1639 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1641 $langs->load(
"agenda");
1645 $sql =
"SELECT cd.fk_product, cd.subprice,";
1646 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1647 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1648 $sql .=
" ed.cost_price";
1649 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1650 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1651 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1652 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1654 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1655 $resql = $this->db->query($sql);
1658 $cpt = $this->db->num_rows($resql);
1659 for ($i = 0; $i < $cpt; $i++) {
1660 $obj = $this->db->fetch_object($resql);
1667 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1670 $mouvS->origin = &$this;
1671 $mouvS->setOrigin($this->element, $this->
id);
1673 if (empty($obj->batch)) {
1677 $inventorycode =
'';
1678 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1680 $this->error = $mouvS->error;
1681 $this->errors = $mouvS->errors;
1689 $inventorycode =
'';
1690 $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);
1693 $this->error = $mouvS->error;
1694 $this->errors = $mouvS->errors;
1701 $this->error = $this->db->lasterror();
1708 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1719 $this->db->commit();
1722 $this->db->rollback();
1739 if ($this->
statut == Reception::STATUS_VALIDATED) {
1744 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1745 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1747 $resql = $this->db->query($sql);
1752 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1759 $this->errors[] = $this->db->lasterror;
1762 if (empty($error)) {
1763 $this->db->commit();
1766 $this->db->rollback();
1778 global $conf, $langs, $user;
1784 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1785 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1787 $resql = $this->db->query($sql);
1789 $this->
statut = self::STATUS_VALIDATED;
1790 $this->
status = self::STATUS_VALIDATED;
1794 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1795 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1796 $numref = $this->ref;
1797 $langs->load(
"agenda");
1801 $sql =
"SELECT ed.fk_product, cd.subprice,";
1802 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1803 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1804 $sql .=
" ed.cost_price";
1805 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1806 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1807 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1808 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1810 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1811 $resql = $this->db->query($sql);
1813 $cpt = $this->db->num_rows($resql);
1814 for ($i = 0; $i < $cpt; $i++) {
1815 $obj = $this->db->fetch_object($resql);
1823 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1827 $mouvS->origin = &$this;
1828 $mouvS->setOrigin($this->element, $this->
id);
1830 if (empty($obj->batch)) {
1834 $inventorycode =
'';
1835 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1838 $this->error = $mouvS->error;
1839 $this->errors = $mouvS->errors;
1847 $inventorycode =
'';
1848 $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);
1850 $this->error = $mouvS->error;
1851 $this->errors = $mouvS->errors;
1858 $this->error = $this->db->lasterror();
1865 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1871 if (!$error && $this->origin ==
'order_supplier') {
1872 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1875 $commande->fetch($this->origin_id);
1876 $result = $commande->setStatus($user, 4);
1879 $this->error = $commande->error;
1880 $this->errors = $commande->errors;
1885 $this->errors[] = $this->db->lasterror();
1889 $this->db->commit();
1892 $this->db->rollback();
1906 global $conf, $langs;
1911 if ($this->
statut <= self::STATUS_DRAFT) {
1915 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
1916 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
1917 $this->error =
'Permission denied';
1923 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1924 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1925 $sql .=
" WHERE rowid = ".((int) $this->
id);
1928 if ($this->db->query($sql)) {
1930 if (!$error && isModEnabled(
'stock') &&
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION')) {
1931 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1933 $langs->load(
"agenda");
1937 $sql =
"SELECT cd.fk_product, cd.subprice,";
1938 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1939 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1940 $sql .=
" ed.cost_price";
1941 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1942 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1943 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1944 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1946 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1947 $resql = $this->db->query($sql);
1949 $cpt = $this->db->num_rows($resql);
1950 for ($i = 0; $i < $cpt; $i++) {
1951 $obj = $this->db->fetch_object($resql);
1959 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1963 $mouvS->origin = &$this;
1964 $mouvS->setOrigin($this->element, $this->
id);
1966 if (empty($obj->batch)) {
1970 $inventorycode =
'';
1971 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1973 $this->error = $mouvS->error;
1974 $this->errors = $mouvS->errors;
1982 $inventorycode =
'';
1983 $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);
1985 $this->error = $mouvS->error;
1986 $this->errors = $mouvS->errors;
1993 $this->error = $this->db->lasterror();
2000 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
2005 if ($this->origin ==
'order_supplier') {
2006 if (!empty($this->origin) && $this->origin_id > 0) {
2008 $origin = $this->origin;
2009 if ($this->$origin->statut == 4) {
2011 $this->$origin->fetchObjectLinked();
2013 if (!empty($this->$origin->linkedObjects[
'reception'])) {
2014 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
2015 if ($rcption->statut > 0) {
2022 $this->$origin->setStatut(3);
2030 $this->
statut = self::STATUS_DRAFT;
2031 $this->
status = self::STATUS_DRAFT;
2032 $this->db->commit();
2035 $this->db->rollback();
2039 $this->error = $this->db->error();
2040 $this->db->rollback();
2055 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2057 global $conf, $langs;
2059 $langs->load(
"receptions");
2062 $modele =
'squille';
2064 if ($this->model_pdf) {
2065 $modele = $this->model_pdf;
2067 $modele = $conf->global->RECEPTION_ADDON_PDF;
2071 $modelpath =
"core/modules/reception/doc/";
2075 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2088 $tables = array(
'reception');
2104 'commande_fournisseur_dispatch'
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Class to manage table commandefournisseurdispatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0)
Return clicable link of object (with eventually picto)
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this record also the stock movement)
getNextNumRef($soc)
Return next contract ref.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='', $cost_price=0)
Add an reception line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
list_delivery_methods($id='')
Fetch all deliveries method and return an array.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
__construct($db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create reception en base.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
setDraft($user)
Set draft status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
trait CommonIncoterm
Superclass for incoterm classes.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut