108 lines
2.8 KiB
PHP
108 lines
2.8 KiB
PHP
<?php
|
|
|
|
class IvtCustomerCreditingModel {
|
|
|
|
|
|
public static function getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
|
|
|
$res = $db->select("customer_crediting", "*", "1=1 ORDER BY id");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new IvtCustomerCrediting($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
public static function getFirst($filter = []) {
|
|
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$res = $db->select("customer_crediting", "*", "$where ORDER BY id LIMIT 1");
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new IvtCustomerCrediting($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) cnt FROM customer_crediting WHERE $where ORDER by id";
|
|
|
|
$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) {
|
|
$items = [];
|
|
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM customer_crediting WHERE $where ORDER by cid,pid,sid,id";
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
if(is_array($limit) && count($limit)) {
|
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
|
} elseif(is_numeric($count)) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new IvtCustomerCrediting($data);
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
/*
|
|
if(array_key_exists("status_id", $filter)) {
|
|
$status_id = $filter['status_id'];
|
|
if(is_numeric($status_id)) {
|
|
$where .= " AND IvtCustomerCrediting.status_id=$status_id";
|
|
}
|
|
}
|
|
|
|
|
|
if(array_key_exists("street", $filter)) {
|
|
$street = FronkDB::singleton()->escape($filter["street"]);
|
|
if($street) {
|
|
$where .= " AND street like '%$street%'";
|
|
}
|
|
}
|
|
*/
|
|
|
|
if(array_key_exists("cust_id", $filter)) {
|
|
$cust_id = $filter['cust_id'];
|
|
if(is_numeric($cust_id)) {
|
|
$where .= " AND cust_id=$cust_id";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|