34 public $element =
'expeditionlignebatch';
39 public $table_element =
'expeditiondet_batch';
47 public $fk_origin_stock;
49 public $fk_expeditiondet;
72 $sql .=
" pl.sellby,";
74 $sql .=
" ps.fk_entrepot";
76 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
77 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"product_stock as ps on pb.fk_product_stock=ps.rowid";
78 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
"product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product";
79 $sql .=
" WHERE pb.rowid = ".(int) $id_stockdluo;
81 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
83 $resql = $this->db->query($sql);
85 if ($this->db->num_rows($resql)) {
86 $obj = $this->db->fetch_object($resql);
88 $this->sellby = $this->db->jdate($obj->sellby);
89 $this->eatby = $this->db->jdate($obj->eatby);
90 $this->batch = $obj->batch;
91 $this->entrepot_id = $obj->fk_entrepot;
92 $this->fk_origin_stock = (int) $id_stockdluo;
94 $this->db->free($resql);
98 $this->error =
"Error ".$this->db->lasterror();
111 public function create($id_line_expdet, $f_user =
null, $notrigger = 0)
116 if (!is_object($f_user)) $f_user = $user;
118 $id_line_expdet = (int) $id_line_expdet;
120 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
121 $sql .=
"fk_expeditiondet";
126 $sql .=
", fk_origin_stock";
128 $sql .=
") VALUES (";
129 $sql .= $id_line_expdet.
",";
130 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' : (
"'".$this->db->idate($this->sellby)).
"'").
",";
131 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' : (
"'".$this->db->idate($this->eatby)).
"'").
",";
132 $sql .=
" ".(!isset($this->batch) ?
'NULL' : (
"'".$this->db->escape($this->batch).
"'")).
",";
133 $sql .=
" ".(!isset($this->qty) ? ((!isset($this->dluo_qty)) ?
'NULL' : $this->dluo_qty) : $this->qty).
",";
134 $sql .=
" ".(!isset($this->fk_origin_stock) ?
'NULL' : $this->fk_origin_stock);
138 $resql = $this->db->query($sql);
140 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
144 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
146 $this->fk_expeditiondet = $id_line_expdet;
149 if (!$error && !$notrigger) {
151 $result = $this->
call_trigger(
'EXPEDITIONLINEBATCH_CREATE', $f_user);
161 foreach ($this->errors as $errmsg) {
162 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
163 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
177 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
178 $sql .=
" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX.
"expeditiondet WHERE fk_expedition=".((int) $id_expedition).
")";
181 if ($this->db->query($sql)) {
195 public function fetchAll($id_line_expdet, $fk_product = 0)
198 $sql .=
" eb.rowid,";
199 $sql .=
" eb.fk_expeditiondet,";
200 $sql .=
" eb.sellby as oldsellby,";
201 $sql .=
" eb.eatby as oldeatby,";
202 $sql .=
" eb.batch,";
204 $sql .=
" eb.fk_origin_stock";
205 if ($fk_product > 0) {
206 $sql .=
", pl.sellby";
207 $sql .=
", pl.eatby";
209 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as eb";
210 if ($fk_product > 0) {
211 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".((int) $fk_product);
213 $sql .=
" WHERE fk_expeditiondet=".(int) $id_line_expdet;
216 $resql = $this->db->query($sql);
218 $num = $this->db->num_rows($resql);
222 $obj = $this->db->fetch_object($resql);
224 $tmp =
new self($this->db);
225 $tmp->sellby = $this->db->jdate($obj->sellby ? $obj->sellby : $obj->oldsellby);
226 $tmp->eatby = $this->db->jdate($obj->eatby ? $obj->eatby : $obj->oldeatby);
227 $tmp->batch = $obj->batch;
228 $tmp->id = $obj->rowid;
229 $tmp->fk_origin_stock = $obj->fk_origin_stock;
230 $tmp->fk_expeditiondet = $obj->fk_expeditiondet;
231 $tmp->dluo_qty = $obj->qty;
232 $tmp->qty = $obj->qty;
238 $this->db->free($resql);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
CRUD class for batch number management within shipment.
__construct($db)
Constructor.
fetchFromStock($id_stockdluo)
Fill object based on a product-warehouse-batch's record.
deleteFromShipment($id_expedition)
Delete batch record attach to a shipment.
create($id_line_expdet, $f_user=null, $notrigger=0)
Create an expeditiondet_batch DB record link to an expedtiondet record.
fetchAll($id_line_expdet, $fk_product=0)
Retrieve all batch number detailed information of a shipment line.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.