161 lines
4.2 KiB
PHP
161 lines
4.2 KiB
PHP
<?php
|
|
|
|
class ManualInvoicepositionModel {
|
|
public $manualinvoice_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 ManualInvoiceposition();
|
|
|
|
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("ManualInvoiceposition", "*", "1 = 1 ORDER BY manualinvoice_id,contract_id,start_date,matchcode");
|
|
if($db->num_rows($res)) {
|
|
while($data = $db->fetch_object($res)) {
|
|
$items[] = new ManualInvoiceposition($data);
|
|
}
|
|
}
|
|
return $items;
|
|
|
|
}
|
|
|
|
public static function getFirst($filter) {
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM ManualInvoiceposition
|
|
WHERE $where
|
|
ORDER BY manualinvoice_id,contract_id,start_date,matchcode LIMIT 1";
|
|
|
|
$res = $db->query($sql);
|
|
if($db->num_rows($res)) {
|
|
$data = $db->fetch_object($res);
|
|
$item = new ManualInvoiceposition($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 ManualInvoiceposition WHERE $where";
|
|
|
|
$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) {
|
|
$items = [];
|
|
|
|
if(!$order) {
|
|
$order = "manualinvoice_id,contract_id,id ASC";
|
|
}
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
$where = self::getSqlFilter($filter);
|
|
$sql = "SELECT * FROM ManualInvoiceposition 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 ManualInvoiceposition($data);
|
|
}
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
private static function getSqlFilter($filter) {
|
|
$where = "1=1 ";
|
|
|
|
$db = FronkDB::singleton();
|
|
|
|
if(array_key_exists("id", $filter)) {
|
|
$id = $filter['id'];
|
|
if(is_numeric($id)) {
|
|
$where .= " AND ManualInvoiceposition.id = $id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("manualinvoice_id", $filter)) {
|
|
$manualinvoice_id = $filter['manualinvoice_id'];
|
|
if(is_numeric($manualinvoice_id)) {
|
|
$where .= " AND ManualInvoiceposition.manualinvoice_id=$manualinvoice_id";
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("add-where", $filter)) {
|
|
$where .= " ".$filter['add-where'];
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
}
|