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;
205 public $lines = array();
211 public $fk_multicurrency;
216 public $multicurrency_code;
217 public $multicurrency_tx;
218 public $multicurrency_total_ht;
219 public $multicurrency_total_tva;
220 public $multicurrency_total_ttc;
225 public $signed_status = 0;
286 $this->ismultientitymanaged = 1;
287 $this->isextrafieldmanaged = 1;
290 $this->labelStatus = array();
291 $this->labelStatus[-1] =
'StatusSendingCanceled';
292 $this->labelStatus[0] =
'StatusSendingDraft';
293 $this->labelStatus[1] =
'StatusSendingValidated';
294 $this->labelStatus[2] =
'StatusSendingProcessed';
297 $this->labelStatusShort = array();
298 $this->labelStatusShort[-1] =
'StatusSendingCanceledShort';
299 $this->labelStatusShort[0] =
'StatusSendingDraftShort';
300 $this->labelStatusShort[1] =
'StatusSendingValidatedShort';
301 $this->labelStatusShort[2] =
'StatusSendingProcessedShort';
312 global $langs, $conf;
313 $langs->load(
"sendings");
322 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
324 foreach ($dirmodels as $reldir) {
328 $mybool = ((bool) @include_once $dir.$file) || $mybool;
336 $obj =
new $classname();
338 $numref = $obj->getNextValue($soc, $this);
343 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
347 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
359 public function create($user, $notrigger = 0)
361 global $conf, $hookmanager;
365 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
370 if (empty($this->fk_project)) {
371 $this->fk_project = 0;
373 if (empty($this->date_shipping) && !empty($this->date_expedition)) {
381 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
384 $sql .=
", ref_customer";
386 $sql .=
", date_creation";
387 $sql .=
", fk_user_author";
388 $sql .=
", date_expedition";
389 $sql .=
", date_delivery";
391 $sql .=
", fk_projet";
392 $sql .=
", fk_address";
393 $sql .=
", fk_shipping_method";
394 $sql .=
", tracking_number";
399 $sql .=
", weight_units";
400 $sql .=
", size_units";
401 $sql .=
", note_private";
402 $sql .=
", note_public";
403 $sql .=
", model_pdf";
404 $sql .=
", fk_incoterms, location_incoterms";
405 $sql .=
") VALUES (";
407 $sql .=
", ".((int) $conf->entity);
408 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
409 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
410 $sql .=
", '".$this->db->idate($now).
"'";
411 $sql .=
", ".((int) $user->id);
412 $sql .=
", ".($this->date_shipping > 0 ?
"'".$this->db->idate($this->date_shipping).
"'" :
"null");
413 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
414 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
415 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
416 $sql .=
", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address :
"null");
417 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
418 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
419 $sql .=
", ".(is_numeric($this->weight) ? $this->weight :
'NULL');
420 $sql .=
", ".(is_numeric($this->sizeS) ? $this->sizeS :
'NULL');
421 $sql .=
", ".(is_numeric($this->sizeW) ? $this->sizeW :
'NULL');
422 $sql .=
", ".(is_numeric($this->sizeH) ? $this->sizeH :
'NULL');
423 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
424 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
425 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
426 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
427 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
428 $sql .=
", ".(int) $this->fk_incoterms;
429 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
432 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
433 $resql = $this->db->query($sql);
435 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
437 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
438 $sql .=
" SET ref = '(PROV".$this->id.
")'";
439 $sql .=
" WHERE rowid = ".((int) $this->
id);
441 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
442 if ($this->db->query($sql)) {
444 $num = count($this->lines);
445 for ($i = 0; $i < $num; $i++) {
447 if (!isset($this->lines[$i]->detail_batch)) {
448 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) {
452 if ($this->
create_line_batch($this->lines[$i], $this->lines[$i]->array_options) <= 0) {
459 if (!$error && $this->
id && $this->origin_id) {
474 if (!$error && !$notrigger) {
476 $result = $this->
call_trigger(
'SHIPPING_CREATE', $user);
486 foreach ($this->errors as $errmsg) {
487 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
488 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
490 $this->db->rollback();
495 $this->db->rollback();
500 $this->error = $this->db->lasterror().
" - sql=$sql";
501 $this->db->rollback();
506 $this->error = $this->db->error().
" - sql=$sql";
507 $this->db->rollback();
523 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [])
529 $expeditionline->fk_expedition = $this->id;
530 $expeditionline->entrepot_id = $entrepot_id;
531 $expeditionline->fk_elementdet = $origin_line_id;
532 $expeditionline->element_type = $this->origin;
533 $expeditionline->qty = $qty;
534 $expeditionline->rang = $rang;
535 $expeditionline->array_options = $array_options;
537 if (($lineId = $expeditionline->insert($user)) < 0) {
538 $this->errors[] = $expeditionline->error;
556 $stockLocationQty = array();
558 $tab = $line_ext->detail_batch;
560 foreach ($tab as $detbatch) {
561 if (!empty($detbatch->entrepot_id)) {
562 if (empty($stockLocationQty[$detbatch->entrepot_id])) {
563 $stockLocationQty[$detbatch->entrepot_id] = 0;
565 $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty;
569 foreach ($stockLocationQty as $stockLocation => $qty) {
570 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
575 foreach ($tab as $detbatch) {
576 if ($detbatch->entrepot_id == $stockLocation) {
577 if (!($detbatch->create($line_id) > 0)) {
578 $this->errors = $detbatch->errors;
602 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
607 if (empty($id) && empty($ref) && empty($ref_ext)) {
611 $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";
612 $sql .=
", e.date_valid";
613 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
614 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
615 $sql .=
", e.fk_shipping_method, e.tracking_number";
616 $sql .=
", e.note_private, e.note_public";
617 $sql .=
', e.fk_incoterms, e.location_incoterms';
618 $sql .=
', e.signed_status';
619 $sql .=
', i.libelle as label_incoterms';
620 $sql .=
', s.libelle as shipping_method';
621 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin_type";
622 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
623 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
624 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
625 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
626 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
628 $sql .=
" AND e.rowid = ".((int) $id);
631 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
634 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
637 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
638 $result = $this->db->query($sql);
640 if ($this->db->num_rows($result)) {
641 $obj = $this->db->fetch_object($result);
643 $this->
id = $obj->rowid;
644 $this->entity = $obj->entity;
645 $this->
ref = $obj->ref;
646 $this->socid = $obj->socid;
647 $this->ref_customer = $obj->ref_customer;
648 $this->ref_ext = $obj->ref_ext;
649 $this->
status = $obj->fk_statut;
650 $this->
statut = $this->status;
651 $this->user_author_id = $obj->fk_user_author;
652 $this->fk_user_author = $obj->fk_user_author;
653 $this->date_creation = $this->db->jdate($obj->date_creation);
654 $this->date_valid = $this->db->jdate($obj->date_valid);
655 $this->date = $this->db->jdate($obj->date_expedition);
656 $this->date_expedition = $this->db->jdate($obj->date_expedition);
657 $this->date_shipping = $this->db->jdate($obj->date_expedition);
658 $this->date_delivery = $this->db->jdate($obj->date_delivery);
659 $this->fk_delivery_address = $obj->fk_address;
660 $this->model_pdf = $obj->model_pdf;
661 $this->shipping_method_id = $obj->fk_shipping_method;
662 $this->shipping_method = $obj->shipping_method;
663 $this->tracking_number = $obj->tracking_number;
664 $this->origin = ($obj->origin_type ? $obj->origin_type :
'commande');
665 $this->origin_type = ($obj->origin_type ? $obj->origin_type :
'commande');
666 $this->origin_id = $obj->origin_id;
667 $this->billed = $obj->billed;
668 $this->fk_project = $obj->fk_project;
669 $this->signed_status = $obj->signed_status;
670 $this->trueWeight = $obj->weight;
671 $this->weight_units = $obj->weight_units;
673 $this->trueWidth = $obj->width;
674 $this->width_units = $obj->size_units;
675 $this->trueHeight = $obj->height;
676 $this->height_units = $obj->size_units;
677 $this->trueDepth = $obj->size;
678 $this->depth_units = $obj->size_units;
680 $this->note_public = $obj->note_public;
681 $this->note_private = $obj->note_private;
684 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
685 $this->size_units = $obj->size_units;
688 $this->fk_incoterms = $obj->fk_incoterms;
689 $this->location_incoterms = $obj->location_incoterms;
690 $this->label_incoterms = $obj->label_incoterms;
692 $this->db->free($result);
704 if (isModEnabled(
'multicurrency')) {
705 if (!empty($this->multicurrency_code)) {
706 $this->multicurrency_code = $this->thirdparty->multicurrency_code;
708 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($this->thirdparty->multicurrency_tx)) {
709 $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
723 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
724 $this->error =
'Shipment with id '.$id.
' not found';
728 $this->error = $this->db->error();
740 public function valid($user, $notrigger = 0)
744 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
750 dol_syslog(get_class($this).
"::valid not in draft status", LOG_WARNING);
754 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'creer'))
755 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'shipping_advance',
'validate')))) {
756 $this->error =
'Permission denied';
757 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
767 $soc->fetch($this->socid);
770 $result = $soc->setAsCustomer();
773 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
775 } elseif (!empty($this->
ref)) {
776 $numref = $this->ref;
778 $numref =
"EXP".$this->id;
785 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
786 $sql .=
" ref='".$this->db->escape($numref).
"'";
787 $sql .=
", fk_statut = 1";
788 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
789 $sql .=
", fk_user_valid = ".$user->id;
790 $sql .=
" WHERE rowid = ".((int) $this->
id);
792 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
793 $resql = $this->db->query($sql);
795 $this->error = $this->db->lasterror();
800 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT')) {
813 if (!$error && !$notrigger) {
815 $result = $this->
call_trigger(
'SHIPPING_VALIDATE', $user);
823 $this->oldref = $this->ref;
826 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
828 $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).
"'";
829 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
830 $resql = $this->db->query($sql);
833 $this->error = $this->db->lasterror();
835 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
836 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
837 $resql = $this->db->query($sql);
840 $this->error = $this->db->lasterror();
846 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
847 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
848 if (!$error && file_exists($dirsource)) {
849 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
851 if (@rename($dirsource, $dirdest)) {
854 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
855 foreach ($listoffiles as $fileentry) {
856 $dirsource = $fileentry[
'name'];
857 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
858 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
859 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
860 @rename($dirsource, $dirdest);
869 $this->
ref = $numref;
878 $this->db->rollback();
897 if ($this->
statut == self::STATUS_VALIDATED || $this->
statut == self::STATUS_CLOSED) {
899 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
900 $delivery =
new Delivery($this->db);
901 $result = $delivery->create_from_sending($user, $this->
id);
905 $this->error = $delivery->error;
928 public function addline($entrepot_id, $id, $qty, $array_options = [])
930 global $conf, $langs;
932 $num = count($this->lines);
935 $line->entrepot_id = $entrepot_id;
936 $line->origin_line_id = $id;
937 $line->fk_elementdet = $id;
938 $line->element_type =
'order';
942 $orderline->fetch($id);
945 $line->rang = $orderline->rang;
946 $line->product_type = $orderline->product_type;
948 if (isModEnabled(
'stock') && !empty($orderline->fk_product)) {
949 $fk_product = $orderline->fk_product;
952 $langs->load(
"errors");
953 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
958 $product =
new Product($this->db);
959 $product->fetch($fk_product);
962 if ($entrepot_id > 0) {
963 $product->load_stock(
'warehouseopen');
964 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
966 $product_stock = $product->stock_reel;
969 $product_type = $product->type;
971 $isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
974 if ($product_stock < $qty) {
975 $langs->load(
"errors");
976 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
977 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
979 $this->db->rollback();
989 if (isModEnabled(
'productbatch') && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) {
990 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$orderline->fk_product;
995 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
996 $line->array_options = $array_options;
999 $this->lines[$num] = $line;
1015 global $conf, $langs;
1017 $num = count($this->lines);
1018 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1021 foreach ($dbatch[
'detail'] as $key => $value) {
1022 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1028 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1033 $linebatch->qty = $value[
'q'];
1034 if ($linebatch->qty == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
1035 $linebatch->batch =
null;
1037 $tab[] = $linebatch;
1040 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1042 $prod_batch->fetch($value[
'id_batch']);
1044 if ($prod_batch->qty < $linebatch->qty) {
1045 $langs->load(
"errors");
1046 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1047 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1048 $this->db->rollback();
1056 $line->entrepot_id = $linebatch->entrepot_id;
1057 $line->origin_line_id = $dbatch[
'ix_l'];
1058 $line->fk_elementdet = $dbatch[
'ix_l'];
1059 $line->qty = $dbatch[
'qty'];
1060 $line->detail_batch = $tab;
1063 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1064 $line->array_options = $array_options;
1068 $this->lines[$num] = $line;
1081 public function update($user =
null, $notrigger = 0)
1088 if (isset($this->
ref)) {
1089 $this->
ref = trim($this->
ref);
1091 if (isset($this->entity)) {
1092 $this->entity = (int) $this->entity;
1094 if (isset($this->ref_customer)) {
1095 $this->ref_customer = trim($this->ref_customer);
1097 if (isset($this->socid)) {
1098 $this->socid = (int) $this->socid;
1100 if (isset($this->fk_user_author)) {
1101 $this->fk_user_author = (int) $this->fk_user_author;
1103 if (isset($this->fk_user_valid)) {
1104 $this->fk_user_valid = (int) $this->fk_user_valid;
1106 if (isset($this->fk_delivery_address)) {
1107 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1109 if (isset($this->shipping_method_id)) {
1110 $this->shipping_method_id = (int) $this->shipping_method_id;
1112 if (isset($this->tracking_number)) {
1113 $this->tracking_number = trim($this->tracking_number);
1115 if (isset($this->
statut)) {
1118 if (isset($this->trueDepth)) {
1119 $this->trueDepth = trim($this->trueDepth);
1121 if (isset($this->trueWidth)) {
1122 $this->trueWidth = trim($this->trueWidth);
1124 if (isset($this->trueHeight)) {
1125 $this->trueHeight = trim($this->trueHeight);
1127 if (isset($this->size_units)) {
1128 $this->size_units = trim($this->size_units);
1130 if (isset($this->weight_units)) {
1131 $this->weight_units = trim($this->weight_units);
1133 if (isset($this->trueWeight)) {
1134 $this->weight = trim((
string) $this->trueWeight);
1136 if (isset($this->note_private)) {
1137 $this->note_private = trim($this->note_private);
1139 if (isset($this->note_public)) {
1140 $this->note_public = trim($this->note_public);
1142 if (isset($this->model_pdf)) {
1143 $this->model_pdf = trim($this->model_pdf);
1150 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1151 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1152 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1153 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1154 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1155 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1156 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1157 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1158 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1159 $sql .=
" date_expedition=".(dol_strlen($this->date_expedition) != 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
'null').
",";
1160 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1161 $sql .=
" fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address :
"null").
",";
1162 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1163 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1164 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1165 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1166 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1167 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1168 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1169 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1170 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1171 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1172 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1173 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1174 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1175 $sql .=
" entity=".$conf->entity;
1176 $sql .=
" WHERE rowid=".((int) $this->
id);
1180 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1181 $resql = $this->db->query($sql);
1184 $this->errors[] =
"Error ".$this->db->lasterror();
1187 if (!$error && !$notrigger) {
1189 $result = $this->
call_trigger(
'SHIPPING_MODIFY', $user);
1198 foreach ($this->errors as $errmsg) {
1199 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1200 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1202 $this->db->rollback();
1205 $this->db->commit();
1218 public function cancel($notrigger = 0, $also_update_stock =
false)
1220 global $conf, $langs, $user;
1222 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1231 if (count($this->linkedObjectsIds) > 0) {
1232 $this->error =
'ErrorThereIsSomeDeliveries';
1236 if (!$error && !$notrigger) {
1238 $result = $this->
call_trigger(
'SHIPPING_CANCEL', $user);
1246 if (!$error && isModEnabled(
'stock') &&
1248 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
statut == self::STATUS_CLOSED && $also_update_stock))) {
1249 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1251 $langs->load(
"agenda");
1254 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1256 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1257 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1258 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1260 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1261 $resql = $this->db->query($sql);
1263 $cpt = $this->db->num_rows($resql);
1267 for ($i = 0; $i < $cpt; $i++) {
1268 dol_syslog(get_class($this).
"::delete movement index ".$i);
1269 $obj = $this->db->fetch_object($resql);
1273 $mouvS->origin =
'';
1276 if (isModEnabled(
'productbatch')) {
1277 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1278 if (!is_array($lotArray)) {
1280 $this->errors[] =
"Error ".$this->db->lasterror();
1284 if (empty($lotArray)) {
1288 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref));
1291 $this->errors = array_merge($this->errors, $mouvS->errors);
1297 foreach ($lotArray as $lot) {
1298 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1301 $this->errors = array_merge($this->errors, $mouvS->errors);
1312 $this->errors[] =
"Error ".$this->db->lasterror();
1317 if (!$error && isModEnabled(
'productbatch')) {
1319 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1321 $this->errors[] =
"Error ".$this->db->lasterror();
1327 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1328 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1330 if ($this->db->query($sql)) {
1339 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"expedition";
1340 $sql .=
" WHERE rowid = ".((int) $this->
id);
1342 if ($this->db->query($sql)) {
1343 if (!empty($this->origin) && $this->origin_id > 0) {
1347 $this->origin_object->loadExpeditions();
1349 if (count($this->origin_object->expeditions) <= 0) {
1356 $this->db->commit();
1360 if (!empty($conf->expedition->dir_output)) {
1361 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1362 $file = $dir.
'/'.$ref.
'.pdf';
1363 if (file_exists($file)) {
1368 if (file_exists($dir)) {
1370 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1378 $this->db->rollback();
1382 $this->error = $this->db->lasterror().
" - sql=$sql";
1383 $this->db->rollback();
1387 $this->error = $this->db->lasterror().
" - sql=$sql";
1388 $this->db->rollback();
1392 $this->error = $this->db->lasterror().
" - sql=$sql";
1393 $this->db->rollback();
1397 $this->db->rollback();
1411 public function delete($user =
null, $notrigger = 0, $also_update_stock =
false)
1413 global $conf, $langs;
1419 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1428 if (count($this->linkedObjectsIds) > 0) {
1429 $this->error =
'ErrorThereIsSomeDeliveries';
1433 if (!$error && !$notrigger) {
1435 $result = $this->
call_trigger(
'SHIPPING_DELETE', $user);
1443 if (!$error && isModEnabled(
'stock') &&
1445 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
statut == self::STATUS_CLOSED && $also_update_stock))) {
1446 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1448 $langs->load(
"agenda");
1454 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1456 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1457 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1458 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1460 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1461 $resql = $this->db->query($sql);
1463 $cpt = $this->db->num_rows($resql);
1464 for ($i = 0; $i < $cpt; $i++) {
1465 dol_syslog(get_class($this).
"::delete movement index ".$i);
1466 $obj = $this->db->fetch_object($resql);
1470 $mouvS->origin =
'';
1472 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1473 if (!is_array($lotArray)) {
1475 $this->errors[] =
"Error ".$this->db->lasterror();
1477 if (empty($lotArray)) {
1481 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref));
1484 $this->errors = array_merge($this->errors, $mouvS->errors);
1490 foreach ($lotArray as $lot) {
1491 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1494 $this->errors = array_merge($this->errors, $mouvS->errors);
1505 $this->errors[] =
"Error ".$this->db->lasterror();
1512 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1514 $this->errors[] =
"Error ".$this->db->lasterror();
1519 $main = MAIN_DB_PREFIX.
'expeditiondet';
1520 $ef = $main.
"_extrafields";
1521 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".((int) $this->
id).
")";
1523 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1524 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1526 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1540 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expedition";
1541 $sql .=
" WHERE rowid = ".((int) $this->
id);
1543 if ($this->db->query($sql)) {
1544 if (!empty($this->origin) && $this->origin_id > 0) {
1548 $this->origin_object->loadExpeditions();
1550 if (count($this->origin_object->expeditions) <= 0) {
1557 $this->db->commit();
1565 if (!empty($conf->expedition->dir_output)) {
1566 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1567 $file = $dir.
'/'.$ref.
'.pdf';
1568 if (file_exists($file)) {
1573 if (file_exists($dir)) {
1575 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1583 $this->db->rollback();
1587 $this->error = $this->db->lasterror().
" - sql=$sql";
1588 $this->db->rollback();
1592 $this->error = $this->db->lasterror().
" - sql=$sql";
1593 $this->db->rollback();
1597 $this->error = $this->db->lasterror().
" - sql=$sql";
1598 $this->db->rollback();
1602 $this->db->rollback();
1618 $this->lines = array();
1623 $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";
1624 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1625 $sql .=
", cd.fk_remise_except, cd.fk_product_fournisseur_price as fk_fournprice";
1626 $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";
1627 $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";
1628 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_element, ed.fk_elementdet, ed.element_type, ed.fk_entrepot";
1629 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
1630 $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";
1631 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
1632 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
1633 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1634 $sql .=
" AND ed.fk_elementdet = cd.rowid";
1635 $sql .=
" ORDER BY cd.rang, ed.fk_elementdet";
1637 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1638 $resql = $this->db->query($sql);
1640 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1642 $num = $this->db->num_rows($resql);
1647 $this->total_ht = 0;
1648 $this->total_tva = 0;
1649 $this->total_ttc = 0;
1650 $this->total_localtax1 = 0;
1651 $this->total_localtax2 = 0;
1653 $this->multicurrency_total_ht = 0;
1654 $this->multicurrency_total_tva = 0;
1655 $this->multicurrency_total_ttc = 0;
1660 $obj = $this->db->fetch_object($resql);
1663 if ($originline > 0 && $originline == $obj->fk_elementdet) {
1664 '@phan-var-force ExpeditionLigne $line';
1665 $line->entrepot_id = 0;
1666 $line->qty_shipped += $obj->qty_shipped;
1669 $line->entrepot_id = $obj->fk_entrepot;
1670 $line->qty_shipped = $obj->qty_shipped;
1674 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
1675 $detail_entrepot->qty_shipped = $obj->qty_shipped;
1676 $detail_entrepot->line_id = $obj->line_id;
1677 $line->details_entrepot[] = $detail_entrepot;
1679 $line->line_id = $obj->line_id;
1680 $line->rowid = $obj->line_id;
1681 $line->id = $obj->line_id;
1683 $line->fk_origin =
'orderline';
1685 $line->fk_element = $obj->fk_element;
1686 $line->origin_id = $obj->fk_element;
1687 $line->fk_elementdet = $obj->fk_elementdet;
1688 $line->origin_line_id = $obj->fk_elementdet;
1689 $line->element_type = $obj->element_type;
1691 $line->fk_expedition = $this->id;
1693 $line->product_type = $obj->product_type;
1694 $line->fk_product = $obj->fk_product;
1695 $line->fk_product_type = $obj->fk_product_type;
1696 $line->ref = $obj->product_ref;
1697 $line->product_ref = $obj->product_ref;
1698 $line->product_label = $obj->product_label;
1699 $line->libelle = $obj->product_label;
1700 $line->product_barcode = $obj->product_barcode;
1701 $line->product_tosell = $obj->product_tosell;
1702 $line->product_tobuy = $obj->product_tobuy;
1703 $line->product_tobatch = $obj->product_tobatch;
1704 $line->fk_fournprice = $obj->fk_fournprice;
1705 $line->label = $obj->custom_label;
1706 $line->description = $obj->description;
1707 $line->qty_asked = $obj->qty_asked;
1708 $line->rang = $obj->rang;
1709 $line->weight = $obj->weight;
1710 $line->weight_units = $obj->weight_units;
1711 $line->length = $obj->length;
1712 $line->length_units = $obj->length_units;
1713 $line->width = $obj->width;
1714 $line->width_units = $obj->width_units;
1715 $line->height = $obj->height;
1716 $line->height_units = $obj->height_units;
1717 $line->surface = $obj->surface;
1718 $line->surface_units = $obj->surface_units;
1719 $line->volume = $obj->volume;
1720 $line->volume_units = $obj->volume_units;
1721 $line->fk_unit = $obj->fk_unit;
1723 $line->pa_ht = $obj->pa_ht;
1726 $localtax_array = array(0 => $obj->localtax1_type, 1 => $obj->localtax1_tx, 2 => $obj->localtax2_type, 3 => $obj->localtax2_tx);
1727 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
1728 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
1731 $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);
1732 $line->desc = $obj->description;
1733 $line->qty = $line->qty_shipped;
1734 $line->total_ht = $tabprice[0];
1735 $line->total_localtax1 = $tabprice[9];
1736 $line->total_localtax2 = $tabprice[10];
1737 $line->total_ttc = $tabprice[2];
1738 $line->total_tva = $tabprice[1];
1739 $line->vat_src_code = $obj->vat_src_code;
1740 $line->tva_tx = $obj->tva_tx;
1741 $line->localtax1_tx = $obj->localtax1_tx;
1742 $line->localtax2_tx = $obj->localtax2_tx;
1743 $line->info_bits = $obj->info_bits;
1744 $line->price = $obj->price;
1745 $line->subprice = $obj->subprice;
1746 $line->fk_remise_except = $obj->fk_remise_except;
1747 $line->remise_percent = $obj->remise_percent;
1749 $this->total_ht += $tabprice[0];
1750 $this->total_tva += $tabprice[1];
1751 $this->total_ttc += $tabprice[2];
1752 $this->total_localtax1 += $tabprice[9];
1753 $this->total_localtax2 += $tabprice[10];
1755 $line->date_start = $this->db->jdate($obj->date_start);
1756 $line->date_end = $this->db->jdate($obj->date_end);
1759 $this->fk_multicurrency = $obj->fk_multicurrency;
1760 $this->multicurrency_code = $obj->multicurrency_code;
1761 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1762 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1763 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1764 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1766 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
1767 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
1768 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
1770 if ($originline != $obj->fk_elementdet) {
1771 $line->detail_batch = array();
1775 if (isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
1776 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
1778 if (is_array($newdetailbatch)) {
1779 if ($originline != $obj->fk_elementdet) {
1780 $line->detail_batch = $newdetailbatch;
1782 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1787 $line->fetch_optionals();
1789 if ($originline != $obj->fk_elementdet) {
1790 $this->lines[$lineindex] = $line;
1793 $line->total_ht += $tabprice[0];
1794 $line->total_localtax1 += $tabprice[9];
1795 $line->total_localtax2 += $tabprice[10];
1796 $line->total_ttc += $tabprice[2];
1797 $line->total_tva += $tabprice[1];
1801 $originline = $obj->fk_elementdet;
1803 $this->db->free($resql);
1806 $this->error = $this->db->error();
1822 if ($this->
statut == self::STATUS_DRAFT) {
1828 $line->fetch($lineid);
1830 if ($line->delete($user) > 0) {
1833 $this->db->commit();
1836 $this->db->rollback();
1840 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1855 global $conf, $langs;
1857 $langs->load(
'sendings');
1859 $nofetch = !empty($params[
'nofetch']);
1862 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
1863 if (isset($this->
statut)) {
1864 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1866 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1867 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1869 $langs->load(
'companies');
1870 if (empty($this->thirdparty)) {
1873 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1890 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1892 global $langs, $hookmanager;
1897 'objecttype' => $this->element,
1898 'option' => $option,
1901 $classfortooltip =
'classfortooltip';
1904 $classfortooltip =
'classforajaxtooltip';
1905 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1911 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
1917 if ($option !==
'nolink') {
1919 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1920 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1921 $add_save_lastsearch_values = 1;
1923 if ($add_save_lastsearch_values) {
1924 $url .=
'&save_lastsearch_values=1';
1929 if (empty($notooltip)) {
1931 $label = $langs->trans(
"Shipment");
1932 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1934 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1935 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1938 $linkstart =
'<a href="'.$url.
'"';
1939 $linkstart .= $linkclose.
'>';
1942 $result .= $linkstart;
1944 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1946 if ($withpicto != 2) {
1947 $result .= $this->ref;
1949 $result .= $linkend;
1951 $hookmanager->initHooks(array($this->element .
'dao'));
1952 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1953 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1955 $result = $hookmanager->resPrint;
1957 $result .= $hookmanager->resPrint;
1986 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1987 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1989 $statusType =
'status'.$status;
1990 if ($status == self::STATUS_VALIDATED) {
1991 $statusType =
'status4';
1993 if ($status == self::STATUS_CLOSED) {
1994 $statusType =
'status6';
1996 if ($status == self::STATUS_CANCELED) {
1997 $statusType =
'status9';
2000 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
2012 global $langs, $conf;
2014 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2016 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2017 $return .=
'<div class="info-box info-box-sm">';
2018 $return .=
'<div class="info-box-icon bg-infobox-action">';
2020 $return .=
'</div>';
2021 $return .=
'<div class="info-box-content">';
2022 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2023 if ($selected >= 0) {
2024 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2026 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2027 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2029 if (property_exists($this,
'total_ht')) {
2030 $return .=
'<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).
' '.$langs->trans(
'HT').
'</div>';
2032 if (method_exists($this,
'getLibStatut')) {
2033 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2035 $return .=
'</div>';
2036 $return .=
'</div>';
2037 $return .=
'</div>';
2055 dol_syslog(get_class($this).
"::initAsSpecimen");
2058 $order->initAsSpecimen();
2062 $this->
ref =
'SPECIMEN';
2063 $this->specimen = 1;
2065 $this->livraison_id = 0;
2067 $this->date_creation = $now;
2068 $this->date_valid = $now;
2069 $this->date_delivery = $now + 24 * 3600;
2070 $this->date_expedition = $now + 24 * 3600;
2072 $this->entrepot_id = 0;
2073 $this->fk_delivery_address = 0;
2076 $this->commande_id = 0;
2077 $this->commande = $order;
2079 $this->origin_id = 1;
2080 $this->origin =
'commande';
2082 $this->note_private =
'Private note';
2083 $this->note_public =
'Public note';
2087 while ($xnbp < $nbp) {
2089 $line->product_desc = $langs->trans(
"Description").
" ".$xnbp;
2090 $line->product_label = $langs->trans(
"Description").
" ".$xnbp;
2092 $line->qty_asked = 5;
2093 $line->qty_shipped = 4;
2094 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
2096 $this->lines[] = $line;
2127 if ($user->hasRight(
'expedition',
'creer')) {
2128 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2129 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2130 $sql .=
" WHERE rowid = ".((int) $this->
id);
2132 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2133 $resql = $this->db->query($sql);
2135 $this->date_delivery = $delivery_date;
2138 $this->error = $this->db->error();
2156 $this->meths = array();
2158 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2159 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2160 $sql .=
" WHERE em.active = 1";
2161 $sql .=
" ORDER BY em.libelle ASC";
2163 $resql = $this->db->query($sql);
2165 while ($obj = $this->db->fetch_object($resql)) {
2166 $label = $langs->trans(
'SendingMethod'.$obj->code);
2167 $this->meths[$obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2184 $this->listmeths = array();
2187 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2188 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2190 $sql .=
" WHERE em.rowid=".((int) $id);
2193 $resql = $this->db->query($sql);
2195 while ($obj = $this->db->fetch_object($resql)) {
2196 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2197 $this->listmeths[$i][
'code'] = $obj->code;
2198 $label = $langs->trans(
'SendingMethod'.$obj->code);
2199 $this->listmeths[$i][
'libelle'] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2200 $this->listmeths[$i][
'description'] = $obj->description;
2201 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2202 $this->listmeths[$i][
'active'] = $obj->active;
2216 if (!empty($this->shipping_method_id)) {
2217 $sql =
"SELECT em.code, em.tracking";
2218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2219 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2221 $resql = $this->db->query($sql);
2223 if ($obj = $this->db->fetch_object($resql)) {
2224 $tracking = $obj->tracking;
2229 if (!empty($tracking) && !empty($value)) {
2230 $url = str_replace(
'{TRACKID}', $value, $tracking);
2231 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
2233 $this->tracking_url = $value;
2249 if ($this->
statut == self::STATUS_CLOSED) {
2256 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
2258 $resql = $this->db->query($sql);
2261 if ($this->origin ==
'commande' && $this->origin_id > 0) {
2263 $order->fetch($this->origin_id);
2265 $order->loadExpeditions(self::STATUS_CLOSED);
2267 $shipments_match_order = 1;
2268 foreach ($order->lines as $line) {
2269 $lineid = $line->id;
2271 if (($line->product_type == 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) {
2272 $shipments_match_order = 0;
2273 $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';
2278 if ($shipments_match_order) {
2279 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');
2281 $order->cloture($user);
2289 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2298 $result = $this->
call_trigger(
'SHIPPING_CLOSED', $user);
2309 $this->db->commit();
2315 $this->db->rollback();
2335 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
2337 $langs->load(
"agenda");
2340 $sql =
"SELECT cd.fk_product, cd.subprice,";
2341 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2343 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock,";
2344 $sql .=
" cd.rowid as cdid, ed.rowid as edid";
2345 $sql .=
" FROM " . MAIN_DB_PREFIX .
"commandedet as cd,";
2346 $sql .=
" " . MAIN_DB_PREFIX .
"expeditiondet as ed";
2347 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2348 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"expedition as e ON ed.fk_expedition = e.rowid";
2349 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
2350 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2352 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
2353 $resql = $this->db->query($sql);
2355 $cpt = $this->db->num_rows($resql);
2356 for ($i = 0; $i < $cpt; $i++) {
2357 $obj = $this->db->fetch_object($resql);
2358 if (empty($obj->edbrowid)) {
2361 $qty = $obj->edbqty;
2363 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
2366 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->rowid .
" edb.rowid=" . $obj->edbrowid);
2369 $mouvS->origin = &$this;
2370 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
2372 if (empty($obj->edbrowid)) {
2376 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref));
2378 $this->error = $mouvS->error;
2379 $this->errors = $mouvS->errors;
2387 $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);
2389 $this->error = $mouvS->error;
2390 $this->errors = $mouvS->errors;
2398 $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)";
2399 $resqldelete = $this->db->query($sqldelete);
2403 $this->error = $this->db->lasterror();
2404 $this->errors[] = $this->db->lasterror();
2423 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET billed = 1';
2424 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2426 $resql = $this->db->query($sql);
2431 $result = $this->
call_trigger(
'SHIPPING_BILLED', $user);
2438 $this->errors[] = $this->db->lasterror;
2441 if (empty($error)) {
2442 $this->db->commit();
2445 $this->db->rollback();
2460 if ($this->
statut <= self::STATUS_DRAFT) {
2464 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
2474 global $langs, $user;
2479 if ($this->
statut == self::STATUS_VALIDATED) {
2485 $oldbilled = $this->billed;
2487 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
2488 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2490 $resql = $this->db->query($sql);
2497 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2498 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2500 $langs->load(
"agenda");
2504 $sql =
"SELECT cd.fk_product, cd.subprice,";
2505 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2506 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2507 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2508 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2509 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2510 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2511 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2513 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2514 $resql = $this->db->query($sql);
2516 $cpt = $this->db->num_rows($resql);
2517 for ($i = 0; $i < $cpt; $i++) {
2518 $obj = $this->db->fetch_object($resql);
2519 if (empty($obj->edbrowid)) {
2522 $qty = $obj->edbqty;
2527 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2531 $mouvS->origin = &$this;
2532 $mouvS->setOrigin($this->element, $this->
id);
2534 if (empty($obj->edbrowid)) {
2538 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
2540 $this->error = $mouvS->error;
2541 $this->errors = $mouvS->errors;
2549 $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);
2551 $this->error = $mouvS->error;
2552 $this->errors = $mouvS->errors;
2559 $this->error = $this->db->lasterror();
2566 $result = $this->
call_trigger(
'SHIPPING_REOPEN', $user);
2573 $this->errors[] = $this->db->lasterror();
2577 $this->db->commit();
2582 $this->billed = $oldbilled;
2583 $this->db->rollback();
2599 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2601 $outputlangs->load(
"products");
2606 if (!empty($this->model_pdf)) {
2607 $modele = $this->model_pdf;
2613 $modelpath =
"core/modules/expedition/doc/";
2617 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2647 public $element =
'expeditiondet';
2652 public $table_element =
'expeditiondet';
2685 public $fk_elementdet;
2690 public $origin_line_id;
2695 public $element_type;
2709 public $fk_expedition;
2724 public $qty_shipped;
2733 public $detail_batch;
2737 public $details_entrepot;
2743 public $entrepot_id;
2760 public $product_ref;
2771 public $product_label;
2783 public $product_desc;
2789 public $product_type = 0;
2800 public $weight_units;
2806 public $length_units;
2812 public $width_units;
2818 public $height_units;
2824 public $surface_units;
2830 public $volume_units;
2833 public $remise_percent;
2854 public $total_localtax1;
2859 public $total_localtax2;
2880 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_elementdet, ed.element_type, ed.qty, ed.rang';
2881 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as ed';
2882 $sql .=
' WHERE ed.rowid = '.((int) $rowid);
2883 $result = $this->db->query($sql);
2885 $objp = $this->db->fetch_object($result);
2886 $this->
id = $objp->rowid;
2887 $this->fk_expedition = $objp->fk_expedition;
2888 $this->entrepot_id = $objp->fk_entrepot;
2889 $this->fk_elementdet = $objp->fk_elementdet;
2890 $this->element_type = $objp->element_type;
2891 $this->qty = $objp->qty;
2892 $this->rang = $objp->rang;
2894 $this->db->free($result);
2898 $this->errors[] = $this->db->lasterror();
2899 $this->error = $this->db->lasterror();
2911 public function insert($user, $notrigger = 0)
2916 if (empty($this->fk_expedition) || empty($this->fk_elementdet) || !is_numeric($this->qty)) {
2917 $this->error =
'ErrorMandatoryParametersNotProvided';
2923 if (empty($this->rang)) {
2928 $ranktouse = $this->rang;
2929 if ($ranktouse == -1) {
2930 $rangmax = $this->
line_max($this->fk_expedition);
2931 $ranktouse = $rangmax + 1;
2934 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expeditiondet (";
2935 $sql .=
"fk_expedition";
2936 $sql .=
", fk_entrepot";
2937 $sql .=
", fk_elementdet";
2938 $sql .=
", element_type";
2941 $sql .=
") VALUES (";
2942 $sql .= $this->fk_expedition;
2943 $sql .=
", ".(empty($this->entrepot_id) ?
'NULL' : $this->entrepot_id);
2944 $sql .=
", ".((int) $this->fk_elementdet);
2945 $sql .=
", '".(empty($this->element_type) ?
'order' : $this->db->escape($this->element_type)).
"'";
2946 $sql .=
", ".price2num($this->qty,
'MS');
2947 $sql .=
", ".((int) $ranktouse);
2950 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2951 $resql = $this->db->query($sql);
2953 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expeditiondet");
2962 if (!$error && !$notrigger) {
2964 $result = $this->
call_trigger(
'LINESHIPPING_INSERT', $user);
2972 foreach ($this->errors as $errmsg) {
2973 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2974 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2982 $this->db->rollback();
2985 $this->db->commit();
2997 public function delete($user =
null, $notrigger = 0)
3004 if (isModEnabled(
'productbatch')) {
3005 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3006 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3008 if (!$this->db->query($sql)) {
3009 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3014 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
3015 $sql .=
" WHERE rowid = ".((int) $this->
id);
3017 if (!$error && $this->db->query($sql)) {
3022 $this->errors[] = $this->error;
3026 if (!$error && !$notrigger) {
3028 $result = $this->
call_trigger(
'LINESHIPPING_DELETE', $user);
3030 $this->errors[] = $this->error;
3036 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3041 $this->db->commit();
3044 foreach ($this->errors as $errmsg) {
3045 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3046 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3048 $this->db->rollback();
3060 public function update($user =
null, $notrigger = 0)
3064 dol_syslog(get_class($this).
"::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
3069 if (empty($this->qty)) {
3076 $expedition_batch_id =
null;
3077 if (is_array($this->detail_batch)) {
3078 if (count($this->detail_batch) > 1) {
3079 dol_syslog(get_class($this).
'::update only possible for one batch', LOG_ERR);
3080 $this->errors[] =
'ErrorBadParameters';
3083 $batch = $this->detail_batch[0]->batch;
3084 $batch_id = $this->detail_batch[0]->fk_origin_stock;
3085 $expedition_batch_id = $this->detail_batch[0]->id;
3086 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) {
3087 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3088 $this->errors[] =
'ErrorBadParameters';
3091 $qty =
price2num($this->detail_batch[0]->qty);
3093 } elseif (!empty($this->detail_batch)) {
3094 $batch = $this->detail_batch->batch;
3095 $batch_id = $this->detail_batch->fk_origin_stock;
3096 $expedition_batch_id = $this->detail_batch->id;
3097 if ($this->entrepot_id != $this->detail_batch->entrepot_id) {
3098 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3099 $this->errors[] =
'ErrorBadParameters';
3102 $qty =
price2num($this->detail_batch->qty);
3106 if (!isset($this->
id) || !isset($this->entrepot_id)) {
3107 dol_syslog(get_class($this).
'::update missing line id and/or warehouse id', LOG_ERR);
3108 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3115 if (!empty($batch) && isModEnabled(
'productbatch')) {
3116 $batch_id_str = $batch_id ??
'null';
3117 dol_syslog(get_class($this).
"::update expedition batch id=$expedition_batch_id, batch_id=$batch_id_str, batch=$batch");
3119 if (empty($batch_id) || empty($this->fk_product)) {
3120 dol_syslog(get_class($this).
'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
3121 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3128 if (!$error && ($lotArray = $shipmentlinebatch->fetchAll($this->id)) < 0) {
3129 $this->errors[] = $this->db->lasterror().
" - ExpeditionLineBatch::fetchAll";
3133 foreach ($lotArray as $lot) {
3134 if ($expedition_batch_id != $lot->id) {
3135 $remainingQty += $lot->qty;
3138 $qty += $remainingQty;
3143 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
3145 if ($lot->fetch(0, $this->fk_product, $batch) < 0) {
3146 $this->errors[] = $lot->errors;
3149 if (!$error && !empty($expedition_batch_id)) {
3151 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3152 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3153 $sql .=
" AND rowid = ".((int) $expedition_batch_id);
3155 if (!$this->db->query($sql)) {
3156 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3160 if (!$error && $this->detail_batch->qty > 0) {
3162 if (isset($lot->id)) {
3164 $shipmentLot->batch = $lot->batch;
3165 $shipmentLot->eatby = $lot->eatby;
3166 $shipmentLot->sellby = $lot->sellby;
3167 $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
3168 $shipmentLot->qty = $this->detail_batch->qty;
3169 $shipmentLot->fk_origin_stock = $batch_id;
3170 if ($shipmentLot->create($this->id) < 0) {
3171 $this->errors = $shipmentLot->errors;
3180 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3181 $sql .=
" fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id :
'null');
3182 $sql .=
" , qty = ".((float)
price2num($qty,
'MS'));
3183 $sql .=
" WHERE rowid = ".((int) $this->
id);
3185 if (!$this->db->query($sql)) {
3186 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3194 $this->errors[] = $this->error;
3199 if (!$error && !$notrigger) {
3201 $result = $this->
call_trigger(
'LINESHIPPING_MODIFY', $user);
3203 $this->errors[] = $this->error;
3209 $this->db->commit();
3212 foreach ($this->errors as $errmsg) {
3213 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3214 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3216 $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