diff --git a/application/Contract/ContractModel.php b/application/Contract/ContractModel.php index cb1856594..24e4591fb 100644 --- a/application/Contract/ContractModel.php +++ b/application/Contract/ContractModel.php @@ -154,7 +154,7 @@ class ContractModel { return null; } - public static function count($filter) { + public static function countActive($filter) { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); @@ -215,6 +215,30 @@ class ContractModel { return $items; } + public static function count($filter) { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM ( + SELECT Contract.* FROM Contract + LEFT JOIN Address ON (Contract.owner_id = Address.id) + LEFT JOIN OrderProduct ON (Contract.orderproduct_id = OrderProduct.id) + LEFT JOIN `Order` ON (OrderProduct.order_id = `Order`.id) + LEFT JOIN Product ON (Contract.product_id = Product.id) + WHERE $where + GROUP BY Contract.id + ) contract"; + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + public static function search($filter, $limit = false) { //var_dump($filter);exit; $items = []; diff --git a/application/OrderProduct/OrderProductModel.php b/application/OrderProduct/OrderProductModel.php index 898f5fec8..bcfa395b3 100644 --- a/application/OrderProduct/OrderProductModel.php +++ b/application/OrderProduct/OrderProductModel.php @@ -205,7 +205,7 @@ class OrderProductModel if (array_key_exists("product_id", $filter)) { $product_id = $filter['product_id']; if (is_numeric($product_id)) { - $where .= " AND order_id=$product_id"; + $where .= " AND product_id=$product_id"; } }