Files
finanzen/app/Entities/eBookingLine.php
Markus 3d99e672e3 fix accounts reference
fix table name for check_or_create on bill table
2026-10-06 21:41:45 +02:00

71 lines
3.1 KiB
PHP

<?php
namespace App\Entities;
use CodeIgniter\Entity\Entity;
use App\Models\mAccounts;
class eBookingLine extends Entity{
protected $attributes =[
'id' => 0,
'bill_id' => 0,
'comment' => '',
'account_id' => 0,
'subamount' => null,
'deleted_at' => null,
];
protected $datamap = [
// property_name => db_column_name
'sid' => 'id',
];
private function checkCreateParentDefault(array &$list, int $parentId) : void {
if ($parentId == 0) return;
if (!array_key_exists($parentId, $list)){
$accounts = model('App\Models\mAccounts'); /* @var \App\Models\mAccounts $accounts */
log_message('debug',"Parent not exists: $parentId in List: ".json_encode(array_keys($list)));
$list[$parentId] = $accounts->getDropDownEntry($parentId);
}
}
private function checkCreateSubDefault(array &$list, int $accountId) : void {
if (!array_key_exists($accountId, $list)){
if ($accountId > 0){
$accounts = model('App\Models\mAccounts'); /* @var \App\Models\mAccounts $accounts */
$list[$accountId] = $accounts->getDropDownEntry($accountId);
} else
$list[0] = '-----';
}
}
public function createFormData(array &$data, int $i){
if (!array_key_exists('sid', $data)) $data['sid'] = [];
if (!array_key_exists('comment', $data)) $data['comment'] = [];
if (!array_key_exists('account_id', $data)) $data['account_id'] = [];
if (!array_key_exists('deleted_at', $data)) $data['deleted_at'] = [];
if (!array_key_exists('input', $data)) $data['input'] = [];
if (!array_key_exists('output', $data)) $data['output'] = [];
$data['sid'][$i] = $this->attributes['id'];
$data['comment'][$i] = $this->attributes['comment'];
$data['account_id'][$i] = $this->attributes['account_id'];
$data['deleted_at'][$i] = $this->attributes['deleted_at'];
$data['input'][$i] = (!is_null($this->attributes['subamount']) && $this->attributes['subamount'] > 0.0) ? $this->attributes['subamount'] :'';
$data['output'][$i] = (!is_null($this->attributes['subamount']) && $this->attributes['subamount'] <= 0.0) ? abs($this->attributes['subamount']) :'';
$this->createDropDownLists($data,$i);
}
public function createDropDownLists(array &$data, int $i){
$accounts = model('App\Models\mAccounts'); /* @var \App\Models\mAccounts $accounts */
$lists = $data['category'] ?? [];
if (!array_key_exists('parent_id', $data)) $data['parent_id'] = [];
if (!array_key_exists('cat_parent', $data)) $data['cat_parent'] = [];
if (!array_key_exists('cat_sub', $data)) $data['cat_sub'] = [];
$data['parent_id'][$i] = $accounts->getParent($data['account_id'][$i]);
$data['cat_parent'][$i] = $lists['parent'];
$this->checkCreateParentDefault($data['cat_parent'][$i],$data['parent_id'][$i]);
$data['cat_sub'][$i] = $lists['subs']->{$data['parent_id'][$i]} ?? [];
$this->checkCreateSubDefault($data['cat_sub'][$i],$data['account_id'][$i]);
}
}