148 public function create($user, $notrigger = 0)
150 global $conf, $langs, $hookmanager;
155 if (isset($this->fk_commande)) {
156 $this->fk_commande = trim($this->fk_commande);
158 if (isset($this->fk_product)) {
159 $this->fk_product = trim($this->fk_product);
161 if (isset($this->fk_commandefourndet)) {
162 $this->fk_commandefourndet = trim($this->fk_commandefourndet);
164 if (isset($this->qty)) {
165 $this->qty = trim($this->qty);
167 if (isset($this->fk_entrepot)) {
168 $this->fk_entrepot = trim($this->fk_entrepot);
170 if (isset($this->fk_user)) {
171 $this->fk_user = trim($this->fk_user);
173 if (isset($this->comment)) {
174 $this->comment = trim($this->comment);
176 if (isset($this->status)) {
177 $this->status = trim($this->status);
179 if (isset($this->batch)) {
180 $this->batch = trim($this->batch);
182 if (empty($this->datec)) {
191 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
192 $sql .=
"fk_commande,";
193 $sql .=
"fk_product,";
194 $sql .=
"fk_commandefourndet,";
196 $sql .=
"fk_entrepot,";
204 $sql .=
"fk_reception,";
205 $sql .=
"cost_price";
208 $sql .=
") VALUES (";
209 $sql .=
" ".(!isset($this->fk_commande) ?
'NULL' :
"'".$this->db->escape($this->fk_commande).
"'").
",";
210 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
211 $sql .=
" ".(!isset($this->fk_commandefourndet) ?
'NULL' :
"'".$this->db->escape($this->fk_commandefourndet).
"'").
",";
212 $sql .=
" ".(!isset($this->qty) ?
'NULL' :
"'".$this->db->escape($this->qty).
"'").
",";
213 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' :
"'".$this->db->escape($this->fk_entrepot).
"'").
",";
214 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' :
"'".$this->db->escape($this->fk_user).
"'").
",";
215 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
216 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
217 $sql .=
" ".(!isset($this->status) ?
'NULL' :
"'".$this->db->escape($this->status).
"'").
",";
218 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
219 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
220 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
221 $sql .=
" ".(!isset($this->fk_reception) ?
'NULL' :
"'".$this->db->escape($this->fk_reception).
"'").
",";
222 $sql .=
" ".(!isset($this->cost_price) ?
'0' :
"'".$this->db->escape($this->cost_price).
"'");
228 $resql = $this->db->query($sql);
230 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
234 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
238 $result=$this->
call_trigger(
'LINERECEPTION_CREATE', $user);
256 foreach ($this->errors as $errmsg) {
258 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
260 $this->db->rollback();
276 public function fetch($id, $ref =
'')
282 $sql .=
" t.fk_commande,";
283 $sql .=
" t.fk_product,";
284 $sql .=
" t.fk_commandefourndet,";
286 $sql .=
" t.fk_entrepot,";
287 $sql .=
" t.fk_user,";
289 $sql .=
" t.comment,";
290 $sql .=
" t.status,";
294 $sql .=
" t.sellby,";
295 $sql .=
" t.fk_reception";
298 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
300 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
302 $sql .=
" WHERE t.rowid = ".((int) $id);
306 $resql = $this->db->query($sql);
308 if ($this->db->num_rows($resql)) {
309 $obj = $this->db->fetch_object($resql);
311 $this->
id = $obj->rowid;
313 $this->fk_commande = $obj->fk_commande;
314 $this->fk_product = $obj->fk_product;
315 $this->fk_commandefourndet = $obj->fk_commandefourndet;
316 $this->qty = $obj->qty;
317 $this->fk_entrepot = $obj->fk_entrepot;
318 $this->fk_user = $obj->fk_user;
319 $this->datec = $this->db->jdate($obj->datec);
320 $this->comment = $obj->comment;
321 $this->status = $obj->status;
322 $this->tms = $this->db->jdate($obj->tms);
323 $this->batch = $obj->batch;
324 $this->eatby = $this->db->jdate($obj->eatby);
325 $this->sellby = $this->db->jdate($obj->sellby);
326 $this->fk_reception = $obj->fk_reception;
330 $this->db->free($resql);
334 $this->error =
"Error ".$this->db->lasterror();
347 public function update($user, $notrigger = 0)
353 if (isset($this->fk_commande)) {
354 $this->fk_commande = trim($this->fk_commande);
356 if (isset($this->fk_product)) {
357 $this->fk_product = trim($this->fk_product);
359 if (isset($this->fk_commandefourndet)) {
360 $this->fk_commandefourndet = trim($this->fk_commandefourndet);
362 if (isset($this->qty)) {
363 $this->qty = trim($this->qty);
365 if (isset($this->fk_entrepot)) {
366 $this->fk_entrepot = trim($this->fk_entrepot);
368 if (isset($this->fk_user)) {
369 $this->fk_user = trim($this->fk_user);
371 if (isset($this->comment)) {
372 $this->comment = trim($this->comment);
374 if (isset($this->status)) {
375 $this->status = trim($this->status);
377 if (isset($this->batch)) {
378 $this->batch = trim($this->batch);
387 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
388 $sql .=
" fk_commande=".(isset($this->fk_commande) ? $this->fk_commande :
"null").
",";
389 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
390 $sql .=
" fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet :
"null").
",";
391 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
392 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
393 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
394 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
395 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
396 $sql .=
" status=".(isset($this->status) ? $this->status :
"null").
",";
397 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
398 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
399 $sql .=
" eatby=".(dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
400 $sql .=
" sellby=".(dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null');
401 $sql .=
" WHERE rowid=".((int) $this->
id);
406 $resql = $this->db->query($sql);
408 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
413 if (empty($this->
id) && !empty($this->
rowid)) {
414 $this->
id = $this->rowid;
424 $result = $this->
call_trigger(
'LINERECEPTION_MODIFY', $user);
434 foreach ($this->errors as $errmsg) {
436 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
438 $this->db->rollback();
579 $langs->load(
'orders');
582 return $langs->trans($this->statuts[$status]);
583 } elseif ($mode == 1) {
584 return $langs->trans($this->statuts_short[$status]);
585 } elseif ($mode == 2) {
586 return $langs->trans($this->statuts[$status]);
587 } elseif ($mode == 3) {
589 return img_picto($langs->trans($this->statuts[$status]),
'statut0');
590 } elseif ($status == 1) {
591 return img_picto($langs->trans($this->statuts[$status]),
'statut4');
592 } elseif ($status == 2) {
593 return img_picto($langs->trans($this->statuts[$status]),
'statut8');
595 } elseif ($mode == 4) {
597 return img_picto($langs->trans($this->statuts[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
598 } elseif ($status == 1) {
599 return img_picto($langs->trans($this->statuts[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
600 } elseif ($status == 2) {
601 return img_picto($langs->trans($this->statuts[$status]),
'statut8').
' '.$langs->trans($this->statuts[$status]);
603 } elseif ($mode == 5) {
605 return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut0');
606 } elseif ($status == 1) {
607 return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut4');
608 } elseif ($status == 2) {
609 return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut8');
653 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
660 $sql .=
" t.fk_commande,";
661 $sql .=
" t.fk_product,";
662 $sql .=
" t.fk_commandefourndet,";
664 $sql .=
" t.fk_entrepot,";
665 $sql .=
" t.fk_user,";
667 $sql .=
" t.comment,";
668 $sql .=
" t.status,";
674 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
678 if (count($filter) > 0) {
679 foreach ($filter as $key => $value) {
680 if ($key ==
't.comment') {
681 $sqlwhere [] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
682 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
683 $sqlwhere [] = $key.
" = '".$this->db->escape($value).
"'";
684 } elseif ($key ==
'qty') {
685 $sqlwhere [] = $key.
" = ".((float) $value);
687 $sqlwhere [] = $key.
" = ".((int) $value);
691 if (count($sqlwhere) > 0) {
692 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
695 if (!empty($sortfield)) {
696 $sql .= $this->db->order($sortfield, $sortorder);
698 if (!empty($limit)) {
699 $sql .= $this->db->plimit($limit, $offset);
701 $this->lines = array();
703 $resql = $this->db->query($sql);
705 $num = $this->db->num_rows($resql);
707 while ($obj = $this->db->fetch_object($resql)) {
708 $line =
new self($this->db);
710 $line->id = $obj->rowid;
712 $line->fk_commande = $obj->fk_commande;
713 $line->fk_product = $obj->fk_product;
714 $line->fk_commandefourndet = $obj->fk_commandefourndet;
715 $line->qty = $obj->qty;
716 $line->fk_entrepot = $obj->fk_entrepot;
717 $line->fk_user = $obj->fk_user;
718 $line->datec = $this->db->jdate($obj->datec);
719 $line->comment = $obj->comment;
720 $line->status = $obj->status;
721 $line->tms = $this->db->jdate($obj->tms);
722 $line->batch = $obj->batch;
723 $line->eatby = $this->db->jdate($obj->eatby);
724 $line->sellby = $this->db->jdate($obj->sellby);
725 $line->fetch_optionals();
727 $this->lines[$line->id] = $line;
729 $this->db->free($resql);
733 $this->errors[] =
'Error '.$this->db->lasterror();
734 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);