69 lines
2.9 KiB
PHP
69 lines
2.9 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)){
|
|
log_message('debug',"Parent not exists: $parentId in List: ".json_encode(array_keys($list)));
|
|
$list[$parentId] = $this->accounts->getDropDownEntry($parentId);
|
|
}
|
|
}
|
|
|
|
private function checkCreateSubDefault(array &$list, int $accountId) : void {
|
|
if (!array_key_exists($accountId, $list)){
|
|
if ($accountId > 0)
|
|
$list[$accountId] = $this->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]);
|
|
}
|
|
} |