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 $qty_received[$dispatch_line->fk_product] += $dispatch_line->qty;
746 foreach ($this->commandeFournisseur->lines as $origin_line) {
748 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $origin_line->product_type > 0) {
752 $qty_wished[$origin_line->fk_product] += $origin_line->qty;
756 $diff_array = array_diff_assoc($qty_received, $qty_wished);
757 $keys_in_wished_not_in_received = array_diff(array_keys($qty_wished), array_keys($qty_received));
758 $keys_in_received_not_in_wished = array_diff(array_keys($qty_received), array_keys($qty_wished));
760 if (count($diff_array) == 0 && count($keys_in_wished_not_in_received) == 0 && count($keys_in_received_not_in_wished) == 0) {
762 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
766 if (count($diff_array) > 0) {
769 foreach ($diff_array as $key => $value) {
771 if ($qty_received[$key] >= $qty_wished[$key]) {
777 if ($close == count($diff_array)) {
804 public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $cost_price = 0)
806 global $conf, $langs, $user;
808 $num = count($this->lines);
811 $line->fk_entrepot = $entrepot_id;
812 $line->fk_commandefourndet = $id;
816 $result = $supplierorderline->fetch($id);
818 $this->error = $supplierorderline->error;
819 $this->errors = $supplierorderline->errors;
824 if (
isModEnabled(
'stock') && !empty($supplierorderline->fk_product)) {
825 $fk_product = $supplierorderline->fk_product;
827 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) {
828 $langs->load(
"errors");
829 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoReceptionLine");
835 $product =
new Product($this->db);
836 $product->fetch($fk_product);
838 $langs->load(
"errors");
839 if (!empty($product->status_batch) && empty($batch)) {
840 $this->error = $langs->trans(
'ErrorProductNeedBatchNumber', $product->ref);
842 } elseif (empty($product->status_batch) && !empty($batch)) {
843 $this->error = $langs->trans(
'ErrorProductDoesNotNeedBatchNumber', $product->ref);
850 $line->array_options = $supplierorderline->array_options;
851 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
852 foreach ($array_options as $key => $value) {
853 $line->array_options[$key] = $value;
857 $line->fk_product = $fk_product;
858 $line->fk_commande = $supplierorderline->fk_commande;
859 $line->fk_user = $user->id;
860 $line->comment = $comment;
861 $line->batch = $batch;
862 $line->eatby = $eatby;
863 $line->sellby = $sellby;
865 $line->cost_price = $cost_price;
866 $line->fk_reception = $this->id;
868 $this->lines[$num] = $line;
881 public function update($user =
null, $notrigger = 0)
888 if (isset($this->
ref)) {
889 $this->
ref = trim($this->
ref);
891 if (isset($this->entity)) {
892 $this->entity = trim($this->entity);
894 if (isset($this->ref_supplier)) {
895 $this->ref_supplier = trim($this->ref_supplier);
897 if (isset($this->socid)) {
898 $this->socid = trim($this->socid);
900 if (isset($this->fk_user_author)) {
901 $this->fk_user_author = trim($this->fk_user_author);
903 if (isset($this->fk_user_valid)) {
904 $this->fk_user_valid = trim($this->fk_user_valid);
906 if (isset($this->shipping_method_id)) {
907 $this->shipping_method_id = trim($this->shipping_method_id);
909 if (isset($this->tracking_number)) {
910 $this->tracking_number = trim($this->tracking_number);
912 if (isset($this->statut)) {
913 $this->statut = (int) $this->statut;
915 if (isset($this->trueDepth)) {
916 $this->trueDepth = trim($this->trueDepth);
918 if (isset($this->trueWidth)) {
919 $this->trueWidth = trim($this->trueWidth);
921 if (isset($this->trueHeight)) {
922 $this->trueHeight = trim($this->trueHeight);
924 if (isset($this->size_units)) {
925 $this->size_units = trim($this->size_units);
927 if (isset($this->weight_units)) {
928 $this->weight_units = trim($this->weight_units);
930 if (isset($this->trueWeight)) {
931 $this->weight = trim($this->trueWeight);
933 if (isset($this->note_private)) {
934 $this->note_private = trim($this->note_private);
936 if (isset($this->note_public)) {
937 $this->note_public = trim($this->note_public);
939 if (isset($this->model_pdf)) {
940 $this->model_pdf = trim($this->model_pdf);
948 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception SET";
950 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
951 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
952 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
953 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
954 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
955 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
956 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
957 $sql .=
" date_reception=".(dol_strlen($this->date_reception) != 0 ?
"'".$this->db->idate($this->date_reception).
"'" :
'null').
",";
958 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
959 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
960 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
961 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
962 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
963 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
964 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
965 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
966 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
967 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
968 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
969 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
970 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
971 $sql .=
" entity = ".((int) $conf->entity);
972 $sql .=
" WHERE rowid=".((int) $this->
id);
976 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
977 $resql = $this->db->query(
$sql);
979 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
985 $result = $this->
call_trigger(
'RECEPTION_MODIFY', $user);
995 foreach ($this->errors as $errmsg) {
996 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
997 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
999 $this->db->rollback();
1002 $this->db->commit();
1015 global $conf, $langs, $user;
1016 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1025 if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_RECEPTION && $this->statut > 0) {
1026 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1028 $langs->load(
"agenda");
1031 $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";
1032 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1033 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1034 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1035 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1037 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1038 $resql = $this->db->query(
$sql);
1040 $cpt = $this->db->num_rows($resql);
1041 for ($i = 0; $i < $cpt; $i++) {
1042 dol_syslog(get_class($this).
"::delete movement index ".$i);
1043 $obj = $this->db->fetch_object($resql);
1047 $mouvS->origin =
null;
1049 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ReceptionDeletedInDolibarr", $this->ref),
'', $obj->eatby, $obj->sellby, $obj->batch);
1052 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1057 $main = MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1058 $ef = $main.
"_extrafields";
1060 $sqlef =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_reception = ".((int) $this->
id).
")";
1062 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1063 $sql .=
" WHERE fk_reception = ".((int) $this->
id);
1065 if ($this->db->query($sqlef) && $this->db->query(
$sql)) {
1073 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"reception";
1074 $sql .=
" WHERE rowid = ".((int) $this->
id);
1076 if ($this->db->query(
$sql)) {
1078 $result = $this->
call_trigger(
'RECEPTION_DELETE', $user);
1084 if (!empty($this->origin) && $this->origin_id > 0) {
1086 $origin = $this->origin;
1087 if ($this->$origin->statut == 4) {
1089 $this->$origin->loadReceptions();
1091 if (count($this->$origin->receptions) <= 0) {
1092 $this->$origin->setStatut(3);
1098 $this->db->commit();
1102 if (!empty($conf->reception->dir_output)) {
1103 $dir = $conf->reception->dir_output.
'/'.$ref;
1104 $file = $dir.
'/'.$ref.
'.pdf';
1105 if (file_exists($file)) {
1110 if (file_exists($dir)) {
1112 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1120 $this->db->rollback();
1124 $this->error = $this->db->lasterror().
" - sql=$sql";
1125 $this->db->rollback();
1129 $this->error = $this->db->lasterror().
" - sql=$sql";
1130 $this->db->rollback();
1134 $this->error = $this->db->lasterror().
" - sql=$sql";
1135 $this->db->rollback();
1139 $this->db->rollback();
1153 $this->lines = array();
1155 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1157 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch WHERE fk_reception = ".((int) $this->
id);
1158 $resql = $this->db->query(
$sql);
1160 if (!empty($resql)) {
1161 while ($obj = $this->db->fetch_object($resql)) {
1164 $line->fetch($obj->rowid);
1167 $line->fetch_product();
1169 $sql_commfourndet =
'SELECT qty, ref, label, description, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent, total_ht, total_ttc, total_tva';
1170 $sql_commfourndet .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet';
1171 $sql_commfourndet .=
' WHERE rowid = '.((int) $line->fk_commandefourndet);
1172 $sql_commfourndet .=
' ORDER BY rang';
1174 $resql_commfourndet = $this->db->query($sql_commfourndet);
1175 if (!empty($resql_commfourndet)) {
1176 $obj = $this->db->fetch_object($resql_commfourndet);
1177 $line->qty_asked = $obj->qty;
1178 $line->description = $obj->description;
1179 $line->desc = $obj->description;
1180 $line->tva_tx = $obj->tva_tx;
1181 $line->vat_src_code = $obj->vat_src_code;
1182 $line->subprice = $obj->subprice;
1183 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1184 $line->remise_percent = $obj->remise_percent;
1185 $line->label = !empty($obj->label) ? $obj->label : $line->product->label;
1186 $line->ref_supplier = $obj->ref;
1187 $line->total_ht = $obj->total_ht;
1188 $line->total_ttc = $obj->total_ttc;
1189 $line->total_tva = $obj->total_tva;
1191 $line->qty_asked = 0;
1192 $line->description =
'';
1194 $line->label = $obj->label;
1197 $pu_ht = ($line->subprice * $line->qty) * (100 - $line->remise_percent) / 100;
1198 $tva = $pu_ht * $line->tva_tx / 100;
1199 $this->total_ht += $pu_ht;
1200 $this->total_tva += $pu_ht * $line->tva_tx / 100;
1202 $this->total_ttc += $pu_ht + $tva;
1204 if (
isModEnabled(
'productbatch') && !empty($line->batch)) {
1205 $detail_batch =
new stdClass();
1206 $detail_batch->eatby = $line->eatby;
1207 $detail_batch->sellby = $line->sellby;
1208 $detail_batch->batch = $line->batch;
1209 $detail_batch->qty = $line->qty;
1210 $line->detail_batch[] = $detail_batch;
1213 $this->lines[] = $line;
1232 public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0)
1234 global $conf, $langs, $hookmanager;
1236 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Reception").
'</u>';
1237 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1238 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.($this->ref_supplier ? $this->ref_supplier :
'');
1240 $url = DOL_URL_ROOT.
'/reception/card.php?id='.$this->id;
1247 if (empty($notooltip)) {
1248 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1249 $label = $langs->trans(
"Reception");
1250 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1252 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1253 $linkclose .=
' class="classfortooltip"';
1256 $linkstart =
'<a href="'.$url.
'"';
1257 $linkstart .= $linkclose.
'>';
1260 $result .= $linkstart;
1262 $result .=
img_object(($notooltip ?
'' : $label), $this->picto,
'', 0, 0, $notooltip ? 0 : 1);
1264 if ($withpicto != 2) {
1265 $result .= $this->ref;
1268 $result .= $linkend;
1271 $hookmanager->initHooks(array($this->element .
'dao'));
1272 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1273 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1275 $result = $hookmanager->resPrint;
1277 $result .= $hookmanager->resPrint;
1290 return $this->
LibStatut($this->statut, $mode);
1307 $this->labelStatus[-1] =
'StatusReceptionCanceled';
1308 $this->labelStatus[0] =
'StatusReceptionDraft';
1310 $this->labelStatus[1] =
'StatusReceptionValidated';
1312 $this->labelStatus[1] =
'StatusReceptionValidatedReceived';
1315 $this->labelStatus[1] =
'StatusReceptionValidatedToReceive';
1317 $this->labelStatus[2] =
'StatusReceptionProcessed';
1320 $this->labelStatusShort[-1] =
'StatusReceptionCanceledShort';
1321 $this->labelStatusShort[0] =
'StatusReceptionDraftShort';
1322 $this->labelStatusShort[1] =
'StatusReceptionValidatedShort';
1323 $this->labelStatusShort[2] =
'StatusReceptionProcessedShort';
1325 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1326 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1328 $statusType =
'status'.$status;
1329 if ($status == self::STATUS_VALIDATED) {
1330 $statusType =
'status4';
1332 if ($status == self::STATUS_CLOSED) {
1333 $statusType =
'status6';
1336 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1350 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1351 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
1354 dol_syslog(get_class($this).
"::initAsSpecimen");
1357 $order->initAsSpecimen();
1361 $this->
ref =
'SPECIMEN';
1362 $this->specimen = 1;
1364 $this->livraison_id = 0;
1366 $this->date_creation = $now;
1367 $this->date_valid = $now;
1368 $this->date_delivery = $now;
1369 $this->date_reception = $now + 24 * 3600;
1371 $this->entrepot_id = 0;
1374 $this->commande_id = 0;
1375 $this->commande = $order;
1377 $this->origin_id = 1;
1378 $this->origin =
'commande';
1380 $this->note_private =
'Private note';
1381 $this->note_public =
'Public note';
1385 while ($xnbp < $nbp) {
1387 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1388 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1389 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1392 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1394 $this->lines[] = $line;
1409 if ($user->rights->reception->creer) {
1410 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1411 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1412 $sql .=
" WHERE rowid = ".((int) $this->
id);
1414 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1415 $resql = $this->db->query(
$sql);
1417 $this->date_delivery = $delivery_date;
1420 $this->error = $this->db->error();
1438 $this->meths = array();
1440 $sql =
"SELECT em.rowid, em.code, em.libelle";
1441 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1442 $sql .=
" WHERE em.active = 1";
1443 $sql .=
" ORDER BY em.libelle ASC";
1445 $resql = $this->db->query(
$sql);
1447 while ($obj = $this->db->fetch_object($resql)) {
1448 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1449 $this->meths[$obj->rowid] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1466 $this->listmeths = array();
1469 $sql =
"SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active";
1470 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1472 $sql .=
" WHERE em.rowid = ".((int) $id);
1475 $resql = $this->db->query(
$sql);
1477 while ($obj = $this->db->fetch_object($resql)) {
1478 $this->listmeths[$i][
'rowid'] = $obj->rowid;
1479 $this->listmeths[$i][
'code'] = $obj->code;
1480 $label = $langs->trans(
'ReceptionMethod'.$obj->code);
1481 $this->listmeths[$i][
'libelle'] = ($label !=
'ReceptionMethod'.$obj->code ? $label : $obj->libelle);
1482 $this->listmeths[$i][
'description'] = $obj->description;
1483 $this->listmeths[$i][
'tracking'] = $obj->tracking;
1484 $this->listmeths[$i][
'active'] = $obj->active;
1498 if (!empty($this->shipping_method_id)) {
1499 $sql =
"SELECT em.code, em.tracking";
1500 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
1501 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
1503 $resql = $this->db->query(
$sql);
1505 if ($obj = $this->db->fetch_object($resql)) {
1506 $tracking = $obj->tracking;
1511 if (!empty($tracking) && !empty($value)) {
1512 $url = str_replace(
'{TRACKID}', $value, $tracking);
1513 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
1515 $this->tracking_url = $value;
1526 global $conf, $langs, $user;
1532 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut='.self::STATUS_CLOSED;
1533 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1535 $resql = $this->db->query(
$sql);
1538 if ($this->origin ==
'order_supplier' && $this->origin_id > 0) {
1540 $order->fetch($this->origin_id);
1542 $order->loadReceptions(self::STATUS_CLOSED);
1544 $receptions_match_order = 1;
1545 foreach ($order->lines as $line) {
1546 $lineid = $line->id;
1548 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->receptions[$lineid] < $qty) {
1549 $receptions_match_order = 0;
1550 $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';
1555 if ($receptions_match_order) {
1556 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');
1557 $order->Livraison($user,
dol_now(),
'tot',
'Reception '.$this->
ref);
1561 $this->statut = self::STATUS_CLOSED;
1565 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1566 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1568 $langs->load(
"agenda");
1572 $sql =
"SELECT cd.fk_product, cd.subprice,";
1573 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1574 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1575 $sql .=
" ed.cost_price";
1576 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1577 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1578 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1579 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1581 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1582 $resql = $this->db->query(
$sql);
1585 $cpt = $this->db->num_rows($resql);
1586 for ($i = 0; $i < $cpt; $i++) {
1587 $obj = $this->db->fetch_object($resql);
1594 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1597 $mouvS->origin = &$this;
1598 $mouvS->setOrigin($this->element, $this->
id);
1600 if (empty($obj->batch)) {
1604 $inventorycode =
'';
1605 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionClassifyClosedInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1607 $this->error = $mouvS->error;
1608 $this->errors = $mouvS->errors;
1615 $inventorycode =
'';
1616 $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);
1619 $this->error = $mouvS->error;
1620 $this->errors = $mouvS->errors;
1626 $this->error = $this->db->lasterror();
1633 $result = $this->
call_trigger(
'RECEPTION_CLOSED', $user);
1644 $this->db->commit();
1647 $this->db->rollback();
1666 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET billed=1';
1667 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1669 $resql = $this->db->query(
$sql);
1675 $result = $this->
call_trigger(
'RECEPTION_BILLED', $user);
1681 $this->errors[] = $this->db->lasterror;
1684 if (empty($error)) {
1685 $this->db->commit();
1688 $this->db->rollback();
1700 global $conf, $langs, $user;
1706 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'reception SET fk_statut=1, billed=0';
1707 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
1709 $resql = $this->db->query(
$sql);
1715 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
1716 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1717 $numref = $this->ref;
1718 $langs->load(
"agenda");
1722 $sql =
"SELECT ed.fk_product, cd.subprice,";
1723 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1724 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1725 $sql .=
" ed.cost_price";
1726 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1727 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1728 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1729 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1731 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1732 $resql = $this->db->query(
$sql);
1734 $cpt = $this->db->num_rows($resql);
1735 for ($i = 0; $i < $cpt; $i++) {
1736 $obj = $this->db->fetch_object($resql);
1744 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid);
1748 $mouvS->origin = &$this;
1749 $mouvS->setOrigin($this->element, $this->
id);
1751 if (empty($obj->batch)) {
1755 $inventorycode =
'';
1756 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionUnClassifyCloseddInDolibarr", $numref),
'',
'',
'',
'', 0, $inventorycode);
1759 $this->error = $mouvS->error;
1760 $this->errors = $mouvS->errors;
1767 $inventorycode =
'';
1768 $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);
1770 $this->error = $mouvS->error;
1771 $this->errors = $mouvS->errors;
1777 $this->error = $this->db->lasterror();
1784 $result = $this->
call_trigger(
'RECEPTION_REOPEN', $user);
1790 if (!$error && $this->origin ==
'order_supplier') {
1792 $commande->fetch($this->origin_id);
1793 $result = $commande->setStatus($user, 4);
1796 $this->error = $commande->error;
1797 $this->errors = $commande->errors;
1802 $this->errors[] = $this->db->lasterror();
1806 $this->db->commit();
1809 $this->db->rollback();
1823 global $conf, $langs;
1828 if ($this->statut <= self::STATUS_DRAFT) {
1832 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
1833 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) {
1834 $this->error =
'Permission denied';
1840 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"reception";
1841 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1842 $sql .=
" WHERE rowid = ".((int) $this->
id);
1845 if ($this->db->query(
$sql)) {
1847 if (!$error &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) {
1848 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1850 $langs->load(
"agenda");
1854 $sql =
"SELECT cd.fk_product, cd.subprice,";
1855 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
1856 $sql .=
" ed.eatby, ed.sellby, ed.batch,";
1857 $sql .=
" ed.cost_price";
1858 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd,";
1859 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as ed";
1860 $sql .=
" WHERE ed.fk_reception = ".((int) $this->
id);
1861 $sql .=
" AND cd.rowid = ed.fk_commandefourndet";
1863 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
1864 $resql = $this->db->query(
$sql);
1866 $cpt = $this->db->num_rows($resql);
1867 for ($i = 0; $i < $cpt; $i++) {
1868 $obj = $this->db->fetch_object($resql);
1876 dol_syslog(get_class($this).
"::reopen reception movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
1880 $mouvS->origin = &$this;
1881 $mouvS->setOrigin($this->element, $this->
id);
1883 if (empty($obj->batch)) {
1887 $inventorycode =
'';
1888 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->cost_price, $langs->trans(
"ReceptionBackToDraftInDolibarr", $this->ref),
'',
'',
'',
'', 0, $inventorycode);
1890 $this->error = $mouvS->error;
1891 $this->errors = $mouvS->errors;
1899 $inventorycode =
'';
1900 $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);
1902 $this->error = $mouvS->error;
1903 $this->errors = $mouvS->errors;
1909 $this->error = $this->db->lasterror();
1916 $result = $this->
call_trigger(
'RECEPTION_UNVALIDATE', $user);
1921 if ($this->origin ==
'order_supplier') {
1922 if (!empty($this->origin) && $this->origin_id > 0) {
1924 $origin = $this->origin;
1925 if ($this->$origin->statut == 4) {
1927 $this->$origin->fetchObjectLinked();
1929 if (!empty($this->$origin->linkedObjects[
'reception'])) {
1930 foreach ($this->$origin->linkedObjects[
'reception'] as $rcption) {
1931 if ($rcption->statut > 0) {
1938 $this->$origin->setStatut(3);
1946 $this->statut = self::STATUS_DRAFT;
1947 $this->db->commit();
1950 $this->db->rollback();
1954 $this->error = $this->db->error();
1955 $this->db->rollback();
1970 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1972 global $conf, $langs;
1974 $langs->load(
"receptions");
1977 $modele =
'squille';
1979 if ($this->model_pdf) {
1980 $modele = $this->model_pdf;
1981 } elseif (!empty($conf->global->RECEPTION_ADDON_PDF)) {
1982 $modele = $conf->global->RECEPTION_ADDON_PDF;
1986 $modelpath =
"core/modules/reception/doc/";
1990 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
2003 $tables = array(
'reception');
2019 'commande_fournisseur_dispatch'