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,17 +3,26 @@
use CodeIgniter\Model;
class mScheduled extends Model {
protected $table = 'budget_scheduled';
protected $primaryKey = 'id';
private $defaultTableName='_budget_scheduled';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $useSoftDeletes = true;
protected $deletedField ="deleted_at";
protected $allowedFields = ['creat_date','next_date','data'];
protected $useTimestamps = false;
protected $skipValidation = false;
public function calcNextDate($date, $num, $type)
protected function initialize() {
$this->table = auth()->user()->preFixDB.$this->defaultTableName;
$this->checkOrCreateTable();
}
public function calcNextDate(string $date, string $num, string $type)
{
$start = strtotime( $date );
$period = $num .' '. $type;
@@ -24,68 +33,78 @@ class mScheduled extends Model {
return date( "Y-m-d", $future );
}
public function getEntry($id){
$accounts = model('App\Models\mAccounts');
public function getEntry(int $id){
$data = $this->asObject()->find($id);
$result = (array)json_decode($data->data);
$result['id'] = $id;
$result['datum'] = $data->next_date; //date( "d.m.Y", strtotime($data->next_date));
for ($i=0;$i<10;$i++){
$result['category_parent'][$i]= $accounts->getParent($result['category'][$i]);
}
return $result;
}
public function getEntries(){
$quelle = model('App\Models\mAccounts');
$result = $this->asObject()->findAll();
log_message('error', 'Get Entries Schedules: {msg}', ['msg'=>(string)$this->db->getLastQuery()]);
foreach ($result as $value) {
$details = json_decode($value->data);
for ($i=0;$i<10;$i++){
if ((floatval($details->input[$i]) == 0.0) && (floatval($details->output[$i]) == 0.0))
foreach ($details->input as $key => $line){
if ((floatval($line) == 0.0) && (floatval($details->output[$key]) == 0.0))
continue;
$value->details[] = ['comment'=>$details->comment[$i], 'description'=>$quelle->getDropDownEntry($details->category[$i]), 'subamount'=>(floatval($details->input[$i])-floatval($details->output[$i]))];
// $account_id = (!isset($details->account_id))?$details->category:$details->account_id;
$value->details[] = ['comment'=>$details->comment[$key], 'description'=>$quelle->getDropDownEntry($details->account_id[$key]), 'subamount'=>(floatval($details->input[$key])-floatval($details->output[$key]))];
}
//$value->details = null;
$value->datum = date( "d.m.Y", strtotime( $value->next_date ));
$value->source = $quelle->getDropDownEntry($details->source);
$source_id = (!isset($details->source_id))?$details->source:$details->source_id;
$value->source = $quelle->getDropDownEntry($source_id);
$value->receiver = $details->receiver;
$value->amount = floatval($details->total_in)-floatval($details->total_out);
// $value->amount = number_format( $value->amount , 2, ',', '.' );
// if (!isset($details->amount)){
// $value->amount = floatval($details->total_in)-floatval($details->total_out);
// $value->amount = number_format( floatval($value->amount) , 2, ',', '.' );
// }
// else
$value->amount = $details->amount; //number_format( floatval($details->amount) , 2, ',', '.' );
}
return $result;
}
public function saveBill($data){
public function saveIt(array $data){
$accounts = model('App\Models\mAccounts');
$data['validate'] = true;
$data['scheduled'] = true;
$data['renummer'] = isset($data['renummer']);
if ($data['transfer']==1){
$data['receiver'] = $accounts->getDropDownEntry($data['category'][0]);
$data['transfer'] = true;
}
else{
$data['multi'] = isset($data['multiple']);
$data['transfer'] = false;
}
unset($data['openamount']);
unset($data['category_parent']);
$data['datum'] = date( "Y-m-d", strtotime($data['datum'] ) );
unset($data['total_in']);
unset($data['total_out']);
// $data['datum'] = date( "Y-m-d", strtotime($data['datum'] ) );
$this->set('next_date', $data['datum']);
$data['total_in'] = 0;
$data['total_out'] = 0;
for ($i=0;$i<10;$i++){
if ($data['category'][$i] > 0){
$data['total_in'] += floatval($data['input'][$i]);
$data['total_out'] += floatval($data['output'][$i]);
}
}
$this->set('data',json_encode($data));
log_message("debug","save Scheduled".json_encode($data));
if ( 0 == $data['id']) $this->insert();
else $this->update($data['id']);
}
public function checkOrCreateTable(){
log_message('debug',"Check or Create Scheduled Table");
if ($this->db->tableExists($this->table)) return;
log_message('debug','Create Scheduled Table '.$this->db->lastQuery);
log_message('debug',"Create Scheduled Table ".$this->table);
$forge = \Config\Database::forge();
$fields = array(
'id' => array( 'type' => 'serial'),
'creat_date' => array( 'type' => 'date','default'=>new \CodeIgniter\Database\RawSql('CURRENT_TIMESTAMP')),
'next_date' => array( 'type' => 'date'),
'data' => array( 'type' => 'text'),
'deleted_at'=> array( 'type' => 'timestamp without time zone','null'=>true),
);
$forge->addField( $fields );
$forge->addPrimaryKey('id');
$forge->createTable($this->table,true);
log_message('debug','Create Scheduled Table '.$this->db->lastQuery);
}
}