redesign for mulituser

change validation concept (client and server)
using entities
This commit is contained in:
Markus
2026-10-06 08:55:35 +02:00
parent 14e050e4ba
commit 995e2ec111
41 changed files with 2402 additions and 1223 deletions

View File

@@ -3,31 +3,60 @@
use CodeIgniter\Model;
class mBillDetails extends Model {
protected $table = 'budget_billdetails';
private $defaultTableName='_budget_billdetails';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'object';
protected $useSoftDeletes = false;
protected $returnType = \App\Entities\eBookingLine::class;
protected $useSoftDeletes = true;
protected $deletedField ="deleted_at";
protected $allowedFields = ['bill_id','comment','account_id','subamount','lkz'];
protected $allowedFields = ['bill_id','comment','account_id','subamount','deleted_at'];
protected $useTimestamps = false;
// public function getEntries($id){
// $this->select('mw_budget_bookingdetails.*,mw_budget_categories.description');
// $this->join('mw_budget_categories', 'mw_budget_categories.id = mw_budget_bookingdetails.account_id', 'left');
// $result = $this->orderBy('id','asc')->where('bill_id',$id)->findAll();
// foreach ($result as $key => $value) {
// // $value->datum = date( "d.m.Y", strtotime( $value->datum ));
// // $value->amount = number_format( $value->amount , 2, ',', '.' );
// }
// return $result;
// }
protected array $casts = [
'subamount' => 'float',
'account_id' => 'int',
'bill_id' => 'int',
];
public function getDetails($ids){
protected $validationRules = [
'bill_id' => 'required|numeric',
'account_id' => 'required|numeric',
];
protected $validationMessages = [
'bill_id' => [
'required' => 'Die Buchungsnummer muss angegeben sein.',
'numeric' => 'Die Buchungsnummer muss eine Zahl sein.',
],
'account_id' => [
'required' => 'Die Kategorie muss angegeben sein.',
'numeric' => 'Die Kategorie muss eine Zahl sein.',
],
];
protected function initialize() {
log_message('debug','mBillDetails initialize');
$this->table = auth()->user()->preFixDB.$this->defaultTableName;
$this->checkOrCreateTable();
}
public function getEntries(int $id){
$accounts = model('App\Models\mAccounts'); /* @var \App\Models\mAccounts $accounts */
$this->select($this->table.'.*,'.$accounts->getTable().'.description');
$this->join($accounts->getTable(), $accounts->getTable().'.id = '.$this->table.'.account_id', 'left');
$result = $this->orderBy('id','asc')->where('bill_id',$id)->findAll();
return $result;
}
/**
* liefert für gegebene Buchung Details
* @param array<int> $ids id der Buchung
*/
public function getDetails(array $ids): array {
$quelle = model('App\Models\mAccounts');
$rows = $this->whereIn('bill_id', $ids)->findAll();
$result = array();
@@ -37,9 +66,18 @@ class mBillDetails extends Model {
}
return $result;
}
public function getEntriesForForm($billId, &$result, $accounts){
$this->select('budget_billdetails.*,budget_accounts.description');
$this->join('budget_accounts', 'budget_accounts.id = budget_billdetails.account_id', 'left');
/**
* liefert für gegebene Buchung Details im Formularformat
* @param int $billId id der Buchung
* @param mixed $result Datenstruktur für Formular mit defaults
* @param \App\Models\mAccounts $accounts modelClass für Konten
*
*/
public function getEntriesForForm(int $billId, &$result){
$accounts = model('App\Models\mAccounts');
$this->select($this->table.'.*,'.$accounts->getTable().'.description');
$this->join($accounts->getTable(), $accounts->getTable().'.id = '.$this->table.'.account_id', 'left');
$data = $this->orderBy('id','asc')->where('bill_id',$billId)->findAll();
$amount = 0.0;
foreach ($data as $key => $row){
@@ -58,12 +96,12 @@ class mBillDetails extends Model {
$result['total_in']= ($amount >= 0.0)?number_format( abs( $amount ), 2, ',', '' ):'';
$result['total_out']= ($amount < 0.0)?number_format( abs( $amount ), 2, ',', '' ):'';
}
else if ($accounts->checkType($result['category'][0],'account'))
else if ($accounts->isAccount($result['category'][0]))
$result['transfer'] = true;
return $result;
}
public function saveEntries($data, $billId){
public function saveEntries(array $data, int $billId){
for ($i=0;$i<10;$i++){
if ($data['category'][$i] > 0){
$this->set('subamount', floatval($data['input'][$i])-floatval($data['output'][$i])); //floatval($data['total_in'])-floatval($data['total_out']));
@@ -82,5 +120,28 @@ class mBillDetails extends Model {
}
}
}
public function checkOrCreateTable(){
log_message('debug',"Check or Create BillDetails Table");
if ($this->db->tableExists($this->table)) return;
log_message('debug',"Create BillDetails Table ".$this->table);
$accounts = model('App\Models\mAccounts'); /* @var \App\Models\mAccounts $accounts */
$bills = model('App\Models\mBills'); /* @var \App\Models\mBills $bills */
$forge = \Config\Database::forge();
$fields = array(
'id' => array( 'type' => 'serial'),
'bill_id' => array( 'type' => 'integer'),
'account_id' => array( 'type' => 'integer' ),
'subamount' => array( 'type' => 'numeric','constraint' => '9,2' ),
'comment' => array( 'type' => 'character varying','constraint' => '150'),
'deleted_at'=> array( 'type' => 'timestamp without time zone','null'=>true),
);
$forge->addField( $fields );
$forge->addPrimaryKey('id');
$forge->addForeignKey('bill_id', $bills->getTable(), 'id','NO ACTION','NO ACTION','bill_id_fk');
$forge->addForeignKey('account_id', $accounts->getTable(), 'id','NO ACTION','NO ACTION','account_id_fk');
$forge->createTable($this->table,true);
log_message('debug','Create BillDetails Table '.$this->db->lastQuery);
}
};
?>