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 @@ -extend('layouts/smarthome'); ?> +extend('layout'); ?> + section('menu'); ?> - include('menu/dashboard_menu') ?> +include('sidebar') ?> endSection(); ?> section('content'); ?>
diff --git a/app/Views/newBill.php b/app/Views/newBill.php index 505cab0..a0a5cea 100644 --- a/app/Views/newBill.php +++ b/app/Views/newBill.php @@ -14,7 +14,12 @@
-

+ +

+ +

+ +
- - - - - + + + + +
@@ -124,8 +129,11 @@ + Zeile > + + + - Zurück +
diff --git a/app/Views/viewBillImg.php b/app/Views/viewBillImg.php new file mode 100644 index 0000000..f768cf1 --- /dev/null +++ b/app/Views/viewBillImg.php @@ -0,0 +1 @@ +Rechnung <?=$filename?> \ No newline at end of file diff --git a/public/js/billing.js b/public/js/billing.js index a41799a..110a787 100644 --- a/public/js/billing.js +++ b/public/js/billing.js @@ -1,81 +1,97 @@ -$(function() { - $('.parent').change(function() { - var $subs = $(this).parent().parent().children( ".sub" ).children(); +$(function () { + $('.parent').change(function () { + var $subs = $(this).parent().parent().children(".sub").children(); $subs.children().remove().end(); var $output = ''; $liste = subsdata[$(this).val()]; - $sort = Object.entries($liste).sort((a,b) => (a[1]>b[1])?1:(b[1]>a[1])?-1:0); - $.each($sort, function(key, value) { - $output += ''; + $sort = Object.entries($liste).sort((a, b) => (a[1] > b[1]) ? 1 : (b[1] > a[1]) ? -1 : 0); + $.each($sort, function (key, value) { + $output += ''; }); $subs.append($output); }); - $('#multi').change(function() { - if($(this).is(":checked")) { + $('#multi').change(function () { + if ($(this).is(":checked")) { $('.single').addClass('d-none'); $('.multi').removeClass('d-none'); - return; + return; } $('.single').removeClass('d-none'); $('.multi').addClass('d-none'); //'unchecked' event code - }).change(); - $('.dt-amount, .dt-subamount').change(function() { - var temp = convertInput( $(this).val()); - $(this).val( convertOutput(temp)); + }).change(); + $('.dt-amount, .dt-subamount').change(function () { + var temp = convertInput($(this).val()); + $(this).val(convertOutput(temp)); if ($('#multi').is(":checked")) { recalcOpenAmount(); } - }).change(); - + }).change(); + }); -function logData(event){ +function logData(event) { var data = document.getElementById("billfile"); console.log(data.value); - + } -function addLine(){ +function addLine() { $('#linecont > div').each(function () { - if ($(this).hasClass("d-none")){ + if ($(this).hasClass("d-none")) { $(this).removeClass("d-none"); return false; } }); } -function convertInput( number ) -{ - var zahl = number.replace( /\,/g, "." ); - var czahl = eval( zahl ); +function removeBillFile(e) { + e.classList.add("d-none"); + document.getElementById("billfile").classList.remove("d-none"); + + const billFile = document.getElementById("billfileRef"); + const form = document.getElementById('newbill'); + var DOB = document.createElement("input"); + DOB.setAttribute("name", "removeBillFile"); + DOB.setAttribute("value", billFile.innerText); + DOB.setAttribute("type", "hidden"); + form.appendChild(DOB); + + + billFile.innerText = "REMOVED FILE: "+billFile.innerText; + billFile.classList.add("text-decoration-line-through"); + billFile.classList.add("text-danger"); + billFile.removeAttribute("href"); +} + +function convertInput(number) { + var zahl = number.replace(/\,/g, "."); + var czahl = eval(zahl); return czahl; } -function convertOutput( number ) -{ - if ( typeof number !== 'undefined' ) - { - var string = number.toFixed( 2 ); - return string.replace( /\,/g, "." ); +function convertOutput(number) { + if (typeof number !== 'undefined') { + var string = number.toFixed(2); + return string.replace(/\,/g, "."); } else return ""; } -function recalcOpenAmount(){ +function recalcOpenAmount() { var summe = 0.0; $('.dt-subamount').each(function () { b = $(this).val(); b = convertInput(b); - if (typeof b !== 'undefined'){ - b = $(this).hasClass("text-danger") ? b*(-1) : b; - summe = summe +b; + if (typeof b !== 'undefined') { + b = $(this).hasClass("text-danger") ? b * (-1) : b; + summe = summe + b; } - // summe = summe + convertInput($(this).val()); + // summe = summe + convertInput($(this).val()); }); - - $('#openamount').val(Math.round( ($('#total_in').val() - $('#total_out').val() - summe) * 100 ) / 100); + + $('#openamount').val(Math.round(($('#total_in').val() - $('#total_out').val() - summe) * 100) / 100); } // $('form').submit(function () {