41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42require_once DOL_DOCUMENT_ROOT.
"/expedition/class/expeditionligne.class.php";
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expeditionlinebatch.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsignedobject.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
62 use CommonSignedObject;
68 public $element =
"shipping";
73 public $fk_element =
"fk_expedition";
78 public $table_element =
"expedition";
83 public $table_element_line =
"expeditiondet";
88 public $class_element_line =
'ExpeditionLigne';
93 public $picto =
'dolly';
99 public $fields = array();
105 public $user_author_id;
111 public $fk_user_author;
117 public $fk_user_valid;
134 public $ref_customer;
144 public $tracking_number;
149 public $tracking_url;
162 public $weight_units;
178 public $height_units;
195 public $livraison_id;
200 public $multicurrency_subprice;
230 public $date_delivery;
244 public $date_expedition;
250 public $date_shipping;
279 public $lines = array();
285 public $fk_multicurrency;
290 public $multicurrency_code;
294 public $multicurrency_tx;
298 public $multicurrency_total_ht;
302 public $multicurrency_total_tva;
306 public $multicurrency_total_ttc;
351 $this->ismultientitymanaged = 1;
352 $this->isextrafieldmanaged = 1;
355 $this->labelStatus = array();
356 $this->labelStatus[-1] =
'StatusSendingCanceled';
357 $this->labelStatus[0] =
'StatusSendingDraft';
358 $this->labelStatus[1] =
'StatusSendingValidated';
359 $this->labelStatus[2] =
'StatusSendingProcessed';
362 $this->labelStatusShort = array();
363 $this->labelStatusShort[-1] =
'StatusSendingCanceledShort';
364 $this->labelStatusShort[0] =
'StatusSendingDraftShort';
365 $this->labelStatusShort[1] =
'StatusSendingValidatedShort';
366 $this->labelStatusShort[2] =
'StatusSendingProcessedShort';
375 public function getNextNumRef($soc)
377 global $langs,
$conf;
378 $langs->load(
"sendings");
387 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
389 foreach ($dirmodels as $reldir) {
393 $mybool = ((bool) @include_once $dir.$file) || $mybool;
397 dol_print_error(
null,
"Failed to include file ".$file);
401 $obj =
new $classname();
402 '@phan-var-force ModelNumRefExpedition $obj';
404 $numref = $obj->getNextValue($soc, $this);
409 dol_print_error($this->db, get_class($this).
"::getNextNumRef ".$obj->error);
413 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_EXPEDITION_ADDON_NUMBER_NotDefined");
425 public function create($user, $notrigger = 0)
429 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
434 $this->tracking_number = preg_replace(
'/\s+/',
'', $this->tracking_number);
436 if (empty($this->fk_project)) {
437 $this->fk_project = 0;
439 if (empty($this->date_creation)) {
440 $this->date_creation = $now;
442 if (empty($this->date_shipping) && !empty($this->date_expedition)) {
443 $this->date_shipping = $this->date_expedition;
451 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"expedition (";
454 $sql .=
", ref_customer";
456 $sql .=
", date_creation";
457 $sql .=
", fk_user_author";
458 $sql .=
", date_expedition";
459 $sql .=
", date_delivery";
461 $sql .=
", fk_projet";
462 $sql .=
", fk_address";
463 $sql .=
", fk_shipping_method";
464 $sql .=
", tracking_number";
469 $sql .=
", weight_units";
470 $sql .=
", size_units";
471 $sql .=
", note_private";
472 $sql .=
", note_public";
473 $sql .=
", model_pdf";
474 $sql .=
", fk_incoterms, location_incoterms";
475 $sql .=
", signed_status";
477 $sql .=
") VALUES (";
479 $sql .=
", ".((int) $this->entity);
480 $sql .=
", ".($this->ref_customer ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null");
481 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
482 $sql .=
", '".$this->db->idate($this->date_creation).
"'";
483 $sql .=
", ".((int) $user->id);
484 $sql .=
", ".($this->date_shipping > 0 ?
"'".$this->db->idate($this->date_shipping).
"'" :
"null");
485 $sql .=
", ".($this->date_delivery > 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
486 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
"null");
487 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
488 $sql .=
", ".($this->fk_delivery_address > 0 ? ((int) $this->fk_delivery_address) :
"null");
489 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
"null");
490 $sql .=
", '".$this->db->escape($this->tracking_number).
"'";
491 $sql .=
", ".(is_numeric($this->weight) ? (float) $this->weight :
'NULL');
492 $sql .=
", ".(is_numeric($this->sizeS) ? (float) $this->sizeS :
'NULL');
493 $sql .=
", ".(is_numeric($this->sizeW) ? (float) $this->sizeW :
'NULL');
494 $sql .=
", ".(is_numeric($this->sizeH) ? (float) $this->sizeH :
'NULL');
495 $sql .=
", ".($this->weight_units !=
'' ? (int) $this->weight_units :
'NULL');
496 $sql .=
", ".($this->size_units !=
'' ? (int) $this->size_units :
'NULL');
497 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
498 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
499 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
500 $sql .=
", ".((int) $this->fk_incoterms);
501 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
502 $sql .=
", ".((int) $this->signed_status);
503 $sql .=
", ".((int) $this->billed);
506 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
507 $resql = $this->db->query($sql);
509 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"expedition");
512 $initialref =
'(PROV'.$this->id.
')';
513 if (!empty($this->
ref)) {
514 $initialref = $this->ref;
517 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
518 $sql .=
" SET ref = '".$this->db->escape($initialref).
"'";
519 $sql .=
" WHERE rowid = ".((int) $this->
id);
521 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
522 if ($this->db->query($sql)) {
523 $this->
ref = $initialref;
525 $num = count($this->lines);
526 $kits_list = array();
528 for ($i = 0; $i < $num; $i++) {
530 $objectsrc->fetch($this->lines[$i]->origin_line_id);
531 if ($this->lines[$i]->product_type ==
"9" && $objectsrc->special_code == SUBTOTALS_SPECIAL_CODE) {
532 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) {
539 $line = $this->lines[$i];
540 if ($line->fk_product > 0) {
546 if (!isset($kits_list[$line->fk_elementdet])) {
547 if (!is_object($line->product)) {
548 $line_product =
new Product($this->db);
549 $result = $line_product->fetch($line->fk_product,
'',
'',
'', 1, 1, 1);
554 $line_product = $line->product;
558 $line_product->get_sousproduits_arbo();
559 $prods_arbo = $line_product->get_arbo_each_prod($line->qty);
560 if (count($prods_arbo) > 0) {
561 $kits_list[$line->fk_elementdet] = array(
562 'arbo' => $prods_arbo,
563 'total_qty' => $line->qty,
567 $kits_list[$line->fk_elementdet][
'total_qty'] += $line->qty;
573 $kits_id_cached = array();
574 $sub_kits_id_cached = array();
575 $sub_parents_cached = array();
576 for ($i = 0; $i < $num; $i++) {
577 $line = $this->lines[$i];
580 if (!isset($kits_id_cached[$line->fk_elementdet])) {
581 if (!isset($line->detail_batch) || (isset($kits_list[$line->fk_elementdet]) && !
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE'))) {
582 $qty = isset($kits_list[$line->fk_elementdet]) ? $kits_list[$line->fk_elementdet][
'total_qty'] : $line->qty;
583 $warehouse_id = (isset($kits_list[$line->fk_elementdet]) && !
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) ? 0 : $line->entrepot_id;
584 $line_id = $this->
create_line($warehouse_id, $line->origin_line_id, $qty, $line->rang, $line->array_options, 0, $line->fk_product);
588 if (isset($kits_list[$line->fk_elementdet])) {
589 $kits_id_cached[$line->fk_elementdet] = $line_id;
597 $line_id = $kits_id_cached[$line->fk_elementdet];
601 if (isset($kits_list[$line->fk_elementdet]) && !
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) {
602 $prods_arbo = $kits_list[$line->fk_elementdet][
'arbo'];
605 $parent_line_id = $line_id;
607 $product_child_id = 0;
608 foreach ($prods_arbo as $index => $product_child_arr) {
623 $product_child_level = (int) $product_child_arr[
'level'];
624 $product_child_incdec = !empty($product_child_arr[
'incdec']);
627 if ($product_child_level != $level_last) {
628 $parent_line_id = $line_id;
629 $parent_product_id = $product_child_id;
630 if (isset($sub_parents_cached[$line->fk_elementdet][$parent_product_id])) {
631 $parent_line_id = $sub_parents_cached[$line->fk_elementdet][$parent_product_id];
633 $sub_parents_cached[$line->fk_elementdet][$parent_product_id] = $parent_line_id;
639 $next_level = $product_child_level;
640 $next_index = $index + 1;
641 if (isset($prods_arbo[$next_index])) {
642 $next_level = (int) $prods_arbo[$next_index][
'level'];
644 if ($next_level > $product_child_level) {
649 $product_child_id = (int) $product_child_arr[
'id'];
650 $product_child_qty = (float) $product_child_arr[
'nb_total'];
651 $warehouse_id = $line->entrepot_id;
652 if ($is_kit || !$product_child_incdec) {
653 if (!$product_child_incdec) {
654 $product_child_qty = 0;
660 if (!isset($sub_kits_id_cached[$line->fk_elementdet][$product_child_id]) || $warehouse_id > 0) {
661 $line_id = $this->
create_line($warehouse_id, ($parent_line_id ? 0 : $line->origin_line_id), $product_child_qty, $line->rang, $line->array_options, $parent_line_id, $product_child_id);
669 if (empty($warehouse_id)) {
670 $sub_kits_id_cached[$line->fk_elementdet][$product_child_id] = $line_id;
674 $level_last = $product_child_level;
680 if (!$error && $this->
id && $this->origin_id) {
687 if (!$error && $this->
id &&
getDolGlobalInt(
'SHIPPING_USE_ITS_OWN_CONTACTS') &&
getDolGlobalString(
'MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN') && !empty($this->origin_type) && !empty($this->origin_id)) {
688 $originforcontact = $this->origin_type;
689 $originidforcontact = $this->origin_id;
691 $sqlcontact =
"SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
692 $sqlcontact .=
" WHERE element_id = ".((int) $originidforcontact).
" AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$this->db->escape($originforcontact).
"'";
694 $resqlcontact = $this->db->query($sqlcontact);
696 while ($objcontact = $this->db->fetch_object($resqlcontact)) {
697 $this->
add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source);
700 dol_print_error($this->db);
712 if (!$error && !$notrigger) {
714 $result = $this->call_trigger(
'SHIPPING_CREATE', $user);
724 foreach ($this->errors as $errmsg) {
725 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
726 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
728 $this->db->rollback();
733 $this->db->rollback();
738 $this->error = $this->db->lasterror().
" - sql=$sql";
739 $this->db->rollback();
744 $this->error = $this->db->error().
" - sql=$sql";
745 $this->db->rollback();
763 public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = [], $parent_line_id = 0, $product_id = 0)
769 $expeditionline->fk_expedition = $this->id;
770 $expeditionline->entrepot_id = $entrepot_id;
771 $expeditionline->fk_elementdet = $origin_line_id;
772 $expeditionline->element_type = $this->origin;
773 $expeditionline->fk_parent = $parent_line_id;
774 $expeditionline->fk_product = $product_id;
775 $expeditionline->qty = $qty;
776 $expeditionline->rang = $rang;
777 $expeditionline->array_options = $array_options;
779 if (!($expeditionline->fk_product > 0)) {
781 $order_line->fetch($expeditionline->fk_elementdet);
782 $expeditionline->fk_product = $order_line->fk_product;
785 if (($lineId = $expeditionline->insert($user)) < 0) {
805 $stockLocationQty = array();
807 $tab = $line_ext->detail_batch;
809 foreach ($tab as $detbatch) {
810 if (!empty($detbatch->fk_warehouse)) {
811 if (empty($stockLocationQty[$detbatch->fk_warehouse])) {
812 $stockLocationQty[$detbatch->fk_warehouse] = 0;
814 $stockLocationQty[$detbatch->fk_warehouse] += $detbatch->qty;
818 foreach ($stockLocationQty as $stockLocation => $qty) {
819 $line_id = $this->
create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options);
824 foreach ($tab as $detbatch) {
825 if ($detbatch->fk_warehouse == $stockLocation) {
826 if (!($detbatch->create($line_id) > 0)) {
827 $this->errors = $detbatch->errors;
851 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
856 if (empty($id) && empty($ref) && empty($ref_ext)) {
860 $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.signed_status, e.fk_projet as fk_project, e.billed";
861 $sql .=
", e.date_valid, e.fk_user_valid";
862 $sql .=
", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
863 $sql .=
", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery";
864 $sql .=
", e.fk_shipping_method, e.tracking_number";
865 $sql .=
", e.note_private, e.note_public";
866 $sql .=
', e.fk_incoterms, e.location_incoterms';
867 $sql .=
', e.signed_status';
868 $sql .=
', i.libelle as label_incoterms';
869 $sql .=
', s.libelle as shipping_method';
870 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin_type";
871 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
872 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
873 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON e.fk_incoterms = i.rowid';
874 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as s ON e.fk_shipping_method = s.rowid';
875 $sql .=
" WHERE e.entity IN (".getEntity(
'expedition').
")";
877 $sql .=
" AND e.rowid = ".((int) $id);
880 $sql .=
" AND e.ref='".$this->db->escape($ref).
"'";
883 $sql .=
" AND e.ref_ext='".$this->db->escape($ref_ext).
"'";
886 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
887 $result = $this->db->query($sql);
889 if ($this->db->num_rows($result)) {
890 $obj = $this->db->fetch_object($result);
892 $this->
id = (int) $obj->rowid;
893 $this->entity = $obj->entity;
894 $this->
ref = $obj->ref;
895 $this->socid = $obj->socid;
896 $this->ref_customer = $obj->ref_customer;
897 $this->ref_ext = $obj->ref_ext;
898 $this->
status = $obj->fk_statut;
899 $this->statut = $this->status;
900 $this->signed_status = $obj->signed_status;
901 $this->user_author_id = $obj->fk_user_author;
902 $this->fk_user_author = $obj->fk_user_author;
903 $this->user_creation_id = $obj->fk_user_author;
904 $this->fk_user_valid = $obj->fk_user_valid;
905 $this->date_creation = $this->db->jdate($obj->date_creation);
906 $this->date_valid = $this->db->jdate($obj->date_valid);
907 $this->
date = $this->db->jdate($obj->date_expedition);
908 $this->date_expedition = $this->db->jdate($obj->date_expedition);
909 $this->date_shipping = $this->db->jdate($obj->date_expedition);
910 $this->date_delivery = $this->db->jdate($obj->date_delivery);
911 $this->fk_delivery_address = $obj->fk_address;
912 $this->model_pdf = $obj->model_pdf;
913 $this->shipping_method_id = $obj->fk_shipping_method;
914 $this->shipping_method = $obj->shipping_method;
915 $this->tracking_number = $obj->tracking_number;
916 $this->origin = ($obj->origin_type ? $obj->origin_type :
'commande');
917 $this->origin_type = ($obj->origin_type ? $obj->origin_type :
'commande');
918 $this->origin_id = $obj->origin_id;
919 $this->billed = $obj->billed;
920 $this->fk_project = $obj->fk_project;
921 $this->signed_status = $obj->signed_status;
922 $this->trueWeight = $obj->weight;
923 $this->weight_units = $obj->weight_units;
925 $this->trueWidth = $obj->width;
926 $this->width_units = $obj->size_units;
927 $this->trueHeight = $obj->height;
928 $this->height_units = $obj->size_units;
929 $this->trueDepth = $obj->size;
930 $this->depth_units = $obj->size_units;
932 $this->note_public = $obj->note_public;
933 $this->note_private = $obj->note_private;
936 $this->trueSize = $obj->size.
"x".$obj->width.
"x".$obj->height;
937 $this->size_units = $obj->size_units;
940 $this->fk_incoterms = $obj->fk_incoterms;
941 $this->location_incoterms = $obj->location_incoterms;
942 $this->label_incoterms = $obj->label_incoterms;
944 $this->db->free($result);
957 if (!empty($this->multicurrency_code)) {
958 $this->multicurrency_code = $this->thirdparty->multicurrency_code;
960 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($this->thirdparty->multicurrency_tx)) {
961 $this->multicurrency_tx = $this->thirdparty->multicurrency_tx;
968 if (empty($obj->origin_id)) {
979 dol_syslog(get_class($this).
'::Fetch no expedition found', LOG_ERR);
980 $this->error =
'Shipment with id '.$id.
' not found';
984 $this->error = $this->db->error();
996 public function valid($user, $notrigger = 0)
1000 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1006 dol_syslog(get_class($this).
"::valid not in draft status", LOG_WARNING);
1010 if (!isset($this->socid)) {
1011 dol_syslog(get_class($this).
"::can't valid socid not set", LOG_WARNING);
1015 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'creer'))
1016 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'shipping_advance',
'validate')))) {
1017 $this->error =
'Permission denied';
1018 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
1027 $soc =
new Societe($this->db);
1028 $soc->fetch($this->socid);
1031 $result = $soc->setAsCustomer();
1034 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1035 $numref = $this->getNextNumRef($soc);
1036 } elseif (!empty($this->
ref)) {
1037 $numref = (string) $this->
ref;
1039 $numref =
"EXP".$this->id;
1046 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1047 $sql .=
" ref = '".$this->db->escape($numref).
"'";
1048 $sql .=
", fk_statut = 1";
1049 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
1050 $sql .=
", fk_user_valid = ".((int) $user->id);
1051 $sql .=
" WHERE rowid = ".((int) $this->
id);
1053 dol_syslog(get_class($this).
"::valid update expedition", LOG_DEBUG);
1054 $resql = $this->db->query($sql);
1056 $this->error = $this->db->lasterror();
1069 if (!$error && $this->origin_id > 0) {
1070 $origintype = ($this->origin_type ? $this->origin_type : $this->origin);
1071 if ($origintype ==
'order') {
1072 $origintype =
'commande';
1074 if ($origintype ==
'commande') {
1076 $triggerKey =
'SHIPPING_ORDER_SHIPMENTONPROCESS';
1086 if (!$error && !$notrigger) {
1088 $result = $this->call_trigger(
'SHIPPING_VALIDATE', $user);
1096 $this->oldref = $this->ref;
1099 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1101 $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).
"'";
1102 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1103 $resql = $this->db->query($sql);
1106 $this->error = $this->db->lasterror();
1108 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref).
"'";
1109 $sql .=
" WHERE filepath = 'expedition/sending/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1110 $resql = $this->db->query($sql);
1113 $this->error = $this->db->lasterror();
1119 $dirsource =
$conf->expedition->dir_output.
'/sending/'.$oldref;
1120 $dirdest =
$conf->expedition->dir_output.
'/sending/'.$newref;
1121 if (!$error && file_exists($dirsource)) {
1122 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
1124 if (@rename($dirsource, $dirdest)) {
1127 $listoffiles =
dol_dir_list(
$conf->expedition->dir_output.
'/sending/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1128 foreach ($listoffiles as $fileentry) {
1129 $dirsource = $fileentry[
'name'];
1130 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1131 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1132 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1133 @rename($dirsource, $dirdest);
1142 $this->
ref = $numref;
1148 $this->db->commit();
1151 $this->db->rollback();
1165 if (empty($rows) || !is_array($rows)) {
1169 $rowToOrigin = array();
1170 $originToRows = array();
1172 $sql =
"SELECT rowid, fk_elementdet";
1173 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet";
1174 $sql .=
" WHERE fk_expedition = ".((int) $this->
id);
1175 $sql .=
" ORDER BY rang ASC, rowid ASC";
1177 $resql = $this->db->query($sql);
1179 while ($obj = $this->db->fetch_object($resql)) {
1180 $rowid = (int) $obj->rowid;
1181 $originLine = (int) $obj->fk_elementdet;
1182 $rowToOrigin[$rowid] = $originLine;
1184 if (!isset($originToRows[$originLine])) {
1185 $originToRows[$originLine] = array();
1187 $originToRows[$originLine][] = $rowid;
1189 $this->db->free($resql);
1191 parent::line_ajaxorder($rows);
1195 $processedOrigins = array();
1198 foreach ($rows as $rowid) {
1199 $rowid = (int) $rowid;
1200 if (empty($rowid)) {
1204 $originLine = isset($rowToOrigin[$rowid]) ? $rowToOrigin[$rowid] : 0;
1205 if ($originLine > 0 && !empty($processedOrigins[$originLine])) {
1209 $rowidsToUpdate = array($rowid);
1210 if ($originLine > 0 && !empty($originToRows[$originLine])) {
1211 $rowidsToUpdate = $originToRows[$originLine];
1212 $processedOrigins[$originLine] = 1;
1215 foreach ($rowidsToUpdate as $childRowId) {
1234 if ($this->
status == self::STATUS_VALIDATED || $this->
status == self::STATUS_CLOSED) {
1236 include_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
1237 $delivery =
new Delivery($this->db);
1238 $result = $delivery->create_from_sending($user, $this->
id);
1260 private function checkLineStockRequirements($fk_product, $fk_entrepot, $qty, $product_type =
null, $forbid_batch_product =
false, $allowEmptyWarehouse =
false)
1264 if (!($fk_product > 0)) {
1268 $warehouseId = (int) $fk_entrepot;
1274 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1276 $product =
new Product($this->db);
1277 $result = $product->fetch($fk_product);
1283 if ($product_type ===
null) {
1284 $product_type = $product->type;
1287 if ($forbid_batch_product &&
isModEnabled(
'productbatch') && $product->hasbatch()) {
1288 $langs->load(
'errors');
1289 $this->error = $langs->trans(
'ErrorTryToMakeMoveOnProductRequiringBatchData', $product->ref);
1290 $this->errorhidden =
'ErrorTryToMakeMoveOnProductRequiringBatchData';
1302 if (!$allowEmptyWarehouse && !empty($qty) && !($warehouseId > 0) && !
getDolGlobalString(
'STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS') && !(
getDolGlobalString(
'SHIPMENT_SUPPORTS_SERVICES') && $product_type ==
Product::TYPE_SERVICE) && $product->stockable_product == Product::ENABLED_STOCK) {
1303 $langs->load(
"errors");
1304 $this->error = $langs->trans(
"ErrorWarehouseRequiredIntoShipmentLine");
1309 if ($allowEmptyWarehouse && !($warehouseId > 0)) {
1314 $productChildrenNb = 0;
1316 $productChildrenNb = $product->hasFatherOrChild(1);
1318 if ($productChildrenNb > 0) {
1319 $product_stock =
null;
1320 $product->loadStockForVirtualProduct(
'warehouseopen', $qty);
1321 if ($warehouseId > 0) {
1322 if (isset($product->stock_warehouse[$warehouseId])) {
1323 $product_stock = $product->stock_warehouse[$warehouseId]->real;
1326 foreach ($product->stock_warehouse as $componentStockWarehouse) {
1327 if ($product_stock ===
null) {
1328 $product_stock = $componentStockWarehouse->real;
1330 $product_stock = min($product_stock, $componentStockWarehouse->real);
1334 if ($product_stock ===
null) {
1339 if ($warehouseId > 0) {
1340 $result = $product->load_stock(
'warehouseopen');
1345 $product_stock = empty($product->stock_warehouse[$warehouseId]) ? 0 : $product->stock_warehouse[$warehouseId]->real;
1347 $product_stock = $product->stock_reel;
1352 $isavirtualproduct = ($productChildrenNb > 0);
1357 || ($isavirtualproduct && !
getDolGlobalInt(
'STOCK_EXCLUDE_VIRTUAL_PRODUCTS'))
1360 if ($product->stockable_product == Product::ENABLED_STOCK && $product_stock < $qty) {
1361 $langs->load(
"errors");
1362 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
1363 $this->errorhidden =
'ErrorStockIsNotEnoughToAddProductOnShipment';
1388 public function addline($entrepot_id, $id, $qty, $array_options = [], $fk_product = 0, $fk_parent = 0)
1392 $num = count($this->lines);
1395 $line->entrepot_id = $entrepot_id;
1396 $line->origin_line_id = $id;
1397 $line->fk_elementdet = $id;
1398 $line->element_type =
'order';
1399 $line->fk_parent = $fk_parent;
1400 $line->fk_product = $fk_product;
1404 $orderline->fetch($id);
1407 $line->rang = $orderline->rang;
1408 $line->product_type = $orderline->product_type;
1409 if (!($line->fk_product > 0)) {
1410 $line->fk_product = $orderline->fk_product;
1413 if (!empty($orderline->fk_product)) {
1414 $result = $this->
checkLineStockRequirements((
int) $orderline->fk_product, $entrepot_id, (
float) $line->qty, (
int) $line->product_type);
1422 if (
isModEnabled(
'productbatch') && !empty($line->fk_product) && !empty($orderline->product_tobatch)) {
1423 $this->error =
'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.
' '.$line->fk_product;
1428 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1429 $line->array_options = $array_options;
1432 $this->lines[$num] = $line;
1451 public function addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $array_options = [], $fk_entrepot = 0)
1453 global
$mysoc, $langs, $user;
1455 if ($this->
status == self::STATUS_DRAFT) {
1471 if ($ranktouse == -1) {
1472 $rangmax = $this->
line_max($fk_parent);
1473 $ranktouse = $rangmax + 1;
1478 $this->line->fk_expedition = $this->id;
1479 $this->line->element_type = $element_type;
1480 $this->line->fk_product = $fk_product;
1481 $this->line->entrepot_id = (int) $fk_entrepot;
1482 $this->line->fk_entrepot = (int) $fk_entrepot;
1483 $this->line->description = $description;
1484 $this->line->desc = $description;
1485 $this->line->fk_parent = $fk_parent;
1486 $this->line->qty = (float) $qty;
1487 $this->line->fk_unit = $fk_unit;
1488 $this->line->rang = $ranktouse;
1490 if (is_array($array_options) && count($array_options) > 0) {
1491 $this->line->array_options = $array_options;
1494 $result = $this->line->insert($user);
1496 if (!isset($this->context[
'createfromclone'])) {
1497 if (!empty($fk_parent)) {
1499 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1500 $linecount = count($this->lines);
1501 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
1505 $this->lines[] = $this->line;
1508 $this->db->commit();
1509 return $this->line->id;
1511 $this->error = $this->line->error;
1512 dol_syslog(get_class($this).
"::addlinefree error=".$this->error, LOG_ERR);
1513 $this->db->rollback();
1517 dol_syslog(get_class($this).
"::addlinefree status of shipment must be Draft to allow use of ->addlinefree()", LOG_ERR);
1538 public function updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $notrigger, $array_options = array(), $fk_entrepot = -1)
1540 global
$mysoc, $langs, $user;
1542 if ($this->
status == self::STATUS_DRAFT) {
1552 $qty = (float) $qty;
1553 $description = trim($description);
1558 $result = $line->fetch($rowid);
1561 $this->db->rollback();
1564 $result = $line->fetch_optionals();
1567 $this->db->rollback();
1572 $fk_product = (int) $line->fk_product;
1573 if ($fk_entrepot < 0) {
1574 $fk_entrepot = (int) $line->entrepot_id;
1579 $this->db->rollback();
1583 $staticline = clone $line;
1585 $line->oldline = $staticline;
1586 $this->line = $line;
1587 $this->line->context = $this->context;
1588 $this->line->rang = $rang;
1589 $this->line->fk_expedition = $this->id;
1590 $this->line->element_type = $element_type;
1591 $this->line->fk_product = $fk_product;
1592 $this->line->entrepot_id = (int) $fk_entrepot;
1593 $this->line->fk_entrepot = (int) $fk_entrepot;
1594 $this->line->qty = $qty;
1595 $this->line->fk_unit = $fk_unit;
1596 $this->line->fk_parent = $fk_parent;
1597 $this->line->description = $description;
1599 if (is_array($array_options) && count($array_options) > 0) {
1601 foreach ($array_options as $key => $value) {
1602 $this->line->array_options[$key] = $array_options[$key];
1606 $result = $this->line->update($user, $notrigger);
1609 if (!empty($fk_parent)) {
1613 $this->db->commit();
1616 $this->error = $this->line->error;
1618 $this->db->rollback();
1622 $this->error = get_class($this).
"::updatelinefree Shipment status makes operation forbidden";
1623 $this->errors = array(
'ShipmentStatusMakeOperationForbidden');
1637 public function addline_batch($dbatch, $array_options = [], $origin_line =
null)
1642 $num = count($this->lines);
1644 if ($dbatch[
'qty'] > 0 || ($dbatch[
'qty'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1647 foreach ($dbatch[
'detail'] as $key => $value) {
1648 if ($value[
'q'] > 0 || ($value[
'q'] == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
1654 $ret = $linebatch->fetchFromStock($value[
'id_batch']);
1659 $linebatch->qty = $value[
'q'];
1660 if ($linebatch->qty == 0 &&
getDolGlobalString(
'SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
1661 $linebatch->batch =
null;
1663 $tab[] = $linebatch;
1666 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
1668 $prod_batch->fetch($value[
'id_batch']);
1670 if ($prod_batch->qty < $linebatch->qty) {
1671 $langs->load(
"errors");
1672 $this->errors[] = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product);
1673 dol_syslog(get_class($this).
"::addline_batch error=Product ".$prod_batch->batch.
": ".$this->errorsToString(), LOG_ERR);
1679 if (is_object($linebatch)) {
1680 $line->entrepot_id = $linebatch->fk_warehouse;
1682 $line->origin_line_id = $dbatch[
'ix_l'];
1683 $line->fk_elementdet = $dbatch[
'ix_l'];
1684 $line->qty = $dbatch[
'qty'];
1685 $line->detail_batch = $tab;
1686 if (!($line->rang > 0)) {
1687 $line->rang = $origin_line->rang;
1689 if (!($line->fk_product > 0)) {
1690 $line->fk_product = $origin_line->fk_product;
1694 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
1695 $line->array_options = $array_options;
1699 $this->lines[$num] = $line;
1712 public function update($user =
null, $notrigger = 0)
1719 if (isset($this->
ref)) {
1720 $this->
ref = trim($this->
ref);
1722 if (isset($this->entity)) {
1723 $this->entity = (int) $this->entity;
1725 if (isset($this->ref_customer)) {
1726 $this->ref_customer = trim($this->ref_customer);
1728 if (isset($this->socid)) {
1729 $this->socid = (int) $this->socid;
1731 if (isset($this->fk_user_author)) {
1732 $this->fk_user_author = (int) $this->fk_user_author;
1734 if (isset($this->fk_user_valid)) {
1735 $this->fk_user_valid = (int) $this->fk_user_valid;
1737 if (isset($this->fk_delivery_address)) {
1738 $this->fk_delivery_address = (int) $this->fk_delivery_address;
1740 if (isset($this->shipping_method_id)) {
1741 $this->shipping_method_id = (int) $this->shipping_method_id;
1743 if (isset($this->tracking_number)) {
1744 $this->tracking_number = trim($this->tracking_number);
1746 if (isset($this->statut)) {
1747 $this->statut = (int) $this->statut;
1749 if (isset($this->
status)) {
1752 if (isset($this->trueDepth)) {
1753 $this->trueDepth = trim($this->trueDepth);
1755 if (isset($this->trueWidth)) {
1756 $this->trueWidth = trim($this->trueWidth);
1758 if (isset($this->trueHeight)) {
1759 $this->trueHeight = trim($this->trueHeight);
1761 if (isset($this->size_units)) {
1762 $this->size_units = trim($this->size_units);
1764 if (isset($this->weight_units)) {
1765 $this->weight_units = (int) $this->weight_units;
1767 if (isset($this->trueWeight)) {
1768 $this->weight = trim((
string) $this->trueWeight);
1770 if (isset($this->note_private)) {
1771 $this->note_private = trim($this->note_private);
1773 if (isset($this->note_public)) {
1774 $this->note_public = trim($this->note_public);
1776 if (isset($this->model_pdf)) {
1777 $this->model_pdf = trim($this->model_pdf);
1779 if (!empty($this->date_expedition)) {
1780 $this->date_shipping = $this->date_expedition;
1787 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
1788 $sql .=
" ref = ".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1789 $sql .=
" ref_ext = ".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1790 $sql .=
" ref_customer = ".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1791 $sql .=
" fk_soc = ".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1792 $sql .=
" date_creation = ".(dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
",";
1793 $sql .=
" fk_user_author = ".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
1794 $sql .=
" date_valid = ".(dol_strlen($this->date_valid) != 0 ?
"'".$this->db->idate($this->date_valid).
"'" :
'null').
",";
1795 $sql .=
" fk_user_valid = ".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) :
"null").
",";
1796 $sql .=
" date_expedition = ".(dol_strlen($this->date_shipping) != 0 ?
"'".$this->db->idate($this->date_shipping).
"'" :
'null').
",";
1797 $sql .=
" date_delivery = ".(dol_strlen($this->date_delivery) != 0 ?
"'".$this->db->idate($this->date_delivery).
"'" :
'null').
",";
1798 $sql .=
" fk_address = ".(isset($this->fk_delivery_address) ? ((int) $this->fk_delivery_address) :
"null").
",";
1799 $sql .=
" fk_shipping_method = ".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? ((
int) $this->shipping_method_id) :
"null").
",";
1800 $sql .=
" tracking_number = ".(isset($this->tracking_number) ?
"'".$this->db->escape($this->tracking_number).
"'" :
"null").
",";
1801 $sql .=
" fk_statut = ".(isset($this->
status) ? ((int) $this->
status) :
"null").
",";
1802 $sql .=
" fk_projet = ".(isset($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
1803 $sql .=
" height = ".(($this->trueHeight !=
'') ? ((
float) $this->trueHeight) :
"null").
",";
1804 $sql .=
" width = ".(($this->trueWidth !=
'') ? ((
float) $this->trueWidth) :
"null").
",";
1805 $sql .=
" size_units = ".(isset($this->size_units) ? ((int) $this->size_units) :
"null").
",";
1806 $sql .=
" size = ".(($this->trueDepth !=
'') ? ((
float) $this->trueDepth) :
"null").
",";
1807 $sql .=
" weight_units = ".(isset($this->weight_units) ? ((int) $this->weight_units) :
"null").
",";
1808 $sql .=
" weight = ".(($this->trueWeight !=
'') ? ((
float) $this->trueWeight) :
"null").
",";
1809 $sql .=
" note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1810 $sql .=
" note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1811 $sql .=
" model_pdf = ".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1812 $sql .=
" entity = ".((int)
$conf->entity);
1813 $sql .=
" WHERE rowid = ".((int) $this->
id);
1817 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1818 $resql = $this->db->query($sql);
1821 $this->errors[] =
"Error ".$this->db->lasterror();
1832 if (!$error && !$notrigger) {
1834 $result = $this->call_trigger(
'SHIPPING_MODIFY', $user);
1843 foreach ($this->errors as $errmsg) {
1844 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1845 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1847 $this->db->rollback();
1850 $this->db->commit();
1864 public function cancel($user, $notrigger = 0, $also_update_stock =
false)
1866 global
$conf, $langs, $user;
1868 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1877 if (isset($this->linkedObjectsIds[
'delivery']) && count($this->linkedObjectsIds[
'delivery']) > 0) {
1878 $this->error =
'ErrorThereIsSomeDeliveries';
1882 if (!$error && !$notrigger) {
1884 $result = $this->call_trigger(
'SHIPPING_CANCEL', $user);
1892 $can_update_stock =
isModEnabled(
'stock') && $also_update_stock &&
1896 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
1898 $langs->load(
"agenda");
1902 $sql .=
" ed.fk_product";
1903 $sql .=
", ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
1904 $sql .=
", SUM(".$this->db->ifsql(
"pa.rowid IS NOT NULL",
"1",
"0").
") as iskit";
1905 $sql .=
", ".$this->db->ifsql(
"pai.incdec IS NULL",
"1",
"pai.incdec").
" as incdec";
1906 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet as ed";
1907 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pa ON pa.fk_product_pere = ed.fk_product";
1908 $sql .=
" LEFT JOIN ".$this->db->prefix().
"expeditiondet as edp ON edp.rowid = ed.fk_parent";
1909 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pai ON pai.fk_product_pere = edp.fk_product AND pai.fk_product_fils = ed.fk_product";
1910 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
1911 $sql .=
" GROUP BY ed.fk_product, ed.qty, ed.fk_entrepot, ed.rowid, pai.incdec";
1912 $sql .= $this->db->order(
"ed.rowid",
"DESC");
1914 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
1915 $resql = $this->db->query($sql);
1917 $cpt = $this->db->num_rows($resql);
1921 for ($i = 0; $i < $cpt; $i++) {
1922 dol_syslog(get_class($this).
"::delete movement index ".$i);
1923 $obj = $this->db->fetch_object($resql);
1924 $line_id = (int) $obj->expeditiondet_id;
1926 if ($can_update_stock && (empty($obj->iskit) ||
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) && !empty($obj->incdec)) {
1929 $mouvS->origin =
'';
1933 $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
1934 if (!is_array($lotArray)) {
1936 $this->errors[] =
"Error ".$this->db->lasterror();
1940 if (empty($lotArray)) {
1944 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->transnoentitiesnoconv(
"ShipmentCanceledInDolibarr", $this->ref),
'',
'',
'',
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
1947 $this->errors = array_merge($this->errors, $mouvS->errors);
1953 foreach ($lotArray as $lot) {
1954 if (empty($lot->qty)) {
1957 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->transnoentitiesnoconv(
"ShipmentCanceledInDolibarr", $this->ref),
'',
'', (
string) $lot->batch,
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
1960 $this->errors = array_merge($this->errors, $mouvS->errors);
1973 $res = $shipment_line->fetch($line_id);
1975 $result = $shipment_line->delete($user);
1978 $this->errors[] =
"Error ".$shipment_line->errorsToString();
1982 $this->errors[] =
"Error ".$shipment_line->errorsToString();
1992 $this->errors[] =
"Error ".$this->db->lasterror();
1998 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"expedition";
1999 $sql .=
" WHERE rowid = ".((int) $this->
id);
2001 if ($this->db->query($sql)) {
2002 if (!empty($this->origin) && $this->origin_id > 0) {
2005 '@phan-var-force Facture|Commande $origin_object';
2016 $this->db->commit();
2020 if (!empty(
$conf->expedition->dir_output)) {
2021 $dir =
$conf->expedition->dir_output.
'/sending/'.$ref;
2022 $file = $dir.
'/'.$ref.
'.pdf';
2023 if (file_exists($file)) {
2028 if (file_exists($dir)) {
2030 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
2038 $this->error = $this->db->lasterror().
" - sql=$sql";
2039 $this->db->rollback();
2043 $this->db->rollback();
2057 public function delete($user =
null, $notrigger = 0, $also_update_stock =
false)
2059 global
$conf, $langs;
2065 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2074 if (isset($this->linkedObjectsIds[
'delivery']) && count($this->linkedObjectsIds[
'delivery']) > 0) {
2075 $this->error =
'ErrorThereIsSomeDeliveries';
2079 if (!$error && !$notrigger) {
2081 $result = $this->call_trigger(
'SHIPPING_DELETE', $user);
2089 $can_update_stock =
isModEnabled(
'stock') && $also_update_stock &&
2093 require_once DOL_DOCUMENT_ROOT.
"/product/stock/class/mouvementstock.class.php";
2095 $langs->load(
"agenda");
2102 $sql .=
" ed.fk_product";
2103 $sql .=
", ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
2104 $sql .=
", SUM(".$this->db->ifsql(
"pa.rowid IS NOT NULL",
"1",
"0").
") as iskit";
2105 $sql .=
", ".$this->db->ifsql(
"pai.incdec IS NULL",
"1",
"pai.incdec").
" as incdec";
2106 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet as ed";
2107 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pa ON pa.fk_product_pere = ed.fk_product";
2108 $sql .=
" LEFT JOIN ".$this->db->prefix().
"expeditiondet as edp ON edp.rowid = ed.fk_parent";
2109 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_association as pai ON pai.fk_product_pere = edp.fk_product AND pai.fk_product_fils = ed.fk_product";
2110 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2111 $sql .=
" GROUP BY ed.fk_product, ed.qty, ed.fk_entrepot, ed.rowid, pai.incdec";
2112 $sql .= $this->db->order(
"ed.rowid",
"DESC");
2114 dol_syslog(get_class($this).
"::delete select details", LOG_DEBUG);
2115 $resql = $this->db->query($sql);
2117 $cpt = $this->db->num_rows($resql);
2118 for ($i = 0; $i < $cpt; $i++) {
2119 dol_syslog(get_class($this).
"::delete movement index ".$i);
2120 $obj = $this->db->fetch_object($resql);
2121 $line_id = (int) $obj->expeditiondet_id;
2123 if ($can_update_stock && (empty($obj->iskit) ||
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE')) && !empty($obj->incdec)) {
2126 $mouvS->origin =
'';
2128 $lotArray = $shipmentlinebatch->fetchAll($line_id);
2129 if (!is_array($lotArray)) {
2131 $this->errors[] =
"Error ".$this->db->lasterror();
2133 if (empty($lotArray)) {
2137 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->transnoentitiesnoconv(
"ShipmentDeletedInDolibarr", $this->ref),
'',
'',
'',
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
2140 $this->errors = array_merge($this->errors, $mouvS->errors);
2146 foreach ($lotArray as $lot) {
2147 if (empty($lot->qty)) {
2150 $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->transnoentitiesnoconv(
"ShipmentDeletedInDolibarr", $this->ref),
'',
'', (
string) $lot->batch,
'', 0,
'', 0, (empty($obj->iskit) ? 1 : 0));
2153 $this->errors = array_merge($this->errors, $mouvS->errors);
2166 $res = $shipment_line->fetch($line_id);
2168 $result = $shipment_line->delete($user);
2171 $this->errors[] =
"Error ".$shipment_line->errorsToString();
2175 $this->errors[] =
"Error ".$shipment_line->errorsToString();
2185 $this->errors[] =
"Error ".$this->db->lasterror();
2210 $sql =
"DELETE FROM ".$this->db->prefix().
"expedition";
2211 $sql .=
" WHERE rowid = ".((int) $this->
id);
2213 if ($this->db->query($sql)) {
2214 if (!empty($this->origin) && $this->origin_id > 0) {
2217 '@phan-var-force Facture|Commande $origin_object';
2227 $this->db->commit();
2235 if (!empty(
$conf->expedition->dir_output) && !empty($ref)) {
2236 $dir =
$conf->expedition->dir_output .
'/sending/' . $ref;
2237 $file = $dir .
'/' . $ref .
'.pdf';
2238 if (file_exists($file)) {
2243 if (file_exists($dir)) {
2245 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
2253 $this->error = $this->db->lasterror().
" - sql=$sql";
2254 $this->db->rollback();
2258 $this->db->rollback();
2262 $this->db->rollback();
2278 $this->lines = array();
2283 $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";
2284 $sql .=
", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
2285 $sql .=
", cd.fk_remise_except, cd.fk_product_fournisseur_price as fk_fournprice";
2286 $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";
2287 $sql .=
", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang, cd.date_start, cd.date_end, cd.special_code";
2288 $sql .=
", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_element, ed.fk_elementdet, ed.element_type, ed.fk_entrepot, ed.extraparams";
2289 $sql .=
", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode";
2290 $sql .=
", p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units";
2291 $sql .=
", p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy";
2292 $sql .=
", p.tobatch as product_tobatch, p.stockable_product";
2293 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed, ".MAIN_DB_PREFIX.
"commandedet as cd";
2294 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = cd.fk_product";
2295 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
2296 $sql .=
" AND ed.fk_elementdet = cd.rowid";
2297 $sql .=
" ORDER BY CASE WHEN ed.rang IS NULL OR ed.rang = 0 THEN cd.rang ELSE ed.rang END, ed.rowid";
2299 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
2300 $resql = $this->db->query($sql);
2302 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2304 $num = $this->db->num_rows($resql);
2310 $this->total_ht = 0;
2311 $this->total_tva = 0;
2312 $this->total_ttc = 0;
2313 $this->total_localtax1 = 0;
2314 $this->total_localtax2 = 0;
2316 $this->multicurrency_total_ht = 0;
2317 $this->multicurrency_total_tva = 0;
2318 $this->multicurrency_total_ttc = 0;
2324 $obj = $this->db->fetch_object($resql);
2326 if ($originline > 0 && $originline == $obj->fk_elementdet) {
2328 $line->entrepot_id = 0;
2329 $line->qty_shipped += $obj->qty_shipped;
2332 $line->entrepot_id = $obj->fk_entrepot;
2333 $line->qty_shipped = $obj->qty_shipped;
2337 $detail_entrepot->entrepot_id = $obj->fk_entrepot;
2338 $detail_entrepot->qty_shipped = $obj->qty_shipped;
2339 $detail_entrepot->line_id = $obj->line_id;
2340 $line->details_entrepot[] = $detail_entrepot;
2342 $line->line_id = $obj->line_id;
2343 $line->rowid = $obj->line_id;
2344 $line->id = $obj->line_id;
2346 $line->fk_origin =
'orderline';
2348 $line->fk_element = $obj->fk_element;
2349 $line->origin_id = $obj->fk_element;
2350 $line->fk_elementdet = $obj->fk_elementdet;
2351 $line->origin_line_id = $obj->fk_elementdet;
2352 $line->element_type = $obj->element_type;
2354 $line->fk_expedition = $this->id;
2356 $line->stockable_product = $obj->stockable_product;
2357 $line->product_type = $obj->product_type;
2358 $line->fk_product = $obj->fk_product;
2359 $line->fk_product_type = $obj->fk_product_type;
2360 $line->ref = $obj->product_ref;
2361 $line->product_ref = $obj->product_ref;
2362 $line->product_label = $obj->product_label;
2363 $line->product_barcode = $obj->product_barcode;
2364 $line->product_tosell = $obj->product_tosell;
2365 $line->product_tobuy = $obj->product_tobuy;
2366 $line->product_tobatch = $obj->product_tobatch;
2367 $line->fk_fournprice = $obj->fk_fournprice;
2368 $line->label = $obj->custom_label;
2370 $line->description = $obj->description;
2371 $line->desc = $obj->description;
2373 $line->qty_asked = $obj->qty_asked;
2374 $line->rang = $obj->rang;
2375 $line->weight = $obj->weight;
2376 $line->weight_units = $obj->weight_units;
2377 $line->length = $obj->length;
2378 $line->length_units = $obj->length_units;
2379 $line->width = $obj->width;
2380 $line->width_units = $obj->width_units;
2381 $line->height = $obj->height;
2382 $line->height_units = $obj->height_units;
2383 $line->surface = $obj->surface;
2384 $line->surface_units = $obj->surface_units;
2385 $line->volume = $obj->volume;
2386 $line->volume_units = $obj->volume_units;
2387 $line->stockable_product = $obj->stockable_product;
2388 $line->fk_unit = $obj->fk_unit;
2390 $line->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
2392 $line->pa_ht = $obj->pa_ht;
2395 $localtax_array = array(0 => $obj->localtax1_type, 1 => $obj->localtax1_tx, 2 => $obj->localtax2_type, 3 => $obj->localtax2_tx);
2396 $localtax1_tx =
get_localtax($obj->tva_tx, 1, $this->thirdparty);
2397 $localtax2_tx =
get_localtax($obj->tva_tx, 2, $this->thirdparty);
2400 $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);
2401 $line->desc = $obj->description;
2402 $line->qty = $line->qty_shipped;
2403 $line->total_ht = (float) $tabprice[0];
2404 $line->total_localtax1 = (float) $tabprice[9];
2405 $line->total_localtax2 = (float) $tabprice[10];
2406 $line->total_ttc = (float) $tabprice[2];
2407 $line->total_tva = (float) $tabprice[1];
2408 $line->vat_src_code = $obj->vat_src_code;
2409 $line->tva_tx = $obj->tva_tx;
2410 $line->localtax1_tx = $obj->localtax1_tx;
2411 $line->localtax2_tx = $obj->localtax2_tx;
2412 $line->info_bits = $obj->info_bits;
2413 $line->price = $obj->price;
2414 $line->subprice = $obj->subprice;
2415 $line->fk_remise_except = $obj->fk_remise_except;
2416 $line->remise_percent = $obj->remise_percent;
2418 $this->total_ht += $tabprice[0];
2419 $this->total_tva += $tabprice[1];
2420 $this->total_ttc += $tabprice[2];
2421 $this->total_localtax1 += $tabprice[9];
2422 $this->total_localtax2 += $tabprice[10];
2424 $line->date_start = $this->db->jdate($obj->date_start);
2425 $line->date_end = $this->db->jdate($obj->date_end);
2427 $line->special_code = $obj->special_code;
2430 $this->fk_multicurrency = $obj->fk_multicurrency;
2431 $this->multicurrency_code = $obj->multicurrency_code;
2432 $line->multicurrency_subprice = $obj->multicurrency_subprice;
2433 $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
2434 $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
2435 $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
2437 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
2438 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
2439 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
2442 if (
isModEnabled(
'productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) {
2443 if ($originline != $obj->fk_elementdet) {
2444 $line->detail_batch = array();
2446 $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product);
2448 if (is_array($newdetailbatch)) {
2449 if ($originline != $obj->fk_elementdet) {
2450 $line->detail_batch = $newdetailbatch;
2452 $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
2459 $detail_children = array();
2460 $line_child_list = array();
2461 $res = $line->findAllChild($line->id, $line_child_list, 1);
2463 foreach ($line_child_list as $child_line) {
2464 foreach ($child_line as $child_obj) {
2465 $child_product_id = (int) $child_obj->fk_product;
2466 $child_warehouse_id = (int) $child_obj->fk_warehouse;
2468 if ($child_warehouse_id > 0) {
2470 if (!isset($detail_children[$child_product_id])) {
2471 $detail_children[$child_product_id] = array();
2473 if (!isset($detail_children[$child_product_id][$child_warehouse_id])) {
2474 $detail_children[$child_product_id][$child_warehouse_id] = 0;
2476 $detail_children[$child_product_id][$child_warehouse_id] += $child_obj->qty;
2481 $line->detail_children = $detail_children;
2484 $line->fetch_optionals();
2486 if ($originline != $obj->fk_elementdet) {
2487 $this->lines[$lineindex] = $line;
2490 $line->total_ht += $tabprice[0];
2491 $line->total_localtax1 += $tabprice[9];
2492 $line->total_localtax2 += $tabprice[10];
2493 $line->total_ttc += $tabprice[2];
2494 $line->total_tva += $tabprice[1];
2498 $originline = $obj->fk_elementdet;
2500 $this->db->free($resql);
2503 $this->error = $this->db->error();
2518 $sql =
"SELECT COUNT(e.rowid) as nb";
2519 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as e";
2520 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
2521 $sql .=
" WHERE e.entity = ".((int)
$conf->entity);
2522 $sql .=
" AND el.rowid IS NULL";
2524 $resql = $this->db->query($sql);
2526 $this->error = $this->db->lasterror();
2529 $obj = $this->db->fetch_object($resql);
2530 $this->db->free($resql);
2532 return (
int) $obj->nb;
2547 $this->lines = array();
2549 $sql =
'SELECT ed.rowid, ed.fk_expedition, ed.fk_entrepot, ed.fk_product, ed.fk_parent, ed.fk_unit, ed.description, ed.fk_elementdet, ed.fk_element, ed.element_type, ed.qty, ed.rang';
2550 $sql .=
', p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode';
2551 $sql .=
', p.weight, p.weight_units, p.volume, p.volume_units';
2552 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as ed';
2553 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = ed.fk_product)';
2554 $sql .=
' WHERE ed.fk_expedition = '.((int) $this->
id);
2555 $sql .=
' ORDER BY ed.rang, ed.rowid';
2557 dol_syslog(get_class($this).
"::fetch_lines_free", LOG_DEBUG);
2558 $result = $this->db->query($sql);
2560 $num = $this->db->num_rows($result);
2564 $objp = $this->db->fetch_object($result);
2568 $line->rowid = $objp->rowid;
2569 $line->id = $objp->rowid;
2570 $line->fk_expedition = $this->id;
2571 $line->description = $objp->description;
2572 $line->desc = $objp->description;
2573 $line->qty = $objp->qty;
2574 $line->qty_shipped = $objp->qty;
2575 $line->fk_entrepot = $objp->fk_entrepot;
2576 $line->entrepot_id = $objp->fk_entrepot;
2577 $line->fk_product = $objp->fk_product;
2578 $line->product_type = (int) $objp->fk_product_type;
2579 $line->fk_product_type = $objp->fk_product_type;
2580 $line->product_ref = $objp->product_ref;
2581 $line->product_label = $objp->product_label;
2582 $line->product_barcode = $objp->product_barcode;
2583 $line->weight = $objp->weight;
2584 $line->weight_units = $objp->weight_units;
2585 $line->volume = $objp->volume;
2586 $line->volume_units = $objp->volume_units;
2587 $line->fk_parent = $objp->fk_parent;
2588 $line->rang = $objp->rang;
2589 $line->fk_element = $objp->fk_element;
2590 $line->fk_unit = $objp->fk_unit;
2591 $line->fk_elementdet = $objp->fk_elementdet;
2592 $line->element_type = $objp->element_type;
2593 $line->fetch_optionals();
2595 $this->lines[$i] = $line;
2600 $this->db->free($result);
2604 $this->error = $this->db->error();
2630 if ($this->status == self::STATUS_DRAFT) {
2636 $line->fetch($lineid);
2638 if ($this->
id > 0 && (
int) $line->fk_expedition !== (
int) $this->id) {
2639 $this->db->rollback();
2640 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2644 if ($line->delete($user) > 0) {
2647 $this->db->commit();
2650 $this->db->rollback();
2654 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
2668 global
$conf, $langs;
2670 $langs->load(
'sendings');
2672 $nofetch = !empty($params[
'nofetch']);
2675 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Shipment").
'</u>';
2676 if (isset($this->status)) {
2677 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
2679 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2680 $datas[
'refcustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
2682 $langs->load(
'companies');
2683 if (empty($this->thirdparty)) {
2686 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
2704 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2706 global $langs, $hookmanager, $user;
2711 'objecttype' => $this->element,
2712 'option' => $option,
2715 $classfortooltip =
'classfortooltip';
2718 $classfortooltip =
'classforajaxtooltip';
2719 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2725 $url = DOL_URL_ROOT.
'/expedition/card.php?id='.$this->id;
2731 if ($option !==
'nolink') {
2733 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2734 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2735 $add_save_lastsearch_values = 1;
2737 if ($add_save_lastsearch_values) {
2738 $url .=
'&save_lastsearch_values=1';
2743 if (empty($notooltip)) {
2745 $label = $langs->trans(
"Shipment");
2746 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2748 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2749 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2752 $linkstart =
'<a href="'.$url.
'"';
2753 $linkstart .= $linkclose.
'>';
2756 $result .= $linkstart;
2758 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2760 if ($withpicto != 2) {
2761 $result .= $this->ref;
2763 $result .= $linkend;
2765 if ($addlinktonotes) {
2766 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2769 $result .=
' <span class="note inline-block">';
2770 $result .=
'<a href="'.DOL_URL_ROOT.
'/expedition/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2771 $result .= img_picto(
'',
'note');
2773 $result .=
'</span>';
2778 $hookmanager->initHooks(array($this->element .
'dao'));
2779 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
2780 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2782 $result = $hookmanager->resPrint;
2784 $result .= $hookmanager->resPrint;
2797 return $this->
LibStatut($this->status, $mode);
2813 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
2814 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
2816 $statusType =
'status'.$status;
2817 if ($status == self::STATUS_VALIDATED) {
2818 $statusType =
'status4';
2820 if ($status == self::STATUS_CLOSED) {
2821 $statusType =
'status6';
2823 if ($status == self::STATUS_CANCELED) {
2824 $statusType =
'status9';
2828 $status_label = $this->signed_status ? $labelStatus . $signed_label : $labelStatus;
2829 $status_label_short = $this->signed_status ? $labelStatusShort . $signed_label : $labelStatusShort;
2831 return dolGetStatus($status_label, $status_label_short,
'', $statusType, $mode);
2843 global $langs,
$conf;
2845 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2847 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2848 $return .=
'<div class="info-box info-box-sm">';
2849 $return .=
'<div class="info-box-icon bg-infobox-action">';
2850 $return .= img_picto(
'',
'order');
2851 $return .=
'</div>';
2852 $return .=
'<div class="info-box-content">';
2853 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
2854 if ($selected >= 0) {
2855 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2857 $return .=
'<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2858 $return .=
'<div class="info-box-ref amount">'.price($this->total_ht, 0, $langs, 0, -1, -1,
getDolCurrency()).
' '.$langs->trans(
'HT').
'</div>';
2859 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2860 $return .=
'</div>';
2861 $return .=
'</div>';
2862 $return .=
'</div>';
2880 dol_syslog(get_class($this).
"::initAsSpecimen");
2883 $order->initAsSpecimen();
2887 $this->
ref =
'SPECIMEN';
2888 $this->specimen = 1;
2890 $this->livraison_id = 0;
2892 $this->date_creation = $now;
2893 $this->date_valid = $now;
2894 $this->date_delivery = $now + 24 * 3600;
2895 $this->date_expedition = $now + 24 * 3600;
2897 $this->entrepot_id = 0;
2898 $this->fk_delivery_address = 0;
2901 $this->commande_id = 0;
2902 $this->commande = $order;
2904 $this->origin_id = 1;
2905 $this->origin_type =
'commande';
2907 $this->note_private =
'Private note';
2908 $this->note_public =
'Public note';
2912 while ($xnbp < $nbp) {
2914 $line->product_desc = $langs->trans(
"Description").
" ".$xnbp;
2915 $line->product_label = $langs->trans(
"Description").
" ".$xnbp;
2917 $line->qty_asked = 5;
2918 $line->qty_shipped = 4;
2919 $line->fk_product = $this->commande->lines[$xnbp]->fk_product;
2921 $line->weight = 1.123456;
2922 $line->weight_units = 0;
2924 $line->volume = 2.34567;
2925 $line->volume_unit = 0;
2927 $this->lines[] = $line;
2959 if ($user->hasRight(
'expedition',
'creer')) {
2962 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
2963 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2964 $sql .=
" WHERE rowid = ".((int) $this->
id);
2966 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
2967 $resql = $this->db->query($sql);
2969 $this->date_delivery = $delivery_date;
2973 $result = $this->call_trigger(
'SHIPPING_MODIFY', $user);
2975 $this->db->rollback();
2981 $this->db->commit();
2984 $this->error = $this->db->error();
2985 $this->db->rollback();
3003 if ($user->hasRight(
'expedition',
'creer')) {
3006 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition";
3007 $sql .=
" SET date_expedition = ".($shipping_date ?
"'".$this->db->idate($shipping_date).
"'" :
'null');
3008 $sql .=
" WHERE rowid = ".((int) $this->
id);
3010 dol_syslog(get_class($this).
"::setShippingDate", LOG_DEBUG);
3011 $resql = $this->db->query($sql);
3013 $this->date_shipping = $shipping_date;
3017 $result = $this->call_trigger(
'SHIPPING_MODIFY', $user);
3019 $this->db->rollback();
3025 $this->db->commit();
3028 $this->error = $this->db->error();
3029 $this->db->rollback();
3049 $sql =
"SELECT em.rowid, em.code, em.libelle as label";
3050 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
3051 $sql .=
" WHERE em.active = 1";
3052 $sql .=
" ORDER BY em.libelle ASC";
3054 $resql = $this->db->query($sql);
3056 while ($obj = $this->db->fetch_object($resql)) {
3057 $label = $langs->trans(
'SendingMethod'.$obj->code);
3058 $this->meths[(int) $obj->rowid] = ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label);
3075 $this->listmeths = [];
3078 $sql =
"SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active";
3079 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
3081 $sql .=
" WHERE em.rowid=".((int) $id);
3084 $resql = $this->db->query($sql);
3086 while ($obj = $this->db->fetch_object($resql)) {
3087 $label = $langs->trans(
'SendingMethod'.$obj->code);
3088 $this->listmeths[$i] = [
3089 'rowid' => (int) $obj->rowid,
3090 'code' => $obj->code,
3091 'libelle' => ($label !=
'SendingMethod'.$obj->code ? $label : $obj->label),
3092 'description' => $obj->description,
3093 'tracking' => $obj->tracking,
3094 'active' => (
int) $obj->active,
3110 if (!empty($this->shipping_method_id)) {
3111 $sql =
"SELECT em.code, em.tracking";
3112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as em";
3113 $sql .=
" WHERE em.rowid = ".((int) $this->shipping_method_id);
3115 $resql = $this->db->query($sql);
3117 if ($obj = $this->db->fetch_object($resql)) {
3118 $tracking = (string) $obj->tracking;
3123 if (!empty($tracking) && !empty($value)) {
3124 $url = str_replace(
'{TRACKID}', $value, $tracking);
3125 $this->tracking_url = sprintf(
'<a target="_blank" rel="noopener noreferrer" href="%s">%s</a>', $url, $value);
3127 $this->tracking_url = $value;
3138 global $langs, $user;
3143 if ($this->status == self::STATUS_CLOSED) {
3148 if ($this->status == self::STATUS_DRAFT) {
3149 $this->
valid($user);
3155 if (empty($this->date_shipping)) {
3156 $sql .=
", date_expedition = '".$this->db->escape($this->db->idate(
dol_now())).
"'";
3158 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut > 0";
3159 $sql .=
" AND fk_statut <> ".self::STATUS_CLOSED;
3161 $resql = $this->db->query($sql);
3162 if ($resql && $this->db->affected_rows($resql) <= 0) {
3165 $this->db->rollback();
3166 dol_syslog(get_class($this).
"::setClosed shipment ".$this->
id.
" is not validated, nothing done", LOG_WARNING);
3171 if ($this->origin_type ==
'commande' && $this->origin_id > 0) {
3173 $order->fetch($this->origin_id);
3175 $order->loadExpeditions(self::STATUS_CLOSED);
3177 $shipments_match_order = 1;
3178 foreach ($order->lines as $line) {
3179 $lineid = $line->id;
3181 if (($line->product_type == 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) {
3182 $shipments_match_order = 0;
3183 $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';
3188 if ($shipments_match_order) {
3189 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');
3191 $order->cloture($user, 0, 0);
3209 $result = $this->call_trigger(
'SHIPPING_CLOSED', $user);
3215 dol_print_error($this->db);
3220 $this->db->commit();
3226 $this->db->rollback();
3240 private function manageStockMvtOnEvt($user, $labelmovement =
'ShipmentClassifyClosedInDolibarr', $reverse =
false)
3246 require_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
3248 $langs->load(
"agenda");
3251 $labelmvt = $langs->transnoentitiesnoconv($labelmovement, $this->
ref);
3255 $sql .=
" ed.rowid as edid, ed.fk_product, ed.qty, ed.fk_entrepot";
3256 $sql .=
", cd.rowid as cdid";
3257 $sql .=
", cd.subprice";
3258 $sql .=
", edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
3260 $sql .=
" FROM " . $this->db->prefix() .
"expeditiondet as ed";
3261 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"commandedet as cd ON cd.rowid = ed.fk_elementdet";
3262 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
3263 $sql .=
" INNER JOIN " . $this->db->prefix() .
"expedition as e ON ed.fk_expedition = e.rowid";
3264 $sql .=
" WHERE ed.fk_expedition = " . ((int) $this->
id);
3267 dol_syslog(get_class($this) .
"::valid select details", LOG_DEBUG);
3268 $resql = $this->db->query($sql);
3270 $cpt = $this->db->num_rows($resql);
3271 for ($i = 0; $i < $cpt; $i++) {
3272 $obj = $this->db->fetch_object($resql);
3273 if (empty($obj->edbrowid)) {
3276 $qty = $obj->edbqty;
3278 if ($qty <= 0 || ($qty < 0 && !
getDolGlobalInt(
'SHIPMENT_ALLOW_NEGATIVE_QTY'))) {
3281 dol_syslog(get_class($this) .
"::valid movement index " . $i .
" ed.rowid=" . $obj->edid .
" edb.rowid=" . $obj->edbrowid);
3286 $qtytouse = $reverse ? -$qty : $qty;
3289 $mouvS->origin = &$this;
3290 $mouvS->setOrigin($this->element, $this->
id, $obj->cdid, $obj->edid);
3292 if (empty($obj->edbrowid)) {
3296 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qtytouse, $obj->subprice, $labelmvt);
3307 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qtytouse, $obj->subprice, $labelmvt,
'', $reverse ?
'' : $this->db->jdate($obj->eatby), $reverse ?
'' : $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock);
3317 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".$this->db->prefix().
"product_batch as pb)";
3318 $resqldelete = $this->db->query($sqldelete);
3324 if (!$resqldelete) {
3325 $this->error = $this->db->lasterror();
3326 $this->errors[] = $this->db->lasterror();
3332 $this->error = $this->db->lasterror();
3333 $this->errors[] = $this->db->lasterror();
3356 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET billed = 1';
3357 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > 0';
3359 $resql = $this->db->query($sql);
3364 $result = $this->call_trigger(
'SHIPPING_BILLED', $user);
3371 $this->errors[] = $this->db->lasterror;
3374 if (empty($error)) {
3375 $this->db->commit();
3378 $this->db->rollback();
3395 if ($this->status <= self::STATUS_DRAFT) {
3400 if ($this->status != self::STATUS_VALIDATED) {
3401 $langs->load(
"sendings");
3402 $this->error = $langs->trans(
"StatusOfRefMustBe", $this->
ref, $langs->transnoentitiesnoconv(
"StatusSendingValidatedShort"));
3403 $this->errors[] = $this->error;
3415 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
3417 $langs->load(
"agenda");
3426 $result = $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'SHIPMENT_UNVALIDATE');
3433 $this->db->commit();
3436 $this->db->rollback();
3448 global $langs, $user;
3453 if ($this->status == self::STATUS_VALIDATED) {
3459 $oldbilled = $this->billed;
3461 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'expedition SET fk_statut = 1';
3464 $resql = $this->db->query($sql);
3465 if ($resql && $this->db->affected_rows($resql) <= 0) {
3467 $this->db->rollback();
3468 $langs->load(
"sendings");
3469 $this->error = $langs->trans(
"StatusOfRefMustBe", $this->
ref, $langs->transnoentitiesnoconv(
"StatusSendingProcessedShort"));
3470 $this->errors[] = $this->error;
3480 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
3482 $langs->load(
"agenda");
3487 $sql =
"SELECT ed.fk_product, cd.subprice,";
3488 $sql .=
" ed.rowid, ed.qty, ed.fk_entrepot,";
3489 $sql .=
" edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
3490 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed";
3491 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commandedet as cd ON cd.rowid = ed.fk_elementdet";
3492 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid";
3493 $sql .=
" WHERE ed.fk_expedition = ".((int) $this->
id);
3495 dol_syslog(get_class($this).
"::valid select details", LOG_DEBUG);
3496 $resql = $this->db->query($sql);
3498 $cpt = $this->db->num_rows($resql);
3499 for ($i = 0; $i < $cpt; $i++) {
3500 $obj = $this->db->fetch_object($resql);
3501 if (empty($obj->edbrowid)) {
3504 $qty = $obj->edbqty;
3509 dol_syslog(get_class($this).
"::reopen expedition movement index ".$i.
" ed.rowid=".$obj->rowid.
" edb.rowid=".$obj->edbrowid);
3513 $mouvS->origin = &$this;
3514 $mouvS->setOrigin($this->element, $this->
id);
3516 if (empty($obj->edbrowid)) {
3520 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->transnoentitiesnoconv(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref));
3530 $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->transnoentitiesnoconv(
"ShipmentUnClassifyCloseddInDolibarr", $this->ref),
'',
'',
'', $obj->batch, $obj->fk_origin_stock);
3539 $this->error = $this->db->lasterror();
3546 $result = $this->call_trigger(
'SHIPPING_REOPEN', $user);
3553 $this->errors[] = $this->db->lasterror();
3557 $this->db->commit();
3562 $this->billed = $oldbilled;
3563 $this->db->rollback();
3579 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3581 $outputlangs->load(
"products");
3584 $modele =
'espadon';
3586 if (!empty($this->model_pdf)) {
3587 $modele = $this->model_pdf;
3593 $modelpath =
"core/modules/expedition/doc/";
3597 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_VALIDATED
Validated status.
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
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).
errorsToString()
Method to output saved errors.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product 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.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage receptions.
Class to manage Dolibarr database access.
addline_batch($dbatch, $array_options=[], $origin_line=null)
Add a shipment line with batch record.
create_delivery($user)
Create a delivery receipt from a shipment.
manageStockMvtOnEvt($user, $labelmovement='ShipmentClassifyClosedInDolibarr', $reverse=false)
Manage Stock MVt onb Close or valid Shipment.
setShippingDate($user, $shipping_date, $notrigger=0)
Set the shipping date.
setDraft($user, $notrigger=0)
Set draft status.
const STATUS_SHIPMENT_IN_PROGRESS
Expedition in progress -> package exit the warehouse and is now in the truck or into the hand of the ...
getUrlTrackingStatus($value='')
Forge an set tracking url.
setClosed()
Classify the shipping as closed (this records also the stock movement)
__construct($db)
Constructor.
create_line($entrepot_id, $origin_line_id, $qty, $rang=0, $array_options=[], $parent_line_id=0, $product_id=0)
Create a expedition line.
addline($entrepot_id, $id, $qty, $array_options=[], $fk_product=0, $fk_parent=0)
Add an expedition line.
create($user, $notrigger=0)
Create expedition en base.
LibStatut($status, $mode)
Return label of a status.
checkLineStockRequirements($fk_product, $fk_entrepot, $qty, $product_type=null, $forbid_batch_product=false, $allowEmptyWarehouse=false)
Check stock constraints for a shipment line.
setBilled()
Classify the shipping as invoiced (used for example by trigger when WORKFLOW_SHIPPING_CLASSIFY_BILLED...
updatelinefree($rowid, $qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $notrigger, $array_options=array(), $fk_entrepot=-1)
Update a simple expedition line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
const STATUS_DRAFT
Draft status.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set the planned delivery date.
line_ajaxorder($rows)
Override to keep every expeditiondet row that belongs to the displayed line in sync when drag & drop ...
const STATUS_CANCELED
Canceled status.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0)
Return clickable link of object (with eventually picto)
getLibStatut($mode=0)
Return status label.
set_date_livraison($user, $delivery_date)
Set delivery date.
initAsSpecimen()
Initialise an instance with random values.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
const STATUS_CLOSED
Closed status -> parcel was received by customer / end of process prev status : validated or shipment...
const STATUS_VALIDATED
Validated status -> parcel is ready to be sent prev status : draft next status : closed or shipment_i...
create_line_batch($line_ext, $array_options=[])
Create the detail of the expedition line.
addlinefree($qty, $element_type, $fk_product, $fk_unit, $rang, $description, $fk_parent, $array_options=[], $fk_entrepot=0)
Add a simple expedition line.
valid($user, $notrigger=0)
Validate object and update stock if option enabled.
update($user=null, $notrigger=0)
Update database.
fetch_lines_free()
Load lines of simple shipment.
fetch_delivery_methods()
Fetch deliveries method and return an array.
countStandalone()
Count the standalone shipments (shipments without source object, like a sales order) of the current e...
fetch($id, $ref='', $ref_ext='', $notused='')
Get object and lines from database.
reOpen()
Classify the shipping as validated/opened.
deleteLine($user, $lineid)
Delete detail line.
getLinesArray()
Create an array of shipment lines.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
list_delivery_methods($id=0)
Fetch all deliveries method and return an array.
Class to manage lines of shipment.
CRUD class for batch number management within shipment.
Class to manage stock movements.
Class to manage order lines.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Manage record for batch number management.
Class to manage third parties objects (customers, suppliers, prospects...)
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
$conf db user
Active Directory does not allow anonymous connections.