32require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
33require_once DOL_DOCUMENT_ROOT.
"/reception/class/reception.class.php";
45 public $TRIGGER_PREFIX =
'LINERECEPTION';
55 public $element =
'receptionlinebatch';
61 public $lines = array();
86 public $fk_elementdet;
91 public $origin_line_id;
132 public $vat_src_code;
136 public $ref_supplier;
169 public $eatby =
null;
173 public $sellby =
null;
177 public $cost_price = 0;
199 $this->labelStatus[0] =
'Received';
200 $this->labelStatus[1] =
'Verified';
201 $this->labelStatus[2] =
'Denied';
202 $this->labelStatusShort[0] =
'Received';
203 $this->labelStatusShort[1] =
'Verified';
204 $this->labelStatusShort[2] =
'Denied';
215 public function create($user, $notrigger = 0)
220 if (isset($this->fk_element)) {
221 $this->fk_element = (int) $this->fk_element;
223 if (isset($this->fk_product)) {
224 $this->fk_product = (int) $this->fk_product;
226 if (isset($this->fk_elementdet)) {
227 $this->fk_elementdet = (int) $this->fk_elementdet;
229 if (isset($this->qty)) {
230 $this->qty = (float) $this->qty;
232 if (isset($this->fk_entrepot)) {
233 $this->fk_entrepot = (int) $this->fk_entrepot;
235 if (isset($this->fk_user)) {
236 $this->fk_user = (int) $this->fk_user;
238 if (isset($this->comment)) {
239 $this->comment = trim($this->comment);
241 if (isset($this->
status)) {
244 if (isset($this->batch)) {
245 $this->batch = trim($this->batch);
247 if (empty($this->datec)) {
252 if (empty($this->fk_product)) {
253 $this->error =
'Error, property ->fk_product must not be empty to create a line of reception';
256 if (empty($this->fk_reception)) {
257 $this->error =
'Error, property ->fk_reception must not be empty to create a line of reception';
262 if (empty($this->rang)) {
267 $ranktouse = $this->rang;
268 if ($ranktouse == -1) {
269 $rangmax = $this->
line_max($this->fk_reception);
270 $ranktouse = $rangmax + 1;
274 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
275 $sql .=
"fk_product,";
276 $sql .=
"fk_element,";
277 $sql .=
"fk_elementdet,";
278 $sql .=
"element_type,";
280 $sql .=
"fk_entrepot,";
289 $sql .=
"description,";
291 $sql .=
"fk_reception,";
292 $sql .=
"cost_price,";
294 $sql .=
") VALUES (";
295 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : (int) $this->fk_product).
",";
296 $sql .=
" ".(!isset($this->fk_element) ?
'NULL' : (int) $this->fk_element).
",";
297 $sql .=
" ".(!isset($this->fk_elementdet) ?
'NULL' : (int) $this->fk_elementdet).
",";
298 $sql .=
" '".(!isset($this->element_type) ?
"supplier_order" : $this->db->escape($this->element_type)).
"',";
299 $sql .=
" ".(!isset($this->qty) ?
'NULL' : (float) $this->qty).
",";
300 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' : (int) $this->fk_entrepot).
",";
301 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' : (int) $this->fk_user).
",";
302 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
303 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
304 $sql .=
" ".(!isset($this->
status) ?
'NULL' : (int) $this->
status).
",";
305 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
306 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen((
string) $this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
307 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen((
string) $this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
308 $sql .=
" ".((int) $this->fk_unit);
310 $sql .=
", ".((int) $ranktouse).
",";
311 $sql .=
" ".((int) $this->fk_reception).
",";
312 $sql .=
" ".(!isset($this->cost_price) ?
'0' : (float) $this->cost_price).
",";
313 $sql .=
" ".(!isset($this->ref_fourn) ?
'NULL' :
"'".$this->db->escape($this->ref_fourn).
"'");
319 $resql = $this->db->query($sql);
322 $this->errors[] =
"Error ".$this->db->lasterror();
326 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
330 $result = $this->call_trigger(
'LINERECEPTION_CREATE', $user);
348 foreach ($this->errors as $errmsg) {
350 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
352 $this->db->rollback();
368 public function insert($user =
null, $notrigger = 0)
374 $origin_id = $this->origin_id;
375 if ($origin_id > 0) {
376 if ((empty($this->fk_reception)
377 || (empty($this->fk_elementdet))
378 || !is_numeric($this->qty))) {
379 $langs->load(
'errors');
380 $this->errors[] = $langs->trans(
'ErrorMandatoryParametersNotProvided');
384 if (empty($this->fk_reception) || !is_numeric($this->qty)) {
385 $langs->load(
'errors');
386 $this->errors[] = $langs->trans(
'ErrorMandatoryParametersNotProvided');
392 if (empty($this->rang)) {
397 $ranktouse = $this->rang;
398 if ($ranktouse == -1) {
399 $rangmax = $this->
line_max($this->fk_reception);
400 $ranktouse = $rangmax + 1;
403 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"receptiondet_batch (";
404 $sql .=
"fk_reception";
405 $sql .=
", fk_entrepot";
406 $sql .=
", fk_elementdet";
407 $sql .=
", fk_product";
408 $sql .=
", element_type";
411 $sql .=
", description";
413 $sql .=
") VALUES (";
414 $sql .= ((int) $this->fk_reception);
415 $sql .=
", ".(empty($this->fk_entrepot) ?
'NULL' : ((int) $this->fk_entrepot));
416 $sql .=
", ".(empty($this->fk_elementdet) ?
'NULL' : ((int) $this->fk_elementdet));
417 $sql .=
", ".(empty($this->fk_product) ?
'NULL' : ((int) $this->fk_product));
418 $sql .=
", '".(empty($this->element_type) ?
'order' : $this->db->escape($this->element_type)).
"'";
419 $sql .=
", ".price2num($this->qty,
'MS');
420 $sql .=
", ".((int) $this->fk_unit);
422 $sql .=
", ".((int) $ranktouse);
425 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
426 $resql = $this->db->query($sql);
428 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"receptiondet_batch");
437 if (!$error && !$notrigger) {
439 $result = $this->call_trigger(
'LINERECEPTION_INSERT', $user);
447 foreach ($this->errors as $errmsg) {
449 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
457 $this->db->rollback();
472 public function fetch($id, $ref =
'')
476 $sql .=
" t.fk_element,";
477 $sql .=
" t.fk_elementdet,";
478 $sql .=
" t.element_type,";
479 $sql .=
" t.fk_product,";
481 $sql .=
" t.fk_entrepot,";
482 $sql .=
" t.fk_user,";
484 $sql .=
" t.comment,";
485 $sql .=
" t.status,";
489 $sql .=
" t.sellby,";
490 $sql .=
" t.fk_unit,";
491 $sql .=
" t.description,";
493 $sql .=
" t.fk_reception";
494 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
496 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
498 $sql .=
" WHERE t.rowid = ".((int) $id);
502 $resql = $this->db->query($sql);
504 if ($this->db->num_rows($resql)) {
505 $obj = $this->db->fetch_object($resql);
507 $this->
id = $obj->rowid;
509 $this->fk_element = $obj->fk_element;
510 $this->origin_id = $obj->fk_element;
511 $this->fk_elementdet = $obj->fk_elementdet;
512 $this->origin_line_id = $obj->fk_elementdet;
513 $this->element_type = $obj->element_type;
514 $this->origin_type = $obj->element_type;
515 $this->fk_product = $obj->fk_product;
516 $this->qty = $obj->qty;
517 $this->fk_entrepot = $obj->fk_entrepot;
518 $this->fk_user = $obj->fk_user;
519 $this->datec = $this->db->jdate($obj->datec);
520 $this->comment = $obj->comment;
521 $this->
status = $obj->status;
522 $this->tms = $this->db->jdate($obj->tms);
523 $this->batch = $obj->batch;
524 $this->eatby = $this->db->jdate($obj->eatby);
525 $this->sellby = $this->db->jdate($obj->sellby);
527 $this->fk_unit = $obj->fk_unit;
528 $this->rang = $obj->rang;
529 $this->fk_reception = $obj->fk_reception;
533 $this->db->free($resql);
537 $this->error =
"Error ".$this->db->lasterror();
550 public function update($user, $notrigger = 0)
556 if (isset($this->fk_element)) {
557 $this->fk_element = (int) $this->fk_element;
559 if (isset($this->fk_product)) {
560 $this->fk_product = (int) $this->fk_product;
562 if (isset($this->fk_elementdet)) {
563 $this->fk_elementdet = (int) $this->fk_elementdet;
565 if (isset($this->qty)) {
566 $this->qty = (float) $this->qty;
568 if (isset($this->fk_entrepot)) {
569 $this->fk_entrepot = (int) $this->fk_entrepot;
571 if (isset($this->fk_user)) {
572 $this->fk_user = (int) $this->fk_user;
574 if (isset($this->comment)) {
575 $this->comment = trim($this->comment);
577 if (isset($this->
status)) {
580 if (isset($this->batch)) {
581 $this->batch = trim($this->batch);
589 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
590 $sql .=
" fk_element=".(isset($this->fk_element) ? ((int) $this->fk_element) :
"null").
",";
591 $sql .=
" fk_product=".(isset($this->fk_product) ? ((int) $this->fk_product) :
"null").
",";
592 $sql .=
" fk_elementdet=".(isset($this->fk_elementdet) ? ((int) $this->fk_elementdet) :
"null").
",";
593 $sql .=
" qty=".(isset($this->qty) ? ((float) $this->qty) :
"null").
",";
594 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? ((int) $this->fk_entrepot) :
"null").
",";
595 $sql .=
" fk_user=".(isset($this->fk_user) ? ((int) $this->fk_user) :
"null").
",";
596 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
597 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
598 $sql .=
" status=".(isset($this->
status) ? ((int) $this->
status) :
"null").
",";
599 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
600 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
601 $sql .=
" eatby=".(dol_strlen((
string) $this->eatby) != 0 ?
"'".$this->db->idate((
int) $this->eatby).
"'" :
'null').
",";
602 $sql .=
" sellby=".(dol_strlen((
string) $this->sellby) != 0 ?
"'".$this->db->idate((
int) $this->sellby).
"'" :
'null').
",";
603 $sql .=
" fk_unit = ".((int) $this->fk_unit);
604 $sql .=
" WHERE rowid=".((int) $this->
id);
609 $resql = $this->db->query($sql);
612 $this->errors[] =
"Error ".$this->db->lasterror();
616 if (empty($this->
id) && !empty($this->rowid)) {
617 $this->
id = $this->rowid;
626 $result = $this->call_trigger(
'LINERECEPTION_MODIFY', $user);
636 foreach ($this->errors as $errmsg) {
638 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
640 $this->db->rollback();
656 public function delete($user, $notrigger = 0)
664 $result = $this->call_trigger(
'LINERECEPTION_DELETE', $user);
677 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
682 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
683 $sql .=
" WHERE rowid=".((int) $this->
id);
686 $resql = $this->db->query($sql);
689 $this->errors[] =
"Error ".$this->db->lasterror();
695 foreach ($this->errors as $errmsg) {
697 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
699 $this->db->rollback();
733 $object->context[
'createfromclone'] =
'createfromclone';
734 $result =
$object->create($user);
745 unset(
$object->context[
'createfromclone']);
752 $this->db->rollback();
781 $langs->load(
'orders');
784 return $langs->trans($this->labelStatus[$status]);
785 } elseif ($mode == 1) {
786 return $langs->trans($this->labelStatusShort[$status]);
787 } elseif ($mode == 2) {
788 return $langs->trans($this->labelStatus[$status]);
789 } elseif ($mode == 3) {
791 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
792 } elseif ($status == 1) {
793 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
794 } elseif ($status == 2) {
795 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
797 } elseif ($mode == 4) {
799 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
800 } elseif ($status == 1) {
801 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4').
' '.$langs->trans($this->labelStatus[$status]);
802 } elseif ($status == 2) {
803 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8').
' '.$langs->trans($this->labelStatus[$status]);
805 } elseif ($mode == 5) {
807 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
808 } elseif ($status == 1) {
809 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
810 } elseif ($status == 2) {
811 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
828 $this->fk_element = 0;
829 $this->fk_product = 0;
830 $this->fk_elementdet = 0;
832 $this->fk_entrepot = 0;
840 $this->sellby =
null;
857 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
863 $sql .=
" t.fk_element,";
864 $sql .=
" t.fk_product,";
865 $sql .=
" t.fk_elementdet,";
867 $sql .=
" t.fk_entrepot,";
868 $sql .=
" t.fk_user,";
870 $sql .=
" t.comment,";
871 $sql .=
" t.status,";
875 $sql .=
" t.sellby,";
876 $sql .=
" t.fk_unit,";
877 $sql .=
" t.description,";
879 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
882 if (is_array($filter)) {
884 if (count($filter) > 0) {
885 foreach ($filter as $key => $value) {
886 if ($key ==
't.comment') {
887 $sqlwhere [] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
888 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
889 $sqlwhere [] = $this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
890 } elseif ($key ==
'qty') {
891 $sqlwhere [] = $this->db->sanitize($key).
" = ".((float) $value);
893 $sqlwhere [] = $this->db->sanitize($key).
" = ".((int) $value);
897 if (count($sqlwhere) > 0) {
898 $sql .=
' WHERE '.implode(
' '.$this->db->sanitize($filtermode).
' ', $sqlwhere);
908 $this->errors[] = $errormessage;
909 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
913 if (!empty($sortfield)) {
914 $sql .= $this->db->order($sortfield, $sortorder);
916 if (!empty($limit)) {
917 $sql .= $this->db->plimit($limit, $offset);
919 $this->lines = array();
921 $resql = $this->db->query($sql);
923 $num = $this->db->num_rows($resql);
925 while ($obj = $this->db->fetch_object($resql)) {
926 $line =
new self($this->db);
928 $line->id = $obj->rowid;
930 $line->fk_element = $obj->fk_element;
931 $line->fk_product = $obj->fk_product;
932 $line->fk_elementdet = $obj->fk_elementdet;
933 $line->qty = $obj->qty;
934 $line->fk_entrepot = $obj->fk_entrepot;
935 $line->fk_user = $obj->fk_user;
936 $line->datec = $this->db->jdate($obj->datec);
937 $line->comment = $obj->comment;
938 $line->status = $obj->status;
939 $line->tms = $this->db->jdate($obj->tms);
940 $line->batch = $obj->batch;
941 $line->eatby = $this->db->jdate($obj->eatby);
942 $line->sellby = $this->db->jdate($obj->sellby);
943 $line->description = $obj->description;
944 $line->fk_unit = $obj->fk_unit;
945 $line->rang = $obj->rang;
946 $line->fetch_optionals();
948 $this->lines[$line->id] = $line;
950 $this->db->free($resql);
954 $this->errors[] =
'Error '.$this->db->lasterror();
955 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
if(! $sortfield) if(! $sortorder) $object
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...
setErrorsFromObject($object)
setErrorsFromObject
deleteExtraFields()
Delete all extra fields values for the current object.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage table commandefournisseurdispatch.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct($db)
Constructor.
insert($user=null, $notrigger=0)
Insert line into database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update($user, $notrigger=0)
Update object into database.
LibStatut($status, $mode=0)
Return label of a status.
$table_element
Name of table without prefix where object is stored.
create($user, $notrigger=0)
Create object into database.
getLibStatut($mode=0)
Return label of the status of object.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load object in memory from the database.
fetch($id, $ref='')
Load object in memory from the database.
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...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)