27 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
28 require_once DOL_DOCUMENT_ROOT.
"/reception/class/reception.class.php";
49 public $errors = array();
54 public $element =
'commandefournisseurdispatch';
60 public $lines = array();
80 public $fk_commandefourndet;
116 public $cost_price = 0;
131 $this->statuts[0] =
'Received';
132 $this->statuts[1] =
'Verified';
133 $this->statuts[2] =
'Denied';
134 $this->statuts_short[0] =
'Received';
135 $this->statuts_short[1] =
'Verified';
136 $this->statuts_short[2] =
'Denied';
147 public function create($user, $notrigger = 0)
149 global $conf, $langs, $hookmanager;
154 if (isset($this->fk_commande)) {
155 $this->fk_commande = trim($this->fk_commande);
157 if (isset($this->fk_product)) {
158 $this->fk_product = trim($this->fk_product);
160 if (isset($this->fk_commandefourndet)) {
161 $this->fk_commandefourndet = trim($this->fk_commandefourndet);
163 if (isset($this->qty)) {
164 $this->qty = trim($this->qty);
166 if (isset($this->fk_entrepot)) {
167 $this->fk_entrepot = trim($this->fk_entrepot);
169 if (isset($this->fk_user)) {
170 $this->fk_user = trim($this->fk_user);
172 if (isset($this->comment)) {
173 $this->comment = trim($this->comment);
175 if (isset($this->status)) {
176 $this->status = trim($this->status);
178 if (isset($this->batch)) {
179 $this->batch = trim($this->batch);
181 if (empty($this->datec)) {
190 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
191 $sql .=
"fk_commande,";
192 $sql .=
"fk_product,";
193 $sql .=
"fk_commandefourndet,";
195 $sql .=
"fk_entrepot,";
203 $sql .=
"fk_reception,";
204 $sql .=
"cost_price";
207 $sql .=
") VALUES (";
208 $sql .=
" ".(!isset($this->fk_commande) ?
'NULL' :
"'".$this->db->escape($this->fk_commande).
"'").
",";
209 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
210 $sql .=
" ".(!isset($this->fk_commandefourndet) ?
'NULL' :
"'".$this->db->escape($this->fk_commandefourndet).
"'").
",";
211 $sql .=
" ".(!isset($this->qty) ?
'NULL' :
"'".$this->db->escape($this->qty).
"'").
",";
212 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' :
"'".$this->db->escape($this->fk_entrepot).
"'").
",";
213 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' :
"'".$this->db->escape($this->fk_user).
"'").
",";
214 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
215 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
216 $sql .=
" ".(!isset($this->status) ?
'NULL' :
"'".$this->db->escape($this->status).
"'").
",";
217 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
218 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
219 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
220 $sql .=
" ".(!isset($this->fk_reception) ?
'NULL' :
"'".$this->db->escape($this->fk_reception).
"'").
",";
221 $sql .=
" ".(!isset($this->cost_price) ?
'0' :
"'".$this->db->escape($this->cost_price).
"'");
229 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
233 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
237 $result=$this->
call_trigger(
'LINERECEPTION_CREATE', $user);
255 foreach ($this->errors as $errmsg) {
257 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
259 $this->
db->rollback();
275 public function fetch($id, $ref =
'')
281 $sql .=
" t.fk_commande,";
282 $sql .=
" t.fk_product,";
283 $sql .=
" t.fk_commandefourndet,";
285 $sql .=
" t.fk_entrepot,";
286 $sql .=
" t.fk_user,";
288 $sql .=
" t.comment,";
289 $sql .=
" t.status,";
293 $sql .=
" t.sellby,";
294 $sql .=
" t.fk_reception";
297 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
299 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
301 $sql .=
" WHERE t.rowid = ".((int) $id);
308 $obj = $this->
db->fetch_object(
$resql);
310 $this->
id = $obj->rowid;
312 $this->fk_commande = $obj->fk_commande;
313 $this->fk_product = $obj->fk_product;
314 $this->fk_commandefourndet = $obj->fk_commandefourndet;
315 $this->qty = $obj->qty;
316 $this->fk_entrepot = $obj->fk_entrepot;
317 $this->fk_user = $obj->fk_user;
318 $this->datec = $this->
db->jdate($obj->datec);
319 $this->comment = $obj->comment;
320 $this->status = $obj->status;
321 $this->tms = $this->
db->jdate($obj->tms);
322 $this->batch = $obj->batch;
323 $this->eatby = $this->
db->jdate($obj->eatby);
324 $this->sellby = $this->
db->jdate($obj->sellby);
325 $this->fk_reception = $obj->fk_reception;
333 $this->error =
"Error ".$this->db->lasterror();
346 public function update($user, $notrigger = 0)
352 if (isset($this->fk_commande)) {
353 $this->fk_commande = trim($this->fk_commande);
355 if (isset($this->fk_product)) {
356 $this->fk_product = trim($this->fk_product);
358 if (isset($this->fk_commandefourndet)) {
359 $this->fk_commandefourndet = trim($this->fk_commandefourndet);
361 if (isset($this->qty)) {
362 $this->qty = trim($this->qty);
364 if (isset($this->fk_entrepot)) {
365 $this->fk_entrepot = trim($this->fk_entrepot);
367 if (isset($this->fk_user)) {
368 $this->fk_user = trim($this->fk_user);
370 if (isset($this->comment)) {
371 $this->comment = trim($this->comment);
373 if (isset($this->status)) {
374 $this->status = trim($this->status);
376 if (isset($this->batch)) {
377 $this->batch = trim($this->batch);
386 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
387 $sql .=
" fk_commande=".(isset($this->fk_commande) ? $this->fk_commande :
"null").
",";
388 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
389 $sql .=
" fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet :
"null").
",";
390 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
391 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
392 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
393 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
394 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
395 $sql .=
" status=".(isset($this->status) ? $this->status :
"null").
",";
396 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
397 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
398 $sql .=
" eatby=".(dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
399 $sql .=
" sellby=".(dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null');
400 $sql .=
" WHERE rowid=".((int) $this->
id);
407 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
412 if (empty($this->
id) && !empty($this->
rowid)) {
413 $this->
id = $this->rowid;
423 $result = $this->
call_trigger(
'LINERECEPTION_MODIFY', $user);
433 foreach ($this->errors as $errmsg) {
435 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
437 $this->
db->rollback();
453 public function delete($user, $notrigger = 0)
462 $result = $this->
call_trigger(
'LINERECEPTION_DELETE', $user);
475 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
480 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
481 $sql .=
" WHERE rowid=".((int) $this->
id);
486 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
492 foreach ($this->errors as $errmsg) {
494 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
496 $this->
db->rollback();
516 $object =
new Commandefournisseurdispatch($this->
db);
521 $object->fetch($fromid);
529 $object->context[
'createfromclone'] =
'createfromclone';
530 $result = $object->create($user);
534 $this->error = $object->error;
541 unset($object->context[
'createfromclone']);
548 $this->
db->rollback();
563 return $this->
LibStatut($this->status, $mode);
578 $langs->load(
'orders');
581 return $langs->trans($this->statuts[$status]);
582 } elseif ($mode == 1) {
583 return $langs->trans($this->statuts_short[$status]);
584 } elseif ($mode == 2) {
585 return $langs->trans($this->statuts[$status]);
586 } elseif ($mode == 3) {
588 return img_picto($langs->trans($this->statuts[$status]),
'statut0');
589 } elseif ($status == 1) {
590 return img_picto($langs->trans($this->statuts[$status]),
'statut4');
591 } elseif ($status == 2) {
592 return img_picto($langs->trans($this->statuts[$status]),
'statut8');
594 } elseif ($mode == 4) {
596 return img_picto($langs->trans($this->statuts[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
597 } elseif ($status == 1) {
598 return img_picto($langs->trans($this->statuts[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
599 } elseif ($status == 2) {
600 return img_picto($langs->trans($this->statuts[$status]),
'statut8').
' '.$langs->trans($this->statuts[$status]);
602 } elseif ($mode == 5) {
604 return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut0');
605 } elseif ($status == 1) {
606 return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut4');
607 } elseif ($status == 2) {
608 return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut8');
624 $this->fk_commande =
'';
625 $this->fk_product =
'';
626 $this->fk_commandefourndet =
'';
628 $this->fk_entrepot =
'';
651 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
658 $sql .=
" t.fk_commande,";
659 $sql .=
" t.fk_product,";
660 $sql .=
" t.fk_commandefourndet,";
662 $sql .=
" t.fk_entrepot,";
663 $sql .=
" t.fk_user,";
665 $sql .=
" t.comment,";
666 $sql .=
" t.status,";
672 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
676 if (count($filter) > 0) {
677 foreach ($filter as $key => $value) {
678 if ($key ==
't.comment') {
679 $sqlwhere [] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
680 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
681 $sqlwhere [] = $key.
" = '".$this->
db->escape($value).
"'";
682 } elseif ($key ==
'qty') {
683 $sqlwhere [] = $key.
" = ".((
float) $value);
685 $sqlwhere [] = $key.
" = ".((int) $value);
689 if (count($sqlwhere) > 0) {
690 $sql .=
' WHERE '.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
693 if (!empty($sortfield)) {
694 $sql .= $this->
db->order($sortfield, $sortorder);
696 if (!empty($limit)) {
697 $sql .= $this->
db->plimit($limit, $offset);
699 $this->lines = array();
705 while ($obj = $this->
db->fetch_object(
$resql)) {
706 $line =
new self($this->db);
708 $line->id = $obj->rowid;
710 $line->fk_commande = $obj->fk_commande;
711 $line->fk_product = $obj->fk_product;
712 $line->fk_commandefourndet = $obj->fk_commandefourndet;
713 $line->qty = $obj->qty;
714 $line->fk_entrepot = $obj->fk_entrepot;
715 $line->fk_user = $obj->fk_user;
716 $line->datec = $this->
db->jdate($obj->datec);
717 $line->comment = $obj->comment;
718 $line->status = $obj->status;
719 $line->tms = $this->
db->jdate($obj->tms);
720 $line->batch = $obj->batch;
721 $line->eatby = $this->
db->jdate($obj->eatby);
722 $line->sellby = $this->
db->jdate($obj->sellby);
723 $line->fetch_optionals();
725 $this->lines[$line->id] = $line;
731 $this->errors[] =
'Error '.$this->db->lasterror();
732 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
Class to manage table commandefournisseurdispatch.
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.
__construct($db)
Constructor.
$table_element
Name of table without prefix where object is stored.
fetch($id, $ref='')
Load object in memory from the database.
getLibStatut($mode=0)
Return label of the status of object.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
LibStatut($status, $mode=0)
Return label of a status.
create($user, $notrigger=0)
Create object into database.
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 Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div float
Buy price without taxes.
$conf db
API class for accounts.