WIP Contract/Billing/Invoice 2024-06-28

This commit is contained in:
Frank Schubert
2024-07-01 11:44:19 +02:00
parent 4589e61ab8
commit ae298a0665
30 changed files with 1898 additions and 212 deletions
@@ -0,0 +1,34 @@
<?php
class Invoiceposition extends mfBaseModel {
public function __clone() {
$me = new User;
$me->loadMe();
$old_id = $this->id;
$this->id = null;
// cleanup data
$this->invoice_id = null;
$this->create_by = $me->id;
$this->edit_by = $me->id;
$this->create = null;
$this->edit = null;
$this->saved = 0;
$this->mode = "new";
$this->_old_data = new StdClass();
/*$this->save();
if($old_id == $this->id) {
$this->log->error("save() of cloned Contract $old_id failed!");
throw new Exception("Saving clone failed.");
}*/
//$this->log->debug("Cloned Invoiceposition $old_id");
}
}
@@ -0,0 +1,165 @@
<?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 $billing_period;
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,start_date,matchcode 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;
}
}