30 require_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.
'(';
118 $sql .=
'fk_product,';
119 $sql .=
'fk_entrepot,';
120 $sql .=
'seuil_stock_alerte,';
121 $sql .=
'desiredstock,';
122 $sql .=
'import_key';
125 $sql .=
') VALUES (';
127 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
128 $sql .=
' '.(!isset($this->fk_entrepot) ?
'NULL' : $this->fk_entrepot).
',';
129 $sql .=
' '.(!isset($this->seuil_stock_alerte) ?
'0' : $this->seuil_stock_alerte).
',';
130 $sql .=
' '.(!isset($this->desiredstock) ?
'0' : $this->desiredstock).
',';
131 $sql .=
' '.(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
141 $this->errors[] =
'Error '.$this->db->lasterror();
142 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
146 $this->
id = $this->
db->last_insert_id($this->
db->prefix().$this->table_element);
161 $this->
db->rollback();
179 public function fetch($id, $fk_product = 0, $fk_entrepot = 0)
181 if (empty($id) && (empty($fk_product) || empty($fk_entrepot))) {
190 $sql .=
" t.fk_product,";
191 $sql .=
" t.fk_entrepot,";
192 $sql .=
" t.seuil_stock_alerte,";
193 $sql .=
" t.desiredstock,";
194 $sql .=
" t.import_key";
195 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
197 $sql .=
" WHERE t.rowid = ".((int) $id);
199 $sql .=
" WHERE t.fk_product = ".((int) $fk_product).
" AND t.fk_entrepot = ".((int) $fk_entrepot);
204 $numrows = $this->
db->num_rows(
$resql);
206 $obj = $this->
db->fetch_object(
$resql);
208 $this->
id = $obj->rowid;
210 $this->tms = $this->
db->jdate($obj->tms);
211 $this->fk_product = $obj->fk_product;
212 $this->fk_entrepot = $obj->fk_entrepot;
213 $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
214 $this->desiredstock = $obj->desiredstock;
215 $this->import_key = $obj->import_key;
232 $this->errors[] =
'Error '.$this->db->lasterror();
233 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
253 public function fetchAll($fk_product =
'', $fk_entrepot =
'', $sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
261 $sql .=
" t.fk_product,";
262 $sql .=
" t.fk_entrepot,";
263 $sql .=
" t.seuil_stock_alerte,";
264 $sql .=
" t.desiredstock,";
265 $sql .=
" t.import_key";
268 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
270 $sql .=
" WHERE 1=1";
274 if (count($filter) > 0) {
275 foreach ($filter as $key => $value) {
276 $sqlwhere [] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
279 if (count($sqlwhere) > 0) {
280 $sql .=
" AND ".implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
283 if (!empty($fk_product) && $fk_product > 0) {
284 $sql .=
" AND fk_product = ".((int) $fk_product);
285 } elseif (!empty($fk_entrepot) && $fk_entrepot > 0) {
286 $sql .=
" AND fk_entrepot = ".((int) $fk_entrepot);
290 if (!empty($sortfield)) {
291 $sql .= $this->
db->order($sortfield, $sortorder);
293 if (!empty($limit)) {
294 $sql .= $this->
db->plimit($limit, $offset);
301 while ($obj = $this->
db->fetch_object(
$resql)) {
302 $lines[$obj->rowid] = array(
304 ,
'fk_product'=>$obj->fk_product
305 ,
'fk_entrepot'=>$obj->fk_entrepot
306 ,
'seuil_stock_alerte'=>$obj->seuil_stock_alerte
307 ,
'desiredstock'=>$obj->desiredstock
314 $this->errors[] =
'Error '.$this->db->lasterror();
315 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
337 if (isset($this->fk_product)) {
338 $this->fk_product = (int) $this->fk_product;
340 if (isset($this->fk_entrepot)) {
341 $this->fk_entrepot = (int) $this->fk_entrepot;
343 if (isset($this->seuil_stock_alerte)) {
344 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
346 if (isset($this->desiredstock)) {
347 $this->desiredstock = trim($this->desiredstock);
349 if (isset($this->import_key)) {
350 $this->import_key = trim($this->import_key);
358 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
360 $sql .=
' tms = '.(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
361 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
362 $sql .=
' fk_entrepot = '.(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
',';
363 $sql .=
' seuil_stock_alerte = '.(isset($this->seuil_stock_alerte) ? $this->seuil_stock_alerte :
"null").
',';
364 $sql .=
' desiredstock = '.(isset($this->desiredstock) ? $this->desiredstock :
"null").
',';
365 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
368 $sql .=
' WHERE rowid='.((int) $this->
id);
375 $this->errors[] =
'Error '.$this->db->lasterror();
376 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
391 $this->
db->rollback();
409 public function delete(
User $user, $notrigger =
false)
428 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
429 $sql .=
' WHERE rowid='.((int) $this->
id);
434 $this->errors[] =
'Error '.$this->db->lasterror();
435 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
441 $this->
db->rollback();
468 $object->fetch($fromid);
476 $object->context[
'createfromclone'] =
'createfromclone';
477 $result = $object->create($user);
482 $this->errors = $object->errors;
483 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
486 unset($object->context[
'createfromclone']);
494 $this->
db->rollback();
511 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
513 global $langs, $conf, $db;
514 global $dolibarr_main_authentication, $dolibarr_main_demo;
521 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
522 $label .=
'<div width="100%">';
523 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
525 $link =
'<a href="'.DOL_URL_ROOT.
'/ProductEntrepot/card.php?id='.$this->
id.
'"';
526 $link .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
531 $result .= ($link.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
532 if ($withpicto != 2) {
536 $result .= $link.$this->ref.$linkend;
548 return $this->
LibStatut($this->status, $mode);
566 return $langs->trans(
'Enabled');
567 } elseif ($status == 0) {
568 return $langs->trans(
'Disabled');
570 } elseif ($mode == 1) {
572 return $langs->trans(
'Enabled');
573 } elseif ($status == 0) {
574 return $langs->trans(
'Disabled');
576 } elseif ($mode == 2) {
578 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
579 } elseif ($status == 0) {
580 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
582 } elseif ($mode == 3) {
584 return img_picto($langs->trans(
'Enabled'),
'statut4');
585 } elseif ($status == 0) {
586 return img_picto($langs->trans(
'Disabled'),
'statut5');
588 } elseif ($mode == 4) {
590 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
591 } elseif ($status == 0) {
592 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
594 } elseif ($mode == 5) {
596 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
597 } elseif ($status == 0) {
598 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
615 $this->fk_product =
null;
616 $this->fk_entrepot =
null;
617 $this->seuil_stock_alerte =
'';
618 $this->desiredstock =
'';
619 $this->import_key =
'';