Contrat->getListOfContracts(): allow to sort contracts by contract status, product category, and line status.
This commit is contained in:
parent
4d01969a4c
commit
a14a63fdad
@ -2130,19 +2130,27 @@ class Contrat extends CommonObject
|
||||
/**
|
||||
* Return list of other contracts for same company than current contract
|
||||
*
|
||||
* @param string $option 'all' or 'others'
|
||||
* @return array|int Array of contracts id or <0 if error
|
||||
* @param string $option 'all' or 'others'
|
||||
* @param array $status sort contracts having these status
|
||||
* @param array $product_categories sort contracts containing these product categories
|
||||
* @param array $line_status sort contracts where lines have these status
|
||||
* @return array|int Array of contracts id or <0 if error
|
||||
*/
|
||||
public function getListOfContracts($option = 'all')
|
||||
public function getListOfContracts($option = 'all', $status = [], $product_categories = [], $line_status = [] )
|
||||
{
|
||||
$tab = array();
|
||||
|
||||
$sql = "SELECT c.rowid, c.ref";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
|
||||
$sql .= " WHERE fk_soc =".((int) $this->socid);
|
||||
if ($option == 'others') {
|
||||
$sql .= " AND c.rowid <> ".((int) $this->id);
|
||||
if (!empty($product_categories)) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON cd.fk_contrat = c.rowid";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = cd.fk_product AND cp.fk_categorie IN (".implode(', ', $product_categories).")";
|
||||
}
|
||||
$sql .= " WHERE c.fk_soc =".((int) $this->socid);
|
||||
$sql .= ($option == 'others') ? " AND c.rowid <> ".((int) $this->id) : "";
|
||||
$sql .= (!empty($status)) ? " AND c.statut IN (".implode(', ', $status).")" : "";
|
||||
$sql .= (!empty($line_status)) ? " AND cd.statut IN (".implode(', ', $line_status).")" : "";
|
||||
$sql .= " GROUP BY c.rowid";
|
||||
|
||||
dol_syslog(get_class($this)."::getOtherContracts()", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user