29require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
30require_once DOL_DOCUMENT_ROOT.
"/reception/class/reception.class.php";
46 public $element =
'receptionlinebatch';
52 public $lines = array();
77 public $fk_elementdet;
82 public $origin_line_id;
123 public $vat_src_code;
127 public $ref_supplier;
160 public $eatby =
null;
164 public $sellby =
null;
168 public $cost_price = 0;
183 $this->labelStatus[0] =
'Received';
184 $this->labelStatus[1] =
'Verified';
185 $this->labelStatus[2] =
'Denied';
186 $this->labelStatusShort[0] =
'Received';
187 $this->labelStatusShort[1] =
'Verified';
188 $this->labelStatusShort[2] =
'Denied';
199 public function create($user, $notrigger = 0)
204 if (isset($this->fk_element)) {
205 $this->fk_element = (int) $this->fk_element;
207 if (isset($this->fk_product)) {
208 $this->fk_product = (int) $this->fk_product;
210 if (isset($this->fk_elementdet)) {
211 $this->fk_elementdet = (int) $this->fk_elementdet;
213 if (isset($this->qty)) {
214 $this->qty = (float) $this->qty;
216 if (isset($this->fk_entrepot)) {
217 $this->fk_entrepot = (int) $this->fk_entrepot;
219 if (isset($this->fk_user)) {
220 $this->fk_user = (int) $this->fk_user;
222 if (isset($this->comment)) {
223 $this->comment = trim($this->comment);
225 if (isset($this->
status)) {
228 if (isset($this->batch)) {
229 $this->batch = trim($this->batch);
231 if (empty($this->datec)) {
236 if (empty($this->fk_product)) {
237 $this->error =
'Error, property ->fk_product must not be empty to create a line of reception';
240 if (empty($this->fk_reception)) {
241 $this->error =
'Error, property ->fk_reception must not be empty to create a line of reception';
246 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
247 $sql .=
"fk_product,";
248 $sql .=
"fk_element,";
249 $sql .=
"fk_elementdet,";
250 $sql .=
"element_type,";
252 $sql .=
"fk_entrepot,";
260 $sql .=
"fk_reception,";
261 $sql .=
"cost_price";
262 $sql .=
") VALUES (";
263 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : (int) $this->fk_product).
",";
264 $sql .=
" ".(!isset($this->fk_element) ?
'NULL' : (int) $this->fk_element).
",";
265 $sql .=
" ".(!isset($this->fk_elementdet) ?
'NULL' : (int) $this->fk_elementdet).
",";
266 $sql .=
" '".(!isset($this->element_type) ?
"supplier_order" : $this->db->escape($this->element_type)).
"',";
267 $sql .=
" ".(!isset($this->qty) ?
'NULL' : (float) $this->qty).
",";
268 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' : (int) $this->fk_entrepot).
",";
269 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' : (int) $this->fk_user).
",";
270 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
271 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
272 $sql .=
" ".(!isset($this->
status) ?
'NULL' : (int) $this->
status).
",";
273 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
274 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen((
string) $this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
275 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen((
string) $this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
276 $sql .=
" ".((int) $this->fk_reception).
",";
277 $sql .=
" ".(!isset($this->cost_price) ?
'0' : (float) $this->cost_price);
283 $resql = $this->db->query($sql);
286 $this->errors[] =
"Error ".$this->db->lasterror();
290 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
294 $result = $this->
call_trigger(
'LINERECEPTION_CREATE', $user);
312 foreach ($this->errors as $errmsg) {
314 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
316 $this->db->rollback();
332 public function fetch($id, $ref =
'')
336 $sql .=
" t.fk_element,";
337 $sql .=
" t.fk_elementdet,";
338 $sql .=
" t.element_type,";
339 $sql .=
" t.fk_product,";
341 $sql .=
" t.fk_entrepot,";
342 $sql .=
" t.fk_user,";
344 $sql .=
" t.comment,";
345 $sql .=
" t.status,";
349 $sql .=
" t.sellby,";
350 $sql .=
" t.fk_reception";
351 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
353 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
355 $sql .=
" WHERE t.rowid = ".((int) $id);
359 $resql = $this->db->query($sql);
361 if ($this->db->num_rows($resql)) {
362 $obj = $this->db->fetch_object($resql);
364 $this->
id = $obj->rowid;
366 $this->fk_element = $obj->fk_element;
367 $this->origin_id = $obj->fk_element;
368 $this->fk_elementdet = $obj->fk_elementdet;
369 $this->origin_line_id = $obj->fk_elementdet;
370 $this->element_type = $obj->element_type;
371 $this->origin_type = $obj->element_type;
373 $this->fk_product = $obj->fk_product;
374 $this->qty = $obj->qty;
375 $this->fk_entrepot = $obj->fk_entrepot;
376 $this->fk_user = $obj->fk_user;
377 $this->datec = $this->db->jdate($obj->datec);
378 $this->comment = $obj->comment;
379 $this->
status = $obj->status;
380 $this->tms = $this->db->jdate($obj->tms);
381 $this->batch = $obj->batch;
382 $this->eatby = $this->db->jdate($obj->eatby);
383 $this->sellby = $this->db->jdate($obj->sellby);
384 $this->fk_reception = $obj->fk_reception;
388 $this->db->free($resql);
392 $this->error =
"Error ".$this->db->lasterror();
405 public function update($user, $notrigger = 0)
411 if (isset($this->fk_element)) {
412 $this->fk_element = (int) $this->fk_element;
414 if (isset($this->fk_product)) {
415 $this->fk_product = (int) $this->fk_product;
417 if (isset($this->fk_elementdet)) {
418 $this->fk_elementdet = (int) $this->fk_elementdet;
420 if (isset($this->qty)) {
421 $this->qty = (float) $this->qty;
423 if (isset($this->fk_entrepot)) {
424 $this->fk_entrepot = (int) $this->fk_entrepot;
426 if (isset($this->fk_user)) {
427 $this->fk_user = (int) $this->fk_user;
429 if (isset($this->comment)) {
430 $this->comment = trim($this->comment);
432 if (isset($this->
status)) {
435 if (isset($this->batch)) {
436 $this->batch = trim($this->batch);
445 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
446 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
447 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
448 $sql .=
" fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet :
"null").
",";
449 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
450 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
451 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
452 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
453 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
454 $sql .=
" status=".(isset($this->
status) ? $this->
status :
"null").
",";
455 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
456 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
457 $sql .=
" eatby=".(dol_strlen((
string) $this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
458 $sql .=
" sellby=".(dol_strlen((
string) $this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null');
459 $sql .=
" WHERE rowid=".((int) $this->
id);
464 $resql = $this->db->query($sql);
467 $this->errors[] =
"Error ".$this->db->lasterror();
471 if (empty($this->
id) && !empty($this->rowid)) {
472 $this->
id = $this->rowid;
481 $result = $this->
call_trigger(
'LINERECEPTION_MODIFY', $user);
491 foreach ($this->errors as $errmsg) {
493 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
495 $this->db->rollback();
511 public function delete($user, $notrigger = 0)
520 $result = $this->
call_trigger(
'LINERECEPTION_DELETE', $user);
533 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
538 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
539 $sql .=
" WHERE rowid=".((int) $this->
id);
542 $resql = $this->db->query($sql);
545 $this->errors[] =
"Error ".$this->db->lasterror();
551 foreach ($this->errors as $errmsg) {
553 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
555 $this->db->rollback();
588 $object->context[
'createfromclone'] =
'createfromclone';
589 $result =
$object->create($user);
600 unset(
$object->context[
'createfromclone']);
607 $this->db->rollback();
637 $langs->load(
'orders');
640 return $langs->trans($this->labelStatus[$status]);
641 } elseif ($mode == 1) {
642 return $langs->trans($this->labelStatusShort[$status]);
643 } elseif ($mode == 2) {
644 return $langs->trans($this->labelStatus[$status]);
645 } elseif ($mode == 3) {
647 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
648 } elseif ($status == 1) {
649 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
650 } elseif ($status == 2) {
651 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
653 } elseif ($mode == 4) {
655 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
656 } elseif ($status == 1) {
657 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4').
' '.$langs->trans($this->labelStatus[$status]);
658 } elseif ($status == 2) {
659 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8').
' '.$langs->trans($this->labelStatus[$status]);
661 } elseif ($mode == 5) {
663 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
664 } elseif ($status == 1) {
665 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
666 } elseif ($status == 2) {
667 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
684 $this->fk_element = 0;
685 $this->fk_product = 0;
686 $this->fk_elementdet = 0;
688 $this->fk_entrepot = 0;
696 $this->sellby =
null;
712 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
718 $sql .=
" t.fk_element,";
719 $sql .=
" t.fk_product,";
720 $sql .=
" t.fk_elementdet,";
722 $sql .=
" t.fk_entrepot,";
723 $sql .=
" t.fk_user,";
725 $sql .=
" t.comment,";
726 $sql .=
" t.status,";
731 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
734 if (is_array($filter)) {
736 if (count($filter) > 0) {
737 foreach ($filter as $key => $value) {
738 if ($key ==
't.comment') {
739 $sqlwhere [] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
740 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
741 $sqlwhere [] = $this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
742 } elseif ($key ==
'qty') {
743 $sqlwhere [] = $this->db->sanitize($key).
" = ".((float) $value);
745 $sqlwhere [] = $this->db->sanitize($key).
" = ".((int) $value);
749 if (count($sqlwhere) > 0) {
750 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
760 $this->errors[] = $errormessage;
761 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
765 if (!empty($sortfield)) {
766 $sql .= $this->db->order($sortfield, $sortorder);
768 if (!empty($limit)) {
769 $sql .= $this->db->plimit($limit, $offset);
771 $this->lines = array();
773 $resql = $this->db->query($sql);
775 $num = $this->db->num_rows($resql);
777 while ($obj = $this->db->fetch_object($resql)) {
778 $line =
new self($this->db);
780 $line->id = $obj->rowid;
782 $line->fk_element = $obj->fk_element;
783 $line->fk_product = $obj->fk_product;
784 $line->fk_elementdet = $obj->fk_elementdet;
785 $line->qty = $obj->qty;
786 $line->fk_entrepot = $obj->fk_entrepot;
787 $line->fk_user = $obj->fk_user;
788 $line->datec = $this->db->jdate($obj->datec);
789 $line->comment = $obj->comment;
790 $line->status = $obj->status;
791 $line->tms = $this->db->jdate($obj->tms);
792 $line->batch = $obj->batch;
793 $line->eatby = $this->db->jdate($obj->eatby);
794 $line->sellby = $this->db->jdate($obj->sellby);
795 $line->fetch_optionals();
797 $this->lines[$line->id] = $line;
799 $this->db->free($resql);
803 $this->errors[] =
'Error '.$this->db->lasterror();
804 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.