31require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
32require_once DOL_DOCUMENT_ROOT.
"/reception/class/reception.class.php";
44 public $TRIGGER_PREFIX =
'LINERECEPTION';
54 public $element =
'receptionlinebatch';
60 public $lines = array();
85 public $fk_elementdet;
90 public $origin_line_id;
131 public $vat_src_code;
135 public $ref_supplier;
168 public $eatby =
null;
172 public $sellby =
null;
176 public $cost_price = 0;
193 $this->labelStatus[0] =
'Received';
194 $this->labelStatus[1] =
'Verified';
195 $this->labelStatus[2] =
'Denied';
196 $this->labelStatusShort[0] =
'Received';
197 $this->labelStatusShort[1] =
'Verified';
198 $this->labelStatusShort[2] =
'Denied';
209 public function create($user, $notrigger = 0)
214 if (isset($this->fk_element)) {
215 $this->fk_element = (int) $this->fk_element;
217 if (isset($this->fk_product)) {
218 $this->fk_product = (int) $this->fk_product;
220 if (isset($this->fk_elementdet)) {
221 $this->fk_elementdet = (int) $this->fk_elementdet;
223 if (isset($this->qty)) {
224 $this->qty = (float) $this->qty;
226 if (isset($this->fk_entrepot)) {
227 $this->fk_entrepot = (int) $this->fk_entrepot;
229 if (isset($this->fk_user)) {
230 $this->fk_user = (int) $this->fk_user;
232 if (isset($this->comment)) {
233 $this->comment = trim($this->comment);
235 if (isset($this->
status)) {
238 if (isset($this->batch)) {
239 $this->batch = trim($this->batch);
241 if (empty($this->datec)) {
246 if (empty($this->fk_product)) {
247 $this->error =
'Error, property ->fk_product must not be empty to create a line of reception';
250 if (empty($this->fk_reception)) {
251 $this->error =
'Error, property ->fk_reception must not be empty to create a line of reception';
256 if (empty($this->rang)) {
261 $ranktouse = $this->rang;
262 if ($ranktouse == -1) {
263 $rangmax = $this->
line_max($this->fk_reception);
264 $ranktouse = $rangmax + 1;
268 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
269 $sql .=
"fk_product,";
270 $sql .=
"fk_element,";
271 $sql .=
"fk_elementdet,";
272 $sql .=
"element_type,";
274 $sql .=
"fk_entrepot,";
283 $sql .=
"description,";
285 $sql .=
"fk_reception,";
286 $sql .=
"cost_price";
287 $sql .=
") VALUES (";
288 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : (int) $this->fk_product).
",";
289 $sql .=
" ".(!isset($this->fk_element) ?
'NULL' : (int) $this->fk_element).
",";
290 $sql .=
" ".(!isset($this->fk_elementdet) ?
'NULL' : (int) $this->fk_elementdet).
",";
291 $sql .=
" '".(!isset($this->element_type) ?
"supplier_order" : $this->db->escape($this->element_type)).
"',";
292 $sql .=
" ".(!isset($this->qty) ?
'NULL' : (float) $this->qty).
",";
293 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' : (int) $this->fk_entrepot).
",";
294 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' : (int) $this->fk_user).
",";
295 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
296 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
297 $sql .=
" ".(!isset($this->
status) ?
'NULL' : (int) $this->
status).
",";
298 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
299 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen((
string) $this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
300 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen((
string) $this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
301 $sql .=
" ".((int) $this->fk_unit);
303 $sql .=
", ".((int) $ranktouse).
",";
304 $sql .=
" ".((int) $this->fk_reception).
",";
305 $sql .=
" ".(!isset($this->cost_price) ?
'0' : (float) $this->cost_price);
311 $resql = $this->db->query($sql);
314 $this->errors[] =
"Error ".$this->db->lasterror();
318 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
322 $result = $this->call_trigger(
'LINERECEPTION_CREATE', $user);
340 foreach ($this->errors as $errmsg) {
342 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
344 $this->db->rollback();
360 public function insert($user =
null, $notrigger = 0)
366 $origin_id = $this->origin_id;
367 if ($origin_id > 0) {
368 if ((empty($this->fk_reception)
369 || (empty($this->fk_elementdet))
370 || !is_numeric($this->qty))) {
371 $langs->load(
'errors');
372 $this->errors[] = $langs->trans(
'ErrorMandatoryParametersNotProvided');
376 if (empty($this->fk_reception) || !is_numeric($this->qty)) {
377 $langs->load(
'errors');
378 $this->errors[] = $langs->trans(
'ErrorMandatoryParametersNotProvided');
384 if (empty($this->rang)) {
389 $ranktouse = $this->rang;
390 if ($ranktouse == -1) {
391 $rangmax = $this->
line_max($this->fk_reception);
392 $ranktouse = $rangmax + 1;
395 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"receptiondet_batch (";
396 $sql .=
"fk_reception";
397 $sql .=
", fk_entrepot";
398 $sql .=
", fk_elementdet";
399 $sql .=
", fk_product";
400 $sql .=
", element_type";
403 $sql .=
", description";
405 $sql .=
") VALUES (";
406 $sql .= $this->fk_reception;
407 $sql .=
", ".(empty($this->fk_entrepot) ?
'NULL' : $this->fk_entrepot);
408 $sql .=
", ".(empty($this->fk_elementdet) ?
'NULL' : $this->fk_elementdet);
409 $sql .=
", ".(empty($this->fk_product) ?
'NULL' : $this->fk_product);
410 $sql .=
", '".(empty($this->element_type) ?
'order' : $this->db->escape($this->element_type)).
"'";
411 $sql .=
", ".price2num($this->qty,
'MS');
412 $sql .=
", ".((int) $this->fk_unit);
414 $sql .=
", ".((int) $ranktouse);
417 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
418 $resql = $this->db->query($sql);
420 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"receptiondet_batch");
429 if (!$error && !$notrigger) {
431 $result = $this->call_trigger(
'LINERECEPTION_INSERT', $user);
439 foreach ($this->errors as $errmsg) {
441 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
449 $this->db->rollback();
464 public function fetch($id, $ref =
'')
468 $sql .=
" t.fk_element,";
469 $sql .=
" t.fk_elementdet,";
470 $sql .=
" t.element_type,";
471 $sql .=
" t.fk_product,";
473 $sql .=
" t.fk_entrepot,";
474 $sql .=
" t.fk_user,";
476 $sql .=
" t.comment,";
477 $sql .=
" t.status,";
481 $sql .=
" t.sellby,";
482 $sql .=
" t.fk_unit,";
483 $sql .=
" t.description,";
485 $sql .=
" t.fk_reception";
486 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
488 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
490 $sql .=
" WHERE t.rowid = ".((int) $id);
494 $resql = $this->db->query($sql);
496 if ($this->db->num_rows($resql)) {
497 $obj = $this->db->fetch_object($resql);
499 $this->
id = $obj->rowid;
501 $this->fk_element = $obj->fk_element;
502 $this->origin_id = $obj->fk_element;
503 $this->fk_elementdet = $obj->fk_elementdet;
504 $this->origin_line_id = $obj->fk_elementdet;
505 $this->element_type = $obj->element_type;
506 $this->origin_type = $obj->element_type;
507 $this->fk_product = $obj->fk_product;
508 $this->qty = $obj->qty;
509 $this->fk_entrepot = $obj->fk_entrepot;
510 $this->fk_user = $obj->fk_user;
511 $this->datec = $this->db->jdate($obj->datec);
512 $this->comment = $obj->comment;
513 $this->
status = $obj->status;
514 $this->tms = $this->db->jdate($obj->tms);
515 $this->batch = $obj->batch;
516 $this->eatby = $this->db->jdate($obj->eatby);
517 $this->sellby = $this->db->jdate($obj->sellby);
519 $this->fk_unit = $obj->fk_unit;
520 $this->rang = $obj->rang;
521 $this->fk_reception = $obj->fk_reception;
525 $this->db->free($resql);
529 $this->error =
"Error ".$this->db->lasterror();
542 public function update($user, $notrigger = 0)
548 if (isset($this->fk_element)) {
549 $this->fk_element = (int) $this->fk_element;
551 if (isset($this->fk_product)) {
552 $this->fk_product = (int) $this->fk_product;
554 if (isset($this->fk_elementdet)) {
555 $this->fk_elementdet = (int) $this->fk_elementdet;
557 if (isset($this->qty)) {
558 $this->qty = (float) $this->qty;
560 if (isset($this->fk_entrepot)) {
561 $this->fk_entrepot = (int) $this->fk_entrepot;
563 if (isset($this->fk_user)) {
564 $this->fk_user = (int) $this->fk_user;
566 if (isset($this->comment)) {
567 $this->comment = trim($this->comment);
569 if (isset($this->
status)) {
572 if (isset($this->batch)) {
573 $this->batch = trim($this->batch);
581 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
582 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
583 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
584 $sql .=
" fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet :
"null").
",";
585 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
586 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
587 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
588 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
589 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
590 $sql .=
" status=".(isset($this->
status) ? $this->
status :
"null").
",";
591 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
592 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
593 $sql .=
" eatby=".(dol_strlen((
string) $this->eatby) != 0 ?
"'".$this->db->idate((
int) $this->eatby).
"'" :
'null').
",";
594 $sql .=
" sellby=".(dol_strlen((
string) $this->sellby) != 0 ?
"'".$this->db->idate((
int) $this->sellby).
"'" :
'null').
",";
595 $sql .=
" fk_unit = ".((int) $this->fk_unit);
596 $sql .=
" WHERE rowid=".((int) $this->
id);
601 $resql = $this->db->query($sql);
604 $this->errors[] =
"Error ".$this->db->lasterror();
608 if (empty($this->
id) && !empty($this->rowid)) {
609 $this->
id = $this->rowid;
618 $result = $this->call_trigger(
'LINERECEPTION_MODIFY', $user);
628 foreach ($this->errors as $errmsg) {
630 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
632 $this->db->rollback();
648 public function delete($user, $notrigger = 0)
656 $result = $this->call_trigger(
'LINERECEPTION_DELETE', $user);
669 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
674 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
675 $sql .=
" WHERE rowid=".((int) $this->
id);
678 $resql = $this->db->query($sql);
681 $this->errors[] =
"Error ".$this->db->lasterror();
687 foreach ($this->errors as $errmsg) {
689 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
691 $this->db->rollback();
725 $object->context[
'createfromclone'] =
'createfromclone';
726 $result =
$object->create($user);
737 unset(
$object->context[
'createfromclone']);
744 $this->db->rollback();
773 $langs->load(
'orders');
776 return $langs->trans($this->labelStatus[$status]);
777 } elseif ($mode == 1) {
778 return $langs->trans($this->labelStatusShort[$status]);
779 } elseif ($mode == 2) {
780 return $langs->trans($this->labelStatus[$status]);
781 } elseif ($mode == 3) {
783 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
784 } elseif ($status == 1) {
785 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
786 } elseif ($status == 2) {
787 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
789 } elseif ($mode == 4) {
791 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
792 } elseif ($status == 1) {
793 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4').
' '.$langs->trans($this->labelStatus[$status]);
794 } elseif ($status == 2) {
795 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8').
' '.$langs->trans($this->labelStatus[$status]);
797 } elseif ($mode == 5) {
799 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
800 } elseif ($status == 1) {
801 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
802 } elseif ($status == 2) {
803 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
820 $this->fk_element = 0;
821 $this->fk_product = 0;
822 $this->fk_elementdet = 0;
824 $this->fk_entrepot = 0;
832 $this->sellby =
null;
849 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
855 $sql .=
" t.fk_element,";
856 $sql .=
" t.fk_product,";
857 $sql .=
" t.fk_elementdet,";
859 $sql .=
" t.fk_entrepot,";
860 $sql .=
" t.fk_user,";
862 $sql .=
" t.comment,";
863 $sql .=
" t.status,";
867 $sql .=
" t.sellby,";
868 $sql .=
" t.fk_unit,";
869 $sql .=
" t.description,";
871 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
874 if (is_array($filter)) {
876 if (count($filter) > 0) {
877 foreach ($filter as $key => $value) {
878 if ($key ==
't.comment') {
879 $sqlwhere [] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
880 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
881 $sqlwhere [] = $this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
882 } elseif ($key ==
'qty') {
883 $sqlwhere [] = $this->db->sanitize($key).
" = ".((float) $value);
885 $sqlwhere [] = $this->db->sanitize($key).
" = ".((int) $value);
889 if (count($sqlwhere) > 0) {
890 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
898 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
900 $this->errors[] = $errormessage;
901 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
905 if (!empty($sortfield)) {
906 $sql .= $this->db->order($sortfield, $sortorder);
908 if (!empty($limit)) {
909 $sql .= $this->db->plimit($limit, $offset);
911 $this->lines = array();
913 $resql = $this->db->query($sql);
915 $num = $this->db->num_rows($resql);
917 while ($obj = $this->db->fetch_object($resql)) {
918 $line =
new self($this->db);
920 $line->id = $obj->rowid;
922 $line->fk_element = $obj->fk_element;
923 $line->fk_product = $obj->fk_product;
924 $line->fk_elementdet = $obj->fk_elementdet;
925 $line->qty = $obj->qty;
926 $line->fk_entrepot = $obj->fk_entrepot;
927 $line->fk_user = $obj->fk_user;
928 $line->datec = $this->db->jdate($obj->datec);
929 $line->comment = $obj->comment;
930 $line->status = $obj->status;
931 $line->tms = $this->db->jdate($obj->tms);
932 $line->batch = $obj->batch;
933 $line->eatby = $this->db->jdate($obj->eatby);
934 $line->sellby = $this->db->jdate($obj->sellby);
935 $line->description = $obj->description;
936 $line->fk_unit = $obj->fk_unit;
937 $line->rang = $obj->rang;
938 $line->fetch_optionals();
940 $this->lines[$line->id] = $line;
942 $this->db->free($resql);
946 $this->errors[] =
'Error '.$this->db->lasterror();
947 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.
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)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.