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;
110 public $date_reception;
115 public $date_creation;
128 public $lines = array();
133 public $detail_batch;
135 const STATUS_DRAFT = 0;
136 const STATUS_VALIDATED = 1;
137 const STATUS_CLOSED = 2;
159 global $langs, $conf;
160 $langs->load(
"receptions");
162 if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) {
165 $file = $conf->global->RECEPTION_ADDON_NUMBER.
".php";
166 $classname = $conf->global->RECEPTION_ADDON_NUMBER;
169 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
171 foreach ($dirmodels as $reldir) {
175 $mybool |= @include_once $dir.$file;
183 $obj =
new $classname();
186 $numref = $obj->getNextValue($soc, $this);
191 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
195 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_RECEPTION_ADDON_NUMBER_NotDefined");
207 public function create($user, $notrigger = 0)
209 global $conf, $hookmanager;
213 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
217 $this->brouillon = 1;
219 if (empty($this->fk_project)) {
220 $this->fk_project = 0;
222 if (empty($this->weight_units)) {
223 $this->weight_units = 0;
225 if (empty($this->size_units)) {
226 $this->size_units = 0;
233 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"reception (";
236 $sql .=
", ref_supplier";
237 $sql .=
", date_creation";
238 $sql .=
", fk_user_author";
239 $sql .=
", date_reception";
240 $sql .=
", date_delivery";
242 $sql .=
", fk_projet";
243 $sql .=
", fk_shipping_method";
244 $sql .=
", tracking_number";
249 $sql .=
", weight_units";
250 $sql .=
", size_units";
251 $sql .=
", note_private";
252 $sql .=
", note_public";
253 $sql .=
", model_pdf";
254 $sql .=
", fk_incoterms, location_incoterms";
255 $sql .=
") VALUES (";
257 $sql .=
", ".((int) $conf->entity);
258 $sql .=
", ".($this->ref_supplier ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null");
259 $sql .=
", '".$this->db->idate($now).
"'";
260 $sql .=
", ".((int) $user->id);
261 $sql .=
", ".($this->date_reception > 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
"null");
262 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
263 $sql .=
", ".((int) $this->socid);
264 $sql .=
", ".((int) $this->fk_project);
265 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
266 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
267 $sql .=
", ".(is_null($this->weight) ?
"NULL" : ((double) $this->weight));
268 $sql .=
", ".(is_null($this->trueDepth) ?
"NULL" : ((double) $this->trueDepth));
269 $sql .=
", ".(is_null($this->trueWidth) ?
"NULL" : ((double) $this->trueWidth));
270 $sql .=
", ".(is_null($this->trueHeight) ?
"NULL" : ((double) $this->trueHeight));
271 $sql .=
", ".(is_null($this->weight_units) ?
"NULL" : ((double) $this->weight_units));
272 $sql .=
", ".(is_null($this->size_units) ?
"NULL" : ((double) $this->size_units));
273 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
274 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
275 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
276 $sql .=
", ".(int) $this->fk_incoterms;
277 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
280 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
282 $resql = $this->db->query(
$sql);
285 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"reception");
287 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
288 $sql .=
" SET ref = '(PROV".$this->id.
")'";
289 $sql .=
" WHERE rowid = ".((int) $this->
id);
291 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
292 if ($this->db->query(
$sql)) {
294 $num = count($this->lines);
295 for ($i = 0; $i < $num; $i++) {
296 $this->lines[$i]->fk_reception = $this->id;
298 if (!$this->lines[$i]->
create($user) > 0) {
303 if (!$error && $this->
id && $this->origin_id) {
318 if (!$error && !$notrigger) {
320 $result = $this->
call_trigger(
'RECEPTION_CREATE', $user);
331 foreach ($this->errors as $errmsg) {
332 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
333 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
335 $this->db->rollback();
340 $this->error = $this->db->lasterror().
" - sql=$sql";
341 $this->db->rollback();
346 $this->error = $this->db->error().
" - sql=$sql";
347 $this->db->rollback();
362 public function fetch($id, $ref =
'', $ref_ext =
'')
365 if (empty($id) && empty($ref) && empty($ref_ext)) {
369 $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";
370 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
371 $sql .=
", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
372 $sql .=
", e.fk_shipping_method, e.tracking_number";
373 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
374 $sql .=
", e.note_private, e.note_public";
375 $sql .=
', e.fk_incoterms, e.location_incoterms';
376 $sql .=
', i.libelle as label_incoterms';
377 $sql .=
" FROM ".MAIN_DB_PREFIX.
"reception as e";
378 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
379 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
380 $sql .=
" WHERE e.entity IN (".getEntity(
'reception').
")";
382 $sql .=
" AND e.rowid=".((int) $id);
385 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
388 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
391 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
392 $result = $this->db->query(
$sql);
394 if ($this->db->num_rows($result)) {
395 $obj = $this->db->fetch_object($result);
397 $this->
id = $obj->rowid;
398 $this->
ref = $obj->ref;
399 $this->socid = $obj->socid;
400 $this->ref_supplier = $obj->ref_supplier;
401 $this->ref_ext = $obj->ref_ext;
402 $this->statut = $obj->fk_statut;
403 $this->user_author_id = $obj->fk_user_author;
404 $this->date_creation = $this->db->jdate($obj->date_creation);
405 $this->date = $this->db->jdate($obj->date_reception);
406 $this->date_reception = $this->db->jdate($obj->date_reception);
407 $this->date_delivery = $this->db->jdate($obj->date_delivery);
408 $this->model_pdf = $obj->model_pdf;
409 $this->modelpdf = $obj->model_pdf;
410 $this->shipping_method_id = $obj->fk_shipping_method;
411 $this->tracking_number = $obj->tracking_number;
412 $this->origin = ($obj->origin ? $obj->origin :
'commande');
413 $this->origin_id = $obj->origin_id;
414 $this->billed = ($obj->fk_statut == 2 ? 1 : 0);
416 $this->trueWeight = $obj->weight;
417 $this->weight_units = $obj->weight_units;
419 $this->trueWidth = $obj->width;
420 $this->width_units = $obj->size_units;
421 $this->trueHeight = $obj->height;
422 $this->height_units = $obj->size_units;
423 $this->trueDepth = $obj->size;
424 $this->depth_units = $obj->size_units;
426 $this->note_public = $obj->note_public;
427 $this->note_private = $obj->note_private;
430 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
431 $this->size_units = $obj->size_units;
434 $this->fk_incoterms = $obj->fk_incoterms;
435 $this->location_incoterms = $obj->location_incoterms;
436 $this->label_incoterms = $obj->label_incoterms;
438 $this->db->free($result);
440 if ($this->statut == 0) {
441 $this->brouillon = 1;
458 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
460 $extrafields->fetch_name_optionals_label($this->table_element,
true);
473 dol_syslog(get_class($this).
'::Fetch no reception found', LOG_ERR);
474 $this->error =
'Delivery with id '.$id.
' not found';
478 $this->error = $this->db->error();
490 public function valid($user, $notrigger = 0)
492 global $conf, $langs;
494 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
500 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
504 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
505 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
506 $this->error =
'Permission denied';
507 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
517 $soc->fetch($this->socid);
521 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
524 $numref = $this->ref;
532 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
533 $sql .=
" ref='".$this->db->escape($numref).
"'";
534 $sql .=
", fk_statut = 1";
535 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
536 $sql .=
", fk_user_valid = ".$user->id;
537 $sql .=
" WHERE rowid = ".((int) $this->
id);
538 dol_syslog(get_class($this).
"::valid update reception", LOG_DEBUG);
539 $resql = $this->db->query(
$sql);
541 $this->error = $this->db->lasterror();
546 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
547 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
549 $langs->load(
"agenda");
553 $sql =
"SELECT cd.fk_product, cd.subprice, cd.remise_percent,";
554 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
555 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
556 $sql .=
" ed.cost_price";
557 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
558 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
559 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
560 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
562 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
563 $resql = $this->db->query(
$sql);
565 $cpt = $this->db->num_rows($resql);
566 for ($i = 0; $i < $cpt; $i++) {
567 $obj = $this->db->fetch_object($resql);
571 if ($qty == 0 || ($qty < 0 && !
getDolGlobalInt(
'RECEPTION_ALLOW_NEGATIVE_QTY'))) {
574 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
578 $mouvS->origin = &$this;
579 $mouvS->setOrigin($this->element, $this->
id);
581 if (empty($obj->batch)) {
586 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionValidatedInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
588 if (intval($result) < 0) {
590 $this->errors[] = $mouvS->error;
591 $this->errors = array_merge($this->errors, $mouvS->errors);
600 $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);
602 if (intval($result) < 0) {
604 $this->errors[] = $mouvS->error;
605 $this->errors = array_merge($this->errors, $mouvS->errors);
611 $this->db->rollback();
612 $this->error = $this->db->error();
624 $ret = $this->commandeFournisseur->Livraison($user,
dol_now(),
'tot',
'');
627 $this->errors = array_merge($this->errors, $this->commandeFournisseur->errors);
630 $ret = $this->
setStatut($status, $this->origin_id,
'commande_fournisseur', $trigger_key);
637 if (!$error && !$notrigger) {
639 $result = $this->
call_trigger(
'RECEPTION_VALIDATE', $user);
647 $this->oldref = $this->ref;
650 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
652 $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).
"'";
653 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'reception/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
654 $resql = $this->db->query(
$sql);
656 $error++; $this->error = $this->db->lasterror();
662 $dirsource = $conf->reception->dir_output.
'/'.$oldref;
663 $dirdest = $conf->reception->dir_output.
'/'.$newref;
664 if (!$error && file_exists($dirsource)) {
665 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
667 if (@rename($dirsource, $dirdest)) {
670 $listoffiles =
dol_dir_list($conf->reception->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
671 foreach ($listoffiles as $fileentry) {
672 $dirsource = $fileentry[
'name'];
673 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
674 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
675 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
676 @rename($dirsource, $dirdest);
685 $this->
ref = $numref;
693 foreach ($this->errors as $errmsg) {
694 dol_syslog(get_class($this).
"::valid ".$errmsg, LOG_ERR);
695 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
697 $this->db->rollback();
711 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
712 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
716 if (!empty($this->origin) && $this->origin_id > 0 && ($this->origin ==
'order_supplier' || $this->origin ==
'commandeFournisseur')) {
717 if (empty($this->commandeFournisseur)) {
719 if (empty($this->commandeFournisseur->lines)) {
720 $res = $this->commandeFournisseur->fetch_lines();
721 if ($res < 0)
return $res;
725 $qty_received = array();
726 $qty_wished = array();
729 $filter = array(
't.fk_commande'=>$this->origin_id);
730 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
731 $filter[
't.status'] = 1;
734 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
736 $this->error = $supplierorderdispatch->error;
737 $this->errors = $supplierorderdispatch->errors;
741 foreach ($supplierorderdispatch->lines as $dispatch_line) {
742 if (array_key_exists($dispatch_line->fk_product, $qty_received)) {
743 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
748 foreach ($this->commandeFournisseur->lines as $origin_line) {
750 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $origin_line->product_type > 0) {
754 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
758 $diff_array = array_diff_assoc($qty_received, $qty_wished);
759 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
760 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
762 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
764 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
768 if (count($diff_array) > 0) {
771 foreach ($diff_array as $key => $value) {
773 if ($qty_received[$key] >= $qty_wished[$key]) {
779 if ($close == count($diff_array)) {
806 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
808 global $conf, $langs, $user;
810 $num = count($this->lines);
813 $line->fk_entrepot = $entrepot_id;
814 $line->fk_commandefourndet = $id;
818 $result = $supplierorderline->fetch($id);
820 $this->error = $supplierorderline->error;
821 $this->errors = $supplierorderline->errors;
826 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
827 $fk_product = $supplierorderline->fk_product;
829 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
830 $langs->load(
"errors");
831 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
837 $product =
new Product($this->db);
838 $product->fetch($fk_product);
840 $langs->load(
"errors");
841 if (!empty($product->status_batch) && empty($batch)) {
842 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
844 } elseif (empty($product->status_batch) && !empty($batch)) {
845 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
852 $line->array_options = $supplierorderline->array_options;
853 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
854 foreach ($array_options as $key => $value) {
855 $line->array_options[$key] = $value;
859 $line->fk_product = $fk_product;
860 $line->fk_commande = $supplierorderline->fk_commande;
861 $line->fk_user = $user->id;
862 $line->comment = $comment;
863 $line->batch = $batch;
864 $line->eatby = $eatby;
865 $line->sellby = $sellby;
867 $line->cost_price = $cost_price;
868 $line->fk_reception = $this->id;
870 $this->lines[$num] = $line;
883 public function update($user =
null, $notrigger = 0)
890 if (isset($this->
ref)) {
891 $this->
ref = trim($this->
ref);
893 if (isset($this->entity)) {
894 $this->entity = trim($this->entity);
896 if (isset($this->ref_supplier)) {
897 $this->ref_supplier = trim($this->ref_supplier);
899 if (isset($this->socid)) {
900 $this->socid = trim($this->socid);
902 if (isset($this->fk_user_author)) {
903 $this->fk_user_author = trim($this->fk_user_author);
905 if (isset($this->fk_user_valid)) {
906 $this->fk_user_valid = trim($this->fk_user_valid);
908 if (isset($this->shipping_method_id)) {
909 $this->shipping_method_id = trim($this->shipping_method_id);
911 if (isset($this->tracking_number)) {
912 $this->tracking_number = trim($this->tracking_number);
914 if (isset($this->statut)) {
915 $this->statut = (int) $this->statut;
917 if (isset($this->trueDepth)) {
918 $this->trueDepth = trim($this->trueDepth);
920 if (isset($this->trueWidth)) {
921 $this->trueWidth = trim($this->trueWidth);
923 if (isset($this->trueHeight)) {
924 $this->trueHeight = trim($this->trueHeight);
926 if (isset($this->size_units)) {
927 $this->size_units = trim($this->size_units);
929 if (isset($this->weight_units)) {
930 $this->weight_units = trim($this->weight_units);
932 if (isset($this->trueWeight)) {
933 $this->weight = trim($this->trueWeight);
935 if (isset($this->note_private)) {
936 $this->note_private = trim($this->note_private);
938 if (isset($this->note_public)) {
939 $this->note_public = trim($this->note_public);
941 if (isset($this->model_pdf)) {
942 $this->model_pdf = trim($this->model_pdf);
950 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
952 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
953 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
954 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
955 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
956 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
957 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
958 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
959 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
960 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
961 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
962 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
963 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
964 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
965 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
966 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
967 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
968 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
969 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
970 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
971 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
972 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
973 $sql .=
" entity = ".((int) $conf->entity);
974 $sql .=
" WHERE rowid=".((int) $this->
id);
978 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
979 $resql = $this->db->query(
$sql);
981 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
987 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
997 foreach ($this->errors as $errmsg) {
998 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
999 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1001 $this->db->rollback();
1004 $this->db->commit();
1017 global $conf, $langs, $user;
1018 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1027 if (
isModEnabled(
'stock') && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0) {
1028 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1030 $langs->load(
"agenda");
1033 $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";
1034 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1035 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1036 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1037 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1039 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1040 $resql = $this->db->query(
$sql);
1042 $cpt = $this->db->num_rows($resql);
1043 for ($i = 0; $i < $cpt; $i++) {
1044 dol_syslog(get_class($this).
"::delete movement index ".$i);
1045 $obj = $this->db->fetch_object($resql);
1049 $mouvS->origin =
null;
1051 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1054 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1059 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1060 $ef = $main.
"_extrafields";
1062 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1064 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1065 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1067 if ($this->db->query($sqlef) && $this->db->query(
$sql)) {
1075 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1076 $sql .=
" WHERE rowid = ".((int) $this->
id);
1078 if ($this->db->query(
$sql)) {
1080 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1086 if (!empty($this->origin) && $this->origin_id > 0) {
1088 $origin = $this->origin;
1089 if ($this->$origin->statut == 4) {
1091 $this->$origin->loadReceptions();
1093 if (count($this->$origin->receptions) <= 0) {
1094 $this->$origin->setStatut(3);
1100 $this->db->commit();
1104 if (!empty($conf->reception->dir_output)) {
1105 $dir = $conf->reception->dir_output.
'/'.$ref;
1106 $file = $dir.
'/'.$ref.
'.pdf';
1107 if (file_exists($file)) {
1112 if (file_exists($dir)) {
1114 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1122 $this->db->rollback();
1126 $this->error = $this->db->lasterror().
" - sql=$sql";
1127 $this->db->rollback();
1131 $this->error = $this->db->lasterror().
" - sql=$sql";
1132 $this->db->rollback();
1136 $this->error = $this->db->lasterror().
" - sql=$sql";
1137 $this->db->rollback();
1141 $this->db->rollback();
1155 $this->lines = array();
1157 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1159 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1160 $resql = $this->db->query(
$sql);
1162 if (!empty($resql)) {
1163 while ($obj = $this->db->fetch_object($resql)) {
1166 $line->fetch($obj->rowid);
1169 $line->fetch_product();
1171 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1172 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1173 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1174 $sql_commfourndet .=
' ORDER BY rang';
1176 $resql_commfourndet = $this->db->query($sql_commfourndet);
1177 if (!empty($resql_commfourndet)) {
1178 $obj = $this->db->fetch_object($resql_commfourndet);
1179 $line->qty_asked = $obj->qty;
1180 $line->description = $obj->description;
1181 $line->desc = $obj->description;
1182 $line->tva_tx = $obj->tva_tx;
1183 $line->vat_src_code = $obj->vat_src_code;
1184 $line->subprice = $obj->subprice;
1185 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1186 $line->remise_percent = $obj->remise_percent;
1187 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1188 $line->ref_supplier = $obj->ref;
1189 $line->total_ht = $obj->total_ht;
1190 $line->total_ttc = $obj->total_ttc;
1191 $line->total_tva = $obj->total_tva;
1193 $line->qty_asked = 0;
1194 $line->description =
'';
1196 $line->label = $obj->label;
1199 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1200 $tva = $pu_ht * $line->tva_tx / 100;
1201 $this->total_ht += $pu_ht;
1202 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1204 $this->total_ttc += $pu_ht + $tva;
1206 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1207 $detail_batch =
new stdClass();
1208 $detail_batch->eatby = $line->eatby;
1209 $detail_batch->sellby = $line->sellby;
1210 $detail_batch->batch = $line->batch;
1211 $detail_batch->qty = $line->qty;
1212 $line->detail_batch[] = $detail_batch;
1215 $this->lines[] = $line;
1234 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1236 global $conf, $langs, $hookmanager;
1238 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1239 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1240 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1242 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1249 if (empty($notooltip)) {
1250 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1251 $label = $langs->trans(
"Reception");
1252 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1254 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1255 $linkclose .=
' class="classfortooltip"';
1258 $linkstart =
'<a href="'.$url.
'"';
1259 $linkstart .= $linkclose.
'>';
1262 $result .= $linkstart;
1264 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1266 if ($withpicto != 2) {
1267 $result .= $this->ref;
1270 $result .= $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);
1309 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1310 $this->labelStatus[0] =
'StatusReceptionDraft';
1312 $this->labelStatus[1] =
'StatusReceptionValidated';
1314 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1317 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1319 $this->labelStatus[2] =
'StatusReceptionProcessed';
1322 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1323 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1324 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1325 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1327 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1328 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1330 $statusType =
'status'.$status;
1331 if ($status == self::STATUS_VALIDATED) {
1332 $statusType =
'status4';
1334 if ($status == self::STATUS_CLOSED) {
1335 $statusType =
'status6';
1338 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1352 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1353 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1356 dol_syslog(get_class($this).
"::initAsSpecimen");
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;
1391 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1394 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1396 $this->lines[] = $line;
1411 if ($user->rights->reception->creer) {
1412 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1413 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1414 $sql .=
" WHERE rowid = ".((int) $this->
id);
1416 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1417 $resql = $this->db->query(
$sql);
1419 $this->date_delivery = $delivery_date;
1422 $this->error = $this->db->error();
1440 $this->meths = array();
1442 $sql =
"SELECT em.rowid, em.code, em.libelle";
1443 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1444 $sql .=
" WHERE em.active = 1";
1445 $sql .=
" ORDER BY em.libelle ASC";
1447 $resql = $this->db->query(
$sql);
1449 while ($obj = $this->db->fetch_object($resql)) {
1450 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1451 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1468 $this->listmeths = array();
1471 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1472 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1474 $sql .=
" WHERE em.rowid = ".((int) $id);
1477 $resql = $this->db->query(
$sql);
1479 while ($obj = $this->db->fetch_object($resql)) {
1480 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1481 $this->listmeths[$i][
'code'] = $obj->code;
1482 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1483 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1484 $this->listmeths[$i][
'description'] = $obj->description;
1485 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1486 $this->listmeths[$i][
'active'] = $obj->active;
1500 if (!empty($this->shipping_method_id)) {
1501 $sql =
"SELECT em.code, em.tracking";
1502 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1503 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1505 $resql = $this->db->query(
$sql);
1507 if ($obj = $this->db->fetch_object($resql)) {
1508 $tracking = $obj->tracking;
1513 if (!empty($tracking) && !empty($value)) {
1514 $url = str_replace(
'{TRACKID}', $value, $tracking);
1515 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1517 $this->tracking_url = $value;
1528 global $conf, $langs, $user;
1534 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1535 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1537 $resql = $this->db->query(
$sql);
1540 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1542 $order->fetch($this->origin_id);
1544 $order->loadReceptions(self::STATUS_CLOSED);
1546 $receptions_match_order = 1;
1547 foreach ($order->lines as $line) {
1548 $lineid = $line->id;
1550 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1551 $receptions_match_order = 0;
1552 $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';
1557 if ($receptions_match_order) {
1558 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');
1559 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1563 $this->statut = self::STATUS_CLOSED;
1567 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1568 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1570 $langs->load(
"agenda");
1574 $sql =
"SELECT cd.fk_product, cd.subprice,";
1575 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1576 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1577 $sql .=
" ed.cost_price";
1578 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1579 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1580 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1581 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1583 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1584 $resql = $this->db->query(
$sql);
1587 $cpt = $this->db->num_rows($resql);
1588 for ($i = 0; $i < $cpt; $i++) {
1589 $obj = $this->db->fetch_object($resql);
1596 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1599 $mouvS->origin = &$this;
1600 $mouvS->setOrigin($this->element, $this->
id);
1602 if (empty($obj->batch)) {
1606 $inventorycode =
'';
1607 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1609 $this->error = $mouvS->error;
1610 $this->errors = $mouvS->errors;
1617 $inventorycode =
'';
1618 $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);
1621 $this->error = $mouvS->error;
1622 $this->errors = $mouvS->errors;
1628 $this->error = $this->db->lasterror();
1635 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1646 $this->db->commit();
1649 $this->db->rollback();
1668 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1669 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1671 $resql = $this->db->query(
$sql);
1677 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1683 $this->errors[] = $this->db->lasterror;
1686 if (empty($error)) {
1687 $this->db->commit();
1690 $this->db->rollback();
1702 global $conf, $langs, $user;
1708 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1709 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1711 $resql = $this->db->query(
$sql);
1717 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1718 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1719 $numref = $this->ref;
1720 $langs->load(
"agenda");
1724 $sql =
"SELECT ed.fk_product, cd.subprice,";
1725 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1726 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1727 $sql .=
" ed.cost_price";
1728 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1729 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1730 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1731 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1733 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1734 $resql = $this->db->query(
$sql);
1736 $cpt = $this->db->num_rows($resql);
1737 for ($i = 0; $i < $cpt; $i++) {
1738 $obj = $this->db->fetch_object($resql);
1746 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1750 $mouvS->origin = &$this;
1751 $mouvS->setOrigin($this->element, $this->
id);
1753 if (empty($obj->batch)) {
1757 $inventorycode =
'';
1758 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1761 $this->error = $mouvS->error;
1762 $this->errors = $mouvS->errors;
1769 $inventorycode =
'';
1770 $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);
1772 $this->error = $mouvS->error;
1773 $this->errors = $mouvS->errors;
1779 $this->error = $this->db->lasterror();
1786 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1792 if (!$error && $this->origin ==
'order_supplier') {
1794 $commande->fetch($this->origin_id);
1795 $result = $commande->setStatus($user, 4);
1798 $this->error = $commande->error;
1799 $this->errors = $commande->errors;
1804 $this->errors[] = $this->db->lasterror();
1808 $this->db->commit();
1811 $this->db->rollback();
1825 global $conf, $langs;
1830 if ($this->statut <= self::STATUS_DRAFT) {
1834 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1835 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1836 $this->error =
'Permission denied';
1842 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1843 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1844 $sql .=
" WHERE rowid = ".((int) $this->
id);
1847 if ($this->db->query(
$sql)) {
1849 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1850 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1852 $langs->load(
"agenda");
1856 $sql =
"SELECT cd.fk_product, cd.subprice,";
1857 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1858 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1859 $sql .=
" ed.cost_price";
1860 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1861 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1862 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1863 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1865 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1866 $resql = $this->db->query(
$sql);
1868 $cpt = $this->db->num_rows($resql);
1869 for ($i = 0; $i < $cpt; $i++) {
1870 $obj = $this->db->fetch_object($resql);
1878 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1882 $mouvS->origin = &$this;
1883 $mouvS->setOrigin($this->element, $this->
id);
1885 if (empty($obj->batch)) {
1889 $inventorycode =
'';
1890 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1892 $this->error = $mouvS->error;
1893 $this->errors = $mouvS->errors;
1901 $inventorycode =
'';
1902 $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);
1904 $this->error = $mouvS->error;
1905 $this->errors = $mouvS->errors;
1911 $this->error = $this->db->lasterror();
1918 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1923 if ($this->origin ==
'order_supplier') {
1924 if (!empty($this->origin) && $this->origin_id > 0) {
1926 $origin = $this->origin;
1927 if ($this->$origin->statut == 4) {
1929 $this->$origin->fetchObjectLinked();
1931 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1932 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1933 if ($rcption->statut > 0) {
1940 $this->$origin->setStatut(3);
1948 $this->statut = self::STATUS_DRAFT;
1949 $this->db->commit();
1952 $this->db->rollback();
1956 $this->error = $this->db->error();
1957 $this->db->rollback();
1972 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1974 global $conf, $langs;
1976 $langs->load(
"receptions");
1979 $modele =
'squille';
1981 if ($this->model_pdf) {
1982 $modele = $this->model_pdf;
1983 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
1984 $modele = $conf->global->RECEPTION_ADDON_PDF;
1988 $modelpath =
"core/modules/reception/doc/";
1992 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2005 $tables = array(
'reception');
2021 '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') && $user->hasRight('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') && $user->hasRight('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)) $sql
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return 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.