redesign for mulituser
change validation concept (client and server) using entities
This commit is contained in:
90
app/Controllers/Bills.php
Normal file
90
app/Controllers/Bills.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php namespace App\Controllers;
|
||||
|
||||
use App\Models\mAccounts;
|
||||
|
||||
use function PHPUnit\Framework\logicalXor;
|
||||
use App\Models\mBills;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
include_once (dirname(__FILE__) . "/FormHandler.php");
|
||||
|
||||
class Bills extends FormHandler {
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function edit(int $id, bool $transfer=false){
|
||||
if ($id == 0){ // erstellen eines leeren Formular
|
||||
log_message('debug','Bills::edit: new bill');
|
||||
$eBooking = new \App\Entities\eBooking();
|
||||
$eBooking->transfer = $transfer;
|
||||
$eBooking->scheduled = false;
|
||||
$data = $eBooking->getNew();
|
||||
} else {
|
||||
$billModel = model(mBills::class);
|
||||
$bill = $billModel->find($id); /* @var \App\Entity\eBooking $bill */
|
||||
$bill->datum = date( "Y-m-d", strtotime( $bill->datum ));
|
||||
$data = $bill->fillDetails();
|
||||
log_message('debug','Bills::edit:ID:'.$id.'; Data: '.json_encode($bill->toArray()));
|
||||
}
|
||||
return $this->viewBill($data);
|
||||
}
|
||||
|
||||
public function viewActivities(){
|
||||
$accounts = model('App\Models\mAccounts'); /* @var \App\Models\mAccounts $accounts */
|
||||
$data = array();
|
||||
$data['source'] = 0;
|
||||
$data['start'] = session('datum_start') ?? date("Y-m-d", strtotime( "- 2 weeks", strtotime( "now" ) ));
|
||||
$data['ende'] = session('datum_ende') ?? date("Y-m-d", strtotime( "now" ) );
|
||||
$data['source'] = session('source') ?? 0;
|
||||
$data['sourcelist'] = $accounts->getDropDownList( 'all', true );
|
||||
return view('activities', $data);
|
||||
}
|
||||
|
||||
public function getOverviewData(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
$result = $billing->getEntries(10);
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
public function getActivitiesData(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
$start = $this->request->getPost('datum_start')??session('datum_start');
|
||||
$ende = $this->request->getPost('datum_ende')??session('datum_ende');
|
||||
$src = intval($this->request->getPost('source'));
|
||||
$_SESSION['datum_start'] = $start;
|
||||
$_SESSION['datum_ende'] = $ende;
|
||||
$_SESSION['source'] = $src;
|
||||
$result = $billing->getEntriesDet($start,$ende,$src);
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
public function delete(){
|
||||
if ($this->request->is('post')) {
|
||||
if (!ctype_digit($this->request->getPost("id"))) return $this->failForbidden("Ungültige ID");
|
||||
log_message('debug',"delete id: ".$this->request->getPost("id"));
|
||||
$billModel = model(mBills::class);
|
||||
$result = $billModel->deleteEntry(intval($this->request->getPost("id")));
|
||||
if ($result !== true)
|
||||
return $this->fail("Database error ".$result);
|
||||
else
|
||||
return $this->respondDeleted(['url'=>session('redirect_url') ?? site_url('/'),'ID'=>$this->request->getPost("id")]);
|
||||
}
|
||||
return $this->failUnauthorized("Schäm Dich");
|
||||
}
|
||||
|
||||
public function getToDosData(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
return json_encode($billing->getToDos());
|
||||
}
|
||||
|
||||
public function getAccountsBalance(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
return json_encode($billing->getAccountsBalance());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user