34 public $element =
'expeditionlignebatch';
44 public $fk_origin_stock;
45 public $fk_expeditiondet;
67 $sql .=
" pl.sellby,";
69 $sql .=
" ps.fk_entrepot";
71 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_batch as pb";
72 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"product_stock as ps on pb.fk_product_stock=ps.rowid";
73 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
"product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product";
74 $sql .=
" WHERE pb.rowid = ".(int) $id_stockdluo;
76 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
82 $obj = $this->
db->fetch_object(
$resql);
84 $this->sellby = $this->
db->jdate($obj->sellby);
85 $this->eatby = $this->
db->jdate($obj->eatby);
86 $this->batch = $obj->batch;
87 $this->entrepot_id = $obj->fk_entrepot;
88 $this->fk_origin_stock = (int) $id_stockdluo;
94 $this->error =
"Error ".$this->db->lasterror();
109 $id_line_expdet = (int) $id_line_expdet;
111 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element.
" (";
112 $sql .=
"fk_expeditiondet";
117 $sql .=
", fk_origin_stock";
118 $sql .=
") VALUES (";
119 $sql .= $id_line_expdet.
",";
120 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' : (
"'".$this->db->idate($this->sellby)).
"'").
",";
121 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' : (
"'".$this->db->idate($this->eatby)).
"'").
",";
122 $sql .=
" ".(!isset($this->batch) ?
'NULL' : (
"'".$this->db->escape($this->batch).
"'")).
",";
123 $sql .=
" ".(!isset($this->qty) ? ((!isset($this->dluo_qty)) ?
'NULL' : $this->dluo_qty) : $this->qty).
",";
124 $sql .=
" ".(!isset($this->fk_origin_stock) ?
'NULL' : $this->fk_origin_stock);
129 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
133 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
134 $this->fk_expeditiondet = $id_line_expdet;
137 foreach ($this->errors as $errmsg)
139 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
140 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
142 $this->
db->rollback();
156 $id_expedition = (int) $id_expedition;
158 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element;
159 $sql .=
" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX.
"expeditiondet WHERE fk_expedition=".$id_expedition.
")";
162 if ($db->query($sql))
178 public static function fetchAll($db, $id_line_expdet, $fk_product = 0)
181 $sql .=
" eb.rowid,";
182 $sql .=
" eb.fk_expeditiondet,";
183 $sql .=
" eb.sellby as oldsellby,";
184 $sql .=
" eb.eatby as oldeatby,";
185 $sql .=
" eb.batch,";
187 $sql .=
" eb.fk_origin_stock";
190 $sql .=
", pl.sellby";
191 $sql .=
", pl.eatby";
193 $sql .=
" FROM ".MAIN_DB_PREFIX.self::$_table_element.
" as eb";
196 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product;
198 $sql .=
" WHERE fk_expeditiondet=".(int) $id_line_expdet;
201 $resql = $db->query($sql);
204 $num = $db->num_rows(
$resql);
209 $tmp =
new self($db);
211 $obj = $db->fetch_object(
$resql);
213 $tmp->sellby = $db->jdate($obj->sellby ? $obj->sellby : $obj->oldsellby);
214 $tmp->eatby = $db->jdate($obj->eatby ? $obj->eatby : $obj->oldeatby);
215 $tmp->batch = $obj->batch;
216 $tmp->id = $obj->rowid;
217 $tmp->fk_origin_stock = $obj->fk_origin_stock;
218 $tmp->fk_expeditiondet = $obj->fk_expeditiondet;
219 $tmp->dluo_qty = $obj->qty;
220 $tmp->qty = $obj->qty;
CRUD class for batch number management within shipment.
static $_table_element
Name of table without prefix where object is stored.
create($id_line_expdet)
Create an expeditiondet_batch DB record link to an expedtiondet record.
static fetchAll($db, $id_line_expdet, $fk_product=0)
Retrieve all batch number detailed information of a shipment line.
$conf db
API class for accounts.
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.
__construct($db)
Constructor.
fetchFromStock($id_stockdluo)
Fill object based on a product-warehouse-batch's record.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
static deletefromexp($db, $id_expedition)
Delete batch record attach to a shipment.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)