From 842d9050dc4bdf8c645c83b36c1f602fdc066b83 Mon Sep 17 00:00:00 2001 From: Markus Date: Fri, 16 May 2025 21:21:09 +0200 Subject: [PATCH] html5 datetime instead of jquery anhang pdf rechnung --- app/Config/App.php | 2 +- app/Controllers/Home.php | 57 +++++++++++++++++++++++++++++++++++---- app/Models/mBills.php | 8 +++--- app/Models/mScheduled.php | 2 +- public/js/billing.js | 6 +++++ public/js/tables.js | 4 ++- 6 files changed, 68 insertions(+), 11 deletions(-) diff --git a/app/Config/App.php b/app/Config/App.php index 7f2cd47..21f258b 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -91,7 +91,7 @@ class App extends BaseConfig | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! | */ - public string $permittedURIChars = 'a-z 0-9~%.:_\-'; + public string $permittedURIChars = 'a-z 0-9~%.:_\-\x{0080}-\x{00ff}'; /** * -------------------------------------------------------------------------- diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 17b242c..54f593f 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -4,6 +4,8 @@ namespace App\Controllers; use App\Models\mBills; use App\Models\mAccounts; use CodeIgniter\Session\Session; +use CodeIgniter\Files\File; +use CodeIgniter\I18n\Time; class Home extends BaseController { @@ -157,9 +159,38 @@ class Home extends BaseController // } return $result; } + + public function viewBill($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]); + } + public function viewPdf($filename) { + $view = \Config\Services::renderer(); + log_message('debug',$filename); + $filePath= WRITEPATH . '/uploads'; + header("Cache-Control: maxage=1"); + header("Pragma: public"); + header('Content-type:application/pdf'); + header('Content-disposition: inline; filename="'.$filename.'"'); + header('content-Transfer-Encoding:binary'); + header('Content-Length:' .filesize($filePath."/".$filename)); + if (($pdf =file_get_contents($filePath."/".$filename)) === false) + print $filePath."/".$filename; + else + print $pdf; + exit; + } + public function attemptNewBilling() { + helper('form'); + $uploading = false; $rules = [ 'source' => 'required|greater_than[0]', 'datum' => 'required', @@ -170,22 +201,38 @@ class Home extends BaseController 'source' => ['required' => 'Konto fehlt','greater_than' => 'Konto fehlt'], 'datum' => ['required' => 'Datum fehlt']]; // 'totalamount' => ['required' => 'Betrag fehlt','numeric' => 'Betrag muss eine Zahl sein']]; - if ( 'on' == $this->request->getPost('multi') ) - { + if ( 'on' == $this->request->getPost('multi') ) { $rules['openamount'] = 'equals[0]'; $errors['openamount'] = ['equals' => 'Betrag muss 0 sein']; } - $fehler= array(); $valid = $this->customValidation($fehler); + $file = $this->request->getFile('billfile'); + if ($file) { + 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]']; + $errors['billfile'] = ['uploaded'=>'Fehler beim Upload','max_size' => 'Zu Groß', 'mime_in' => "Ungültiger Datentyp"]; + $uploading = true; + } + } if ((! $this->validate($rules,$errors)) || (!$valid)){ return $this->newBill($this->request->getPost(), array_merge($this->validator->getErrors(),$fehler),$this->request->getPost('scheduled')); // return redirect()->back()->withInput()->with('errors', $validation->getErrors()); } else{ + $data = $this->request->getPost(); + //log_message('debug',print_r($data,true)); if ($this->request->getPost('scheduled') =="0"){ - $bills = model('App\Models\mBills'); - $bills->saveBill($this->request->getPost()); + 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); $redirectURL = session('redirect_url') ?? site_url('/'); unset($_SESSION['redirect_url']); return redirect()->to($redirectURL); diff --git a/app/Models/mBills.php b/app/Models/mBills.php index bfd88b2..c6875d3 100644 --- a/app/Models/mBills.php +++ b/app/Models/mBills.php @@ -13,7 +13,7 @@ class mBills extends Model { protected $returnType = 'object'; protected $useSoftDeletes = false; - protected $allowedFields = ['renummer','datum','receiver','source_id','amount','type','comment','validate','lkz']; + protected $allowedFields = ['renummer','datum','receiver','source_id','amount','type','comment','validate','lkz','rechnung']; protected $useTimestamps = false; @@ -100,8 +100,9 @@ class mBills extends Model { $details = model('App\Models\mBillDetails'); $quelle = model('App\Models\mAccounts'); $data = $this->orderBy('datum','desc')->find($id); - $result['datum'] = date( "d.m.Y", strtotime($data->datum)); + $result['datum'] = $data->datum;//date( "d.m.Y", strtotime($data->datum)); $result['receiver'] = $data->receiver; + $result['billfile'] = $data->rechnung; $result['source'] = $data->source_id; $result['validate'] = $data->validate; $result['id'] = $id; @@ -177,12 +178,13 @@ class mBills extends Model { $total = floatval($data['total_in'])-floatval($data['total_out']); if ( !isset($data['multi']) ) $total = floatval($data['input'][0])-floatval($data['output'][0]); + if ( isset($data['rechnung']) ) + $this->set('rechnung', $data['rechnung']); $this->set('amount', $total); $this->set('validate', $data['validate']??false); if ($data['transfer']==1){ $this->set('receiver', $accounts->getDropDownEntry($data['category'][0])); $this->set('type', 'transfer'); - } else{ $this->set('receiver', $data['receiver']); diff --git a/app/Models/mScheduled.php b/app/Models/mScheduled.php index 3584f01..76c6cc3 100644 --- a/app/Models/mScheduled.php +++ b/app/Models/mScheduled.php @@ -29,7 +29,7 @@ class mScheduled extends Model { $data = $this->asObject()->find($id); $result = (array)json_decode($data->data); $result['id'] = $id; - $result['datum'] = date( "d.m.Y", strtotime($data->next_date)); + $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]); } diff --git a/public/js/billing.js b/public/js/billing.js index 9847d6d..a41799a 100644 --- a/public/js/billing.js +++ b/public/js/billing.js @@ -30,6 +30,12 @@ $(function() { }); +function logData(event){ + var data = document.getElementById("billfile"); + console.log(data.value); + +} + function addLine(){ $('#linecont > div').each(function () { if ($(this).hasClass("d-none")){ diff --git a/public/js/tables.js b/public/js/tables.js index faba663..54301a7 100644 --- a/public/js/tables.js +++ b/public/js/tables.js @@ -73,6 +73,8 @@ function deleteId(id, table) { function formatDetails ( d ) { details = ''; str=''; + if (d.rechnung) + str += 'Rechnung: '+d.rechnung+''; // `d` is the original data object for the row d.details.forEach(function(item){ details += ''; @@ -84,7 +86,7 @@ function formatDetails ( d ) { details += ''; }); if (typeof d.quelle !== 'undefined'){ - str =''+ + str +='
'+ ''+ ''+ ''+
Quelle:'+d.quelle+'