37 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
40 if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
41 if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
42 if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionbatch.class.php';
55 public $element =
"shipping";
60 public $fk_element =
"fk_expedition";
65 public $table_element =
"expedition";
70 public $table_element_line =
"expeditiondet";
76 public $ismultientitymanaged = 1;
81 public $picto =
'dolly';
113 public $tracking_number;
118 public $tracking_url;
127 public $weight_units;
131 public $height_units;
140 public $date_delivery;
158 public $date_shipping;
163 public $date_creation;
173 public $lines = array();
209 $this->statuts = array();
210 $this->statuts[-1] =
'StatusSendingCanceled';
211 $this->statuts[0] =
'StatusSendingDraft';
212 $this->statuts[1] =
'StatusSendingValidated';
213 $this->statuts[2] =
'StatusSendingProcessed';
216 $this->statutshorts = array();
217 $this->statutshorts[-1] =
'StatusSendingCanceledShort';
218 $this->statutshorts[0] =
'StatusSendingDraftShort';
219 $this->statutshorts[1] =
'StatusSendingValidatedShort';
220 $this->statutshorts[2] =
'StatusSendingProcessedShort';
231 global $langs, $conf;
232 $langs->load(
"sendings");
234 if (!empty($conf->global->EXPEDITION_ADDON_NUMBER))
238 $file = $conf->global->EXPEDITION_ADDON_NUMBER.
".php";
239 $classname = $conf->global->EXPEDITION_ADDON_NUMBER;
242 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
244 foreach ($dirmodels as $reldir) {
248 $mybool |= @include_once $dir.$file;
257 $obj =
new $classname();
259 $numref = $obj->getNextValue($soc, $this);
269 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
281 public function create($user, $notrigger = 0)
283 global $conf, $hookmanager;
287 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
291 $this->brouillon = 1;
293 if (empty($this->fk_project)) $this->fk_project = 0;
300 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
304 $sql .=
", ref_customer";
307 $sql .=
", date_creation";
308 $sql .=
", fk_user_author";
309 $sql .=
", date_expedition";
310 $sql .=
", date_delivery";
312 $sql .=
", fk_projet";
313 $sql .=
", fk_address";
314 $sql .=
", fk_shipping_method";
315 $sql .=
", tracking_number";
320 $sql .=
", weight_units";
321 $sql .=
", size_units";
322 $sql .=
", note_private";
323 $sql .=
", note_public";
324 $sql .=
", model_pdf";
325 $sql .=
", fk_incoterms, location_incoterms";
326 $sql .=
") VALUES (";
328 $sql .=
", ".$conf->entity;
329 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
330 $sql .=
", ".($this->ref_int ?
"'".$this->db->escape($this->ref_int).
"'" :
"null");
331 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
332 $sql .=
", '".$this->db->idate($now).
"'";
333 $sql .=
", ".$user->id;
334 $sql .=
", ".($this->date_expedition > 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
"null");
335 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
336 $sql .=
", ".$this->socid;
337 $sql .=
", ".$this->fk_project;
338 $sql .=
", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address :
"null");
339 $sql .=
", ".($this->shipping_method_id > 0 ? $this->shipping_method_id :
"null");
340 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
341 $sql .=
", ".(is_numeric($this->weight) ? $this->weight :
'NULL');
342 $sql .=
", ".(is_numeric($this->sizeS) ? $this->sizeS :
'NULL');
343 $sql .=
", ".(is_numeric($this->sizeW) ? $this->sizeW :
'NULL');
344 $sql .=
", ".(is_numeric($this->sizeH) ? $this->sizeH :
'NULL');
345 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
346 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
347 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
348 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
349 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
350 $sql .=
", ".(int) $this->fk_incoterms;
351 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
354 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
358 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
360 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
361 $sql .=
" SET ref = '(PROV".$this->id.
")'";
362 $sql .=
" WHERE rowid = ".$this->id;
364 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
365 if ($this->
db->query($sql))
368 $num = count($this->lines);
369 for ($i = 0; $i < $num; $i++)
371 if (!isset($this->lines[$i]->detail_batch))
373 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)
378 if (!$this->
create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0)
385 if (!$error && $this->
id && $this->origin_id)
404 if (!$error && !$notrigger)
407 $result = $this->
call_trigger(
'SHIPPING_CREATE', $user);
408 if ($result < 0) { $error++; }
416 foreach ($this->errors as $errmsg)
418 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
419 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
421 $this->
db->rollback();
426 $this->error = $this->
db->lasterror().
" - sql=$sql";
427 $this->
db->rollback();
432 $this->error = $this->
db->lasterror().
" - sql=$sql";
433 $this->
db->rollback();
438 $this->error = $this->
db->error().
" - sql=$sql";
439 $this->
db->rollback();
455 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = 0)
461 $expeditionline->fk_expedition = $this->id;
462 $expeditionline->entrepot_id = $entrepot_id;
463 $expeditionline->fk_origin_line = $origin_line_id;
464 $expeditionline->qty = $qty;
465 $expeditionline->rang = $rang;
466 $expeditionline->array_options = $array_options;
468 if (($lineId = $expeditionline->insert($user)) < 0)
470 $this->errors[] = $expeditionline->error;
488 $stockLocationQty = array();
490 $tab = $line_ext->detail_batch;
492 foreach ($tab as $detbatch)
494 if ($detbatch->entrepot_id)
496 $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty;
500 foreach ($stockLocationQty as $stockLocation => $qty)
502 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
507 foreach ($tab as $detbatch)
509 if ($detbatch->entrepot_id == $stockLocation) {
510 if (!($detbatch->create($line_id) > 0))
519 if (!$error)
return 1;
532 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
537 if (empty($id) && empty($ref) && empty($ref_ext))
return -1;
539 $sql =
"SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut, e.fk_projet as fk_project, e.billed";
540 $sql .=
", e.date_valid";
541 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
542 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
543 $sql .=
", e.fk_shipping_method, e.tracking_number";
544 $sql .=
", e.note_private, e.note_public";
545 $sql .=
', e.fk_incoterms, e.location_incoterms';
546 $sql .=
', i.libelle as label_incoterms';
547 $sql .=
', s.libelle as shipping_method';
548 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
549 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
550 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->
db->escape($this->element).
"'";
551 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
552 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
553 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
554 if ($id) $sql .=
" AND e.rowid=".$id;
555 if ($ref) $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
556 if ($ref_ext) $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
557 if ($notused) $sql .=
" AND e.ref_int='".$this->db->escape($notused).
"'";
559 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
560 $result = $this->
db->query($sql);
563 if ($this->
db->num_rows($result))
565 $obj = $this->
db->fetch_object($result);
567 $this->
id = $obj->rowid;
568 $this->entity = $obj->entity;
569 $this->ref = $obj->ref;
570 $this->socid = $obj->socid;
571 $this->ref_customer = $obj->ref_customer;
572 $this->ref_ext = $obj->ref_ext;
573 $this->ref_int = $obj->ref_int;
574 $this->
statut = $obj->fk_statut;
575 $this->user_author_id = $obj->fk_user_author;
576 $this->date_creation = $this->
db->jdate($obj->date_creation);
577 $this->date_valid = $this->
db->jdate($obj->date_valid);
578 $this->date = $this->
db->jdate($obj->date_expedition);
579 $this->date_expedition = $this->
db->jdate($obj->date_expedition);
580 $this->date_shipping = $this->
db->jdate($obj->date_expedition);
581 $this->date_delivery = $this->
db->jdate($obj->date_delivery);
582 $this->fk_delivery_address = $obj->fk_address;
583 $this->model_pdf = $obj->model_pdf;
584 $this->modelpdf = $obj->model_pdf;
585 $this->shipping_method_id = $obj->fk_shipping_method;
586 $this->shipping_method = $obj->shipping_method;
587 $this->tracking_number = $obj->tracking_number;
588 $this->origin = ($obj->origin ? $obj->origin :
'commande');
589 $this->origin_id = $obj->origin_id;
590 $this->billed = $obj->billed;
591 $this->fk_project = $obj->fk_project;
593 $this->trueWeight = $obj->weight;
594 $this->weight_units = $obj->weight_units;
596 $this->trueWidth = $obj->width;
597 $this->width_units = $obj->size_units;
598 $this->trueHeight = $obj->height;
599 $this->height_units = $obj->size_units;
600 $this->trueDepth = $obj->size;
601 $this->depth_units = $obj->size_units;
603 $this->note_public = $obj->note_public;
604 $this->note_private = $obj->note_private;
607 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
608 $this->size_units = $obj->size_units;
611 $this->fk_incoterms = $obj->fk_incoterms;
612 $this->location_incoterms = $obj->location_incoterms;
613 $this->label_incoterms = $obj->label_incoterms;
615 $this->
db->free($result);
617 if ($this->
statut == self::STATUS_DRAFT) $this->brouillon = 1;
629 if (!empty($conf->multicurrency->enabled))
631 if (!empty($this->multicurrency_code)) $this->multicurrency_code = $this->thirdparty->multicurrency_code;
632 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($this->thirdparty->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
646 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
647 $this->error =
'Delivery with id '.$id.
' not found';
651 $this->error = $this->
db->error();
663 public function valid($user, $notrigger = 0)
665 global $conf, $langs;
667 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
674 dol_syslog(get_class($this).
"::valid no draft status", LOG_WARNING);
678 if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))
679 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))))
681 $this->error =
'Permission denied';
682 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
692 $soc->fetch($this->socid);
695 $result = $soc->set_as_client();
698 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref)))
702 $numref =
"EXP".$this->id;
709 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
710 $sql .=
" ref='".$this->db->escape($numref).
"'";
711 $sql .=
", fk_statut = 1";
712 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
713 $sql .=
", fk_user_valid = ".$user->id;
714 $sql .=
" WHERE rowid = ".$this->id;
716 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
720 $this->error = $this->
db->lasterror();
725 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
727 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
729 $langs->load(
"agenda");
732 $sql =
"SELECT cd.fk_product, cd.subprice,";
733 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
734 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
735 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
736 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
737 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
738 $sql .=
" WHERE ed.fk_expedition = ".$this->id;
739 $sql .=
" AND cd.rowid = ed.fk_origin_line";
741 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
746 for ($i = 0; $i < $cpt; $i++)
748 $obj = $this->
db->fetch_object(
$resql);
749 if (empty($obj->edbrowid))
755 if ($qty <= 0)
continue;
756 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
760 $mouvS->origin = &$this;
762 if (empty($obj->edbrowid))
767 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans(
"ShipmentValidatedInDolibarr", $numref));
770 $this->error = $mouvS->error;
771 $this->errors = array_merge($this->errors, $mouvS->errors);
779 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans(
"ShipmentValidatedInDolibarr", $numref),
'', $this->
db->jdate($obj->eatby), $this->
db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
782 $this->error = $mouvS->error;
783 $this->errors = array_merge($this->errors, $mouvS->errors);
789 $this->
db->rollback();
790 $this->error = $this->
db->error();
803 if (!$error && !$notrigger)
806 $result = $this->
call_trigger(
'SHIPPING_VALIDATE', $user);
807 if ($result < 0) { $error++; }
813 $this->oldref = $this->ref;
816 if (preg_match(
'/^[\(]?PROV/i', $this->ref))
819 $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).
"'";
820 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'expedition/sending/".$this->
db->escape($this->ref).
"' and entity = ".$conf->entity;
822 if (!
$resql) { $error++; $this->error = $this->
db->lasterror(); }
827 $dirsource = $conf->expedition->dir_output.
'/sending/'.$oldref;
828 $dirdest = $conf->expedition->dir_output.
'/sending/'.$newref;
829 if (!$error && file_exists($dirsource))
831 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
833 if (@rename($dirsource, $dirdest))
837 $listoffiles =
dol_dir_list($conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
838 foreach ($listoffiles as $fileentry)
840 $dirsource = $fileentry[
'name'];
841 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
842 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
843 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
844 @rename($dirsource, $dirdest);
854 $this->ref = $numref;
855 $this->
statut = self::STATUS_VALIDATED;
863 $this->
db->rollback();
881 if ($conf->delivery_note->enabled)
883 if ($this->
statut == self::STATUS_VALIDATED || $this->
statut == self::STATUS_CLOSED)
886 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
888 $result = $delivery->create_from_sending($user, $this->
id);
893 $this->error = $delivery->error;
911 public function addline($entrepot_id, $id, $qty, $array_options = 0)
913 global $conf, $langs;
915 $num = count($this->lines);
918 $line->entrepot_id = $entrepot_id;
919 $line->origin_line_id = $id;
920 $line->fk_origin_line = $id;
924 $orderline->fetch($id);
927 $line->rang = $orderline->rang;
929 if (!empty($conf->stock->enabled) && !empty($orderline->fk_product))
931 $fk_product = $orderline->fk_product;
933 if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) {
934 $langs->load(
"errors");
935 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
939 if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
941 $product->fetch($fk_product);
944 if ($entrepot_id > 0) {
945 $product->load_stock(
'warehouseopen');
946 $product_stock = $product->stock_warehouse[$entrepot_id]->real;
948 $product_stock = $product->stock_reel;
951 $product_type = $product->type;
952 if ($product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
953 $isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
955 if (!$isavirtualproduct || empty($conf->global->PRODUIT_SOUSPRODUITS) || ($isavirtualproduct && empty($conf->global->STOCK_EXCLUDE_VIRTUAL_PRODUCTS))) {
956 if ($product_stock < $qty) {
957 $langs->load(
"errors");
958 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
959 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
961 $this->
db->rollback();
970 if (!empty($conf->productbatch->enabled) && !empty($orderline->fk_product) && !empty($orderline->product_tobatch))
972 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
977 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0)
978 $line->array_options = $array_options;
980 $this->lines[$num] = $line;
994 global $conf, $langs;
996 $num = count($this->lines);
997 if ($dbatch[
'qty'] > 0)
1001 foreach ($dbatch[
'detail'] as $key=>$value)
1003 if ($value[
'q'] > 0)
1010 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1013 $this->error = $linebatch->error;
1016 $linebatch->qty = $value[
'q'];
1017 $tab[] = $linebatch;
1019 if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
1021 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1023 $prod_batch->fetch($value[
'id_batch']);
1025 if ($prod_batch->qty < $linebatch->qty)
1027 $langs->load(
"errors");
1028 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1029 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1030 $this->
db->rollback();
1038 $line->entrepot_id = $linebatch->entrepot_id;
1039 $line->origin_line_id = $dbatch[
'ix_l'];
1040 $line->fk_origin_line = $dbatch[
'ix_l'];
1041 $line->qty = $dbatch[
'qty'];
1042 $line->detail_batch = $tab;
1045 if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0)
1046 $line->array_options = $array_options;
1049 $this->lines[$num] = $line;
1061 public function update($user = null, $notrigger = 0)
1068 if (isset($this->ref)) $this->ref = trim($this->ref);
1069 if (isset($this->entity)) $this->entity = (int) $this->entity;
1070 if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer);
1071 if (isset($this->socid)) $this->socid = (
int) $this->socid;
1072 if (isset($this->fk_user_author)) $this->fk_user_author = (
int) $this->fk_user_author;
1073 if (isset($this->fk_user_valid)) $this->fk_user_valid = (
int) $this->fk_user_valid;
1074 if (isset($this->fk_delivery_address)) $this->fk_delivery_address = (
int) $this->fk_delivery_address;
1075 if (isset($this->shipping_method_id)) $this->shipping_method_id = (
int) $this->shipping_method_id;
1076 if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number);
1077 if (isset($this->
statut)) $this->
statut = (
int) $this->statut;
1078 if (isset($this->trueDepth)) $this->trueDepth = trim($this->trueDepth);
1079 if (isset($this->trueWidth)) $this->trueWidth = trim($this->trueWidth);
1080 if (isset($this->trueHeight)) $this->trueHeight = trim($this->trueHeight);
1081 if (isset($this->size_units)) $this->size_units = trim($this->size_units);
1082 if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units);
1083 if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight);
1084 if (isset($this->note_private)) $this->note_private = trim($this->note_private);
1085 if (isset($this->note_public)) $this->note_public = trim($this->note_public);
1086 if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf);
1094 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1096 $sql .=
" ref=".(isset($this->ref) ?
"'".$this->db->escape($this->ref).
"'" :
"null").
",";
1097 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1098 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1099 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1100 $sql .=
" date_creation=".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1101 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
",";
1102 $sql .=
" date_valid=".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1103 $sql .=
" fk_user_valid=".(isset($this->fk_user_valid) ? $this->fk_user_valid :
"null").
",";
1104 $sql .=
" date_expedition=".(dol_strlen($this->date_expedition) != 0 ?
"'".$this->db->idate($this->date_expedition).
"'" :
'null').
",";
1105 $sql .=
" date_delivery=".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1106 $sql .=
" fk_address=".(isset($this->fk_delivery_address) ? $this->fk_delivery_address :
"null").
",";
1107 $sql .=
" fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id :
"null").
",";
1108 $sql .=
" tracking_number=".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1109 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1110 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1111 $sql .=
" height=".(($this->trueHeight !=
'') ? $this->trueHeight :
"null").
",";
1112 $sql .=
" width=".(($this->trueWidth !=
'') ? $this->trueWidth :
"null").
",";
1113 $sql .=
" size_units=".(isset($this->size_units) ? $this->size_units :
"null").
",";
1114 $sql .=
" size=".(($this->trueDepth !=
'') ? $this->trueDepth :
"null").
",";
1115 $sql .=
" weight_units=".(isset($this->weight_units) ? $this->weight_units :
"null").
",";
1116 $sql .=
" weight=".(($this->trueWeight !=
'') ? $this->trueWeight :
"null").
",";
1117 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1118 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1119 $sql .=
" model_pdf=".(isset($this->modelpdf) ?
"'".$this->db->escape($this->modelpdf).
"'" :
"null").
",";
1120 $sql .=
" entity=".$conf->entity;
1122 $sql .=
" WHERE rowid=".$this->id;
1126 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1128 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
1130 if (!$error && !$notrigger) {
1132 $result = $this->
call_trigger(
'SHIPPING_MODIFY', $user);
1133 if ($result < 0) { $error++; }
1140 foreach ($this->errors as $errmsg)
1142 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1143 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1145 $this->
db->rollback();
1148 $this->
db->commit();
1161 public function cancel($notrigger = 0, $also_update_stock =
false)
1163 global $conf, $langs, $user;
1165 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1166 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionbatch.class.php';
1175 if (count($this->linkedObjectsIds) > 0) {
1176 $this->error =
'ErrorThereIsSomeDeliveries';
1180 if (!$error && !$notrigger) {
1182 $result = $this->
call_trigger(
'SHIPPING_CANCEL', $user);
1183 if ($result < 0) { $error++; }
1188 if (!$error && $conf->stock->enabled &&
1189 (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) ||
1190 ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock)))
1192 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1194 $langs->load(
"agenda");
1197 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1198 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1199 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1200 $sql .=
" WHERE ed.fk_expedition = ".$this->id;
1201 $sql .=
" AND cd.rowid = ed.fk_origin_line";
1203 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1207 $cpt = $this->
db->num_rows(
$resql);
1208 for ($i = 0; $i < $cpt; $i++)
1210 dol_syslog(get_class($this).
"::delete movement index ".$i);
1211 $obj = $this->
db->fetch_object(
$resql);
1215 $mouvS->origin = null;
1218 if ($conf->productbatch->enabled)
1221 if (!is_array($lotArray))
1223 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1226 if (empty($lotArray)) {
1230 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref));
1233 $error++; $this->errors = $this->errors + $mouvS->errors;
1239 foreach ($lotArray as $lot)
1241 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1244 $error++; $this->errors = $this->errors + $mouvS->errors;
1252 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1257 if (!$error && $conf->productbatch->enabled)
1261 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1268 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1269 $sql .=
" WHERE fk_expedition = ".$this->id;
1271 if ($this->
db->query($sql))
1275 if ($res < 0) $error++;
1280 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"expedition";
1281 $sql .=
" WHERE rowid = ".$this->id;
1283 if ($this->
db->query($sql))
1285 if (!empty($this->origin) && $this->origin_id > 0)
1288 $origin = $this->origin;
1292 $this->$origin->loadExpeditions();
1294 if (count($this->$origin->expeditions) <= 0)
1303 $this->
db->commit();
1307 if (!empty($conf->expedition->dir_output))
1309 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1310 $file = $dir.
'/'.$ref.
'.pdf';
1311 if (file_exists($file))
1318 if (file_exists($dir))
1322 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1330 $this->
db->rollback();
1334 $this->error = $this->
db->lasterror().
" - sql=$sql";
1335 $this->
db->rollback();
1339 $this->error = $this->
db->lasterror().
" - sql=$sql";
1340 $this->
db->rollback();
1344 $this->error = $this->
db->lasterror().
" - sql=$sql";
1345 $this->
db->rollback();
1349 $this->
db->rollback();
1362 public function delete($notrigger = 0, $also_update_stock =
false)
1364 global $conf, $langs, $user;
1366 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1367 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionbatch.class.php';
1376 if (count($this->linkedObjectsIds) > 0)
1378 $this->error =
'ErrorThereIsSomeDeliveries';
1382 if (!$error && !$notrigger) {
1384 $result = $this->
call_trigger(
'SHIPPING_DELETE', $user);
1385 if ($result < 0) { $error++; }
1390 if (!$error && $conf->stock->enabled &&
1391 (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) ||
1392 ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock)))
1394 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1396 $langs->load(
"agenda");
1399 $sql =
"SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1400 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
1401 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
1402 $sql .=
" WHERE ed.fk_expedition = ".$this->id;
1403 $sql .=
" AND cd.rowid = ed.fk_origin_line";
1405 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1409 $cpt = $this->
db->num_rows(
$resql);
1410 for ($i = 0; $i < $cpt; $i++)
1412 dol_syslog(get_class($this).
"::delete movement index ".$i);
1413 $obj = $this->
db->fetch_object(
$resql);
1417 $mouvS->origin = null;
1420 if ($conf->productbatch->enabled)
1423 if (!is_array($lotArray))
1425 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1428 if (empty($lotArray)) {
1432 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref));
1435 $error++; $this->errors = $this->errors + $mouvS->errors;
1441 foreach ($lotArray as $lot)
1443 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans(
"ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
1446 $error++; $this->errors = $this->errors + $mouvS->errors;
1454 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1459 if (!$error && $conf->productbatch->enabled)
1463 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1469 $main = MAIN_DB_PREFIX.
'expeditiondet';
1470 $ef = $main.
"_extrafields";
1471 $sqlef =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".$this->id.
")";
1473 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
1474 $sql .=
" WHERE fk_expedition = ".$this->id;
1476 if ($this->
db->query($sqlef) && $this->
db->query($sql))
1480 if ($res < 0) $error++;
1484 if ($res < 0) $error++;
1488 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expedition";
1489 $sql .=
" WHERE rowid = ".$this->id;
1491 if ($this->
db->query($sql))
1493 if (!empty($this->origin) && $this->origin_id > 0)
1496 $origin = $this->origin;
1500 $this->$origin->loadExpeditions();
1502 if (count($this->$origin->expeditions) <= 0)
1511 $this->
db->commit();
1518 if (!empty($conf->expedition->dir_output))
1520 $dir = $conf->expedition->dir_output.
'/sending/'.$ref;
1521 $file = $dir.
'/'.$ref.
'.pdf';
1522 if (file_exists($file))
1529 if (file_exists($dir))
1533 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
1541 $this->
db->rollback();
1545 $this->error = $this->
db->lasterror().
" - sql=$sql";
1546 $this->
db->rollback();
1550 $this->error = $this->
db->lasterror().
" - sql=$sql";
1551 $this->
db->rollback();
1555 $this->error = $this->
db->lasterror().
" - sql=$sql";
1556 $this->
db->rollback();
1560 $this->
db->rollback();
1574 global $conf, $mysoc;
1576 $this->lines = array();
1578 $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";
1579 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
1580 $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";
1581 $sql .=
", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang";
1582 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
1583 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type";
1584 $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";
1585 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
1586 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
1587 $sql .=
" WHERE ed.fk_expedition = ".$this->id;
1588 $sql .=
" AND ed.fk_origin_line = cd.rowid";
1589 $sql .=
" ORDER BY cd.rang, ed.fk_origin_line";
1591 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1595 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1597 $num = $this->
db->num_rows(
$resql);
1602 $this->total_ht = 0;
1603 $this->total_tva = 0;
1604 $this->total_ttc = 0;
1605 $this->total_localtax1 = 0;
1606 $this->total_localtax2 = 0;
1612 $obj = $this->
db->fetch_object(
$resql);
1614 if ($originline == $obj->fk_origin_line) {
1615 $line->entrepot_id = 0;
1616 $line->qty_shipped += $obj->qty_shipped;
1619 $line->entrepot_id = $obj->fk_entrepot;
1620 $line->qty_shipped = $obj->qty_shipped;
1623 $detail_entrepot =
new stdClass;
1624 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
1625 $detail_entrepot->qty_shipped = $obj->qty_shipped;
1626 $detail_entrepot->line_id = $obj->line_id;
1627 $line->details_entrepot[] = $detail_entrepot;
1629 $line->line_id = $obj->line_id;
1630 $line->rowid = $obj->line_id;
1631 $line->id = $obj->line_id;
1633 $line->fk_origin =
'orderline';
1634 $line->fk_origin_line = $obj->fk_origin_line;
1635 $line->origin_line_id = $obj->fk_origin_line;
1637 $line->fk_expedition = $this->id;
1639 $line->product_type = $obj->product_type;
1640 $line->fk_product = $obj->fk_product;
1641 $line->fk_product_type = $obj->fk_product_type;
1642 $line->ref = $obj->product_ref;
1643 $line->product_ref = $obj->product_ref;
1644 $line->product_label = $obj->product_label;
1645 $line->libelle = $obj->product_label;
1646 $line->product_tosell = $obj->product_tosell;
1647 $line->product_tobuy = $obj->product_tobuy;
1648 $line->product_tobatch = $obj->product_tobatch;
1649 $line->label = $obj->custom_label;
1650 $line->description = $obj->description;
1651 $line->qty_asked = $obj->qty_asked;
1652 $line->rang = $obj->rang;
1653 $line->weight = $obj->weight;
1654 $line->weight_units = $obj->weight_units;
1655 $line->length = $obj->length;
1656 $line->length_units = $obj->length_units;
1657 $line->surface = $obj->surface;
1658 $line->surface_units = $obj->surface_units;
1659 $line->volume = $obj->volume;
1660 $line->volume_units = $obj->volume_units;
1661 $line->fk_unit = $obj->fk_unit;
1663 $line->pa_ht = $obj->pa_ht;
1666 $localtax_array = array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
1667 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
1668 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
1671 $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);
1672 $line->desc = $obj->description;
1673 $line->qty = $line->qty_shipped;
1674 $line->total_ht = $tabprice[0];
1675 $line->total_localtax1 = $tabprice[9];
1676 $line->total_localtax2 = $tabprice[10];
1677 $line->total_ttc = $tabprice[2];
1678 $line->total_tva = $tabprice[1];
1679 $line->vat_src_code = $obj->vat_src_code;
1680 $line->tva_tx = $obj->tva_tx;
1681 $line->localtax1_tx = $obj->localtax1_tx;
1682 $line->localtax2_tx = $obj->localtax2_tx;
1683 $line->info_bits = $obj->info_bits;
1684 $line->price = $obj->price;
1685 $line->subprice = $obj->subprice;
1686 $line->remise_percent = $obj->remise_percent;
1688 $this->total_ht += $tabprice[0];
1689 $this->total_tva += $tabprice[1];
1690 $this->total_ttc += $tabprice[2];
1691 $this->total_localtax1 += $tabprice[9];
1692 $this->total_localtax2 += $tabprice[10];
1695 $this->fk_multicurrency = $obj->fk_multicurrency;
1696 $this->multicurrency_code = $obj->multicurrency_code;
1697 $this->multicurrency_subprice = $obj->multicurrency_subprice;
1698 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1699 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1700 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1702 if ($originline != $obj->fk_origin_line)
1704 $line->detail_batch = array();
1708 if (!empty($conf->productbatch->enabled) && $obj->line_id > 0 && $obj->product_tobatch > 0)
1710 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionbatch.class.php';
1713 if (is_array($newdetailbatch))
1715 if ($originline != $obj->fk_origin_line)
1717 $line->detail_batch = $newdetailbatch;
1719 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
1724 if ($originline != $obj->fk_origin_line)
1726 $this->lines[$lineindex] = $line;
1729 $line->total_ht += $tabprice[0];
1730 $line->total_localtax1 += $tabprice[9];
1731 $line->total_localtax2 += $tabprice[10];
1732 $line->total_ttc += $tabprice[2];
1733 $line->total_tva += $tabprice[1];
1735 $line->fetch_optionals();
1737 $originline = $obj->fk_origin_line;
1742 $this->error = $this->
db->error();
1758 if ($this->
statut == self::STATUS_DRAFT)
1765 $line->fetch($lineid);
1767 if ($line->delete($user) > 0)
1771 $this->
db->commit();
1774 $this->
db->rollback();
1778 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1795 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1)
1797 global $langs, $conf;
1800 $label =
'<u>'.$langs->trans(
"Shipment").
'</u>';
1801 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1802 $label .=
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
1804 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
1806 if ($short)
return $url;
1808 if ($option !==
'nolink')
1811 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1812 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1813 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1817 if (empty($notooltip))
1819 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1821 $label = $langs->trans(
"Shipment");
1822 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1824 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1825 $linkclose .=
' class="classfortooltip"';
1828 $linkstart =
'<a href="'.$url.
'"';
1829 $linkstart .= $linkclose.
'>';
1832 $result .= $linkstart;
1833 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1834 if ($withpicto != 2) $result .= $this->ref;
1835 $result .= $linkend;
1864 $labelStatus = $langs->trans($this->statuts[$status]);
1865 $labelStatusShort = $langs->trans($this->statutshorts[$status]);
1867 $statusType =
'status'.$status;
1868 if ($status == self::STATUS_VALIDATED) $statusType =
'status4';
1869 if ($status == self::STATUS_CLOSED) $statusType =
'status6';
1870 if ($status == self::STATUS_CANCELED) $statusType =
'status9';
1872 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1888 dol_syslog(get_class($this).
"::initAsSpecimen");
1893 $sql =
"SELECT rowid";
1894 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1895 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1899 $num_prods = $this->
db->num_rows(
$resql);
1901 while ($i < $num_prods)
1904 $row = $this->
db->fetch_row(
$resql);
1905 $prodids[$i] = $row[0];
1910 $order->initAsSpecimen();
1914 $this->ref =
'SPECIMEN';
1915 $this->specimen = 1;
1916 $this->
statut = self::STATUS_VALIDATED;
1917 $this->livraison_id = 0;
1919 $this->date_creation = $now;
1920 $this->date_valid = $now;
1921 $this->date_delivery = $now;
1922 $this->date_expedition = $now + 24 * 3600;
1924 $this->entrepot_id = 0;
1925 $this->fk_delivery_address = 0;
1928 $this->commande_id = 0;
1929 $this->commande = $order;
1931 $this->origin_id = 1;
1932 $this->origin =
'commande';
1934 $this->note_private =
'Private note';
1935 $this->note_public =
'Public note';
1939 while ($xnbp < $nbp)
1942 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1943 $line->libelle = $langs->trans(
"Description").
" ".$xnbp;
1944 $line->label = $langs->trans(
"Description").
" ".$xnbp;
1946 $line->qty_asked = 5;
1947 $line->qty_shipped = 4;
1948 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
1950 $this->lines[] = $line;
1979 if ($user->rights->expedition->creer)
1981 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
1982 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1983 $sql .=
" WHERE rowid = ".$this->id;
1985 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1989 $this->date_delivery = $delivery_date;
1992 $this->error = $this->
db->error();
2010 $this->meths = array();
2012 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
2013 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2014 $sql .=
" WHERE em.active = 1";
2015 $sql .=
" ORDER BY em.libelle ASC";
2020 while ($obj = $this->
db->fetch_object(
$resql))
2022 $label = $langs->trans(
'SendingMethod'.$obj->code);
2023 $this->meths[$obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2040 $this->listmeths = array();
2043 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
2044 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2045 if ($id !=
'') $sql .=
" WHERE em.rowid=".$id;
2050 while ($obj = $this->
db->fetch_object(
$resql))
2052 $this->listmeths[$i][
'rowid'] = $obj->rowid;
2053 $this->listmeths[$i][
'code'] = $obj->code;
2054 $label = $langs->trans(
'SendingMethod'.$obj->code);
2055 $this->listmeths[$i][
'libelle'] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
2056 $this->listmeths[$i][
'description'] = $obj->description;
2057 $this->listmeths[$i][
'tracking'] = $obj->tracking;
2058 $this->listmeths[$i][
'active'] = $obj->active;
2077 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"c_shipment_mode (code, libelle, description, tracking)";
2078 $sql .=
" VALUES ('".$this->db->escape($this->
update[
'code']).
"','".$this->
db->escape($this->
update[
'libelle']).
"','".$this->
db->escape($this->
update[
'description']).
"','".$this->
db->escape($this->
update[
'tracking']).
"')";
2081 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_shipment_mode SET";
2082 $sql .=
" code='".$this->db->escape($this->
update[
'code']).
"'";
2083 $sql .=
",libelle='".$this->db->escape($this->
update[
'libelle']).
"'";
2084 $sql .=
",description='".$this->db->escape($this->
update[
'description']).
"'";
2085 $sql .=
",tracking='".$this->db->escape($this->
update[
'tracking']).
"'";
2086 $sql .=
" WHERE rowid=".$id;
2102 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'c_shipment_mode SET active=1';
2103 $sql .=
' WHERE rowid='.$id;
2119 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'c_shipment_mode SET active=0';
2120 $sql .=
' WHERE rowid='.$id;
2134 if (!empty($this->shipping_method_id))
2136 $sql =
"SELECT em.code, em.tracking";
2137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
2138 $sql .=
" WHERE em.rowid = ".$this->shipping_method_id;
2143 if ($obj = $this->
db->fetch_object(
$resql))
2145 $tracking = $obj->tracking;
2150 if (!empty($tracking) && !empty($value))
2152 $url = str_replace(
'{TRACKID}', $value, $tracking);
2153 $this->tracking_url = sprintf(
'<a target="_blank" href="%s">'.($value ? $value :
'url').
'</a>', $url, $url);
2155 $this->tracking_url = $value;
2166 global $conf, $langs, $user;
2171 if ($this->
statut == self::STATUS_CLOSED)
2178 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut='.self::STATUS_CLOSED;
2179 $sql .=
' WHERE rowid = '.$this->id.
' AND fk_statut > 0';
2185 if ($this->origin ==
'commande' && $this->origin_id > 0)
2188 $order->fetch($this->origin_id);
2190 $order->loadExpeditions(self::STATUS_CLOSED);
2192 $shipments_match_order = 1;
2193 foreach ($order->lines as $line)
2195 $lineid = $line->id;
2197 if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty)
2199 $shipments_match_order = 0;
2200 $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';
2205 if ($shipments_match_order)
2207 dol_syslog(
"Qty for the ".count($order->lines).
" lines of order have same value for shipments with status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.
', so we close order');
2208 $order->cloture($user);
2212 $this->
statut = self::STATUS_CLOSED;
2216 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2218 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2220 $langs->load(
"agenda");
2224 $sql =
"SELECT cd.fk_product, cd.subprice,";
2225 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2226 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2228 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2229 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2230 $sql .=
" WHERE ed.fk_expedition = ".$this->id;
2231 $sql .=
" AND cd.rowid = ed.fk_origin_line";
2233 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2237 $cpt = $this->
db->num_rows(
$resql);
2238 for ($i = 0; $i < $cpt; $i++)
2240 $obj = $this->
db->fetch_object(
$resql);
2241 if (empty($obj->edbrowid))
2245 $qty = $obj->edbqty;
2247 if ($qty <= 0)
continue;
2248 dol_syslog(get_class($this).
"::valid movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2251 $mouvS->origin = &$this;
2253 if (empty($obj->edbrowid))
2258 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans(
"ShipmentClassifyClosedInDolibarr", $numref));
2260 $this->error = $mouvS->error;
2261 $this->errors = $mouvS->errors;
2268 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans(
"ShipmentClassifyClosedInDolibarr", $numref),
'', $this->
db->jdate($obj->eatby), $this->
db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2270 $this->error = $mouvS->error;
2271 $this->errors = $mouvS->errors;
2277 $this->error = $this->
db->lasterror();
2285 $result = $this->
call_trigger(
'SHIPPING_CLOSED', $user);
2297 $this->
db->commit();
2300 $this->
statut = self::STATUS_VALIDATED;
2301 $this->
db->rollback();
2320 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut=2, billed=1';
2321 $sql .=
' WHERE rowid = '.$this->id.
' AND fk_statut > 0';
2326 $this->
statut = self::STATUS_CLOSED;
2330 $result = $this->
call_trigger(
'SHIPPING_BILLED', $user);
2336 $this->errors[] = $this->
db->lasterror;
2339 if (empty($error)) {
2340 $this->
db->commit();
2343 $this->
statut = self::STATUS_VALIDATED;
2345 $this->
db->rollback();
2357 global $conf, $langs, $user;
2362 if ($this->
statut == self::STATUS_VALIDATED)
2369 $oldbilled = $this->billed;
2371 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut=1';
2372 $sql .=
' WHERE rowid = '.$this->id.
' AND fk_statut > 0';
2377 $this->
statut = self::STATUS_VALIDATED;
2381 if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE))
2383 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2385 $langs->load(
"agenda");
2389 $sql =
"SELECT cd.fk_product, cd.subprice,";
2390 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
2391 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
2392 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd,";
2393 $sql .=
" ".MAIN_DB_PREFIX.
"expeditiondet as ed";
2394 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
2395 $sql .=
" WHERE ed.fk_expedition = ".$this->id;
2396 $sql .=
" AND cd.rowid = ed.fk_origin_line";
2398 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
2402 $cpt = $this->
db->num_rows(
$resql);
2403 for ($i = 0; $i < $cpt; $i++)
2405 $obj = $this->
db->fetch_object(
$resql);
2406 if (empty($obj->edbrowid))
2410 $qty = $obj->edbqty;
2412 if ($qty <= 0)
continue;
2413 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
2417 $mouvS->origin = &$this;
2419 if (empty($obj->edbrowid))
2424 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $numref));
2426 $this->error = $mouvS->error;
2427 $this->errors = $mouvS->errors;
2434 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans(
"ShipmentUnClassifyCloseddInDolibarr", $numref),
'', $this->
db->jdate($obj->eatby), $this->
db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
2436 $this->error = $mouvS->error;
2437 $this->errors = $mouvS->errors;
2443 $this->error = $this->
db->lasterror();
2450 $result = $this->
call_trigger(
'SHIPPING_REOPEN', $user);
2457 $this->errors[] = $this->
db->lasterror();
2462 $this->
db->commit();
2465 $this->
statut = self::STATUS_CLOSED;
2466 $this->billed = $oldbilled;
2467 $this->
db->rollback();
2483 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2487 $outputlangs->load(
"products");
2492 if (!empty($this->model_pdf)) {
2493 $modele = $this->model_pdf;
2494 } elseif (!empty($this->modelpdf)) {
2495 $modele = $this->modelpdf;
2496 } elseif (!empty($conf->global->EXPEDITION_ADDON_PDF)) {
2497 $modele = $conf->global->EXPEDITION_ADDON_PDF;
2501 $modelpath =
"core/modules/expedition/doc/";
2505 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2535 public $element =
'expeditiondet';
2540 public $table_element =
'expeditiondet';
2551 public $fk_origin_line;
2556 public $fk_expedition;
2571 public $qty_shipped;
2577 public $detail_batch;
2582 public $entrepot_id;
2599 public $product_ref;
2610 public $product_label;
2622 public $product_desc;
2633 public $weight_units;
2639 public $length_units;
2645 public $surface_units;
2651 public $volume_units;
2654 public $remise_percent;
2675 public $total_localtax1;
2680 public $total_localtax2;
2701 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang';
2702 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as ed';
2703 $sql .=
' WHERE ed.rowid = '.$rowid;
2704 $result = $this->
db->query($sql);
2707 $objp = $this->
db->fetch_object($result);
2708 $this->
id = $objp->rowid;
2709 $this->fk_expedition = $objp->fk_expedition;
2710 $this->entrepot_id = $objp->fk_entrepot;
2711 $this->fk_origin_line = $objp->fk_origin_line;
2712 $this->qty = $objp->qty;
2713 $this->rang = $objp->rang;
2715 $this->
db->free($result);
2719 $this->errors[] = $this->
db->lasterror();
2720 $this->error = $this->
db->lasterror();
2732 public function insert($user, $notrigger = 0)
2734 global $langs, $conf;
2739 if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty))
2741 $this->error =
'ErrorMandatoryParametersNotProvided';
2747 if (empty($this->rang)) $this->rang = 0;
2750 $ranktouse = $this->rang;
2751 if ($ranktouse == -1)
2753 $rangmax = $this->
line_max($this->fk_expedition);
2754 $ranktouse = $rangmax + 1;
2757 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expeditiondet (";
2758 $sql .=
"fk_expedition";
2759 $sql .=
", fk_entrepot";
2760 $sql .=
", fk_origin_line";
2763 $sql .=
") VALUES (";
2764 $sql .= $this->fk_expedition;
2765 $sql .=
", ".(empty($this->entrepot_id) ?
'NULL' : $this->entrepot_id);
2766 $sql .=
", ".$this->fk_origin_line;
2767 $sql .=
", ".$this->qty;
2768 $sql .=
", ".$ranktouse;
2771 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2775 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"expeditiondet");
2786 if (!$error && !$notrigger)
2789 $result = $this->
call_trigger(
'LINESHIPPING_INSERT', $user);
2798 $this->
db->commit();
2802 foreach ($this->errors as $errmsg)
2804 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2805 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2808 $this->
db->rollback();
2822 public function delete($user = null, $notrigger = 0)
2831 if ($conf->productbatch->enabled)
2833 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
2834 $sql .=
" WHERE fk_expeditiondet = ".$this->id;
2836 if (!$this->
db->query($sql))
2838 $this->errors[] = $this->
db->lasterror().
" - sql=$sql";
2843 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet";
2844 $sql .=
" WHERE rowid = ".$this->id;
2846 if (!$error && $this->
db->query($sql))
2854 $this->errors[] = $this->error;
2858 if (!$error && !$notrigger)
2861 $result = $this->
call_trigger(
'LINESHIPPING_DELETE', $user);
2864 $this->errors[] = $this->error;
2870 $this->errors[] = $this->
db->lasterror().
" - sql=$sql";
2875 $this->
db->commit();
2878 foreach ($this->errors as $errmsg)
2880 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2881 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2883 $this->
db->rollback();
2895 public function update($user = null, $notrigger = 0)
2901 dol_syslog(get_class($this).
"::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
2906 if (empty($this->qty)) $this->qty = 0;
2911 $expedition_batch_id = null;
2912 if (is_array($this->detail_batch))
2914 if (count($this->detail_batch) > 1)
2916 dol_syslog(get_class($this).
'::update only possible for one batch', LOG_ERR);
2917 $this->errors[] =
'ErrorBadParameters';
2920 $batch = $this->detail_batch[0]->batch;
2921 $batch_id = $this->detail_batch[0]->fk_origin_stock;
2922 $expedition_batch_id = $this->detail_batch[0]->id;
2923 if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id)
2925 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
2926 $this->errors[] =
'ErrorBadParameters';
2929 $qty =
price2num($this->detail_batch[0]->qty);
2931 } elseif (!empty($this->detail_batch))
2933 $batch = $this->detail_batch->batch;
2934 $batch_id = $this->detail_batch->fk_origin_stock;
2935 $expedition_batch_id = $this->detail_batch->id;
2936 if ($this->entrepot_id != $this->detail_batch->entrepot_id)
2938 dol_syslog(get_class($this).
'::update only possible for batch of same warehouse', LOG_ERR);
2939 $this->errors[] =
'ErrorBadParameters';
2942 $qty =
price2num($this->detail_batch->qty);
2946 if (!isset($this->
id) || !isset($this->entrepot_id))
2948 dol_syslog(get_class($this).
'::update missing line id and/or warehouse id', LOG_ERR);
2949 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
2956 if (!empty($batch) && $conf->productbatch->enabled)
2958 dol_syslog(get_class($this).
"::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch");
2960 if (empty($batch_id) || empty($this->fk_product)) {
2961 dol_syslog(get_class($this).
'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
2962 $this->errors[] =
'ErrorMandatoryParametersNotProvided';
2967 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionbatch.class.php';
2970 $this->errors[] = $this->
db->lasterror().
" - ExpeditionLineBatch::fetchAll";
2974 foreach ($lotArray as $lot)
2976 if ($expedition_batch_id != $lot->id)
2978 $remainingQty += $lot->qty;
2981 $qty += $remainingQty;
2986 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
2988 if ($lot->fetch(0, $this->fk_product, $batch) < 0)
2990 $this->errors[] = $lot->errors;
2993 if (!$error && !empty($expedition_batch_id))
2996 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"expeditiondet_batch";
2997 $sql .=
" WHERE fk_expeditiondet = ".$this->id;
2998 $sql .=
" AND rowid = ".$expedition_batch_id;
3000 if (!$this->
db->query($sql))
3002 $this->errors[] = $this->
db->lasterror().
" - sql=$sql";
3006 if (!$error && $this->detail_batch->qty > 0)
3009 if (isset($lot->id))
3012 $shipmentLot->batch = $lot->batch;
3013 $shipmentLot->eatby = $lot->eatby;
3014 $shipmentLot->sellby = $lot->sellby;
3015 $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id;
3016 $shipmentLot->qty = $this->detail_batch->qty;
3017 $shipmentLot->fk_origin_stock = $batch_id;
3018 if ($shipmentLot->create($this->id) < 0)
3020 $this->errors[] = $shipmentLot->errors;
3030 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3031 $sql .=
" fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id :
'null');
3032 $sql .=
" , qty = ".$qty;
3033 $sql .=
" WHERE rowid = ".$this->id;
3035 if (!$this->
db->query($sql))
3037 $this->errors[] = $this->
db->lasterror().
" - sql=$sql";
3049 $this->errors[] = $this->error;
3055 if (!$error && !$notrigger)
3058 $result = $this->
call_trigger(
'LINESHIPPING_UPDATE', $user);
3061 $this->errors[] = $this->error;
3067 $this->
db->commit();
3070 foreach ($this->errors as $errmsg)
3072 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3073 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3075 $this->
db->rollback();
update($user=null, $notrigger=0)
Update database.
Class to manage receptions.
list_delivery_methods($id= '')
Fetch all deliveries method and return an array.
Class to manage stock movements.
addline_batch($dbatch, $array_options=0)
Add a shipment line with batch record.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
fetch_delivery_methods()
Fetch deliveries method and return an array.
__construct($db)
Constructor.
reOpen()
Classify the shipping as validated/opened.
Class with list of lots and properties.
Classe to manage lines of shipment.
disable_delivery_method($id)
DesActivate delivery method.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
CRUD class for batch number management within shipment.
const STATUS_DRAFT
Draft status.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
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.
Class to manage Dolibarr database access.
create_line_batch($line_ext, $array_options=0)
Create the detail (eat-by date) of the expedition line.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_origin()
Read linked origin object.
addline($entrepot_id, $id, $qty, $array_options=0)
Add an expedition line.
static fetchAll($db, $id_line_expdet, $fk_product=0)
Retrieve all batch number detailed information of a shipment line.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
deleteline($user, $lineid)
Delete detail line.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
set_billed()
Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
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, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
update($user=null, $notrigger=0)
Update a line in database.
const STATUS_CLOSED
Closed status.
$conf db
API class for accounts.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage order lines.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
fetch($rowid)
Load line expedition.
Class to manage third parties objects (customers, suppliers, prospects...)
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
fetch($id, $ref= '', $ref_ext= '', $notused= '')
Get object and lines from database.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
initAsSpecimen()
Initialise an instance with random values.
deleteEcmFiles($mode=0)
Delete related files of object in database.
Class to manage shipments.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Class to manage customers orders.
create($user, $notrigger=0)
Create expedition en base.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
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). ...
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
__construct($db)
Constructor.
deleteExtraFields()
Delete all extra fields values for the current object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
getUrlTrackingStatus($value= '')
Forge an set tracking url.
create_delivery($user)
Create a delivery receipt from a shipment.
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...
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '')
Delete all links between an object $this.
const STATUS_VALIDATED
Validated status.
print $_SERVER["PHP_SELF"]
Edit parameters.
LibStatut($status, $mode)
Return label of a status.
update_delivery_method($id= '')
Update/create delivery method.
const STATUS_VALIDATED
Validated status.
Manage record for batch number management.
trait CommonIncoterm
Superclass for incoterm classes.
cancel($notrigger=0, $also_update_stock=false)
Cancel shipment.
print
Draft customers invoices.
getNomUrl($withpicto=0, $option= '', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1)
Return clicable link of object (with eventually picto)
call_trigger($triggerName, $user)
Call trigger based on this instance.
set_date_livraison($user, $delivery_date)
Set delivery date.
getNextNumRef($soc)
Return next contract ref.
setStatut($status, $elementId=null, $elementType= '', $trigkey= '')
Set status of an object.
const STATUS_CANCELED
Canceled status.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getLibStatut($mode=0)
Return status label.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
static deletefromexp($db, $id_expedition)
Delete batch record attach to a shipment.
activ_delivery_method($id)
Activate delivery method.
add_object_linked($origin=null, $origin_id=null)
Add objects linked in llx_element_element.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
insert($user, $notrigger=0)
Insert line into database.
setClosed()
Classify the shipping as closed.
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=0)
Create a expedition line.