40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41require_once DOL_DOCUMENT_ROOT.
"/expedition/class/expeditionligne.class.php";
42require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionlinebatch.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsignedobject.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
61 use CommonSignedObject;
67 public $element =
"shipping";
72 public $fk_element =
"fk_expedition";
77 public $table_element =
"expedition";
82 public $table_element_line =
"expeditiondet";
87 public $class_element_line =
'ExpeditionLigne';
92 public $picto =
'dolly';
98 public $fields = array();
104 public $user_author_id;
110 public $fk_user_author;
116 public $fk_user_valid;
133 public $ref_customer;
143 public $tracking_number;
148 public $tracking_url;
161 public $weight_units;
177 public $height_units;
194 public $livraison_id;
199 public $multicurrency_subprice;
229 public $date_delivery;
243 public $date_expedition;
249 public $date_shipping;
278 public $lines = array();
284 public $fk_multicurrency;
289 public $multicurrency_code;
293 public $multicurrency_tx;
297 public $multicurrency_total_ht;
301 public $multicurrency_total_tva;
305 public $multicurrency_total_ttc;
352 $this->ismultientitymanaged = 1;
353 $this->isextrafieldmanaged = 1;
356 $this->labelStatus = array();
357 $this->labelStatus[-1] =
'StatusSendingCanceled';
358 $this->labelStatus[0] =
'StatusSendingDraft';
359 $this->labelStatus[1] =
'StatusSendingValidated';
360 $this->labelStatus[2] =
'StatusSendingProcessed';
363 $this->labelStatusShort = array();
364 $this->labelStatusShort[-1] =
'StatusSendingCanceledShort';
365 $this->labelStatusShort[0] =
'StatusSendingDraftShort';
366 $this->labelStatusShort[1] =
'StatusSendingValidatedShort';
367 $this->labelStatusShort[2] =
'StatusSendingProcessedShort';
376 public function getNextNumRef($soc)
378 global $langs, $conf;
379 $langs->load(
"sendings");
388 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
390 foreach ($dirmodels as $reldir) {
394 $mybool = ((bool) @include_once $dir.$file) || $mybool;
402 $obj =
new $classname();
403 '@phan-var-force ModelNumRefExpedition $obj';
405 $numref = $obj->getNextValue($soc, $this);
410 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
414 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
426 public function create($user, $notrigger = 0)
430 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
435 if (empty($this->fk_project)) {
436 $this->fk_project = 0;
438 if (empty($this->date_creation)) {
439 $this->date_creation = $now;
441 if (empty($this->date_shipping) && !empty($this->date_expedition)) {
442 $this->date_shipping = $this->date_expedition;
450 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
453 $sql .=
", ref_customer";
455 $sql .=
", date_creation";
456 $sql .=
", fk_user_author";
457 $sql .=
", date_expedition";
458 $sql .=
", date_delivery";
460 $sql .=
", fk_projet";
461 $sql .=
", fk_address";
462 $sql .=
", fk_shipping_method";
463 $sql .=
", tracking_number";
468 $sql .=
", weight_units";
469 $sql .=
", size_units";
470 $sql .=
", note_private";
471 $sql .=
", note_public";
472 $sql .=
", model_pdf";
473 $sql .=
", fk_incoterms, location_incoterms";
474 $sql .=
", signed_status";
475 $sql .=
") VALUES (";
477 $sql .=
", ".((int) $this->entity);
478 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
479 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
480 $sql .=
", '".$this->db->idate($this->date_creation).
"'";
481 $sql .=
", ".((int) $user->id);
482 $sql .=
", ".($this->date_shipping > 0 ?
"'".$this->db->idate($this->date_shipping).
"'" :
"null");
483 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
484 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
485 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
486 $sql .=
", ".($this->fk_delivery_address > 0 ? ((int) $this->fk_delivery_address) :
"null");
487 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
488 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
489 $sql .=
", ".(is_numeric($this->weight) ? (float) $this->weight :
'NULL');
490 $sql .=
", ".(is_numeric($this->sizeS) ? (float) $this->sizeS :
'NULL');
491 $sql .=
", ".(is_numeric($this->sizeW) ? (float) $this->sizeW :
'NULL');
492 $sql .=
", ".(is_numeric($this->sizeH) ? (float) $this->sizeH :
'NULL');
493 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
494 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
495 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
496 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
497 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
498 $sql .=
", ".((int) $this->fk_incoterms);
499 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
500 $sql .=
", ".((int) $this->signed_status);
503 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
504 $resql = $this->db->query($sql);
506 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
509 $initialref =
'(PROV'.$this->id.
')';
510 if (!empty($this->
ref)) {
511 $initialref = $this->ref;
514 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
515 $sql .=
" SET ref = '".$this->db->escape($initialref).
"'";
516 $sql .=
" WHERE rowid = ".((int) $this->
id);
518 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
519 if ($this->db->query($sql)) {
520 $this->
ref = $initialref;
522 $num = count($this->lines);
523 $kits_list = array();
525 for ($i = 0; $i < $num; $i++) {
527 $objectsrc->fetch($this->lines[$i]->origin_line_id);
528 if ($this->lines[$i]->product_type ==
"9" && $objectsrc->special_code == SUBTOTALS_SPECIAL_CODE) {
529 if ($this->
create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->rang, $this->lines[$i]->array_options) <= 0) {
536 $line = $this->lines[$i];
537 if ($line->fk_product > 0) {
543 if (!isset($kits_list[$line->fk_elementdet])) {
544 if (!is_object($line->product)) {
545 $line_product =
new Product($this->db);
546 $result = $line_product->fetch($line->fk_product,
'',
'',
'', 1, 1, 1);
551 $line_product = $line->product;
555 $line_product->get_sousproduits_arbo();
556 $prods_arbo = $line_product->get_arbo_each_prod($line->qty);
557 if (count($prods_arbo) > 0) {
558 $kits_list[$line->fk_elementdet] = array(
559 'arbo' => $prods_arbo,
560 'total_qty' => $line->qty,
564 $kits_list[$line->fk_elementdet][
'total_qty'] += $line->qty;
570 $kits_id_cached = array();
571 $sub_kits_id_cached = array();
572 $sub_parents_cached = array();
573 for ($i = 0; $i < $num; $i++) {
574 $line = $this->lines[$i];
577 if (!isset($kits_id_cached[$line->fk_elementdet])) {
578 if (!isset($line->detail_batch) || (isset($kits_list[$line->fk_elementdet]) && !
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE'))) {
579 $qty = isset($kits_list[$line->fk_elementdet]) ? $kits_list[$line->fk_elementdet][
'total_qty'] : $line->qty;
580 $warehouse_id = (isset($kits_list[$line->fk_elementdet]) && !
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) ? 0 : $line->entrepot_id;
581 $line_id = $this->
create_line($warehouse_id, $line->origin_line_id, $qty, $line->rang, $line->array_options, 0, $line->fk_product);
585 if (isset($kits_list[$line->fk_elementdet])) {
586 $kits_id_cached[$line->fk_elementdet] = $line_id;
594 $line_id = $kits_id_cached[$line->fk_elementdet];
598 if (isset($kits_list[$line->fk_elementdet]) && !
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) {
599 $prods_arbo = $kits_list[$line->fk_elementdet][
'arbo'];
602 $parent_line_id = $line_id;
604 $product_child_id = 0;
605 foreach ($prods_arbo as $index => $product_child_arr) {
620 $product_child_level = (int) $product_child_arr[
'level'];
621 $product_child_incdec = !empty($product_child_arr[
'incdec']);
624 if ($product_child_level != $level_last) {
625 $parent_line_id = $line_id;
626 $parent_product_id = $product_child_id;
627 if (isset($sub_parents_cached[$line->fk_elementdet][$parent_product_id])) {
628 $parent_line_id = $sub_parents_cached[$line->fk_elementdet][$parent_product_id];
630 $sub_parents_cached[$line->fk_elementdet][$parent_product_id] = $parent_line_id;
636 $next_level = $product_child_level;
637 $next_index = $index + 1;
638 if (isset($prods_arbo[$next_index])) {
639 $next_level = (int) $prods_arbo[$next_index][
'level'];
641 if ($next_level > $product_child_level) {
646 $product_child_id = (int) $product_child_arr[
'id'];
647 $product_child_qty = (float) $product_child_arr[
'nb_total'];
648 $warehouse_id = $line->entrepot_id;
649 if ($is_kit || !$product_child_incdec) {
650 if (!$product_child_incdec) {
651 $product_child_qty = 0;
657 if (!isset($sub_kits_id_cached[$line->fk_elementdet][$product_child_id]) || $warehouse_id > 0) {
658 $line_id = $this->
create_line($warehouse_id, ($parent_line_id ? 0 : $line->origin_line_id), $product_child_qty, $line->rang, $line->array_options, $parent_line_id, $product_child_id);
666 if (empty($warehouse_id)) {
667 $sub_kits_id_cached[$line->fk_elementdet][$product_child_id] = $line_id;
671 $level_last = $product_child_level;
677 if (!$error && $this->
id && $this->origin_id) {
684 if (!$error && $this->
id &&
getDolGlobalInt(
'SHIPPING_USE_ITS_OWN_CONTACTS') &&
getDolGlobalString(
'MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN') && !empty($this->origin_type) && !empty($this->origin_id)) {
685 $originforcontact = $this->origin_type;
686 $originidforcontact = $this->origin_id;
688 $sqlcontact =
"SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
689 $sqlcontact .=
" WHERE element_id = ".((int) $originidforcontact).
" AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$this->db->escape($originforcontact).
"'";
691 $resqlcontact = $this->db->query($sqlcontact);
693 while ($objcontact = $this->db->fetch_object($resqlcontact)) {
694 $this->
add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source);
709 if (!$error && !$notrigger) {
711 $result = $this->call_trigger(
'SHIPPING_CREATE', $user);
721 foreach ($this->errors as $errmsg) {
722 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
723 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
725 $this->db->rollback();
730 $this->db->rollback();
735 $this->error = $this->db->lasterror().
" - sql=$sql";
736 $this->db->rollback();
741 $this->error = $this->db->error().
" - sql=$sql";
742 $this->db->rollback();
760 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
766 $expeditionline->fk_expedition = $this->id;
767 $expeditionline->entrepot_id = $entrepot_id;
768 $expeditionline->fk_elementdet = $origin_line_id;
769 $expeditionline->element_type = $this->origin;
770 $expeditionline->fk_parent = $parent_line_id;
771 $expeditionline->fk_product = $product_id;
772 $expeditionline->qty = $qty;
773 $expeditionline->rang = $rang;
774 $expeditionline->array_options = $array_options;
776 if (!($expeditionline->fk_product > 0)) {
778 $order_line->fetch($expeditionline->fk_elementdet);
779 $expeditionline->fk_product = $order_line->fk_product;
782 if (($lineId = $expeditionline->insert($user)) < 0) {
783 $this->errors[] = $expeditionline->error;
801 $stockLocationQty = array();
803 $tab = $line_ext->detail_batch;
805 foreach ($tab as $detbatch) {
806 if (!empty($detbatch->fk_warehouse)) {
807 if (empty($stockLocationQty[$detbatch->fk_warehouse])) {
808 $stockLocationQty[$detbatch->fk_warehouse] = 0;
810 $stockLocationQty[$detbatch->fk_warehouse] += $detbatch->qty;
814 foreach ($stockLocationQty as $stockLocation => $qty) {
815 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
820 foreach ($tab as $detbatch) {
821 if ($detbatch->fk_warehouse == $stockLocation) {
822 if (!($detbatch->create($line_id) > 0)) {
823 $this->errors = $detbatch->errors;
847 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
852 if (empty($id) && empty($ref) && empty($ref_ext)) {
856 $sql =
"SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.fk_user_author, e.fk_statut, e.signed_status, e.fk_projet as fk_project, e.billed";
857 $sql .=
", e.date_valid";
858 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
859 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
860 $sql .=
", e.fk_shipping_method, e.tracking_number";
861 $sql .=
", e.note_private, e.note_public";
862 $sql .=
', e.fk_incoterms, e.location_incoterms';
863 $sql .=
', e.signed_status';
864 $sql .=
', i.libelle as label_incoterms';
865 $sql .=
', s.libelle as shipping_method';
866 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin_type";
867 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
868 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
869 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
870 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
871 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
873 $sql .=
" AND e.rowid = ".((int) $id);
876 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
879 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
882 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
883 $result = $this->db->query($sql);
885 if ($this->db->num_rows($result)) {
886 $obj = $this->db->fetch_object($result);
888 $this->
id = (int) $obj->rowid;
889 $this->entity = $obj->entity;
890 $this->
ref = $obj->ref;
891 $this->socid = $obj->socid;
892 $this->ref_customer = $obj->ref_customer;
893 $this->ref_ext = $obj->ref_ext;
894 $this->
status = $obj->fk_statut;
895 $this->statut = $this->status;
896 $this->signed_status = $obj->signed_status;
897 $this->user_author_id = $obj->fk_user_author;
898 $this->fk_user_author = $obj->fk_user_author;
899 $this->user_creation_id = $obj->fk_user_author;
900 $this->date_creation = $this->db->jdate($obj->date_creation);
901 $this->date_valid = $this->db->jdate($obj->date_valid);
902 $this->
date = $this->db->jdate($obj->date_expedition);
903 $this->date_expedition = $this->db->jdate($obj->date_expedition);
904 $this->date_shipping = $this->db->jdate($obj->date_expedition);
905 $this->date_delivery = $this->db->jdate($obj->date_delivery);
906 $this->fk_delivery_address = $obj->fk_address;
907 $this->model_pdf = $obj->model_pdf;
908 $this->shipping_method_id = $obj->fk_shipping_method;
909 $this->shipping_method = $obj->shipping_method;
910 $this->tracking_number = $obj->tracking_number;
911 $this->origin = ($obj->origin_type ? $obj->origin_type :
'commande');
912 $this->origin_type = ($obj->origin_type ? $obj->origin_type :
'commande');
913 $this->origin_id = $obj->origin_id;
914 $this->billed = $obj->billed;
915 $this->fk_project = $obj->fk_project;
916 $this->signed_status = $obj->signed_status;
917 $this->trueWeight = $obj->weight;
918 $this->weight_units = $obj->weight_units;
920 $this->trueWidth = $obj->width;
921 $this->width_units = $obj->size_units;
922 $this->trueHeight = $obj->height;
923 $this->height_units = $obj->size_units;
924 $this->trueDepth = $obj->size;
925 $this->depth_units = $obj->size_units;
927 $this->note_public = $obj->note_public;
928 $this->note_private = $obj->note_private;
931 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
932 $this->size_units = $obj->size_units;
935 $this->fk_incoterms = $obj->fk_incoterms;
936 $this->location_incoterms = $obj->location_incoterms;
937 $this->label_incoterms = $obj->label_incoterms;
939 $this->db->free($result);
952 if (!empty($this->multicurrency_code)) {
953 $this->multicurrency_code = $this->thirdparty->multicurrency_code;
955 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($this->thirdparty->multicurrency_tx)) {
956 $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
963 if (empty($obj->origin_id)) {
974 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
975 $this->error =
'Shipment with id '.$id.
' not found';
979 $this->error = $this->db->error();
991 public function valid($user, $notrigger = 0)
995 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1001 dol_syslog(get_class($this).
"::valid not in draft status", LOG_WARNING);
1005 if (!isset($this->socid)) {
1006 dol_syslog(get_class($this).
"::can't valid socid not set", LOG_WARNING);
1010 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'creer'))
1011 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'shipping_advance',
'validate')))) {
1012 $this->error =
'Permission denied';
1013 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
1022 $soc =
new Societe($this->db);
1023 $soc->fetch($this->socid);
1026 $result = $soc->setAsCustomer();
1029 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1030 $numref = $this->getNextNumRef($soc);
1031 } elseif (!empty($this->
ref)) {
1032 $numref = (string) $this->
ref;
1034 $numref =
"EXP".$this->id;
1041 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1042 $sql .=
" ref = '".$this->db->escape($numref).
"'";
1043 $sql .=
", fk_statut = 1";
1044 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
1045 $sql .=
", fk_user_valid = ".((int) $user->id);
1046 $sql .=
" WHERE rowid = ".((int) $this->
id);
1048 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
1049 $resql = $this->db->query($sql);
1051 $this->error = $this->db->lasterror();
1064 $triggerKey =
'SHIPPING_';
1065 if ($this->origin ==
'commande') {
1066 $triggerKey .=
'ORDER_SHIPMENTONPROCESS';
1068 $triggerKey .= strtoupper($this->origin).
'_SHIPMENTONPROCESS';
1077 if (!$error && !$notrigger) {
1079 $result = $this->call_trigger(
'SHIPPING_VALIDATE', $user);
1087 $this->oldref = $this->ref;
1090 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1092 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
1093 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
1094 $resql = $this->db->query($sql);
1097 $this->error = $this->db->lasterror();
1099 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
1100 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
1101 $resql = $this->db->query($sql);
1104 $this->error = $this->db->lasterror();
1110 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
1111 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
1112 if (!$error && file_exists($dirsource)) {
1113 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
1115 if (@rename($dirsource, $dirdest)) {
1118 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1119 foreach ($listoffiles as $fileentry) {
1120 $dirsource = $fileentry[
'name'];
1121 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1122 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1123 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1124 @rename($dirsource, $dirdest);
1133 $this->
ref = $numref;
1139 $this->db->commit();
1142 $this->db->rollback();
1159 if ($this->
status == self::STATUS_VALIDATED || $this->
status == self::STATUS_CLOSED) {
1161 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
1162 $delivery =
new Delivery($this->db);
1163 $result = $delivery->create_from_sending($user, $this->
id);
1188 public function addline($entrepot_id, $id, $qty, $array_options = [], $fk_product = 0, $fk_parent = 0)
1192 $num = count($this->lines);
1195 $line->entrepot_id = $entrepot_id;
1196 $line->origin_line_id = $id;
1197 $line->fk_elementdet = $id;
1198 $line->element_type =
'order';
1199 $line->fk_parent = $fk_parent;
1200 $line->fk_product = $fk_product;
1204 $orderline->fetch($id);
1207 $line->rang = $orderline->rang;
1208 $line->product_type = $orderline->product_type;
1209 if (!($line->fk_product > 0)) {
1210 $line->fk_product = $orderline->fk_product;
1213 if (
isModEnabled(
'stock') && !empty($orderline->fk_product)) {
1214 $product =
new Product($this->db);
1215 $product->fetch($orderline->fk_product);
1218 $langs->load(
"errors");
1219 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
1224 $productChildrenNb = 0;
1226 $productChildrenNb = $product->hasFatherOrChild(1);
1228 if ($productChildrenNb > 0) {
1229 $product_stock =
null;
1230 $product->loadStockForVirtualProduct(
'warehouseopen', $line->qty);
1231 if ($entrepot_id > 0) {
1232 if (isset($product->stock_warehouse[$entrepot_id])) {
1233 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
1236 foreach ($product->stock_warehouse as $componentStockWarehouse) {
1237 if ($product_stock ===
null) {
1238 $product_stock = $componentStockWarehouse->real;
1240 $product_stock = min($product_stock, $componentStockWarehouse->real);
1244 if ($product_stock ===
null) {
1249 if ($entrepot_id > 0) {
1250 $product->load_stock(
'warehouseopen');
1251 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
1253 $product_stock = $product->stock_reel;
1257 $product_type = $product->type;
1259 $isavirtualproduct = ($productChildrenNb > 0);
1264 || ($isavirtualproduct && !
getDolGlobalInt(
'STOCK_EXCLUDE_VIRTUAL_PRODUCTS'))
1267 if ($product->stockable_product == Product::ENABLED_STOCK && $product_stock < $qty) {
1268 $langs->load(
"errors");
1269 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
1270 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
1281 if (
isModEnabled(
'productbatch') && !empty($line->fk_product) && !empty($orderline->product_tobatch)) {
1282 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$line->fk_product;
1287 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1288 $line->array_options = $array_options;
1291 $this->lines[$num] = $line;
1309 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $array_options = [])
1311 global
$mysoc, $langs, $user;
1313 if ($this->
status == self::STATUS_DRAFT) {
1324 if ($ranktouse == -1) {
1325 $rangmax = $this->
line_max($fk_parent);
1326 $ranktouse = $rangmax + 1;
1331 $this->line->fk_expedition = $this->id;
1332 $this->line->element_type = $element_type;
1333 $this->line->fk_product = $fk_product;
1334 $this->line->description = $description;
1335 $this->line->desc = $description;
1336 $this->line->fk_parent = $fk_parent;
1337 $this->line->qty = (float) $qty;
1338 $this->line->fk_unit = $fk_unit;
1339 $this->line->rang = $ranktouse;
1341 if (is_array($array_options) && count($array_options) > 0) {
1342 $this->line->array_options = $array_options;
1345 $result = $this->line->insert($user);
1347 if (!isset($this->context[
'createfromclone'])) {
1348 if (!empty($fk_parent)) {
1350 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1351 $linecount = count($this->lines);
1352 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1356 $this->lines[] = $this->line;
1359 $this->db->commit();
1360 return $this->line->id;
1362 $this->error = $this->line->error;
1363 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1364 $this->db->rollback();
1368 dol_syslog(get_class($this).
"::addlinefree status of shipment must be Draft to allow use of ->addlinefree()", LOG_ERR);
1388 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $notrigger, $array_options = array())
1390 global
$mysoc, $langs, $user;
1392 if ($this->
status == self::STATUS_DRAFT) {
1402 $qty = (float) $qty;
1403 $description = trim($description);
1408 $line->fetch($rowid);
1409 $line->fetch_optionals();
1411 if (!empty($line->fk_product)) {
1412 $product =
new Product($this->db);
1413 $result = $product->fetch($line->fk_product);
1414 $product_type = $product->type;
1417 $staticline = clone $line;
1419 $line->oldline = $staticline;
1420 $this->line = $line;
1421 $this->line->context = $this->context;
1422 $this->line->rang = $rang;
1423 $this->line->fk_expedition = $this->id;
1424 $this->line->element_type = $element_type;
1425 $this->line->fk_product = $fk_product;
1426 $this->line->qty = $qty;
1427 $this->line->fk_unit = $fk_unit;
1428 $this->line->fk_parent = $fk_parent;
1429 $this->line->description = $description;
1431 if (is_array($array_options) && count($array_options) > 0) {
1433 foreach ($array_options as $key => $value) {
1434 $this->line->array_options[$key] = $array_options[$key];
1438 $result = $this->line->update($user, $notrigger);
1441 if (!empty($fk_parent)) {
1445 $this->db->commit();
1448 $this->error = $this->line->error;
1450 $this->db->rollback();
1454 $this->error = get_class($this).
"::updatelinefree Shipment status makes operation forbidden";
1455 $this->errors = array(
'ShipmentStatusMakeOperationForbidden');
1469 public function addline_batch($dbatch, $array_options = [], $origin_line =
null)
1474 $num = count($this->lines);
1476 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1479 foreach ($dbatch[
'detail'] as $key => $value) {
1480 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1486 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1491 $linebatch->qty = $value[
'q'];
1492 if ($linebatch->qty == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
1493 $linebatch->batch =
null;
1495 $tab[] = $linebatch;
1498 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1500 $prod_batch->fetch($value[
'id_batch']);
1502 if ($prod_batch->qty < $linebatch->qty) {
1503 $langs->load(
"errors");
1504 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1505 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1511 if (is_object($linebatch)) {
1512 $line->entrepot_id = $linebatch->fk_warehouse;
1514 $line->origin_line_id = $dbatch[
'ix_l'];
1515 $line->fk_elementdet = $dbatch[
'ix_l'];
1516 $line->qty = $dbatch[
'qty'];
1517 $line->detail_batch = $tab;
1518 if (!($line->rang > 0)) {
1519 $line->rang = $origin_line->rang;
1521 if (!($line->fk_product > 0)) {
1522 $line->fk_product = $origin_line->fk_product;
1526 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1527 $line->array_options = $array_options;
1531 $this->lines[$num] = $line;
1544 public function update($user =
null, $notrigger = 0)
1551 if (isset($this->
ref)) {
1552 $this->
ref = trim($this->
ref);
1554 if (isset($this->entity)) {
1555 $this->entity = (int) $this->entity;
1557 if (isset($this->ref_customer)) {
1558 $this->ref_customer = trim($this->ref_customer);
1560 if (isset($this->socid)) {
1561 $this->socid = (int) $this->socid;
1563 if (isset($this->fk_user_author)) {
1564 $this->fk_user_author = (int) $this->fk_user_author;
1566 if (isset($this->fk_user_valid)) {
1567 $this->fk_user_valid = (int) $this->fk_user_valid;
1569 if (isset($this->fk_delivery_address)) {
1570 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1572 if (isset($this->shipping_method_id)) {
1573 $this->shipping_method_id = (int) $this->shipping_method_id;
1575 if (isset($this->tracking_number)) {
1576 $this->tracking_number = trim($this->tracking_number);
1578 if (isset($this->statut)) {
1579 $this->statut = (int) $this->statut;
1581 if (isset($this->
status)) {
1584 if (isset($this->trueDepth)) {
1585 $this->trueDepth = trim($this->trueDepth);
1587 if (isset($this->trueWidth)) {
1588 $this->trueWidth = trim($this->trueWidth);
1590 if (isset($this->trueHeight)) {
1591 $this->trueHeight = trim($this->trueHeight);
1593 if (isset($this->size_units)) {
1594 $this->size_units = trim($this->size_units);
1596 if (isset($this->weight_units)) {
1597 $this->weight_units = (int) $this->weight_units;
1599 if (isset($this->trueWeight)) {
1600 $this->weight = trim((
string) $this->trueWeight);
1602 if (isset($this->note_private)) {
1603 $this->note_private = trim($this->note_private);
1605 if (isset($this->note_public)) {
1606 $this->note_public = trim($this->note_public);
1608 if (isset($this->model_pdf)) {
1609 $this->model_pdf = trim($this->model_pdf);
1611 if (!empty($this->date_expedition)) {
1612 $this->date_shipping = $this->date_expedition;
1619 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1620 $sql .=
" ref = ".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1621 $sql .=
" ref_ext = ".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1622 $sql .=
" ref_customer = ".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1623 $sql .=
" fk_soc = ".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1624 $sql .=
" date_creation = ".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1625 $sql .=
" fk_user_author = ".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
1626 $sql .=
" date_valid = ".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1627 $sql .=
" fk_user_valid = ".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1628 $sql .=
" date_expedition = ".(dol_strlen($this->date_shipping) != 0 ?
"'".$this->db->idate($this->date_shipping).
"'" :
'null').
",";
1629 $sql .=
" date_delivery = ".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1630 $sql .=
" fk_address = ".(isset($this->fk_delivery_address) ? ((int) $this->fk_delivery_address) :
"null").
",";
1631 $sql .=
" fk_shipping_method = ".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? ((
int) $this->shipping_method_id) :
"null").
",";
1632 $sql .=
" tracking_number = ".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1633 $sql .=
" fk_statut = ".(isset($this->
status) ? ((int) $this->
status) :
"null").
",";
1634 $sql .=
" fk_projet = ".(isset($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
1635 $sql .=
" height = ".(($this->trueHeight !=
'') ? ((
float) $this->trueHeight) :
"null").
",";
1636 $sql .=
" width = ".(($this->trueWidth !=
'') ? ((
float) $this->trueWidth) :
"null").
",";
1637 $sql .=
" size_units = ".(isset($this->size_units) ? ((int) $this->size_units) :
"null").
",";
1638 $sql .=
" size = ".(($this->trueDepth !=
'') ? ((
float) $this->trueDepth) :
"null").
",";
1639 $sql .=
" weight_units = ".(isset($this->weight_units) ? ((int) $this->weight_units) :
"null").
",";
1640 $sql .=
" weight = ".(($this->trueWeight !=
'') ? ((
float) $this->trueWeight) :
"null").
",";
1641 $sql .=
" note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1642 $sql .=
" note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1643 $sql .=
" model_pdf = ".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1644 $sql .=
" entity = ".((int) $conf->entity);
1645 $sql .=
" WHERE rowid = ".((int) $this->
id);
1649 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1650 $resql = $this->db->query($sql);
1653 $this->errors[] =
"Error ".$this->db->lasterror();
1664 if (!$error && !$notrigger) {
1666 $result = $this->call_trigger(
'SHIPPING_MODIFY', $user);
1675 foreach ($this->errors as $errmsg) {
1676 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1677 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1679 $this->db->rollback();
1682 $this->db->commit();
1696 public function cancel($user, $notrigger = 0, $also_update_stock =
false)
1698 global $conf, $langs, $user;
1700 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1709 if (isset($this->linkedObjectsIds[
'delivery']) && count($this->linkedObjectsIds[
'delivery']) > 0) {
1710 $this->error =
'ErrorThereIsSomeDeliveries';
1714 if (!$error && !$notrigger) {
1716 $result = $this->call_trigger(
'SHIPPING_CANCEL', $user);
1726 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
status == self::STATUS_CLOSED && $also_update_stock));
1728 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1730 $langs->load(
"agenda");
1734 $sql .=
" ed.fk_product";
1735 $sql .=
", ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1736 $sql .=
", SUM(".$this->db->ifsql(
"pa.rowid IS NOT NULL",
"1",
"0").
") as iskit";
1737 $sql .=
", ".$this->db->ifsql(
"pai.incdec IS NULL",
"1",
"pai.incdec").
" as incdec";
1738 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet as ed";
1739 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pa ON pa.fk_product_pere = ed.fk_product";
1740 $sql .=
" LEFT JOIN ".$this->db->prefix().
"expeditiondet as edp ON edp.rowid = ed.fk_parent";
1741 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pai ON pai.fk_product_pere = edp.fk_product AND pai.fk_product_fils = ed.fk_product";
1742 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1743 $sql .=
" GROUP BY ed.fk_product, ed.qty, ed.fk_entrepot, ed.rowid, pai.incdec";
1744 $sql .= $this->db->order(
"ed.rowid",
"DESC");
1746 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1747 $resql = $this->db->query($sql);
1749 $cpt = $this->db->num_rows($resql);
1753 for ($i = 0; $i < $cpt; $i++) {
1754 dol_syslog(get_class($this).
"::delete movement index ".$i);
1755 $obj = $this->db->fetch_object($resql);
1756 $line_id = (int) $obj->expeditiondet_id;
1758 if ($can_update_stock && (empty($obj->iskit) ||
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) && !empty($obj->incdec)) {
1761 $mouvS->origin =
'';
1765 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1766 if (!is_array($lotArray)) {
1768 $this->errors[] =
"Error ".$this->db->lasterror();
1772 if (empty($lotArray)) {
1776 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref),
'',
'',
'',
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
1779 $this->errors = array_merge($this->errors, $mouvS->errors);
1785 foreach ($lotArray as $lot) {
1786 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, (
string) $lot->batch,
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
1789 $this->errors = array_merge($this->errors, $mouvS->errors);
1802 $res = $shipment_line->fetch($line_id);
1804 $result = $shipment_line->delete($user);
1807 $this->errors[] =
"Error ".$shipment_line->errorsToString();
1811 $this->errors[] =
"Error ".$shipment_line->errorsToString();
1821 $this->errors[] =
"Error ".$this->db->lasterror();
1834 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"expedition";
1835 $sql .=
" WHERE rowid = ".((int) $this->
id);
1837 if ($this->db->query($sql)) {
1838 if (!empty($this->origin) && $this->origin_id > 0) {
1841 '@phan-var-force Facture|Commande $origin_object';
1852 $this->db->commit();
1856 if (!empty($conf->expedition->dir_output)) {
1857 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1858 $file = $dir.
'/'.$ref.
'.pdf';
1859 if (file_exists($file)) {
1864 if (file_exists($dir)) {
1866 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1874 $this->error = $this->db->lasterror().
" - sql=$sql";
1875 $this->db->rollback();
1879 $this->db->rollback();
1883 $this->db->rollback();
1897 public function delete($user =
null, $notrigger = 0, $also_update_stock =
false)
1899 global $conf, $langs;
1905 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1914 if (isset($this->linkedObjectsIds[
'delivery']) && count($this->linkedObjectsIds[
'delivery']) > 0) {
1915 $this->error =
'ErrorThereIsSomeDeliveries';
1919 if (!$error && !$notrigger) {
1921 $result = $this->call_trigger(
'SHIPPING_DELETE', $user);
1931 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
status == self::STATUS_CLOSED && $also_update_stock));
1933 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1935 $langs->load(
"agenda");
1942 $sql .=
" ed.fk_product";
1943 $sql .=
", ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1944 $sql .=
", SUM(".$this->db->ifsql(
"pa.rowid IS NOT NULL",
"1",
"0").
") as iskit";
1945 $sql .=
", ".$this->db->ifsql(
"pai.incdec IS NULL",
"1",
"pai.incdec").
" as incdec";
1946 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet as ed";
1947 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pa ON pa.fk_product_pere = ed.fk_product";
1948 $sql .=
" LEFT JOIN ".$this->db->prefix().
"expeditiondet as edp ON edp.rowid = ed.fk_parent";
1949 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pai ON pai.fk_product_pere = edp.fk_product AND pai.fk_product_fils = ed.fk_product";
1950 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1951 $sql .=
" GROUP BY ed.fk_product, ed.qty, ed.fk_entrepot, ed.rowid, pai.incdec";
1952 $sql .= $this->db->order(
"ed.rowid",
"DESC");
1954 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1955 $resql = $this->db->query($sql);
1957 $cpt = $this->db->num_rows($resql);
1958 for ($i = 0; $i < $cpt; $i++) {
1959 dol_syslog(get_class($this).
"::delete movement index ".$i);
1960 $obj = $this->db->fetch_object($resql);
1961 $line_id = (int) $obj->expeditiondet_id;
1963 if ($can_update_stock && (empty($obj->iskit) ||
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) && !empty($obj->incdec)) {
1966 $mouvS->origin =
'';
1968 $lotArray = $shipmentlinebatch->fetchAll($line_id);
1969 if (!is_array($lotArray)) {
1971 $this->errors[] =
"Error ".$this->db->lasterror();
1973 if (empty($lotArray)) {
1977 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref),
'',
'',
'',
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
1980 $this->errors = array_merge($this->errors, $mouvS->errors);
1986 foreach ($lotArray as $lot) {
1987 if (empty($lot->qty)) {
1990 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, (
string) $lot->batch,
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
1993 $this->errors = array_merge($this->errors, $mouvS->errors);
2006 $res = $shipment_line->fetch($line_id);
2008 $result = $shipment_line->delete($user);
2011 $this->errors[] =
"Error ".$shipment_line->errorsToString();
2015 $this->errors[] =
"Error ".$shipment_line->errorsToString();
2025 $this->errors[] =
"Error ".$this->db->lasterror();
2050 $sql =
"DELETE FROM ".$this->db->prefix().
"expedition";
2051 $sql .=
" WHERE rowid = ".((int) $this->
id);
2053 if ($this->db->query($sql)) {
2054 if (!empty($this->origin) && $this->origin_id > 0) {
2057 '@phan-var-force Facture|Commande $origin_object';
2067 $this->db->commit();
2075 if (!empty($conf->expedition->dir_output)) {
2076 $dir = $conf->expedition->dir_output .
'/sending/' . $ref;
2077 $file = $dir .
'/' . $ref .
'.pdf';
2078 if (file_exists($file)) {
2083 if (file_exists($dir)) {
2085 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
2093 $this->error = $this->db->lasterror().
" - sql=$sql";
2094 $this->db->rollback();
2098 $this->db->rollback();
2102 $this->db->rollback();
2118 $this->lines = array();
2123 $sql =
"SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked, cd.product_type, cd.fk_unit";
2124 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
2125 $sql .=
", cd.fk_remise_except, cd.fk_product_fournisseur_price as fk_fournprice";
2126 $sql .=
", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.info_bits, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
2127 $sql .=
", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang, cd.date_start, cd.date_end, cd.special_code";
2128 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_element, ed.fk_elementdet, ed.element_type, ed.fk_entrepot, ed.extraparams";
2129 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
2130 $sql .=
", p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units";
2131 $sql .=
", p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy";
2132 $sql .=
", p.tobatch as product_tobatch, p.stockable_product";
2133 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
2134 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
2135 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2136 $sql .=
" AND ed.fk_elementdet = cd.rowid";
2137 $sql .=
" ORDER BY cd.rang, ed.fk_elementdet";
2139 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
2140 $resql = $this->db->query($sql);
2142 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2144 $num = $this->db->num_rows($resql);
2150 $this->total_ht = 0;
2151 $this->total_tva = 0;
2152 $this->total_ttc = 0;
2153 $this->total_localtax1 = 0;
2154 $this->total_localtax2 = 0;
2156 $this->multicurrency_total_ht = 0;
2157 $this->multicurrency_total_tva = 0;
2158 $this->multicurrency_total_ttc = 0;
2164 $obj = $this->db->fetch_object($resql);
2166 if ($originline > 0 && $originline == $obj->fk_elementdet) {
2168 $line->entrepot_id = 0;
2169 $line->qty_shipped += $obj->qty_shipped;
2172 $line->entrepot_id = $obj->fk_entrepot;
2173 $line->qty_shipped = $obj->qty_shipped;
2177 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
2178 $detail_entrepot->qty_shipped = $obj->qty_shipped;
2179 $detail_entrepot->line_id = $obj->line_id;
2180 $line->details_entrepot[] = $detail_entrepot;
2182 $line->line_id = $obj->line_id;
2183 $line->rowid = $obj->line_id;
2184 $line->id = $obj->line_id;
2186 $line->fk_origin =
'orderline';
2188 $line->fk_element = $obj->fk_element;
2189 $line->origin_id = $obj->fk_element;
2190 $line->fk_elementdet = $obj->fk_elementdet;
2191 $line->origin_line_id = $obj->fk_elementdet;
2192 $line->element_type = $obj->element_type;
2194 $line->fk_expedition = $this->id;
2196 $line->stockable_product = $obj->stockable_product;
2197 $line->product_type = $obj->product_type;
2198 $line->fk_product = $obj->fk_product;
2199 $line->fk_product_type = $obj->fk_product_type;
2200 $line->ref = $obj->product_ref;
2201 $line->product_ref = $obj->product_ref;
2202 $line->product_label = $obj->product_label;
2203 $line->libelle = $obj->product_label;
2204 $line->product_barcode = $obj->product_barcode;
2205 $line->product_tosell = $obj->product_tosell;
2206 $line->product_tobuy = $obj->product_tobuy;
2207 $line->product_tobatch = $obj->product_tobatch;
2208 $line->fk_fournprice = $obj->fk_fournprice;
2209 $line->label = $obj->custom_label;
2210 $line->description = $obj->description;
2211 $line->qty_asked = $obj->qty_asked;
2212 $line->rang = $obj->rang;
2213 $line->weight = $obj->weight;
2214 $line->weight_units = $obj->weight_units;
2215 $line->length = $obj->length;
2216 $line->length_units = $obj->length_units;
2217 $line->width = $obj->width;
2218 $line->width_units = $obj->width_units;
2219 $line->height = $obj->height;
2220 $line->height_units = $obj->height_units;
2221 $line->surface = $obj->surface;
2222 $line->surface_units = $obj->surface_units;
2223 $line->volume = $obj->volume;
2224 $line->volume_units = $obj->volume_units;
2225 $line->stockable_product = $obj->stockable_product;
2226 $line->fk_unit = $obj->fk_unit;
2228 $line->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
2230 $line->pa_ht = $obj->pa_ht;
2233 $localtax_array = array(0 => $obj->localtax1_type, 1 => $obj->localtax1_tx, 2 => $obj->localtax2_type, 3 => $obj->localtax2_tx);
2234 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
2235 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
2238 $tabprice =
calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $localtax1_tx, $localtax2_tx, 0,
'HT', $obj->info_bits, $obj->fk_product_type,
$mysoc, $localtax_array);
2239 $line->desc = $obj->description;
2240 $line->qty = $line->qty_shipped;
2241 $line->total_ht = (float) $tabprice[0];
2242 $line->total_localtax1 = (float) $tabprice[9];
2243 $line->total_localtax2 = (float) $tabprice[10];
2244 $line->total_ttc = (float) $tabprice[2];
2245 $line->total_tva = (float) $tabprice[1];
2246 $line->vat_src_code = $obj->vat_src_code;
2247 $line->tva_tx = $obj->tva_tx;
2248 $line->localtax1_tx = $obj->localtax1_tx;
2249 $line->localtax2_tx = $obj->localtax2_tx;
2250 $line->info_bits = $obj->info_bits;
2251 $line->price = $obj->price;
2252 $line->subprice = $obj->subprice;
2253 $line->fk_remise_except = $obj->fk_remise_except;
2254 $line->remise_percent = $obj->remise_percent;
2256 $this->total_ht += $tabprice[0];
2257 $this->total_tva += $tabprice[1];
2258 $this->total_ttc += $tabprice[2];
2259 $this->total_localtax1 += $tabprice[9];
2260 $this->total_localtax2 += $tabprice[10];
2262 $line->date_start = $this->db->jdate($obj->date_start);
2263 $line->date_end = $this->db->jdate($obj->date_end);
2265 $line->special_code = $obj->special_code;
2268 $this->fk_multicurrency = $obj->fk_multicurrency;
2269 $this->multicurrency_code = $obj->multicurrency_code;
2270 $line->multicurrency_subprice = $obj->multicurrency_subprice;
2271 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
2272 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
2273 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
2275 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
2276 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
2277 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
2279 if ($originline != $obj->fk_elementdet) {
2280 $line->detail_batch = array();
2284 if (
isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
2285 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
2287 if (is_array($newdetailbatch)) {
2288 if ($originline != $obj->fk_elementdet) {
2289 $line->detail_batch = $newdetailbatch;
2291 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
2298 $detail_children = array();
2299 $line_child_list = array();
2300 $res = $line->findAllChild($line->id, $line_child_list, 1);
2302 foreach ($line_child_list as $child_line) {
2303 foreach ($child_line as $child_obj) {
2304 $child_product_id = (int) $child_obj->fk_product;
2305 $child_warehouse_id = (int) $child_obj->fk_warehouse;
2307 if ($child_warehouse_id > 0) {
2309 if (!isset($detail_children[$child_product_id])) {
2310 $detail_children[$child_product_id] = array();
2312 if (!isset($detail_children[$child_product_id][$child_warehouse_id])) {
2313 $detail_children[$child_product_id][$child_warehouse_id] = 0;
2315 $detail_children[$child_product_id][$child_warehouse_id] += $child_obj->qty;
2320 $line->detail_children = $detail_children;
2323 $line->fetch_optionals();
2325 if ($originline != $obj->fk_elementdet) {
2326 $this->lines[$lineindex] = $line;
2329 $line->total_ht += $tabprice[0];
2330 $line->total_localtax1 += $tabprice[9];
2331 $line->total_localtax2 += $tabprice[10];
2332 $line->total_ttc += $tabprice[2];
2333 $line->total_tva += $tabprice[1];
2337 $originline = $obj->fk_elementdet;
2339 $this->db->free($resql);
2342 $this->error = $this->db->error();
2359 $this->lines = array();
2361 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_product, ed.fk_unit, ed.description, ed.fk_elementdet, ed.fk_element, ed.element_type, ed.qty, ed.rang';
2362 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as ed';
2363 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = ed.fk_product)';
2364 $sql .=
' WHERE ed.fk_expedition = '.((int) $this->
id);
2365 $sql .=
' ORDER BY ed.rang, ed.rowid';
2367 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
2368 $result = $this->db->query($sql);
2370 $num = $this->db->num_rows($result);
2374 $objp = $this->db->fetch_object($result);
2378 $line->rowid = $objp->rowid;
2379 $line->id = $objp->rowid;
2380 $line->fk_expedition = $this->id;
2381 $line->description = $objp->description;
2382 $line->qty = $objp->qty;
2383 $line->fk_entrepot = $objp->fk_entrepot;
2384 $line->fk_product = $objp->fk_product;
2385 $line->rang = $objp->rang;
2386 $line->fk_element = $objp->fk_element;
2387 $line->fk_unit = $objp->fk_unit;
2388 $line->fk_elementdet = $objp->fk_elementdet;
2389 $line->fk_element_type = $objp->element_type;
2390 $line->fetch_optionals();
2392 $this->lines[$i] = $line;
2397 $this->db->free($result);
2401 $this->error = $this->db->error();
2427 if ($this->
status == self::STATUS_DRAFT) {
2433 $line->fetch($lineid);
2435 if ($line->delete($user) > 0) {
2438 $this->db->commit();
2441 $this->db->rollback();
2445 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
2459 global $conf, $langs;
2461 $langs->load(
'sendings');
2463 $nofetch = !empty($params[
'nofetch']);
2466 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
2467 if (isset($this->
status)) {
2468 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
2470 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2471 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
2473 $langs->load(
'companies');
2474 if (empty($this->thirdparty)) {
2477 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
2494 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
2496 global $langs, $hookmanager;
2501 'objecttype' => $this->element,
2502 'option' => $option,
2505 $classfortooltip =
'classfortooltip';
2508 $classfortooltip =
'classforajaxtooltip';
2509 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2515 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
2521 if ($option !==
'nolink') {
2523 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2524 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2525 $add_save_lastsearch_values = 1;
2527 if ($add_save_lastsearch_values) {
2528 $url .=
'&save_lastsearch_values=1';
2533 if (empty($notooltip)) {
2535 $label = $langs->trans(
"Shipment");
2536 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2538 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2539 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2542 $linkstart =
'<a href="'.$url.
'"';
2543 $linkstart .= $linkclose.
'>';
2546 $result .= $linkstart;
2548 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2550 if ($withpicto != 2) {
2551 $result .= $this->ref;
2553 $result .= $linkend;
2555 $hookmanager->initHooks(array($this->element .
'dao'));
2556 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
2557 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2559 $result = $hookmanager->resPrint;
2561 $result .= $hookmanager->resPrint;
2590 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
2591 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
2593 $statusType =
'status'.$status;
2594 if ($status == self::STATUS_VALIDATED) {
2595 $statusType =
'status4';
2597 if ($status == self::STATUS_CLOSED) {
2598 $statusType =
'status6';
2600 if ($status == self::STATUS_CANCELED) {
2601 $statusType =
'status9';
2605 $status_label = $this->signed_status ? $labelStatus . $signed_label : $labelStatus;
2606 $status_label_short = $this->signed_status ? $labelStatusShort . $signed_label : $labelStatusShort;
2608 return dolGetStatus($status_label, $status_label_short,
'', $statusType, $mode);
2620 global $langs, $conf;
2622 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2624 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2625 $return .=
'<div class="info-box info-box-sm">';
2626 $return .=
'<div class="info-box-icon bg-infobox-action">';
2628 $return .=
'</div>';
2629 $return .=
'<div class="info-box-content">';
2630 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
2631 if ($selected >= 0) {
2632 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2634 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2635 $return .=
'<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1,
getDolCurrency()).
' '.$langs->trans(
'HT').
'</div>';
2636 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2637 $return .=
'</div>';
2638 $return .=
'</div>';
2639 $return .=
'</div>';
2657 dol_syslog(get_class($this).
"::initAsSpecimen");
2660 $order->initAsSpecimen();
2664 $this->
ref =
'SPECIMEN';
2665 $this->specimen = 1;
2667 $this->livraison_id = 0;
2669 $this->date_creation = $now;
2670 $this->date_valid = $now;
2671 $this->date_delivery = $now + 24 * 3600;
2672 $this->date_expedition = $now + 24 * 3600;
2674 $this->entrepot_id = 0;
2675 $this->fk_delivery_address = 0;
2678 $this->commande_id = 0;
2679 $this->commande = $order;
2681 $this->origin_id = 1;
2682 $this->origin_type =
'commande';
2684 $this->note_private =
'Private note';
2685 $this->note_public =
'Public note';
2689 while ($xnbp < $nbp) {
2691 $line->product_desc = $langs->trans(
"Description").
" ".$xnbp;
2692 $line->product_label = $langs->trans(
"Description").
" ".$xnbp;
2694 $line->qty_asked = 5;
2695 $line->qty_shipped = 4;
2696 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
2698 $line->weight = 1.123456;
2699 $line->weight_units = 0;
2701 $line->volume = 2.34567;
2702 $line->volume_unit = 0;
2704 $this->lines[] = $line;
2735 if ($user->hasRight(
'expedition',
'creer')) {
2736 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2737 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2738 $sql .=
" WHERE rowid = ".((int) $this->
id);
2740 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2741 $resql = $this->db->query($sql);
2743 $this->date_delivery = $delivery_date;
2746 $this->error = $this->db->error();
2763 if ($user->hasRight(
'expedition',
'creer')) {
2764 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2765 $sql .=
" SET date_expedition = ".($shipping_date ?
"'".$this->db->idate($shipping_date).
"'" :
'null');
2766 $sql .=
" WHERE rowid = ".((int) $this->
id);
2768 dol_syslog(get_class($this).
"::setShippingDate", LOG_DEBUG);
2769 $resql = $this->db->query($sql);
2771 $this->date_shipping = $shipping_date;
2774 $this->error = $this->db->error();
2794 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2795 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2796 $sql .=
" WHERE em.active = 1";
2797 $sql .=
" ORDER BY em.libelle ASC";
2799 $resql = $this->db->query($sql);
2801 while ($obj = $this->db->fetch_object($resql)) {
2802 $label = $langs->trans(
'SendingMethod'.$obj->code);
2803 $this->meths[(int) $obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2820 $this->listmeths = [];
2823 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2824 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2826 $sql .=
" WHERE em.rowid=".((int) $id);
2829 $resql = $this->db->query($sql);
2831 while ($obj = $this->db->fetch_object($resql)) {
2832 $label = $langs->trans(
'SendingMethod'.$obj->code);
2833 $this->listmeths[$i] = [
2834 'rowid' => (int) $obj->rowid,
2835 'code' => $obj->code,
2836 'libelle' => ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label),
2837 'description' => $obj->description,
2838 'tracking' => $obj->tracking,
2839 'active' => (
int) $obj->active,
2855 if (!empty($this->shipping_method_id)) {
2856 $sql =
"SELECT em.code, em.tracking";
2857 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2858 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2860 $resql = $this->db->query($sql);
2862 if ($obj = $this->db->fetch_object($resql)) {
2863 $tracking = (string) $obj->tracking;
2868 if (!empty($tracking) && !empty($value)) {
2869 $url = str_replace(
'{TRACKID}', $value, $tracking);
2870 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, $value);
2872 $this->tracking_url = $value;
2888 if ($this->
status == self::STATUS_CLOSED) {
2895 if (empty($this->date_shipping)) {
2896 $sql .=
", date_expedition = '".$this->db->escape($this->db->idate(
dol_now())).
"'";
2898 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
2900 $resql = $this->db->query($sql);
2903 if ($this->origin_type ==
'commande' && $this->origin_id > 0) {
2905 $order->fetch($this->origin_id);
2907 $order->loadExpeditions(self::STATUS_CLOSED);
2909 $shipments_match_order = 1;
2910 foreach ($order->lines as $line) {
2911 $lineid = $line->id;
2913 if (($line->product_type == 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) {
2914 $shipments_match_order = 0;
2915 $text =
'Qty for order line id '.$lineid.
' is '.$qty.
'. However in the shipments with status Expedition::STATUS_CLOSED='.self::STATUS_CLOSED.
' we have qty = '.$order->expeditions[$lineid].
', so we can t close order';
2920 if ($shipments_match_order) {
2921 dol_syslog(
"Qty for the ".count($order->lines).
" lines of the origin order is same than qty for lines in the shipment we close (shipments_match_order is true), with new status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.
', so we close order');
2923 $order->cloture($user);
2941 $result = $this->call_trigger(
'SHIPPING_CLOSED', $user);
2952 $this->db->commit();
2958 $this->db->rollback();
2977 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
2979 $langs->load(
"agenda");
2983 $sql .=
" ed.rowid as edid, ed.fk_product, ed.qty, ed.fk_entrepot";
2984 $sql .=
", cd.rowid as cdid";
2985 $sql .=
", cd.subprice";
2986 $sql .=
", edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2988 $sql .=
" FROM " . $this->db->prefix() .
"expeditiondet as ed";
2989 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"commandedet as cd ON cd.rowid = ed.fk_elementdet";
2990 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2991 $sql .=
" INNER JOIN " . $this->db->prefix() .
"expedition as e ON ed.fk_expedition = e.rowid";
2992 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
2995 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
2996 $resql = $this->db->query($sql);
2998 $cpt = $this->db->num_rows($resql);
2999 for ($i = 0; $i < $cpt; $i++) {
3000 $obj = $this->db->fetch_object($resql);
3001 if (empty($obj->edbrowid)) {
3004 $qty = $obj->edbqty;
3006 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
3009 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->edid .
" edb.rowid=" . $obj->edbrowid);
3012 $mouvS->origin = &$this;
3013 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
3015 if (empty($obj->edbrowid)) {
3019 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref));
3029 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref),
'', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
3039 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".$this->db->prefix().
"product_batch as pb)";
3040 $resqldelete = $this->db->query($sqldelete);
3044 $this->error = $this->db->lasterror();
3045 $this->errors[] = $this->db->lasterror();
3068 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET billed = 1';
3069 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
3071 $resql = $this->db->query($sql);
3076 $result = $this->call_trigger(
'SHIPPING_BILLED', $user);
3083 $this->errors[] = $this->db->lasterror;
3086 if (empty($error)) {
3087 $this->db->commit();
3090 $this->db->rollback();
3105 if ($this->
status <= self::STATUS_DRAFT) {
3109 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
3119 global $langs, $user;
3124 if ($this->
status == self::STATUS_VALIDATED) {
3130 $oldbilled = $this->billed;
3132 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
3133 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
3135 $resql = $this->db->query($sql);
3143 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
3145 $langs->load(
"agenda");
3149 $sql =
"SELECT cd.fk_product, cd.subprice,";
3150 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
3151 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
3152 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
3153 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
3154 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
3155 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
3156 $sql .=
" AND cd.rowid = ed.fk_elementdet";
3158 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
3159 $resql = $this->db->query($sql);
3161 $cpt = $this->db->num_rows($resql);
3162 for ($i = 0; $i < $cpt; $i++) {
3163 $obj = $this->db->fetch_object($resql);
3164 if (empty($obj->edbrowid)) {
3167 $qty = $obj->edbqty;
3172 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
3176 $mouvS->origin = &$this;
3177 $mouvS->setOrigin($this->element, $this->
id);
3179 if (empty($obj->edbrowid)) {
3183 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
3193 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref),
'', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
3202 $this->error = $this->db->lasterror();
3209 $result = $this->call_trigger(
'SHIPPING_REOPEN', $user);
3216 $this->errors[] = $this->db->lasterror();
3220 $this->db->commit();
3225 $this->billed = $oldbilled;
3226 $this->db->rollback();
3242 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3244 $outputlangs->load(
"products");
3249 if (!empty($this->model_pdf)) {
3250 $modele = $this->model_pdf;
3256 $modelpath =
"core/modules/expedition/doc/";
3260 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_VALIDATED
Validated status.
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
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=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
deleteExtraFields()
Delete all extra fields values for the current object.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
errorsToString()
Method to output saved errors.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch_origin()
Read linked origin object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage receptions.
Class to manage Dolibarr database access.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1)
Return clickable link of object (with eventually picto)
addline_batch($dbatch, $array_options=[], $origin_line=null)
Add a shipment line with batch record.
create_delivery($user)
Create a delivery receipt from a shipment.
setDraft($user, $notrigger=0)
Set draft status.
const STATUS_SHIPMENT_IN_PROGRESS
Expedition in progress -> package exit the warehouse and is now in the truck or into the hand of the ...
getUrlTrackingStatus($value='')
Forge an set tracking url.
setClosed()
Classify the shipping as closed (this records also the stock movement)
__construct($db)
Constructor.
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a expedition line.
addline($entrepot_id, $id, $qty, $array_options=[], $fk_product=0, $fk_parent=0)
Add an expedition line.
create($user, $notrigger=0)
Create expedition en base.
LibStatut($status, $mode)
Return label of a status.
setBilled()
Classify the shipping as invoiced (used for example by trigger when WORKFLOW_SHIPPING_CLASSIFY_BILLED...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getTooltipContentArray($params)
getTooltipContentArray
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $array_options=[])
Add a simple expedition line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
setShippingDate($user, $shipping_date)
Set the shipping date.
const STATUS_DRAFT
Draft status.
const STATUS_CANCELED
Canceled status.
getLibStatut($mode=0)
Return status label.
set_date_livraison($user, $delivery_date)
Set delivery date.
initAsSpecimen()
Initialise an instance with random values.
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $notrigger, $array_options=array())
Update a simple expedition line.
const STATUS_CLOSED
Closed status -> parcel was received by customer / end of process prev status : validated or shipment...
const STATUS_VALIDATED
Validated status -> parcel is ready to be sent prev status : draft next status : closed or shipment_i...
create_line_batch($line_ext, $array_options=[])
Create the detail of the expedition line.
manageStockMvtOnEvt($user, $labelmovement='ShipmentClassifyClosedInDolibarr')
Manage Stock MVt onb Close or valid Shipment.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
update($user=null, $notrigger=0)
Update database.
fetch_lines_free()
Load lines of simple shipment.
fetch_delivery_methods()
Fetch deliveries method and return an array.
fetch($id, $ref='', $ref_ext='', $notused='')
Get object and lines from database.
reOpen()
Classify the shipping as validated/opened.
deleteLine($user, $lineid)
Delete detail line.
getLinesArray()
Create an array of shipment lines.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
Class to manage lines of shipment.
CRUD class for batch number management within shipment.
Class to manage stock movements.
Class to manage order lines.
Class to manage products or services.
const TYPE_SERVICE
Service.
Manage record for batch number management.
Class to manage third parties objects (customers, suppliers, prospects...)
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_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_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
$conf db user
Active Directory does not allow anonymous connections.