Add Gutschrift functionality to ManualInvoice with modal and backend support
This commit is contained in:
@@ -1,160 +1,28 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
class ManualInvoicepositionModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
public ?int $manualinvoice_id;
|
||||
public ?int $billing_id;
|
||||
public int $contract_id;
|
||||
public string $start_date;
|
||||
public ?string $end_date;
|
||||
public ?string $matchcode;
|
||||
public int $product_id;
|
||||
public string $product_name;
|
||||
public ?string $product_info;
|
||||
public float $amount;
|
||||
public float $price;
|
||||
public float $price_total;
|
||||
public float $price_gross;
|
||||
public float $vatrate;
|
||||
public ?int $fibu_cost_account;
|
||||
public ?int $fibu_cost_account_legacy;
|
||||
public ?int $fibu_taxcode;
|
||||
public int $billing_period;
|
||||
public ?string $options;
|
||||
public int $create_by;
|
||||
public int $edit_by;
|
||||
public int $create;
|
||||
public int $edit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user