39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/reception/class/receptionlinebatch.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
62 public $TRIGGER_PREFIX =
'RECEPTION';
72 public $element =
"reception";
77 public $fk_element =
"fk_reception";
82 public $table_element =
"reception";
87 public $table_element_line =
"receptiondet_batch";
92 public $picto =
'dollyrevert';
101 public $ref_supplier;
110 public $tracking_number;
114 public $tracking_url;
131 public $weight_units;
147 public $height_units;
167 public $user_author_id;
172 public $date_delivery;
184 public $date_reception;
203 public $lines = array();
210 public $detail_batch;
212 const STATUS_CANCELED = -1;
213 const STATUS_DRAFT = 0;
214 const STATUS_VALIDATED = 1;
215 const STATUS_CLOSED = 2;
227 $this->ismultientitymanaged = 1;
228 $this->isextrafieldmanaged = 1;
237 public function getNextNumRef($soc)
239 global $langs,
$conf;
240 $langs->load(
"receptions");
249 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
251 foreach ($dirmodels as $reldir) {
255 $mybool = ((bool) @include_once $dir.$file) || $mybool;
263 $obj =
new $classname();
264 '@phan-var-force ModelNumRefReception $obj';
267 $numref = $obj->getNextValue($soc, $this);
272 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
276 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
288 public function create($user, $notrigger = 0)
294 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
299 if (empty($this->fk_project)) {
300 $this->fk_project = 0;
302 if (empty($this->weight_units)) {
303 $this->weight_units = 0;
305 if (empty($this->size_units)) {
306 $this->size_units = 0;
308 if (empty($this->date_creation)) {
309 $this->date_creation = $now;
318 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
321 $sql .=
", ref_supplier";
322 $sql .=
", date_creation";
323 $sql .=
", fk_user_author";
324 $sql .=
", date_reception";
325 $sql .=
", date_delivery";
327 $sql .=
", fk_projet";
328 $sql .=
", fk_shipping_method";
329 $sql .=
", tracking_number";
334 $sql .=
", weight_units";
335 $sql .=
", size_units";
336 $sql .=
", note_private";
337 $sql .=
", note_public";
338 $sql .=
", model_pdf";
339 $sql .=
", fk_incoterms, location_incoterms";
340 $sql .=
") VALUES (";
342 $sql .=
", ".((int) $this->entity);
343 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
344 $sql .=
", '".$this->db->idate($this->date_creation).
"'";
345 $sql .=
", ".((int) $user->id);
346 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
347 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
348 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
349 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
350 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
351 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
352 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((float) $this->weight));
353 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((float) $this->trueDepth));
354 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((float) $this->trueWidth));
355 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((float) $this->trueHeight));
356 $sql .=
", ".((int) $this->weight_units);
357 $sql .=
", ".((int) $this->size_units);
358 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
359 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
360 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
361 $sql .=
", ".(int) $this->fk_incoterms;
362 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
365 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
367 $resql = $this->db->query($sql);
370 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
373 $initialref =
'(PROV'.$this->id.
')';
374 if (!empty($this->
ref)) {
375 $initialref = $this->ref;
378 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
379 $sql .=
" SET ref = '".$this->db->escape($initialref).
"'";
380 $sql .=
" WHERE rowid = ".((int) $this->
id);
382 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
383 if ($this->db->query($sql)) {
385 $num = count($this->lines);
386 for ($i = 0; $i < $num; $i++) {
387 $this->lines[$i]->fk_reception = $this->id;
389 if ($this->lines[$i]->
create($user) <= 0) {
395 if (!$error && $this->
id && $this->origin_id) {
410 if (!$error && !$notrigger) {
412 $result = $this->call_trigger(
'RECEPTION_CREATE', $user);
423 foreach ($this->errors as $errmsg) {
424 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
425 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
427 $this->db->rollback();
432 $this->error = $this->db->lasterror().
" - sql=$sql";
433 $this->db->rollback();
438 $this->error = $this->db->error().
" - sql=$sql";
439 $this->db->rollback();
457 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
463 $receptionline->fk_reception = $this->id;
464 $receptionline->entrepot_id = $entrepot_id;
465 $receptionline->fk_elementdet = $origin_line_id;
466 $receptionline->element_type = $this->origin;
467 $receptionline->fk_parent = $parent_line_id;
468 $receptionline->fk_product = $product_id;
469 $receptionline->qty = $qty;
470 $receptionline->rang = $rang;
471 $receptionline->array_options = $array_options;
473 if (!($receptionline->fk_product > 0)) {
475 $order_line->fetch($receptionline->fk_elementdet);
476 $receptionline->fk_product = $order_line->fk_product;
479 if (($lineId = $receptionline->insert($user)) < 0) {
480 $this->errors[] = $receptionline->error;
493 public function fetch($id, $ref =
'', $ref_ext =
'')
496 if (empty($id) && empty($ref) && empty($ref_ext)) {
500 $sql =
"SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut as status, e.fk_projet as fk_project, e.billed";
501 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
502 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery, e.date_valid";
503 $sql .=
", e.fk_shipping_method, e.tracking_number";
504 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
505 $sql .=
", e.note_private, e.note_public";
506 $sql .=
', e.fk_incoterms, e.location_incoterms';
507 $sql .=
', i.libelle as label_incoterms';
508 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
509 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"' AND el.sourcetype = 'order_supplier'";
510 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
513 $sql .=
" WHERE e.rowid = ".((int) $id);
515 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
517 $sql .=
" AND e.ref = '".$this->db->escape($ref).
"'";
518 } elseif ($ref_ext) {
519 $sql .=
" AND e.ref_ext = '".$this->db->escape($ref_ext).
"'";
523 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
524 $result = $this->db->query($sql);
526 if ($this->db->num_rows($result)) {
527 $obj = $this->db->fetch_object($result);
529 $this->
id = $obj->rowid;
530 $this->entity = $obj->entity;
531 $this->
ref = $obj->ref;
532 $this->socid = $obj->socid;
533 $this->ref_supplier = $obj->ref_supplier;
534 $this->ref_ext = $obj->ref_ext;
535 $this->statut = $obj->status;
536 $this->
status = $obj->status;
537 $this->billed = $obj->billed;
538 $this->fk_project = $obj->fk_project;
539 $this->user_author_id = $obj->fk_user_author;
540 $this->date_creation = $this->db->jdate($obj->date_creation);
541 $this->
date = $this->db->jdate($obj->date_reception);
542 $this->date_reception = $this->db->jdate($obj->date_reception);
543 $this->date_delivery = $this->db->jdate($obj->date_delivery);
544 $this->date_valid = $this->db->jdate($obj->date_valid);
545 $this->model_pdf = $obj->model_pdf;
546 $this->shipping_method_id = $obj->fk_shipping_method;
547 $this->tracking_number = $obj->tracking_number;
548 $this->origin = ($obj->origin ? $obj->origin :
'commande');
549 $this->origin_type = ($obj->origin ? $obj->origin :
'commande');
550 $this->origin_id = $obj->origin_id;
552 $this->trueWeight = $obj->weight;
553 $this->weight_units = $obj->weight_units;
555 $this->trueWidth = $obj->width;
556 $this->width_units = $obj->size_units;
557 $this->trueHeight = $obj->height;
558 $this->height_units = $obj->size_units;
559 $this->trueDepth = $obj->size;
560 $this->depth_units = $obj->size_units;
562 $this->note_public = $obj->note_public;
563 $this->note_private = $obj->note_private;
566 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
567 $this->size_units = $obj->size_units;
570 $this->fk_incoterms = $obj->fk_incoterms;
571 $this->location_incoterms = $obj->location_incoterms;
572 $this->label_incoterms = $obj->label_incoterms;
574 $this->db->free($result);
590 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
592 $extrafields->fetch_name_optionals_label($this->table_element,
true);
598 if (empty($obj->origin_id)) {
609 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
610 $this->error =
'Reception with id '.$id.
' not found';
614 $this->error = $this->db->error();
626 public function valid($user, $notrigger = 0)
628 global
$conf, $langs;
630 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
636 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
640 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
641 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
642 $this->error =
'Permission denied';
643 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
653 $soc->fetch($this->socid);
657 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
658 $numref = $this->getNextNumRef($soc);
668 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
669 $sql .=
" ref='".$this->db->escape($numref).
"'";
670 $sql .=
", fk_statut = 1";
671 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
672 $sql .=
", fk_user_valid = ".((int) $user->id);
673 $sql .=
" WHERE rowid = ".((int) $this->
id);
674 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
675 $resql = $this->db->query($sql);
677 $this->error = $this->db->lasterror();
683 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
685 $langs->load(
"agenda");
689 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
690 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
691 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
692 $sql .=
" ed.fk_elementdet, ed.cost_price";
693 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
694 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
695 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
696 $sql .=
" AND cd.rowid = ed.fk_elementdet";
698 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
699 $resql = $this->db->query($sql);
701 $cpt = $this->db->num_rows($resql);
702 for ($i = 0; $i < $cpt; $i++) {
703 $obj = $this->db->fetch_object($resql);
707 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
711 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
715 $mouvS->origin = &$this;
716 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
718 if (empty($obj->batch)) {
723 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
725 if (intval($result) < 0) {
736 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch,
'', 0, $inventorycode);
738 if (intval($result) < 0) {
746 $this->db->rollback();
747 $this->error = $this->db->error();
752 if (!$error && $this->origin_id > 0) {
760 $ret = $this->origin_object->Livraison($user,
dol_now(),
'tot',
'');
763 $this->errors = array_merge($this->errors, $this->origin_object->errors);
766 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
774 if (!$error && !$notrigger) {
776 $result = $this->call_trigger(
'RECEPTION_VALIDATE', $user);
784 $this->oldref = $this->ref;
787 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
789 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'reception/".$this->db->escape($this->newref).
"'";
790 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
791 $resql = $this->db->query($sql);
794 $this->error = $this->db->lasterror();
796 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'reception/".$this->db->escape($this->newref).
"'";
797 $sql .=
" WHERE filepath = 'reception/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
798 $resql = $this->db->query($sql);
801 $this->error = $this->db->lasterror();
807 $dirsource =
$conf->reception->dir_output.
'/'.$oldref;
808 $dirdest =
$conf->reception->dir_output.
'/'.$newref;
809 if (!$error && file_exists($dirsource)) {
810 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
812 if (@rename($dirsource, $dirdest)) {
815 $listoffiles =
dol_dir_list(
$conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
816 foreach ($listoffiles as $fileentry) {
817 $dirsource = $fileentry[
'name'];
818 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
819 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
820 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
821 @rename($dirsource, $dirdest);
830 $this->
ref = $numref;
831 $this->statut = self::STATUS_VALIDATED;
832 $this->
status = self::STATUS_VALIDATED;
839 foreach ($this->errors as $errmsg) {
840 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
841 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
843 $this->db->rollback();
855 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
856 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
860 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
861 if (empty($this->origin_object)) {
863 if ($this->origin_object instanceof
CommonObject && empty($this->origin_object->lines)) {
864 $res = $this->origin_object->fetch_lines();
865 $this->commandeFournisseur =
null;
869 } elseif ($this->origin_object instanceof
CommandeFournisseur && empty($this->origin_object->lines)) {
870 $res = $this->origin_object->fetch_lines();
878 $qty_received = array();
879 $qty_wished = array();
882 $filter = array(
't.fk_element' => $this->origin_id);
884 $filter[
't.status'] = 1;
887 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
893 foreach ($supplierorderdispatch->lines as $dispatch_line) {
894 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
895 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
897 $qty_received[$dispatch_line->fk_product] = $dispatch_line->qty;
902 foreach ($this->origin_object->lines as $origin_line) {
904 if (($origin_line->product_type > 0 && (!
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES') || empty($origin_line->stockable_product))) || $origin_line->product_type > 1) {
907 if (array_key_exists($origin_line->fk_product, $qty_wished)) {
908 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
910 $qty_wished[$origin_line->fk_product] = $origin_line->qty;
915 $diff_array = array_diff_assoc($qty_received, $qty_wished);
916 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
917 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
919 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
925 if (count($diff_array) > 0) {
928 foreach ($diff_array as $key => $value) {
930 if ($qty_received[$key] >= $qty_wished[$key]) {
936 if ($close == count($diff_array)) {
963 public function addline($entrepot_id, $id, $qty, $array_options = [], $comment =
'', $eatby =
null, $sellby =
null, $batch =
'', $cost_price = 0)
965 global
$conf, $langs, $user;
967 $num = count($this->lines);
970 $line->fk_entrepot = $entrepot_id;
971 $line->fk_commandefourndet = $id;
975 $result = $supplierorderline->fetch($id);
982 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
983 $fk_product = $supplierorderline->fk_product;
985 if (!($entrepot_id > 0) && !
getDolGlobalInt(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS')) {
986 $langs->load(
"errors");
987 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
993 $product =
new Product($this->db);
994 $product->fetch($fk_product);
996 $langs->load(
"errors");
997 if (!empty($product->status_batch) && empty($batch)) {
998 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
1000 } elseif (empty($product->status_batch) && !empty($batch)) {
1001 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
1007 if (!empty($errorMsgArr)) {
1008 $errorMessage =
'<b>' . $product->ref .
'</b> : ';
1009 $errorMessage .=
'<ul>';
1010 foreach ($errorMsgArr as $errorMsg) {
1011 $errorMessage .=
'<li>' . $errorMsg .
'</li>';
1013 $errorMessage .=
'</ul>';
1014 $this->error = $errorMessage;
1021 $line->array_options = $supplierorderline->array_options;
1022 if (!
getDolGlobalInt(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1023 foreach ($array_options as $key => $value) {
1024 $line->array_options[$key] = $value;
1028 $line->fk_product = $fk_product;
1029 $line->fk_commande = $supplierorderline->fk_commande;
1030 $line->fk_user = $user->id;
1031 $line->comment = $comment;
1032 $line->batch = $batch;
1033 $line->eatby = $eatby;
1034 $line->sellby = $sellby;
1036 $line->cost_price = $cost_price;
1037 $line->fk_reception = $this->id;
1039 $this->lines[$num] = $line;
1056 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options = [])
1058 global
$mysoc, $langs, $user;
1060 if ($this->
status == self::STATUS_DRAFT) {
1070 $ranktouse = $this->rang;
1071 if ($ranktouse == -1) {
1072 $rangmax = $this->
line_max($this->fk_reception);
1073 $ranktouse = $rangmax + 1;
1078 $this->line->fk_reception = $this->id;
1079 $this->line->element_type = $element_type;
1080 $this->line->fk_product = $fk_product;
1081 $this->line->description = $description;
1083 $this->line->qty = (float) $qty;
1084 $this->line->fk_unit = $fk_unit;
1085 $this->line->rang = $ranktouse;
1087 if (is_array($array_options) && count($array_options) > 0) {
1088 $this->line->array_options = $array_options;
1091 $result = $this->line->insert($user);
1093 if (!isset($this->context[
'createfromclone'])) {
1094 if ($this->fk_reception) {
1096 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1097 $linecount = count($this->lines);
1098 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1102 $this->lines[] = $this->line;
1105 $this->db->commit();
1106 return $this->line->id;
1108 $this->error = $this->line->error;
1109 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1110 $this->db->rollback();
1114 dol_syslog(get_class($this).
"::addlinefree status of reception must be Draft to allow use of ->addlinefree()", LOG_ERR);
1133 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options = array())
1135 global
$mysoc, $langs, $user;
1137 if ($this->statut == self::STATUS_DRAFT) {
1147 $qty = (float) $qty;
1148 $description = trim((
string) $description);
1153 $line->fetch($rowid);
1154 $line->fetch_optionals();
1156 if (!empty($line->fk_product)) {
1157 $product =
new Product($this->db);
1158 $result = $product->fetch($line->fk_product);
1159 $product_type = $product->type;
1162 $staticline = clone $line;
1164 $line->oldline = $staticline;
1165 $this->line = $line;
1166 $this->line->context = $this->context;
1167 $this->line->rang = $rang;
1168 $this->line->fk_reception = $this->id;
1169 $this->line->element_type = $element_type;
1170 $this->line->fk_product = $line->fk_product;
1171 $this->line->qty = $qty;
1172 $this->line->fk_unit = $fk_unit;
1173 $this->line->description = $description;
1175 if (is_array($array_options) && count($array_options) > 0) {
1177 foreach ($array_options as $key => $value) {
1178 $this->line->array_options[$key] = $array_options[$key];
1183 $result = $this->line->update($user, $notrigger);
1188 $this->db->commit();
1191 $this->error = $this->line->error;
1193 $this->db->rollback();
1197 $this->error = get_class($this).
"::updatelinefree reception status makes operation forbidden";
1198 $this->errors = array(
'ReceptionStatusMakeOperationForbidden');
1212 $this->lines = array();
1214 $sql =
'SELECT rc.rowid, rc.fk_reception, rc.fk_entrepot, rc.fk_product, rc.fk_unit, rc.description, rc.fk_elementdet, rc.fk_element, rc.element_type, rc.qty, rc.rang';
1215 $sql .=
' FROM '.MAIN_DB_PREFIX.
'receptiondet_batch as rc';
1216 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = rc.fk_product)';
1217 $sql .=
' WHERE rc.fk_reception = '.((int) $this->
id);
1219 $sql .=
' ORDER BY rc.rang, rc.rowid';
1221 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
1222 $result = $this->db->query($sql);
1224 $num = $this->db->num_rows($result);
1228 $objp = $this->db->fetch_object($result);
1232 $line->rowid = $objp->rowid;
1233 $line->id = $objp->rowid;
1234 $line->fk_reception = $this->id;
1236 $line->description = $objp->description;
1237 $line->qty = $objp->qty;
1238 $line->fk_entrepot = $objp->fk_entrepot;
1239 $line->fk_product = $objp->fk_product;
1241 $line->rang = $objp->rang;
1244 $line->fk_element = $objp->fk_element;
1245 $line->fk_unit = $objp->fk_unit;
1246 $line->fk_elementdet = $objp->fk_elementdet;
1247 $line->fk_element_type = $objp->element_type;
1248 $line->fetch_optionals();
1250 $this->lines[$i] = $line;
1255 $this->db->free($result);
1259 $this->error = $this->db->error();
1281 public function update($user =
null, $notrigger = 0)
1288 if (isset($this->
ref)) {
1289 $this->
ref = trim($this->
ref);
1291 if (isset($this->entity)) {
1292 $this->entity = (int) $this->entity;
1294 if (isset($this->ref_supplier)) {
1295 $this->ref_supplier = trim($this->ref_supplier);
1297 if (isset($this->socid)) {
1298 $this->socid = (int) trim((
string) $this->socid);
1300 if (isset($this->fk_user_author)) {
1301 $this->fk_user_author = (int) $this->fk_user_author;
1303 if (isset($this->fk_user_valid)) {
1304 $this->fk_user_valid = (int) $this->fk_user_valid;
1306 if (isset($this->shipping_method_id)) {
1307 $this->shipping_method_id = (int) $this->shipping_method_id;
1309 if (isset($this->tracking_number)) {
1310 $this->tracking_number = trim($this->tracking_number);
1312 if (isset($this->statut)) {
1313 $this->statut = (int) $this->statut;
1315 if (isset($this->trueDepth)) {
1316 $this->trueDepth =
price2num($this->trueDepth);
1318 if (isset($this->trueWidth)) {
1319 $this->trueWidth =
price2num($this->trueWidth);
1321 if (isset($this->trueHeight)) {
1322 $this->trueHeight =
price2num($this->trueHeight);
1324 $this->size_units = (int) $this->size_units;
1326 if (isset($this->trueWeight)) {
1327 $this->weight =
price2num($this->trueWeight);
1329 $this->weight_units = (int) $this->weight_units;
1331 if (isset($this->note_private)) {
1332 $this->note_private = trim($this->note_private);
1334 if (isset($this->note_public)) {
1335 $this->note_public = trim($this->note_public);
1337 if (isset($this->model_pdf)) {
1338 $this->model_pdf = trim($this->model_pdf);
1346 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
1348 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1349 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1350 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1351 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1352 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
1353 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1354 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1355 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
1356 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1357 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? ((
int) $this->shipping_method_id) :
"null").
",";
1358 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1359 $sql .=
" fk_statut=".(isset($this->statut) ? ((int) $this->statut) :
"null").
",";
1360 $sql .=
" height=".(($this->trueHeight !=
'') ? (
float) $this->trueHeight :
"null").
",";
1361 $sql .=
" width=".(($this->trueWidth !=
'') ? (
float) $this->trueWidth :
"null").
",";
1362 $sql .=
" size_units=".((int) $this->size_units).
",";
1363 $sql .=
" size=".(($this->trueDepth !=
'') ? (
float) $this->trueDepth :
"null").
",";
1364 $sql .=
" weight_units=".((int) $this->weight_units).
",";
1365 $sql .=
" weight=".(($this->trueWeight !=
'') ? (
float) $this->trueWeight :
"null").
",";
1366 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1367 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1368 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1369 $sql .=
" fk_projet=".((isset($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1370 $sql .=
" entity = ".((int)
$conf->entity);
1371 $sql .=
" WHERE rowid=".((int) $this->
id);
1375 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1376 $resql = $this->db->query($sql);
1379 $this->errors[] =
"Error ".$this->db->lasterror();
1385 $result = $this->call_trigger(
'RECEPTION_MODIFY', $user);
1395 foreach ($this->errors as $errmsg) {
1396 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1397 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1399 $this->db->rollback();
1402 $this->db->commit();
1413 public function delete(
User $user)
1415 global
$conf, $langs, $user;
1416 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1426 || (
getDolGlobalInt(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') && $this->
status == Reception::STATUS_CLOSED))
1428 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1430 $langs->load(
"agenda");
1433 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.eatby, ed.sellby, ed.batch, ed.rowid as receptiondet_batch_id";
1434 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1435 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
1436 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1437 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1439 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1440 $resql = $this->db->query($sql);
1442 $cpt = $this->db->num_rows($resql);
1443 for ($i = 0; $i < $cpt; $i++) {
1444 dol_syslog(get_class($this).
"::delete movement index ".$i);
1445 $obj = $this->db->fetch_object($resql);
1449 $mouvS->origin =
null;
1451 $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);
1454 $this->error = $mouvS->error;
1455 $this->errors = $mouvS->errors;
1460 $this->errors[] =
"Error ".$this->db->lasterror();
1465 $sanitized_main = MAIN_DB_PREFIX.
'receptiondet_batch';
1466 $sanitized_ef = $sanitized_main.
"_extrafields";
1468 $sqlef =
"DELETE FROM ".$sanitized_ef.
" WHERE fk_object IN (SELECT rowid FROM ".$sanitized_main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1470 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1471 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1473 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1481 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1482 $sql .=
" WHERE rowid = ".((int) $this->
id);
1484 if ($this->db->query($sql)) {
1486 $result = $this->call_trigger(
'RECEPTION_DELETE', $user);
1492 if (!empty($this->origin) && $this->origin_id > 0) {
1495 '@phan-var-force CommandeFournisseur $origin_object';
1508 $this->db->commit();
1512 if (!empty(
$conf->reception->dir_output)) {
1513 $dir =
$conf->reception->dir_output.
'/'.$ref;
1514 $file = $dir.
'/'.$ref.
'.pdf';
1515 if (file_exists($file)) {
1520 if (file_exists($dir)) {
1522 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1530 $this->db->rollback();
1534 $this->error = $this->db->lasterror().
" - sql=$sql";
1535 $this->db->rollback();
1539 $this->error = $this->db->lasterror().
" - sql=$sql";
1540 $this->db->rollback();
1544 $this->error = $this->db->lasterror().
" - sql=$sql";
1545 $this->db->rollback();
1549 $this->db->rollback();
1563 $this->lines = array();
1565 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1567 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"receptiondet_batch";
1568 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1570 $resql = $this->db->query($sql);
1572 if (!empty($resql)) {
1573 while ($obj = $this->db->fetch_object($resql)) {
1576 $line->fetch($obj->rowid);
1579 $line->fetch_product();
1581 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1582 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1583 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1584 $sql_commfourndet .=
' ORDER BY rang';
1586 $resql_commfourndet = $this->db->query($sql_commfourndet);
1587 if (!empty($resql_commfourndet)) {
1588 $obj = $this->db->fetch_object($resql_commfourndet);
1589 $line->qty_asked = $obj->qty;
1590 $line->description = $obj->description;
1591 $line->desc = $obj->description;
1592 $line->tva_tx = $obj->tva_tx;
1593 $line->vat_src_code = $obj->vat_src_code;
1594 $line->subprice = $obj->subprice;
1595 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1596 $line->remise_percent = $obj->remise_percent;
1597 $line->label = !empty($obj->label) ? $obj->label : (is_object($line->product) ? $line->product->label :
'');
1598 $line->ref_supplier = $obj->ref;
1599 $line->total_ht = $obj->total_ht;
1600 $line->total_ttc = $obj->total_ttc;
1601 $line->total_tva = $obj->total_tva;
1603 $line->qty_asked = 0;
1604 $line->description =
'';
1606 $line->label = $obj->label;
1609 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1610 $tva = $pu_ht * $line->tva_tx / 100;
1611 $this->total_ht += $pu_ht;
1612 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1614 $this->total_ttc += $pu_ht + $tva;
1616 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1618 $detail_batch->eatby = $line->eatby;
1619 $detail_batch->sellby = $line->sellby;
1620 $detail_batch->batch = $line->batch;
1621 $detail_batch->qty = $line->qty;
1623 $line->detail_batch[] = $detail_batch;
1626 $this->lines[] = $line;
1645 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0)
1647 global $langs, $hookmanager;
1650 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1651 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1652 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1654 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1661 if (empty($notooltip)) {
1663 $label = $langs->trans(
"Reception");
1664 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1666 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1667 $linkclose .=
' class="classfortooltip"';
1670 $linkstart =
'<a href="'.$url.
'"';
1671 $linkstart .= $linkclose.
'>';
1674 $result .= $linkstart;
1676 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1678 if ($withpicto != 2) {
1679 $result .= $this->ref;
1682 $result .= $linkend;
1685 $hookmanager->initHooks(array($this->element .
'dao'));
1686 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1687 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1689 $result = $hookmanager->resPrint;
1691 $result .= $hookmanager->resPrint;
1704 return $this->
LibStatut($this->statut, $mode);
1721 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1722 $this->labelStatus[0] =
'StatusReceptionDraft';
1724 $this->labelStatus[1] =
'StatusReceptionValidated';
1726 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1729 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1731 $this->labelStatus[2] =
'StatusReceptionProcessed';
1734 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1735 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1736 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1737 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1739 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1740 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1742 $statusType =
'status'.$status;
1743 if ($status == self::STATUS_VALIDATED) {
1744 $statusType =
'status4';
1746 if ($status == self::STATUS_CLOSED) {
1747 $statusType =
'status6';
1750 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1762 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1764 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1765 $return .=
'<div class="info-box info-box-sm">';
1766 $return .=
'<div class="info-box-icon bg-infobox-action">';
1768 $return .=
'</div>';
1769 $return .=
'<div class="info-box-content">';
1770 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1771 if ($selected >= 0) {
1772 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1774 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1775 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1780 if (method_exists($this,
'getLibStatut')) {
1781 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1783 $return .=
'</div>';
1784 $return .=
'</div>';
1785 $return .=
'</div>';
1801 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1802 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1805 dol_syslog(get_class($this).
"::initAsSpecimen");
1808 $order->initAsSpecimen();
1812 $this->
ref =
'SPECIMEN';
1813 $this->specimen = 1;
1817 $this->date_creation = $now;
1818 $this->date_valid = $now;
1819 $this->date_delivery = $now;
1820 $this->date_reception = $now + 24 * 3600;
1821 $this->entrepot_id = 0;
1823 $this->origin_id = 1;
1824 $this->origin_type =
'supplier_order';
1825 $this->origin_object = $order;
1826 $this->note_private =
'Private note';
1827 $this->note_public =
'Public note';
1828 $this->tracking_number =
'TRACKID-ABC123';
1829 $this->fk_incoterms = 1;
1832 while ($xnbp < $nbp) {
1834 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1835 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1836 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1839 $line->fk_product = $this->origin_object->lines[$xnbp]->fk_product;
1841 $this->lines[] = $line;
1858 if ($user->hasRight(
'reception',
'creer')) {
1859 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1860 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1861 $sql .=
" WHERE rowid = ".((int) $this->
id);
1863 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1864 $resql = $this->db->query($sql);
1866 $this->date_delivery = $delivery_date;
1869 $this->error = $this->db->error();
1886 if ($user->hasRight(
'reception',
'creer')) {
1887 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1888 $sql .=
" SET date_reception = ".($reception_date ?
"'".$this->db->idate($reception_date).
"'" :
'null');
1889 $sql .=
" WHERE rowid = ".((int) $this->
id);
1891 dol_syslog(get_class($this).
"::setReceptionDate", LOG_DEBUG);
1892 $resql = $this->db->query($sql);
1894 $this->date_reception = $reception_date;
1897 $this->error = $this->db->error();
1915 $this->meths = array();
1917 $sql =
"SELECT em.rowid, em.code, em.libelle";
1918 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1919 $sql .=
" WHERE em.active = 1";
1920 $sql .=
" ORDER BY em.libelle ASC";
1922 $resql = $this->db->query($sql);
1924 while ($obj = $this->db->fetch_object($resql)) {
1925 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1926 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1943 $this->listmeths = array();
1946 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1947 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1949 $sql .=
" WHERE em.rowid = ".((int) $id);
1952 $resql = $this->db->query($sql);
1954 while ($obj = $this->db->fetch_object($resql)) {
1955 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1956 $this->listmeths[$i][
'code'] = $obj->code;
1957 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1958 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1959 $this->listmeths[$i][
'description'] = $obj->description;
1960 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1961 $this->listmeths[$i][
'active'] = $obj->active;
1975 if (!empty($this->shipping_method_id)) {
1976 $sql =
"SELECT em.code, em.tracking";
1977 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1978 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1980 $resql = $this->db->query($sql);
1982 if ($obj = $this->db->fetch_object($resql)) {
1983 $tracking = $obj->tracking;
1988 if (!empty($tracking) && !empty($value)) {
1989 $url = str_replace(
'{TRACKID}', $value, $tracking);
1990 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
1992 $this->tracking_url = $value;
2003 global
$conf, $langs, $user;
2008 if ($this->statut == Reception::STATUS_CLOSED) {
2009 dol_syslog(get_class($this).
"::setClosed already in closed status", LOG_WARNING);
2015 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut = '.self::STATUS_CLOSED;
2016 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2018 $resql = $this->db->query($sql);
2021 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
2022 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2025 $order->fetch($this->origin_id);
2027 $order->loadReceptions(self::STATUS_CLOSED);
2029 $receptions_match_order = 1;
2030 foreach ($order->lines as $line) {
2031 $lineid = $line->id;
2033 if (($line->product_type == 0 ||
getDolGlobalInt(
'STOCK_SUPPORTS_SERVICES')) && $order->receptions[$lineid] < $qty) {
2034 $receptions_match_order = 0;
2035 $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';
2040 if ($receptions_match_order) {
2041 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');
2042 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
2046 $this->statut = self::STATUS_CLOSED;
2047 $this->
status = self::STATUS_CLOSED;
2051 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2053 $langs->load(
"agenda");
2057 $sql =
"SELECT cd.fk_product, cd.subprice,";
2058 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2059 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2060 $sql .=
" ed.fk_elementdet, ed.cost_price";
2061 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2062 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2063 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2064 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2066 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2067 $resql = $this->db->query($sql);
2070 $cpt = $this->db->num_rows($resql);
2071 for ($i = 0; $i < $cpt; $i++) {
2072 $obj = $this->db->fetch_object($resql);
2076 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2080 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid);
2083 $mouvS->origin = &$this;
2084 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2086 if (empty($obj->batch)) {
2090 $inventorycode =
'';
2091 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2093 $this->error = $mouvS->error;
2094 $this->errors = $mouvS->errors;
2102 $inventorycode =
'';
2103 $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);
2106 $this->error = $mouvS->error;
2107 $this->errors = $mouvS->errors;
2114 $this->error = $this->db->lasterror();
2121 $result = $this->call_trigger(
'RECEPTION_CLOSED', $user);
2132 $this->db->commit();
2135 $this->statut = self::STATUS_VALIDATED;
2136 $this->
status = self::STATUS_VALIDATED;
2137 $this->db->rollback();
2154 if ($this->statut == Reception::STATUS_VALIDATED) {
2159 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
2160 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2162 $resql = $this->db->query($sql);
2167 $result = $this->call_trigger(
'RECEPTION_BILLED', $user);
2174 $this->errors[] = $this->db->lasterror;
2177 if (empty($error)) {
2178 $this->db->commit();
2181 $this->db->rollback();
2193 global $langs, $user;
2199 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
2200 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2202 $resql = $this->db->query($sql);
2203 $rollbackStatus = $this->status;
2204 $rollbackBilled = $this->billed;
2206 $this->statut = self::STATUS_VALIDATED;
2207 $this->
status = self::STATUS_VALIDATED;
2212 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2214 $langs->load(
"agenda");
2218 $sql =
"SELECT ed.fk_product, cd.subprice,";
2219 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2220 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2221 $sql .=
" ed.fk_elementdet, ed.cost_price";
2222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2223 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2224 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2225 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2227 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2228 $resql = $this->db->query($sql);
2230 $cpt = $this->db->num_rows($resql);
2231 for ($i = 0; $i < $cpt; $i++) {
2232 $obj = $this->db->fetch_object($resql);
2236 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2239 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2243 $mouvS->origin = &$this;
2244 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2246 if (empty($obj->batch)) {
2250 $inventorycode =
'';
2251 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
2254 $this->error = $mouvS->error;
2255 $this->errors = $mouvS->errors;
2263 $inventorycode =
'';
2264 $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);
2266 $this->error = $mouvS->error;
2267 $this->errors = $mouvS->errors;
2274 $this->error = $this->db->lasterror();
2281 $result = $this->call_trigger(
'RECEPTION_REOPEN', $user);
2287 if (!$error && $this->origin ==
'order_supplier') {
2288 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
2291 $commande->fetch($this->origin_id);
2292 $result = $commande->setStatus($user, 4);
2295 $this->error = $commande->error;
2296 $this->errors = $commande->errors;
2301 $this->errors[] = $this->db->lasterror();
2305 $this->db->commit();
2308 $this->statut = $this->
status = $rollbackStatus;
2309 $this->billed = $rollbackBilled;
2310 $this->db->rollback();
2329 if ($this->statut <= self::STATUS_DRAFT) {
2333 if (!((!
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'creer'))
2334 || (
getDolGlobalInt(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'reception',
'reception_advance',
'validate')))) {
2335 $this->error =
'Permission denied';
2341 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
2342 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2343 $sql .=
" WHERE rowid = ".((int) $this->
id);
2346 if ($this->db->query($sql)) {
2349 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2351 $langs->load(
"agenda");
2355 $sql =
"SELECT cd.fk_product, cd.subprice,";
2356 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2357 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
2358 $sql .=
" ed.fk_elementdet, ed.cost_price";
2359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
2360 $sql .=
" ".MAIN_DB_PREFIX.
"receptiondet_batch as ed";
2361 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
2362 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2364 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2365 $resql = $this->db->query($sql);
2367 $cpt = $this->db->num_rows($resql);
2368 for ($i = 0; $i < $cpt; $i++) {
2369 $obj = $this->db->fetch_object($resql);
2373 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
2377 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
2381 $mouvS->origin = &$this;
2382 $mouvS->setOrigin($this->element, $this->
id, $obj->fk_elementdet, $obj->rowid);
2384 if (empty($obj->batch)) {
2388 $inventorycode =
'';
2389 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
2391 $this->error = $mouvS->error;
2392 $this->errors = $mouvS->errors;
2400 $inventorycode =
'';
2401 $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);
2403 $this->error = $mouvS->error;
2404 $this->errors = $mouvS->errors;
2411 $this->error = $this->db->lasterror();
2418 $result = $this->call_trigger(
'RECEPTION_UNVALIDATE', $user);
2423 if ($this->origin ==
'order_supplier') {
2424 if (!empty($this->origin) && $this->origin_id > 0) {
2426 if ($this->origin_object->statut == 4) {
2428 $this->origin_object->fetchObjectLinked();
2430 if (!empty($this->origin_object->linkedObjects[
'reception'])) {
2431 foreach ($this->origin_object->linkedObjects[
'reception'] as $rcption) {
2432 if ($rcption->statut > 0) {
2439 $this->origin_object->setStatut(3);
2447 $this->statut = self::STATUS_DRAFT;
2448 $this->
status = self::STATUS_DRAFT;
2449 $this->db->commit();
2452 $this->db->rollback();
2456 $this->error = $this->db->error();
2457 $this->db->rollback();
2472 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2474 global
$conf, $langs;
2476 $langs->load(
"receptions");
2479 $modele =
'squille';
2481 if ($this->model_pdf) {
2482 $modele = $this->model_pdf;
2488 $modelpath =
"core/modules/reception/doc/";
2492 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2505 $tables = array(
'reception');
2521 'receptiondet_batch'
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used for example by trigger when WORKFLOW_RECEPTION_CLASSIFY_BILL...
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $notrigger, $array_options=array())
Update a simple reception line.
getUrlTrackingStatus($value='')
Forge an set tracking url.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLinesArray()
Create an array of reception lines.
fetch_lines_free()
Load lines of simple reception.
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this records also the stock movement)
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0)
Return clickable link of object (with eventually picto)
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a reception line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
__construct($db)
Constructor.
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $array_options=[])
Add a simple reception line.
initAsSpecimen()
Initialise an instance with random values.
setReceptionDate($user, $reception_date)
Set the reception date.
create($user, $notrigger=0)
Create reception.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
addline($entrepot_id, $id, $qty, $array_options=[], $comment='', $eatby=null, $sellby=null, $batch='', $cost_price=0)
Add an reception line.
setDraft($user)
Set draft status.
Class to manage table commandefournisseurdispatch.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
$conf db user
Active Directory does not allow anonymous connections.