38require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
41if (isModEnabled(
"propal")) {
42 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
44if (isModEnabled(
'order')) {
45 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionlinebatch.class.php';
60 public $element =
"shipping";
65 public $fk_element =
"fk_expedition";
70 public $table_element =
"expedition";
75 public $table_element_line =
"expeditiondet";
80 public $picto =
'dolly';
86 public $fields = array();
91 public $user_author_id;
96 public $fk_user_author;
110 public $ref_customer;
120 public $tracking_number;
125 public $tracking_url;
134 public $weight_units;
138 public $height_units;
144 public $livraison_id;
149 public $multicurrency_subprice;
164 public $date_delivery;
182 public $date_shipping;
187 public $date_creation;
210 public $lines = array();
216 public $fk_multicurrency;
221 public $multicurrency_code;
222 public $multicurrency_tx;
223 public $multicurrency_total_ht;
224 public $multicurrency_total_tva;
225 public $multicurrency_total_ttc;
230 public $signed_status = 0;
291 $this->ismultientitymanaged = 1;
292 $this->isextrafieldmanaged = 1;
295 $this->labelStatus = array();
296 $this->labelStatus[-1] =
'StatusSendingCanceled';
297 $this->labelStatus[0] =
'StatusSendingDraft';
298 $this->labelStatus[1] =
'StatusSendingValidated';
299 $this->labelStatus[2] =
'StatusSendingProcessed';
302 $this->labelStatusShort = array();
303 $this->labelStatusShort[-1] =
'StatusSendingCanceledShort';
304 $this->labelStatusShort[0] =
'StatusSendingDraftShort';
305 $this->labelStatusShort[1] =
'StatusSendingValidatedShort';
306 $this->labelStatusShort[2] =
'StatusSendingProcessedShort';
317 global $langs, $conf;
318 $langs->load(
"sendings");
327 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
329 foreach ($dirmodels as $reldir) {
333 $mybool = ((bool) @include_once $dir.$file) || $mybool;
341 $obj =
new $classname();
343 $numref = $obj->getNextValue($soc, $this);
348 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
352 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
364 public function create($user, $notrigger = 0)
366 global $conf, $hookmanager;
370 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
375 if (empty($this->fk_project)) {
376 $this->fk_project = 0;
378 if (empty($this->date_shipping) && !empty($this->date_expedition)) {
386 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
389 $sql .=
", ref_customer";
391 $sql .=
", date_creation";
392 $sql .=
", fk_user_author";
393 $sql .=
", date_expedition";
394 $sql .=
", date_delivery";
396 $sql .=
", fk_projet";
397 $sql .=
", fk_address";
398 $sql .=
", fk_shipping_method";
399 $sql .=
", tracking_number";
404 $sql .=
", weight_units";
405 $sql .=
", size_units";
406 $sql .=
", note_private";
407 $sql .=
", note_public";
408 $sql .=
", model_pdf";
409 $sql .=
", fk_incoterms, location_incoterms";
410 $sql .=
") VALUES (";
412 $sql .=
", ".((int) $conf->entity);
413 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
414 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
415 $sql .=
", '".$this->db->idate($now).
"'";
416 $sql .=
", ".((int) $user->id);
417 $sql .=
", ".($this->date_shipping > 0 ?
"'".$this->db->idate($this->date_shipping).
"'" :
"null");
418 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
419 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
420 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
421 $sql .=
", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address :
"null");
422 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
423 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
424 $sql .=
", ".(is_numeric($this->weight) ? $this->weight :
'NULL');
425 $sql .=
", ".(is_numeric($this->sizeS) ? $this->sizeS :
'NULL');
426 $sql .=
", ".(is_numeric($this->sizeW) ? $this->sizeW :
'NULL');
427 $sql .=
", ".(is_numeric($this->sizeH) ? $this->sizeH :
'NULL');
428 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
429 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
430 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
431 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
432 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
433 $sql .=
", ".(int) $this->fk_incoterms;
434 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
437 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
438 $resql = $this->db->query($sql);
440 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
442 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
443 $sql .=
" SET ref = '(PROV".$this->id.
")'";
444 $sql .=
" WHERE rowid = ".((int) $this->
id);
446 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
447 if ($this->db->query($sql)) {
449 $num = count($this->lines);
450 for ($i = 0; $i < $num; $i++) {
452 if (!isset($this->lines[$i]->detail_batch)) {
453 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) {
457 if ($this->
create_line_batch($this->lines[$i], $this->lines[$i]->array_options) <= 0) {
464 if (!$error && $this->
id && $this->origin_id) {
479 if (!$error && !$notrigger) {
481 $result = $this->
call_trigger(
'SHIPPING_CREATE', $user);
491 foreach ($this->errors as $errmsg) {
492 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
493 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
495 $this->db->rollback();
500 $this->db->rollback();
505 $this->error = $this->db->lasterror().
" - sql=$sql";
506 $this->db->rollback();
511 $this->error = $this->db->error().
" - sql=$sql";
512 $this->db->rollback();
528 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [])
534 $expeditionline->fk_expedition = $this->id;
535 $expeditionline->entrepot_id = $entrepot_id;
536 $expeditionline->fk_elementdet = $origin_line_id;
537 $expeditionline->element_type = $this->origin;
538 $expeditionline->qty = $qty;
539 $expeditionline->rang = $rang;
540 $expeditionline->array_options = $array_options;
542 if (($lineId = $expeditionline->insert($user)) < 0) {
543 $this->errors[] = $expeditionline->error;
561 $stockLocationQty = array();
563 $tab = $line_ext->detail_batch;
565 foreach ($tab as $detbatch) {
566 if (!empty($detbatch->entrepot_id)) {
567 if (empty($stockLocationQty[$detbatch->entrepot_id])) {
568 $stockLocationQty[$detbatch->entrepot_id] = 0;
570 $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty;
574 foreach ($stockLocationQty as $stockLocation => $qty) {
575 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
580 foreach ($tab as $detbatch) {
581 if ($detbatch->entrepot_id == $stockLocation) {
582 if (!($detbatch->create($line_id) > 0)) {
583 $this->errors = $detbatch->errors;
607 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
612 if (empty($id) && empty($ref) && empty($ref_ext)) {
616 $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.fk_projet as fk_project, e.billed";
617 $sql .=
", e.date_valid";
618 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
619 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
620 $sql .=
", e.fk_shipping_method, e.tracking_number";
621 $sql .=
", e.note_private, e.note_public";
622 $sql .=
', e.fk_incoterms, e.location_incoterms';
623 $sql .=
', e.signed_status';
624 $sql .=
', i.libelle as label_incoterms';
625 $sql .=
', s.libelle as shipping_method';
626 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin_type";
627 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
628 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
629 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
630 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
631 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
633 $sql .=
" AND e.rowid = ".((int) $id);
636 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
639 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
642 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
643 $result = $this->db->query($sql);
645 if ($this->db->num_rows($result)) {
646 $obj = $this->db->fetch_object($result);
648 $this->
id = $obj->rowid;
649 $this->entity = $obj->entity;
650 $this->
ref = $obj->ref;
651 $this->socid = $obj->socid;
652 $this->ref_customer = $obj->ref_customer;
653 $this->ref_ext = $obj->ref_ext;
654 $this->
status = $obj->fk_statut;
655 $this->
statut = $this->status;
656 $this->user_author_id = $obj->fk_user_author;
657 $this->fk_user_author = $obj->fk_user_author;
658 $this->date_creation = $this->db->jdate($obj->date_creation);
659 $this->date_valid = $this->db->jdate($obj->date_valid);
660 $this->date = $this->db->jdate($obj->date_expedition);
661 $this->date_expedition = $this->db->jdate($obj->date_expedition);
662 $this->date_shipping = $this->db->jdate($obj->date_expedition);
663 $this->date_delivery = $this->db->jdate($obj->date_delivery);
664 $this->fk_delivery_address = $obj->fk_address;
665 $this->model_pdf = $obj->model_pdf;
666 $this->shipping_method_id = $obj->fk_shipping_method;
667 $this->shipping_method = $obj->shipping_method;
668 $this->tracking_number = $obj->tracking_number;
669 $this->origin = ($obj->origin_type ? $obj->origin_type :
'commande');
670 $this->origin_type = ($obj->origin_type ? $obj->origin_type :
'commande');
671 $this->origin_id = $obj->origin_id;
672 $this->billed = $obj->billed;
673 $this->fk_project = $obj->fk_project;
674 $this->signed_status = $obj->signed_status;
675 $this->trueWeight = $obj->weight;
676 $this->weight_units = $obj->weight_units;
678 $this->trueWidth = $obj->width;
679 $this->width_units = $obj->size_units;
680 $this->trueHeight = $obj->height;
681 $this->height_units = $obj->size_units;
682 $this->trueDepth = $obj->size;
683 $this->depth_units = $obj->size_units;
685 $this->note_public = $obj->note_public;
686 $this->note_private = $obj->note_private;
689 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
690 $this->size_units = $obj->size_units;
693 $this->fk_incoterms = $obj->fk_incoterms;
694 $this->location_incoterms = $obj->location_incoterms;
695 $this->label_incoterms = $obj->label_incoterms;
697 $this->db->free($result);
709 if (isModEnabled(
'multicurrency')) {
710 if (!empty($this->multicurrency_code)) {
711 $this->multicurrency_code = $this->thirdparty->multicurrency_code;
713 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($this->thirdparty->multicurrency_tx)) {
714 $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
728 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
729 $this->error =
'Shipment with id '.$id.
' not found';
733 $this->error = $this->db->error();
745 public function valid($user, $notrigger = 0)
749 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
755 dol_syslog(get_class($this).
"::valid not in draft status", LOG_WARNING);
759 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'creer'))
760 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'shipping_advance',
'validate')))) {
761 $this->error =
'Permission denied';
762 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
772 $soc->fetch($this->socid);
775 $result = $soc->setAsCustomer();
778 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
780 } elseif (!empty($this->
ref)) {
781 $numref = $this->ref;
783 $numref =
"EXP".$this->id;
790 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
791 $sql .=
" ref='".$this->db->escape($numref).
"'";
792 $sql .=
", fk_statut = 1";
793 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
794 $sql .=
", fk_user_valid = ".$user->id;
795 $sql .=
" WHERE rowid = ".((int) $this->
id);
797 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
798 $resql = $this->db->query($sql);
800 $this->error = $this->db->lasterror();
805 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT')) {
813 $triggerKey =
'SHIPPING_';
814 if ($this->origin ==
'commande') {
815 $triggerKey.=
'ORDER_SHIPMENTONPROCESS';
817 $triggerKey.= strtoupper($this->origin).
'_SHIPMENTONPROCESS';
826 if (!$error && !$notrigger) {
828 $result = $this->
call_trigger(
'SHIPPING_VALIDATE', $user);
836 $this->oldref = $this->ref;
839 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
841 $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).
"'";
842 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
843 $resql = $this->db->query($sql);
846 $this->error = $this->db->lasterror();
848 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
849 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
850 $resql = $this->db->query($sql);
853 $this->error = $this->db->lasterror();
859 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
860 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
861 if (!$error && file_exists($dirsource)) {
862 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
864 if (@rename($dirsource, $dirdest)) {
867 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
868 foreach ($listoffiles as $fileentry) {
869 $dirsource = $fileentry[
'name'];
870 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
871 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
872 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
873 @rename($dirsource, $dirdest);
882 $this->
ref = $numref;
891 $this->db->rollback();
910 if ($this->
statut == self::STATUS_VALIDATED || $this->
statut == self::STATUS_CLOSED) {
912 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
913 $delivery =
new Delivery($this->db);
914 $result = $delivery->create_from_sending($user, $this->
id);
918 $this->error = $delivery->error;
941 public function addline($entrepot_id, $id, $qty, $array_options = [])
943 global $conf, $langs;
945 $num = count($this->lines);
948 $line->entrepot_id = $entrepot_id;
949 $line->origin_line_id = $id;
950 $line->fk_elementdet = $id;
951 $line->element_type =
'order';
955 $orderline->fetch($id);
958 $line->rang = $orderline->rang;
959 $line->product_type = $orderline->product_type;
961 if (isModEnabled(
'stock') && !empty($orderline->fk_product)) {
962 $fk_product = $orderline->fk_product;
965 $langs->load(
"errors");
966 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
971 $product =
new Product($this->db);
972 $product->fetch($fk_product);
975 if ($entrepot_id > 0) {
976 $product->load_stock(
'warehouseopen');
977 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
979 $product_stock = $product->stock_reel;
982 $product_type = $product->type;
984 $isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
987 if ($product_stock < $qty) {
988 $langs->load(
"errors");
989 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
990 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
992 $this->db->rollback();
1002 if (isModEnabled(
'productbatch') && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) {
1003 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$orderline->fk_product;
1008 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1009 $line->array_options = $array_options;
1012 $this->lines[$num] = $line;
1028 global $conf, $langs;
1030 $num = count($this->lines);
1031 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1034 foreach ($dbatch[
'detail'] as $key => $value) {
1035 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1041 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1046 $linebatch->qty = $value[
'q'];
1047 if ($linebatch->qty == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
1048 $linebatch->batch =
null;
1050 $tab[] = $linebatch;
1053 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1055 $prod_batch->fetch($value[
'id_batch']);
1057 if ($prod_batch->qty < $linebatch->qty) {
1058 $langs->load(
"errors");
1059 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1060 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1061 $this->db->rollback();
1069 $line->entrepot_id = $linebatch->entrepot_id;
1070 $line->origin_line_id = $dbatch[
'ix_l'];
1071 $line->fk_elementdet = $dbatch[
'ix_l'];
1072 $line->qty = $dbatch[
'qty'];
1073 $line->detail_batch = $tab;
1076 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1077 $line->array_options = $array_options;
1081 $this->lines[$num] = $line;
1094 public function update($user =
null, $notrigger = 0)
1101 if (isset($this->
ref)) {
1102 $this->
ref = trim($this->
ref);
1104 if (isset($this->entity)) {
1105 $this->entity = (int) $this->entity;
1107 if (isset($this->ref_customer)) {
1108 $this->ref_customer = trim($this->ref_customer);
1110 if (isset($this->socid)) {
1111 $this->socid = (int) $this->socid;
1113 if (isset($this->fk_user_author)) {
1114 $this->fk_user_author = (int) $this->fk_user_author;
1116 if (isset($this->fk_user_valid)) {
1117 $this->fk_user_valid = (int) $this->fk_user_valid;
1119 if (isset($this->fk_delivery_address)) {
1120 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1122 if (isset($this->shipping_method_id)) {
1123 $this->shipping_method_id = (int) $this->shipping_method_id;
1125 if (isset($this->tracking_number)) {
1126 $this->tracking_number = trim($this->tracking_number);
1128 if (isset($this->
statut)) {
1131 if (isset($this->trueDepth)) {
1132 $this->trueDepth = trim($this->trueDepth);
1134 if (isset($this->trueWidth)) {
1135 $this->trueWidth = trim($this->trueWidth);
1137 if (isset($this->trueHeight)) {
1138 $this->trueHeight = trim($this->trueHeight);
1140 if (isset($this->size_units)) {
1141 $this->size_units = trim($this->size_units);
1143 if (isset($this->weight_units)) {
1144 $this->weight_units = trim($this->weight_units);
1146 if (isset($this->trueWeight)) {
1147 $this->weight = trim((
string) $this->trueWeight);
1149 if (isset($this->note_private)) {
1150 $this->note_private = trim($this->note_private);
1152 if (isset($this->note_public)) {
1153 $this->note_public = trim($this->note_public);
1155 if (isset($this->model_pdf)) {
1156 $this->model_pdf = trim($this->model_pdf);
1163 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1164 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1165 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1166 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1167 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1168 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1169 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1170 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1171 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1172 $sql .=
" date_expedition=".(dol_strlen($this->date_expedition) != 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
'null').
",";
1173 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1174 $sql .=
" fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address :
"null").
",";
1175 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1176 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1177 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1178 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1179 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1180 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1181 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1182 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1183 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1184 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1185 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1186 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1187 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1188 $sql .=
" entity=".$conf->entity;
1189 $sql .=
" WHERE rowid=".((int) $this->
id);
1193 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1194 $resql = $this->db->query($sql);
1197 $this->errors[] =
"Error ".$this->db->lasterror();
1200 if (!$error && !$notrigger) {
1202 $result = $this->
call_trigger(
'SHIPPING_MODIFY', $user);
1211 foreach ($this->errors as $errmsg) {
1212 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1213 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1215 $this->db->rollback();
1218 $this->db->commit();
1231 public function cancel($notrigger = 0, $also_update_stock =
false)
1233 global $conf, $langs, $user;
1235 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1244 if (count($this->linkedObjectsIds) > 0) {
1245 $this->error =
'ErrorThereIsSomeDeliveries';
1249 if (!$error && !$notrigger) {
1251 $result = $this->
call_trigger(
'SHIPPING_CANCEL', $user);
1259 if (!$error && isModEnabled(
'stock') &&
1261 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
statut == self::STATUS_CLOSED && $also_update_stock))) {
1262 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1264 $langs->load(
"agenda");
1267 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1268 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1269 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1270 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1271 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1273 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1274 $resql = $this->db->query($sql);
1276 $cpt = $this->db->num_rows($resql);
1280 for ($i = 0; $i < $cpt; $i++) {
1281 dol_syslog(get_class($this).
"::delete movement index ".$i);
1282 $obj = $this->db->fetch_object($resql);
1286 $mouvS->origin =
'';
1289 if (isModEnabled(
'productbatch')) {
1290 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1291 if (!is_array($lotArray)) {
1293 $this->errors[] =
"Error ".$this->db->lasterror();
1297 if (empty($lotArray)) {
1301 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref));
1304 $this->errors = array_merge($this->errors, $mouvS->errors);
1310 foreach ($lotArray as $lot) {
1311 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1314 $this->errors = array_merge($this->errors, $mouvS->errors);
1325 $this->errors[] =
"Error ".$this->db->lasterror();
1330 if (!$error && isModEnabled(
'productbatch')) {
1332 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1334 $this->errors[] =
"Error ".$this->db->lasterror();
1340 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1341 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1343 if ($this->db->query($sql)) {
1352 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"expedition";
1353 $sql .=
" WHERE rowid = ".((int) $this->
id);
1355 if ($this->db->query($sql)) {
1356 if (!empty($this->origin) && $this->origin_id > 0) {
1360 $this->origin_object->loadExpeditions();
1362 if (count($this->origin_object->expeditions) <= 0) {
1369 $this->db->commit();
1373 if (!empty($conf->expedition->dir_output)) {
1374 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1375 $file = $dir.
'/'.$ref.
'.pdf';
1376 if (file_exists($file)) {
1381 if (file_exists($dir)) {
1383 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1391 $this->db->rollback();
1395 $this->error = $this->db->lasterror().
" - sql=$sql";
1396 $this->db->rollback();
1400 $this->error = $this->db->lasterror().
" - sql=$sql";
1401 $this->db->rollback();
1405 $this->error = $this->db->lasterror().
" - sql=$sql";
1406 $this->db->rollback();
1410 $this->db->rollback();
1424 public function delete($user =
null, $notrigger = 0, $also_update_stock =
false)
1426 global $conf, $langs;
1432 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1441 if (count($this->linkedObjectsIds) > 0) {
1442 $this->error =
'ErrorThereIsSomeDeliveries';
1446 if (!$error && !$notrigger) {
1448 $result = $this->
call_trigger(
'SHIPPING_DELETE', $user);
1456 if (!$error && isModEnabled(
'stock') &&
1458 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
statut == self::STATUS_CLOSED && $also_update_stock))) {
1459 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1461 $langs->load(
"agenda");
1467 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1468 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1469 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1470 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1471 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1473 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1474 $resql = $this->db->query($sql);
1476 $cpt = $this->db->num_rows($resql);
1477 for ($i = 0; $i < $cpt; $i++) {
1478 dol_syslog(get_class($this).
"::delete movement index ".$i);
1479 $obj = $this->db->fetch_object($resql);
1483 $mouvS->origin =
'';
1485 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1486 if (!is_array($lotArray)) {
1488 $this->errors[] =
"Error ".$this->db->lasterror();
1490 if (empty($lotArray)) {
1494 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref));
1497 $this->errors = array_merge($this->errors, $mouvS->errors);
1503 foreach ($lotArray as $lot) {
1504 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1507 $this->errors = array_merge($this->errors, $mouvS->errors);
1518 $this->errors[] =
"Error ".$this->db->lasterror();
1525 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1527 $this->errors[] =
"Error ".$this->db->lasterror();
1532 $main = MAIN_DB_PREFIX.
'expeditiondet';
1533 $ef = $main.
"_extrafields";
1534 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".((int) $this->
id).
")";
1536 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1537 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1539 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1553 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expedition";
1554 $sql .=
" WHERE rowid = ".((int) $this->
id);
1556 if ($this->db->query($sql)) {
1557 if (!empty($this->origin) && $this->origin_id > 0) {
1561 $this->origin_object->loadExpeditions();
1563 if (count($this->origin_object->expeditions) <= 0) {
1570 $this->db->commit();
1578 if (!empty($conf->expedition->dir_output)) {
1579 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1580 $file = $dir.
'/'.$ref.
'.pdf';
1581 if (file_exists($file)) {
1586 if (file_exists($dir)) {
1588 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1596 $this->db->rollback();
1600 $this->error = $this->db->lasterror().
" - sql=$sql";
1601 $this->db->rollback();
1605 $this->error = $this->db->lasterror().
" - sql=$sql";
1606 $this->db->rollback();
1610 $this->error = $this->db->lasterror().
" - sql=$sql";
1611 $this->db->rollback();
1615 $this->db->rollback();
1631 $this->lines = array();
1636 $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";
1637 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1638 $sql .=
", cd.fk_remise_except, cd.fk_product_fournisseur_price as fk_fournprice";
1639 $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";
1640 $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";
1641 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_element, ed.fk_elementdet, ed.element_type, ed.fk_entrepot";
1642 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
1643 $sql .=
", p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch";
1644 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
1645 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
1646 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1647 $sql .=
" AND ed.fk_elementdet = cd.rowid";
1648 $sql .=
" ORDER BY cd.rang, ed.fk_elementdet";
1650 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1651 $resql = $this->db->query($sql);
1653 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1655 $num = $this->db->num_rows($resql);
1660 $this->total_ht = 0;
1661 $this->total_tva = 0;
1662 $this->total_ttc = 0;
1663 $this->total_localtax1 = 0;
1664 $this->total_localtax2 = 0;
1666 $this->multicurrency_total_ht = 0;
1667 $this->multicurrency_total_tva = 0;
1668 $this->multicurrency_total_ttc = 0;
1673 $obj = $this->db->fetch_object($resql);
1676 if ($originline > 0 && $originline == $obj->fk_elementdet) {
1677 '@phan-var-force ExpeditionLigne $line';
1678 $line->entrepot_id = 0;
1679 $line->qty_shipped += $obj->qty_shipped;
1682 $line->entrepot_id = $obj->fk_entrepot;
1683 $line->qty_shipped = $obj->qty_shipped;
1687 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
1688 $detail_entrepot->qty_shipped = $obj->qty_shipped;
1689 $detail_entrepot->line_id = $obj->line_id;
1690 $line->details_entrepot[] = $detail_entrepot;
1692 $line->line_id = $obj->line_id;
1693 $line->rowid = $obj->line_id;
1694 $line->id = $obj->line_id;
1696 $line->fk_origin =
'orderline';
1698 $line->fk_element = $obj->fk_element;
1699 $line->origin_id = $obj->fk_element;
1700 $line->fk_elementdet = $obj->fk_elementdet;
1701 $line->origin_line_id = $obj->fk_elementdet;
1702 $line->element_type = $obj->element_type;
1704 $line->fk_expedition = $this->id;
1706 $line->product_type = $obj->product_type;
1707 $line->fk_product = $obj->fk_product;
1708 $line->fk_product_type = $obj->fk_product_type;
1709 $line->ref = $obj->product_ref;
1710 $line->product_ref = $obj->product_ref;
1711 $line->product_label = $obj->product_label;
1712 $line->libelle = $obj->product_label;
1713 $line->product_barcode = $obj->product_barcode;
1714 $line->product_tosell = $obj->product_tosell;
1715 $line->product_tobuy = $obj->product_tobuy;
1716 $line->product_tobatch = $obj->product_tobatch;
1717 $line->fk_fournprice = $obj->fk_fournprice;
1718 $line->label = $obj->custom_label;
1719 $line->description = $obj->description;
1720 $line->qty_asked = $obj->qty_asked;
1721 $line->rang = $obj->rang;
1722 $line->weight = $obj->weight;
1723 $line->weight_units = $obj->weight_units;
1724 $line->length = $obj->length;
1725 $line->length_units = $obj->length_units;
1726 $line->width = $obj->width;
1727 $line->width_units = $obj->width_units;
1728 $line->height = $obj->height;
1729 $line->height_units = $obj->height_units;
1730 $line->surface = $obj->surface;
1731 $line->surface_units = $obj->surface_units;
1732 $line->volume = $obj->volume;
1733 $line->volume_units = $obj->volume_units;
1734 $line->fk_unit = $obj->fk_unit;
1736 $line->pa_ht = $obj->pa_ht;
1739 $localtax_array = array(0 => $obj->localtax1_type, 1 => $obj->localtax1_tx, 2 => $obj->localtax2_type, 3 => $obj->localtax2_tx);
1740 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
1741 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
1744 $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);
1745 $line->desc = $obj->description;
1746 $line->qty = $line->qty_shipped;
1747 $line->total_ht = $tabprice[0];
1748 $line->total_localtax1 = $tabprice[9];
1749 $line->total_localtax2 = $tabprice[10];
1750 $line->total_ttc = $tabprice[2];
1751 $line->total_tva = $tabprice[1];
1752 $line->vat_src_code = $obj->vat_src_code;
1753 $line->tva_tx = $obj->tva_tx;
1754 $line->localtax1_tx = $obj->localtax1_tx;
1755 $line->localtax2_tx = $obj->localtax2_tx;
1756 $line->info_bits = $obj->info_bits;
1757 $line->price = $obj->price;
1758 $line->subprice = $obj->subprice;
1759 $line->fk_remise_except = $obj->fk_remise_except;
1760 $line->remise_percent = $obj->remise_percent;
1762 $this->total_ht += $tabprice[0];
1763 $this->total_tva += $tabprice[1];
1764 $this->total_ttc += $tabprice[2];
1765 $this->total_localtax1 += $tabprice[9];
1766 $this->total_localtax2 += $tabprice[10];
1768 $line->date_start = $this->db->jdate($obj->date_start);
1769 $line->date_end = $this->db->jdate($obj->date_end);
1772 $this->fk_multicurrency = $obj->fk_multicurrency;
1773 $this->multicurrency_code = $obj->multicurrency_code;
1774 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1775 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1776 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1777 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1779 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
1780 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
1781 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
1783 if ($originline != $obj->fk_elementdet) {
1784 $line->detail_batch = array();
1788 if (isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
1789 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
1791 if (is_array($newdetailbatch)) {
1792 if ($originline != $obj->fk_elementdet) {
1793 $line->detail_batch = $newdetailbatch;
1795 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1800 $line->fetch_optionals();
1802 if ($originline != $obj->fk_elementdet) {
1803 $this->lines[$lineindex] = $line;
1806 $line->total_ht += $tabprice[0];
1807 $line->total_localtax1 += $tabprice[9];
1808 $line->total_localtax2 += $tabprice[10];
1809 $line->total_ttc += $tabprice[2];
1810 $line->total_tva += $tabprice[1];
1814 $originline = $obj->fk_elementdet;
1816 $this->db->free($resql);
1819 $this->error = $this->db->error();
1835 if ($this->
statut == self::STATUS_DRAFT) {
1841 $line->fetch($lineid);
1843 if ($line->delete($user) > 0) {
1846 $this->db->commit();
1849 $this->db->rollback();
1853 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1868 global $conf, $langs;
1870 $langs->load(
'sendings');
1872 $nofetch = !empty($params[
'nofetch']);
1875 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
1876 if (isset($this->
statut)) {
1877 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1879 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1880 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1882 $langs->load(
'companies');
1883 if (empty($this->thirdparty)) {
1886 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1903 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1905 global $langs, $hookmanager;
1910 'objecttype' => $this->element,
1911 'option' => $option,
1914 $classfortooltip =
'classfortooltip';
1917 $classfortooltip =
'classforajaxtooltip';
1918 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1924 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
1930 if ($option !==
'nolink') {
1932 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1933 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1934 $add_save_lastsearch_values = 1;
1936 if ($add_save_lastsearch_values) {
1937 $url .=
'&save_lastsearch_values=1';
1942 if (empty($notooltip)) {
1944 $label = $langs->trans(
"Shipment");
1945 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1947 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1948 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1951 $linkstart =
'<a href="'.$url.
'"';
1952 $linkstart .= $linkclose.
'>';
1955 $result .= $linkstart;
1957 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1959 if ($withpicto != 2) {
1960 $result .= $this->ref;
1962 $result .= $linkend;
1964 $hookmanager->initHooks(array($this->element .
'dao'));
1965 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1966 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1968 $result = $hookmanager->resPrint;
1970 $result .= $hookmanager->resPrint;
1999 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
2000 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
2002 $statusType =
'status'.$status;
2003 if ($status == self::STATUS_VALIDATED) {
2004 $statusType =
'status4';
2006 if ($status == self::STATUS_CLOSED) {
2007 $statusType =
'status6';
2009 if ($status == self::STATUS_CANCELED) {
2010 $statusType =
'status9';
2013 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
2025 global $langs, $conf;
2027 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2029 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2030 $return .=
'<div class="info-box info-box-sm">';
2031 $return .=
'<div class="info-box-icon bg-infobox-action">';
2033 $return .=
'</div>';
2034 $return .=
'<div class="info-box-content">';
2035 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2036 if ($selected >= 0) {
2037 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2039 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2040 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2042 if (property_exists($this,
'total_ht')) {
2043 $return .=
'<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).
' '.$langs->trans(
'HT').
'</div>';
2045 if (method_exists($this,
'getLibStatut')) {
2046 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2048 $return .=
'</div>';
2049 $return .=
'</div>';
2050 $return .=
'</div>';
2068 dol_syslog(get_class($this).
"::initAsSpecimen");
2071 $order->initAsSpecimen();
2075 $this->
ref =
'SPECIMEN';
2076 $this->specimen = 1;
2078 $this->livraison_id = 0;
2080 $this->date_creation = $now;
2081 $this->date_valid = $now;
2082 $this->date_delivery = $now + 24 * 3600;
2083 $this->date_expedition = $now + 24 * 3600;
2085 $this->entrepot_id = 0;
2086 $this->fk_delivery_address = 0;
2089 $this->commande_id = 0;
2090 $this->commande = $order;
2092 $this->origin_id = 1;
2093 $this->origin =
'commande';
2095 $this->note_private =
'Private note';
2096 $this->note_public =
'Public note';
2100 while ($xnbp < $nbp) {
2102 $line->product_desc = $langs->trans(
"Description").
" ".$xnbp;
2103 $line->product_label = $langs->trans(
"Description").
" ".$xnbp;
2105 $line->qty_asked = 5;
2106 $line->qty_shipped = 4;
2107 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
2109 $this->lines[] = $line;
2140 if ($user->hasRight(
'expedition',
'creer')) {
2141 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2142 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2143 $sql .=
" WHERE rowid = ".((int) $this->
id);
2145 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2146 $resql = $this->db->query($sql);
2148 $this->date_delivery = $delivery_date;
2151 $this->error = $this->db->error();
2169 $this->meths = array();
2171 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2172 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2173 $sql .=
" WHERE em.active = 1";
2174 $sql .=
" ORDER BY em.libelle ASC";
2176 $resql = $this->db->query($sql);
2178 while ($obj = $this->db->fetch_object($resql)) {
2179 $label = $langs->trans(
'SendingMethod'.$obj->code);
2180 $this->meths[$obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2197 $this->listmeths = array();
2200 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2203 $sql .=
" WHERE em.rowid=".((int) $id);
2206 $resql = $this->db->query($sql);
2208 while ($obj = $this->db->fetch_object($resql)) {
2209 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2210 $this->listmeths[$i][
'code'] = $obj->code;
2211 $label = $langs->trans(
'SendingMethod'.$obj->code);
2212 $this->listmeths[$i][
'libelle'] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2213 $this->listmeths[$i][
'description'] = $obj->description;
2214 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2215 $this->listmeths[$i][
'active'] = $obj->active;
2229 if (!empty($this->shipping_method_id)) {
2230 $sql =
"SELECT em.code, em.tracking";
2231 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2232 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2234 $resql = $this->db->query($sql);
2236 if ($obj = $this->db->fetch_object($resql)) {
2237 $tracking = $obj->tracking;
2242 if (!empty($tracking) && !empty($value)) {
2243 $url = str_replace(
'{TRACKID}', $value, $tracking);
2244 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
2246 $this->tracking_url = $value;
2262 if ($this->
statut == self::STATUS_CLOSED) {
2269 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
2271 $resql = $this->db->query($sql);
2274 if ($this->origin ==
'commande' && $this->origin_id > 0) {
2276 $order->fetch($this->origin_id);
2278 $order->loadExpeditions(self::STATUS_CLOSED);
2280 $shipments_match_order = 1;
2281 foreach ($order->lines as $line) {
2282 $lineid = $line->id;
2284 if (($line->product_type == 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) {
2285 $shipments_match_order = 0;
2286 $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';
2291 if ($shipments_match_order) {
2292 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');
2294 $order->cloture($user);
2302 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2311 $result = $this->
call_trigger(
'SHIPPING_CLOSED', $user);
2322 $this->db->commit();
2328 $this->db->rollback();
2348 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
2350 $langs->load(
"agenda");
2353 $sql =
"SELECT cd.fk_product, cd.subprice,";
2354 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2356 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock,";
2357 $sql .=
" cd.rowid as cdid, ed.rowid as edid";
2358 $sql .=
" FROM " . MAIN_DB_PREFIX .
"commandedet as cd,";
2359 $sql .=
" " . MAIN_DB_PREFIX .
"expeditiondet as ed";
2360 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2361 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"expedition as e ON ed.fk_expedition = e.rowid";
2362 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
2363 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2365 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
2366 $resql = $this->db->query($sql);
2368 $cpt = $this->db->num_rows($resql);
2369 for ($i = 0; $i < $cpt; $i++) {
2370 $obj = $this->db->fetch_object($resql);
2371 if (empty($obj->edbrowid)) {
2374 $qty = $obj->edbqty;
2376 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
2379 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->rowid .
" edb.rowid=" . $obj->edbrowid);
2382 $mouvS->origin = &$this;
2383 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
2385 if (empty($obj->edbrowid)) {
2389 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref));
2391 $this->error = $mouvS->error;
2392 $this->errors = $mouvS->errors;
2400 $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);
2402 $this->error = $mouvS->error;
2403 $this->errors = $mouvS->errors;
2411 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".MAIN_DB_PREFIX.
"product_batch as pb)";
2412 $resqldelete = $this->db->query($sqldelete);
2416 $this->error = $this->db->lasterror();
2417 $this->errors[] = $this->db->lasterror();
2440 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET billed = 1';
2441 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2443 $resql = $this->db->query($sql);
2448 $result = $this->
call_trigger(
'SHIPPING_BILLED', $user);
2455 $this->errors[] = $this->db->lasterror;
2458 if (empty($error)) {
2459 $this->db->commit();
2462 $this->db->rollback();
2477 if ($this->
statut <= self::STATUS_DRAFT) {
2481 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
2491 global $langs, $user;
2496 if ($this->
statut == self::STATUS_VALIDATED) {
2502 $oldbilled = $this->billed;
2504 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
2505 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2507 $resql = $this->db->query($sql);
2514 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2515 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2517 $langs->load(
"agenda");
2521 $sql =
"SELECT cd.fk_product, cd.subprice,";
2522 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2523 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2524 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2525 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2526 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2527 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2528 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2530 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2531 $resql = $this->db->query($sql);
2533 $cpt = $this->db->num_rows($resql);
2534 for ($i = 0; $i < $cpt; $i++) {
2535 $obj = $this->db->fetch_object($resql);
2536 if (empty($obj->edbrowid)) {
2539 $qty = $obj->edbqty;
2544 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2548 $mouvS->origin = &$this;
2549 $mouvS->setOrigin($this->element, $this->
id);
2551 if (empty($obj->edbrowid)) {
2555 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
2557 $this->error = $mouvS->error;
2558 $this->errors = $mouvS->errors;
2566 $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);
2568 $this->error = $mouvS->error;
2569 $this->errors = $mouvS->errors;
2576 $this->error = $this->db->lasterror();
2583 $result = $this->
call_trigger(
'SHIPPING_REOPEN', $user);
2590 $this->errors[] = $this->db->lasterror();
2594 $this->db->commit();
2599 $this->billed = $oldbilled;
2600 $this->db->rollback();
2616 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2618 $outputlangs->load(
"products");
2623 if (!empty($this->model_pdf)) {
2624 $modele = $this->model_pdf;
2630 $modelpath =
"core/modules/expedition/doc/";
2634 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2664 public $element =
'expeditiondet';
2669 public $table_element =
'expeditiondet';
2702 public $fk_elementdet;
2707 public $origin_line_id;
2712 public $element_type;
2726 public $fk_expedition;
2741 public $qty_shipped;
2750 public $detail_batch;
2754 public $details_entrepot;
2760 public $entrepot_id;
2777 public $product_ref;
2788 public $product_label;
2800 public $product_desc;
2806 public $product_type = 0;
2817 public $weight_units;
2823 public $length_units;
2829 public $width_units;
2835 public $height_units;
2841 public $surface_units;
2847 public $volume_units;
2850 public $remise_percent;
2871 public $total_localtax1;
2876 public $total_localtax2;
2897 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_elementdet, ed.element_type, ed.qty, ed.rang';
2898 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as ed';
2899 $sql .=
' WHERE ed.rowid = '.((int) $rowid);
2900 $result = $this->db->query($sql);
2902 $objp = $this->db->fetch_object($result);
2903 $this->
id = $objp->rowid;
2904 $this->fk_expedition = $objp->fk_expedition;
2905 $this->entrepot_id = $objp->fk_entrepot;
2906 $this->fk_elementdet = $objp->fk_elementdet;
2907 $this->element_type = $objp->element_type;
2908 $this->qty = $objp->qty;
2909 $this->rang = $objp->rang;
2911 $this->db->free($result);
2915 $this->errors[] = $this->db->lasterror();
2916 $this->error = $this->db->lasterror();
2928 public function insert($user, $notrigger = 0)
2933 if (empty($this->fk_expedition) || empty($this->fk_elementdet) || !is_numeric($this->qty)) {
2934 $this->error =
'ErrorMandatoryParametersNotProvided';
2940 if (empty($this->rang)) {
2945 $ranktouse = $this->rang;
2946 if ($ranktouse == -1) {
2947 $rangmax = $this->
line_max($this->fk_expedition);
2948 $ranktouse = $rangmax + 1;
2951 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expeditiondet (";
2952 $sql .=
"fk_expedition";
2953 $sql .=
", fk_entrepot";
2954 $sql .=
", fk_elementdet";
2955 $sql .=
", element_type";
2958 $sql .=
") VALUES (";
2959 $sql .= $this->fk_expedition;
2960 $sql .=
", ".(empty($this->entrepot_id) ?
'NULL' : $this->entrepot_id);
2961 $sql .=
", ".((int) $this->fk_elementdet);
2962 $sql .=
", '".(empty($this->element_type) ?
'order' : $this->db->escape($this->element_type)).
"'";
2963 $sql .=
", ".price2num($this->qty,
'MS');
2964 $sql .=
", ".((int) $ranktouse);
2967 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2968 $resql = $this->db->query($sql);
2970 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expeditiondet");
2979 if (!$error && !$notrigger) {
2981 $result = $this->
call_trigger(
'LINESHIPPING_INSERT', $user);
2989 foreach ($this->errors as $errmsg) {
2990 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2991 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2999 $this->db->rollback();
3002 $this->db->commit();
3014 public function delete($user =
null, $notrigger = 0)
3021 if (isModEnabled(
'productbatch')) {
3022 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3023 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3025 if (!$this->db->query($sql)) {
3026 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3031 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
3032 $sql .=
" WHERE rowid = ".((int) $this->
id);
3034 if (!$error && $this->db->query($sql)) {
3039 $this->errors[] = $this->error;
3043 if (!$error && !$notrigger) {
3045 $result = $this->
call_trigger(
'LINESHIPPING_DELETE', $user);
3047 $this->errors[] = $this->error;
3053 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3058 $this->db->commit();
3061 foreach ($this->errors as $errmsg) {
3062 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3063 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3065 $this->db->rollback();
3077 public function update($user =
null, $notrigger = 0)
3081 dol_syslog(get_class($this).
"::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
3086 if (empty($this->qty)) {
3093 $expedition_batch_id =
null;
3094 if (is_array($this->detail_batch)) {
3095 if (count($this->detail_batch) > 1) {
3096 dol_syslog(get_class($this).
'::update only possible for one batch', LOG_ERR);
3097 $this->errors[] =
'ErrorBadParameters';
3100 $batch = $this->detail_batch[0]->batch;
3101 $batch_id = $this->detail_batch[0]->fk_origin_stock;
3102 $expedition_batch_id = $this->detail_batch[0]->id;
3103 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) {
3104 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3105 $this->errors[] =
'ErrorBadParameters';
3108 $qty =
price2num($this->detail_batch[0]->qty);
3110 } elseif (!empty($this->detail_batch)) {
3111 $batch = $this->detail_batch->batch;
3112 $batch_id = $this->detail_batch->fk_origin_stock;
3113 $expedition_batch_id = $this->detail_batch->id;
3114 if ($this->entrepot_id != $this->detail_batch->entrepot_id) {
3115 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3116 $this->errors[] =
'ErrorBadParameters';
3119 $qty =
price2num($this->detail_batch->qty);
3123 if (!isset($this->
id) || !isset($this->entrepot_id)) {
3124 dol_syslog(get_class($this).
'::update missing line id and/or warehouse id', LOG_ERR);
3125 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3132 if (!empty($batch) && isModEnabled(
'productbatch')) {
3133 $batch_id_str = $batch_id ??
'null';
3134 dol_syslog(get_class($this).
"::update expedition batch id=$expedition_batch_id, batch_id=$batch_id_str, batch=$batch");
3136 if (empty($batch_id) || empty($this->fk_product)) {
3137 dol_syslog(get_class($this).
'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
3138 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3145 if (!$error && ($lotArray = $shipmentlinebatch->fetchAll($this->id)) < 0) {
3146 $this->errors[] = $this->db->lasterror().
" - ExpeditionLineBatch::fetchAll";
3150 foreach ($lotArray as $lot) {
3151 if ($expedition_batch_id != $lot->id) {
3152 $remainingQty += $lot->qty;
3155 $qty += $remainingQty;
3160 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
3162 if ($lot->fetch(0, $this->fk_product, $batch) < 0) {
3163 $this->errors[] = $lot->errors;
3166 if (!$error && !empty($expedition_batch_id)) {
3168 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3169 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3170 $sql .=
" AND rowid = ".((int) $expedition_batch_id);
3172 if (!$this->db->query($sql)) {
3173 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3177 if (!$error && $this->detail_batch->qty > 0) {
3179 if (isset($lot->id)) {
3181 $shipmentLot->batch = $lot->batch;
3182 $shipmentLot->eatby = $lot->eatby;
3183 $shipmentLot->sellby = $lot->sellby;
3184 $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
3185 $shipmentLot->qty = $this->detail_batch->qty;
3186 $shipmentLot->fk_origin_stock = $batch_id;
3187 if ($shipmentLot->create($this->id) < 0) {
3188 $this->errors = $shipmentLot->errors;
3197 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3198 $sql .=
" fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id :
'null');
3199 $sql .=
" , qty = ".((float)
price2num($qty,
'MS'));
3200 $sql .=
" WHERE rowid = ".((int) $this->
id);
3202 if (!$this->db->query($sql)) {
3203 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3211 $this->errors[] = $this->error;
3216 if (!$error && !$notrigger) {
3218 $result = $this->
call_trigger(
'LINESHIPPING_MODIFY', $user);
3220 $this->errors[] = $this->error;
3226 $this->db->commit();
3229 foreach ($this->errors as $errmsg) {
3230 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3231 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3233 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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...
deleteEcmFiles($mode=0)
Delete related files of object in database.
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
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
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).
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage receptions.
Class to manage Dolibarr database access.
Class to manage shipments.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1)
Return clicable link of object (with eventually picto)
create_delivery($user)
Create a delivery receipt from a shipment.
const STATUS_NO_SIGNATURE
No signature.
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($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...
addline($entrepot_id, $id, $qty, $array_options=[])
Add an expedition line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getTooltipContentArray($params)
getTooltipContentArray
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[])
Create a expedition line.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
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.
addline_batch($dbatch, $array_options=[])
Add a shipment line with batch record.
getNextNumRef($soc)
Return next expedition ref.
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.
const STATUS_SIGNED
Signed status.
update($user=null, $notrigger=0)
Update database.
cancel($notrigger=0, $also_update_stock=false)
Cancel 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.
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.
fetch($rowid)
Load line expedition.
__construct($db)
Constructor.
insert($user, $notrigger=0)
Insert line into database.
update($user=null, $notrigger=0)
Update a line in database.
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 with list of lots and properties.
Class to manage third parties objects (customers, suppliers, prospects...)
trait CommonIncoterm
Superclass for incoterm classes.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 dolibarr global constant string value.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, 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='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
$conf db user
Active Directory does not allow anonymous connections.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut