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.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->
ref = $obj->ref;
414 $this->socid = $obj->socid;
415 $this->ref_supplier = $obj->ref_supplier;
416 $this->ref_ext = $obj->ref_ext;
417 $this->statut = $obj->fk_statut;
418 $this->user_author_id = $obj->fk_user_author;
419 $this->date_creation = $this->
db->jdate($obj->date_creation);
420 $this->date = $this->
db->jdate($obj->date_reception);
421 $this->date_reception = $this->
db->jdate($obj->date_reception);
422 $this->date_reception = $this->
db->jdate($obj->date_reception);
423 $this->date_delivery = $this->
db->jdate($obj->date_delivery);
424 $this->model_pdf = $obj->model_pdf;
425 $this->modelpdf = $obj->model_pdf;
426 $this->shipping_method_id = $obj->fk_shipping_method;
427 $this->tracking_number = $obj->tracking_number;
428 $this->origin = ($obj->origin ? $obj->origin :
'commande');
429 $this->origin_id = $obj->origin_id;
430 $this->billed = ($obj->fk_statut == 2 ? 1 : 0);
432 $this->trueWeight = $obj->weight;
433 $this->weight_units = $obj->weight_units;
435 $this->trueWidth = $obj->width;
436 $this->width_units = $obj->size_units;
437 $this->trueHeight = $obj->height;
438 $this->height_units = $obj->size_units;
439 $this->trueDepth = $obj->size;
440 $this->depth_units = $obj->size_units;
442 $this->note_public = $obj->note_public;
443 $this->note_private = $obj->note_private;
446 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
447 $this->size_units = $obj->size_units;
450 $this->fk_incoterms = $obj->fk_incoterms;
451 $this->location_incoterms = $obj->location_incoterms;
452 $this->label_incoterms = $obj->label_incoterms;
454 $this->
db->free($result);
456 if ($this->statut == 0) {
457 $this->brouillon = 1;
474 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
476 $extrafields->fetch_name_optionals_label($this->table_element,
true);
489 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
490 $this->error =
'Delivery with id '.$id.
' not found';
494 $this->error = $this->
db->error();
506 public function valid($user, $notrigger = 0)
508 global $conf, $langs;
510 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
516 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
520 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
521 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
522 $this->error =
'Permission denied';
523 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
533 $soc->fetch($this->socid);
537 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
540 $numref = $this->ref;
548 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
549 $sql .=
" ref='".$this->db->escape($numref).
"'";
550 $sql .=
", fk_statut = 1";
551 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
552 $sql .=
", fk_user_valid = ".$user->id;
553 $sql .=
" WHERE rowid = ".((int) $this->
id);
554 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
557 $this->error = $this->
db->lasterror();
562 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
563 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
565 $langs->load(
"agenda");
569 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
570 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
571 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
572 $sql .=
" ed.cost_price";
573 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
574 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
575 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
576 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
578 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
582 for ($i = 0; $i < $cpt; $i++) {
583 $obj = $this->
db->fetch_object(
$resql);
587 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
590 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
594 $mouvS->origin = &$this;
595 $mouvS->setOrigin($this->element, $this->
id);
597 if (empty($obj->batch)) {
602 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
604 if (intval($result) < 0) {
606 $this->errors[] = $mouvS->error;
607 $this->errors = array_merge($this->errors, $mouvS->errors);
616 $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);
618 if (intval($result) < 0) {
620 $this->errors[] = $mouvS->error;
621 $this->errors = array_merge($this->errors, $mouvS->errors);
627 $this->
db->rollback();
628 $this->error = $this->
db->error();
640 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
643 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
646 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
653 if (!$error && !$notrigger) {
655 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
663 $this->oldref = $this->ref;
666 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
668 $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).
"'";
669 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->
db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
672 $error++; $this->error = $this->
db->lasterror();
678 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
679 $dirdest = $conf->reception->dir_output.
'/'.$newref;
680 if (!$error && file_exists($dirsource)) {
681 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
683 if (@rename($dirsource, $dirdest)) {
686 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
687 foreach ($listoffiles as $fileentry) {
688 $dirsource = $fileentry[
'name'];
689 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
690 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
691 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
692 @rename($dirsource, $dirdest);
701 $this->
ref = $numref;
709 foreach ($this->errors as $errmsg) {
710 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
711 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
713 $this->
db->rollback();
727 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
728 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
732 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
733 if (empty($this->commandeFournisseur)) {
735 if (empty($this->commandeFournisseur->lines)) {
736 $res = $this->commandeFournisseur->fetch_lines();
737 if ($res < 0)
return $res;
741 $qty_received = array();
742 $qty_wished = array();
745 $filter = array(
't.fk_commande'=>$this->origin_id);
746 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
747 $filter[
't.status'] = 1;
750 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
752 $this->error = $supplierorderdispatch->error;
753 $this->errors = $supplierorderdispatch->errors;
757 foreach ($supplierorderdispatch->lines as $dispatch_line) {
758 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
762 foreach ($this->commandeFournisseur->lines as $origin_line) {
764 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $origin_line->product_type > 0) {
768 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
772 $diff_array = array_diff_assoc($qty_received, $qty_wished);
773 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
774 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
776 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
778 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
782 if (count($diff_array) > 0) {
785 foreach ($diff_array as $key => $value) {
787 if ($qty_received[$key] >= $qty_wished[$key]) {
793 if ($close == count($diff_array)) {
820 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
822 global $conf, $langs, $user;
824 $num = count($this->lines);
827 $line->fk_entrepot = $entrepot_id;
828 $line->fk_commandefourndet = $id;
832 $result = $supplierorderline->fetch($id);
834 $this->error = $supplierorderline->error;
835 $this->errors = $supplierorderline->errors;
840 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
841 $fk_product = $supplierorderline->fk_product;
843 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
844 $langs->load(
"errors");
845 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
852 $product->fetch($fk_product);
854 $langs->load(
"errors");
855 if (!empty($product->status_batch) && empty($batch)) {
856 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
858 } elseif (empty($product->status_batch) && !empty($batch)) {
859 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
866 $line->array_options = $supplierorderline->array_options;
867 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
868 foreach ($array_options as $key => $value) {
869 $line->array_options[$key] = $value;
873 $line->fk_product = $fk_product;
874 $line->fk_commande = $supplierorderline->fk_commande;
875 $line->fk_user = $user->id;
876 $line->comment = $comment;
877 $line->batch = $batch;
878 $line->eatby = $eatby;
879 $line->sellby = $sellby;
881 $line->cost_price = $cost_price;
882 $line->fk_reception = $this->id;
884 $this->lines[$num] = $line;
897 public function update($user =
null, $notrigger = 0)
904 if (isset($this->
ref)) {
905 $this->
ref = trim($this->
ref);
907 if (isset($this->entity)) {
908 $this->entity = trim($this->entity);
910 if (isset($this->ref_supplier)) {
911 $this->ref_supplier = trim($this->ref_supplier);
913 if (isset($this->socid)) {
914 $this->socid = trim($this->socid);
916 if (isset($this->fk_user_author)) {
917 $this->fk_user_author = trim($this->fk_user_author);
919 if (isset($this->fk_user_valid)) {
920 $this->fk_user_valid = trim($this->fk_user_valid);
922 if (isset($this->shipping_method_id)) {
923 $this->shipping_method_id = trim($this->shipping_method_id);
925 if (isset($this->tracking_number)) {
926 $this->tracking_number = trim($this->tracking_number);
928 if (isset($this->statut)) {
929 $this->statut = (int) $this->statut;
931 if (isset($this->trueDepth)) {
932 $this->trueDepth = trim($this->trueDepth);
934 if (isset($this->trueWidth)) {
935 $this->trueWidth = trim($this->trueWidth);
937 if (isset($this->trueHeight)) {
938 $this->trueHeight = trim($this->trueHeight);
940 if (isset($this->size_units)) {
941 $this->size_units = trim($this->size_units);
943 if (isset($this->weight_units)) {
944 $this->weight_units = trim($this->weight_units);
946 if (isset($this->trueWeight)) {
947 $this->weight = trim($this->trueWeight);
949 if (isset($this->note_private)) {
950 $this->note_private = trim($this->note_private);
952 if (isset($this->note_public)) {
953 $this->note_public = trim($this->note_public);
955 if (isset($this->model_pdf)) {
956 $this->model_pdf = trim($this->model_pdf);
964 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
966 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
967 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
968 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
969 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
970 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
971 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
972 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
973 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
974 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
975 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
976 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
977 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
978 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
979 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
980 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
981 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
982 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
983 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
984 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
985 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
986 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
987 $sql .=
" entity = ".((int) $conf->entity);
988 $sql .=
" WHERE rowid=".((int) $this->
id);
992 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
995 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1001 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
1011 foreach ($this->errors as $errmsg) {
1012 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1013 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1015 $this->
db->rollback();
1018 $this->
db->commit();
1031 global $conf, $langs, $user;
1032 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1041 if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0) {
1042 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1044 $langs->load(
"agenda");
1047 $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";
1048 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1049 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1050 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1051 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1053 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1056 $cpt = $this->
db->num_rows(
$resql);
1057 for ($i = 0; $i < $cpt; $i++) {
1058 dol_syslog(get_class($this).
"::delete movement index ".$i);
1059 $obj = $this->
db->fetch_object(
$resql);
1063 $mouvS->origin =
null;
1065 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1068 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1073 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1074 $ef = $main.
"_extrafields";
1076 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1078 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1079 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1081 if ($this->
db->query($sqlef) && $this->
db->query($sql)) {
1089 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1090 $sql .=
" WHERE rowid = ".((int) $this->
id);
1092 if ($this->
db->query($sql)) {
1094 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1100 if (!empty($this->origin) && $this->origin_id > 0) {
1102 $origin = $this->origin;
1103 if ($this->$origin->statut == 4) {
1105 $this->$origin->loadReceptions();
1107 if (count($this->$origin->receptions) <= 0) {
1108 $this->$origin->setStatut(3);
1114 $this->
db->commit();
1118 if (!empty($conf->reception->dir_output)) {
1119 $dir = $conf->reception->dir_output.
'/'.$ref;
1120 $file = $dir.
'/'.$ref.
'.pdf';
1121 if (file_exists($file)) {
1126 if (file_exists($dir)) {
1128 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1136 $this->
db->rollback();
1140 $this->error = $this->
db->lasterror().
" - sql=$sql";
1141 $this->
db->rollback();
1145 $this->error = $this->
db->lasterror().
" - sql=$sql";
1146 $this->
db->rollback();
1150 $this->error = $this->
db->lasterror().
" - sql=$sql";
1151 $this->
db->rollback();
1155 $this->
db->rollback();
1169 $this->lines = array();
1171 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1173 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1177 while ($obj = $this->
db->fetch_object(
$resql)) {
1180 $line->fetch($obj->rowid);
1183 $line->fetch_product();
1185 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1186 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1187 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1188 $sql_commfourndet .=
' ORDER BY rang';
1190 $resql_commfourndet = $this->
db->query($sql_commfourndet);
1191 if (!empty($resql_commfourndet)) {
1192 $obj = $this->
db->fetch_object($resql_commfourndet);
1193 $line->qty_asked = $obj->qty;
1194 $line->description = $obj->description;
1195 $line->desc = $obj->description;
1196 $line->tva_tx = $obj->tva_tx;
1197 $line->vat_src_code = $obj->vat_src_code;
1198 $line->subprice = $obj->subprice;
1199 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1200 $line->remise_percent = $obj->remise_percent;
1201 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1202 $line->ref_supplier = $obj->ref;
1203 $line->total_ht = $obj->total_ht;
1204 $line->total_ttc = $obj->total_ttc;
1205 $line->total_tva = $obj->total_tva;
1207 $line->qty_asked = 0;
1208 $line->description =
'';
1210 $line->label = $obj->label;
1213 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1214 $tva = $pu_ht * $line->tva_tx / 100;
1215 $this->total_ht += $pu_ht;
1216 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1218 $this->total_ttc += $pu_ht + $tva;
1220 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1221 $detail_batch =
new stdClass();
1222 $detail_batch->eatby = $line->eatby;
1223 $detail_batch->sellby = $line->sellby;
1224 $detail_batch->batch = $line->batch;
1225 $detail_batch->qty = $line->qty;
1226 $line->detail_batch[] = $detail_batch;
1229 $this->lines[] = $line;
1248 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1250 global $conf, $langs, $hookmanager;
1252 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1253 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1254 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1256 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1263 if (empty($notooltip)) {
1264 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1265 $label = $langs->trans(
"Reception");
1266 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1268 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1269 $linkclose .=
' class="classfortooltip"';
1272 $linkstart =
'<a href="'.$url.
'"';
1273 $linkstart .= $linkclose.
'>';
1277 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
1279 if ($withpicto && $withpicto != 2) {
1282 $result .= $linkstart.$this->ref.$linkend;
1285 $hookmanager->initHooks(array($this->element .
'dao'));
1286 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1287 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1289 $result = $hookmanager->resPrint;
1291 $result .= $hookmanager->resPrint;
1304 return $this->
LibStatut($this->statut, $mode);
1320 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
1321 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
1323 $statusType =
'status'.$status;
1324 if ($status == self::STATUS_VALIDATED) {
1325 $statusType =
'status4';
1327 if ($status == self::STATUS_CLOSED) {
1328 $statusType =
'status6';
1331 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1345 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1346 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1349 dol_syslog(get_class($this).
"::initAsSpecimen");
1352 $order->initAsSpecimen();
1356 $this->
ref =
'SPECIMEN';
1357 $this->specimen = 1;
1359 $this->livraison_id = 0;
1361 $this->date_creation = $now;
1362 $this->date_valid = $now;
1363 $this->date_delivery = $now;
1364 $this->date_reception = $now + 24 * 3600;
1366 $this->entrepot_id = 0;
1369 $this->commande_id = 0;
1370 $this->commande = $order;
1372 $this->origin_id = 1;
1373 $this->origin =
'commande';
1375 $this->note_private =
'Private note';
1376 $this->note_public =
'Public note';
1380 while ($xnbp < $nbp) {
1382 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1383 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1386 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1388 $this->lines[] = $line;
1403 if ($user->rights->reception->creer) {
1404 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1405 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1406 $sql .=
" WHERE rowid = ".((int) $this->
id);
1408 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1411 $this->date_delivery = $delivery_date;
1414 $this->error = $this->
db->error();
1432 $this->meths = array();
1434 $sql =
"SELECT em.rowid, em.code, em.libelle";
1435 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1436 $sql .=
" WHERE em.active = 1";
1437 $sql .=
" ORDER BY em.libelle ASC";
1441 while ($obj = $this->
db->fetch_object(
$resql)) {
1442 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1443 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1460 $this->listmeths = array();
1463 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1464 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1466 $sql .=
" WHERE em.rowid = ".((int) $id);
1471 while ($obj = $this->
db->fetch_object(
$resql)) {
1472 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1473 $this->listmeths[$i][
'code'] = $obj->code;
1474 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1475 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1476 $this->listmeths[$i][
'description'] = $obj->description;
1477 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1478 $this->listmeths[$i][
'active'] = $obj->active;
1492 if (!empty($this->shipping_method_id)) {
1493 $sql =
"SELECT em.code, em.tracking";
1494 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1495 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1499 if ($obj = $this->
db->fetch_object(
$resql)) {
1500 $tracking = $obj->tracking;
1505 if (!empty($tracking) && !empty($value)) {
1506 $url = str_replace(
'{TRACKID}', $value, $tracking);
1507 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1509 $this->tracking_url = $value;
1520 global $conf, $langs, $user;
1526 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1527 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1532 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1534 $order->fetch($this->origin_id);
1536 $order->loadReceptions(self::STATUS_CLOSED);
1538 $receptions_match_order = 1;
1539 foreach ($order->lines as $line) {
1540 $lineid = $line->id;
1542 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1543 $receptions_match_order = 0;
1544 $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';
1549 if ($receptions_match_order) {
1550 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');
1551 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1555 $this->statut = self::STATUS_CLOSED;
1559 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1560 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1562 $langs->load(
"agenda");
1566 $sql =
"SELECT cd.fk_product, cd.subprice,";
1567 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1568 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1569 $sql .=
" ed.cost_price";
1570 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1571 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1572 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1573 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1575 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1579 $cpt = $this->
db->num_rows(
$resql);
1580 for ($i = 0; $i < $cpt; $i++) {
1581 $obj = $this->
db->fetch_object(
$resql);
1588 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1591 $mouvS->origin = &$this;
1592 $mouvS->setOrigin($this->element, $this->
id);
1594 if (empty($obj->batch)) {
1598 $inventorycode =
'';
1599 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1601 $this->error = $mouvS->error;
1602 $this->errors = $mouvS->errors;
1609 $inventorycode =
'';
1610 $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);
1613 $this->error = $mouvS->error;
1614 $this->errors = $mouvS->errors;
1620 $this->error = $this->
db->lasterror();
1627 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1638 $this->
db->commit();
1641 $this->
db->rollback();
1660 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1661 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1669 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1675 $this->errors[] = $this->
db->lasterror;
1678 if (empty($error)) {
1679 $this->
db->commit();
1682 $this->
db->rollback();
1694 global $conf, $langs, $user;
1700 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1701 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1709 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1710 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1711 $numref = $this->ref;
1712 $langs->load(
"agenda");
1716 $sql =
"SELECT ed.fk_product, cd.subprice,";
1717 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1718 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1719 $sql .=
" ed.cost_price";
1720 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1721 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1722 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1723 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1725 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1728 $cpt = $this->
db->num_rows(
$resql);
1729 for ($i = 0; $i < $cpt; $i++) {
1730 $obj = $this->
db->fetch_object(
$resql);
1738 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1742 $mouvS->origin = &$this;
1743 $mouvS->setOrigin($this->element, $this->
id);
1745 if (empty($obj->batch)) {
1749 $inventorycode =
'';
1750 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1753 $this->error = $mouvS->error;
1754 $this->errors = $mouvS->errors;
1761 $inventorycode =
'';
1762 $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);
1764 $this->error = $mouvS->error;
1765 $this->errors = $mouvS->errors;
1771 $this->error = $this->
db->lasterror();
1778 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1784 if (!$error && $this->origin ==
'order_supplier') {
1786 $commande->fetch($this->origin_id);
1787 $result = $commande->setStatus($user, 4);
1790 $this->error = $commande->error;
1791 $this->errors = $commande->errors;
1796 $this->errors[] = $this->
db->lasterror();
1800 $this->
db->commit();
1803 $this->
db->rollback();
1817 global $conf, $langs;
1822 if ($this->statut <= self::STATUS_DRAFT) {
1826 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1827 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1828 $this->error =
'Permission denied';
1834 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1835 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1836 $sql .=
" WHERE rowid = ".((int) $this->
id);
1839 if ($this->
db->query($sql)) {
1841 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1842 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1844 $langs->load(
"agenda");
1848 $sql =
"SELECT cd.fk_product, cd.subprice,";
1849 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1850 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1851 $sql .=
" ed.cost_price";
1852 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1853 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1854 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1855 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1857 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1860 $cpt = $this->
db->num_rows(
$resql);
1861 for ($i = 0; $i < $cpt; $i++) {
1862 $obj = $this->
db->fetch_object(
$resql);
1870 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1874 $mouvS->origin = &$this;
1875 $mouvS->setOrigin($this->element, $this->
id);
1877 if (empty($obj->batch)) {
1881 $inventorycode =
'';
1882 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1884 $this->error = $mouvS->error;
1885 $this->errors = $mouvS->errors;
1893 $inventorycode =
'';
1894 $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);
1896 $this->error = $mouvS->error;
1897 $this->errors = $mouvS->errors;
1903 $this->error = $this->
db->lasterror();
1910 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1915 if ($this->origin ==
'order_supplier') {
1916 if (!empty($this->origin) && $this->origin_id > 0) {
1918 $origin = $this->origin;
1919 if ($this->$origin->statut == 4) {
1921 $this->$origin->fetchObjectLinked();
1923 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1924 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1925 if ($rcption->statut > 0) {
1932 $this->$origin->setStatut(3);
1940 $this->statut = self::STATUS_DRAFT;
1941 $this->
db->commit();
1944 $this->
db->rollback();
1948 $this->error = $this->
db->error();
1949 $this->
db->rollback();
1964 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1966 global $conf, $langs;
1968 $langs->load(
"receptions");
1971 $modele =
'squille';
1973 if ($this->model_pdf) {
1974 $modele = $this->model_pdf;
1975 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
1976 $modele = $conf->global->RECEPTION_ADDON_PDF;
1980 $modelpath =
"core/modules/reception/doc/";
1984 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1997 $tables = array(
'reception');
2013 'commande_fournisseur_dispatch'
Class to manage table commandefournisseurdispatch.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage line orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
Class to manage receptions.
setBilled()
Classify the reception as invoiced (used when WORKFLOW_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.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0)
Return clicable link of object (with eventually picto)
update($user=null, $notrigger=0)
Update database.
setClosed()
Classify the reception as closed (this record also the stock movement)
getNextNumRef($soc)
Return next contract ref.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($status, $mode)
Return label of a status.
addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='', $cost_price=0)
Add an reception line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
list_delivery_methods($id='')
Fetch all deliveries method and return an array.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
__construct($db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create reception en base.
fetch($id, $ref='', $ref_ext='')
Get object and lines from database.
reOpen()
Classify the reception as validated/opened.
getStatusDispatch()
Get status from all dispatched lines.
setDraft($user)
Set draft status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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.