30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
46 public $element =
'ProductStockEntrepot';
51 public $table_element =
'product_warehouse_properties';
65 public $seuil_stock_alerte;
96 if (isset($this->fk_product)) {
97 $this->fk_product = (int) $this->fk_product;
99 if (isset($this->fk_entrepot)) {
100 $this->fk_entrepot = (int) $this->fk_entrepot;
102 if (isset($this->seuil_stock_alerte)) {
103 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
105 if (isset($this->desiredstock)) {
106 $this->desiredstock = trim($this->desiredstock);
108 if (isset($this->import_key)) {
109 $this->import_key = trim($this->import_key);
116 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
117 $sql .=
'fk_product,';
118 $sql .=
'fk_entrepot,';
119 $sql .=
'seuil_stock_alerte,';
120 $sql .=
'desiredstock,';
121 $sql .=
'import_key';
122 $sql .=
') VALUES (';
123 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
124 $sql .=
' '.(!isset($this->fk_entrepot) ?
'NULL' : $this->fk_entrepot).
',';
125 $sql .=
' '.(!isset($this->seuil_stock_alerte) ?
'0' : $this->seuil_stock_alerte).
',';
126 $sql .=
' '.(!isset($this->desiredstock) ?
'0' : $this->desiredstock).
',';
127 $sql .=
' '.(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
132 $resql = $this->db->query($sql);
135 $this->errors[] =
'Error '.$this->db->lasterror();
136 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
140 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
155 $this->db->rollback();
173 public function fetch($id, $fk_product = 0, $fk_entrepot = 0)
175 if (empty($id) && (empty($fk_product) || empty($fk_entrepot))) {
184 $sql .=
" t.fk_product,";
185 $sql .=
" t.fk_entrepot,";
186 $sql .=
" t.seuil_stock_alerte,";
187 $sql .=
" t.desiredstock,";
188 $sql .=
" t.import_key";
189 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
191 $sql .=
" WHERE t.rowid = ".((int) $id);
193 $sql .=
" WHERE t.fk_product = ".((int) $fk_product).
" AND t.fk_entrepot = ".((int) $fk_entrepot);
196 $resql = $this->db->query($sql);
198 $numrows = $this->db->num_rows($resql);
200 $obj = $this->db->fetch_object($resql);
202 $this->
id = $obj->rowid;
204 $this->tms = $this->db->jdate($obj->tms);
205 $this->fk_product = $obj->fk_product;
206 $this->fk_entrepot = $obj->fk_entrepot;
207 $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
208 $this->desiredstock = $obj->desiredstock;
209 $this->import_key = $obj->import_key;
218 $this->db->free($resql);
226 $this->errors[] =
'Error '.$this->db->lasterror();
227 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
247 public function fetchAll($fk_product =
'', $fk_entrepot =
'', $sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
255 $sql .=
" t.fk_product,";
256 $sql .=
" t.fk_entrepot,";
257 $sql .=
" t.seuil_stock_alerte,";
258 $sql .=
" t.desiredstock,";
259 $sql .=
" t.import_key";
262 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
264 $sql .=
" WHERE 1=1";
268 if (count($filter) > 0) {
269 foreach ($filter as $key => $value) {
270 $sqlwhere [] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
273 if (count($sqlwhere) > 0) {
274 $sql .=
" AND ".implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
277 if (!empty($fk_product) && $fk_product > 0) {
278 $sql .=
" AND fk_product = ".((int) $fk_product);
279 } elseif (!empty($fk_entrepot) && $fk_entrepot > 0) {
280 $sql .=
" AND fk_entrepot = ".((int) $fk_entrepot);
284 if (!empty($sortfield)) {
285 $sql .= $this->db->order($sortfield, $sortorder);
287 if (!empty($limit)) {
288 $sql .= $this->db->plimit($limit, $offset);
293 $resql = $this->db->query($sql);
295 while ($obj = $this->db->fetch_object($resql)) {
296 $lines[$obj->rowid] = array(
298 ,
'fk_product'=>$obj->fk_product
299 ,
'fk_entrepot'=>$obj->fk_entrepot
300 ,
'seuil_stock_alerte'=>$obj->seuil_stock_alerte
301 ,
'desiredstock'=>$obj->desiredstock
304 $this->db->free($resql);
308 $this->errors[] =
'Error '.$this->db->lasterror();
309 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
331 if (isset($this->fk_product)) {
332 $this->fk_product = (int) $this->fk_product;
334 if (isset($this->fk_entrepot)) {
335 $this->fk_entrepot = (int) $this->fk_entrepot;
337 if (isset($this->seuil_stock_alerte)) {
338 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
340 if (isset($this->desiredstock)) {
341 $this->desiredstock = trim($this->desiredstock);
343 if (isset($this->import_key)) {
344 $this->import_key = trim($this->import_key);
352 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
354 $sql .=
' tms = '.(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
355 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
356 $sql .=
' fk_entrepot = '.(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
',';
357 $sql .=
' seuil_stock_alerte = '.(isset($this->seuil_stock_alerte) ? $this->seuil_stock_alerte :
"null").
',';
358 $sql .=
' desiredstock = '.(isset($this->desiredstock) ? $this->desiredstock :
"null").
',';
359 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
362 $sql .=
' WHERE rowid='.((int) $this->
id);
366 $resql = $this->db->query($sql);
369 $this->errors[] =
'Error '.$this->db->lasterror();
370 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
385 $this->db->rollback();
403 public function delete(
User $user, $notrigger =
false)
422 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
423 $sql .=
' WHERE rowid='.((int) $this->
id);
425 $resql = $this->db->query($sql);
428 $this->errors[] =
'Error '.$this->db->lasterror();
429 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
435 $this->db->rollback();
462 $object->fetch($fromid);
470 $object->context[
'createfromclone'] =
'createfromclone';
471 $result = $object->create($user);
476 $this->errors = $object->errors;
477 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
480 unset($object->context[
'createfromclone']);
488 $this->db->rollback();
505 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
507 global $langs, $conf, $db;
508 global $dolibarr_main_authentication, $dolibarr_main_demo;
515 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
516 $label .=
'<div width="100%">';
517 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
519 $link =
'<a href="'.DOL_URL_ROOT.
'/ProductEntrepot/card.php?id='.$this->
id.
'"';
520 $link .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
525 $result .= ($link.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
526 if ($withpicto != 2) {
530 $result .= $link.$this->ref.$linkend;
560 return $langs->trans(
'Enabled');
561 } elseif ($status == 0) {
562 return $langs->trans(
'Disabled');
564 } elseif ($mode == 1) {
566 return $langs->trans(
'Enabled');
567 } elseif ($status == 0) {
568 return $langs->trans(
'Disabled');
570 } elseif ($mode == 2) {
572 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
573 } elseif ($status == 0) {
574 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
576 } elseif ($mode == 3) {
578 return img_picto($langs->trans(
'Enabled'),
'statut4');
579 } elseif ($status == 0) {
580 return img_picto($langs->trans(
'Disabled'),
'statut5');
582 } elseif ($mode == 4) {
584 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
585 } elseif ($status == 0) {
586 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
588 } elseif ($mode == 5) {
590 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
591 } elseif ($status == 0) {
592 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
611 $this->fk_product =
null;
612 $this->fk_entrepot =
null;
613 $this->seuil_stock_alerte =
'';
614 $this->desiredstock =
'';
615 $this->import_key =
'';
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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...
Class to manage Dolibarr database access.
Class ProductStockEntrepot.
create(User $user, $notrigger=false)
Create object into database.
fetch($id, $fk_product=0, $fk_entrepot=0)
Load object in memory from the database.
update(User $user, $notrigger=false)
Update object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionaly the picto) Use this->id,this->lastname,...
getLibStatut($mode=0)
Return the label of the status.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
fetchAll($fk_product='', $fk_entrepot='', $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
LibStatut($status, $mode=0)
Renvoi le libelle d'un status donne.
Class to manage Dolibarr users.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.