29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'productlot';
46 public $table_element =
'product_lot';
51 public $picto =
'lot';
57 public $ismultientitymanaged = 1;
88 public $fields = array(
89 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'noteditable'=>1,
'notnull'=> 1,
'index'=>1,
'position'=>1,
'comment'=>
'Id',
'css'=>
'left'),
90 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>15,
'notnull'=>1,
'index'=>1,
'searchall'=>1),
91 'batch' => array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>1,
'notnull'=>0,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'comment'=>
'Batch',
'searchall'=>1),
92 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'notnull'=>1,
'index'=>1,
'position'=>20),
93 'sellby' => array(
'type'=>
'date',
'label'=>
'SellByDate',
'enabled'=>
'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0',
'visible'=>5,
'position'=>60),
94 'eatby' => array(
'type'=>
'date',
'label'=>
'EatByDate',
'enabled'=>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible'=>5,
'position'=>62),
95 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>500),
96 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
97 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>510,
'foreignkey'=>
'llx_user.rowid'),
98 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511)
120 public $fk_user_creat;
125 public $fk_user_modif;
157 if (isset($this->entity)) {
158 $this->entity = (int) $this->entity;
160 if (isset($this->fk_product)) {
161 $this->fk_product = (int) $this->fk_product;
163 if (isset($this->batch)) {
164 $this->batch = trim($this->batch);
166 if (isset($this->fk_user_creat)) {
167 $this->fk_user_creat = (int) $this->fk_user_creat;
169 if (isset($this->fk_user_modif)) {
170 $this->fk_user_modif = (int) $this->fk_user_modif;
172 if (isset($this->import_key)) {
173 $this->import_key = trim($this->import_key);
182 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
184 $sql .=
'fk_product,';
189 $sql .=
'fk_user_creat,';
190 $sql .=
'fk_user_modif,';
191 $sql .=
'import_key';
192 $sql .=
') VALUES (';
193 $sql .=
' '.(!isset($this->entity) ? $conf->entity : $this->entity).
',';
194 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
195 $sql .=
' '.(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
',';
196 $sql .=
' '.(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
',';
197 $sql .=
' '.(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
',';
198 $sql .=
' '.
"'".$this->
db->idate(
dol_now()).
"'".
',';
199 $sql .=
' '.(!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat).
',';
200 $sql .=
' '.(!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif).
',';
201 $sql .=
' '.(!isset($this->import_key) ?
'NULL' : $this->import_key);
209 $this->errors[] =
'Error '.$this->db->lasterror();
210 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
214 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
226 if (!$error && !$notrigger) {
231 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
232 if ($result < 0) $error++;
239 $this->
db->rollback();
258 public function fetch($id = 0, $product_id = 0, $batch =
'')
265 $sql .=
" t.entity,";
266 $sql .=
" t.fk_product,";
269 $sql .=
" t.sellby,";
272 $sql .=
" t.fk_user_creat,";
273 $sql .=
" t.fk_user_modif,";
274 $sql .=
" t.import_key";
275 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
276 if ($product_id > 0 && $batch !=
'') {
277 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".$product_id;
279 $sql .=
' WHERE t.rowid = '.$id;
284 $numrows = $this->
db->num_rows(
$resql);
286 $obj = $this->
db->fetch_object(
$resql);
288 $this->
id = $obj->rowid;
289 $this->ref = $obj->rowid;
292 $this->batch = $obj->batch;
293 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity);
294 $this->fk_product = $obj->fk_product;
295 $this->eatby = $this->
db->jdate($obj->eatby);
296 $this->sellby = $this->
db->jdate($obj->sellby);
297 $this->datec = $this->
db->jdate($obj->datec);
298 $this->tms = $this->
db->jdate($obj->tms);
299 $this->fk_user_creat = $obj->fk_user_creat;
300 $this->fk_user_modif = $obj->fk_user_modif;
301 $this->import_key = $obj->import_key;
315 $this->errors[] =
'Error '.$this->db->lasterror();
316 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
338 if (isset($this->entity)) {
339 $this->entity = (int) $this->entity;
341 if (isset($this->fk_product)) {
342 $this->fk_product = (int) $this->fk_product;
344 if (isset($this->batch)) {
345 $this->batch = trim($this->batch);
347 if (isset($this->fk_user_creat)) {
348 $this->fk_user_creat = (int) $this->fk_user_creat;
350 if (isset($this->fk_user_modif)) {
351 $this->fk_user_modif = (int) $this->fk_user_modif;
353 if (isset($this->import_key)) {
354 $this->import_key = trim($this->import_key);
360 if (empty($this->oldcopy))
362 $org =
new self($this->db);
363 $org->fetch($this->
id);
364 $this->oldcopy = $org;
368 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
369 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
370 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
371 $sql .=
' batch = '.(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
',';
372 $sql .=
' eatby = '.(!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
',';
373 $sql .=
' sellby = '.(!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null').
',';
374 $sql .=
' datec = '.(!isset($this->datec) ||
dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
',';
375 $sql .=
' tms = '.(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
376 $sql .=
' fk_user_creat = '.(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
',';
377 $sql .=
' fk_user_modif = '.(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
',';
378 $sql .=
' import_key = '.(isset($this->import_key) ? $this->import_key :
"null");
379 $sql .=
' WHERE rowid='.$this->id;
386 $this->errors[] =
'Error '.$this->db->lasterror();
387 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
400 if (!$error && !$notrigger) {
402 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
403 if ($result < 0) { $error++; }
409 $this->
db->rollback();
427 public function delete(
User $user, $notrigger =
false)
448 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
449 $sql .=
' WHERE rowid='.$this->id;
454 $this->errors[] =
'Error '.$this->db->lasterror();
455 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
461 $this->
db->rollback();
488 $object->fetch($fromid);
496 $object->context[
'createfromclone'] =
'createfromclone';
497 $result = $object->create($user);
502 $this->errors = $object->errors;
503 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
506 unset($object->context[
'createfromclone']);
514 $this->
db->rollback();
563 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
565 global $langs, $conf, $db;
566 global $dolibarr_main_authentication, $dolibarr_main_demo;
571 $label =
'<u>'.$langs->trans(
"Batch").
'</u>';
572 $label .=
'<div width="100%">';
573 $label .=
'<b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
576 $label .=
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
580 $label .=
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
583 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
585 if ($option !=
'nolink')
588 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
589 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
590 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
594 if (empty($notooltip))
596 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
598 $label = $langs->trans(
"ShowMyObject");
599 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
601 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
602 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
603 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
605 $linkstart =
'<a href="'.$url.
'"';
606 $linkstart .= $linkclose.
'>';
609 $result .= $linkstart;
610 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
611 if ($withpicto != 2) $result .= $this->batch;
628 $this->entity = null;
629 $this->fk_product = null;
635 $this->fk_user_creat = null;
636 $this->fk_user_modif = null;
637 $this->import_key =
'';
create(User $user, $notrigger=false)
Create object into database.
Class with list of lots and properties.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
LibStatut($status, $mode=0)
Return label of a given status.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
fetch($id=0, $product_id=0, $batch= '')
Load object in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
$conf db
API class for accounts.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $maxlen=24, $morecss= '', $save_lastsearch_value=-1)
Return a link to the a lot card (with optionaly the picto) Use this->id,this->lastname, this->firstname.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
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.
getLibStatut($mode=0)
Return label of status of object.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
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...
__construct(DoliDB $db)
Constructor.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)