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;
120 $this->statuts[0] =
'Received';
121 $this->statuts[1] =
'Verified';
122 $this->statuts[2] =
'Denied';
123 $this->statutshort[0] =
'Received';
124 $this->statutshort[1] =
'Verified';
125 $this->statutshort[2] =
'Denied';
136 public function create($user, $notrigger = 0)
138 global $conf, $langs, $hookmanager;
143 if (isset($this->fk_commande)) $this->fk_commande = trim($this->fk_commande);
144 if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product);
145 if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet = trim($this->fk_commandefourndet);
146 if (isset($this->qty)) $this->qty = trim($this->qty);
147 if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot);
148 if (isset($this->fk_user)) $this->fk_user = trim($this->fk_user);
149 if (isset($this->comment)) $this->comment = trim($this->comment);
150 if (isset($this->status)) $this->status = trim($this->status);
151 if (isset($this->batch)) $this->batch = trim($this->batch);
152 if (empty($this->datec)) $this->datec =
dol_now();
159 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
160 $sql .=
"fk_commande,";
161 $sql .=
"fk_product,";
162 $sql .=
"fk_commandefourndet,";
164 $sql .=
"fk_entrepot,";
172 $sql .=
"fk_reception";
175 $sql .=
") VALUES (";
176 $sql .=
" ".(!isset($this->fk_commande) ?
'NULL' :
"'".$this->db->escape($this->fk_commande).
"'").
",";
177 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
178 $sql .=
" ".(!isset($this->fk_commandefourndet) ?
'NULL' :
"'".$this->db->escape($this->fk_commandefourndet).
"'").
",";
179 $sql .=
" ".(!isset($this->qty) ?
'NULL' :
"'".$this->db->escape($this->qty).
"'").
",";
180 $sql .=
" ".(!isset($this->fk_entrepot) ?
'NULL' :
"'".$this->db->escape($this->fk_entrepot).
"'").
",";
181 $sql .=
" ".(!isset($this->fk_user) ?
'NULL' :
"'".$this->db->escape($this->fk_user).
"'").
",";
182 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
183 $sql .=
" ".(!isset($this->comment) ?
'NULL' :
"'".$this->db->escape($this->comment).
"'").
",";
184 $sql .=
" ".(!isset($this->status) ?
'NULL' :
"'".$this->db->escape($this->status).
"'").
",";
185 $sql .=
" ".(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
",";
186 $sql .=
" ".(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
",";
187 $sql .=
" ".(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
",";
188 $sql .=
" ".(!isset($this->fk_reception) ?
'NULL' :
"'".$this->db->escape($this->fk_reception).
"'").
"";
195 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
199 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
217 if ($result < 0) $error++;
223 foreach ($this->errors as $errmsg)
226 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
228 $this->
db->rollback();
244 public function fetch($id, $ref =
'')
250 $sql .=
" t.fk_commande,";
251 $sql .=
" t.fk_product,";
252 $sql .=
" t.fk_commandefourndet,";
254 $sql .=
" t.fk_entrepot,";
255 $sql .=
" t.fk_user,";
257 $sql .=
" t.comment,";
258 $sql .=
" t.status,";
262 $sql .=
" t.sellby,";
263 $sql .=
" t.fk_reception";
266 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
267 if ($ref) $sql .=
" WHERE t.ref = '".$ref.
"'";
268 else $sql .=
" WHERE t.rowid = ".$id;
276 $obj = $this->
db->fetch_object(
$resql);
278 $this->
id = $obj->rowid;
280 $this->fk_commande = $obj->fk_commande;
281 $this->fk_product = $obj->fk_product;
282 $this->fk_commandefourndet = $obj->fk_commandefourndet;
283 $this->qty = $obj->qty;
284 $this->fk_entrepot = $obj->fk_entrepot;
285 $this->fk_user = $obj->fk_user;
286 $this->datec = $this->
db->jdate($obj->datec);
287 $this->comment = $obj->comment;
288 $this->status = $obj->status;
289 $this->tms = $this->
db->jdate($obj->tms);
290 $this->batch = $obj->batch;
291 $this->eatby = $this->
db->jdate($obj->eatby);
292 $this->sellby = $this->
db->jdate($obj->sellby);
293 $this->fk_reception = $obj->fk_reception;
301 $this->error =
"Error ".$this->db->lasterror();
314 public function update($user, $notrigger = 0)
316 global $conf, $langs;
321 if (isset($this->fk_commande)) $this->fk_commande = trim($this->fk_commande);
322 if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product);
323 if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet = trim($this->fk_commandefourndet);
324 if (isset($this->qty)) $this->qty = trim($this->qty);
325 if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot);
326 if (isset($this->fk_user)) $this->fk_user = trim($this->fk_user);
327 if (isset($this->comment)) $this->comment = trim($this->comment);
328 if (isset($this->status)) $this->status = trim($this->status);
329 if (isset($this->batch)) $this->batch = trim($this->batch);
337 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
339 $sql .=
" fk_commande=".(isset($this->fk_commande) ? $this->fk_commande :
"null").
",";
340 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
341 $sql .=
" fk_commandefourndet=".(isset($this->fk_commandefourndet) ? $this->fk_commandefourndet :
"null").
",";
342 $sql .=
" qty=".(isset($this->qty) ? $this->qty :
"null").
",";
343 $sql .=
" fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot :
"null").
",";
344 $sql .=
" fk_user=".(isset($this->fk_user) ? $this->fk_user :
"null").
",";
345 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
346 $sql .=
" comment=".(isset($this->comment) ?
"'".$this->db->escape($this->comment).
"'" :
"null").
",";
347 $sql .=
" status=".(isset($this->status) ? $this->status :
"null").
",";
348 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
349 $sql .=
" batch=".(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
",";
350 $sql .=
" eatby=".(dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
351 $sql .=
" sellby=".(dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null').
"";
354 $sql .=
" WHERE rowid=".$this->id;
360 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
366 if (empty($this->
id) && !empty($this->
rowid))$this->
id = $this->rowid;
377 $result = $this->
call_trigger(
'LINERECEPTION_UPDATE', $user);
378 if ($result < 0) $error++;
386 foreach ($this->errors as $errmsg)
389 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
391 $this->
db->rollback();
407 public function delete($user, $notrigger = 0)
409 global $conf, $langs;
434 dol_syslog(get_class($this).
"::delete error deleteExtraFields ".$this->error, LOG_ERR);
440 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
441 $sql .=
" WHERE rowid=".$this->id;
445 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
451 foreach ($this->errors as $errmsg)
454 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
456 $this->
db->rollback();
477 $object =
new Commandefournisseurdispatch($this->
db);
482 $object->fetch($fromid);
490 $object->context[
'createfromclone'] =
'createfromclone';
491 $result = $object->create($user);
496 $this->error = $object->error;
504 unset($object->context[
'createfromclone']);
512 $this->
db->rollback();
527 return $this->
LibStatut($this->status, $mode);
542 $langs->load(
'orders');
546 return $langs->trans($this->statuts[$status]);
547 } elseif ($mode == 1)
549 return $langs->trans($this->statutshort[$status]);
550 } elseif ($mode == 2)
552 return $langs->trans($this->statuts[$status]);
553 } elseif ($mode == 3)
555 if ($status == 0)
return img_picto($langs->trans($this->statuts[$status]),
'statut0');
556 elseif ($status == 1)
return img_picto($langs->trans($this->statuts[$status]),
'statut4');
557 elseif ($status == 2)
return img_picto($langs->trans($this->statuts[$status]),
'statut8');
558 } elseif ($mode == 4)
560 if ($status == 0)
return img_picto($langs->trans($this->statuts[$status]),
'statut0').
' '.$langs->trans($this->statuts[$status]);
561 elseif ($status == 1)
return img_picto($langs->trans($this->statuts[$status]),
'statut4').
' '.$langs->trans($this->statuts[$status]);
562 elseif ($status == 2)
return img_picto($langs->trans($this->statuts[$status]),
'statut8').
' '.$langs->trans($this->statuts[$status]);
563 } elseif ($mode == 5)
565 if ($status == 0)
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut0');
566 elseif ($status == 1)
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut4');
567 elseif ($status == 2)
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$status]).
' </span>'.
img_picto($langs->trans($this->statuts[$status]),
'statut8');
582 $this->fk_commande =
'';
583 $this->fk_product =
'';
584 $this->fk_commandefourndet =
'';
586 $this->fk_entrepot =
'';
609 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
616 $sql .=
" t.fk_commande,";
617 $sql .=
" t.fk_product,";
618 $sql .=
" t.fk_commandefourndet,";
620 $sql .=
" t.fk_entrepot,";
621 $sql .=
" t.fk_user,";
623 $sql .=
" t.comment,";
624 $sql .=
" t.status,";
630 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
634 if (count($filter) > 0) {
635 foreach ($filter as $key => $value) {
636 if ($key ==
't.comment') {
637 $sqlwhere [] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
638 } elseif ($key ==
't.datec' || $key ==
't.tms' || $key ==
't.eatby' || $key ==
't.sellby' || $key ==
't.batch') {
639 $sqlwhere [] = $key.
' = \''.$this->
db->escape($value).
'\'';
641 $sqlwhere [] = $key.
' = '.$this->
db->escape($value);
645 if (count($sqlwhere) > 0) {
646 $sql .=
' WHERE '.implode(
' '.$filtermode.
' ', $sqlwhere);
649 if (!empty($sortfield)) {
650 $sql .= $this->
db->order($sortfield, $sortorder);
652 if (!empty($limit)) {
653 $sql .=
' '.$this->db->plimit($limit, $offset);
655 $this->lines = array();
661 while ($obj = $this->
db->fetch_object(
$resql)) {
662 $line =
new self($this->db);
664 $line->id = $obj->rowid;
666 $line->fk_commande = $obj->fk_commande;
667 $line->fk_product = $obj->fk_product;
668 $line->fk_commandefourndet = $obj->fk_commandefourndet;
669 $line->qty = $obj->qty;
670 $line->fk_entrepot = $obj->fk_entrepot;
671 $line->fk_user = $obj->fk_user;
672 $line->datec = $this->
db->jdate($obj->datec);
673 $line->comment = $obj->comment;
674 $line->status = $obj->status;
675 $line->tms = $this->
db->jdate($obj->tms);
676 $line->batch = $obj->batch;
677 $line->eatby = $this->
db->jdate($obj->eatby);
678 $line->sellby = $this->
db->jdate($obj->sellby);
679 $line->fetch_optionals();
681 $this->lines[$line->id] = $line;
687 $this->errors[] =
'Error '.$this->db->lasterror();
688 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Class to manage table commandefournisseurdispatch.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
__construct($db)
Constructor.
fetch($id, $ref= '')
Load object in memory from the database.
LibStatut($status, $mode=0)
Return label of a status.
$conf db
API class for accounts.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load object in memory from the database.
getLibStatut($mode=0)
Return label of the status of object.
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.
deleteExtraFields()
Delete all extra fields values for the current 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...
create($user, $notrigger=0)
Create object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
$table_element
Name of table without prefix where object is stored.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
update($user, $notrigger=0)
Update object into database.