414 lines
14 KiB
PHP
414 lines
14 KiB
PHP
<?php
|
|
|
|
class BillingVoicenumberModel {
|
|
public $invoice_id;
|
|
public $contract_id;
|
|
public $start_date;
|
|
public $end_date;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new BillingVoicenumber();
|
|
|
|
foreach($data as $field => $value) {
|
|
if(property_exists(get_called_class(), $field)) {
|
|
$model ->$field = $value;
|
|
}
|
|
}
|
|
|
|
$me = new User();
|
|
$me->loadMe();
|
|
|
|
if($model->create_by === null) {
|
|
$model->create_by = $me->id;
|
|
}
|
|
if($model->edit_by === null) {
|
|
$model->edit_by = $me->id;
|
|
}
|
|
|
|
return $model;
|
|
}
|
|
|
|
public static function getAll() {
|
|
$items = [];
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$res = $db->select("BillingVoicenumber", "*", "1 = 1 ORDER BY BillingVoicenumberaddress_id");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new BillingVoicenumber($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM BillingVoicenumber
|
|
WHERE $where
|
|
ORDER BY BillingVoicenumberaddress_id LIMIT 1";
|
|
//var_dump($sql);exit;
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new BillingVoicenumber($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getLast($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM BillingVoicenumber
|
|
WHERE $where
|
|
ORDER BY `create` DESC LIMIT 1";
|
|
//var_dump($sql);exit;
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new BillingVoicenumber($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getInvoiceBaseData($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$items = [];
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT owner_id, BillingVoicenumberaddress_id, BillingVoicenumber_type, BillingVoicenumber_delivery FROM BillingVoicenumber
|
|
WHERE $where
|
|
GROUP BY owner_id, BillingVoicenumberaddress_id, BillingVoicenumber_type, BillingVoicenumber_delivery
|
|
ORDER BY owner_id, BillingVoicenumberaddress_id, BillingVoicenumber_type, BillingVoicenumber_delivery";
|
|
//var_dump($sql);exit;
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = [
|
|
"owner_id" => $data->owner_id,
|
|
"BillingVoicenumberaddress_id" => $data->BillingVoicenumberaddress_id,
|
|
"BillingVoicenumber_type" => $data->BillingVoicenumber_type,
|
|
"BillingVoicenumber_delivery" => $data->BillingVoicenumber_delivery
|
|
];
|
|
}
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM BillingVoicenumber
|
|
WHERE $where";
|
|
|
|
//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, $order = false) {
|
|
//var_dump($filter);exit;
|
|
$items = [];
|
|
|
|
if(!$order) {
|
|
$order = "id ASC";
|
|
}
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM BillingVoicenumber
|
|
WHERE $where
|
|
ORDER BY $order";
|
|
|
|
if(is_array($limit) && count($limit)) {
|
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
|
} elseif(is_numeric($limit['count'])) {
|
|
$sql .= " LIMIT ".$limit['count'];
|
|
}
|
|
}
|
|
|
|
mfLoghandler::singleton()->debug($sql);
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[$data->id] = new BillingVoicenumber($data);
|
|
}
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
//var_dump($filter);exit;
|
|
|
|
if(array_key_exists("id", $filter)) {
|
|
$id = $filter['id'];
|
|
if(is_numeric($id)) {
|
|
$where .= " AND BillingVoicenumber.id like '%$id%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("approved", $filter)) {
|
|
$approved = $filter['approved'];
|
|
if($approved) {
|
|
$where .= " AND BillingVoicenumber.approved = 1";
|
|
} else {
|
|
$where .= " AND BillingVoicenumber.approved = 0";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("invoice_id", $filter)) {
|
|
$invoice_id = $filter['invoice_id'];
|
|
if(is_numeric($invoice_id)) {
|
|
$where .= " AND BillingVoicenumber.invoice_id=$invoice_id";
|
|
} elseif($invoice_id === null || $invoice_id === false) {
|
|
$where .= " AND (BillingVoicenumber.invoice_id IS NULL OR BillingVoicenumber.invoice_id=0)";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("contract_id", $filter)) {
|
|
$contract_id = $filter['contract_id'];
|
|
if(is_numeric($contract_id)) {
|
|
$where .= " AND BillingVoicenumber.contract_id=$contract_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("start_date", $filter)) {
|
|
$start_date = FronkDB::singleton()->escape($filter['start_date']);
|
|
if($start_date) {
|
|
$where .= " AND BillingVoicenumber.start_date='$start_date'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("start_date>", $filter)) {
|
|
$start_date = FronkDB::singleton()->escape($filter['start_date>']);
|
|
if($start_date) {
|
|
$where .= " AND BillingVoicenumber.start_date > '$start_date'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("start_date<", $filter)) {
|
|
$start_date = FronkDB::singleton()->escape($filter['start_date<']);
|
|
if($start_date) {
|
|
$where .= " AND BillingVoicenumber.start_date < '$start_date'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("start_date>=", $filter)) {
|
|
$start_date = FronkDB::singleton()->escape($filter['start_date>=']);
|
|
if($start_date) {
|
|
$where .= " AND BillingVoicenumber.start_date >= '$start_date'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("start_date<=", $filter)) {
|
|
$start_date = FronkDB::singleton()->escape($filter['start_date<=']);
|
|
if($start_date) {
|
|
$where .= " AND BillingVoicenumber.start_date <= '$start_date'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("owner_id", $filter)) {
|
|
$owner_id = $filter['owner_id'];
|
|
if(is_numeric($owner_id)) {
|
|
$where .= " AND BillingVoicenumber.owner_id=$owner_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("BillingVoicenumberaddress_id", $filter)) {
|
|
$BillingVoicenumberaddress_id = $filter['BillingVoicenumberaddress_id'];
|
|
if(is_numeric($BillingVoicenumberaddress_id)) {
|
|
$where .= " AND BillingVoicenumber.BillingVoicenumberaddress_id=$BillingVoicenumberaddress_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("customer_number", $filter)) {
|
|
$customer_number = $filter['customer_number'];
|
|
if(is_numeric($customer_number)) {
|
|
$where .= " AND BillingVoicenumber.customer_number LIKE $customer_number";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("company", $filter)) {
|
|
$company = FronkDB::singleton()->escape($filter["company"]);
|
|
if ($company) {
|
|
$where .= " AND company like '%$company%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("firstname", $filter)) {
|
|
$firstname = FronkDB::singleton()->escape($filter["firstname"]);
|
|
if ($firstname) {
|
|
$where .= " AND firstname like '%$firstname%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("lastname", $filter)) {
|
|
$lastname = FronkDB::singleton()->escape($filter["lastname"]);
|
|
if ($lastname) {
|
|
$where .= " AND lastname like '%$lastname%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("mergedName", $filter)) {
|
|
$name = FronkDB::singleton()->escape($filter["mergedName"]);
|
|
if ($name) {
|
|
$where .= " AND (CONCAT(firstname, ' ', lastname) like '%$name%' OR CONCAT(lastname, ' ', firstname) like '%$name%' )";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("street", $filter)) {
|
|
$street = FronkDB::singleton()->escape($filter["street"]);
|
|
if ($street) {
|
|
$where .= " AND street like '%$street%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("zip", $filter)) {
|
|
$zip = FronkDB::singleton()->escape($filter["zip"]);
|
|
if ($zip) {
|
|
$where .= " AND zip like '%$zip%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("city", $filter)) {
|
|
$city = FronkDB::singleton()->escape($filter["city"]);
|
|
if ($city) {
|
|
$where .= " AND city like '%$city%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("country", $filter)) {
|
|
$country = FronkDB::singleton()->escape($filter["country"]);
|
|
if ($country) {
|
|
$where .= " AND country like '%$country%'";
|
|
}
|
|
}
|
|
|
|
if (array_key_exists("email", $filter)) {
|
|
$email = FronkDB::singleton()->escape($filter["email"]);
|
|
if ($email) {
|
|
$where .= " AND email like '%$email%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("matchcode", $filter)) {
|
|
$matchcode = FronkDB::singleton()->escape($filter["matchcode"]);
|
|
if($matchcode) {
|
|
$where .= " AND matchcode like '%$matchcode%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("product_id", $filter)) {
|
|
$product_id = $filter['product_id'];
|
|
if(is_numeric($product_id)) {
|
|
$where .= " AND BillingVoicenumber.product_id=$product_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("product_name", $filter)) {
|
|
$product_name = $db->escape($filter['product_name']);
|
|
if($product_name) {
|
|
$where .= " AND product_name like '%$product_name%')";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("matchcode", $filter)) {
|
|
$matchcode = $db->escape($filter['matchcode']);
|
|
if($matchcode) {
|
|
$where .= " AND BillingVoicenumber.`matchcode` like '%$matchcode%'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("price<", $filter)) {
|
|
$price = $filter['price<'];
|
|
if(is_numeric($price)) {
|
|
$where .= " AND BillingVoicenumber.price < $price";
|
|
}
|
|
}
|
|
if(array_key_exists("price<=", $filter)) {
|
|
$price = $filter['price<='];
|
|
if(is_numeric($price)) {
|
|
$where .= " AND BillingVoicenumber.price <= $price";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("price>", $filter)) {
|
|
$price = $filter['price>'];
|
|
if(is_numeric($price)) {
|
|
$where .= " AND BillingVoicenumber.price > $price";
|
|
}
|
|
}
|
|
if(array_key_exists("price>=", $filter)) {
|
|
$price = $filter['price>='];
|
|
if(is_numeric($price)) {
|
|
$where .= " AND BillingVoicenumber.price >= $price";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("add-where", $filter)) {
|
|
$where .= " ".$filter['add-where'];
|
|
}
|
|
|
|
|
|
if(array_key_exists("BillingVoicenumber_type", $filter)) {
|
|
$BillingVoicenumber_type = $filter['BillingVoicenumber_type'];
|
|
if(is_numeric($BillingVoicenumber_type)) {
|
|
$where .= " AND BillingVoicenumber.BillingVoicenumber_type = $BillingVoicenumber_type";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("BillingVoicenumber_type", $filter)) {
|
|
$BillingVoicenumber_type = $db->escape($filter['BillingVoicenumber_type']);
|
|
if($BillingVoicenumber_type) {
|
|
$where .= " AND BillingVoicenumber.BillingVoicenumber_type = '$BillingVoicenumber_type'";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("BillingVoicenumber_delivery", $filter)) {
|
|
$BillingVoicenumber_delivery = $db->escape($filter['BillingVoicenumber_delivery']);
|
|
if($BillingVoicenumber_delivery) {
|
|
$where .= " AND BillingVoicenumber.BillingVoicenumber_delivery = '$BillingVoicenumber_delivery'";
|
|
}
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|