27 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
50 public $errors = array();
55 public $element=
'commandefournisseurdispatch';
61 public $lines=array();
81 public $fk_commandefourndet;
121 $this->statuts[0] =
'Received';
122 $this->statuts[1] =
'Verified';
123 $this->statuts[2] =
'Denied';
124 $this->statutshort[0] =
'Received';
125 $this->statutshort[1] =
'Verified';
126 $this->statutshort[2] =
'Denied';
139 global $conf, $langs;
144 if (isset($this->fk_commande)) $this->fk_commande=trim($this->fk_commande);
145 if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product);
146 if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet=trim($this->fk_commandefourndet);
147 if (isset($this->qty)) $this->qty=trim($this->qty);
148 if (isset($this->fk_entrepot)) $this->fk_entrepot=trim($this->fk_entrepot);
149 if (isset($this->fk_user)) $this->fk_user=trim($this->fk_user);
150 if (isset($this->comment)) $this->comment=trim($this->comment);
151 if (isset($this->status)) $this->status=trim($this->status);
152 if (isset($this->batch)) $this->batch=trim($this->batch);
158 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
159 $sql.=
"fk_commande,";
160 $sql.=
"fk_product,";
161 $sql.=
"fk_commandefourndet,";
163 $sql.=
"fk_entrepot,";
172 $sql.=
" ".(! isset($this->fk_commande)?
'NULL':
"'".$this->db->escape($this->fk_commande).
"'").
",";
173 $sql.=
" ".(! isset($this->fk_product)?
'NULL':
"'".$this->db->escape($this->fk_product).
"'").
",";
174 $sql.=
" ".(! isset($this->fk_commandefourndet)?
'NULL':
"'".$this->db->escape($this->fk_commandefourndet).
"'").
",";
175 $sql.=
" ".(! isset($this->qty)?
'NULL':
"'".$this->db->escape($this->qty).
"'").
",";
176 $sql.=
" ".(! isset($this->fk_entrepot)?
'NULL':
"'".$this->db->escape($this->fk_entrepot).
"'").
",";
177 $sql.=
" ".(! isset($this->fk_user)?
'NULL':
"'".$this->db->escape($this->fk_user).
"'").
",";
178 $sql.=
" ".(! isset($this->datec) ||
dol_strlen($this->datec)==0?
'NULL':
"'".$this->db->idate($this->datec).
"'").
",";
179 $sql.=
" ".(! isset($this->comment)?
'NULL':
"'".$this->db->escape($this->comment).
"'").
",";
180 $sql.=
" ".(! isset($this->status)?
'NULL':
"'".$this->db->escape($this->status).
"'").
",";
181 $sql.=
" ".(! isset($this->batch)?
'NULL':
"'".$this->db->escape($this->batch).
"'").
",";
182 $sql.=
" ".(! isset($this->eatby) ||
dol_strlen($this->eatby)==0?
'NULL':
"'".$this->db->idate($this->eatby).
"'").
",";
183 $sql.=
" ".(! isset($this->sellby) ||
dol_strlen($this->sellby)==0?
'NULL':
"'".$this->db->idate($this->sellby).
"'").
"";
189 $resql=$this->db->query($sql);
190 if (!
$resql) { $error++; $this->errors[]=
"Error ".$this->db->lasterror(); }
194 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
211 foreach($this->errors as $errmsg)
214 $this->error.=($this->error?
', '.$errmsg:$errmsg);
216 $this->db->rollback();
240 $sql.=
" t.fk_commande,";
241 $sql.=
" t.fk_product,";
242 $sql.=
" t.fk_commandefourndet,";
244 $sql.=
" t.fk_entrepot,";
245 $sql.=
" t.fk_user,";
247 $sql.=
" t.comment,";
255 $sql.=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
256 if ($ref) $sql.=
" WHERE t.ref = '".$ref.
"'";
257 else $sql.=
" WHERE t.rowid = ".$id;
260 $resql=$this->db->query($sql);
263 if ($this->db->num_rows(
$resql))
265 $obj = $this->db->fetch_object(
$resql);
267 $this->
id = $obj->rowid;
269 $this->fk_commande = $obj->fk_commande;
270 $this->fk_product = $obj->fk_product;
271 $this->fk_commandefourndet = $obj->fk_commandefourndet;
272 $this->qty = $obj->qty;
273 $this->fk_entrepot = $obj->fk_entrepot;
274 $this->fk_user = $obj->fk_user;
275 $this->datec = $this->db->jdate($obj->datec);
276 $this->comment = $obj->comment;
277 $this->status = $obj->status;
278 $this->tms = $this->db->jdate($obj->tms);
279 $this->batch = $obj->batch;
280 $this->eatby = $this->db->jdate($obj->eatby);
281 $this->sellby = $this->db->jdate($obj->sellby);
289 $this->error=
"Error ".$this->db->lasterror();
304 global $conf, $langs;
309 if (isset($this->fk_commande)) $this->fk_commande=trim($this->fk_commande);
310 if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product);
311 if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet=trim($this->fk_commandefourndet);
312 if (isset($this->qty)) $this->qty=trim($this->qty);
313 if (isset($this->fk_entrepot)) $this->fk_entrepot=trim($this->fk_entrepot);
314 if (isset($this->fk_user)) $this->fk_user=trim($this->fk_user);
315 if (isset($this->comment)) $this->comment=trim($this->comment);
316 if (isset($this->status)) $this->status=trim($this->status);
317 if (isset($this->batch)) $this->batch=trim($this->batch);
325 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
327 $sql.=
" fk_commande=".(isset($this->fk_commande)?$this->fk_commande:
"null").
",";
328 $sql.=
" fk_product=".(isset($this->fk_product)?$this->fk_product:
"null").
",";
329 $sql.=
" fk_commandefourndet=".(isset($this->fk_commandefourndet)?$this->fk_commandefourndet:
"null").
",";
330 $sql.=
" qty=".(isset($this->qty)?$this->qty:
"null").
",";
331 $sql.=
" fk_entrepot=".(isset($this->fk_entrepot)?$this->fk_entrepot:
"null").
",";
332 $sql.=
" fk_user=".(isset($this->fk_user)?$this->fk_user:
"null").
",";
333 $sql.=
" datec=".(dol_strlen($this->datec)!=0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
334 $sql.=
" comment=".(isset($this->comment)?
"'".$this->db->escape($this->comment).
"'":
"null").
",";
335 $sql.=
" status=".(isset($this->status)?$this->status:
"null").
",";
336 $sql.=
" tms=".(dol_strlen($this->tms)!=0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
337 $sql.=
" batch=".(isset($this->batch)?
"'".$this->db->escape($this->batch).
"'":
"null").
",";
338 $sql.=
" eatby=".(dol_strlen($this->eatby)!=0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
",";
339 $sql.=
" sellby=".(dol_strlen($this->sellby)!=0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null').
"";
342 $sql.=
" WHERE rowid=".$this->id;
347 $resql = $this->db->query($sql);
348 if (!
$resql) { $error++; $this->errors[]=
"Error ".$this->db->lasterror(); }
367 foreach($this->errors as $errmsg)
370 $this->error.=($this->error?
', '.$errmsg:$errmsg);
372 $this->db->rollback();
390 function delete($user, $notrigger=0)
392 global $conf, $langs;
413 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
414 $sql.=
" WHERE rowid=".$this->id;
417 $resql = $this->db->query($sql);
418 if (!
$resql) { $error++; $this->errors[]=
"Error ".$this->db->lasterror(); }
424 foreach($this->errors as $errmsg)
427 $this->error.=($this->error?
', '.$errmsg:$errmsg);
429 $this->db->rollback();
453 $object=
new Commandefournisseurdispatch($this->db);
458 $object->fetch($fromid);
466 $object->context[
'createfromclone'] =
'createfromclone';
467 $result=$object->create($user);
472 $this->error=$object->error;
481 unset($object->context[
'createfromclone']);
491 $this->db->rollback();
506 return $this->
LibStatut($this->status,$mode);
521 $langs->load(
'orders');
525 return $langs->trans($this->statuts[$statut]);
529 return $langs->trans($this->statutshort[$statut]);
533 return $langs->trans($this->statuts[$statut]);
537 if ($statut==0)
return img_picto($langs->trans($this->statuts[$statut]),
'statut0');
538 if ($statut==1)
return img_picto($langs->trans($this->statuts[$statut]),
'statut4');
539 if ($statut==2)
return img_picto($langs->trans($this->statuts[$statut]),
'statut8');
543 if ($statut==0)
return img_picto($langs->trans($this->statuts[$statut]),
'statut0').
' '.$langs->trans($this->statuts[$statut]);
544 if ($statut==1)
return img_picto($langs->trans($this->statuts[$statut]),
'statut4').
' '.$langs->trans($this->statuts[$statut]);
545 if ($statut==2)
return img_picto($langs->trans($this->statuts[$statut]),
'statut8').
' '.$langs->trans($this->statuts[$statut]);
549 if ($statut==0)
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$statut]).
' </span>'.
img_picto($langs->trans($this->statuts[$statut]),
'statut0');
550 if ($statut==1)
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$statut]).
' </span>'.
img_picto($langs->trans($this->statuts[$statut]),
'statut4');
551 if ($statut==2)
return '<span class="hideonsmartphone">'.$langs->trans($this->statutshort[$statut]).
' </span>'.
img_picto($langs->trans($this->statuts[$statut]),
'statut8');
566 $this->fk_commande=
'';
567 $this->fk_product=
'';
568 $this->fk_commandefourndet=
'';
570 $this->fk_entrepot=
'';
593 public function fetchAll($sortorder=
'', $sortfield=
'', $limit=0, $offset=0, array $filter = array(), $filtermode=
'AND')
600 $sql.=
" t.fk_commande,";
601 $sql.=
" t.fk_product,";
602 $sql.=
" t.fk_commandefourndet,";
604 $sql.=
" t.fk_entrepot,";
605 $sql.=
" t.fk_user,";
607 $sql.=
" t.comment,";
614 $sql.=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
618 if (count($filter) > 0) {
619 foreach ($filter as $key => $value) {
620 if ($key==
't.comment') {
621 $sqlwhere [] = $key .
' LIKE \'%' . $this->db->escape($value) .
'%\'';
622 } elseif ($key==
't.datec' || $key==
't.tms' || $key==
't.eatby' || $key==
't.sellby' || $key==
't.batch') {
623 $sqlwhere [] = $key .
' = \'' . $this->db->escape($value) .
'\'';
625 $sqlwhere [] = $key .
' = ' . $this->db->escape($value);
629 if (count($sqlwhere) > 0) {
630 $sql .=
' WHERE ' . implode(
' '.$filtermode.
' ', $sqlwhere);
633 if (!empty($sortfield)) {
634 $sql .= $this->db->order($sortfield,$sortorder);
636 if (!empty($limit)) {
637 $sql .=
' ' . $this->db->plimit($limit, $offset);
639 $this->lines = array();
641 $resql = $this->db->query($sql);
643 $num = $this->db->num_rows(
$resql);
645 while ($obj = $this->db->fetch_object(
$resql)) {
646 $line =
new self($this->db);
648 $line->id = $obj->rowid;
650 $line->fk_commande = $obj->fk_commande;
651 $line->fk_product = $obj->fk_product;
652 $line->fk_commandefourndet = $obj->fk_commandefourndet;
653 $line->qty = $obj->qty;
654 $line->fk_entrepot = $obj->fk_entrepot;
655 $line->fk_user = $obj->fk_user;
656 $line->datec = $this->db->jdate($obj->datec);
657 $line->comment = $obj->comment;
658 $line->status = $obj->status;
659 $line->tms = $this->db->jdate($obj->tms);
660 $line->batch = $obj->batch;
661 $line->eatby = $this->db->jdate($obj->eatby);
662 $line->sellby = $this->db->jdate($obj->sellby);
664 $this->lines[$line->id] = $line;
670 $this->errors[] =
'Error ' . $this->db->lasterror();
671 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
createFromClone($fromid)
Load an object from its id and create a new one in database.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Class to manage table commandefournisseurdispatch.
fetch($id, $ref='')
Load object in memory from the database.
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getLibStatut($mode=0)
Return label of the status of object.
create($user, $notrigger=0)
Create object into database.
$table_element
Name of table without prefix where object is stored.
LibStatut($statut, $mode=0)
Return label of a status.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
update($user, $notrigger=0)
Update object into database.