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 $picto =
'dolly';
91 public $fields = array();
96 public $user_author_id;
101 public $fk_user_author;
115 public $ref_customer;
127 public $tracking_number;
132 public $tracking_url;
141 public $weight_units;
145 public $height_units;
154 public $date_delivery;
172 public $date_shipping;
177 public $date_creation;
200 public $lines = array();
206 public $fk_multicurrency;
211 public $multicurrency_code;
212 public $multicurrency_tx;
213 public $multicurrency_total_ht;
214 public $multicurrency_total_tva;
215 public $multicurrency_total_ttc;
250 $this->statuts = array();
251 $this->statuts[-1] =
'StatusSendingCanceled';
252 $this->statuts[0] =
'StatusSendingDraft';
253 $this->statuts[1] =
'StatusSendingValidated';
254 $this->statuts[2] =
'StatusSendingProcessed';
257 $this->statuts_short = array();
258 $this->statuts_short[-1] =
'StatusSendingCanceledShort';
259 $this->statuts_short[0] =
'StatusSendingDraftShort';
260 $this->statuts_short[1] =
'StatusSendingValidatedShort';
261 $this->statuts_short[2] =
'StatusSendingProcessedShort';
272 global $langs, $conf;
273 $langs->load(
"sendings");
275 if (!empty($conf->global->EXPEDITION_ADDON_NUMBER)) {
278 $file = $conf->global->EXPEDITION_ADDON_NUMBER.
".php";
279 $classname = $conf->global->EXPEDITION_ADDON_NUMBER;
282 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
284 foreach ($dirmodels as $reldir) {
288 $mybool |= @include_once $dir.$file;
296 $obj =
new $classname();
298 $numref = $obj->getNextValue($soc, $this);
303 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
307 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
319 public function create($user, $notrigger = 0)
321 global $conf, $hookmanager;
325 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
329 $this->brouillon = 1;
331 if (empty($this->fk_project)) {
332 $this->fk_project = 0;
340 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
343 $sql .=
", ref_customer";
345 $sql .=
", date_creation";
346 $sql .=
", fk_user_author";
347 $sql .=
", date_expedition";
348 $sql .=
", date_delivery";
350 $sql .=
", fk_projet";
351 $sql .=
", fk_address";
352 $sql .=
", fk_shipping_method";
353 $sql .=
", tracking_number";
358 $sql .=
", weight_units";
359 $sql .=
", size_units";
360 $sql .=
", note_private";
361 $sql .=
", note_public";
362 $sql .=
", model_pdf";
363 $sql .=
", fk_incoterms, location_incoterms";
364 $sql .=
") VALUES (";
366 $sql .=
", ".((int) $conf->entity);
367 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
368 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
369 $sql .=
", '".$this->db->idate($now).
"'";
370 $sql .=
", ".((int) $user->id);
371 $sql .=
", ".($this->date_expedition > 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
"null");
372 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
373 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
374 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
375 $sql .=
", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address :
"null");
376 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
377 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
378 $sql .=
", ".(is_numeric($this->weight) ? $this->weight :
'NULL');
379 $sql .=
", ".(is_numeric($this->sizeS) ? $this->sizeS :
'NULL');
380 $sql .=
", ".(is_numeric($this->sizeW) ? $this->sizeW :
'NULL');
381 $sql .=
", ".(is_numeric($this->sizeH) ? $this->sizeH :
'NULL');
382 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
383 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
384 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
385 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
386 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
387 $sql .=
", ".(int) $this->fk_incoterms;
388 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
391 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
392 $resql = $this->db->query($sql);
394 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
396 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
397 $sql .=
" SET ref = '(PROV".$this->id.
")'";
398 $sql .=
" WHERE rowid = ".((int) $this->
id);
400 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
401 if ($this->db->query($sql)) {
403 $num = count($this->lines);
404 for ($i = 0; $i < $num; $i++) {
405 if (empty($this->lines[$i]->product_type) || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
406 if (!isset($this->lines[$i]->detail_batch)) {
407 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) {
411 if ($this->
create_line_batch($this->lines[$i], $this->lines[$i]->array_options) <= 0) {
418 if (!$error && $this->
id && $this->origin_id) {
433 if (!$error && !$notrigger) {
435 $result = $this->
call_trigger(
'SHIPPING_CREATE', $user);
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
447 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
449 $this->db->rollback();
454 $this->db->rollback();
459 $this->error = $this->db->lasterror().
" - sql=$sql";
460 $this->db->rollback();
465 $this->error = $this->db->error().
" - sql=$sql";
466 $this->db->rollback();
482 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options =
null)
488 $expeditionline->fk_expedition = $this->id;
489 $expeditionline->entrepot_id = $entrepot_id;
490 $expeditionline->fk_origin_line = $origin_line_id;
491 $expeditionline->qty = $qty;
492 $expeditionline->rang = $rang;
493 $expeditionline->array_options = $array_options;
495 if (($lineId = $expeditionline->insert($user)) < 0) {
496 $this->errors[] = $expeditionline->error;
514 $stockLocationQty = array();
516 $tab = $line_ext->detail_batch;
518 foreach ($tab as $detbatch) {
519 if (!empty($detbatch->entrepot_id)) {
520 if (empty($stockLocationQty[$detbatch->entrepot_id])) {
521 $stockLocationQty[$detbatch->entrepot_id] = 0;
523 $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty;
527 foreach ($stockLocationQty as $stockLocation => $qty) {
528 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
533 foreach ($tab as $detbatch) {
534 if ($detbatch->entrepot_id == $stockLocation) {
535 if (!($detbatch->create($line_id) > 0)) {
536 $this->errors = $detbatch->errors;
560 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
565 if (empty($id) && empty($ref) && empty($ref_ext)) {
569 $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";
570 $sql .=
", e.date_valid";
571 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
572 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
573 $sql .=
", e.fk_shipping_method, e.tracking_number";
574 $sql .=
", e.note_private, e.note_public";
575 $sql .=
', e.fk_incoterms, e.location_incoterms';
576 $sql .=
', i.libelle as label_incoterms';
577 $sql .=
', s.libelle as shipping_method';
578 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
579 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
580 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
581 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
582 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
583 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
585 $sql .=
" AND e.rowid = ".((int) $id);
588 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
591 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
594 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
595 $result = $this->db->query($sql);
597 if ($this->db->num_rows($result)) {
598 $obj = $this->db->fetch_object($result);
600 $this->
id = $obj->rowid;
601 $this->entity = $obj->entity;
602 $this->
ref = $obj->ref;
603 $this->socid = $obj->socid;
604 $this->ref_customer = $obj->ref_customer;
605 $this->ref_ext = $obj->ref_ext;
606 $this->status = $obj->fk_statut;
607 $this->
statut = $this->status;
608 $this->user_author_id = $obj->fk_user_author;
609 $this->fk_user_author = $obj->fk_user_author;
610 $this->date_creation = $this->db->jdate($obj->date_creation);
611 $this->date_valid = $this->db->jdate($obj->date_valid);
612 $this->date = $this->db->jdate($obj->date_expedition);
613 $this->date_expedition = $this->db->jdate($obj->date_expedition);
614 $this->date_shipping = $this->db->jdate($obj->date_expedition);
615 $this->date_delivery = $this->db->jdate($obj->date_delivery);
616 $this->fk_delivery_address = $obj->fk_address;
617 $this->model_pdf = $obj->model_pdf;
618 $this->modelpdf = $obj->model_pdf;
619 $this->shipping_method_id = $obj->fk_shipping_method;
620 $this->shipping_method = $obj->shipping_method;
621 $this->tracking_number = $obj->tracking_number;
622 $this->origin = ($obj->origin ? $obj->origin :
'commande');
623 $this->origin_id = $obj->origin_id;
624 $this->billed = $obj->billed;
625 $this->fk_project = $obj->fk_project;
627 $this->trueWeight = $obj->weight;
628 $this->weight_units = $obj->weight_units;
630 $this->trueWidth = $obj->width;
631 $this->width_units = $obj->size_units;
632 $this->trueHeight = $obj->height;
633 $this->height_units = $obj->size_units;
634 $this->trueDepth = $obj->size;
635 $this->depth_units = $obj->size_units;
637 $this->note_public = $obj->note_public;
638 $this->note_private = $obj->note_private;
641 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
642 $this->size_units = $obj->size_units;
645 $this->fk_incoterms = $obj->fk_incoterms;
646 $this->location_incoterms = $obj->location_incoterms;
647 $this->label_incoterms = $obj->label_incoterms;
649 $this->db->free($result);
651 if ($this->
statut == self::STATUS_DRAFT) {
652 $this->brouillon = 1;
665 if (isModEnabled(
'multicurrency')) {
666 if (!empty($this->multicurrency_code)) {
667 $this->multicurrency_code = $this->thirdparty->multicurrency_code;
669 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($this->thirdparty->multicurrency_tx)) {
670 $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
684 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
685 $this->error =
'Shipment with id '.$id.
' not found';
689 $this->error = $this->db->error();
701 public function valid($user, $notrigger = 0)
703 global $conf, $langs;
705 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
711 dol_syslog(get_class($this).
"::valid not in draft status", LOG_WARNING);
715 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))
716 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate)))) {
717 $this->error =
'Permission denied';
718 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
728 $soc->fetch($this->socid);
731 $result = $soc->set_as_client();
734 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
736 } elseif (!empty($this->
ref)) {
737 $numref = $this->ref;
739 $numref =
"EXP".$this->id;
746 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
747 $sql .=
" ref='".$this->db->escape($numref).
"'";
748 $sql .=
", fk_statut = 1";
749 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
750 $sql .=
", fk_user_valid = ".$user->id;
751 $sql .=
" WHERE rowid = ".((int) $this->
id);
753 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
754 $resql = $this->db->query($sql);
756 $this->error = $this->db->lasterror();
761 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
774 if (!$error && !$notrigger) {
776 $result = $this->
call_trigger(
'SHIPPING_VALIDATE', $user);
784 $this->oldref = $this->ref;
787 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
789 $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).
"'";
790 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
791 $resql = $this->db->query($sql);
793 $error++; $this->error = $this->db->lasterror();
795 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
796 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
797 $resql = $this->db->query($sql);
799 $error++; $this->error = $this->db->lasterror();
805 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
806 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
807 if (!$error && file_exists($dirsource)) {
808 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
810 if (@rename($dirsource, $dirdest)) {
813 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
814 foreach ($listoffiles as $fileentry) {
815 $dirsource = $fileentry[
'name'];
816 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
817 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
818 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
819 @rename($dirsource, $dirdest);
828 $this->
ref = $numref;
836 $this->db->rollback();
855 if ($this->
statut == self::STATUS_VALIDATED || $this->
statut == self::STATUS_CLOSED) {
857 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
858 $delivery =
new Delivery($this->db);
859 $result = $delivery->create_from_sending($user, $this->
id);
863 $this->error = $delivery->error;
886 public function addline($entrepot_id, $id, $qty, $array_options = 0)
888 global $conf, $langs;
890 $num = count($this->lines);
893 $line->entrepot_id = $entrepot_id;
894 $line->origin_line_id = $id;
895 $line->fk_origin_line = $id;
899 $orderline->fetch($id);
902 $line->rang = $orderline->rang;
903 $line->product_type = $orderline->product_type;
905 if (isModEnabled(
'stock') && !empty($orderline->fk_product)) {
906 $fk_product = $orderline->fk_product;
908 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) {
909 $langs->load(
"errors");
910 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
914 if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)) {
915 $product =
new Product($this->db);
916 $product->fetch($fk_product);
919 if ($entrepot_id > 0) {
920 $product->load_stock(
'warehouseopen');
921 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
923 $product_stock = $product->stock_reel;
926 $product_type = $product->type;
927 if ($product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
928 $isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
930 if (!$isavirtualproduct || empty($conf->global->PRODUIT_SOUSPRODUITS) || ($isavirtualproduct && empty($conf->global->STOCK_EXCLUDE_VIRTUAL_PRODUCTS))) {
931 if ($product_stock < $qty) {
932 $langs->load(
"errors");
933 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
934 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
936 $this->db->rollback();
946 if (isModEnabled(
'productbatch') && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) {
947 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$orderline->fk_product;
952 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
953 $line->array_options = $array_options;
956 $this->lines[$num] = $line;
972 global $conf, $langs;
974 $num = count($this->lines);
975 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
978 foreach ($dbatch[
'detail'] as $key => $value) {
979 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
985 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
987 $this->error = $linebatch->error;
990 $linebatch->qty = $value[
'q'];
992 $linebatch->batch =
null;
997 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
999 $prod_batch->fetch($value[
'id_batch']);
1001 if ($prod_batch->qty < $linebatch->qty) {
1002 $langs->load(
"errors");
1003 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1004 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1005 $this->db->rollback();
1013 $line->entrepot_id = $linebatch->entrepot_id;
1014 $line->origin_line_id = $dbatch[
'ix_l'];
1015 $line->fk_origin_line = $dbatch[
'ix_l'];
1016 $line->qty = $dbatch[
'qty'];
1017 $line->detail_batch = $tab;
1020 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
1021 $line->array_options = $array_options;
1025 $this->lines[$num] = $line;
1037 public function update($user =
null, $notrigger = 0)
1044 if (isset($this->
ref)) {
1045 $this->
ref = trim($this->
ref);
1047 if (isset($this->entity)) {
1048 $this->entity = (int) $this->entity;
1050 if (isset($this->ref_customer)) {
1051 $this->ref_customer = trim($this->ref_customer);
1053 if (isset($this->socid)) {
1054 $this->socid = (int) $this->socid;
1056 if (isset($this->fk_user_author)) {
1057 $this->fk_user_author = (int) $this->fk_user_author;
1059 if (isset($this->fk_user_valid)) {
1060 $this->fk_user_valid = (int) $this->fk_user_valid;
1062 if (isset($this->fk_delivery_address)) {
1063 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1065 if (isset($this->shipping_method_id)) {
1066 $this->shipping_method_id = (int) $this->shipping_method_id;
1068 if (isset($this->tracking_number)) {
1069 $this->tracking_number = trim($this->tracking_number);
1071 if (isset($this->
statut)) {
1074 if (isset($this->trueDepth)) {
1075 $this->trueDepth = trim($this->trueDepth);
1077 if (isset($this->trueWidth)) {
1078 $this->trueWidth = trim($this->trueWidth);
1080 if (isset($this->trueHeight)) {
1081 $this->trueHeight = trim($this->trueHeight);
1083 if (isset($this->size_units)) {
1084 $this->size_units = trim($this->size_units);
1086 if (isset($this->weight_units)) {
1087 $this->weight_units = trim($this->weight_units);
1089 if (isset($this->trueWeight)) {
1090 $this->weight = trim($this->trueWeight);
1092 if (isset($this->note_private)) {
1093 $this->note_private = trim($this->note_private);
1095 if (isset($this->note_public)) {
1096 $this->note_public = trim($this->note_public);
1098 if (isset($this->model_pdf)) {
1099 $this->model_pdf = trim($this->model_pdf);
1106 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1107 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1108 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1109 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1110 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1111 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1112 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1113 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1114 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1115 $sql .=
" date_expedition=".(dol_strlen($this->date_expedition) != 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
'null').
",";
1116 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1117 $sql .=
" fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address :
"null").
",";
1118 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1119 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1120 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1121 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1122 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1123 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1124 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1125 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1126 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1127 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1128 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1129 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1130 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1131 $sql .=
" entity=".$conf->entity;
1132 $sql .=
" WHERE rowid=".((int) $this->
id);
1136 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1137 $resql = $this->db->query($sql);
1139 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1142 if (!$error && !$notrigger) {
1144 $result = $this->
call_trigger(
'SHIPPING_MODIFY', $user);
1153 foreach ($this->errors as $errmsg) {
1154 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1155 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1157 $this->db->rollback();
1160 $this->db->commit();
1173 public function cancel($notrigger = 0, $also_update_stock =
false)
1175 global $conf, $langs, $user;
1177 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1186 if (count($this->linkedObjectsIds) > 0) {
1187 $this->error =
'ErrorThereIsSomeDeliveries';
1191 if (!$error && !$notrigger) {
1193 $result = $this->
call_trigger(
'SHIPPING_CANCEL', $user);
1201 if (!$error && isModEnabled(
'stock') &&
1202 (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) ||
1203 ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) {
1204 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1206 $langs->load(
"agenda");
1209 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1210 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1211 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1212 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1213 $sql .=
" AND cd.rowid = ed.fk_origin_line";
1215 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1216 $resql = $this->db->query($sql);
1218 $cpt = $this->db->num_rows($resql);
1222 for ($i = 0; $i < $cpt; $i++) {
1223 dol_syslog(get_class($this).
"::delete movement index ".$i);
1224 $obj = $this->db->fetch_object($resql);
1228 $mouvS->origin =
null;
1231 if (isModEnabled(
'productbatch')) {
1232 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1233 if (!is_array($lotArray)) {
1235 $this->errors[] =
"Error ".$this->db->lasterror();
1239 if (empty($lotArray)) {
1243 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref));
1246 $this->errors = array_merge($this->errors, $mouvS->errors);
1252 foreach ($lotArray as $lot) {
1253 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1256 $this->errors = array_merge($this->errors, $mouvS->errors);
1266 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1271 if (!$error && isModEnabled(
'productbatch')) {
1273 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1274 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1280 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1281 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1283 if ($this->db->query($sql)) {
1292 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"expedition";
1293 $sql .=
" WHERE rowid = ".((int) $this->
id);
1295 if ($this->db->query($sql)) {
1296 if (!empty($this->origin) && $this->origin_id > 0) {
1298 $origin = $this->origin;
1301 $this->$origin->loadExpeditions();
1303 if (count($this->$origin->expeditions) <= 0) {
1310 $this->db->commit();
1314 if (!empty($conf->expedition->dir_output)) {
1315 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1316 $file = $dir.
'/'.$ref.
'.pdf';
1317 if (file_exists($file)) {
1322 if (file_exists($dir)) {
1324 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1332 $this->db->rollback();
1336 $this->error = $this->db->lasterror().
" - sql=$sql";
1337 $this->db->rollback();
1341 $this->error = $this->db->lasterror().
" - sql=$sql";
1342 $this->db->rollback();
1346 $this->error = $this->db->lasterror().
" - sql=$sql";
1347 $this->db->rollback();
1351 $this->db->rollback();
1364 public function delete($notrigger = 0, $also_update_stock =
false)
1366 global $conf, $langs, $user;
1368 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1377 if (count($this->linkedObjectsIds) > 0) {
1378 $this->error =
'ErrorThereIsSomeDeliveries';
1382 if (!$error && !$notrigger) {
1384 $result = $this->
call_trigger(
'SHIPPING_DELETE', $user);
1392 if (!$error && isModEnabled(
'stock') &&
1393 (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) ||
1394 ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) {
1395 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1397 $langs->load(
"agenda");
1403 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1405 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1406 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1407 $sql .=
" AND cd.rowid = ed.fk_origin_line";
1409 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1410 $resql = $this->db->query($sql);
1412 $cpt = $this->db->num_rows($resql);
1413 for ($i = 0; $i < $cpt; $i++) {
1414 dol_syslog(get_class($this).
"::delete movement index ".$i);
1415 $obj = $this->db->fetch_object($resql);
1419 $mouvS->origin =
null;
1421 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1422 if (!is_array($lotArray)) {
1423 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1425 if (empty($lotArray)) {
1429 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref));
1432 $this->errors = array_merge($this->errors, $mouvS->errors);
1438 foreach ($lotArray as $lot) {
1439 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1442 $this->errors = array_merge($this->errors, $mouvS->errors);
1452 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1459 if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
1460 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1465 $main = MAIN_DB_PREFIX.
'expeditiondet';
1466 $ef = $main.
"_extrafields";
1467 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".((int) $this->
id).
")";
1469 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1470 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1472 if ($this->db->query($sqlef) && $this->db->query($sql)) {
1486 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expedition";
1487 $sql .=
" WHERE rowid = ".((int) $this->
id);
1489 if ($this->db->query($sql)) {
1490 if (!empty($this->origin) && $this->origin_id > 0) {
1492 $origin = $this->origin;
1495 $this->$origin->loadExpeditions();
1497 if (count($this->$origin->expeditions) <= 0) {
1504 $this->db->commit();
1511 if (!empty($conf->expedition->dir_output)) {
1512 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1513 $file = $dir.
'/'.$ref.
'.pdf';
1514 if (file_exists($file)) {
1519 if (file_exists($dir)) {
1521 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1529 $this->db->rollback();
1533 $this->error = $this->db->lasterror().
" - sql=$sql";
1534 $this->db->rollback();
1538 $this->error = $this->db->lasterror().
" - sql=$sql";
1539 $this->db->rollback();
1543 $this->error = $this->db->lasterror().
" - sql=$sql";
1544 $this->db->rollback();
1548 $this->db->rollback();
1562 global $conf, $mysoc;
1564 $this->lines = array();
1569 $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";
1570 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1571 $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";
1572 $sql .=
", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang";
1573 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1574 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type";
1575 $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";
1576 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
1577 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
1578 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1579 $sql .=
" AND ed.fk_origin_line = cd.rowid";
1580 $sql .=
" ORDER BY cd.rang, ed.fk_origin_line";
1582 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1583 $resql = $this->db->query($sql);
1585 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1587 $num = $this->db->num_rows($resql);
1592 $this->total_ht = 0;
1593 $this->total_tva = 0;
1594 $this->total_ttc = 0;
1595 $this->total_localtax1 = 0;
1596 $this->total_localtax2 = 0;
1598 $this->multicurrency_total_ht = 0;
1599 $this->multicurrency_total_tva = 0;
1600 $this->multicurrency_total_ttc = 0;
1605 $obj = $this->db->fetch_object($resql);
1608 if ($originline > 0 && $originline == $obj->fk_origin_line) {
1609 $line->entrepot_id = 0;
1610 $line->qty_shipped += $obj->qty_shipped;
1613 $line->entrepot_id = $obj->fk_entrepot;
1614 $line->qty_shipped = $obj->qty_shipped;
1617 $detail_entrepot =
new stdClass();
1618 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
1619 $detail_entrepot->qty_shipped = $obj->qty_shipped;
1620 $detail_entrepot->line_id = $obj->line_id;
1621 $line->details_entrepot[] = $detail_entrepot;
1623 $line->line_id = $obj->line_id;
1624 $line->rowid = $obj->line_id;
1625 $line->id = $obj->line_id;
1627 $line->fk_origin =
'orderline';
1628 $line->fk_origin_line = $obj->fk_origin_line;
1629 $line->origin_line_id = $obj->fk_origin_line;
1631 $line->fk_expedition = $this->id;
1633 $line->product_type = $obj->product_type;
1634 $line->fk_product = $obj->fk_product;
1635 $line->fk_product_type = $obj->fk_product_type;
1636 $line->ref = $obj->product_ref;
1637 $line->product_ref = $obj->product_ref;
1638 $line->product_label = $obj->product_label;
1639 $line->libelle = $obj->product_label;
1640 $line->product_tosell = $obj->product_tosell;
1641 $line->product_tobuy = $obj->product_tobuy;
1642 $line->product_tobatch = $obj->product_tobatch;
1643 $line->label = $obj->custom_label;
1644 $line->description = $obj->description;
1645 $line->qty_asked = $obj->qty_asked;
1646 $line->rang = $obj->rang;
1647 $line->weight = $obj->weight;
1648 $line->weight_units = $obj->weight_units;
1649 $line->length = $obj->length;
1650 $line->length_units = $obj->length_units;
1651 $line->surface = $obj->surface;
1652 $line->surface_units = $obj->surface_units;
1653 $line->volume = $obj->volume;
1654 $line->volume_units = $obj->volume_units;
1655 $line->fk_unit = $obj->fk_unit;
1657 $line->pa_ht = $obj->pa_ht;
1660 $localtax_array = array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1661 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
1662 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
1665 $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);
1666 $line->desc = $obj->description;
1667 $line->qty = $line->qty_shipped;
1668 $line->total_ht = $tabprice[0];
1669 $line->total_localtax1 = $tabprice[9];
1670 $line->total_localtax2 = $tabprice[10];
1671 $line->total_ttc = $tabprice[2];
1672 $line->total_tva = $tabprice[1];
1673 $line->vat_src_code = $obj->vat_src_code;
1674 $line->tva_tx = $obj->tva_tx;
1675 $line->localtax1_tx = $obj->localtax1_tx;
1676 $line->localtax2_tx = $obj->localtax2_tx;
1677 $line->info_bits = $obj->info_bits;
1678 $line->price = $obj->price;
1679 $line->subprice = $obj->subprice;
1680 $line->remise_percent = $obj->remise_percent;
1682 $this->total_ht += $tabprice[0];
1683 $this->total_tva += $tabprice[1];
1684 $this->total_ttc += $tabprice[2];
1685 $this->total_localtax1 += $tabprice[9];
1686 $this->total_localtax2 += $tabprice[10];
1689 $this->fk_multicurrency = $obj->fk_multicurrency;
1690 $this->multicurrency_code = $obj->multicurrency_code;
1691 $line->multicurrency_subprice = $obj->multicurrency_subprice;
1692 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
1693 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
1694 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1696 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
1697 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
1698 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
1700 if ($originline != $obj->fk_origin_line) {
1701 $line->detail_batch = array();
1705 if (isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
1706 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
1708 if (is_array($newdetailbatch)) {
1709 if ($originline != $obj->fk_origin_line) {
1710 $line->detail_batch = $newdetailbatch;
1712 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1717 $line->fetch_optionals();
1719 if ($originline != $obj->fk_origin_line) {
1720 $this->lines[$lineindex] = $line;
1723 $line->total_ht += $tabprice[0];
1724 $line->total_localtax1 += $tabprice[9];
1725 $line->total_localtax2 += $tabprice[10];
1726 $line->total_ttc += $tabprice[2];
1727 $line->total_tva += $tabprice[1];
1731 $originline = $obj->fk_origin_line;
1733 $this->db->free($resql);
1736 $this->error = $this->db->error();
1752 if ($this->
statut == self::STATUS_DRAFT) {
1758 $line->fetch($lineid);
1760 if ($line->delete($user) > 0) {
1763 $this->db->commit();
1766 $this->db->rollback();
1770 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1785 global $conf, $langs;
1787 $langs->load(
'sendings');
1789 $nofetch = !empty($params[
'nofetch']);
1792 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
1793 if (isset($this->
statut)) {
1794 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1796 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1797 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1799 $langs->load(
'companies');
1800 if (empty($this->thirdparty)) {
1803 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1820 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1822 global $langs, $conf, $hookmanager;
1827 'objecttype' => $this->element,
1828 'option' => $option,
1831 $classfortooltip =
'classfortooltip';
1834 $classfortooltip =
'classforajaxtooltip';
1835 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1841 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
1847 if ($option !==
'nolink') {
1849 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1850 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1851 $add_save_lastsearch_values = 1;
1853 if ($add_save_lastsearch_values) {
1854 $url .=
'&save_lastsearch_values=1';
1859 if (empty($notooltip)) {
1860 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1861 $label = $langs->trans(
"Shipment");
1862 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1864 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1865 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1868 $linkstart =
'<a href="'.$url.
'"';
1869 $linkstart .= $linkclose.
'>';
1872 $result .= $linkstart;
1874 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1876 if ($withpicto != 2) {
1877 $result .= $this->ref;
1879 $result .= $linkend;
1881 $hookmanager->initHooks(array($this->element .
'dao'));
1882 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1883 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1885 $result = $hookmanager->resPrint;
1887 $result .= $hookmanager->resPrint;
1916 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
1917 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
1919 $statusType =
'status'.$status;
1920 if ($status == self::STATUS_VALIDATED) {
1921 $statusType =
'status4';
1923 if ($status == self::STATUS_CLOSED) {
1924 $statusType =
'status6';
1926 if ($status == self::STATUS_CANCELED) {
1927 $statusType =
'status9';
1930 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1946 dol_syslog(get_class($this).
"::initAsSpecimen");
1949 $order->initAsSpecimen();
1953 $this->
ref =
'SPECIMEN';
1954 $this->specimen = 1;
1956 $this->livraison_id = 0;
1958 $this->date_creation = $now;
1959 $this->date_valid = $now;
1960 $this->date_delivery = $now + 24 * 3600;
1961 $this->date_expedition = $now + 24 * 3600;
1963 $this->entrepot_id = 0;
1964 $this->fk_delivery_address = 0;
1967 $this->commande_id = 0;
1968 $this->commande = $order;
1970 $this->origin_id = 1;
1971 $this->origin =
'commande';
1973 $this->note_private =
'Private note';
1974 $this->note_public =
'Public note';
1978 while ($xnbp < $nbp) {
1980 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1981 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1982 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1984 $line->qty_asked = 5;
1985 $line->qty_shipped = 4;
1986 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1988 $this->lines[] = $line;
2017 if ($user->rights->expedition->creer) {
2018 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2019 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2020 $sql .=
" WHERE rowid = ".((int) $this->
id);
2022 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2023 $resql = $this->db->query($sql);
2025 $this->date_delivery = $delivery_date;
2028 $this->error = $this->db->error();
2046 $this->meths = array();
2048 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2049 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2050 $sql .=
" WHERE em.active = 1";
2051 $sql .=
" ORDER BY em.libelle ASC";
2053 $resql = $this->db->query($sql);
2055 while ($obj = $this->db->fetch_object($resql)) {
2056 $label = $langs->trans(
'SendingMethod'.$obj->code);
2057 $this->meths[$obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2074 $this->listmeths = array();
2077 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2078 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2080 $sql .=
" WHERE em.rowid=".((int) $id);
2083 $resql = $this->db->query($sql);
2085 while ($obj = $this->db->fetch_object($resql)) {
2086 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2087 $this->listmeths[$i][
'code'] = $obj->code;
2088 $label = $langs->trans(
'SendingMethod'.$obj->code);
2089 $this->listmeths[$i][
'libelle'] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2090 $this->listmeths[$i][
'description'] = $obj->description;
2091 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2092 $this->listmeths[$i][
'active'] = $obj->active;
2106 if (!empty($this->shipping_method_id)) {
2107 $sql =
"SELECT em.code, em.tracking";
2108 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2109 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
2111 $resql = $this->db->query($sql);
2113 if ($obj = $this->db->fetch_object($resql)) {
2114 $tracking = $obj->tracking;
2119 if (!empty($tracking) && !empty($value)) {
2120 $url = str_replace(
'{TRACKID}', $value, $tracking);
2121 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
2123 $this->tracking_url = $value;
2134 global $conf, $langs, $user;
2139 if ($this->
statut == self::STATUS_CLOSED) {
2146 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
2148 $resql = $this->db->query($sql);
2151 if ($this->origin ==
'commande' && $this->origin_id > 0) {
2153 $order->fetch($this->origin_id);
2155 $order->loadExpeditions(self::STATUS_CLOSED);
2157 $shipments_match_order = 1;
2158 foreach ($order->lines as $line) {
2159 $lineid = $line->id;
2161 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty) {
2162 $shipments_match_order = 0;
2163 $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';
2168 if ($shipments_match_order) {
2169 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');
2171 $order->cloture($user);
2179 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
2188 $result = $this->
call_trigger(
'SHIPPING_CLOSED', $user);
2199 $this->db->commit();
2205 $this->db->rollback();
2225 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
2227 $langs->load(
"agenda");
2230 $sql =
"SELECT cd.fk_product, cd.subprice,";
2231 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2233 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock,";
2234 $sql .=
" cd.rowid as cdid, ed.rowid as edid";
2235 $sql .=
" FROM " . MAIN_DB_PREFIX .
"commandedet as cd,";
2236 $sql .=
" " . MAIN_DB_PREFIX .
"expeditiondet as ed";
2237 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2238 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"expedition as e ON ed.fk_expedition = e.rowid";
2239 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
2240 $sql .=
" AND cd.rowid = ed.fk_origin_line";
2242 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
2243 $resql = $this->db->query($sql);
2245 $cpt = $this->db->num_rows($resql);
2246 for ($i = 0; $i < $cpt; $i++) {
2247 $obj = $this->db->fetch_object($resql);
2248 if (empty($obj->edbrowid)) {
2251 $qty = $obj->edbqty;
2253 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
2256 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->rowid .
" edb.rowid=" . $obj->edbrowid);
2259 $mouvS->origin = &$this;
2260 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
2262 if (empty($obj->edbrowid)) {
2266 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref));
2268 $this->error = $mouvS->error;
2269 $this->errors = $mouvS->errors;
2277 $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);
2279 $this->error = $mouvS->error;
2280 $this->errors = $mouvS->errors;
2288 $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)";
2289 $resqldelete = $this->db->query($sqldelete);
2293 $this->error = $this->db->lasterror();
2294 $this->errors[] = $this->db->lasterror();
2317 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut=2, billed=1';
2318 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2320 $resql = $this->db->query($sql);
2326 $result = $this->
call_trigger(
'SHIPPING_BILLED', $user);
2332 $this->errors[] = $this->db->lasterror;
2335 if (empty($error)) {
2336 $this->db->commit();
2341 $this->db->rollback();
2356 if ($this->
statut <= self::STATUS_DRAFT) {
2360 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
2370 global $conf, $langs, $user;
2375 if ($this->
statut == self::STATUS_VALIDATED) {
2381 $oldbilled = $this->billed;
2383 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
2384 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
2386 $resql = $this->db->query($sql);
2392 if (!$error && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
2393 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2395 $langs->load(
"agenda");
2399 $sql =
"SELECT cd.fk_product, cd.subprice,";
2400 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2401 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2402 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2403 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2404 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2405 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2406 $sql .=
" AND cd.rowid = ed.fk_origin_line";
2408 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2409 $resql = $this->db->query($sql);
2411 $cpt = $this->db->num_rows($resql);
2412 for ($i = 0; $i < $cpt; $i++) {
2413 $obj = $this->db->fetch_object($resql);
2414 if (empty($obj->edbrowid)) {
2417 $qty = $obj->edbqty;
2422 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2426 $mouvS->origin = &$this;
2427 $mouvS->setOrigin($this->element, $this->
id);
2429 if (empty($obj->edbrowid)) {
2433 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
2435 $this->error = $mouvS->error;
2436 $this->errors = $mouvS->errors;
2444 $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);
2446 $this->error = $mouvS->error;
2447 $this->errors = $mouvS->errors;
2454 $this->error = $this->db->lasterror();
2461 $result = $this->
call_trigger(
'SHIPPING_REOPEN', $user);
2468 $this->errors[] = $this->db->lasterror();
2472 $this->db->commit();
2476 $this->billed = $oldbilled;
2477 $this->db->rollback();
2493 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2497 $outputlangs->load(
"products");
2502 if (!empty($this->model_pdf)) {
2503 $modele = $this->model_pdf;
2504 } elseif (!empty($this->modelpdf)) {
2505 $modele = $this->modelpdf;
2506 } elseif (!empty($conf->global->EXPEDITION_ADDON_PDF)) {
2507 $modele = $conf->global->EXPEDITION_ADDON_PDF;
2511 $modelpath =
"core/modules/expedition/doc/";
2515 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2545 public $element =
'expeditiondet';
2550 public $table_element =
'expeditiondet';
2577 public $fk_origin_line;
2582 public $fk_expedition;
2597 public $qty_shipped;
2606 public $detail_batch;
2610 public $details_entrepot;
2616 public $entrepot_id;
2633 public $product_ref;
2644 public $product_label;
2656 public $product_desc;
2662 public $product_type = 0;
2673 public $weight_units;
2679 public $length_units;
2685 public $surface_units;
2691 public $volume_units;
2694 public $remise_percent;
2715 public $total_localtax1;
2720 public $total_localtax2;
2741 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang';
2742 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as ed';
2743 $sql .=
' WHERE ed.rowid = '.((int) $rowid);
2744 $result = $this->db->query($sql);
2746 $objp = $this->db->fetch_object($result);
2747 $this->
id = $objp->rowid;
2748 $this->fk_expedition = $objp->fk_expedition;
2749 $this->entrepot_id = $objp->fk_entrepot;
2750 $this->fk_origin_line = $objp->fk_origin_line;
2751 $this->qty = $objp->qty;
2752 $this->rang = $objp->rang;
2754 $this->db->free($result);
2758 $this->errors[] = $this->db->lasterror();
2759 $this->error = $this->db->lasterror();
2771 public function insert($user, $notrigger = 0)
2773 global $langs, $conf;
2778 if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) {
2779 $this->error =
'ErrorMandatoryParametersNotProvided';
2785 if (empty($this->rang)) {
2790 $ranktouse = $this->rang;
2791 if ($ranktouse == -1) {
2792 $rangmax = $this->
line_max($this->fk_expedition);
2793 $ranktouse = $rangmax + 1;
2796 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expeditiondet (";
2797 $sql .=
"fk_expedition";
2798 $sql .=
", fk_entrepot";
2799 $sql .=
", fk_origin_line";
2802 $sql .=
") VALUES (";
2803 $sql .= $this->fk_expedition;
2804 $sql .=
", ".(empty($this->entrepot_id) ?
'NULL' : $this->entrepot_id);
2805 $sql .=
", ".((int) $this->fk_origin_line);
2806 $sql .=
", ".price2num($this->qty,
'MS');
2807 $sql .=
", ".((int) $ranktouse);
2810 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2811 $resql = $this->db->query($sql);
2813 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expeditiondet");
2822 if (!$error && !$notrigger) {
2824 $result = $this->
call_trigger(
'LINESHIPPING_INSERT', $user);
2832 foreach ($this->errors as $errmsg) {
2833 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2834 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2842 $this->db->rollback();
2845 $this->db->commit();
2857 public function delete($user =
null, $notrigger = 0)
2864 if (isModEnabled(
'productbatch')) {
2865 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
2866 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
2868 if (!$this->db->query($sql)) {
2869 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
2874 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
2875 $sql .=
" WHERE rowid = ".((int) $this->
id);
2877 if (!$error && $this->db->query($sql)) {
2882 $this->errors[] = $this->error;
2886 if (!$error && !$notrigger) {
2888 $result = $this->
call_trigger(
'LINESHIPPING_DELETE', $user);
2890 $this->errors[] = $this->error;
2896 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
2901 $this->db->commit();
2904 foreach ($this->errors as $errmsg) {
2905 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2906 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2908 $this->db->rollback();
2920 public function update($user =
null, $notrigger = 0)
2924 dol_syslog(get_class($this).
"::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
2929 if (empty($this->qty)) {
2936 $expedition_batch_id =
null;
2937 if (is_array($this->detail_batch)) {
2938 if (count($this->detail_batch) > 1) {
2939 dol_syslog(get_class($this).
'::update only possible for one batch', LOG_ERR);
2940 $this->errors[] =
'ErrorBadParameters';
2943 $batch = $this->detail_batch[0]->batch;
2944 $batch_id = $this->detail_batch[0]->fk_origin_stock;
2945 $expedition_batch_id = $this->detail_batch[0]->id;
2946 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) {
2947 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
2948 $this->errors[] =
'ErrorBadParameters';
2951 $qty =
price2num($this->detail_batch[0]->qty);
2953 } elseif (!empty($this->detail_batch)) {
2954 $batch = $this->detail_batch->batch;
2955 $batch_id = $this->detail_batch->fk_origin_stock;
2956 $expedition_batch_id = $this->detail_batch->id;
2957 if ($this->entrepot_id != $this->detail_batch->entrepot_id) {
2958 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
2959 $this->errors[] =
'ErrorBadParameters';
2962 $qty =
price2num($this->detail_batch->qty);
2966 if (!isset($this->
id) || !isset($this->entrepot_id)) {
2967 dol_syslog(get_class($this).
'::update missing line id and/or warehouse id', LOG_ERR);
2968 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
2975 if (!empty($batch) && isModEnabled(
'productbatch')) {
2976 dol_syslog(get_class($this).
"::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch");
2978 if (empty($batch_id) || empty($this->fk_product)) {
2979 dol_syslog(get_class($this).
'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
2980 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
2987 if (!$error && ($lotArray = $shipmentlinebatch->fetchAll($this->id)) < 0) {
2988 $this->errors[] = $this->db->lasterror().
" - ExpeditionLineBatch::fetchAll";
2992 foreach ($lotArray as $lot) {
2993 if ($expedition_batch_id != $lot->id) {
2994 $remainingQty += $lot->qty;
2997 $qty += $remainingQty;
3002 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
3004 if ($lot->fetch(0, $this->fk_product, $batch) < 0) {
3005 $this->errors[] = $lot->errors;
3008 if (!$error && !empty($expedition_batch_id)) {
3010 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
3011 $sql .=
" WHERE fk_expeditiondet = ".((int) $this->
id);
3012 $sql .=
" AND rowid = ".((int) $expedition_batch_id);
3014 if (!$this->db->query($sql)) {
3015 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3019 if (!$error && $this->detail_batch->qty > 0) {
3021 if (isset($lot->id)) {
3023 $shipmentLot->batch = $lot->batch;
3024 $shipmentLot->eatby = $lot->eatby;
3025 $shipmentLot->sellby = $lot->sellby;
3026 $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
3027 $shipmentLot->qty = $this->detail_batch->qty;
3028 $shipmentLot->fk_origin_stock = $batch_id;
3029 if ($shipmentLot->create($this->id) < 0) {
3030 $this->errors = $shipmentLot->errors;
3039 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3040 $sql .=
" fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id :
'null');
3041 $sql .=
" , qty = ".((float)
price2num($qty,
'MS'));
3042 $sql .=
" WHERE rowid = ".((int) $this->
id);
3044 if (!$this->db->query($sql)) {
3045 $this->errors[] = $this->db->lasterror().
" - sql=$sql";
3054 $this->errors[] = $this->error;
3060 if (!$error && !$notrigger) {
3062 $result = $this->
call_trigger(
'LINESHIPPING_MODIFY', $user);
3064 $this->errors[] = $this->error;
3070 $this->db->commit();
3073 foreach ($this->errors as $errmsg) {
3074 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3075 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3077 $this->db->rollback();
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='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
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.
__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 when WORKFLOW_BILL_ON_SHIPMENT is on)
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.
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.
Manage record for batch number management.
Class with list of lots and properties.
Class to manage third parties objects (customers, suppliers, prospects...)
print $langs trans("Ref").' m m m statut
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 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.
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.