28 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
29 require_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;
100 public $vat_src_code;
101 public $ref_supplier;
124 public $cost_price = 0;
139 $this->labelStatus[0] =
'Received';
140 $this->labelStatus[1] =
'Verified';
141 $this->labelStatus[2] =
'Denied';
142 $this->labelStatusShort[0] =
'Received';
143 $this->labelStatusShort[1] =
'Verified';
144 $this->labelStatusShort[2] =
'Denied';
155 public function create($user, $notrigger = 0)
160 if (isset($this->fk_element)) {
161 $this->fk_element = (int) $this->fk_element;
163 if (isset($this->fk_product)) {
164 $this->fk_product = (int) $this->fk_product;
166 if (isset($this->fk_elementdet)) {
167 $this->fk_elementdet = (int) $this->fk_elementdet;
169 if (isset($this->qty)) {
170 $this->qty = trim($this->qty);
172 if (isset($this->fk_entrepot)) {
173 $this->fk_entrepot = (int) $this->fk_entrepot;
175 if (isset($this->fk_user)) {
176 $this->fk_user = (int) $this->fk_user;
178 if (isset($this->comment)) {
179 $this->comment = trim($this->comment);
181 if (isset($this->
status)) {
184 if (isset($this->batch)) {
185 $this->batch = trim($this->batch);
187 if (empty($this->datec)) {
192 if (empty($this->fk_product)) {
193 $this->error =
'Error, property ->fk_product must not be empty to create a line of reception';
196 if (empty($this->fk_reception)) {
197 $this->error =
'Error, property ->fk_reception must not be empty to create a line of reception';
202 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
203 $sql .=
"fk_product,";
204 $sql .=
"fk_element,";
205 $sql .=
"fk_elementdet,";
206 $sql .=
"element_type,";
208 $sql .=
"fk_entrepot,";
216 $sql .=
"fk_reception,";
217 $sql .=
"cost_price";
218 $sql .=
") VALUES (";
219 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : (int) $this->fk_product).
",";
220 $sql .=
" ".(!isset($this->fk_element) ?
'NULL' : (int) $this->fk_element).
",";
221 $sql .=
" ".(!isset($this->fk_elementdet) ?
'NULL' : (int) $this->fk_elementdet).
",";
222 $sql .=
" '".(!isset($this->element_type) ?
"supplier_order" : $this->db->escape($this->element_type)).
"',";
223 $sql .=
" ".(!isset($this->qty) ?
'NULL' : (
float) $this->qty).
",";
224 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' : (int) $this->fk_entrepot).
",";
225 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' : (int) $this->fk_user).
",";
226 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
227 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
229 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
230 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
231 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
232 $sql .=
" ".((int) $this->fk_reception).
",";
233 $sql .=
" ".(!isset($this->cost_price) ?
'0' : (
float) $this->cost_price);
239 $resql = $this->db->query(
$sql);
242 $this->errors[] =
"Error ".$this->db->lasterror();
246 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
250 $result = $this->
call_trigger(
'LINERECEPTION_CREATE', $user);
268 foreach ($this->errors as $errmsg) {
270 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
272 $this->db->rollback();
288 public function fetch($id, $ref =
'')
292 $sql .=
" t.fk_element,";
293 $sql .=
" t.fk_elementdet,";
294 $sql .=
" t.element_type,";
295 $sql .=
" t.fk_product,";
297 $sql .=
" t.fk_entrepot,";
298 $sql .=
" t.fk_user,";
300 $sql .=
" t.comment,";
301 $sql .=
" t.status,";
305 $sql .=
" t.sellby,";
306 $sql .=
" t.fk_reception";
307 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
309 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
311 $sql .=
" WHERE t.rowid = ".((int) $id);
315 $resql = $this->db->query(
$sql);
317 if ($this->db->num_rows($resql)) {
318 $obj = $this->db->fetch_object($resql);
320 $this->
id = $obj->rowid;
322 $this->fk_element = $obj->fk_element;
323 $this->origin_id = $obj->fk_element;
324 $this->fk_elementdet = $obj->fk_elementdet;
325 $this->origin_line_id = $obj->fk_elementdet;
326 $this->element_type = $obj->element_type;
327 $this->origin_type = $obj->element_type;
329 $this->fk_product = $obj->fk_product;
330 $this->qty = $obj->qty;
331 $this->fk_entrepot = $obj->fk_entrepot;
332 $this->fk_user = $obj->fk_user;
333 $this->datec = $this->db->jdate($obj->datec);
334 $this->comment = $obj->comment;
335 $this->
status = $obj->status;
336 $this->tms = $this->db->jdate($obj->tms);
337 $this->batch = $obj->batch;
338 $this->eatby = $this->db->jdate($obj->eatby);
339 $this->sellby = $this->db->jdate($obj->sellby);
340 $this->fk_reception = $obj->fk_reception;
344 $this->db->free($resql);
348 $this->error =
"Error ".$this->db->lasterror();
361 public function update($user, $notrigger = 0)
367 if (isset($this->fk_element)) {
368 $this->fk_element = (int) $this->fk_element;
370 if (isset($this->fk_product)) {
371 $this->fk_product = (int) $this->fk_product;
373 if (isset($this->fk_elementdet)) {
374 $this->fk_elementdet = (int) $this->fk_elementdet;
376 if (isset($this->qty)) {
377 $this->qty = trim($this->qty);
379 if (isset($this->fk_entrepot)) {
380 $this->fk_entrepot = (int) $this->fk_entrepot;
382 if (isset($this->fk_user)) {
383 $this->fk_user = (int) $this->fk_user;
385 if (isset($this->comment)) {
386 $this->comment = trim($this->comment);
388 if (isset($this->
status)) {
391 if (isset($this->batch)) {
392 $this->batch = trim($this->batch);
401 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
402 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
403 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
404 $sql .=
" fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet :
"null").
",";
405 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
406 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
407 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
408 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
409 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
411 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
412 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
413 $sql .=
" eatby=".(dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
414 $sql .=
" sellby=".(dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null');
415 $sql .=
" WHERE rowid=".((int) $this->
id);
420 $resql = $this->db->query(
$sql);
423 $this->errors[] =
"Error ".$this->db->lasterror();
427 if (empty($this->
id) && !empty($this->
rowid)) {
428 $this->
id = $this->rowid;
437 $result = $this->
call_trigger(
'LINERECEPTION_MODIFY', $user);
447 foreach ($this->errors as $errmsg) {
449 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
451 $this->db->rollback();
467 public function delete($user, $notrigger = 0)
476 $result = $this->
call_trigger(
'LINERECEPTION_DELETE', $user);
489 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
494 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
495 $sql .=
" WHERE rowid=".((int) $this->
id);
498 $resql = $this->db->query(
$sql);
501 $this->errors[] =
"Error ".$this->db->lasterror();
507 foreach ($this->errors as $errmsg) {
509 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
511 $this->db->rollback();
544 $object->context[
'createfromclone'] =
'createfromclone';
545 $result =
$object->create($user);
556 unset(
$object->context[
'createfromclone']);
563 $this->db->rollback();
593 $langs->load(
'orders');
596 return $langs->trans($this->labelStatus[$status]);
597 } elseif ($mode == 1) {
598 return $langs->trans($this->labelStatusShort[$status]);
599 } elseif ($mode == 2) {
600 return $langs->trans($this->labelStatus[$status]);
601 } elseif ($mode == 3) {
603 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
604 } elseif ($status == 1) {
605 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
606 } elseif ($status == 2) {
607 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
609 } elseif ($mode == 4) {
611 return img_picto($langs->trans($this->labelStatus[$status]),
'statut0').
' '.$langs->trans($this->labelStatus[$status]);
612 } elseif ($status == 1) {
613 return img_picto($langs->trans($this->labelStatus[$status]),
'statut4').
' '.$langs->trans($this->labelStatus[$status]);
614 } elseif ($status == 2) {
615 return img_picto($langs->trans($this->labelStatus[$status]),
'statut8').
' '.$langs->trans($this->labelStatus[$status]);
617 } elseif ($mode == 5) {
619 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut0');
620 } elseif ($status == 1) {
621 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut4');
622 } elseif ($status == 2) {
623 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).
' </span>'.
img_picto($langs->trans($this->labelStatus[$status]),
'statut8');
640 $this->fk_element = 0;
641 $this->fk_product = 0;
642 $this->fk_elementdet = 0;
644 $this->fk_entrepot = 0;
668 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
674 $sql .=
" t.fk_element,";
675 $sql .=
" t.fk_product,";
676 $sql .=
" t.fk_elementdet,";
678 $sql .=
" t.fk_entrepot,";
679 $sql .=
" t.fk_user,";
681 $sql .=
" t.comment,";
682 $sql .=
" t.status,";
687 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
690 if (is_array($filter)) {
692 if (count($filter) > 0) {
693 foreach ($filter as $key => $value) {
694 if ($key ==
't.comment') {
695 $sqlwhere [] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
696 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
697 $sqlwhere [] = $this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
698 } elseif ($key ==
'qty') {
699 $sqlwhere [] = $this->db->sanitize($key).
" = ".((
float) $value);
701 $sqlwhere [] = $this->db->sanitize($key).
" = ".((int) $value);
705 if (count($sqlwhere) > 0) {
706 $sql .=
' WHERE '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
716 $this->errors[] = $errormessage;
717 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
721 if (!empty($sortfield)) {
722 $sql .= $this->db->order($sortfield, $sortorder);
724 if (!empty($limit)) {
725 $sql .= $this->db->plimit($limit, $offset);
727 $this->lines = array();
729 $resql = $this->db->query(
$sql);
731 $num = $this->db->num_rows($resql);
733 while ($obj = $this->db->fetch_object($resql)) {
734 $line =
new self($this->db);
736 $line->id = $obj->rowid;
738 $line->fk_element = $obj->fk_element;
739 $line->fk_product = $obj->fk_product;
740 $line->fk_elementdet = $obj->fk_elementdet;
741 $line->qty = $obj->qty;
742 $line->fk_entrepot = $obj->fk_entrepot;
743 $line->fk_user = $obj->fk_user;
744 $line->datec = $this->db->jdate($obj->datec);
745 $line->comment = $obj->comment;
746 $line->status = $obj->status;
747 $line->tms = $this->db->jdate($obj->tms);
748 $line->batch = $obj->batch;
749 $line->eatby = $this->db->jdate($obj->eatby);
750 $line->sellby = $this->db->jdate($obj->sellby);
751 $line->fetch_optionals();
753 $this->lines[$line->id] = $line;
755 $this->db->free($resql);
759 $this->errors[] =
'Error '.$this->db->lasterror();
760 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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
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.
div float
Buy price without taxes.