32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/commonincoterm.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
54 public $element =
"delivery";
60 public $TRIGGER_PREFIX =
'DELIVERY';
65 public $fk_element =
"fk_delivery";
70 public $table_element =
"delivery";
75 public $table_element_line =
"deliverydet";
80 public $picto =
'sending';
100 public $date_delivery;
120 public $lines = array();
125 public $user_author_id;
128 const STATUS_DRAFT = 0;
129 const STATUS_VALIDATED = 1;
130 const STATUS_CANCELED = -1;
143 $this->labelStatus[-1] =
'StatusDeliveryCanceled';
144 $this->labelStatus[0] =
'StatusDeliveryDraft';
145 $this->labelStatus[1] =
'StatusDeliveryValidated';
160 if (empty($this->model_pdf)) {
166 $this->ref_customer = trim((
string) $this->ref_customer);
175 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"delivery (";
179 $sql .=
", ref_customer";
180 $sql .=
", date_creation";
181 $sql .=
", fk_user_author";
182 $sql .=
", date_delivery";
183 $sql .=
", fk_address";
184 $sql .=
", note_private";
185 $sql .=
", note_public";
186 $sql .=
", model_pdf";
187 $sql .=
", fk_incoterms, location_incoterms";
188 $sql .=
") VALUES (";
190 $sql .=
", ".((int)
$conf->entity);
191 $sql .=
", ".((int) $this->socid);
192 $sql .=
", '".$this->db->escape($this->ref_customer).
"'";
193 $sql .=
", '".$this->db->idate($now).
"'";
194 $sql .=
", ".((int) $user->id);
195 $sql .=
", ".($this->date_delivery ?
"'".$this->db->idate($this->date_delivery).
"'" :
"null");
196 $sql .=
", ".($this->fk_delivery_address > 0 ? ((int) $this->fk_delivery_address) :
"null");
197 $sql .=
", ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
198 $sql .=
", ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
199 $sql .=
", ".(!empty($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
200 $sql .=
", ".(int) $this->fk_incoterms;
201 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
206 $resql = $this->db->query($sql);
208 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"delivery");
210 $numref =
"(PROV".$this->id.
")";
212 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"delivery ";
213 $sql .=
"SET ref = '".$this->db->escape($numref).
"'";
214 $sql .=
" WHERE rowid = ".((int) $this->
id);
217 $resql = $this->db->query($sql);
220 $commande =
new Commande($this->db);
221 $commande->id = $this->commande_id;
222 $commande->fetch_lines();
229 $num = count($this->lines);
230 for ($i = 0; $i < $num; $i++) {
231 $origin_id = $this->lines[$i]->origin_line_id;
233 $origin_id = $this->lines[$i]->commande_ligne_id;
236 if (!$this->
create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->
description, $this->lines[$i]->array_options)) {
241 if (!$error && $this->
id && $this->origin_id) {
248 $ret = $this->
setStatut(2, $this->origin_id, $this->origin);
257 $result = $this->call_trigger(
'DELIVERY_CREATE', $user);
269 $this->error = $this->db->lasterror().
" - sql=".$this->db->lastqueryerror;
270 $this->db->rollback();
275 $this->error = $this->db->lasterror().
" - sql=".$this->db->lastqueryerror;
276 $this->db->rollback();
281 $this->error = $this->db->lasterror().
" - sql=".$this->db->lastqueryerror;
282 $this->db->rollback();
298 public function create_line($origin_id, $qty, $fk_product, $description, $array_options = [])
303 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"deliverydet (fk_delivery, fk_origin_line,";
304 $sql .=
" fk_product, description, qty)";
305 $sql .=
" VALUES (".((int) $this->
id).
",".((int) $origin_id).
",";
306 $sql .=
" ".($fk_product > 0 ? ((int) $fk_product) :
"null").
",";
307 $sql .=
" ".($description ?
"'".$this->db->escape($description).
"'" :
"null").
",";
310 dol_syslog(get_class($this).
"::create_line", LOG_DEBUG);
311 if (!$this->db->query($sql)) {
315 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"deliverydet");
317 if (is_array($array_options) && count($array_options) > 0) {
320 $line->array_options = $array_options;
321 $result = $line->insertExtraFields();
339 $sql =
"SELECT l.rowid, l.fk_soc, l.date_creation, l.date_valid, l.ref, l.ref_customer, l.fk_user_author,";
340 $sql .=
" l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public";
341 $sql .=
", l.date_delivery, l.fk_address, l.model_pdf";
342 $sql .=
", el.fk_source as origin_id, el.sourcetype as origin";
343 $sql .=
', l.fk_incoterms, l.location_incoterms';
344 $sql .=
", i.libelle as label_incoterms";
345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"delivery as l";
346 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element).
"'";
347 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON l.fk_incoterms = i.rowid';
348 $sql .=
" WHERE l.rowid = ".((int) $id);
350 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
351 $result = $this->db->query($sql);
353 if ($this->db->num_rows($result)) {
354 $obj = $this->db->fetch_object($result);
356 $this->
id = $obj->rowid;
357 $this->date_delivery = $this->db->jdate($obj->date_delivery);
358 $this->date_creation = $this->db->jdate($obj->date_creation);
359 $this->date_valid = $this->db->jdate($obj->date_valid);
360 $this->
ref = $obj->ref;
361 $this->ref_customer = $obj->ref_customer;
362 $this->socid = $obj->fk_soc;
363 $this->statut = $obj->fk_statut;
364 $this->
status = $obj->fk_statut;
365 $this->user_author_id = $obj->fk_user_author;
366 $this->user_validation_id = $obj->fk_user_valid;
367 $this->fk_delivery_address = $obj->fk_address;
368 $this->note = $obj->note_private;
369 $this->note_private = $obj->note_private;
370 $this->note_public = $obj->note_public;
371 $this->model_pdf = $obj->model_pdf;
372 $this->origin = $obj->origin;
373 $this->origin_type = $obj->origin;
374 $this->origin_id = $obj->origin_id;
377 $this->fk_incoterms = $obj->fk_incoterms;
378 $this->location_incoterms = $obj->location_incoterms;
379 $this->label_incoterms = $obj->label_incoterms;
380 $this->db->free($result);
398 $this->error =
'Delivery with id '.$id.
' not found sql='.$sql;
399 dol_syslog(get_class($this).
'::fetch Error '.$this->error, LOG_ERR);
403 $this->error = $this->db->error();
415 public function valid($user, $notrigger = 0)
419 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
423 if (!isset($this->socid)) {
424 dol_syslog(get_class($this).
"::can't valid socid not set", LOG_WARNING);
432 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'delivery',
'creer'))
433 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expedition',
'delivery_advance',
'validate'))) {
438 if (is_readable(DOL_DOCUMENT_ROOT.
'/core/modules/delivery/'.$modName.
'.php')) {
439 require_once DOL_DOCUMENT_ROOT.
'/core/modules/delivery/'.$modName.
'.php';
444 $objMod =
new $modName($this->db);
445 '@phan-var-force ModeleNumRefDeliveryOrder $objMod';
448 $soc->fetch($this->socid);
450 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
451 $numref = $objMod->getNextValue($soc, $this);
453 $numref = (string) $this->
ref;
459 $sql .=
" FROM ".MAIN_DB_PREFIX.
"delivery";
460 $sql .=
" WHERE ref = '".$this->db->escape($numref).
"'";
461 $sql .=
" AND fk_statut <> 0";
462 $sql .=
" AND entity = ".((int)
$conf->entity);
464 $resql = $this->db->query($sql);
466 $num = $this->db->num_rows($resql);
472 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"delivery SET";
473 $sql .=
" ref = '".$this->db->escape($numref).
"'";
474 $sql .=
", fk_statut = 1";
475 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
476 if (!empty($this->date_delivery)) {
477 $sql .=
", date_delivery = '".$this->db->idate($this->date_delivery).
"'";
479 $sql .=
", fk_user_valid = ".((int) $user->id);
480 $sql .=
" WHERE rowid = ".((int) $this->
id);
481 $sql .=
" AND fk_statut = 0";
483 $resql = $this->db->query($sql);
485 dol_print_error($this->db);
486 $this->error = $this->db->lasterror();
490 if (!$error && !$notrigger) {
492 $result = $this->call_trigger(
'DELIVERY_VALIDATE', $user);
500 $this->oldref = $this->ref;
503 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
505 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'expedition/receipt/".$this->db->escape($this->newref).
"'";
506 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expedition/receipt/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
507 $resql = $this->db->query($sql);
510 $this->error = $this->db->lasterror();
512 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expedition/receipt/".$this->db->escape($this->newref).
"'";
513 $sql .=
" WHERE filepath = 'expedition/receipt/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
514 $resql = $this->db->query($sql);
517 $this->error = $this->db->lasterror();
523 $dirsource =
$conf->expedition->dir_output.
'/receipt/'.$oldref;
524 $dirdest =
$conf->expedition->dir_output.
'/receipt/'.$newref;
525 if (!$error && file_exists($dirsource)) {
526 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
528 if (@rename($dirsource, $dirdest)) {
531 $listoffiles =
dol_dir_list(
$conf->expedition->dir_output.
'/receipt/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
532 foreach ($listoffiles as $fileentry) {
533 $dirsource = $fileentry[
'name'];
534 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
535 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
536 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
537 @rename($dirsource, $dirdest);
545 $this->
ref = $numref;
556 $this->db->rollback();
564 $this->error =
"NotAllowed";
565 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
584 $result = $expedition->fetch($sending_id);
589 $this->lines = array();
591 $num = count($expedition->lines);
592 for ($i = 0; $i < $num; $i++) {
594 $line->origin_line_id = $expedition->lines[$i]->origin_line_id;
595 $line->label = $expedition->lines[$i]->label;
596 $line->description = $expedition->lines[$i]->description;
597 $line->qty = $expedition->lines[$i]->qty_shipped;
598 $line->fk_product = $expedition->lines[$i]->fk_product;
599 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($expedition->lines[$i]->array_options) && count($expedition->lines[$i]->array_options) > 0) {
600 $line->array_options = $expedition->lines[$i]->array_options;
602 $this->lines[$i] = $line;
605 $this->origin = $expedition->element;
606 $this->origin_id = $expedition->id;
607 $this->note_private = $expedition->note_private;
608 $this->note_public = $expedition->note_public;
609 $this->fk_project = $expedition->fk_project;
610 $this->date_delivery =
'';
611 $this->fk_delivery_address = $expedition->fk_delivery_address;
612 $this->socid = $expedition->socid;
613 $this->ref_customer = $expedition->ref_customer;
616 $this->fk_incoterms = $expedition->fk_incoterms;
617 $this->location_incoterms = $expedition->location_incoterms;
619 return $this->
create($user);
636 if ($id > 0 && !$error && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
638 $line->array_options = $array_options;
640 $result = $line->insertExtraFields();
643 $this->errors[] = $line->error;
664 public function addline($origin_id, $qty, $array_options = [])
666 $num = count($this->lines);
669 $line->origin_id = $origin_id;
671 if (!
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) {
672 $line->array_options = $array_options;
674 $this->lines[$num] = $line;
686 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commandedet";
687 $sql .=
" WHERE rowid = ".((int) $lineid);
689 if ($this->db->query($sql)) {
707 public function delete($user =
null)
709 global
$conf, $langs;
711 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
717 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"deliverydet";
718 $sql .=
" WHERE fk_delivery = ".((int) $this->
id);
719 if ($this->db->query($sql)) {
727 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"delivery";
728 $sql .=
" WHERE rowid = ".((int) $this->
id);
729 if ($this->db->query($sql)) {
734 if (!empty(
$conf->expedition->dir_output)) {
735 $dir =
$conf->expedition->dir_output.
'/receipt/'.$ref;
736 $file = $dir.
'/'.$ref.
'.pdf';
737 if (file_exists($file)) {
742 if (file_exists($dir)) {
744 $this->error = $langs->trans(
"ErrorCanNotDeleteDir", $dir);
751 $result = $this->call_trigger(
'DELIVERY_DELETE', $user);
753 $this->db->rollback();
760 $this->error = $this->db->lasterror().
" - sql=$sql";
761 $this->db->rollback();
765 $this->error = $this->db->lasterror().
" - sql=$sql";
766 $this->db->rollback();
770 $this->error = $this->db->lasterror().
" - sql=$sql";
771 $this->db->rollback();
786 $langs->load(
'sendings');
790 $datas[
'picto'] = img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly').
' <u>'.$langs->trans(
"ShowReceiving").
'</u>:<br>';
791 $datas[
'ref'] =
'<b>'.$langs->trans(
"Ref").
'</b>: '.$this->ref;
803 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1)
805 global $langs, $hookmanager;
811 'objecttype' => $this->element,
813 $classfortooltip =
'classfortooltip';
816 $classfortooltip =
'classforajaxtooltip';
817 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
823 $url = DOL_URL_ROOT.
'/delivery/card.php?id='.$this->id;
828 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
829 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
830 $add_save_lastsearch_values = 1;
832 if ($add_save_lastsearch_values) {
833 $url .=
'&save_lastsearch_values=1';
837 $linkstart =
'<a href="'.$url.
'"';
838 $linkstart .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
839 $linkstart .= $dataparams.
' class="'.$classfortooltip.
'">';
843 $result .= ($linkstart.img_object($label, $this->picto, $dataparams.
' class="'.$classfortooltip.
'"').$linkend);
845 if ($withpicto && $withpicto != 2) {
848 $result .= $linkstart.$this->ref.$linkend;
851 $hookmanager->initHooks(array($this->element .
'dao'));
852 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
853 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
855 $result = $hookmanager->resPrint;
857 $result .= $hookmanager->resPrint;
871 $this->lines = array();
873 $sql =
"SELECT ld.rowid, ld.fk_product, ld.description, ld.subprice, ld.total_ht, ld.qty as qty_shipped, ld.fk_origin_line, ld.extraparams,";
874 $sql .=
" cd.qty as qty_asked, cd.label as custom_label, cd.fk_unit,";
875 $sql .=
" p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc,";
876 $sql .=
" p.weight, p.weight_units, p.width, p.width_units, p.length, p.length_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch";
877 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"deliverydet as ld";
878 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p on p.rowid = ld.fk_product";
879 $sql .=
" WHERE ld.fk_origin_line = cd.rowid";
880 $sql .=
" AND ld.fk_delivery = ".((int) $this->
id);
882 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
883 $resql = $this->db->query($sql);
885 $num = $this->db->num_rows($resql);
888 $obj = $this->db->fetch_object($resql);
892 $line->id = $obj->rowid;
893 $line->label = $obj->custom_label;
894 $line->description = $obj->description;
895 $line->fk_product = $obj->fk_product;
896 $line->qty_asked = $obj->qty_asked;
897 $line->qty_shipped = $obj->qty_shipped;
899 $line->product_label = $obj->product_label;
900 $line->product_ref = $obj->product_ref;
901 $line->product_desc = $obj->product_desc;
902 $line->product_type = $obj->fk_product_type;
904 $line->fk_origin_line = $obj->fk_origin_line;
906 $line->price = $obj->subprice;
907 $line->total_ht = $obj->total_ht;
910 $line->weight = $obj->weight;
911 $line->weight_units = $obj->weight_units;
912 $line->width = $obj->width;
913 $line->width_units = $obj->width_units;
914 $line->height = $obj->height;
915 $line->height_units = $obj->height_units;
916 $line->length = $obj->length;
917 $line->length_units = $obj->length_units;
918 $line->surface = $obj->surface;
919 $line->surface_units = $obj->surface_units;
920 $line->volume = $obj->volume;
921 $line->volume_units = $obj->volume_units;
923 $line->fk_unit = $obj->fk_unit;
924 $line->fetch_optionals();
926 $line->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
928 $this->lines[$i] = $line;
932 $this->db->free($resql);
965 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
968 $this->labelStatus[-1] = $langs->transnoentitiesnoconv(
'StatusDeliveryCanceled');
969 $this->labelStatus[0] = $langs->transnoentitiesnoconv(
'StatusDeliveryDraft');
970 $this->labelStatus[1] = $langs->transnoentitiesnoconv(
'StatusDeliveryValidated');
971 $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv(
'StatusDeliveryCanceled');
972 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv(
'StatusDeliveryDraft');
973 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv(
'StatusDeliveryValidated');
976 $statusType =
'status0';
978 $statusType =
'status5';
981 $statusType =
'status4';
984 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1002 $sql =
"SELECT rowid";
1003 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
1004 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1005 $sql .=
" AND tosell = 1";
1006 $sql .= $this->db->plimit(100);
1008 $resql = $this->db->query($sql);
1010 $num_prods = $this->db->num_rows($resql);
1012 while ($i < $num_prods) {
1014 $row = $this->db->fetch_row($resql);
1015 $prodids[$i] = $row[0];
1021 $this->
ref =
'SPECIMEN';
1022 $this->specimen = 1;
1024 $this->date_delivery = $now;
1025 $this->note_public =
'Public note';
1026 $this->note_private =
'Private note';
1030 $line->fk_product = reset($prodids);
1031 $line->qty_asked = 10;
1032 $line->qty_shipped = 9;
1033 $line->product_ref =
'REFPROD';
1034 $line->label =
'Specimen';
1035 $line->description =
'Description';
1037 $line->total_ht = 100;
1039 $this->lines[$i] = $line;
1056 $sqlSourceLine =
"SELECT st.rowid, st.description, st.qty";
1057 $sqlSourceLine .=
", p.ref, p.label";
1058 $sqlSourceLine .=
" FROM ".MAIN_DB_PREFIX.$this->db->sanitize($this->linkedObjectsIds[0][
'type']).
"det as st";
1059 $sqlSourceLine .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON st.fk_product = p.rowid";
1060 $sqlSourceLine .=
" WHERE fk_".$this->db->sanitize($this->linked_objects[0][
'type']).
" = ".((int) $this->linked_objects[0][
'linkid']);
1062 $resultSourceLine = $this->db->query($sqlSourceLine);
1063 if ($resultSourceLine) {
1064 $num_lines = $this->db->num_rows($resultSourceLine);
1067 while ($i < $num_lines) {
1068 $objSourceLine = $this->db->fetch_object($resultSourceLine);
1071 $sql =
"SELECT ld.fk_origin_line, sum(ld.qty) as qty";
1072 $sql .=
" FROM ".MAIN_DB_PREFIX.
"deliverydet as ld, ".MAIN_DB_PREFIX.
"delivery as l,";
1073 $sql .=
" ".MAIN_DB_PREFIX.$this->db->sanitize($this->linked_objects[0][
'type']).
" as c";
1074 $sql .=
", ".MAIN_DB_PREFIX.$this->db->sanitize($this->linked_objects[0][
'type']).
"det as cd";
1075 $sql .=
" WHERE ld.fk_delivery = l.rowid";
1076 $sql .=
" AND ld.fk_origin_line = cd.rowid";
1077 $sql .=
" AND cd.fk_".$this->db->sanitize($this->linked_objects[0][
'type']).
" = c.rowid";
1078 $sql .=
" AND cd.fk_".$this->db->sanitize($this->linked_objects[0][
'type']).
" = ".((int) $this->linked_objects[0][
'linkid']);
1079 $sql .=
" AND ld.fk_origin_line = ".((int) $objSourceLine->rowid);
1080 $sql .=
" GROUP BY ld.fk_origin_line";
1082 $result = $this->db->query($sql);
1083 $row = $this->db->fetch_row($result);
1085 if ($objSourceLine->qty - $row[1] > 0) {
1086 if ($row[0] == $objSourceLine->rowid) {
1087 $array[$i][
'qty'] = $objSourceLine->qty - $row[1];
1089 $array[$i][
'qty'] = $objSourceLine->qty;
1092 $array[$i][
'ref'] = $objSourceLine->ref;
1093 $array[$i][
'label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
1094 } elseif ($objSourceLine->qty - $row[1] < 0) {
1095 $array[$i][
'qty'] = $objSourceLine->qty - $row[1].
" Erreur livraison !";
1096 $array[$i][
'ref'] = $objSourceLine->ref;
1097 $array[$i][
'label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
1104 $this->error = $this->db->error().
" - sql=$sqlSourceLine";
1118 if ($user->hasRight(
'expedition',
'creer')) {
1119 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"delivery";
1120 $sql .=
" SET date_delivery = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1121 $sql .=
" WHERE rowid = ".((int) $this->
id);
1123 dol_syslog(get_class($this).
"::setDeliveryDate", LOG_DEBUG);
1124 $resql = $this->db->query($sql);
1126 $this->date_delivery = $delivery_date;
1129 $this->error = $this->db->error();
1147 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1151 $langs->load(
"sendings");
1152 $outputlangs->load(
"products");
1157 if ($this->model_pdf) {
1158 $modele = $this->model_pdf;
1164 $modelpath =
"core/modules/delivery/doc/";
1166 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1218 public $element =
'deliverydet';
1223 public $table_element =
'deliverydet';
1233 public $description;
1262 public $qty_shipped;
1271 public $product_desc;
1275 public $product_type;
1279 public $product_ref;
1283 public $product_label;
1293 public $fk_origin_line;
1302 public $origin_line_id;
1309 public $commande_ligne_id;
Class to manage customers orders.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
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.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage receptions.
create_line($origin_id, $qty, $fk_product, $description, $array_options=[])
Create a line.
__construct($db)
Constructor.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
deleteLine($lineid)
Delete line.
setDeliveryDate($user, $delivery_date)
Set the planned delivery date.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
update_line($id, $array_options=[])
Update a livraison line (only extrafields)
addline($origin_id, $qty, $array_options=[])
Add line.
fetch($id)
Load a delivery receipt.
create($user)
Create delivery receipt in database.
initAsSpecimen()
Initialise an instance with random values.
create_from_sending($user, $sending_id)
Creating the delivery slip from an existing shipment.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getTooltipContentArray($params)
getTooltipContentArray
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode)
Return the label of a given status.
fetch_lines()
Load lines insto $this->lines.
getRemainingDelivered()
Get data list of Products remaining to be delivered for an order (with qty)
getNomUrl($withpicto=0, $save_lastsearch_value=-1)
Return clickable name (with picto eventually)
Management class of delivery note lines.
__construct($db)
Constructor.
Class to manage Dolibarr database access.
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...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db user
Active Directory does not allow anonymous connections.