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)) {
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);
231 $this->errors[] =
"Error ".$this->db->lasterror();
235 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
239 $result=$this->
call_trigger(
'LINERECEPTION_CREATE', $user);
257 foreach ($this->errors as $errmsg) {
259 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
261 $this->db->rollback();
277 public function fetch($id, $ref =
'')
283 $sql .=
" t.fk_commande,";
284 $sql .=
" t.fk_product,";
285 $sql .=
" t.fk_commandefourndet,";
287 $sql .=
" t.fk_entrepot,";
288 $sql .=
" t.fk_user,";
290 $sql .=
" t.comment,";
291 $sql .=
" t.status,";
295 $sql .=
" t.sellby,";
296 $sql .=
" t.fk_reception";
299 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
301 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
303 $sql .=
" WHERE t.rowid = ".((int) $id);
307 $resql = $this->db->query($sql);
309 if ($this->db->num_rows($resql)) {
310 $obj = $this->db->fetch_object($resql);
312 $this->
id = $obj->rowid;
314 $this->fk_commande = $obj->fk_commande;
315 $this->fk_product = $obj->fk_product;
316 $this->fk_commandefourndet = $obj->fk_commandefourndet;
317 $this->qty = $obj->qty;
318 $this->fk_entrepot = $obj->fk_entrepot;
319 $this->fk_user = $obj->fk_user;
320 $this->datec = $this->db->jdate($obj->datec);
321 $this->comment = $obj->comment;
322 $this->
status = $obj->status;
323 $this->tms = $this->db->jdate($obj->tms);
324 $this->batch = $obj->batch;
325 $this->eatby = $this->db->jdate($obj->eatby);
326 $this->sellby = $this->db->jdate($obj->sellby);
327 $this->fk_reception = $obj->fk_reception;
331 $this->db->free($resql);
335 $this->error =
"Error ".$this->db->lasterror();
348 public function update($user, $notrigger = 0)
354 if (isset($this->fk_commande)) {
355 $this->fk_commande = trim($this->fk_commande);
357 if (isset($this->fk_product)) {
358 $this->fk_product = trim($this->fk_product);
360 if (isset($this->fk_commandefourndet)) {
361 $this->fk_commandefourndet = trim($this->fk_commandefourndet);
363 if (isset($this->qty)) {
364 $this->qty = trim($this->qty);
366 if (isset($this->fk_entrepot)) {
367 $this->fk_entrepot = trim($this->fk_entrepot);
369 if (isset($this->fk_user)) {
370 $this->fk_user = trim($this->fk_user);
372 if (isset($this->comment)) {
373 $this->comment = trim($this->comment);
375 if (isset($this->
status)) {
378 if (isset($this->batch)) {
379 $this->batch = trim($this->batch);
388 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
389 $sql .=
" fk_commande=".(isset($this->fk_commande) ? $this->fk_commande :
"null").
",";
390 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
391 $sql .=
" fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet :
"null").
",";
392 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
393 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
394 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
395 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
396 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
397 $sql .=
" status=".(isset($this->
status) ? $this->
status :
"null").
",";
398 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
399 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
400 $sql .=
" eatby=".(dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
401 $sql .=
" sellby=".(dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null');
402 $sql .=
" WHERE rowid=".((int) $this->
id);
407 $resql = $this->db->query($sql);
410 $this->errors[] =
"Error ".$this->db->lasterror();
415 if (empty($this->
id) && !empty($this->
rowid)) {
416 $this->
id = $this->rowid;
426 $result = $this->
call_trigger(
'LINERECEPTION_MODIFY', $user);
436 foreach ($this->errors as $errmsg) {
438 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
440 $this->db->rollback();
582 $langs->load(
'orders');
585 return $langs->trans($this->labelStatus[$status]);
586 } elseif ($mode == 1) {
587 return $langs->trans($this->labelStatusShort[$status]);
588 } elseif ($mode == 2) {
589 return $langs->trans($this->labelStatus[$status]);
590 } elseif ($mode == 3) {
592 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
593 } elseif ($status == 1) {
594 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
595 } elseif ($status == 2) {
596 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
598 } elseif ($mode == 4) {
600 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
601 } elseif ($status == 1) {
602 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4').
' '.$langs->trans($this->labelStatus[$status]);
603 } elseif ($status == 2) {
604 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8').
' '.$langs->trans($this->labelStatus[$status]);
606 } elseif ($mode == 5) {
608 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
609 } elseif ($status == 1) {
610 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
611 } elseif ($status == 2) {
612 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
656 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
663 $sql .=
" t.fk_commande,";
664 $sql .=
" t.fk_product,";
665 $sql .=
" t.fk_commandefourndet,";
667 $sql .=
" t.fk_entrepot,";
668 $sql .=
" t.fk_user,";
670 $sql .=
" t.comment,";
671 $sql .=
" t.status,";
677 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
681 if (count($filter) > 0) {
682 foreach ($filter as $key => $value) {
683 if ($key ==
't.comment') {
684 $sqlwhere [] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
685 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
686 $sqlwhere [] = $key.
" = '".$this->db->escape($value).
"'";
687 } elseif ($key ==
'qty') {
688 $sqlwhere [] = $key.
" = ".((float) $value);
690 $sqlwhere [] = $key.
" = ".((int) $value);
694 if (count($sqlwhere) > 0) {
695 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
698 if (!empty($sortfield)) {
699 $sql .= $this->db->order($sortfield, $sortorder);
701 if (!empty($limit)) {
702 $sql .= $this->db->plimit($limit, $offset);
704 $this->lines = array();
706 $resql = $this->db->query($sql);
708 $num = $this->db->num_rows($resql);
710 while ($obj = $this->db->fetch_object($resql)) {
711 $line =
new self($this->db);
713 $line->id = $obj->rowid;
715 $line->fk_commande = $obj->fk_commande;
716 $line->fk_product = $obj->fk_product;
717 $line->fk_commandefourndet = $obj->fk_commandefourndet;
718 $line->qty = $obj->qty;
719 $line->fk_entrepot = $obj->fk_entrepot;
720 $line->fk_user = $obj->fk_user;
721 $line->datec = $this->db->jdate($obj->datec);
722 $line->comment = $obj->comment;
723 $line->status = $obj->status;
724 $line->tms = $this->db->jdate($obj->tms);
725 $line->batch = $obj->batch;
726 $line->eatby = $this->db->jdate($obj->eatby);
727 $line->sellby = $this->db->jdate($obj->sellby);
728 $line->fetch_optionals();
730 $this->lines[$line->id] = $line;
732 $this->db->free($resql);
736 $this->errors[] =
'Error '.$this->db->lasterror();
737 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);