37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40if (isModEnabled(
"propal")) {
41 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
43if (isModEnabled(
'commande')) {
44 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionlinebatch.class.php';
59 public $element =
"shipping";
64 public $fk_element =
"fk_expedition";
69 public $table_element =
"expedition";
74 public $table_element_line =
"expeditiondet";
80 public $ismultientitymanaged = 1;
85 public $isextrafieldmanaged = 1;
90 public $picto =
'dolly';
96 public $fields = array();
101 public $user_author_id;
106 public $fk_user_author;
120 public $ref_customer;
130 public $tracking_number;
135 public $tracking_url;
144 public $weight_units;
148 public $height_units;
154 public $livraison_id;
159 public $multicurrency_subprice;
174 public $date_delivery;
192 public $date_shipping;
197 public $date_creation;
220 public $lines = array();
226 public $fk_multicurrency;
231 public $multicurrency_code;
232 public $multicurrency_tx;
233 public $multicurrency_total_ht;
234 public $multicurrency_total_tva;
235 public $multicurrency_total_ttc;
270 $this->labelStatus = array();
271 $this->labelStatus[-1] =
'StatusSendingCanceled';
272 $this->labelStatus[0] =
'StatusSendingDraft';
273 $this->labelStatus[1] =
'StatusSendingValidated';
274 $this->labelStatus[2] =
'StatusSendingProcessed';
277 $this->labelStatusShort = array();
278 $this->labelStatusShort[-1] =
'StatusSendingCanceledShort';
279 $this->labelStatusShort[0] =
'StatusSendingDraftShort';
280 $this->labelStatusShort[1] =
'StatusSendingValidatedShort';
281 $this->labelStatusShort[2] =
'StatusSendingProcessedShort';
292 global $langs, $conf;
293 $langs->load(
"sendings");
299 $classname = $conf->global->EXPEDITION_ADDON_NUMBER;
302 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
304 foreach ($dirmodels as $reldir) {
308 $mybool |= @include_once $dir.$file;
316 $obj =
new $classname();
318 $numref = $obj->getNextValue($soc, $this);
323 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
327 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
339 public function create($user, $notrigger = 0)
341 global $conf, $hookmanager;
345 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
350 if (empty($this->fk_project)) {
351 $this->fk_project = 0;
358 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
361 $sql .=
", ref_customer";
363 $sql .=
", date_creation";
364 $sql .=
", fk_user_author";
365 $sql .=
", date_expedition";
366 $sql .=
", date_delivery";
368 $sql .=
", fk_projet";
369 $sql .=
", fk_address";
370 $sql .=
", fk_shipping_method";
371 $sql .=
", tracking_number";
376 $sql .=
", weight_units";
377 $sql .=
", size_units";
378 $sql .=
", note_private";
379 $sql .=
", note_public";
380 $sql .=
", model_pdf";
381 $sql .=
", fk_incoterms, location_incoterms";
382 $sql .=
") VALUES (";
384 $sql .=
", ".((int) $conf->entity);
385 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
386 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
387 $sql .=
", '".$this->db->idate($now).
"'";
388 $sql .=
", ".((int) $user->id);
389 $sql .=
", ".($this->date_expedition > 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
"null");
390 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
391 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
392 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
393 $sql .=
", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address :
"null");
394 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
395 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
396 $sql .=
", ".(is_numeric($this->weight) ? $this->weight :
'NULL');
397 $sql .=
", ".(is_numeric($this->sizeS) ? $this->sizeS :
'NULL');
398 $sql .=
", ".(is_numeric($this->sizeW) ? $this->sizeW :
'NULL');
399 $sql .=
", ".(is_numeric($this->sizeH) ? $this->sizeH :
'NULL');
400 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
401 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
402 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
403 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
404 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
405 $sql .=
", ".(int) $this->fk_incoterms;
406 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
409 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
410 $resql = $this->db->query($sql);
412 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
414 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
415 $sql .=
" SET ref = '(PROV".$this->id.
")'";
416 $sql .=
" WHERE rowid = ".((int) $this->
id);
418 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
419 if ($this->db->query($sql)) {
421 $num = count($this->lines);
422 for ($i = 0; $i < $num; $i++) {
424 if (!isset($this->lines[$i]->detail_batch)) {
425 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) {
429 if ($this->
create_line_batch($this->lines[$i], $this->lines[$i]->array_options) <= 0) {
436 if (!$error && $this->
id && $this->origin_id) {
451 if (!$error && !$notrigger) {
453 $result = $this->
call_trigger(
'SHIPPING_CREATE', $user);
463 foreach ($this->errors as $errmsg) {
464 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
465 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
467 $this->db->rollback();
472 $this->db->rollback();
477 $this->error = $this->db->lasterror().
" - sql=$sql";
478 $this->db->rollback();
483 $this->error = $this->db->error().
" - sql=$sql";
484 $this->db->rollback();
500 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options =
null)
506 $expeditionline->fk_expedition = $this->id;
507 $expeditionline->entrepot_id = $entrepot_id;
508 $expeditionline->fk_origin_line = $origin_line_id;
509 $expeditionline->qty = $qty;
510 $expeditionline->rang = $rang;
511 $expeditionline->array_options = $array_options;
513 if (($lineId = $expeditionline->insert($user)) < 0) {
514 $this->errors[] = $expeditionline->error;
532 $stockLocationQty = array();
534 $tab = $line_ext->detail_batch;
536 foreach ($tab as $detbatch) {
537 if (!empty($detbatch->entrepot_id)) {
538 if (empty($stockLocationQty[$detbatch->entrepot_id])) {
539 $stockLocationQty[$detbatch->entrepot_id] = 0;
541 $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty;
545 foreach ($stockLocationQty as $stockLocation => $qty) {
546 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
551 foreach ($tab as $detbatch) {
552 if ($detbatch->entrepot_id == $stockLocation) {
553 if (!($detbatch->create($line_id) > 0)) {
554 $this->errors = $detbatch->errors;
578 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
583 if (empty($id) && empty($ref) && empty($ref_ext)) {
587 $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";
588 $sql .=
", e.date_valid";
589 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
590 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
591 $sql .=
", e.fk_shipping_method, e.tracking_number";
592 $sql .=
", e.note_private, e.note_public";
593 $sql .=
', e.fk_incoterms, e.location_incoterms';
594 $sql .=
', i.libelle as label_incoterms';
595 $sql .=
', s.libelle as shipping_method';
596 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
597 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
598 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
599 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
600 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
601 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
603 $sql .=
" AND e.rowid = ".((int) $id);
606 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
609 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
612 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
613 $result = $this->db->query($sql);
615 if ($this->db->num_rows($result)) {
616 $obj = $this->db->fetch_object($result);
618 $this->
id = $obj->rowid;
619 $this->entity = $obj->entity;
620 $this->
ref = $obj->ref;
621 $this->socid = $obj->socid;
622 $this->ref_customer = $obj->ref_customer;
623 $this->ref_ext = $obj->ref_ext;
624 $this->
status = $obj->fk_statut;
625 $this->
statut = $this->status;
626 $this->user_author_id = $obj->fk_user_author;
627 $this->fk_user_author = $obj->fk_user_author;
628 $this->date_creation = $this->db->jdate($obj->date_creation);
629 $this->date_valid = $this->db->jdate($obj->date_valid);
630 $this->date = $this->db->jdate($obj->date_expedition);
631 $this->date_expedition = $this->db->jdate($obj->date_expedition);
632 $this->date_shipping = $this->db->jdate($obj->date_expedition);
633 $this->date_delivery = $this->db->jdate($obj->date_delivery);
634 $this->fk_delivery_address = $obj->fk_address;
635 $this->model_pdf = $obj->model_pdf;
636 $this->shipping_method_id = $obj->fk_shipping_method;
637 $this->shipping_method = $obj->shipping_method;
638 $this->tracking_number = $obj->tracking_number;
639 $this->origin = ($obj->origin ? $obj->origin :
'commande');
640 $this->origin_id = $obj->origin_id;
641 $this->billed = $obj->billed;
642 $this->fk_project = $obj->fk_project;
644 $this->trueWeight = $obj->weight;
645 $this->weight_units = $obj->weight_units;
647 $this->trueWidth = $obj->width;
648 $this->width_units = $obj->size_units;
649 $this->trueHeight = $obj->height;
650 $this->height_units = $obj->size_units;
651 $this->trueDepth = $obj->size;
652 $this->depth_units = $obj->size_units;
654 $this->note_public = $obj->note_public;
655 $this->note_private = $obj->note_private;
658 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
659 $this->size_units = $obj->size_units;
662 $this->fk_incoterms = $obj->fk_incoterms;
663 $this->location_incoterms = $obj->location_incoterms;
664 $this->label_incoterms = $obj->label_incoterms;
666 $this->db->free($result);
678 if (isModEnabled(
'multicurrency')) {
679 if (!empty($this->multicurrency_code)) {
680 $this->multicurrency_code = $this->thirdparty->multicurrency_code;
682 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($this->thirdparty->multicurrency_tx)) {
683 $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
697 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
698 $this->error =
'Shipment with id '.$id.
' not found';
702 $this->error = $this->db->error();
714 public function valid($user, $notrigger = 0)
718 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
724 dol_syslog(get_class($this).
"::valid not in draft status", LOG_WARNING);
728 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'creer'))
729 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'shipping_advance',
'validate')))) {
730 $this->error =
'Permission denied';
731 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
741 $soc->fetch($this->socid);
744 $result = $soc->setAsCustomer();
747 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
749 } elseif (!empty($this->
ref)) {
750 $numref = $this->ref;
752 $numref =
"EXP".$this->id;
759 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
760 $sql .=
" ref='".$this->db->escape($numref).
"'";
761 $sql .=
", fk_statut = 1";
762 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
763 $sql .=
", fk_user_valid = ".$user->id;
764 $sql .=
" WHERE rowid = ".((int) $this->
id);
766 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
767 $resql = $this->db->query($sql);
769 $this->error = $this->db->lasterror();
774 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT')) {
787 if (!$error && !$notrigger) {
789 $result = $this->
call_trigger(
'SHIPPING_VALIDATE', $user);
797 $this->oldref = $this->ref;
800 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
802 $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).
"'";
803 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
804 $resql = $this->db->query($sql);
807 $this->error = $this->db->lasterror();
809 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
810 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
811 $resql = $this->db->query($sql);
814 $this->error = $this->db->lasterror();
820 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
821 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
822 if (!$error && file_exists($dirsource)) {
823 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
825 if (@rename($dirsource, $dirdest)) {
828 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
829 foreach ($listoffiles as $fileentry) {
830 $dirsource = $fileentry[
'name'];
831 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
832 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
833 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
834 @rename($dirsource, $dirdest);
843 $this->
ref = $numref;
851 $this->db->rollback();
870 if ($this->
statut == self::STATUS_VALIDATED || $this->
statut == self::STATUS_CLOSED) {
872 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
873 $delivery =
new Delivery($this->db);
874 $result = $delivery->create_from_sending($user, $this->
id);
878 $this->error = $delivery->error;
901 public function addline($entrepot_id, $id, $qty, $array_options = 0)
903 global $conf, $langs;
905 $num = count($this->lines);
908 $line->entrepot_id = $entrepot_id;
909 $line->origin_line_id = $id;
910 $line->fk_origin_line = $id;
914 $orderline->fetch($id);
917 $line->rang = $orderline->rang;
918 $line->product_type = $orderline->product_type;
920 if (isModEnabled(
'stock') && !empty($orderline->fk_product)) {
921 $fk_product = $orderline->fk_product;
924 $langs->load(
"errors");
925 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
930 $product =
new Product($this->db);
931 $product->fetch($fk_product);
934 if ($entrepot_id > 0) {
935 $product->load_stock(
'warehouseopen');
936 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
938 $product_stock = $product->stock_reel;
941 $product_type = $product->type;
943 $isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
946 if ($product_stock < $qty) {
947 $langs->load(
"errors");
948 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
949 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
951 $this->db->rollback();
961 if (isModEnabled(
'productbatch') && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) {
962 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$orderline->fk_product;
967 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
968 $line->array_options = $array_options;
971 $this->lines[$num] = $line;
987 global $conf, $langs;
989 $num = count($this->lines);
990 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
993 foreach ($dbatch[
'detail'] as $key => $value) {
994 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1000 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1005 $linebatch->qty = $value[
'q'];
1006 if ($linebatch->qty == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
1007 $linebatch->batch =
null;
1009 $tab[] = $linebatch;
1012 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1014 $prod_batch->fetch($value[
'id_batch']);
1016 if ($prod_batch->qty < $linebatch->qty) {
1017 $langs->load(
"errors");
1018 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1019 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1020 $this->db->rollback();
1028 $line->entrepot_id = $linebatch->entrepot_id;
1029 $line->origin_line_id = $dbatch[
'ix_l'];
1030 $line->fk_origin_line = $dbatch[
'ix_l'];
1031 $line->qty = $dbatch[
'qty'];
1032 $line->detail_batch = $tab;
1035 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1036 $line->array_options = $array_options;
1040 $this->lines[$num] = $line;
1053 public function update($user =
null, $notrigger = 0)
1060 if (isset($this->
ref)) {
1061 $this->
ref = trim($this->
ref);
1063 if (isset($this->entity)) {
1064 $this->entity = (int) $this->entity;
1066 if (isset($this->ref_customer)) {
1067 $this->ref_customer = trim($this->ref_customer);
1069 if (isset($this->socid)) {
1070 $this->socid = (int) $this->socid;
1072 if (isset($this->fk_user_author)) {
1073 $this->fk_user_author = (int) $this->fk_user_author;
1075 if (isset($this->fk_user_valid)) {
1076 $this->fk_user_valid = (int) $this->fk_user_valid;
1078 if (isset($this->fk_delivery_address)) {
1079 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1081 if (isset($this->shipping_method_id)) {
1082 $this->shipping_method_id = (int) $this->shipping_method_id;
1084 if (isset($this->tracking_number)) {
1085 $this->tracking_number = trim($this->tracking_number);
1087 if (isset($this->
statut)) {
1090 if (isset($this->trueDepth)) {
1091 $this->trueDepth = trim($this->trueDepth);
1093 if (isset($this->trueWidth)) {
1094 $this->trueWidth = trim($this->trueWidth);
1096 if (isset($this->trueHeight)) {
1097 $this->trueHeight = trim($this->trueHeight);
1099 if (isset($this->size_units)) {
1100 $this->size_units = trim($this->size_units);
1102 if (isset($this->weight_units)) {
1103 $this->weight_units = trim($this->weight_units);
1105 if (isset($this->trueWeight)) {
1106 $this->weight = trim($this->trueWeight);
1108 if (isset($this->note_private)) {
1109 $this->note_private = trim($this->note_private);
1111 if (isset($this->note_public)) {
1112 $this->note_public = trim($this->note_public);
1114 if (isset($this->model_pdf)) {
1115 $this->model_pdf = trim($this->model_pdf);
1122 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1123 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1124 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1125 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1126 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1127 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1128 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1129 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1130 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1131 $sql .=
" date_expedition=".(dol_strlen($this->date_expedition) != 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
'null').
",";
1132 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1133 $sql .=
" fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address :
"null").
",";
1134 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1135 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1136 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1137 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1138 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1139 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1140 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1141 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1142 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1143 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1144 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1145 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1146 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1147 $sql .=
" entity=".$conf->entity;
1148 $sql .=
" WHERE rowid=".((int) $this->
id);
1152 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1153 $resql = $this->db->query($sql);
1156 $this->errors[] =
"Error ".$this->db->lasterror();
1159 if (!$error && !$notrigger) {
1161 $result = $this->
call_trigger(
'SHIPPING_MODIFY', $user);
1170 foreach ($this->errors as $errmsg) {
1171 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1172 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1174 $this->db->rollback();
1177 $this->db->commit();
1190 public function cancel($notrigger = 0, $also_update_stock =
false)
1192 global $conf, $langs, $user;
1194 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1203 if (count($this->linkedObjectsIds) > 0) {
1204 $this->error =
'ErrorThereIsSomeDeliveries';
1208 if (!$error && !$notrigger) {
1210 $result = $this->
call_trigger(
'SHIPPING_CANCEL', $user);
1218 if (!$error && isModEnabled(
'stock') &&
1219 (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) ||
1220 ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) {
1221 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1223 $langs->load(
"agenda");
1226 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1228 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1229 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1230 $sql .=
" AND cd.rowid = ed.fk_origin_line";
1232 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1233 $resql = $this->db->query($sql);
1235 $cpt = $this->db->num_rows($resql);
1239 for ($i = 0; $i < $cpt; $i++) {
1240 dol_syslog(get_class($this).
"::delete movement index ".$i);
1241 $obj = $this->db->fetch_object($resql);
1245 $mouvS->origin =
null;
1248 if (isModEnabled(
'productbatch')) {
1249 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1250 if (!is_array($lotArray)) {
1252 $this->errors[] =
"Error ".$this->db->lasterror();
1256 if (empty($lotArray)) {
1260 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref));
1263 $this->errors = array_merge($this->errors, $mouvS->errors);
1269 foreach ($lotArray as $lot) {
1270 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1273 $this->errors = array_merge($this->errors, $mouvS->errors);
1284 $this->errors[] =
"Error ".$this->db->lasterror();
1289 if (!$error && isModEnabled(
'productbatch')) {
1291 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1293 $this->errors[] =
"Error ".$this->db->lasterror();
1299 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1300 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1302 if ($this->db->query($sql)) {
1311 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"expedition";
1312 $sql .=
" WHERE rowid = ".((int) $this->
id);
1314 if ($this->db->query($sql)) {
1315 if (!empty($this->origin) && $this->origin_id > 0) {
1317 $origin = $this->origin;
1320 $this->$origin->loadExpeditions();
1322 if (count($this->$origin->expeditions) <= 0) {
1329 $this->db->commit();
1333 if (!empty($conf->expedition->dir_output)) {
1334 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1335 $file = $dir.
'/'.$ref.
'.pdf';
1336 if (file_exists($file)) {
1341 if (file_exists($dir)) {
1343 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1351 $this->db->rollback();
1355 $this->error = $this->db->lasterror().
" - sql=$sql";
1356 $this->db->rollback();
1360 $this->error = $this->db->lasterror().
" - sql=$sql";
1361 $this->db->rollback();
1365 $this->error = $this->db->lasterror().
" - sql=$sql";
1366 $this->db->rollback();
1370 $this->db->rollback();
1383 public function delete($notrigger = 0, $also_update_stock =
false)
1385 global $conf, $langs, $user;
1387 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1396 if (count($this->linkedObjectsIds) > 0) {
1397 $this->error =
'ErrorThereIsSomeDeliveries';
1401 if (!$error && !$notrigger) {
1403 $result = $this->
call_trigger(
'SHIPPING_DELETE', $user);
1411 if (!$error && isModEnabled(
'stock') &&
1412 (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) ||
1413 ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) {
1414 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1416 $langs->load(
"agenda");
1422 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1423 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1424 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1425 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1426 $sql .=
" AND cd.rowid = ed.fk_origin_line";
1428 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1429 $resql = $this->db->query($sql);
1431 $cpt = $this->db->num_rows($resql);
1432 for ($i = 0; $i < $cpt; $i++) {
1433 dol_syslog(get_class($this).
"::delete movement index ".$i);
1434 $obj = $this->db->fetch_object($resql);
1438 $mouvS->origin =
null;
1440 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1441 if (!is_array($lotArray)) {
1443 $this->errors[] =
"Error ".$this->db->lasterror();
1445 if (empty($lotArray)) {
1449 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref));
1452 $this->errors = array_merge($this->errors, $mouvS->errors);
1458 foreach ($lotArray as $lot) {
1459 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1462 $this->errors = array_merge($this->errors, $mouvS->errors);
1473 $this->errors[] =
"Error ".$this->db->lasterror();
1480 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1482 $this->errors[] =
"Error ".$this->db->lasterror();
1487 $main = MAIN_DB_PREFIX.
'expeditiondet';
1488 $ef = $main.
"_extrafields";
1489 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".((int) $this->
id).
")";
1491 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1492 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1494 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1508 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expedition";
1509 $sql .=
" WHERE rowid = ".((int) $this->
id);
1511 if ($this->db->query($sql)) {
1512 if (!empty($this->origin) && $this->origin_id > 0) {
1514 $origin = $this->origin;
1517 $this->$origin->loadExpeditions();
1519 if (count($this->$origin->expeditions) <= 0) {
1526 $this->db->commit();
1534 if (!empty($conf->expedition->dir_output)) {
1535 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1536 $file = $dir.
'/'.$ref.
'.pdf';
1537 if (file_exists($file)) {
1542 if (file_exists($dir)) {
1544 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1552 $this->db->rollback();
1556 $this->error = $this->db->lasterror().
" - sql=$sql";
1557 $this->db->rollback();
1561 $this->error = $this->db->lasterror().
" - sql=$sql";
1562 $this->db->rollback();
1566 $this->error = $this->db->lasterror().
" - sql=$sql";
1567 $this->db->rollback();
1571 $this->db->rollback();
1585 global $conf, $mysoc;
1587 $this->lines = array();
1592 $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";
1593 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1594 $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";
1595 $sql .=
", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang";
1596 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1597 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
1598 $sql .=
", p.weight, p.weight_units, p.length, p.length_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";
1599 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
1600 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
1601 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1602 $sql .=
" AND ed.fk_origin_line = cd.rowid";
1603 $sql .=
" ORDER BY cd.rang, ed.fk_origin_line";
1605 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1606 $resql = $this->db->query($sql);
1608 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1610 $num = $this->db->num_rows($resql);
1615 $this->total_ht = 0;
1616 $this->total_tva = 0;
1617 $this->total_ttc = 0;
1618 $this->total_localtax1 = 0;
1619 $this->total_localtax2 = 0;
1621 $this->multicurrency_total_ht = 0;
1622 $this->multicurrency_total_tva = 0;
1623 $this->multicurrency_total_ttc = 0;
1628 $obj = $this->db->fetch_object($resql);
1631 if ($originline > 0 && $originline == $obj->fk_origin_line) {
1632 $line->entrepot_id = 0;
1633 $line->qty_shipped += $obj->qty_shipped;
1636 $line->entrepot_id = $obj->fk_entrepot;
1637 $line->qty_shipped = $obj->qty_shipped;
1641 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
1642 $detail_entrepot->qty_shipped = $obj->qty_shipped;
1643 $detail_entrepot->line_id = $obj->line_id;
1644 $line->details_entrepot[] = $detail_entrepot;
1646 $line->line_id = $obj->line_id;
1647 $line->rowid = $obj->line_id;
1648 $line->id = $obj->line_id;
1650 $line->fk_origin =
'orderline';
1651 $line->fk_origin_line = $obj->fk_origin_line;
1652 $line->origin_line_id = $obj->fk_origin_line;
1654 $line->fk_expedition = $this->id;
1656 $line->product_type = $obj->product_type;
1657 $line->fk_product = $obj->fk_product;
1658 $line->fk_product_type = $obj->fk_product_type;
1659 $line->ref = $obj->product_ref;
1660 $line->product_ref = $obj->product_ref;
1661 $line->product_label = $obj->product_label;
1662 $line->libelle = $obj->product_label;
1663 $line->product_barcode = $obj->product_barcode;
1664 $line->product_tosell = $obj->product_tosell;
1665 $line->product_tobuy = $obj->product_tobuy;
1666 $line->product_tobatch = $obj->product_tobatch;
1667 $line->label = $obj->custom_label;
1668 $line->description = $obj->description;
1669 $line->qty_asked = $obj->qty_asked;
1670 $line->rang = $obj->rang;
1671 $line->weight = $obj->weight;
1672 $line->weight_units = $obj->weight_units;
1673 $line->length = $obj->length;
1674 $line->length_units = $obj->length_units;
1675 $line->surface = $obj->surface;
1676 $line->surface_units = $obj->surface_units;
1677 $line->volume = $obj->volume;
1678 $line->volume_units = $obj->volume_units;
1679 $line->fk_unit = $obj->fk_unit;
1681 $line->pa_ht = $obj->pa_ht;
1684 $localtax_array = array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1685 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
1686 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
1689 $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);
1690 $line->desc = $obj->description;
1691 $line->qty = $line->qty_shipped;
1692 $line->total_ht = $tabprice[0];
1693 $line->total_localtax1 = $tabprice[9];
1694 $line->total_localtax2 = $tabprice[10];
1695 $line->total_ttc = $tabprice[2];
1696 $line->total_tva = $tabprice[1];
1697 $line->vat_src_code = $obj->vat_src_code;
1698 $line->tva_tx = $obj->tva_tx;
1699 $line->localtax1_tx = $obj->localtax1_tx;
1700 $line->localtax2_tx = $obj->localtax2_tx;
1701 $line->info_bits = $obj->info_bits;
1702 $line->price = $obj->price;
1703 $line->subprice = $obj->subprice;
1704 $line->remise_percent = $obj->remise_percent;
1706 $this->total_ht += $tabprice[0];
1707 $this->total_tva += $tabprice[1];
1708 $this->total_ttc += $tabprice[2];
1709 $this->total_localtax1 += $tabprice[9];
1710 $this->total_localtax2 += $tabprice[10];
1713 $this->fk_multicurrency = $obj->fk_multicurrency;
1714 $this->multicurrency_code = $obj->multicurrency_code;
1715 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1716 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1717 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1718 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1720 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
1721 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
1722 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
1724 if ($originline != $obj->fk_origin_line) {
1725 $line->detail_batch = array();
1729 if (isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
1730 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
1732 if (is_array($newdetailbatch)) {
1733 if ($originline != $obj->fk_origin_line) {
1734 $line->detail_batch = $newdetailbatch;
1736 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1741 $line->fetch_optionals();
1743 if ($originline != $obj->fk_origin_line) {
1744 $this->lines[$lineindex] = $line;
1747 $line->total_ht += $tabprice[0];
1748 $line->total_localtax1 += $tabprice[9];
1749 $line->total_localtax2 += $tabprice[10];
1750 $line->total_ttc += $tabprice[2];
1751 $line->total_tva += $tabprice[1];
1755 $originline = $obj->fk_origin_line;
1757 $this->db->free($resql);
1760 $this->error = $this->db->error();
1776 if ($this->
statut == self::STATUS_DRAFT) {
1782 $line->fetch($lineid);
1784 if ($line->delete($user) > 0) {
1787 $this->db->commit();
1790 $this->db->rollback();
1794 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1809 global $conf, $langs;
1811 $langs->load(
'sendings');
1813 $nofetch = !empty($params[
'nofetch']);
1816 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
1817 if (isset($this->
statut)) {
1818 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1820 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1821 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1823 $langs->load(
'companies');
1824 if (empty($this->thirdparty)) {
1827 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1844 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1846 global $langs, $hookmanager;
1851 'objecttype' => $this->element,
1852 'option' => $option,
1855 $classfortooltip =
'classfortooltip';
1858 $classfortooltip =
'classforajaxtooltip';
1859 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1865 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
1871 if ($option !==
'nolink') {
1873 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1874 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1875 $add_save_lastsearch_values = 1;
1877 if ($add_save_lastsearch_values) {
1878 $url .=
'&save_lastsearch_values=1';
1883 if (empty($notooltip)) {
1885 $label = $langs->trans(
"Shipment");
1886 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1888 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1889 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1892 $linkstart =
'<a href="'.$url.
'"';
1893 $linkstart .= $linkclose.
'>';
1896 $result .= $linkstart;
1898 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1900 if ($withpicto != 2) {
1901 $result .= $this->ref;
1903 $result .= $linkend;
1905 $hookmanager->initHooks(array($this->element .
'dao'));
1906 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1907 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1909 $result = $hookmanager->resPrint;
1911 $result .= $hookmanager->resPrint;
1940 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
1941 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1943 $statusType =
'status'.$status;
1944 if ($status == self::STATUS_VALIDATED) {
1945 $statusType =
'status4';
1947 if ($status == self::STATUS_CLOSED) {
1948 $statusType =
'status6';
1950 if ($status == self::STATUS_CANCELED) {
1951 $statusType =
'status9';
1954 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1966 global $langs, $conf;
1968 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1970 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1971 $return .=
'<div class="info-box info-box-sm">';
1972 $return .=
'<div class="info-box-icon bg-infobox-action">';
1974 $return .=
'</div>';
1975 $return .=
'<div class="info-box-content">';
1976 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1977 if ($selected >= 0) {
1978 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1980 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
1981 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
1983 if (property_exists($this,
'total_ht')) {
1984 $return .=
'<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).
' '.$langs->trans(
'HT').
'</div>';
1986 if (method_exists($this,
'getLibStatut')) {
1987 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1989 $return .=
'</div>';
1990 $return .=
'</div>';
1991 $return .=
'</div>';
2009 dol_syslog(get_class($this).
"::initAsSpecimen");
2012 $order->initAsSpecimen();
2016 $this->
ref =
'SPECIMEN';
2017 $this->specimen = 1;
2019 $this->livraison_id = 0;
2021 $this->date_creation = $now;
2022 $this->date_valid = $now;
2023 $this->date_delivery = $now + 24 * 3600;
2024 $this->date_expedition = $now + 24 * 3600;
2026 $this->entrepot_id = 0;
2027 $this->fk_delivery_address = 0;
2030 $this->commande_id = 0;
2031 $this->commande = $order;
2033 $this->origin_id = 1;
2034 $this->origin =
'commande';
2036 $this->note_private =
'Private note';
2037 $this->note_public =
'Public note';
2041 while ($xnbp < $nbp) {
2043 $line->product_desc = $langs->trans(
"Description").
" ".$xnbp;
2044 $line->product_label = $langs->trans(
"Description").
" ".$xnbp;
2046 $line->qty_asked = 5;
2047 $line->qty_shipped = 4;
2048 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
2050 $this->lines[] = $line;
2079 if ($user->hasRight(
'expedition',
'creer')) {
2080 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2081 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2082 $sql .=
" WHERE rowid = ".((int) $this->
id);
2084 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2085 $resql = $this->db->query($sql);
2087 $this->date_delivery = $delivery_date;
2090 $this->error = $this->db->error();
2108 $this->meths = array();
2110 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2111 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2112 $sql .=
" WHERE em.active = 1";
2113 $sql .=
" ORDER BY em.libelle ASC";
2115 $resql = $this->db->query($sql);
2117 while ($obj = $this->db->fetch_object($resql)) {
2118 $label = $langs->trans(
'SendingMethod'.$obj->code);
2119 $this->meths[$obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2136 $this->listmeths = array();
2139 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2140 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2142 $sql .=
" WHERE em.rowid=".((int) $id);
2145 $resql = $this->db->query($sql);
2147 while ($obj = $this->db->fetch_object($resql)) {
2148 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2149 $this->listmeths[$i][
'code'] = $obj->code;
2150 $label = $langs->trans(
'SendingMethod'.$obj->code);
2151 $this->listmeths[$i][
'libelle'] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2152 $this->listmeths[$i][
'description'] = $obj->description;
2153 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2154 $this->listmeths[$i][
'active'] = $obj->active;
2168 if (!empty($this->shipping_method_id)) {
2169 $sql =
"SELECT em.code, em.tracking";
2170 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2171 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2173 $resql = $this->db->query($sql);
2175 if ($obj = $this->db->fetch_object($resql)) {
2176 $tracking = $obj->tracking;
2181 if (!empty($tracking) && !empty($value)) {
2182 $url = str_replace(
'{TRACKID}', $value, $tracking);
2183 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
2185 $this->tracking_url = $value;
2196 global $conf, $user;
2201 if ($this->
statut == self::STATUS_CLOSED) {
2208 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
2210 $resql = $this->db->query($sql);
2213 if ($this->origin ==
'commande' && $this->origin_id > 0) {
2215 $order->fetch($this->origin_id);
2217 $order->loadExpeditions(self::STATUS_CLOSED);
2219 $shipments_match_order = 1;
2220 foreach ($order->lines as $line) {
2221 $lineid = $line->id;
2223 if (($line->product_type == 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) {
2224 $shipments_match_order = 0;
2225 $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';
2230 if ($shipments_match_order) {
2231 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');
2233 $order->cloture($user);
2241 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2250 $result = $this->
call_trigger(
'SHIPPING_CLOSED', $user);
2261 $this->db->commit();
2267 $this->db->rollback();
2287 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
2289 $langs->load(
"agenda");
2292 $sql =
"SELECT cd.fk_product, cd.subprice,";
2293 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2295 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock,";
2296 $sql .=
" cd.rowid as cdid, ed.rowid as edid";
2297 $sql .=
" FROM " . MAIN_DB_PREFIX .
"commandedet as cd,";
2298 $sql .=
" " . MAIN_DB_PREFIX .
"expeditiondet as ed";
2299 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2300 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"expedition as e ON ed.fk_expedition = e.rowid";
2301 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
2302 $sql .=
" AND cd.rowid = ed.fk_origin_line";
2304 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
2305 $resql = $this->db->query($sql);
2307 $cpt = $this->db->num_rows($resql);
2308 for ($i = 0; $i < $cpt; $i++) {
2309 $obj = $this->db->fetch_object($resql);
2310 if (empty($obj->edbrowid)) {
2313 $qty = $obj->edbqty;
2315 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
2318 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->rowid .
" edb.rowid=" . $obj->edbrowid);
2321 $mouvS->origin = &$this;
2322 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
2324 if (empty($obj->edbrowid)) {
2328 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref));
2330 $this->error = $mouvS->error;
2331 $this->errors = $mouvS->errors;
2339 $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);
2341 $this->error = $mouvS->error;
2342 $this->errors = $mouvS->errors;
2350 $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)";
2351 $resqldelete = $this->db->query($sqldelete);
2355 $this->error = $this->db->lasterror();
2356 $this->errors[] = $this->db->lasterror();
2375 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET billed = 1';
2376 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2378 $resql = $this->db->query($sql);
2383 $result = $this->
call_trigger(
'SHIPPING_BILLED', $user);
2390 $this->errors[] = $this->db->lasterror;
2393 if (empty($error)) {
2394 $this->db->commit();
2397 $this->db->rollback();
2412 if ($this->
statut <= self::STATUS_DRAFT) {
2416 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
2426 global $conf, $langs, $user;
2431 if ($this->
statut == self::STATUS_VALIDATED) {
2437 $oldbilled = $this->billed;
2439 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
2440 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2442 $resql = $this->db->query($sql);
2448 if (!$error && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2449 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2451 $langs->load(
"agenda");
2455 $sql =
"SELECT cd.fk_product, cd.subprice,";
2456 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2457 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2459 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2460 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2461 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2462 $sql .=
" AND cd.rowid = ed.fk_origin_line";
2464 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2465 $resql = $this->db->query($sql);
2467 $cpt = $this->db->num_rows($resql);
2468 for ($i = 0; $i < $cpt; $i++) {
2469 $obj = $this->db->fetch_object($resql);
2470 if (empty($obj->edbrowid)) {
2473 $qty = $obj->edbqty;
2478 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2482 $mouvS->origin = &$this;
2483 $mouvS->setOrigin($this->element, $this->
id);
2485 if (empty($obj->edbrowid)) {
2489 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
2491 $this->error = $mouvS->error;
2492 $this->errors = $mouvS->errors;
2500 $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);
2502 $this->error = $mouvS->error;
2503 $this->errors = $mouvS->errors;
2510 $this->error = $this->db->lasterror();
2517 $result = $this->
call_trigger(
'SHIPPING_REOPEN', $user);
2524 $this->errors[] = $this->db->lasterror();
2528 $this->db->commit();
2532 $this->billed = $oldbilled;
2533 $this->db->rollback();
2549 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2553 $outputlangs->load(
"products");
2558 if (!empty($this->model_pdf)) {
2559 $modele = $this->model_pdf;
2561 $modele = $conf->global->EXPEDITION_ADDON_PDF;
2565 $modelpath =
"core/modules/expedition/doc/";
2569 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2599 public $element =
'expeditiondet';
2604 public $table_element =
'expeditiondet';
2631 public $fk_origin_line;
2636 public $fk_expedition;
2651 public $qty_shipped;
2660 public $detail_batch;
2664 public $details_entrepot;
2670 public $entrepot_id;
2687 public $product_ref;
2698 public $product_label;
2710 public $product_desc;
2716 public $product_type = 0;
2727 public $weight_units;
2733 public $length_units;
2739 public $surface_units;
2745 public $volume_units;
2748 public $remise_percent;
2769 public $total_localtax1;
2774 public $total_localtax2;
2795 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang';
2796 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as ed';
2797 $sql .=
' WHERE ed.rowid = '.((int) $rowid);
2798 $result = $this->db->query($sql);
2800 $objp = $this->db->fetch_object($result);
2801 $this->
id = $objp->rowid;
2802 $this->fk_expedition = $objp->fk_expedition;
2803 $this->entrepot_id = $objp->fk_entrepot;
2804 $this->fk_origin_line = $objp->fk_origin_line;
2805 $this->qty = $objp->qty;
2806 $this->rang = $objp->rang;
2808 $this->db->free($result);
2812 $this->errors[] = $this->db->lasterror();
2813 $this->error = $this->db->lasterror();
2825 public function insert($user, $notrigger = 0)
2830 if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) {
2831 $this->error =
'ErrorMandatoryParametersNotProvided';
2837 if (empty($this->rang)) {
2842 $ranktouse = $this->rang;
2843 if ($ranktouse == -1) {
2844 $rangmax = $this->
line_max($this->fk_expedition);
2845 $ranktouse = $rangmax + 1;
2848 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expeditiondet (";
2849 $sql .=
"fk_expedition";
2850 $sql .=
", fk_entrepot";
2851 $sql .=
", fk_origin_line";
2854 $sql .=
") VALUES (";
2855 $sql .= $this->fk_expedition;
2856 $sql .=
", ".(empty($this->entrepot_id) ?
'NULL' : $this->entrepot_id);
2857 $sql .=
", ".((int) $this->fk_origin_line);
2858 $sql .=
", ".price2num($this->qty,
'MS');
2859 $sql .=
", ".((int) $ranktouse);
2862 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2863 $resql = $this->db->query($sql);
2865 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expeditiondet");
2874 if (!$error && !$notrigger) {
2876 $result = $this->
call_trigger(
'LINESHIPPING_INSERT', $user);
2884 foreach ($this->errors as $errmsg) {
2885 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2886 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2894 $this->db->rollback();
2897 $this->db->commit();
2909 public function delete($user =
null, $notrigger = 0)
2916 if (isModEnabled(
'productbatch')) {
2917 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
2918 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
2920 if (!$this->db->query($sql)) {
2921 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
2926 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
2927 $sql .=
" WHERE rowid = ".((int) $this->
id);
2929 if (!$error && $this->db->query($sql)) {
2934 $this->errors[] = $this->error;
2938 if (!$error && !$notrigger) {
2940 $result = $this->
call_trigger(
'LINESHIPPING_DELETE', $user);
2942 $this->errors[] = $this->error;
2948 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
2953 $this->db->commit();
2956 foreach ($this->errors as $errmsg) {
2957 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2958 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2960 $this->db->rollback();
2972 public function update($user =
null, $notrigger = 0)
2976 dol_syslog(get_class($this).
"::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
2981 if (empty($this->qty)) {
2988 $expedition_batch_id =
null;
2989 if (is_array($this->detail_batch)) {
2990 if (count($this->detail_batch) > 1) {
2991 dol_syslog(get_class($this).
'::update only possible for one batch', LOG_ERR);
2992 $this->errors[] =
'ErrorBadParameters';
2995 $batch = $this->detail_batch[0]->batch;
2996 $batch_id = $this->detail_batch[0]->fk_origin_stock;
2997 $expedition_batch_id = $this->detail_batch[0]->id;
2998 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) {
2999 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3000 $this->errors[] =
'ErrorBadParameters';
3003 $qty =
price2num($this->detail_batch[0]->qty);
3005 } elseif (!empty($this->detail_batch)) {
3006 $batch = $this->detail_batch->batch;
3007 $batch_id = $this->detail_batch->fk_origin_stock;
3008 $expedition_batch_id = $this->detail_batch->id;
3009 if ($this->entrepot_id != $this->detail_batch->entrepot_id) {
3010 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
3011 $this->errors[] =
'ErrorBadParameters';
3014 $qty =
price2num($this->detail_batch->qty);
3018 if (!isset($this->
id) || !isset($this->entrepot_id)) {
3019 dol_syslog(get_class($this).
'::update missing line id and/or warehouse id', LOG_ERR);
3020 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3027 if (!empty($batch) && isModEnabled(
'productbatch')) {
3028 dol_syslog(get_class($this).
"::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch");
3030 if (empty($batch_id) || empty($this->fk_product)) {
3031 dol_syslog(get_class($this).
'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
3032 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
3039 if (!$error && ($lotArray = $shipmentlinebatch->fetchAll($this->id)) < 0) {
3040 $this->errors[] = $this->db->lasterror().
" - ExpeditionLineBatch::fetchAll";
3044 foreach ($lotArray as $lot) {
3045 if ($expedition_batch_id != $lot->id) {
3046 $remainingQty += $lot->qty;
3049 $qty += $remainingQty;
3054 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
3056 if ($lot->fetch(0, $this->fk_product, $batch) < 0) {
3057 $this->errors[] = $lot->errors;
3060 if (!$error && !empty($expedition_batch_id)) {
3062 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3063 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3064 $sql .=
" AND rowid = ".((int) $expedition_batch_id);
3066 if (!$this->db->query($sql)) {
3067 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3071 if (!$error && $this->detail_batch->qty > 0) {
3073 if (isset($lot->id)) {
3075 $shipmentLot->batch = $lot->batch;
3076 $shipmentLot->eatby = $lot->eatby;
3077 $shipmentLot->sellby = $lot->sellby;
3078 $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
3079 $shipmentLot->qty = $this->detail_batch->qty;
3080 $shipmentLot->fk_origin_stock = $batch_id;
3081 if ($shipmentLot->create($this->id) < 0) {
3082 $this->errors = $shipmentLot->errors;
3091 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3092 $sql .=
" fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id :
'null');
3093 $sql .=
" , qty = ".((float)
price2num($qty,
'MS'));
3094 $sql .=
" WHERE rowid = ".((int) $this->
id);
3096 if (!$this->db->query($sql)) {
3097 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3106 $this->errors[] = $this->error;
3112 if (!$error && !$notrigger) {
3114 $result = $this->
call_trigger(
'LINESHIPPING_MODIFY', $user);
3116 $this->errors[] = $this->error;
3122 $this->db->commit();
3125 foreach ($this->errors as $errmsg) {
3126 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3127 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3129 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
deleteline($user, $lineid)
Delete detail line.
setDraft($user, $notrigger=0)
Set draft status.
getUrlTrackingStatus($value='')
Forge an set tracking url.
setClosed()
Classify the shipping as closed (this record also the stock movement)
__construct($db)
Constructor.
list_delivery_methods($id='')
Fetch all deliveries method and return an array.
create($user, $notrigger=0)
Create expedition en base.
LibStatut($status, $mode)
Return label of a status.
setBilled()
Classify the shipping as invoiced (used for exemple by trigger when WORKFLOW_SHIPPING_CLASSIFY_BILLED...
addline_batch($dbatch, $array_options=0)
Add a shipment line with batch record.
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.
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.
getNextNumRef($soc)
Return next expedition ref.
const STATUS_CLOSED
Closed status.
const STATUS_VALIDATED
Validated status.
manageStockMvtOnEvt($user, $labelmovement='ShipmentClassifyClosedInDolibarr')
Manage Stock MVt onb Close or valid Shipment.
create_line_batch($line_ext, $array_options=0)
Create the detail of the expedition line.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
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.
addline($entrepot_id, $id, $qty, $array_options=0)
Add an expedition line.
fetch($id, $ref='', $ref_ext='', $notused='')
Get object and lines from database.
reOpen()
Classify the shipping as validated/opened.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=null)
Create a expedition line.
Classe 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($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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
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.