170 lines
4.3 KiB
PHP
170 lines
4.3 KiB
PHP
<?php
|
|
|
|
class InvoicepositionModel {
|
|
public $invoice_id;
|
|
public $billing_id;
|
|
public $contract_id;
|
|
public $start_date;
|
|
public $end_date;
|
|
public $matchcode;
|
|
public $product_id;
|
|
public $product_name;
|
|
public $product_info;
|
|
public $amount;
|
|
public $price;
|
|
public $price_total;
|
|
public $price_gross;
|
|
public $vatrate;
|
|
public $fibu_cost_account;
|
|
public $fibu_cost_account_legacy;
|
|
public $fibu_taxcode;
|
|
public $billing_period;
|
|
public $options;
|
|
|
|
public $create_by;
|
|
public $edit_by;
|
|
public $create;
|
|
public $edit;
|
|
|
|
|
|
public static function create(Array $data) {
|
|
$model = new Invoiceposition();
|
|
|
|
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("Invoiceposition", "*", "1 = 1 ORDER BY invoice_id,contract_id,start_date,matchcode");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new Invoiceposition($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM Invoiceposition
|
|
WHERE $where
|
|
ORDER BY invoice_id,contract_id,start_date,matchcode LIMIT 1";
|
|
//var_dump($sql);exit;
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new Invoiceposition($data);
|
|
if($item->id) {
|
|
return $item;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function count($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT COUNT(*) as cnt FROM Invoiceposition
|
|
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 = "invoice_id,contract_id,id ASC";
|
|
}
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM Invoiceposition
|
|
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 Invoiceposition($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 Invoiceposition.id = $id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("invoice_id", $filter)) {
|
|
$invoice_id = $filter['invoice_id'];
|
|
if(is_numeric($invoice_id)) {
|
|
$where .= " AND Invoiceposition.invoice_id=$invoice_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("add-where", $filter)) {
|
|
$where .= " ".$filter['add-where'];
|
|
}
|
|
|
|
//var_dump($filter, $where);exit;
|
|
return $where;
|
|
}
|
|
|
|
}
|