35 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
38 if (!empty($conf->propal->enabled)) {
39 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
41 if (!empty($conf->commande->enabled)) {
42 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
56 public $element =
"reception";
61 public $fk_element =
"fk_reception";
62 public $table_element =
"reception";
63 public $table_element_line =
"commande_fournisseur_dispatch";
64 public $ismultientitymanaged = 1;
69 public $picto =
'dollyrevert';
82 public $tracking_number;
98 public $date_delivery;
104 public $date_reception;
109 public $date_creation;
119 public $lines = array();
122 const STATUS_DRAFT = 0;
123 const STATUS_VALIDATED = 1;
124 const STATUS_CLOSED = 2;
138 $this->statuts = array();
139 $this->statuts[-1] =
'StatusReceptionCanceled';
140 $this->statuts[0] =
'StatusReceptionDraft';
142 $this->statuts[1] =
'StatusReceptionValidated';
144 $this->statuts[1] =
'StatusReceptionValidatedReceived';
147 $this->statuts[1] =
'StatusReceptionValidatedToReceive';
149 $this->statuts[2] =
'StatusReceptionProcessed';
152 $this->statutshorts = array();
153 $this->statutshorts[-1] =
'StatusReceptionCanceledShort';
154 $this->statutshorts[0] =
'StatusReceptionDraftShort';
155 $this->statutshorts[1] =
'StatusReceptionValidatedShort';
156 $this->statutshorts[2] =
'StatusReceptionProcessedShort';
167 global $langs, $conf;
168 $langs->load(
"receptions");
170 if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) {
173 $file = $conf->global->RECEPTION_ADDON_NUMBER.
".php";
174 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
177 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
179 foreach ($dirmodels as $reldir) {
183 $mybool |= @include_once $dir.$file;
191 $obj =
new $classname();
194 $numref = $obj->getNextValue($soc, $this);
203 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
215 public function create($user, $notrigger = 0)
217 global $conf, $hookmanager;
221 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
225 $this->brouillon = 1;
227 if (empty($this->fk_project)) {
228 $this->fk_project = 0;
230 if (empty($this->weight_units)) {
231 $this->weight_units = 0;
233 if (empty($this->size_units)) {
234 $this->size_units = 0;
241 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
244 $sql .=
", ref_supplier";
245 $sql .=
", date_creation";
246 $sql .=
", fk_user_author";
247 $sql .=
", date_reception";
248 $sql .=
", date_delivery";
250 $sql .=
", fk_projet";
251 $sql .=
", fk_shipping_method";
252 $sql .=
", tracking_number";
257 $sql .=
", weight_units";
258 $sql .=
", size_units";
259 $sql .=
", note_private";
260 $sql .=
", note_public";
261 $sql .=
", model_pdf";
262 $sql .=
", fk_incoterms, location_incoterms";
263 $sql .=
") VALUES (";
265 $sql .=
", ".((int) $conf->entity);
266 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
267 $sql .=
", '".$this->db->idate($now).
"'";
268 $sql .=
", ".((int) $user->id);
269 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
270 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
271 $sql .=
", ".((int) $this->socid);
272 $sql .=
", ".((int) $this->fk_project);
273 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
274 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
275 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((double) $this->weight));
276 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((double) $this->trueDepth));
277 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((double) $this->trueWidth));
278 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((double) $this->trueHeight));
279 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((double) $this->weight_units));
280 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((double) $this->size_units));
281 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
282 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
283 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
284 $sql .=
", ".(int) $this->fk_incoterms;
285 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
288 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
293 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"reception");
295 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
296 $sql .=
" SET ref = '(PROV".$this->id.
")'";
297 $sql .=
" WHERE rowid = ".((int) $this->
id);
299 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
300 if ($this->
db->query($sql)) {
302 $num = count($this->lines);
303 for ($i = 0; $i < $num; $i++) {
304 $this->lines[$i]->fk_reception = $this->id;
306 if (!$this->lines[$i]->
create($user) > 0) {
311 if (!$error && $this->
id && $this->origin_id) {
326 if (!$error && !$notrigger) {
328 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
339 foreach ($this->errors as $errmsg) {
340 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
341 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
343 $this->
db->rollback();
348 $this->error = $this->
db->lasterror().
" - sql=$sql";
349 $this->
db->rollback();
354 $this->error = $this->
db->error().
" - sql=$sql";
355 $this->
db->rollback();
371 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
376 if (empty($id) && empty($ref) && empty($ref_ext)) {
380 $sql =
"SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.fk_user_author, e.fk_statut";
381 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
382 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
383 $sql .=
", e.fk_shipping_method, e.tracking_number";
384 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
385 $sql .=
", e.note_private, e.note_public";
386 $sql .=
', e.fk_incoterms, e.location_incoterms';
387 $sql .=
', i.libelle as label_incoterms';
388 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
389 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->
db->escape($this->element).
"'";
390 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
391 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
393 $sql .=
" AND e.rowid=".((int) $id);
396 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
399 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
402 $sql .=
" AND e.ref_int='".$this->db->escape($notused).
"'";
405 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
406 $result = $this->
db->query($sql);
408 if ($this->
db->num_rows($result)) {
409 $obj = $this->
db->fetch_object($result);
411 $this->
id = $obj->rowid;
412 $this->
ref = $obj->ref;
413 $this->socid = $obj->socid;
414 $this->ref_supplier = $obj->ref_supplier;
415 $this->ref_ext = $obj->ref_ext;
416 $this->statut = $obj->fk_statut;
417 $this->user_author_id = $obj->fk_user_author;
418 $this->date_creation = $this->
db->jdate($obj->date_creation);
419 $this->date = $this->
db->jdate($obj->date_reception);
420 $this->date_reception = $this->
db->jdate($obj->date_reception);
421 $this->date_reception = $this->
db->jdate($obj->date_reception);
422 $this->date_delivery = $this->
db->jdate($obj->date_delivery);
423 $this->model_pdf = $obj->model_pdf;
424 $this->modelpdf = $obj->model_pdf;
425 $this->shipping_method_id = $obj->fk_shipping_method;
426 $this->tracking_number = $obj->tracking_number;
427 $this->origin = ($obj->origin ? $obj->origin :
'commande');
428 $this->origin_id = $obj->origin_id;
429 $this->billed = ($obj->fk_statut == 2 ? 1 : 0);
431 $this->trueWeight = $obj->weight;
432 $this->weight_units = $obj->weight_units;
434 $this->trueWidth = $obj->width;
435 $this->width_units = $obj->size_units;
436 $this->trueHeight = $obj->height;
437 $this->height_units = $obj->size_units;
438 $this->trueDepth = $obj->size;
439 $this->depth_units = $obj->size_units;
441 $this->note_public = $obj->note_public;
442 $this->note_private = $obj->note_private;
445 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
446 $this->size_units = $obj->size_units;
449 $this->fk_incoterms = $obj->fk_incoterms;
450 $this->location_incoterms = $obj->location_incoterms;
451 $this->label_incoterms = $obj->label_incoterms;
453 $this->
db->free($result);
455 if ($this->statut == 0) {
456 $this->brouillon = 1;
473 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
475 $extrafields->fetch_name_optionals_label($this->table_element,
true);
488 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
489 $this->error =
'Delivery with id '.$id.
' not found';
493 $this->error = $this->
db->error();
505 public function valid($user, $notrigger = 0)
507 global $conf, $langs;
509 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
515 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
519 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
520 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
521 $this->error =
'Permission denied';
522 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
532 $soc->fetch($this->socid);
536 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
539 $numref = $this->ref;
547 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
548 $sql .=
" ref='".$this->db->escape($numref).
"'";
549 $sql .=
", fk_statut = 1";
550 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
551 $sql .=
", fk_user_valid = ".$user->id;
552 $sql .=
" WHERE rowid = ".((int) $this->
id);
553 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
556 $this->error = $this->
db->lasterror();
561 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
562 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
564 $langs->load(
"agenda");
568 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
569 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
570 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
571 $sql .=
" ed.cost_price";
572 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
573 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
574 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
575 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
577 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
581 for ($i = 0; $i < $cpt; $i++) {
582 $obj = $this->
db->fetch_object(
$resql);
589 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
593 $mouvS->origin = &$this;
594 $mouvS->setOrigin($this->element, $this->
id);
596 if (empty($obj->batch)) {
601 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
603 if (intval($result) < 0) {
605 $this->errors[] = $mouvS->error;
606 $this->errors = array_merge($this->errors, $mouvS->errors);
615 $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);
617 if (intval($result) < 0) {
619 $this->errors[] = $mouvS->error;
620 $this->errors = array_merge($this->errors, $mouvS->errors);
626 $this->
db->rollback();
627 $this->error = $this->
db->error();
639 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
642 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
645 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
652 if (!$error && !$notrigger) {
654 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
662 $this->oldref = $this->ref;
665 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
667 $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).
"'";
668 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->
db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
671 $error++; $this->error = $this->
db->lasterror();
677 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
678 $dirdest = $conf->reception->dir_output.
'/'.$newref;
679 if (!$error && file_exists($dirsource)) {
680 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
682 if (@rename($dirsource, $dirdest)) {
685 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
686 foreach ($listoffiles as $fileentry) {
687 $dirsource = $fileentry[
'name'];
688 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
689 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
690 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
691 @rename($dirsource, $dirdest);
700 $this->
ref = $numref;
708 foreach ($this->errors as $errmsg) {
709 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
710 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
712 $this->
db->rollback();
726 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
727 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
731 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
732 if (empty($this->commandeFournisseur)) {
734 if (empty($this->commandeFournisseur->lines)) {
735 $res = $this->commandeFournisseur->fetch_lines();
736 if ($res < 0)
return $res;
740 $qty_received = array();
741 $qty_wished = array();
744 $filter = array(
't.fk_commande'=>$this->origin_id);
745 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
746 $filter[
't.status'] = 1;
749 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
751 $this->error = $supplierorderdispatch->error;
752 $this->errors = $supplierorderdispatch->errors;
756 foreach ($supplierorderdispatch->lines as $dispatch_line) {
757 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
761 foreach ($this->commandeFournisseur->lines as $origin_line) {
763 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $origin_line->product_type > 0) {
767 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
771 $diff_array = array_diff_assoc($qty_received, $qty_wished);
772 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
773 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
775 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
777 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
781 if (count($diff_array) > 0) {
784 foreach ($diff_array as $key => $value) {
786 if ($qty_received[$key] >= $qty_wished[$key]) {
792 if ($close == count($diff_array)) {
819 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
821 global $conf, $langs, $user;
823 $num = count($this->lines);
826 $line->fk_entrepot = $entrepot_id;
827 $line->fk_commandefourndet = $id;
831 $result = $supplierorderline->fetch($id);
833 $this->error = $supplierorderline->error;
834 $this->errors = $supplierorderline->errors;
839 if (!empty($conf->stock->enabled) && !empty($supplierorderline->fk_product)) {
840 $fk_product = $supplierorderline->fk_product;
842 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
843 $langs->load(
"errors");
844 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
851 $product->fetch($fk_product);
852 if (!empty($conf->productbatch->enabled)) {
853 $langs->load(
"errors");
854 if (!empty($product->status_batch) && empty($batch)) {
855 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
857 } elseif (empty($product->status_batch) && !empty($batch)) {
858 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
865 $line->array_options = $supplierorderline->array_options;
866 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
867 foreach ($array_options as $key => $value) {
868 $line->array_options[$key] = $value;
872 $line->fk_product = $fk_product;
873 $line->fk_commande = $supplierorderline->fk_commande;
874 $line->fk_user = $user->id;
875 $line->comment = $comment;
876 $line->batch = $batch;
877 $line->eatby = $eatby;
878 $line->sellby = $sellby;
880 $line->cost_price = $cost_price;
881 $line->fk_reception = $this->id;
883 $this->lines[$num] = $line;
896 public function update($user = null, $notrigger = 0)
903 if (isset($this->
ref)) {
904 $this->
ref = trim($this->
ref);
906 if (isset($this->entity)) {
907 $this->entity = trim($this->entity);
909 if (isset($this->ref_supplier)) {
910 $this->ref_supplier = trim($this->ref_supplier);
912 if (isset($this->socid)) {
913 $this->socid = trim($this->socid);
915 if (isset($this->fk_user_author)) {
916 $this->fk_user_author = trim($this->fk_user_author);
918 if (isset($this->fk_user_valid)) {
919 $this->fk_user_valid = trim($this->fk_user_valid);
921 if (isset($this->shipping_method_id)) {
922 $this->shipping_method_id = trim($this->shipping_method_id);
924 if (isset($this->tracking_number)) {
925 $this->tracking_number = trim($this->tracking_number);
927 if (isset($this->statut)) {
928 $this->statut = (int) $this->statut;
930 if (isset($this->trueDepth)) {
931 $this->trueDepth = trim($this->trueDepth);
933 if (isset($this->trueWidth)) {
934 $this->trueWidth = trim($this->trueWidth);
936 if (isset($this->trueHeight)) {
937 $this->trueHeight = trim($this->trueHeight);
939 if (isset($this->size_units)) {
940 $this->size_units = trim($this->size_units);
942 if (isset($this->weight_units)) {
943 $this->weight_units = trim($this->weight_units);
945 if (isset($this->trueWeight)) {
946 $this->weight = trim($this->trueWeight);
948 if (isset($this->note_private)) {
949 $this->note_private = trim($this->note_private);
951 if (isset($this->note_public)) {
952 $this->note_public = trim($this->note_public);
954 if (isset($this->model_pdf)) {
955 $this->model_pdf = trim($this->model_pdf);
963 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
965 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
966 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
967 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
968 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
969 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
970 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
971 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
972 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
973 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
974 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
975 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
976 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
977 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
978 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
979 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
980 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
981 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
982 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
983 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
984 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
985 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
986 $sql .=
" entity = ".((int) $conf->entity);
987 $sql .=
" WHERE rowid=".((int) $this->
id);
991 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
994 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1000 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1010 foreach ($this->errors as $errmsg) {
1011 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1012 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1014 $this->
db->rollback();
1017 $this->
db->commit();
1030 global $conf, $langs, $user;
1031 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1040 if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0) {
1041 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1043 $langs->load(
"agenda");
1046 $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";
1047 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1048 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1049 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1050 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1052 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1055 $cpt = $this->
db->num_rows(
$resql);
1056 for ($i = 0; $i < $cpt; $i++) {
1057 dol_syslog(get_class($this).
"::delete movement index ".$i);
1058 $obj = $this->
db->fetch_object(
$resql);
1062 $mouvS->origin = null;
1064 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1067 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1072 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1073 $ef = $main.
"_extrafields";
1075 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1077 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1078 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1080 if ($this->
db->query($sqlef) && $this->
db->query($sql)) {
1088 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1089 $sql .=
" WHERE rowid = ".((int) $this->
id);
1091 if ($this->
db->query($sql)) {
1093 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1099 if (!empty($this->origin) && $this->origin_id > 0) {
1101 $origin = $this->origin;
1102 if ($this->$origin->statut == 4) {
1104 $this->$origin->loadReceptions();
1106 if (count($this->$origin->receptions) <= 0) {
1107 $this->$origin->setStatut(3);
1113 $this->
db->commit();
1117 if (!empty($conf->reception->dir_output)) {
1118 $dir = $conf->reception->dir_output.
'/'.$ref;
1119 $file = $dir.
'/'.$ref.
'.pdf';
1120 if (file_exists($file)) {
1125 if (file_exists($dir)) {
1127 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1135 $this->
db->rollback();
1139 $this->error = $this->
db->lasterror().
" - sql=$sql";
1140 $this->
db->rollback();
1144 $this->error = $this->
db->lasterror().
" - sql=$sql";
1145 $this->
db->rollback();
1149 $this->error = $this->
db->lasterror().
" - sql=$sql";
1150 $this->
db->rollback();
1154 $this->
db->rollback();
1168 $this->lines = array();
1170 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1172 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1176 while ($obj = $this->
db->fetch_object(
$resql)) {
1179 $line->fetch($obj->rowid);
1182 $line->fetch_product();
1184 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent';
1185 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1186 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1187 $sql_commfourndet .=
' ORDER BY rang';
1189 $resql_commfourndet = $this->
db->query($sql_commfourndet);
1190 if (!empty($resql_commfourndet)) {
1191 $obj = $this->
db->fetch_object($resql_commfourndet);
1192 $line->qty_asked = $obj->qty;
1193 $line->description = $obj->description;
1194 $line->desc = $obj->description;
1195 $line->tva_tx = $obj->tva_tx;
1196 $line->vat_src_code = $obj->vat_src_code;
1197 $line->subprice = $obj->subprice;
1198 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1199 $line->remise_percent = $obj->remise_percent;
1200 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1201 $line->ref_supplier = $obj->ref;
1203 $line->qty_asked = 0;
1204 $line->description =
'';
1206 $line->label = $obj->label;
1209 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1210 $tva = $pu_ht * $line->tva_tx / 100;
1211 $this->total_ht += $pu_ht;
1212 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1214 $this->total_ttc += $pu_ht + $tva;
1217 $this->lines[] = $line;
1236 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1238 global $conf, $langs, $hookmanager;
1240 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1241 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1242 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1244 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1251 if (empty($notooltip)) {
1252 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1253 $label = $langs->trans(
"Reception");
1254 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1256 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1257 $linkclose .=
' class="classfortooltip"';
1260 $linkstart =
'<a href="'.$url.
'"';
1261 $linkstart .= $linkclose.
'>';
1265 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
1267 if ($withpicto && $withpicto != 2) {
1270 $result .= $linkstart.$this->ref.$linkend;
1273 $hookmanager->initHooks(array($this->element .
'dao'));
1274 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1275 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1277 $result = $hookmanager->resPrint;
1279 $result .= $hookmanager->resPrint;
1292 return $this->
LibStatut($this->statut, $mode);
1308 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
1309 $labelStatusShort = $langs->transnoentitiesnoconv($this->statutshorts[$status]);
1311 $statusType =
'status'.$status;
1312 if ($status == self::STATUS_VALIDATED) {
1313 $statusType =
'status4';
1315 if ($status == self::STATUS_CLOSED) {
1316 $statusType =
'status6';
1319 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1333 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1334 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1337 dol_syslog(get_class($this).
"::initAsSpecimen");
1342 $sql =
"SELECT rowid";
1343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1344 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1345 $sql .= $this->
db->plimit(100);
1349 $num_prods = $this->
db->num_rows(
$resql);
1351 while ($i < $num_prods) {
1353 $row = $this->
db->fetch_row(
$resql);
1354 $prodids[$i] = $row[0];
1359 $order->initAsSpecimen();
1363 $this->
ref =
'SPECIMEN';
1364 $this->specimen = 1;
1366 $this->livraison_id = 0;
1368 $this->date_creation = $now;
1369 $this->date_valid = $now;
1370 $this->date_delivery = $now;
1371 $this->date_reception = $now + 24 * 3600;
1373 $this->entrepot_id = 0;
1376 $this->commande_id = 0;
1377 $this->commande = $order;
1379 $this->origin_id = 1;
1380 $this->origin =
'commande';
1382 $this->note_private =
'Private note';
1383 $this->note_public =
'Public note';
1387 while ($xnbp < $nbp) {
1389 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1390 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1393 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1395 $this->lines[] = $line;
1410 if ($user->rights->reception->creer) {
1411 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1412 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1413 $sql .=
" WHERE rowid = ".((int) $this->
id);
1415 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1418 $this->date_delivery = $delivery_date;
1421 $this->error = $this->
db->error();
1439 $this->meths = array();
1441 $sql =
"SELECT em.rowid, em.code, em.libelle";
1442 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1443 $sql .=
" WHERE em.active = 1";
1444 $sql .=
" ORDER BY em.libelle ASC";
1448 while ($obj = $this->
db->fetch_object(
$resql)) {
1449 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1450 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1467 $this->listmeths = array();
1470 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1471 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1473 $sql .=
" WHERE em.rowid = ".((int) $id);
1478 while ($obj = $this->
db->fetch_object(
$resql)) {
1479 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1480 $this->listmeths[$i][
'code'] = $obj->code;
1481 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1482 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1483 $this->listmeths[$i][
'description'] = $obj->description;
1484 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1485 $this->listmeths[$i][
'active'] = $obj->active;
1499 if (!empty($this->shipping_method_id)) {
1500 $sql =
"SELECT em.code, em.tracking";
1501 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1502 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1506 if ($obj = $this->
db->fetch_object(
$resql)) {
1507 $tracking = $obj->tracking;
1512 if (!empty($tracking) && !empty($value)) {
1513 $url = str_replace(
'{TRACKID}', $value, $tracking);
1514 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1516 $this->tracking_url = $value;
1527 global $conf, $langs, $user;
1533 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1534 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1539 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1541 $order->fetch($this->origin_id);
1543 $order->loadReceptions(self::STATUS_CLOSED);
1545 $receptions_match_order = 1;
1546 foreach ($order->lines as $line) {
1547 $lineid = $line->id;
1549 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1550 $receptions_match_order = 0;
1551 $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';
1556 if ($receptions_match_order) {
1557 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');
1558 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1562 $this->statut = self::STATUS_CLOSED;
1566 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1567 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1569 $langs->load(
"agenda");
1573 $sql =
"SELECT cd.fk_product, cd.subprice,";
1574 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1575 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1576 $sql .=
" ed.cost_price";
1577 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1578 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1579 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1580 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1582 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1586 $cpt = $this->
db->num_rows(
$resql);
1587 for ($i = 0; $i < $cpt; $i++) {
1588 $obj = $this->
db->fetch_object(
$resql);
1595 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1598 $mouvS->origin = &$this;
1599 $mouvS->setOrigin($this->element, $this->
id);
1601 if (empty($obj->batch)) {
1605 $inventorycode =
'';
1606 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1608 $this->error = $mouvS->error;
1609 $this->errors = $mouvS->errors;
1616 $inventorycode =
'';
1617 $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);
1620 $this->error = $mouvS->error;
1621 $this->errors = $mouvS->errors;
1627 $this->error = $this->
db->lasterror();
1634 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1645 $this->
db->commit();
1648 $this->
db->rollback();
1664 dol_syslog(get_class($this).
"::set_billed is deprecated, use setBilled instead", LOG_NOTICE);
1682 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1683 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1691 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1697 $this->errors[] = $this->
db->lasterror;
1700 if (empty($error)) {
1701 $this->
db->commit();
1704 $this->
db->rollback();
1716 global $conf, $langs, $user;
1722 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1723 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1731 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1732 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1733 $numref = $this->ref;
1734 $langs->load(
"agenda");
1738 $sql =
"SELECT ed.fk_product, cd.subprice,";
1739 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1740 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1741 $sql .=
" ed.cost_price";
1742 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1743 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1744 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1745 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1747 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1750 $cpt = $this->
db->num_rows(
$resql);
1751 for ($i = 0; $i < $cpt; $i++) {
1752 $obj = $this->
db->fetch_object(
$resql);
1760 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1764 $mouvS->origin = &$this;
1765 $mouvS->setOrigin($this->element, $this->
id);
1767 if (empty($obj->batch)) {
1771 $inventorycode =
'';
1772 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1775 $this->error = $mouvS->error;
1776 $this->errors = $mouvS->errors;
1783 $inventorycode =
'';
1784 $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);
1786 $this->error = $mouvS->error;
1787 $this->errors = $mouvS->errors;
1793 $this->error = $this->
db->lasterror();
1800 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1806 if (!$error && $this->origin ==
'order_supplier') {
1808 $commande->fetch($this->origin_id);
1809 $result = $commande->setStatus($user, 4);
1812 $this->error = $commande->error;
1813 $this->errors = $commande->errors;
1818 $this->errors[] = $this->
db->lasterror();
1822 $this->
db->commit();
1825 $this->
db->rollback();
1839 global $conf, $langs;
1844 if ($this->statut <= self::STATUS_DRAFT) {
1848 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1849 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1850 $this->error =
'Permission denied';
1856 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1857 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1858 $sql .=
" WHERE rowid = ".((int) $this->
id);
1861 if ($this->
db->query($sql)) {
1863 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1864 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1866 $langs->load(
"agenda");
1870 $sql =
"SELECT cd.fk_product, cd.subprice,";
1871 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1872 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1873 $sql .=
" ed.cost_price";
1874 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1875 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1876 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1877 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1879 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1882 $cpt = $this->
db->num_rows(
$resql);
1883 for ($i = 0; $i < $cpt; $i++) {
1884 $obj = $this->
db->fetch_object(
$resql);
1892 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1896 $mouvS->origin = &$this;
1897 $mouvS->setOrigin($this->element, $this->
id);
1899 if (empty($obj->batch)) {
1903 $inventorycode =
'';
1904 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1906 $this->error = $mouvS->error;
1907 $this->errors = $mouvS->errors;
1915 $inventorycode =
'';
1916 $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);
1918 $this->error = $mouvS->error;
1919 $this->errors = $mouvS->errors;
1925 $this->error = $this->
db->lasterror();
1932 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1937 if ($this->origin ==
'order_supplier') {
1938 if (!empty($this->origin) && $this->origin_id > 0) {
1940 $origin = $this->origin;
1941 if ($this->$origin->statut == 4) {
1943 $this->$origin->fetchObjectLinked();
1945 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1946 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1947 if ($rcption->statut > 0) {
1954 $this->$origin->setStatut(3);
1962 $this->statut = self::STATUS_DRAFT;
1963 $this->
db->commit();
1966 $this->
db->rollback();
1970 $this->error = $this->
db->error();
1971 $this->
db->rollback();
1986 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1988 global $conf, $langs;
1990 $langs->load(
"receptions");
1993 $modele =
'squille';
1995 if ($this->model_pdf) {
1996 $modele = $this->model_pdf;
1997 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
1998 $modele = $conf->global->RECEPTION_ADDON_PDF;
2002 $modelpath =
"core/modules/reception/doc/";
2006 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2019 $tables = array(
'reception');
2035 'commande_fournisseur_dispatch'
Class to manage stock movements.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
LibStatut($status, $mode)
Return label of a status.
getLibStatut($mode=0)
Return status label.
setClosed()
Classify the reception as closed (this record also the stock movement)
getUrlTrackingStatus($value= '')
Forge an set tracking url.
const STATUS_RECEIVED_COMPLETELY
Received completely.
$conf db
API class for accounts.
update($user=null, $notrigger=0)
Update database.
Class to manage table commandefournisseurdispatch.
reOpen()
Classify the reception as validated/opened.
Class to manage products or services.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
dol_now($mode= 'auto')
Return date for now.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '', $f_user=null, $notrigger=0)
Delete all links between an object $this.
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
list_delivery_methods($id= '')
Fetch all deliveries method and return an array.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch($id, $ref= '', $ref_ext= '', $notused= '')
Get object and lines from database.
fetch_origin()
Read linked origin object.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
Class to manage third parties objects (customers, suppliers, prospects...)
getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0)
Return clicable link of object (with eventually picto)
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
setDraft($user)
Set draft status.
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) ...
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
const STATUS_RECEIVED_PARTIALLY
Received partially.
set_billed()
Classify the reception as invoiced (used when WORKFLOW_BILL_ON_RECEPTION is on)
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
setBilled()
Classify the reception as invoiced (used when WORKFLOW_BILL_ON_RECEPTION is on)
Class to manage receptions.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
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...
Class to manage predefined suppliers products.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
getNextNumRef($soc)
Return next contract ref.
create($user, $notrigger=0)
Create reception en base.
trait CommonIncoterm
Superclass for incoterm classes.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getStatusDispatch()
Get status from all dispatched lines.
addline($entrepot_id, $id, $qty, $array_options=0, $comment= '', $eatby= '', $sellby= '', $batch= '', $cost_price=0)
Add an reception line.
call_trigger($triggerName, $user)
Call trigger based on this instance.
__construct($db)
Constructor.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add objects linked in llx_element_element.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
initAsSpecimen()
Initialise an instance with random values.
setStatut($status, $elementId=null, $elementType= '', $trigkey= '', $fieldstatus= 'fk_statut')
Set status of an object.
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.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
fetch_delivery_methods()
Fetch deliveries method and return an array.
Class to manage line orders.