diff --git a/app/Controllers/Charts.php b/app/Controllers/Charts.php index 84737ba..8d4acee 100644 --- a/app/Controllers/Charts.php +++ b/app/Controllers/Charts.php @@ -56,6 +56,9 @@ class Charts extends BaseController { GROUP BY description, account_id EOD; $data = array(); + $werte = array(); + $ids = array(); + $labels = array(); $result = $this->db->query($query); foreach ($result->getResult() as $row) { $werte[] = $row->amount; diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 54f593f..76869d7 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -160,17 +160,23 @@ class Home extends BaseController return $result; } - public function viewBill($filename) { + public function viewBill(string $filename) { $filePath= WRITEPATH . '/uploads'; $file = new \CodeIgniter\Files\File($filePath."/".$filename); log_message('debug',$file->getMimeType()); if ($file->getMimeType() == 'application/pdf') $this->viewPdf($filename); - else - return view('viewBillImg', ['filename'=>WRITEPATH . '/uploads'.$filename]); + else{ + $imginfo = getimagesize($filePath."/".$filename); + header("Content-type: {$imginfo['mime']}"); + readfile($filePath."/".$filename); + exit; + } +// return view('viewBillImg', ['filename'=>'writable/uploads/'.$filename]); } - public function viewPdf($filename) { + + public function viewPdf(string $filename) { $view = \Config\Services::renderer(); log_message('debug',$filename); $filePath= WRITEPATH . '/uploads'; @@ -212,7 +218,7 @@ class Home extends BaseController if (! $file->isValid() && ($file->getError() != UPLOAD_ERR_NO_FILE)) { throw new \RuntimeException($file->getErrorString() . '(' . $file->getError() . ')'); } else if ($file->isValid()) { - $rules['billfile'] = ['uploaded[billfile]','max_size[billfile,10000]','mime_in[billfile,application/pdf]']; + $rules['billfile'] = ['uploaded[billfile]','max_size[billfile,10000]','mime_in[billfile,application/pdf,image/jpg,image/jpeg]']; $errors['billfile'] = ['uploaded'=>'Fehler beim Upload','max_size' => 'Zu Groß', 'mime_in' => "Ungültiger Datentyp"]; $uploading = true; } @@ -223,23 +229,30 @@ class Home extends BaseController } else{ $data = $this->request->getPost(); - //log_message('debug',print_r($data,true)); + log_message('debug',print_r($data,true)); + if ($this->request->getPost('scheduled') =="0"){ - if ($uploading){ - $date = Time::parse($this->request->getPost('datum')); - $file->move(WRITEPATH . 'uploads',$date->toLocalizedString('yyyyMMdd')." ".$this->request->getPost('receiver')." ".$this->request->getPost("comment[0]").".".$file->guessExtension()); - $data['rechnung'] = $file->getName(); - log_message('debug', $file->getName()); - } $bills = model('App\Models\mBills'); - $bills->saveBill($data); + if ($this->request->getPost('removeBillFile')){ + $bills->deleteBillFile($data['id']); + unlink(WRITEPATH . 'uploads/'.$this->request->getPost('removeBillFile')); + } + $billId = $bills->saveBill($data); + + if ($uploading){ + $date = Time::parse($data['datum']); + $file->move(WRITEPATH . 'uploads',$date->toLocalizedString('yyyyMMdd')." ".$data['receiver']." ".$billId.".".$file->guessExtension()); + log_message('debug', $file->getName()); + $bills->storeBillFile($billId, $file->getName()); + } + $redirectURL = session('redirect_url') ?? site_url('/'); unset($_SESSION['redirect_url']); return redirect()->to($redirectURL); } else{ $scheduled = model('App\Models\mScheduled'); - $scheduled->saveBill($this->request->getPost()); + $scheduled->saveBill($data); } $this->response->redirect(site_url('/')); } diff --git a/app/Models/mBills.php b/app/Models/mBills.php index c6875d3..4ae8369 100644 --- a/app/Models/mBills.php +++ b/app/Models/mBills.php @@ -6,12 +6,17 @@ use App\Models\Mcategories; class mBills extends Model { protected $table = 'budget_bills'; - protected $primaryKey = 'id'; + protected $primaryKey = 'id'; protected $useAutoIncrement = true; protected $returnType = 'object'; + protected $useSoftDeletes = false; + //TODO timestamps aktivieren + // protected $createdField = 'created_at'; + // protected $updatedField = 'updated_at'; + // protected $deletedField = 'deleted_at'; protected $allowedFields = ['renummer','datum','receiver','source_id','amount','type','comment','validate','lkz','rechnung']; @@ -131,45 +136,19 @@ class mBills extends Model { return $result; } function getAccountsBalance(){ - // $this->select('SUM(amount) as amount, source_id as idd, budget_accounts.description',FALSE); - // $this->groupby('source_id')->asArray(); - // $this->join('budget_accounts', 'budget_accounts.id = budget_bills.source_id', 'left'); - // $this->where('budget_accounts.type','account'); - // $this->where('budget_accounts.lkz',null); - // $this->where('budget_bills.validate',false); - // $result1 = $this->where('budget_bills.lkz',null)->findAll(); - // $assoc1 = array(); - // foreach ($result1 as $value) { - // $assoc1[$value['idd']] = $value; - // } - - // $details = model('App\Models\mBillDetails'); - // $details->select('SUM((-1)*subamount) as amount, account_id as idd, budget_accounts.description',FALSE); - // $details->groupby('account_id')->asArray(); - // $details->join('budget_accounts', 'budget_accounts.id = budget_billdetails.account_id', 'left'); - // $details->join('budget_bills', 'budget_bills.id = budget_billdetails.bill_id', 'left'); - // $details->where('budget_accounts.type','account'); - // $details->where('budget_bills.validate',false); - // $details->where('budget_accounts.lkz',NULL); - // $result3 = $details->where('budget_billdetails.lkz',NULL)->findAll(); - // $assoc3 = array(); - // foreach ($result3 as $value) { - // $assoc3[$value['idd']] = $value; - // } - // $sums = array(); - // foreach (array_keys($assoc1 + $assoc3) as $key) { - // $obj = new \stdClass; - // $obj->amount = (isset($assoc1[$key]) ? floatval($assoc1[$key]['amount']) : 0) + (isset($assoc3[$key]) ? floatval($assoc3[$key]['amount']) : 0); - // $obj->description = isset($assoc1[$key]) ? $assoc1[$key]['description'] : $assoc3[$key]['description']; - // $sums[] = $obj; - // } $sums = $this->db->query("SELECT * FROM get_account_balance4()"); - //$this->from("get_account_balance4()")->findAll(); - // $this->groupby('source_id')->asArray(); return $sums->getResult(); } - public function saveBill($data){ + public function storeBillFile(int $billId, string $filename){ + $this->update($billId, [ 'rechnung' => $filename ]); + } + public function deleteBillFile(int $billId){ + $this->set('rechnung', 'NULL',false); + $this->update($billId); + } + + public function saveBill($data) : int { $details = model('App\Models\mBillDetails'); $accounts = model('App\Models\mAccounts'); $this->set('datum', date( "Y-m-d", strtotime($data['datum'] ) )); @@ -201,7 +180,7 @@ class mBills extends Model { $this->update($data['id']); } $details->saveEntries($data, $billId); - + return $billId; } /** diff --git a/app/Views/auth/register.php b/app/Views/auth/register.php index ef0d17e..6506752 100644 --- a/app/Views/auth/register.php +++ b/app/Views/auth/register.php @@ -1,6 +1,7 @@ -= $this->extend('layouts/smarthome'); ?> += $this->extend('layout'); ?> + = $this->section('menu'); ?> - = $this->include('menu/dashboard_menu') ?> += $this->include('sidebar') ?> = $this->endSection(); ?> = $this->section('content'); ?>