30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45 public $element =
'ProductStockEntrepot';
50 public $table_element =
'product_warehouse_properties';
65 public $seuil_stock_alerte;
101 if (isset($this->fk_product)) {
102 $this->fk_product = (int) $this->fk_product;
104 if (isset($this->fk_entrepot)) {
105 $this->fk_entrepot = (int) $this->fk_entrepot;
107 if (isset($this->seuil_stock_alerte)) {
108 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
110 if (isset($this->desiredstock)) {
111 $this->desiredstock = trim($this->desiredstock);
113 if (isset($this->import_key)) {
114 $this->import_key = trim($this->import_key);
121 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
122 $sql .=
'fk_product,';
123 $sql .=
'fk_entrepot,';
124 $sql .=
'seuil_stock_alerte,';
125 $sql .=
'desiredstock,';
126 $sql .=
'import_key';
127 $sql .=
') VALUES (';
128 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
129 $sql .=
' '.(!isset($this->fk_entrepot) ?
'NULL' : $this->fk_entrepot).
',';
130 $sql .=
' '.(!isset($this->seuil_stock_alerte) ?
'0' : $this->seuil_stock_alerte).
',';
131 $sql .=
' '.(!isset($this->desiredstock) ?
'0' : $this->desiredstock).
',';
132 $sql .=
' '.(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
137 $resql = $this->db->query($sql);
140 $this->errors[] =
'Error '.$this->db->lasterror();
141 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
145 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
160 $this->db->rollback();
178 public function fetch($id, $fk_product = 0, $fk_entrepot = 0)
180 if (empty($id) && (empty($fk_product) || empty($fk_entrepot))) {
189 $sql .=
" t.fk_product,";
190 $sql .=
" t.fk_entrepot,";
191 $sql .=
" t.seuil_stock_alerte,";
192 $sql .=
" t.desiredstock,";
193 $sql .=
" t.import_key";
194 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
196 $sql .=
" WHERE t.rowid = ".((int) $id);
198 $sql .=
" WHERE t.fk_product = ".((int) $fk_product).
" AND t.fk_entrepot = ".((int) $fk_entrepot);
201 $resql = $this->db->query($sql);
203 $numrows = $this->db->num_rows($resql);
205 $obj = $this->db->fetch_object($resql);
207 $this->
id = $obj->rowid;
209 $this->tms = $this->db->jdate($obj->tms);
210 $this->fk_product = $obj->fk_product;
211 $this->fk_entrepot = $obj->fk_entrepot;
212 $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
213 $this->desiredstock = $obj->desiredstock;
214 $this->import_key = $obj->import_key;
223 $this->db->free($resql);
231 $this->errors[] =
'Error '.$this->db->lasterror();
232 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
251 public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
258 $sql .=
" t.fk_product,";
259 $sql .=
" t.fk_entrepot,";
260 $sql .=
" t.seuil_stock_alerte,";
261 $sql .=
" t.desiredstock,";
262 $sql .=
" t.import_key";
263 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
264 $sql .=
" WHERE 1=1";
267 if (is_array($filter)) {
269 if (count($filter) > 0) {
270 foreach ($filter as $key => $value) {
271 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
274 if (count($sqlwhere) > 0) {
275 $sql .=
" AND ".implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
285 $this->errors[] = $errormessage;
286 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
290 if (!empty($fk_product) && $fk_product > 0) {
291 $sql .=
" AND fk_product = ".((int) $fk_product);
292 } elseif (!empty($fk_entrepot) && $fk_entrepot > 0) {
293 $sql .=
" AND fk_entrepot = ".((int) $fk_entrepot);
297 if (!empty($sortfield)) {
298 $sql .= $this->db->order($sortfield, $sortorder);
300 if (!empty($limit)) {
301 $sql .= $this->db->plimit($limit, $offset);
306 $resql = $this->db->query($sql);
308 while ($obj = $this->db->fetch_object($resql)) {
309 $lines[$obj->rowid] = array(
311 ,
'fk_product' => $obj->fk_product
312 ,
'fk_entrepot' => $obj->fk_entrepot
313 ,
'seuil_stock_alerte' => $obj->seuil_stock_alerte
314 ,
'desiredstock' => $obj->desiredstock
317 $this->db->free($resql);
321 $this->errors[] =
'Error '.$this->db->lasterror();
322 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
343 if (isset($this->fk_product)) {
344 $this->fk_product = (int) $this->fk_product;
346 if (isset($this->fk_entrepot)) {
347 $this->fk_entrepot = (int) $this->fk_entrepot;
349 if (isset($this->seuil_stock_alerte)) {
350 $this->seuil_stock_alerte = trim($this->seuil_stock_alerte);
352 if (isset($this->desiredstock)) {
353 $this->desiredstock = trim($this->desiredstock);
355 if (isset($this->import_key)) {
356 $this->import_key = trim($this->import_key);
364 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
366 $sql .=
' tms = '.(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
367 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
368 $sql .=
' fk_entrepot = '.(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
',';
369 $sql .=
' seuil_stock_alerte = '.(isset($this->seuil_stock_alerte) ? $this->seuil_stock_alerte :
"null").
',';
370 $sql .=
' desiredstock = '.(isset($this->desiredstock) ? $this->desiredstock :
"null").
',';
371 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
374 $sql .=
' WHERE rowid='.((int) $this->
id);
378 $resql = $this->db->query($sql);
381 $this->errors[] =
'Error '.$this->db->lasterror();
382 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
397 $this->db->rollback();
414 public function delete(
User $user, $notrigger = 0)
433 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
434 $sql .=
' WHERE rowid='.((int) $this->
id);
436 $resql = $this->db->query($sql);
439 $this->errors[] =
'Error '.$this->db->lasterror();
440 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
446 $this->db->rollback();
481 $object->context[
'createfromclone'] =
'createfromclone';
482 $result =
$object->create($user);
487 $this->errors =
$object->errors;
488 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
491 unset(
$object->context[
'createfromclone']);
499 $this->db->rollback();
516 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
522 $label =
'<u>'.$langs->trans(
"MyModule").
'</u>';
523 $label .=
'<div width="100%">';
524 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
526 $link =
'<a href="'.DOL_URL_ROOT.
'/ProductEntrepot/card.php?id='.$this->
id.
'"';
527 $link .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
532 $result .= ($link.img_object(($notooltip ?
'' : $label),
'label', ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
533 if ($withpicto != 2) {
537 $result .= $link.$this->ref.$linkend;
568 return $langs->trans(
'Enabled');
569 } elseif ($status == 0) {
570 return $langs->trans(
'Disabled');
572 } elseif ($mode == 1) {
574 return $langs->trans(
'Enabled');
575 } elseif ($status == 0) {
576 return $langs->trans(
'Disabled');
578 } elseif ($mode == 2) {
580 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
581 } elseif ($status == 0) {
582 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
584 } elseif ($mode == 3) {
586 return img_picto($langs->trans(
'Enabled'),
'statut4');
587 } elseif ($status == 0) {
588 return img_picto($langs->trans(
'Disabled'),
'statut5');
590 } elseif ($mode == 4) {
592 return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
593 } elseif ($status == 0) {
594 return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
596 } elseif ($mode == 5) {
598 return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
599 } elseif ($status == 0) {
600 return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
619 $this->fk_product = 0;
620 $this->fk_entrepot = 0;
621 $this->seuil_stock_alerte =
'';
622 $this->desiredstock =
'';
623 $this->import_key =
'';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.