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')) {
818 if (!$error && !$notrigger) {
820 $result = $this->
call_trigger(
'SHIPPING_VALIDATE', $user);
828 $this->oldref = $this->ref;
831 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
833 $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).
"'";
834 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
835 $resql = $this->db->query($sql);
838 $this->error = $this->db->lasterror();
840 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
841 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
842 $resql = $this->db->query($sql);
845 $this->error = $this->db->lasterror();
851 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
852 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
853 if (!$error && file_exists($dirsource)) {
854 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
856 if (@rename($dirsource, $dirdest)) {
859 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
860 foreach ($listoffiles as $fileentry) {
861 $dirsource = $fileentry[
'name'];
862 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
863 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
864 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
865 @rename($dirsource, $dirdest);
874 $this->
ref = $numref;
883 $this->db->rollback();
902 if ($this->
statut == self::STATUS_VALIDATED || $this->
statut == self::STATUS_CLOSED) {
904 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
905 $delivery =
new Delivery($this->db);
906 $result = $delivery->create_from_sending($user, $this->
id);
910 $this->error = $delivery->error;
933 public function addline($entrepot_id, $id, $qty, $array_options = [])
935 global $conf, $langs;
937 $num = count($this->lines);
940 $line->entrepot_id = $entrepot_id;
941 $line->origin_line_id = $id;
942 $line->fk_elementdet = $id;
943 $line->element_type =
'order';
947 $orderline->fetch($id);
950 $line->rang = $orderline->rang;
951 $line->product_type = $orderline->product_type;
953 if (isModEnabled(
'stock') && !empty($orderline->fk_product)) {
954 $fk_product = $orderline->fk_product;
957 $langs->load(
"errors");
958 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
963 $product =
new Product($this->db);
964 $product->fetch($fk_product);
967 if ($entrepot_id > 0) {
968 $product->load_stock(
'warehouseopen');
969 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
971 $product_stock = $product->stock_reel;
974 $product_type = $product->type;
976 $isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
979 if ($product_stock < $qty) {
980 $langs->load(
"errors");
981 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
982 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
984 $this->db->rollback();
994 if (isModEnabled(
'productbatch') && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) {
995 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$orderline->fk_product;
1000 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1001 $line->array_options = $array_options;
1004 $this->lines[$num] = $line;
1020 global $conf, $langs;
1022 $num = count($this->lines);
1023 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1026 foreach ($dbatch[
'detail'] as $key => $value) {
1027 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1033 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1038 $linebatch->qty = $value[
'q'];
1039 if ($linebatch->qty == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
1040 $linebatch->batch =
null;
1042 $tab[] = $linebatch;
1045 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1047 $prod_batch->fetch($value[
'id_batch']);
1049 if ($prod_batch->qty < $linebatch->qty) {
1050 $langs->load(
"errors");
1051 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1052 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1053 $this->db->rollback();
1061 $line->entrepot_id = $linebatch->entrepot_id;
1062 $line->origin_line_id = $dbatch[
'ix_l'];
1063 $line->fk_elementdet = $dbatch[
'ix_l'];
1064 $line->qty = $dbatch[
'qty'];
1065 $line->detail_batch = $tab;
1068 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1069 $line->array_options = $array_options;
1073 $this->lines[$num] = $line;
1086 public function update($user =
null, $notrigger = 0)
1093 if (isset($this->
ref)) {
1094 $this->
ref = trim($this->
ref);
1096 if (isset($this->entity)) {
1097 $this->entity = (int) $this->entity;
1099 if (isset($this->ref_customer)) {
1100 $this->ref_customer = trim($this->ref_customer);
1102 if (isset($this->socid)) {
1103 $this->socid = (int) $this->socid;
1105 if (isset($this->fk_user_author)) {
1106 $this->fk_user_author = (int) $this->fk_user_author;
1108 if (isset($this->fk_user_valid)) {
1109 $this->fk_user_valid = (int) $this->fk_user_valid;
1111 if (isset($this->fk_delivery_address)) {
1112 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1114 if (isset($this->shipping_method_id)) {
1115 $this->shipping_method_id = (int) $this->shipping_method_id;
1117 if (isset($this->tracking_number)) {
1118 $this->tracking_number = trim($this->tracking_number);
1120 if (isset($this->
statut)) {
1123 if (isset($this->trueDepth)) {
1124 $this->trueDepth = trim($this->trueDepth);
1126 if (isset($this->trueWidth)) {
1127 $this->trueWidth = trim($this->trueWidth);
1129 if (isset($this->trueHeight)) {
1130 $this->trueHeight = trim($this->trueHeight);
1132 if (isset($this->size_units)) {
1133 $this->size_units = trim($this->size_units);
1135 if (isset($this->weight_units)) {
1136 $this->weight_units = trim($this->weight_units);
1138 if (isset($this->trueWeight)) {
1139 $this->weight = trim((
string) $this->trueWeight);
1141 if (isset($this->note_private)) {
1142 $this->note_private = trim($this->note_private);
1144 if (isset($this->note_public)) {
1145 $this->note_public = trim($this->note_public);
1147 if (isset($this->model_pdf)) {
1148 $this->model_pdf = trim($this->model_pdf);
1155 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1156 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1157 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1158 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1159 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1160 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1161 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1162 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1163 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1164 $sql .=
" date_expedition=".(dol_strlen($this->date_expedition) != 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
'null').
",";
1165 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1166 $sql .=
" fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address :
"null").
",";
1167 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1168 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1169 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1170 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1171 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1172 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1173 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1174 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1175 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1176 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1177 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1178 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1179 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1180 $sql .=
" entity=".$conf->entity;
1181 $sql .=
" WHERE rowid=".((int) $this->
id);
1185 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1186 $resql = $this->db->query($sql);
1189 $this->errors[] =
"Error ".$this->db->lasterror();
1192 if (!$error && !$notrigger) {
1194 $result = $this->
call_trigger(
'SHIPPING_MODIFY', $user);
1203 foreach ($this->errors as $errmsg) {
1204 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1205 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1207 $this->db->rollback();
1210 $this->db->commit();
1223 public function cancel($notrigger = 0, $also_update_stock =
false)
1225 global $conf, $langs, $user;
1227 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1236 if (count($this->linkedObjectsIds) > 0) {
1237 $this->error =
'ErrorThereIsSomeDeliveries';
1241 if (!$error && !$notrigger) {
1243 $result = $this->
call_trigger(
'SHIPPING_CANCEL', $user);
1251 if (!$error && isModEnabled(
'stock') &&
1253 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
statut == self::STATUS_CLOSED && $also_update_stock))) {
1254 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1256 $langs->load(
"agenda");
1259 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1261 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1262 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1263 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1265 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1266 $resql = $this->db->query($sql);
1268 $cpt = $this->db->num_rows($resql);
1272 for ($i = 0; $i < $cpt; $i++) {
1273 dol_syslog(get_class($this).
"::delete movement index ".$i);
1274 $obj = $this->db->fetch_object($resql);
1278 $mouvS->origin =
'';
1281 if (isModEnabled(
'productbatch')) {
1282 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1283 if (!is_array($lotArray)) {
1285 $this->errors[] =
"Error ".$this->db->lasterror();
1289 if (empty($lotArray)) {
1293 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref));
1296 $this->errors = array_merge($this->errors, $mouvS->errors);
1302 foreach ($lotArray as $lot) {
1303 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1306 $this->errors = array_merge($this->errors, $mouvS->errors);
1317 $this->errors[] =
"Error ".$this->db->lasterror();
1322 if (!$error && isModEnabled(
'productbatch')) {
1324 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1326 $this->errors[] =
"Error ".$this->db->lasterror();
1332 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1333 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1335 if ($this->db->query($sql)) {
1344 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"expedition";
1345 $sql .=
" WHERE rowid = ".((int) $this->
id);
1347 if ($this->db->query($sql)) {
1348 if (!empty($this->origin) && $this->origin_id > 0) {
1352 $this->origin_object->loadExpeditions();
1354 if (count($this->origin_object->expeditions) <= 0) {
1361 $this->db->commit();
1365 if (!empty($conf->expedition->dir_output)) {
1366 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1367 $file = $dir.
'/'.$ref.
'.pdf';
1368 if (file_exists($file)) {
1373 if (file_exists($dir)) {
1375 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
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->error = $this->db->lasterror().
" - sql=$sql";
1398 $this->db->rollback();
1402 $this->db->rollback();
1416 public function delete($user =
null, $notrigger = 0, $also_update_stock =
false)
1418 global $conf, $langs;
1424 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1433 if (count($this->linkedObjectsIds) > 0) {
1434 $this->error =
'ErrorThereIsSomeDeliveries';
1438 if (!$error && !$notrigger) {
1440 $result = $this->
call_trigger(
'SHIPPING_DELETE', $user);
1448 if (!$error && isModEnabled(
'stock') &&
1450 (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') && $this->
statut == self::STATUS_CLOSED && $also_update_stock))) {
1451 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1453 $langs->load(
"agenda");
1459 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1460 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1461 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1462 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1463 $sql .=
" AND cd.rowid = ed.fk_elementdet";
1465 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1466 $resql = $this->db->query($sql);
1468 $cpt = $this->db->num_rows($resql);
1469 for ($i = 0; $i < $cpt; $i++) {
1470 dol_syslog(get_class($this).
"::delete movement index ".$i);
1471 $obj = $this->db->fetch_object($resql);
1475 $mouvS->origin =
'';
1477 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1478 if (!is_array($lotArray)) {
1480 $this->errors[] =
"Error ".$this->db->lasterror();
1482 if (empty($lotArray)) {
1486 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref));
1489 $this->errors = array_merge($this->errors, $mouvS->errors);
1495 foreach ($lotArray as $lot) {
1496 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1499 $this->errors = array_merge($this->errors, $mouvS->errors);
1510 $this->errors[] =
"Error ".$this->db->lasterror();
1517 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1519 $this->errors[] =
"Error ".$this->db->lasterror();
1524 $main = MAIN_DB_PREFIX.
'expeditiondet';
1525 $ef = $main.
"_extrafields";
1526 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".((int) $this->
id).
")";
1528 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1529 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1531 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1545 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expedition";
1546 $sql .=
" WHERE rowid = ".((int) $this->
id);
1548 if ($this->db->query($sql)) {
1549 if (!empty($this->origin) && $this->origin_id > 0) {
1553 $this->origin_object->loadExpeditions();
1555 if (count($this->origin_object->expeditions) <= 0) {
1562 $this->db->commit();
1570 if (!empty($conf->expedition->dir_output)) {
1571 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1572 $file = $dir.
'/'.$ref.
'.pdf';
1573 if (file_exists($file)) {
1578 if (file_exists($dir)) {
1580 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
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->error = $this->db->lasterror().
" - sql=$sql";
1603 $this->db->rollback();
1607 $this->db->rollback();
1623 $this->lines = array();
1628 $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";
1629 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1630 $sql .=
", cd.fk_remise_except, cd.fk_product_fournisseur_price as fk_fournprice";
1631 $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";
1632 $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";
1633 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_element, ed.fk_elementdet, ed.element_type, ed.fk_entrepot";
1634 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
1635 $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";
1636 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
1637 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
1638 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1639 $sql .=
" AND ed.fk_elementdet = cd.rowid";
1640 $sql .=
" ORDER BY cd.rang, ed.fk_elementdet";
1642 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1643 $resql = $this->db->query($sql);
1645 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1647 $num = $this->db->num_rows($resql);
1652 $this->total_ht = 0;
1653 $this->total_tva = 0;
1654 $this->total_ttc = 0;
1655 $this->total_localtax1 = 0;
1656 $this->total_localtax2 = 0;
1658 $this->multicurrency_total_ht = 0;
1659 $this->multicurrency_total_tva = 0;
1660 $this->multicurrency_total_ttc = 0;
1665 $obj = $this->db->fetch_object($resql);
1668 if ($originline > 0 && $originline == $obj->fk_elementdet) {
1669 '@phan-var-force ExpeditionLigne $line';
1670 $line->entrepot_id = 0;
1671 $line->qty_shipped += $obj->qty_shipped;
1674 $line->entrepot_id = $obj->fk_entrepot;
1675 $line->qty_shipped = $obj->qty_shipped;
1679 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
1680 $detail_entrepot->qty_shipped = $obj->qty_shipped;
1681 $detail_entrepot->line_id = $obj->line_id;
1682 $line->details_entrepot[] = $detail_entrepot;
1684 $line->line_id = $obj->line_id;
1685 $line->rowid = $obj->line_id;
1686 $line->id = $obj->line_id;
1688 $line->fk_origin =
'orderline';
1690 $line->fk_element = $obj->fk_element;
1691 $line->origin_id = $obj->fk_element;
1692 $line->fk_elementdet = $obj->fk_elementdet;
1693 $line->origin_line_id = $obj->fk_elementdet;
1694 $line->element_type = $obj->element_type;
1696 $line->fk_expedition = $this->id;
1698 $line->product_type = $obj->product_type;
1699 $line->fk_product = $obj->fk_product;
1700 $line->fk_product_type = $obj->fk_product_type;
1701 $line->ref = $obj->product_ref;
1702 $line->product_ref = $obj->product_ref;
1703 $line->product_label = $obj->product_label;
1704 $line->libelle = $obj->product_label;
1705 $line->product_barcode = $obj->product_barcode;
1706 $line->product_tosell = $obj->product_tosell;
1707 $line->product_tobuy = $obj->product_tobuy;
1708 $line->product_tobatch = $obj->product_tobatch;
1709 $line->fk_fournprice = $obj->fk_fournprice;
1710 $line->label = $obj->custom_label;
1711 $line->description = $obj->description;
1712 $line->qty_asked = $obj->qty_asked;
1713 $line->rang = $obj->rang;
1714 $line->weight = $obj->weight;
1715 $line->weight_units = $obj->weight_units;
1716 $line->length = $obj->length;
1717 $line->length_units = $obj->length_units;
1718 $line->width = $obj->width;
1719 $line->width_units = $obj->width_units;
1720 $line->height = $obj->height;
1721 $line->height_units = $obj->height_units;
1722 $line->surface = $obj->surface;
1723 $line->surface_units = $obj->surface_units;
1724 $line->volume = $obj->volume;
1725 $line->volume_units = $obj->volume_units;
1726 $line->fk_unit = $obj->fk_unit;
1728 $line->pa_ht = $obj->pa_ht;
1731 $localtax_array = array(0 => $obj->localtax1_type, 1 => $obj->localtax1_tx, 2 => $obj->localtax2_type, 3 => $obj->localtax2_tx);
1732 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
1733 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
1736 $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);
1737 $line->desc = $obj->description;
1738 $line->qty = $line->qty_shipped;
1739 $line->total_ht = $tabprice[0];
1740 $line->total_localtax1 = $tabprice[9];
1741 $line->total_localtax2 = $tabprice[10];
1742 $line->total_ttc = $tabprice[2];
1743 $line->total_tva = $tabprice[1];
1744 $line->vat_src_code = $obj->vat_src_code;
1745 $line->tva_tx = $obj->tva_tx;
1746 $line->localtax1_tx = $obj->localtax1_tx;
1747 $line->localtax2_tx = $obj->localtax2_tx;
1748 $line->info_bits = $obj->info_bits;
1749 $line->price = $obj->price;
1750 $line->subprice = $obj->subprice;
1751 $line->fk_remise_except = $obj->fk_remise_except;
1752 $line->remise_percent = $obj->remise_percent;
1754 $this->total_ht += $tabprice[0];
1755 $this->total_tva += $tabprice[1];
1756 $this->total_ttc += $tabprice[2];
1757 $this->total_localtax1 += $tabprice[9];
1758 $this->total_localtax2 += $tabprice[10];
1760 $line->date_start = $this->db->jdate($obj->date_start);
1761 $line->date_end = $this->db->jdate($obj->date_end);
1764 $this->fk_multicurrency = $obj->fk_multicurrency;
1765 $this->multicurrency_code = $obj->multicurrency_code;
1766 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1767 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1768 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1769 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1771 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
1772 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
1773 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
1775 if ($originline != $obj->fk_elementdet) {
1776 $line->detail_batch = array();
1780 if (isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
1781 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
1783 if (is_array($newdetailbatch)) {
1784 if ($originline != $obj->fk_elementdet) {
1785 $line->detail_batch = $newdetailbatch;
1787 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1792 $line->fetch_optionals();
1794 if ($originline != $obj->fk_elementdet) {
1795 $this->lines[$lineindex] = $line;
1798 $line->total_ht += $tabprice[0];
1799 $line->total_localtax1 += $tabprice[9];
1800 $line->total_localtax2 += $tabprice[10];
1801 $line->total_ttc += $tabprice[2];
1802 $line->total_tva += $tabprice[1];
1806 $originline = $obj->fk_elementdet;
1808 $this->db->free($resql);
1811 $this->error = $this->db->error();
1827 if ($this->
statut == self::STATUS_DRAFT) {
1833 $line->fetch($lineid);
1835 if ($line->delete($user) > 0) {
1838 $this->db->commit();
1841 $this->db->rollback();
1845 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1860 global $conf, $langs;
1862 $langs->load(
'sendings');
1864 $nofetch = !empty($params[
'nofetch']);
1867 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
1868 if (isset($this->
statut)) {
1869 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1871 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1872 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1874 $langs->load(
'companies');
1875 if (empty($this->thirdparty)) {
1878 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1895 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1897 global $langs, $hookmanager;
1902 'objecttype' => $this->element,
1903 'option' => $option,
1906 $classfortooltip =
'classfortooltip';
1909 $classfortooltip =
'classforajaxtooltip';
1910 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1916 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
1922 if ($option !==
'nolink') {
1924 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1925 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1926 $add_save_lastsearch_values = 1;
1928 if ($add_save_lastsearch_values) {
1929 $url .=
'&save_lastsearch_values=1';
1934 if (empty($notooltip)) {
1936 $label = $langs->trans(
"Shipment");
1937 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1939 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1940 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1943 $linkstart =
'<a href="'.$url.
'"';
1944 $linkstart .= $linkclose.
'>';
1947 $result .= $linkstart;
1949 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1951 if ($withpicto != 2) {
1952 $result .= $this->ref;
1954 $result .= $linkend;
1956 $hookmanager->initHooks(array($this->element .
'dao'));
1957 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1958 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1960 $result = $hookmanager->resPrint;
1962 $result .= $hookmanager->resPrint;
1991 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1992 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1994 $statusType =
'status'.$status;
1995 if ($status == self::STATUS_VALIDATED) {
1996 $statusType =
'status4';
1998 if ($status == self::STATUS_CLOSED) {
1999 $statusType =
'status6';
2001 if ($status == self::STATUS_CANCELED) {
2002 $statusType =
'status9';
2005 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
2017 global $langs, $conf;
2019 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2021 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2022 $return .=
'<div class="info-box info-box-sm">';
2023 $return .=
'<div class="info-box-icon bg-infobox-action">';
2025 $return .=
'</div>';
2026 $return .=
'<div class="info-box-content">';
2027 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2028 if ($selected >= 0) {
2029 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2031 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2032 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2034 if (property_exists($this,
'total_ht')) {
2035 $return .=
'<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).
' '.$langs->trans(
'HT').
'</div>';
2037 if (method_exists($this,
'getLibStatut')) {
2038 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2040 $return .=
'</div>';
2041 $return .=
'</div>';
2042 $return .=
'</div>';
2060 dol_syslog(get_class($this).
"::initAsSpecimen");
2063 $order->initAsSpecimen();
2067 $this->
ref =
'SPECIMEN';
2068 $this->specimen = 1;
2070 $this->livraison_id = 0;
2072 $this->date_creation = $now;
2073 $this->date_valid = $now;
2074 $this->date_delivery = $now + 24 * 3600;
2075 $this->date_expedition = $now + 24 * 3600;
2077 $this->entrepot_id = 0;
2078 $this->fk_delivery_address = 0;
2081 $this->commande_id = 0;
2082 $this->commande = $order;
2084 $this->origin_id = 1;
2085 $this->origin =
'commande';
2087 $this->note_private =
'Private note';
2088 $this->note_public =
'Public note';
2092 while ($xnbp < $nbp) {
2094 $line->product_desc = $langs->trans(
"Description").
" ".$xnbp;
2095 $line->product_label = $langs->trans(
"Description").
" ".$xnbp;
2097 $line->qty_asked = 5;
2098 $line->qty_shipped = 4;
2099 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
2101 $this->lines[] = $line;
2132 if ($user->hasRight(
'expedition',
'creer')) {
2133 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2134 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2135 $sql .=
" WHERE rowid = ".((int) $this->
id);
2137 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2138 $resql = $this->db->query($sql);
2140 $this->date_delivery = $delivery_date;
2143 $this->error = $this->db->error();
2161 $this->meths = array();
2163 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2164 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2165 $sql .=
" WHERE em.active = 1";
2166 $sql .=
" ORDER BY em.libelle ASC";
2168 $resql = $this->db->query($sql);
2170 while ($obj = $this->db->fetch_object($resql)) {
2171 $label = $langs->trans(
'SendingMethod'.$obj->code);
2172 $this->meths[$obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2189 $this->listmeths = array();
2192 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2193 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2195 $sql .=
" WHERE em.rowid=".((int) $id);
2198 $resql = $this->db->query($sql);
2200 while ($obj = $this->db->fetch_object($resql)) {
2201 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2202 $this->listmeths[$i][
'code'] = $obj->code;
2203 $label = $langs->trans(
'SendingMethod'.$obj->code);
2204 $this->listmeths[$i][
'libelle'] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2205 $this->listmeths[$i][
'description'] = $obj->description;
2206 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2207 $this->listmeths[$i][
'active'] = $obj->active;
2221 if (!empty($this->shipping_method_id)) {
2222 $sql =
"SELECT em.code, em.tracking";
2223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2224 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2226 $resql = $this->db->query($sql);
2228 if ($obj = $this->db->fetch_object($resql)) {
2229 $tracking = $obj->tracking;
2234 if (!empty($tracking) && !empty($value)) {
2235 $url = str_replace(
'{TRACKID}', $value, $tracking);
2236 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, ($value ? $value :
'url'));
2238 $this->tracking_url = $value;
2254 if ($this->
statut == self::STATUS_CLOSED) {
2261 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
2263 $resql = $this->db->query($sql);
2266 if ($this->origin ==
'commande' && $this->origin_id > 0) {
2268 $order->fetch($this->origin_id);
2270 $order->loadExpeditions(self::STATUS_CLOSED);
2272 $shipments_match_order = 1;
2273 foreach ($order->lines as $line) {
2274 $lineid = $line->id;
2276 if (($line->product_type == 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) {
2277 $shipments_match_order = 0;
2278 $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';
2283 if ($shipments_match_order) {
2284 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');
2286 $order->cloture($user);
2294 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2303 $result = $this->
call_trigger(
'SHIPPING_CLOSED', $user);
2314 $this->db->commit();
2320 $this->db->rollback();
2340 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
2342 $langs->load(
"agenda");
2345 $sql =
"SELECT cd.fk_product, cd.subprice,";
2346 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2348 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock,";
2349 $sql .=
" cd.rowid as cdid, ed.rowid as edid";
2350 $sql .=
" FROM " . MAIN_DB_PREFIX .
"commandedet as cd,";
2351 $sql .=
" " . MAIN_DB_PREFIX .
"expeditiondet as ed";
2352 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2353 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"expedition as e ON ed.fk_expedition = e.rowid";
2354 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
2355 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2357 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
2358 $resql = $this->db->query($sql);
2360 $cpt = $this->db->num_rows($resql);
2361 for ($i = 0; $i < $cpt; $i++) {
2362 $obj = $this->db->fetch_object($resql);
2363 if (empty($obj->edbrowid)) {
2366 $qty = $obj->edbqty;
2368 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
2371 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->rowid .
" edb.rowid=" . $obj->edbrowid);
2374 $mouvS->origin = &$this;
2375 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
2377 if (empty($obj->edbrowid)) {
2381 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref));
2383 $this->error = $mouvS->error;
2384 $this->errors = $mouvS->errors;
2392 $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);
2394 $this->error = $mouvS->error;
2395 $this->errors = $mouvS->errors;
2403 $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)";
2404 $resqldelete = $this->db->query($sqldelete);
2408 $this->error = $this->db->lasterror();
2409 $this->errors[] = $this->db->lasterror();
2428 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET billed = 1';
2429 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2431 $resql = $this->db->query($sql);
2436 $result = $this->
call_trigger(
'SHIPPING_BILLED', $user);
2443 $this->errors[] = $this->db->lasterror;
2446 if (empty($error)) {
2447 $this->db->commit();
2450 $this->db->rollback();
2465 if ($this->
statut <= self::STATUS_DRAFT) {
2469 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
2479 global $langs, $user;
2484 if ($this->
statut == self::STATUS_VALIDATED) {
2490 $oldbilled = $this->billed;
2492 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
2493 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2495 $resql = $this->db->query($sql);
2502 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2503 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2505 $langs->load(
"agenda");
2509 $sql =
"SELECT cd.fk_product, cd.subprice,";
2510 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2511 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2512 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2513 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2514 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2515 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2516 $sql .=
" AND cd.rowid = ed.fk_elementdet";
2518 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2519 $resql = $this->db->query($sql);
2521 $cpt = $this->db->num_rows($resql);
2522 for ($i = 0; $i < $cpt; $i++) {
2523 $obj = $this->db->fetch_object($resql);
2524 if (empty($obj->edbrowid)) {
2527 $qty = $obj->edbqty;
2532 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2536 $mouvS->origin = &$this;
2537 $mouvS->setOrigin($this->element, $this->
id);
2539 if (empty($obj->edbrowid)) {
2543 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
2545 $this->error = $mouvS->error;
2546 $this->errors = $mouvS->errors;
2554 $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);
2556 $this->error = $mouvS->error;
2557 $this->errors = $mouvS->errors;
2564 $this->error = $this->db->lasterror();
2571 $result = $this->
call_trigger(
'SHIPPING_REOPEN', $user);
2578 $this->errors[] = $this->db->lasterror();
2582 $this->db->commit();
2587 $this->billed = $oldbilled;
2588 $this->db->rollback();
2604 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2606 $outputlangs->load(
"products");
2611 if (!empty($this->model_pdf)) {
2612 $modele = $this->model_pdf;
2618 $modelpath =
"core/modules/expedition/doc/";
2622 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2652 public $element =
'expeditiondet';
2657 public $table_element =
'expeditiondet';
2690 public $fk_elementdet;
2695 public $origin_line_id;
2700 public $element_type;
2714 public $fk_expedition;
2729 public $qty_shipped;
2738 public $detail_batch;
2742 public $details_entrepot;
2748 public $entrepot_id;
2765 public $product_ref;
2776 public $product_label;
2788 public $product_desc;
2794 public $product_type = 0;
2805 public $weight_units;
2811 public $length_units;
2817 public $width_units;
2823 public $height_units;
2829 public $surface_units;
2835 public $volume_units;
2838 public $remise_percent;
2859 public $total_localtax1;
2864 public $total_localtax2;
2885 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_elementdet, ed.element_type, ed.qty, ed.rang';
2886 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as ed';
2887 $sql .=
' WHERE ed.rowid = '.((int) $rowid);
2888 $result = $this->db->query($sql);
2890 $objp = $this->db->fetch_object($result);
2891 $this->
id = $objp->rowid;
2892 $this->fk_expedition = $objp->fk_expedition;
2893 $this->entrepot_id = $objp->fk_entrepot;
2894 $this->fk_elementdet = $objp->fk_elementdet;
2895 $this->element_type = $objp->element_type;
2896 $this->qty = $objp->qty;
2897 $this->rang = $objp->rang;
2899 $this->db->free($result);
2903 $this->errors[] = $this->db->lasterror();
2904 $this->error = $this->db->lasterror();
2916 public function insert($user, $notrigger = 0)
2921 if (empty($this->fk_expedition) || empty($this->fk_elementdet) || !is_numeric($this->qty)) {
2922 $this->error =
'ErrorMandatoryParametersNotProvided';
2928 if (empty($this->rang)) {
2933 $ranktouse = $this->rang;
2934 if ($ranktouse == -1) {
2935 $rangmax = $this->
line_max($this->fk_expedition);
2936 $ranktouse = $rangmax + 1;
2939 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expeditiondet (";
2940 $sql .=
"fk_expedition";
2941 $sql .=
", fk_entrepot";
2942 $sql .=
", fk_elementdet";
2943 $sql .=
", element_type";
2946 $sql .=
") VALUES (";
2947 $sql .= $this->fk_expedition;
2948 $sql .=
", ".(empty($this->entrepot_id) ?
'NULL' : $this->entrepot_id);
2949 $sql .=
", ".((int) $this->fk_elementdet);
2950 $sql .=
", '".(empty($this->element_type) ?
'order' : $this->db->escape($this->element_type)).
"'";
2951 $sql .=
", ".price2num($this->qty,
'MS');
2952 $sql .=
", ".((int) $ranktouse);
2955 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2956 $resql = $this->db->query($sql);
2958 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expeditiondet");
2967 if (!$error && !$notrigger) {
2969 $result = $this->
call_trigger(
'LINESHIPPING_INSERT', $user);
2977 foreach ($this->errors as $errmsg) {
2978 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2979 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2987 $this->db->rollback();
2990 $this->db->commit();
3002 public function delete($user =
null, $notrigger = 0)
3009 if (isModEnabled(
'productbatch')) {
3010 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3011 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3013 if (!$this->db->query($sql)) {
3014 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3019 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
3020 $sql .=
" WHERE rowid = ".((int) $this->
id);
3022 if (!$error && $this->db->query($sql)) {
3027 $this->errors[] = $this->error;
3031 if (!$error && !$notrigger) {
3033 $result = $this->
call_trigger(
'LINESHIPPING_DELETE', $user);
3035 $this->errors[] = $this->error;
3041 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3046 $this->db->commit();
3049 foreach ($this->errors as $errmsg) {
3050 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3051 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3053 $this->db->rollback();
3065 public function update($user =
null, $notrigger = 0)
3069 dol_syslog(get_class($this).
"::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
3074 if (empty($this->qty)) {
3081 $expedition_batch_id =
null;
3082 if (is_array($this->detail_batch)) {
3083 if (count($this->detail_batch) > 1) {
3084 dol_syslog(get_class($this).
'::update only possible for one batch', LOG_ERR);
3085 $this->errors[] =
'ErrorBadParameters';
3088 $batch = $this->detail_batch[0]->batch;
3089 $batch_id = $this->detail_batch[0]->fk_origin_stock;
3090 $expedition_batch_id = $this->detail_batch[0]->id;
3091 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) {
3092 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3093 $this->errors[] =
'ErrorBadParameters';
3096 $qty =
price2num($this->detail_batch[0]->qty);
3098 } elseif (!empty($this->detail_batch)) {
3099 $batch = $this->detail_batch->batch;
3100 $batch_id = $this->detail_batch->fk_origin_stock;
3101 $expedition_batch_id = $this->detail_batch->id;
3102 if ($this->entrepot_id != $this->detail_batch->entrepot_id) {
3103 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3104 $this->errors[] =
'ErrorBadParameters';
3107 $qty =
price2num($this->detail_batch->qty);
3111 if (!isset($this->
id) || !isset($this->entrepot_id)) {
3112 dol_syslog(get_class($this).
'::update missing line id and/or warehouse id', LOG_ERR);
3113 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3120 if (!empty($batch) && isModEnabled(
'productbatch')) {
3121 $batch_id_str = $batch_id ??
'null';
3122 dol_syslog(get_class($this).
"::update expedition batch id=$expedition_batch_id, batch_id=$batch_id_str, batch=$batch");
3124 if (empty($batch_id) || empty($this->fk_product)) {
3125 dol_syslog(get_class($this).
'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
3126 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3133 if (!$error && ($lotArray = $shipmentlinebatch->fetchAll($this->id)) < 0) {
3134 $this->errors[] = $this->db->lasterror().
" - ExpeditionLineBatch::fetchAll";
3138 foreach ($lotArray as $lot) {
3139 if ($expedition_batch_id != $lot->id) {
3140 $remainingQty += $lot->qty;
3143 $qty += $remainingQty;
3148 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
3150 if ($lot->fetch(0, $this->fk_product, $batch) < 0) {
3151 $this->errors[] = $lot->errors;
3154 if (!$error && !empty($expedition_batch_id)) {
3156 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3157 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3158 $sql .=
" AND rowid = ".((int) $expedition_batch_id);
3160 if (!$this->db->query($sql)) {
3161 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3165 if (!$error && $this->detail_batch->qty > 0) {
3167 if (isset($lot->id)) {
3169 $shipmentLot->batch = $lot->batch;
3170 $shipmentLot->eatby = $lot->eatby;
3171 $shipmentLot->sellby = $lot->sellby;
3172 $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
3173 $shipmentLot->qty = $this->detail_batch->qty;
3174 $shipmentLot->fk_origin_stock = $batch_id;
3175 if ($shipmentLot->create($this->id) < 0) {
3176 $this->errors = $shipmentLot->errors;
3185 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3186 $sql .=
" fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id :
'null');
3187 $sql .=
" , qty = ".((float)
price2num($qty,
'MS'));
3188 $sql .=
" WHERE rowid = ".((int) $this->
id);
3190 if (!$this->db->query($sql)) {
3191 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3199 $this->errors[] = $this->error;
3204 if (!$error && !$notrigger) {
3206 $result = $this->
call_trigger(
'LINESHIPPING_MODIFY', $user);
3208 $this->errors[] = $this->error;
3214 $this->db->commit();
3217 foreach ($this->errors as $errmsg) {
3218 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3219 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3221 $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