34 public $element =
'expeditionlignebatch';
39 public $table_element =
'expeditiondet_batch';
51 public $fk_origin_stock;
53 public $fk_expeditiondet;
76 $sql .=
" pl.sellby,";
78 $sql .=
" ps.fk_entrepot";
79 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
80 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"product_stock as ps on pb.fk_product_stock=ps.rowid";
81 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
"product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product";
82 $sql .=
" WHERE pb.rowid = ".(int) $id_stockdluo;
84 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
86 $resql = $this->db->query($sql);
88 if ($this->db->num_rows($resql)) {
89 $obj = $this->db->fetch_object($resql);
91 $this->sellby = $this->db->jdate($obj->sellby);
92 $this->eatby = $this->db->jdate($obj->eatby);
93 $this->batch = $obj->batch;
94 $this->entrepot_id = $obj->fk_entrepot;
95 $this->fk_origin_stock = (int) $id_stockdluo;
97 $this->db->free($resql);
101 $this->error =
"Error ".$this->db->lasterror();
114 public function create($id_line_expdet, $f_user =
null, $notrigger = 0)
119 if (!is_object($f_user)) {
123 $id_line_expdet = (int) $id_line_expdet;
125 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
126 $sql .=
"fk_expeditiondet";
131 $sql .=
", fk_origin_stock";
132 $sql .=
", fk_warehouse";
133 $sql .=
") VALUES (";
134 $sql .= $id_line_expdet;
135 $sql .=
", ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' : (
"'".$this->db->idate($this->sellby)).
"'");
136 $sql .=
", ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' : (
"'".$this->db->idate($this->eatby)).
"'");
137 $sql .=
", ".(!isset($this->batch) ?
'NULL' : (
"'".$this->db->escape($this->batch).
"'"));
138 $sql .=
", ".(!isset($this->qty) ? ((!isset($this->dluo_qty)) ?
'NULL' : $this->dluo_qty) : $this->qty);
139 $sql .=
", ".(!isset($this->fk_origin_stock) ?
'NULL' : $this->fk_origin_stock);
140 $sql .=
", ".(!isset($this->fk_warehouse) ?
'NULL' : $this->fk_warehouse);
144 $resql = $this->db->query($sql);
147 $this->errors[] =
"Error ".$this->db->lasterror();
151 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
153 $this->fk_expeditiondet = $id_line_expdet;
156 if (!$error && !$notrigger) {
158 $result = $this->
call_trigger(
'EXPEDITIONLINEBATCH_CREATE', $f_user);
168 foreach ($this->errors as $errmsg) {
169 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
170 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
184 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
185 $sql .=
" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX.
"expeditiondet WHERE fk_expedition=".((int) $id_expedition).
")";
188 if ($this->db->query($sql)) {
202 public function fetchAll($id_line_expdet, $fk_product = 0)
205 $sql .=
" eb.rowid,";
206 $sql .=
" eb.fk_expeditiondet,";
207 $sql .=
" eb.sellby as oldsellby,";
208 $sql .=
" eb.eatby as oldeatby,";
209 $sql .=
" eb.batch,";
211 $sql .=
" eb.fk_origin_stock,";
212 $sql .=
" eb.fk_warehouse";
213 if ($fk_product > 0) {
214 $sql .=
", pl.sellby";
215 $sql .=
", pl.eatby";
217 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as eb";
218 if ($fk_product > 0) {
219 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".((int) $fk_product);
221 $sql .=
" WHERE fk_expeditiondet=".(int) $id_line_expdet;
224 $resql = $this->db->query($sql);
226 $num = $this->db->num_rows($resql);
230 $obj = $this->db->fetch_object($resql);
232 $tmp =
new self($this->db);
233 $tmp->sellby = $this->db->jdate(($fk_product > 0 && $obj->sellby) ? $obj->sellby : $obj->oldsellby);
234 $tmp->eatby = $this->db->jdate(($fk_product > 0 && $obj->eatby) ? $obj->eatby : $obj->oldeatby);
235 $tmp->batch = $obj->batch;
236 $tmp->id = $obj->rowid;
237 $tmp->fk_origin_stock = $obj->fk_origin_stock;
238 $tmp->fk_expeditiondet = $obj->fk_expeditiondet;
239 $tmp->fk_warehouse = $obj->fk_warehouse;
240 $tmp->dluo_qty = $obj->qty;
241 $tmp->qty = $obj->qty;
247 $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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.