30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45 public $element =
'ProductStockEntrepot';
50 public $table_element =
'product_warehouse_properties';
62 public $seuil_stock_alerte;
92 if (isset($this->fk_product)) {
93 $this->fk_product = (int) $this->fk_product;
95 if (isset($this->fk_entrepot)) {
96 $this->fk_entrepot = (int) $this->fk_entrepot;
98 if (isset($this->seuil_stock_alerte)) {
99 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
101 if (isset($this->desiredstock)) {
102 $this->desiredstock = trim($this->desiredstock);
104 if (isset($this->import_key)) {
105 $this->import_key = trim($this->import_key);
112 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
113 $sql .=
'fk_product,';
114 $sql .=
'fk_entrepot,';
115 $sql .=
'seuil_stock_alerte,';
116 $sql .=
'desiredstock,';
117 $sql .=
'import_key';
118 $sql .=
') VALUES (';
119 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
120 $sql .=
' '.(!isset($this->fk_entrepot) ?
'NULL' : $this->fk_entrepot).
',';
121 $sql .=
' '.(!isset($this->seuil_stock_alerte) ?
'0' : $this->seuil_stock_alerte).
',';
122 $sql .=
' '.(!isset($this->desiredstock) ?
'0' : $this->desiredstock).
',';
123 $sql .=
' '.(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
128 $resql = $this->db->query($sql);
131 $this->errors[] =
'Error '.$this->db->lasterror();
132 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
136 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
151 $this->db->rollback();
169 public function fetch($id, $fk_product = 0, $fk_entrepot = 0)
171 if (empty($id) && (empty($fk_product) || empty($fk_entrepot))) {
180 $sql .=
" t.fk_product,";
181 $sql .=
" t.fk_entrepot,";
182 $sql .=
" t.seuil_stock_alerte,";
183 $sql .=
" t.desiredstock,";
184 $sql .=
" t.import_key";
185 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
187 $sql .=
" WHERE t.rowid = ".((int) $id);
189 $sql .=
" WHERE t.fk_product = ".((int) $fk_product).
" AND t.fk_entrepot = ".((int) $fk_entrepot);
192 $resql = $this->db->query($sql);
194 $numrows = $this->db->num_rows($resql);
196 $obj = $this->db->fetch_object($resql);
198 $this->
id = $obj->rowid;
200 $this->tms = $this->db->jdate($obj->tms);
201 $this->fk_product = $obj->fk_product;
202 $this->fk_entrepot = $obj->fk_entrepot;
203 $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
204 $this->desiredstock = $obj->desiredstock;
205 $this->import_key = $obj->import_key;
214 $this->db->free($resql);
222 $this->errors[] =
'Error '.$this->db->lasterror();
223 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
242 public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
249 $sql .=
" t.fk_product,";
250 $sql .=
" t.fk_entrepot,";
251 $sql .=
" t.seuil_stock_alerte,";
252 $sql .=
" t.desiredstock,";
253 $sql .=
" t.import_key";
254 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
255 $sql .=
" WHERE 1=1";
258 if (is_array($filter)) {
260 if (count($filter) > 0) {
261 foreach ($filter as $key => $value) {
262 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
265 if (count($sqlwhere) > 0) {
266 $sql .=
" AND ".implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
276 $this->errors[] = $errormessage;
277 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
281 if (!empty($fk_product) && $fk_product > 0) {
282 $sql .=
" AND fk_product = ".((int) $fk_product);
283 } elseif (!empty($fk_entrepot) && $fk_entrepot > 0) {
284 $sql .=
" AND fk_entrepot = ".((int) $fk_entrepot);
288 if (!empty($sortfield)) {
289 $sql .= $this->db->order($sortfield, $sortorder);
291 if (!empty($limit)) {
292 $sql .= $this->db->plimit($limit, $offset);
297 $resql = $this->db->query($sql);
299 while ($obj = $this->db->fetch_object($resql)) {
300 $lines[$obj->rowid] = array(
302 ,
'fk_product' => $obj->fk_product
303 ,
'fk_entrepot' => $obj->fk_entrepot
304 ,
'seuil_stock_alerte' => $obj->seuil_stock_alerte
305 ,
'desiredstock' => $obj->desiredstock
308 $this->db->free($resql);
312 $this->errors[] =
'Error '.$this->db->lasterror();
313 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
334 if (isset($this->fk_product)) {
335 $this->fk_product = (int) $this->fk_product;
337 if (isset($this->fk_entrepot)) {
338 $this->fk_entrepot = (int) $this->fk_entrepot;
340 if (isset($this->seuil_stock_alerte)) {
341 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
343 if (isset($this->desiredstock)) {
344 $this->desiredstock = trim($this->desiredstock);
346 if (isset($this->import_key)) {
347 $this->import_key = trim($this->import_key);
355 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
357 $sql .=
' tms = '.(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
358 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
359 $sql .=
' fk_entrepot = '.(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
',';
360 $sql .=
' seuil_stock_alerte = '.(isset($this->seuil_stock_alerte) ? $this->seuil_stock_alerte :
"null").
',';
361 $sql .=
' desiredstock = '.(isset($this->desiredstock) ? $this->desiredstock :
"null").
',';
362 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
365 $sql .=
' WHERE rowid='.((int) $this->
id);
369 $resql = $this->db->query($sql);
372 $this->errors[] =
'Error '.$this->db->lasterror();
373 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
388 $this->db->rollback();
405 public function delete(
User $user, $notrigger = 0)
424 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
425 $sql .=
' WHERE rowid='.((int) $this->
id);
427 $resql = $this->db->query($sql);
430 $this->errors[] =
'Error '.$this->db->lasterror();
431 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
437 $this->db->rollback();
472 $object->context[
'createfromclone'] =
'createfromclone';
473 $result =
$object->create($user);
478 $this->errors =
$object->errors;
479 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
482 unset(
$object->context[
'createfromclone']);
490 $this->db->rollback();
507 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
513 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
514 $label .=
'<div width="100%">';
515 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
517 $link =
'<a href="'.DOL_URL_ROOT.
'/ProductEntrepot/card.php?id='.$this->
id.
'"';
518 $link .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
523 $result .= ($link.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
524 if ($withpicto != 2) {
528 $result .= $link.$this->ref.$linkend;
559 return $langs->trans(
'Enabled');
560 } elseif ($status == 0) {
561 return $langs->trans(
'Disabled');
563 } elseif ($mode == 1) {
565 return $langs->trans(
'Enabled');
566 } elseif ($status == 0) {
567 return $langs->trans(
'Disabled');
569 } elseif ($mode == 2) {
571 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
572 } elseif ($status == 0) {
573 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
575 } elseif ($mode == 3) {
577 return img_picto($langs->trans(
'Enabled'),
'statut4');
578 } elseif ($status == 0) {
579 return img_picto($langs->trans(
'Disabled'),
'statut5');
581 } elseif ($mode == 4) {
583 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
584 } elseif ($status == 0) {
585 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
587 } elseif ($mode == 5) {
589 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
590 } elseif ($status == 0) {
591 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
610 $this->fk_product = 0;
611 $this->fk_entrepot = 0;
612 $this->seuil_stock_alerte =
'';
613 $this->desiredstock =
'';
614 $this->import_key =
'';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
update(User $user, $notrigger=0)
Update object into database.
fetch($id, $fk_product=0, $fk_entrepot=0)
Load object in memory from the 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 optionally the picto) Use this->id,this->lastname,...
getLibStatut($mode=0)
Return the label of the status.
fetchAll($fk_product=0, $fk_entrepot=0, $sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load object in memory from the database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
create(User $user, $notrigger=0)
Create object into database.
LibStatut($status, $mode=0)
Renvoi le libelle d'un status donne.
Class to manage Dolibarr users.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.