36 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
62 public $element =
"reception";
67 public $fk_element =
"fk_reception";
68 public $table_element =
"reception";
69 public $table_element_line =
"commande_fournisseur_dispatch";
70 public $ismultientitymanaged = 1;
75 public $picto =
'dollyrevert';
82 public $tracking_number;
98 public $date_delivery;
104 public $date_reception;
109 public $date_creation;
122 public $lines = array();
127 public $detail_batch;
129 const STATUS_DRAFT = 0;
130 const STATUS_VALIDATED = 1;
131 const STATUS_CLOSED = 2;
145 $this->statuts = array();
146 $this->statuts[-1] =
'StatusReceptionCanceled';
147 $this->statuts[0] =
'StatusReceptionDraft';
149 $this->statuts[1] =
'StatusReceptionValidated';
151 $this->statuts[1] =
'StatusReceptionValidatedReceived';
154 $this->statuts[1] =
'StatusReceptionValidatedToReceive';
156 $this->statuts[2] =
'StatusReceptionProcessed';
159 $this->statuts_short = array();
160 $this->statuts_short[-1] =
'StatusReceptionCanceledShort';
161 $this->statuts_short[0] =
'StatusReceptionDraftShort';
162 $this->statuts_short[1] =
'StatusReceptionValidatedShort';
163 $this->statuts_short[2] =
'StatusReceptionProcessedShort';
174 global $langs, $conf;
175 $langs->load(
"receptions");
177 if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) {
180 $file = $conf->global->RECEPTION_ADDON_NUMBER.
".php";
181 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
184 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
186 foreach ($dirmodels as $reldir) {
190 $mybool |= @include_once $dir.$file;
198 $obj =
new $classname();
201 $numref = $obj->getNextValue($soc, $this);
210 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
222 public function create($user, $notrigger = 0)
224 global $conf, $hookmanager;
228 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
232 $this->brouillon = 1;
234 if (empty($this->fk_project)) {
235 $this->fk_project = 0;
237 if (empty($this->weight_units)) {
238 $this->weight_units = 0;
240 if (empty($this->size_units)) {
241 $this->size_units = 0;
248 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
251 $sql .=
", ref_supplier";
252 $sql .=
", date_creation";
253 $sql .=
", fk_user_author";
254 $sql .=
", date_reception";
255 $sql .=
", date_delivery";
257 $sql .=
", fk_projet";
258 $sql .=
", fk_shipping_method";
259 $sql .=
", tracking_number";
264 $sql .=
", weight_units";
265 $sql .=
", size_units";
266 $sql .=
", note_private";
267 $sql .=
", note_public";
268 $sql .=
", model_pdf";
269 $sql .=
", fk_incoterms, location_incoterms";
270 $sql .=
") VALUES (";
272 $sql .=
", ".((int) $conf->entity);
273 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
274 $sql .=
", '".$this->db->idate($now).
"'";
275 $sql .=
", ".((int) $user->id);
276 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
277 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
278 $sql .=
", ".((int) $this->socid);
279 $sql .=
", ".((int) $this->fk_project);
280 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
281 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
282 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((double) $this->weight));
283 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((double) $this->trueDepth));
284 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((double) $this->trueWidth));
285 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((double) $this->trueHeight));
286 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((double) $this->weight_units));
287 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((double) $this->size_units));
288 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
289 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
290 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
291 $sql .=
", ".(int) $this->fk_incoterms;
292 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
295 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
300 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"reception");
302 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
303 $sql .=
" SET ref = '(PROV".$this->id.
")'";
304 $sql .=
" WHERE rowid = ".((int) $this->
id);
306 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
307 if ($this->
db->query($sql)) {
309 $num = count($this->lines);
310 for ($i = 0; $i < $num; $i++) {
311 $this->lines[$i]->fk_reception = $this->id;
313 if (!$this->lines[$i]->
create($user) > 0) {
318 if (!$error && $this->
id && $this->origin_id) {
333 if (!$error && !$notrigger) {
335 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
346 foreach ($this->errors as $errmsg) {
347 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
348 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
350 $this->
db->rollback();
355 $this->error = $this->
db->lasterror().
" - sql=$sql";
356 $this->
db->rollback();
361 $this->error = $this->
db->error().
" - sql=$sql";
362 $this->
db->rollback();
377 public function fetch($id, $ref =
'', $ref_ext =
'')
380 if (empty($id) && empty($ref) && empty($ref_ext)) {
384 $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";
385 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
386 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
387 $sql .=
", e.fk_shipping_method, e.tracking_number";
388 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
389 $sql .=
", e.note_private, e.note_public";
390 $sql .=
', e.fk_incoterms, e.location_incoterms';
391 $sql .=
', i.libelle as label_incoterms';
392 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
393 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->
db->escape($this->element).
"'";
394 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
395 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
397 $sql .=
" AND e.rowid=".((int) $id);
400 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
403 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
406 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
407 $result = $this->
db->query($sql);
409 if ($this->
db->num_rows($result)) {
410 $obj = $this->
db->fetch_object($result);
412 $this->
id = $obj->rowid;
413 $this->entity = $obj->entity;
414 $this->
ref = $obj->ref;
415 $this->socid = $obj->socid;
416 $this->ref_supplier = $obj->ref_supplier;
417 $this->ref_ext = $obj->ref_ext;
418 $this->statut = $obj->fk_statut;
419 $this->user_author_id = $obj->fk_user_author;
420 $this->date_creation = $this->
db->jdate($obj->date_creation);
421 $this->date = $this->
db->jdate($obj->date_reception);
422 $this->date_reception = $this->
db->jdate($obj->date_reception);
423 $this->date_reception = $this->
db->jdate($obj->date_reception);
424 $this->date_delivery = $this->
db->jdate($obj->date_delivery);
425 $this->model_pdf = $obj->model_pdf;
426 $this->modelpdf = $obj->model_pdf;
427 $this->shipping_method_id = $obj->fk_shipping_method;
428 $this->tracking_number = $obj->tracking_number;
429 $this->origin = ($obj->origin ? $obj->origin :
'commande');
430 $this->origin_id = $obj->origin_id;
431 $this->billed = ($obj->fk_statut == 2 ? 1 : 0);
433 $this->trueWeight = $obj->weight;
434 $this->weight_units = $obj->weight_units;
436 $this->trueWidth = $obj->width;
437 $this->width_units = $obj->size_units;
438 $this->trueHeight = $obj->height;
439 $this->height_units = $obj->size_units;
440 $this->trueDepth = $obj->size;
441 $this->depth_units = $obj->size_units;
443 $this->note_public = $obj->note_public;
444 $this->note_private = $obj->note_private;
447 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
448 $this->size_units = $obj->size_units;
451 $this->fk_incoterms = $obj->fk_incoterms;
452 $this->location_incoterms = $obj->location_incoterms;
453 $this->label_incoterms = $obj->label_incoterms;
455 $this->
db->free($result);
457 if ($this->statut == 0) {
458 $this->brouillon = 1;
475 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
477 $extrafields->fetch_name_optionals_label($this->table_element,
true);
490 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
491 $this->error =
'Delivery with id '.$id.
' not found';
495 $this->error = $this->
db->error();
507 public function valid($user, $notrigger = 0)
509 global $conf, $langs;
511 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
517 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
521 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
522 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
523 $this->error =
'Permission denied';
524 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
534 $soc->fetch($this->socid);
538 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
541 $numref = $this->ref;
549 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
550 $sql .=
" ref='".$this->db->escape($numref).
"'";
551 $sql .=
", fk_statut = 1";
552 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
553 $sql .=
", fk_user_valid = ".$user->id;
554 $sql .=
" WHERE rowid = ".((int) $this->
id);
555 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
558 $this->error = $this->
db->lasterror();
563 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
564 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
566 $langs->load(
"agenda");
570 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
571 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
572 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
573 $sql .=
" ed.cost_price";
574 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
575 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
576 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
577 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
579 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
583 for ($i = 0; $i < $cpt; $i++) {
584 $obj = $this->
db->fetch_object(
$resql);
588 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
591 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
595 $mouvS->origin = &$this;
596 $mouvS->setOrigin($this->element, $this->
id);
598 if (empty($obj->batch)) {
603 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
605 if (intval($result) < 0) {
607 $this->errors[] = $mouvS->error;
608 $this->errors = array_merge($this->errors, $mouvS->errors);
617 $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);
619 if (intval($result) < 0) {
621 $this->errors[] = $mouvS->error;
622 $this->errors = array_merge($this->errors, $mouvS->errors);
628 $this->
db->rollback();
629 $this->error = $this->
db->error();
641 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
644 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
647 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
654 if (!$error && !$notrigger) {
656 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
664 $this->oldref = $this->ref;
667 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
669 $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).
"'";
670 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->
db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
673 $error++; $this->error = $this->
db->lasterror();
679 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
680 $dirdest = $conf->reception->dir_output.
'/'.$newref;
681 if (!$error && file_exists($dirsource)) {
682 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
684 if (@rename($dirsource, $dirdest)) {
687 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
688 foreach ($listoffiles as $fileentry) {
689 $dirsource = $fileentry[
'name'];
690 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
691 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
692 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
693 @rename($dirsource, $dirdest);
702 $this->
ref = $numref;
710 foreach ($this->errors as $errmsg) {
711 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
712 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
714 $this->
db->rollback();
728 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
729 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
733 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
734 if (empty($this->commandeFournisseur)) {
736 if (empty($this->commandeFournisseur->lines)) {
737 $res = $this->commandeFournisseur->fetch_lines();
738 if ($res < 0)
return $res;
742 $qty_received = array();
743 $qty_wished = array();
746 $filter = array(
't.fk_commande'=>$this->origin_id);
747 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
748 $filter[
't.status'] = 1;
751 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
753 $this->error = $supplierorderdispatch->error;
754 $this->errors = $supplierorderdispatch->errors;
758 foreach ($supplierorderdispatch->lines as $dispatch_line) {
759 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
763 foreach ($this->commandeFournisseur->lines as $origin_line) {
765 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $origin_line->product_type > 0) {
769 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
773 $diff_array = array_diff_assoc($qty_received, $qty_wished);
774 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
775 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
777 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
779 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
783 if (count($diff_array) > 0) {
786 foreach ($diff_array as $key => $value) {
788 if ($qty_received[$key] >= $qty_wished[$key]) {
794 if ($close == count($diff_array)) {
821 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
823 global $conf, $langs, $user;
825 $num = count($this->lines);
828 $line->fk_entrepot = $entrepot_id;
829 $line->fk_commandefourndet = $id;
833 $result = $supplierorderline->fetch($id);
835 $this->error = $supplierorderline->error;
836 $this->errors = $supplierorderline->errors;
841 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
842 $fk_product = $supplierorderline->fk_product;
844 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
845 $langs->load(
"errors");
846 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
853 $product->fetch($fk_product);
855 $langs->load(
"errors");
856 if (!empty($product->status_batch) && empty($batch)) {
857 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
859 } elseif (empty($product->status_batch) && !empty($batch)) {
860 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
867 $line->array_options = $supplierorderline->array_options;
868 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
869 foreach ($array_options as $key => $value) {
870 $line->array_options[$key] = $value;
874 $line->fk_product = $fk_product;
875 $line->fk_commande = $supplierorderline->fk_commande;
876 $line->fk_user = $user->id;
877 $line->comment = $comment;
878 $line->batch = $batch;
879 $line->eatby = $eatby;
880 $line->sellby = $sellby;
882 $line->cost_price = $cost_price;
883 $line->fk_reception = $this->id;
885 $this->lines[$num] = $line;
898 public function update($user =
null, $notrigger = 0)
905 if (isset($this->
ref)) {
906 $this->
ref = trim($this->
ref);
908 if (isset($this->entity)) {
909 $this->entity = trim($this->entity);
911 if (isset($this->ref_supplier)) {
912 $this->ref_supplier = trim($this->ref_supplier);
914 if (isset($this->socid)) {
915 $this->socid = trim($this->socid);
917 if (isset($this->fk_user_author)) {
918 $this->fk_user_author = trim($this->fk_user_author);
920 if (isset($this->fk_user_valid)) {
921 $this->fk_user_valid = trim($this->fk_user_valid);
923 if (isset($this->shipping_method_id)) {
924 $this->shipping_method_id = trim($this->shipping_method_id);
926 if (isset($this->tracking_number)) {
927 $this->tracking_number = trim($this->tracking_number);
929 if (isset($this->statut)) {
930 $this->statut = (int) $this->statut;
932 if (isset($this->trueDepth)) {
933 $this->trueDepth = trim($this->trueDepth);
935 if (isset($this->trueWidth)) {
936 $this->trueWidth = trim($this->trueWidth);
938 if (isset($this->trueHeight)) {
939 $this->trueHeight = trim($this->trueHeight);
941 if (isset($this->size_units)) {
942 $this->size_units = trim($this->size_units);
944 if (isset($this->weight_units)) {
945 $this->weight_units = trim($this->weight_units);
947 if (isset($this->trueWeight)) {
948 $this->weight = trim($this->trueWeight);
950 if (isset($this->note_private)) {
951 $this->note_private = trim($this->note_private);
953 if (isset($this->note_public)) {
954 $this->note_public = trim($this->note_public);
956 if (isset($this->model_pdf)) {
957 $this->model_pdf = trim($this->model_pdf);
965 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
967 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
968 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
969 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
970 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
971 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
972 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
973 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
974 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
975 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
976 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
977 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
978 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
979 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
980 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
981 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
982 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
983 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
984 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
985 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
986 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
987 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
988 $sql .=
" entity = ".((int) $conf->entity);
989 $sql .=
" WHERE rowid=".((int) $this->
id);
993 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
996 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1002 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1012 foreach ($this->errors as $errmsg) {
1013 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1014 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1016 $this->
db->rollback();
1019 $this->
db->commit();
1032 global $conf, $langs, $user;
1033 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1042 if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0) {
1043 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1045 $langs->load(
"agenda");
1048 $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";
1049 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1050 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1051 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1052 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1054 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1057 $cpt = $this->
db->num_rows(
$resql);
1058 for ($i = 0; $i < $cpt; $i++) {
1059 dol_syslog(get_class($this).
"::delete movement index ".$i);
1060 $obj = $this->
db->fetch_object(
$resql);
1064 $mouvS->origin =
null;
1066 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1069 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1074 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1075 $ef = $main.
"_extrafields";
1077 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1079 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1080 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1082 if ($this->
db->query($sqlef) && $this->
db->query($sql)) {
1090 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1091 $sql .=
" WHERE rowid = ".((int) $this->
id);
1093 if ($this->
db->query($sql)) {
1095 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1101 if (!empty($this->origin) && $this->origin_id > 0) {
1103 $origin = $this->origin;
1104 if ($this->$origin->statut == 4) {
1106 $this->$origin->loadReceptions();
1108 if (count($this->$origin->receptions) <= 0) {
1109 $this->$origin->setStatut(3);
1115 $this->
db->commit();
1119 if (!empty($conf->reception->dir_output)) {
1120 $dir = $conf->reception->dir_output.
'/'.$ref;
1121 $file = $dir.
'/'.$ref.
'.pdf';
1122 if (file_exists($file)) {
1127 if (file_exists($dir)) {
1129 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1137 $this->
db->rollback();
1141 $this->error = $this->
db->lasterror().
" - sql=$sql";
1142 $this->
db->rollback();
1146 $this->error = $this->
db->lasterror().
" - sql=$sql";
1147 $this->
db->rollback();
1151 $this->error = $this->
db->lasterror().
" - sql=$sql";
1152 $this->
db->rollback();
1156 $this->
db->rollback();
1170 $this->lines = array();
1172 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1174 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1178 while ($obj = $this->
db->fetch_object(
$resql)) {
1181 $line->fetch($obj->rowid);
1184 $line->fetch_product();
1186 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1187 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1188 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1189 $sql_commfourndet .=
' ORDER BY rang';
1191 $resql_commfourndet = $this->
db->query($sql_commfourndet);
1192 if (!empty($resql_commfourndet)) {
1193 $obj = $this->
db->fetch_object($resql_commfourndet);
1194 $line->qty_asked = $obj->qty;
1195 $line->description = $obj->description;
1196 $line->desc = $obj->description;
1197 $line->tva_tx = $obj->tva_tx;
1198 $line->vat_src_code = $obj->vat_src_code;
1199 $line->subprice = $obj->subprice;
1200 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1201 $line->remise_percent = $obj->remise_percent;
1202 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1203 $line->ref_supplier = $obj->ref;
1204 $line->total_ht = $obj->total_ht;
1205 $line->total_ttc = $obj->total_ttc;
1206 $line->total_tva = $obj->total_tva;
1208 $line->qty_asked = 0;
1209 $line->description =
'';
1211 $line->label = $obj->label;
1214 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1215 $tva = $pu_ht * $line->tva_tx / 100;
1216 $this->total_ht += $pu_ht;
1217 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1219 $this->total_ttc += $pu_ht + $tva;
1221 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1222 $detail_batch =
new stdClass();
1223 $detail_batch->eatby = $line->eatby;
1224 $detail_batch->sellby = $line->sellby;
1225 $detail_batch->batch = $line->batch;
1226 $detail_batch->qty = $line->qty;
1227 $line->detail_batch[] = $detail_batch;
1230 $this->lines[] = $line;
1249 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1251 global $conf, $langs, $hookmanager;
1253 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1254 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1255 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1257 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1264 if (empty($notooltip)) {
1265 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1266 $label = $langs->trans(
"Reception");
1267 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1269 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1270 $linkclose .=
' class="classfortooltip"';
1273 $linkstart =
'<a href="'.$url.
'"';
1274 $linkstart .= $linkclose.
'>';
1278 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
1280 if ($withpicto && $withpicto != 2) {
1283 $result .= $linkstart.$this->ref.$linkend;
1286 $hookmanager->initHooks(array($this->element .
'dao'));
1287 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1288 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1290 $result = $hookmanager->resPrint;
1292 $result .= $hookmanager->resPrint;
1305 return $this->
LibStatut($this->statut, $mode);
1321 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
1322 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
1324 $statusType =
'status'.$status;
1325 if ($status == self::STATUS_VALIDATED) {
1326 $statusType =
'status4';
1328 if ($status == self::STATUS_CLOSED) {
1329 $statusType =
'status6';
1332 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1346 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1347 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1350 dol_syslog(get_class($this).
"::initAsSpecimen");
1355 $sql =
"SELECT rowid";
1356 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1357 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1358 $sql .= $this->
db->plimit(100);
1362 $num_prods = $this->
db->num_rows(
$resql);
1364 while ($i < $num_prods) {
1366 $row = $this->
db->fetch_row(
$resql);
1367 $prodids[$i] = $row[0];
1372 $order->initAsSpecimen();
1376 $this->
ref =
'SPECIMEN';
1377 $this->specimen = 1;
1379 $this->livraison_id = 0;
1381 $this->date_creation = $now;
1382 $this->date_valid = $now;
1383 $this->date_delivery = $now;
1384 $this->date_reception = $now + 24 * 3600;
1386 $this->entrepot_id = 0;
1389 $this->commande_id = 0;
1390 $this->commande = $order;
1392 $this->origin_id = 1;
1393 $this->origin =
'commande';
1395 $this->note_private =
'Private note';
1396 $this->note_public =
'Public note';
1400 while ($xnbp < $nbp) {
1402 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1403 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1406 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1408 $this->lines[] = $line;
1423 if ($user->rights->reception->creer) {
1424 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1425 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1426 $sql .=
" WHERE rowid = ".((int) $this->
id);
1428 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1431 $this->date_delivery = $delivery_date;
1434 $this->error = $this->
db->error();
1452 $this->meths = array();
1454 $sql =
"SELECT em.rowid, em.code, em.libelle";
1455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1456 $sql .=
" WHERE em.active = 1";
1457 $sql .=
" ORDER BY em.libelle ASC";
1461 while ($obj = $this->
db->fetch_object(
$resql)) {
1462 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1463 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1480 $this->listmeths = array();
1483 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1484 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1486 $sql .=
" WHERE em.rowid = ".((int) $id);
1491 while ($obj = $this->
db->fetch_object(
$resql)) {
1492 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1493 $this->listmeths[$i][
'code'] = $obj->code;
1494 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1495 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1496 $this->listmeths[$i][
'description'] = $obj->description;
1497 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1498 $this->listmeths[$i][
'active'] = $obj->active;
1512 if (!empty($this->shipping_method_id)) {
1513 $sql =
"SELECT em.code, em.tracking";
1514 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1515 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1519 if ($obj = $this->
db->fetch_object(
$resql)) {
1520 $tracking = $obj->tracking;
1525 if (!empty($tracking) && !empty($value)) {
1526 $url = str_replace(
'{TRACKID}', $value, $tracking);
1527 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1529 $this->tracking_url = $value;
1540 global $conf, $langs, $user;
1546 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1547 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1552 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1554 $order->fetch($this->origin_id);
1556 $order->loadReceptions(self::STATUS_CLOSED);
1558 $receptions_match_order = 1;
1559 foreach ($order->lines as $line) {
1560 $lineid = $line->id;
1562 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1563 $receptions_match_order = 0;
1564 $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';
1569 if ($receptions_match_order) {
1570 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');
1571 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1575 $this->statut = self::STATUS_CLOSED;
1579 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1580 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1582 $langs->load(
"agenda");
1586 $sql =
"SELECT cd.fk_product, cd.subprice,";
1587 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1588 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1589 $sql .=
" ed.cost_price";
1590 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1591 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1592 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1593 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1595 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1599 $cpt = $this->
db->num_rows(
$resql);
1600 for ($i = 0; $i < $cpt; $i++) {
1601 $obj = $this->
db->fetch_object(
$resql);
1608 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1611 $mouvS->origin = &$this;
1612 $mouvS->setOrigin($this->element, $this->
id);
1614 if (empty($obj->batch)) {
1618 $inventorycode =
'';
1619 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1621 $this->error = $mouvS->error;
1622 $this->errors = $mouvS->errors;
1629 $inventorycode =
'';
1630 $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);
1633 $this->error = $mouvS->error;
1634 $this->errors = $mouvS->errors;
1640 $this->error = $this->
db->lasterror();
1647 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1658 $this->
db->commit();
1661 $this->
db->rollback();
1680 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1681 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1689 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1695 $this->errors[] = $this->
db->lasterror;
1698 if (empty($error)) {
1699 $this->
db->commit();
1702 $this->
db->rollback();
1714 global $conf, $langs, $user;
1720 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1721 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1729 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1730 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1731 $numref = $this->ref;
1732 $langs->load(
"agenda");
1736 $sql =
"SELECT ed.fk_product, cd.subprice,";
1737 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1738 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1739 $sql .=
" ed.cost_price";
1740 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1741 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1742 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1743 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1745 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1748 $cpt = $this->
db->num_rows(
$resql);
1749 for ($i = 0; $i < $cpt; $i++) {
1750 $obj = $this->
db->fetch_object(
$resql);
1758 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1762 $mouvS->origin = &$this;
1763 $mouvS->setOrigin($this->element, $this->
id);
1765 if (empty($obj->batch)) {
1769 $inventorycode =
'';
1770 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1773 $this->error = $mouvS->error;
1774 $this->errors = $mouvS->errors;
1781 $inventorycode =
'';
1782 $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);
1784 $this->error = $mouvS->error;
1785 $this->errors = $mouvS->errors;
1791 $this->error = $this->
db->lasterror();
1798 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1804 if (!$error && $this->origin ==
'order_supplier') {
1806 $commande->fetch($this->origin_id);
1807 $result = $commande->setStatus($user, 4);
1810 $this->error = $commande->error;
1811 $this->errors = $commande->errors;
1816 $this->errors[] = $this->
db->lasterror();
1820 $this->
db->commit();
1823 $this->
db->rollback();
1837 global $conf, $langs;
1842 if ($this->statut <= self::STATUS_DRAFT) {
1846 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1847 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1848 $this->error =
'Permission denied';
1854 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1855 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1856 $sql .=
" WHERE rowid = ".((int) $this->
id);
1859 if ($this->
db->query($sql)) {
1861 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1862 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1864 $langs->load(
"agenda");
1868 $sql =
"SELECT cd.fk_product, cd.subprice,";
1869 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1870 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1871 $sql .=
" ed.cost_price";
1872 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1873 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1874 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1875 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1877 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1880 $cpt = $this->
db->num_rows(
$resql);
1881 for ($i = 0; $i < $cpt; $i++) {
1882 $obj = $this->
db->fetch_object(
$resql);
1890 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1894 $mouvS->origin = &$this;
1895 $mouvS->setOrigin($this->element, $this->
id);
1897 if (empty($obj->batch)) {
1901 $inventorycode =
'';
1902 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1904 $this->error = $mouvS->error;
1905 $this->errors = $mouvS->errors;
1913 $inventorycode =
'';
1914 $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);
1916 $this->error = $mouvS->error;
1917 $this->errors = $mouvS->errors;
1923 $this->error = $this->
db->lasterror();
1930 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1935 if ($this->origin ==
'order_supplier') {
1936 if (!empty($this->origin) && $this->origin_id > 0) {
1938 $origin = $this->origin;
1939 if ($this->$origin->statut == 4) {
1941 $this->$origin->fetchObjectLinked();
1943 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1944 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1945 if ($rcption->statut > 0) {
1952 $this->$origin->setStatut(3);
1960 $this->statut = self::STATUS_DRAFT;
1961 $this->
db->commit();
1964 $this->
db->rollback();
1968 $this->error = $this->
db->error();
1969 $this->
db->rollback();
1984 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1986 global $conf, $langs;
1988 $langs->load(
"receptions");
1991 $modele =
'squille';
1993 if ($this->model_pdf) {
1994 $modele = $this->model_pdf;
1995 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
1996 $modele = $conf->global->RECEPTION_ADDON_PDF;
2000 $modelpath =
"core/modules/reception/doc/";
2004 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2017 $tables = array(
'reception');
2033 'commande_fournisseur_dispatch'
Class to manage table commandefournisseurdispatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used when WORKFLOW_EXPEDITION_CLASSIFY_CLOSED_INVOICE is on)
fetch_delivery_methods()
Fetch deliveries method and return an array.
getLibStatut($mode=0)
Return status label.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
getUrlTrackingStatus($value='')
Forge an set tracking url.
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.
LibStatut($status, $mode)
Return label of a status.
addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='', $cost_price=0)
Add an reception line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
list_delivery_methods($id='')
Fetch all deliveries method and return an array.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
__construct($db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
create($user, $notrigger=0)
Create reception en base.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.