28require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
29require_once DOL_DOCUMENT_ROOT.
"/reception/class/reception.class.php";
45 public $element =
'receptionlinebatch';
51 public $lines = array();
76 public $fk_elementdet;
81 public $origin_line_id;
107 public $vat_src_code;
108 public $ref_supplier;
131 public $cost_price = 0;
146 $this->labelStatus[0] =
'Received';
147 $this->labelStatus[1] =
'Verified';
148 $this->labelStatus[2] =
'Denied';
149 $this->labelStatusShort[0] =
'Received';
150 $this->labelStatusShort[1] =
'Verified';
151 $this->labelStatusShort[2] =
'Denied';
162 public function create($user, $notrigger = 0)
167 if (isset($this->fk_element)) {
168 $this->fk_element = (int) $this->fk_element;
170 if (isset($this->fk_product)) {
171 $this->fk_product = (int) $this->fk_product;
173 if (isset($this->fk_elementdet)) {
174 $this->fk_elementdet = (int) $this->fk_elementdet;
176 if (isset($this->qty)) {
177 $this->qty = (float) $this->qty;
179 if (isset($this->fk_entrepot)) {
180 $this->fk_entrepot = (int) $this->fk_entrepot;
182 if (isset($this->fk_user)) {
183 $this->fk_user = (int) $this->fk_user;
185 if (isset($this->comment)) {
186 $this->comment = trim($this->comment);
188 if (isset($this->
status)) {
191 if (isset($this->batch)) {
192 $this->batch = trim($this->batch);
194 if (empty($this->datec)) {
199 if (empty($this->fk_product)) {
200 $this->error =
'Error, property ->fk_product must not be empty to create a line of reception';
203 if (empty($this->fk_reception)) {
204 $this->error =
'Error, property ->fk_reception must not be empty to create a line of reception';
209 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
210 $sql .=
"fk_product,";
211 $sql .=
"fk_element,";
212 $sql .=
"fk_elementdet,";
213 $sql .=
"element_type,";
215 $sql .=
"fk_entrepot,";
223 $sql .=
"fk_reception,";
224 $sql .=
"cost_price";
225 $sql .=
") VALUES (";
226 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : (int) $this->fk_product).
",";
227 $sql .=
" ".(!isset($this->fk_element) ?
'NULL' : (int) $this->fk_element).
",";
228 $sql .=
" ".(!isset($this->fk_elementdet) ?
'NULL' : (int) $this->fk_elementdet).
",";
229 $sql .=
" '".(!isset($this->element_type) ?
"supplier_order" : $this->db->escape($this->element_type)).
"',";
230 $sql .=
" ".(!isset($this->qty) ?
'NULL' : (float) $this->qty).
",";
231 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' : (int) $this->fk_entrepot).
",";
232 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' : (int) $this->fk_user).
",";
233 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
234 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
235 $sql .=
" ".(!isset($this->
status) ?
'NULL' : (int) $this->
status).
",";
236 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
237 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
238 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
239 $sql .=
" ".((int) $this->fk_reception).
",";
240 $sql .=
" ".(!isset($this->cost_price) ?
'0' : (float) $this->cost_price);
246 $resql = $this->db->query($sql);
249 $this->errors[] =
"Error ".$this->db->lasterror();
253 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
257 $result = $this->
call_trigger(
'LINERECEPTION_CREATE', $user);
275 foreach ($this->errors as $errmsg) {
277 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
279 $this->db->rollback();
295 public function fetch($id, $ref =
'')
299 $sql .=
" t.fk_element,";
300 $sql .=
" t.fk_elementdet,";
301 $sql .=
" t.element_type,";
302 $sql .=
" t.fk_product,";
304 $sql .=
" t.fk_entrepot,";
305 $sql .=
" t.fk_user,";
307 $sql .=
" t.comment,";
308 $sql .=
" t.status,";
312 $sql .=
" t.sellby,";
313 $sql .=
" t.fk_reception";
314 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
316 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
318 $sql .=
" WHERE t.rowid = ".((int) $id);
322 $resql = $this->db->query($sql);
324 if ($this->db->num_rows($resql)) {
325 $obj = $this->db->fetch_object($resql);
327 $this->
id = $obj->rowid;
329 $this->fk_element = $obj->fk_element;
330 $this->origin_id = $obj->fk_element;
331 $this->fk_elementdet = $obj->fk_elementdet;
332 $this->origin_line_id = $obj->fk_elementdet;
333 $this->element_type = $obj->element_type;
334 $this->origin_type = $obj->element_type;
336 $this->fk_product = $obj->fk_product;
337 $this->qty = $obj->qty;
338 $this->fk_entrepot = $obj->fk_entrepot;
339 $this->fk_user = $obj->fk_user;
340 $this->datec = $this->db->jdate($obj->datec);
341 $this->comment = $obj->comment;
342 $this->
status = $obj->status;
343 $this->tms = $this->db->jdate($obj->tms);
344 $this->batch = $obj->batch;
345 $this->eatby = $this->db->jdate($obj->eatby);
346 $this->sellby = $this->db->jdate($obj->sellby);
347 $this->fk_reception = $obj->fk_reception;
351 $this->db->free($resql);
355 $this->error =
"Error ".$this->db->lasterror();
368 public function update($user, $notrigger = 0)
374 if (isset($this->fk_element)) {
375 $this->fk_element = (int) $this->fk_element;
377 if (isset($this->fk_product)) {
378 $this->fk_product = (int) $this->fk_product;
380 if (isset($this->fk_elementdet)) {
381 $this->fk_elementdet = (int) $this->fk_elementdet;
383 if (isset($this->qty)) {
384 $this->qty = (float) $this->qty;
386 if (isset($this->fk_entrepot)) {
387 $this->fk_entrepot = (int) $this->fk_entrepot;
389 if (isset($this->fk_user)) {
390 $this->fk_user = (int) $this->fk_user;
392 if (isset($this->comment)) {
393 $this->comment = trim($this->comment);
395 if (isset($this->
status)) {
398 if (isset($this->batch)) {
399 $this->batch = trim($this->batch);
408 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
409 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
410 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
411 $sql .=
" fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet :
"null").
",";
412 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
413 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
414 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
415 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
416 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
417 $sql .=
" status=".(isset($this->
status) ? $this->
status :
"null").
",";
418 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
419 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
420 $sql .=
" eatby=".(dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
421 $sql .=
" sellby=".(dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null');
422 $sql .=
" WHERE rowid=".((int) $this->
id);
427 $resql = $this->db->query($sql);
430 $this->errors[] =
"Error ".$this->db->lasterror();
434 if (empty($this->
id) && !empty($this->
rowid)) {
435 $this->
id = $this->rowid;
444 $result = $this->
call_trigger(
'LINERECEPTION_MODIFY', $user);
454 foreach ($this->errors as $errmsg) {
456 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
458 $this->db->rollback();
474 public function delete($user, $notrigger = 0)
483 $result = $this->
call_trigger(
'LINERECEPTION_DELETE', $user);
496 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
501 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
502 $sql .=
" WHERE rowid=".((int) $this->
id);
505 $resql = $this->db->query($sql);
508 $this->errors[] =
"Error ".$this->db->lasterror();
514 foreach ($this->errors as $errmsg) {
516 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
518 $this->db->rollback();
551 $object->context[
'createfromclone'] =
'createfromclone';
552 $result =
$object->create($user);
563 unset(
$object->context[
'createfromclone']);
570 $this->db->rollback();
600 $langs->load(
'orders');
603 return $langs->trans($this->labelStatus[$status]);
604 } elseif ($mode == 1) {
605 return $langs->trans($this->labelStatusShort[$status]);
606 } elseif ($mode == 2) {
607 return $langs->trans($this->labelStatus[$status]);
608 } elseif ($mode == 3) {
610 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
611 } elseif ($status == 1) {
612 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
613 } elseif ($status == 2) {
614 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
616 } elseif ($mode == 4) {
618 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
619 } elseif ($status == 1) {
620 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4').
' '.$langs->trans($this->labelStatus[$status]);
621 } elseif ($status == 2) {
622 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8').
' '.$langs->trans($this->labelStatus[$status]);
624 } elseif ($mode == 5) {
626 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
627 } elseif ($status == 1) {
628 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
629 } elseif ($status == 2) {
630 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
647 $this->fk_element = 0;
648 $this->fk_product = 0;
649 $this->fk_elementdet = 0;
651 $this->fk_entrepot = 0;
675 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
681 $sql .=
" t.fk_element,";
682 $sql .=
" t.fk_product,";
683 $sql .=
" t.fk_elementdet,";
685 $sql .=
" t.fk_entrepot,";
686 $sql .=
" t.fk_user,";
688 $sql .=
" t.comment,";
689 $sql .=
" t.status,";
694 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
697 if (is_array($filter)) {
699 if (count($filter) > 0) {
700 foreach ($filter as $key => $value) {
701 if ($key ==
't.comment') {
702 $sqlwhere [] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
703 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
704 $sqlwhere [] = $this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
705 } elseif ($key ==
'qty') {
706 $sqlwhere [] = $this->db->sanitize($key).
" = ".((float) $value);
708 $sqlwhere [] = $this->db->sanitize($key).
" = ".((int) $value);
712 if (count($sqlwhere) > 0) {
713 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
723 $this->errors[] = $errormessage;
724 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
728 if (!empty($sortfield)) {
729 $sql .= $this->db->order($sortfield, $sortorder);
731 if (!empty($limit)) {
732 $sql .= $this->db->plimit($limit, $offset);
734 $this->lines = array();
736 $resql = $this->db->query($sql);
738 $num = $this->db->num_rows($resql);
740 while ($obj = $this->db->fetch_object($resql)) {
741 $line =
new self($this->db);
743 $line->id = $obj->rowid;
745 $line->fk_element = $obj->fk_element;
746 $line->fk_product = $obj->fk_product;
747 $line->fk_elementdet = $obj->fk_elementdet;
748 $line->qty = $obj->qty;
749 $line->fk_entrepot = $obj->fk_entrepot;
750 $line->fk_user = $obj->fk_user;
751 $line->datec = $this->db->jdate($obj->datec);
752 $line->comment = $obj->comment;
753 $line->status = $obj->status;
754 $line->tms = $this->db->jdate($obj->tms);
755 $line->batch = $obj->batch;
756 $line->eatby = $this->db->jdate($obj->eatby);
757 $line->sellby = $this->db->jdate($obj->sellby);
758 $line->fetch_optionals();
760 $this->lines[$line->id] = $line;
762 $this->db->free($resql);
766 $this->errors[] =
'Error '.$this->db->lasterror();
767 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid