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'=>5,
'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 'eol_date' => array(
'type'=>
'date',
'label'=>
'EndOfLife',
'enabled'=>
'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1',
'visible'=>5,
'position'=>70),
95 'manufacturing_date' => array(
'type'=>
'date',
'label'=>
'ManufacturingDate',
'enabled'=>
'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1',
'visible'=>5,
'position'=>80),
96 'scrapping_date' => array(
'type'=>
'date',
'label'=>
'DestructionDate',
'enabled'=>
'empty($conf->global->PRODUCT_ENABLE_TRACEABILITY)?0:1',
'visible'=>5,
'position'=>90),
99 'eatby' => array(
'type'=>
'date',
'label'=>
'EatByDate',
'enabled'=>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible'=>5,
'position'=>62),
100 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>500),
101 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
102 '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'),
103 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511),
104 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'index'=>0,
'position'=>1000)
123 public $eol_date =
'';
124 public $manufacturing_date =
'';
125 public $scrapping_date =
'';
134 public $fk_user_creat;
139 public $fk_user_modif;
174 if (isset($this->entity)) {
175 $this->entity = (int) $this->entity;
177 if (isset($this->fk_product)) {
178 $this->fk_product = (int) $this->fk_product;
180 if (isset($this->batch)) {
181 $this->batch = trim($this->batch);
183 if (isset($this->fk_user_creat)) {
184 $this->fk_user_creat = (int) $this->fk_user_creat;
186 if (isset($this->fk_user_modif)) {
187 $this->fk_user_modif = (int) $this->fk_user_modif;
189 if (isset($this->import_key)) {
190 $this->import_key = trim($this->import_key);
197 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
199 $sql .=
'fk_product,';
204 $sql .=
'manufacturing_date,';
205 $sql .=
'scrapping_date,';
209 $sql .=
'fk_user_creat,';
210 $sql .=
'fk_user_modif,';
211 $sql .=
'import_key';
212 $sql .=
') VALUES (';
213 $sql .=
' '.(!isset($this->entity) ? $conf->entity : $this->entity).
',';
214 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
215 $sql .=
' '.(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
',';
216 $sql .=
' '.(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
',';
217 $sql .=
' '.(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
',';
218 $sql .=
' '.(!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->eol_date).
"'").
',';
219 $sql .=
' '.(!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->manufacturing_date).
"'").
',';
220 $sql .=
' '.(!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->scrapping_date).
"'").
',';
223 $sql .=
' '.
"'".$this->
db->idate(
dol_now()).
"'".
',';
224 $sql .=
' '.(!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat).
',';
225 $sql .=
' '.(!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif).
',';
226 $sql .=
' '.(!isset($this->import_key) ?
'NULL' : $this->import_key);
234 $this->errors[] =
'Error '.$this->db->lasterror();
235 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
239 $this->
id = $this->
db->last_insert_id($this->
db->prefix().$this->table_element);
249 if (!$error && !$notrigger) {
251 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
261 $this->
db->rollback();
280 public function fetch($id = 0, $product_id = 0, $batch =
'')
287 $sql .=
" t.entity,";
288 $sql .=
" t.fk_product,";
291 $sql .=
" t.sellby,";
292 $sql .=
" t.eol_date,";
293 $sql .=
" t.manufacturing_date,";
294 $sql .=
" t.scrapping_date,";
299 $sql .=
" t.fk_user_creat,";
300 $sql .=
" t.fk_user_modif,";
301 $sql .=
" t.import_key,";
302 $sql .=
" t.note_public,";
303 $sql .=
" t.note_private";
304 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
305 if ($product_id > 0 && $batch !=
'') {
306 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
308 $sql .=
" WHERE t.rowid = ".((int) $id);
313 $numrows = $this->
db->num_rows(
$resql);
315 $obj = $this->
db->fetch_object(
$resql);
317 $this->
id = $obj->rowid;
318 $this->
ref = $obj->rowid;
321 $this->batch = $obj->batch;
322 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity);
323 $this->fk_product = $obj->fk_product;
324 $this->eatby = $this->
db->jdate($obj->eatby);
325 $this->sellby = $this->
db->jdate($obj->sellby);
326 $this->eol_date = $this->
db->jdate($obj->eol_date);
327 $this->manufacturing_date = $this->
db->jdate($obj->manufacturing_date);
328 $this->scrapping_date = $this->
db->jdate($obj->scrapping_date);
332 $this->datec = $this->
db->jdate($obj->datec);
333 $this->tms = $this->
db->jdate($obj->tms);
334 $this->fk_user_creat = $obj->fk_user_creat;
335 $this->fk_user_modif = $obj->fk_user_modif;
336 $this->import_key = $obj->import_key;
337 $this->note_public = $obj->note_public;
338 $this->note_private = $obj->note_private;
352 $this->errors[] =
'Error '.$this->db->lasterror();
353 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
375 if (isset($this->entity)) {
376 $this->entity = (int) $this->entity;
378 if (isset($this->fk_product)) {
379 $this->fk_product = (int) $this->fk_product;
381 if (isset($this->batch)) {
382 $this->batch = trim($this->batch);
384 if (isset($this->fk_user_creat)) {
385 $this->fk_user_creat = (int) $this->fk_user_creat;
387 if (isset($this->fk_user_modif)) {
388 $this->fk_user_modif = (int) $this->fk_user_modif;
390 if (isset($this->import_key)) {
391 $this->import_key = trim($this->import_key);
395 if (empty($this->oldcopy)) {
400 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
401 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
402 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
403 $sql .=
' batch = '.(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
',';
404 $sql .=
' eatby = '.(!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
',';
405 $sql .=
' sellby = '.(!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null').
',';
406 $sql .=
' eol_date = '.(!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'".$this->db->idate($this->eol_date).
"'" :
'null').
',';
407 $sql .=
' manufacturing_date = '.(!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'".$this->db->idate($this->manufacturing_date).
"'" :
'null').
',';
408 $sql .=
' scrapping_date = '.(!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'".$this->db->idate($this->scrapping_date).
"'" :
'null').
',';
411 $sql .=
' datec = '.(!isset($this->datec) ||
dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
',';
412 $sql .=
' tms = '.(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
413 $sql .=
' fk_user_creat = '.(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
',';
414 $sql .=
' fk_user_modif = '.(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
',';
415 $sql .=
' import_key = '.(isset($this->import_key) ? $this->import_key :
"null");
416 $sql .=
' WHERE rowid='.((int) $this->
id);
423 $this->errors[] =
'Error '.$this->db->lasterror();
424 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
435 if (!$error && !$notrigger) {
437 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
446 $this->
db->rollback();
464 public function delete(
User $user, $notrigger =
false)
485 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
486 $sql .=
' WHERE rowid='.((int) $this->
id);
491 $this->errors[] =
'Error '.$this->db->lasterror();
492 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
498 $this->
db->rollback();
525 $object->fetch($fromid);
533 $object->context[
'createfromclone'] =
'createfromclone';
534 $result = $object->create($user);
539 $this->errors = $object->errors;
540 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
543 unset($object->context[
'createfromclone']);
551 $this->
db->rollback();
600 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
602 global $langs, $conf, $hookmanager, $db;
603 global $dolibarr_main_authentication, $dolibarr_main_demo;
608 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Batch").
'</u>';
609 $label .=
'<div width="100%">';
610 $label .=
'<b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
611 if ($this->eatby && empty($conf->global->PRODUCT_DISABLE_EATBY)) {
612 $label .=
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
614 if ($this->sellby && empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
615 $label .=
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
618 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
620 if ($option !=
'nolink') {
622 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
623 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
624 $add_save_lastsearch_values = 1;
626 if ($add_save_lastsearch_values) {
627 $url .=
'&save_lastsearch_values=1';
632 if (empty($notooltip)) {
633 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
634 $label = $langs->trans(
"ShowMyObject");
635 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
637 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
638 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
640 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
643 if ($option ==
'nolink') {
644 $linkstart =
'<span';
646 $linkstart =
'<a href="'.$url.
'"';
648 $linkstart .= $linkclose.
'>';
649 if ($option ==
'nolink') {
650 $linkend =
'</span>';
655 $result .= $linkstart;
657 $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);
659 if ($withpicto != 2) {
660 $result .= $this->batch;
665 $hookmanager->initHooks(array(
'productlotdao'));
666 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
667 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
669 $result = $hookmanager->resPrint;
671 $result .= $hookmanager->resPrint;
688 $this->entity =
null;
689 $this->fk_product =
null;
695 $this->fk_user_creat =
null;
696 $this->fk_user_modif =
null;
697 $this->import_key =
'';
Parent class of all other business classes (invoices, contracts, proposals, 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...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class with list of lots and properties.
getLibStatut($mode=0)
Return label of status of object.
fetch($id=0, $product_id=0, $batch='')
Load object in memory from the database.
LibStatut($status, $mode=0)
Return label of a given status.
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,...
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
create(User $user, $notrigger=false)
Create object into database.
update(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.