Initial
This commit is contained in:
64
app/Controllers/Ajax.php
Normal file
64
app/Controllers/Ajax.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
use App\Models\mBills;
|
||||
use CodeIgniter\Session\Session;
|
||||
|
||||
|
||||
class Ajax extends BaseController
|
||||
{
|
||||
|
||||
protected $session;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = service('session');
|
||||
}
|
||||
|
||||
public function getTabelData(){
|
||||
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')) ?? 0;
|
||||
$_SESSION['datum_start'] = $start;
|
||||
$_SESSION['datum_ende'] = $ende;
|
||||
$_SESSION['source'] = $src;
|
||||
$result = $billing->getEntriesDet($start,$ende,$src);
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
public function getAccountsBalance(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
return json_encode($billing->getAccountsBalance());
|
||||
}
|
||||
|
||||
public function getScheduledData(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$scheduled = model('App\Models\mScheduled');
|
||||
return json_encode($scheduled->getEntries());
|
||||
}
|
||||
|
||||
public function getToDosData(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
return json_encode($billing->getToDos());
|
||||
}
|
||||
|
||||
public function getOverviewData(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$billing = model('App\Models\mBills');
|
||||
$result = $billing->getEntries();
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
public function deleteBill(){
|
||||
if (!$this->request->isAJAX()) return;
|
||||
$bills = model('App\Models\mBills');
|
||||
$bills->deleteEntry($this->request->getPost('id'));
|
||||
return json_encode(["result"=>"done"]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
52
app/Controllers/BaseController.php
Normal file
52
app/Controllers/BaseController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*
|
||||
* BaseController provides a convenient place for loading components
|
||||
* and performing functions that are needed by all your controllers.
|
||||
* Extend this class in any new controllers:
|
||||
* class Home extends BaseController
|
||||
*
|
||||
* For security be sure to declare any new methods as protected or private.
|
||||
*/
|
||||
class BaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Instance of the main Request object.
|
||||
*
|
||||
* @var CLIRequest|IncomingRequest
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These helpers will be available
|
||||
* to all other controllers that extend BaseController.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $helpers = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
// Do Not Edit This Line
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
// E.g.: $this->session = \Config\Services::session();
|
||||
}
|
||||
}
|
||||
144
app/Controllers/Converter.php
Normal file
144
app/Controllers/Converter.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
use App\Models\mBills;
|
||||
use App\Models\mAccounts;
|
||||
|
||||
class Converter extends BaseController
|
||||
{
|
||||
private function loadFormDefaults(){
|
||||
$data['id'] = 0;
|
||||
$data['source'] = 0;
|
||||
$data['datum'] ='';
|
||||
$data['multi'] = false;
|
||||
$data['transfer'] = false;
|
||||
$data['receiver'] = '';
|
||||
$data['total_in'] = 0;
|
||||
$data['total_out'] = 0;
|
||||
$data['validate'] = false;
|
||||
$data['scheduled'] = false;
|
||||
$data['scheduledNum'] = 0;
|
||||
$data['scheduledType'] = 0;
|
||||
for ($i=0;$i<10;$i++){
|
||||
$data['sid'][$i] = 0;
|
||||
$data['category_parent'][$i] = 0;
|
||||
$data['category'][$i] = 0;
|
||||
$data['input'][$i] = 0;
|
||||
$data['output'][$i] = 0;
|
||||
$data['comment'][$i] = '';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function convertDataOld(){
|
||||
$bills = model('App\Models\mBills');
|
||||
$details = model('App\Models\mBillDetails');
|
||||
$result = $bills->where('type','bill')->findAll();
|
||||
foreach( $result as $row){
|
||||
$data = array();
|
||||
$data['booking_id'] = $row->id;
|
||||
$data['category_id'] = $row->target_id;
|
||||
$data['comment'] = $row->comment;
|
||||
$data['subamount'] = $row->amount;
|
||||
$details->insert($data);
|
||||
$bills->update($row->id,['type'=>'multiple']);
|
||||
echo $row->id; echo "\n";
|
||||
}
|
||||
$result = $bills->where('type','transfer')->findAll();
|
||||
foreach( $result as $row){
|
||||
$data = array();
|
||||
$data['booking_id'] = $row->id;
|
||||
$data['category_id'] = $row->target_id;
|
||||
$data['comment'] = $row->comment;
|
||||
$data['subamount'] = $row->amount;
|
||||
$details->insert($data);
|
||||
echo $row->id; echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// only with old database style
|
||||
public function convertScheduled(){
|
||||
$scheduled = model('App\Models\mScheduled');
|
||||
$accounts = model('App\Models\mAccounts');
|
||||
$result = $scheduled->findAll();
|
||||
foreach( $result as $row){
|
||||
|
||||
$book = new \Booking;
|
||||
$book = unserialize($row['billdata']);
|
||||
$zeilendata = $book->getData();
|
||||
// if ($book->getType() == 'transfer'){
|
||||
// echo "\n<br>";
|
||||
// print_r($zeilendata);
|
||||
// }
|
||||
// if ($book->getType() == 'multiple'){
|
||||
// echo "\n<br>";
|
||||
// print_r($book->getBookingDetails());
|
||||
// }
|
||||
//echo "\n\n<br><br>";
|
||||
$data = $this->loadFormDefaults();
|
||||
$data['id'] = $zeilendata['id'];
|
||||
$data['source'] = $zeilendata['source_id'];
|
||||
$data['datum'] =$zeilendata['datum'];
|
||||
$data['multi'] = $book->getType() == 'multiple';
|
||||
$data['transfer'] = $book->getType() == 'transfer';
|
||||
$data['validate'] = true;
|
||||
$data['scheduled'] = true;
|
||||
switch ($row['interval'])
|
||||
{
|
||||
case '2weekly':
|
||||
$data['scheduledNum'] = 2;
|
||||
$data['scheduledType'] = 'week';
|
||||
break;
|
||||
case 'monthly':
|
||||
$data['scheduledNum'] = 1;
|
||||
$data['scheduledType'] = 'month';
|
||||
break;
|
||||
case '2monthly':
|
||||
$data['scheduledNum'] = 2;
|
||||
$data['scheduledType'] = 'month';
|
||||
break;
|
||||
case '3monthly':
|
||||
$data['scheduledNum'] = 3;
|
||||
$data['scheduledType'] = 'month';
|
||||
break;
|
||||
case '6monthly':
|
||||
$data['scheduledNum'] = 6;
|
||||
$data['scheduledType'] = 'month';
|
||||
break;
|
||||
case 'yearly':
|
||||
$data['scheduledNum'] = 1;
|
||||
$data['scheduledType'] = 'year';
|
||||
break;
|
||||
}
|
||||
|
||||
$data['receiver'] = $zeilendata['receiver'];
|
||||
$data['total_in'] = ($zeilendata['amount'] >= 0.0)?abs( $zeilendata['amount'] ):'';
|
||||
$data['total_out'] = ($zeilendata['amount']< 0.0)?abs( $zeilendata['amount'] ):'';
|
||||
|
||||
if (($book->getType() == 'bill')||($book->getType() == 'transfer')){
|
||||
$data['input'][0] = $data['total_in'];
|
||||
$data['output'][0] = $data['total_out'];
|
||||
$data['comment'][0] = $zeilendata ['comment'];
|
||||
$data['category'][0] = $zeilendata['target_id'];
|
||||
}
|
||||
else{
|
||||
echo "\n<br>";$i=0;
|
||||
|
||||
foreach($book->getBookingDetails() as $detail){
|
||||
echo "\n<br>";
|
||||
print_r($detail->getData(array()));
|
||||
$data['category'][$i] = $detail->getCategoryId();
|
||||
$data['input'][$i] = $detail->getAmountIn();
|
||||
$data['output'][$i] = $detail->getAmountOut();
|
||||
$data['comment'][$i] = $detail->getComment();
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
unset($data['category_parent']);
|
||||
$scheduled->update($row['id'],['data'=>json_encode($data)]);
|
||||
}
|
||||
echo "Done";
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
283
app/Controllers/Home.php
Normal file
283
app/Controllers/Home.php
Normal file
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
use App\Models\mBills;
|
||||
use App\Models\mAccounts;
|
||||
use CodeIgniter\Session\Session;
|
||||
|
||||
class Home extends BaseController
|
||||
{
|
||||
|
||||
private $accounts;
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = service('session');
|
||||
$this->accounts = model('App\Models\mAccounts');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('table');
|
||||
}
|
||||
public function Table()
|
||||
{
|
||||
return view('table');
|
||||
}
|
||||
|
||||
private function checkDDPList(&$arr, $ele){
|
||||
|
||||
if (!array_key_exists($ele, $arr)){
|
||||
$arr[$ele] = $this->accounts->getDropDownEntry($ele);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkDDSList($arr, $par, $ele){
|
||||
if (!array_key_exists($par, $arr)){
|
||||
$ret = array();
|
||||
if ($ele > 0)
|
||||
$ret[$ele] = $this->accounts->getDropDownEntry($ele);
|
||||
else
|
||||
$ret[0] = '-----';
|
||||
return $ret;
|
||||
}
|
||||
else{
|
||||
return $arr[$par];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function loadFormDefaults(){
|
||||
$data['id'] = 0;
|
||||
$data['source'] = 0;
|
||||
$data['datum'] ='';
|
||||
$data['renummer'] = false;
|
||||
$data['multi'] = false;
|
||||
$data['transfer'] = false;
|
||||
$data['receiver'] = '';
|
||||
$data['total_in'] = 0;
|
||||
$data['total_out'] = 0;
|
||||
$data['validate'] = false;
|
||||
$data['scheduled'] = false;
|
||||
$data['scheduledNum'] = 0;
|
||||
$data['scheduledType'] = 0;
|
||||
for ($i=0;$i<10;$i++){
|
||||
$data['sid'][$i] = 0;
|
||||
$data['category_parent'][$i] = 0;
|
||||
$data['category'][$i] = 0;
|
||||
$data['input'][$i] = 0;
|
||||
$data['output'][$i] = 0;
|
||||
$data['comment'][$i] = '';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function newScheduled(){
|
||||
return $this->newBill(NULL,NULL,true);
|
||||
}
|
||||
|
||||
public function newTransfer(){
|
||||
$data = $this->loadFormDefaults();
|
||||
$data['transfer'] = true;
|
||||
return $this->newBill($data,NULL);
|
||||
}
|
||||
|
||||
public function newBill($data = NULL, $errors = NULL,$scheduled = false){
|
||||
helper('form');
|
||||
$data = $data ?? $this->loadFormDefaults();
|
||||
$data['isScheduled'] = $scheduled;
|
||||
$data['validation'] = $errors;
|
||||
|
||||
$srclist = $this->accounts->getDropDownList( 'Acc', TRUE );
|
||||
$this->checkDDPList($srclist,$data['source']);
|
||||
$data['sourcelist'] = $srclist;
|
||||
$data['scheduled'] = array('NumList' => array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6'),
|
||||
'TypeList' => array('week'=>'Woche(n)','month'=>'Monat(e)','year'=>'Jahr(e)'),
|
||||
'style' => 'class="form-select"');
|
||||
if (!$data['transfer'])
|
||||
$categories = $this->accounts->getDropDownLists( 'InOut', TRUE );
|
||||
else
|
||||
$categories = $this->accounts->getDropDownLists( 'Acc', TRUE );
|
||||
// $data['catparentlist'] = $categories['parent'];
|
||||
// if (!array_key_exists('catparent', $data))
|
||||
// $data['catparent'] = $this->accounts->getParent($data['cat']);
|
||||
// $this->checkDDPList($data['catparentlist'],$data['catparent']);
|
||||
|
||||
// $data['catlist'] = $this->checkDDSList((array)$categories['subs'],$data['catparent'],$data['cat']);
|
||||
|
||||
$data['subsparent'] = array();
|
||||
$data['subscategory'] = array();
|
||||
for ($i=0;$i<10;$i++){
|
||||
$data['subsparent'][$i] = $categories['parent'];
|
||||
$data['category_parent'][$i] = $data['category_parent'][$i] ?? 0;
|
||||
$this->checkDDPList($data['subsparent'][$i],$data['category_parent'][$i]);
|
||||
$data['subscategory'][$i] = $this->checkDDSList((array)$categories['subs'],$data['category_parent'][$i],$data['category'][$i]??0);
|
||||
}
|
||||
$data['subsdata'] = json_encode($categories['subs']);
|
||||
return view('newBill', $data);
|
||||
}
|
||||
|
||||
private function customValidation(&$errors){
|
||||
$result = true;
|
||||
// if ( "on" == $this->request->getPost('multi') )
|
||||
// {
|
||||
for ($i=0;$i<10;$i++){
|
||||
$inp = $this->request->getPost("input[$i]");
|
||||
$outp = $this->request->getPost("output[$i]");
|
||||
$cat = $this->request->getPost("category[$i]");
|
||||
if ((is_numeric($inp) && $inp > 0.0) || (is_numeric($outp) && $outp > 0.0)){
|
||||
if ($cat == 0){
|
||||
$result &= false;
|
||||
$errors['Kategorie']="Kategorie [$i] fehlt oder ungültig";
|
||||
}
|
||||
}
|
||||
if ($cat > 0){
|
||||
$errors['log2'] = "cat recognized";
|
||||
if (!((is_numeric($inp) && ($inp > 0.0)) || (is_numeric($outp) && ($outp > 0.0)))){
|
||||
$errors['Betrag']="Betrag [$i] fehlt oder ungültig";
|
||||
$result &= false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// else{
|
||||
// if ((is_numeric($this->request->getPost('total_in')) && $this->request->getPost('total_in') > 0.0) || (is_numeric($this->request->getPost('total_out')) && $this->request->getPost('total_out') > 0.0)){
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// $errors['Betrag']="Betrag fehlt oder ungültig";
|
||||
// }
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function attemptNewBilling()
|
||||
{
|
||||
$rules = [
|
||||
'source' => 'required|greater_than[0]',
|
||||
'datum' => 'required',
|
||||
'category.0' => 'required|greater_than[0]'
|
||||
// 'totalamount'=>'required|numeric'
|
||||
];
|
||||
$errors = [ // Errors
|
||||
'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') )
|
||||
{
|
||||
$rules['openamount'] = 'equals[0]';
|
||||
$errors['openamount'] = ['equals' => 'Betrag muss 0 sein'];
|
||||
}
|
||||
|
||||
$fehler= array();
|
||||
$valid = $this->customValidation($fehler);
|
||||
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{
|
||||
if ($this->request->getPost('scheduled') =="0"){
|
||||
$bills = model('App\Models\mBills');
|
||||
$bills->saveBill($this->request->getPost());
|
||||
$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());
|
||||
}
|
||||
$this->response->redirect(site_url('/Home/Table'));
|
||||
}
|
||||
}
|
||||
|
||||
public function editBill($id){
|
||||
$bills = model('App\Models\mBills');
|
||||
$data = $this->loadFormDefaults();
|
||||
$result = $bills->getEntry($id, $data, $this->accounts);
|
||||
return $this->newBill($result);
|
||||
}
|
||||
|
||||
public function editScheduled($id){
|
||||
$scheduled = model('App\Models\mScheduled');
|
||||
$entry = $scheduled->getEntry($id);
|
||||
// $bill = array_merge($this->loadFormDefaults(),(array)json_decode($entry['data']));
|
||||
// $bill['datum'] = $entry['next_date'];
|
||||
return $this->newBill($entry,NULL,true);
|
||||
}
|
||||
|
||||
public function deleteScheduled($id){
|
||||
$scheduled = model('App\Models\mScheduled');
|
||||
$entry = $scheduled->getEntry($id);
|
||||
// $bill = array_merge($this->loadFormDefaults(),(array)json_decode($entry['data']));
|
||||
// $bill['datum'] = $entry['next_date'];
|
||||
return $this->newBill($entry,NULL,true);
|
||||
}
|
||||
|
||||
public function syncScheduled(){
|
||||
$scheduled = model('App\Models\mScheduled');
|
||||
$schedules = $scheduled->findAll();
|
||||
foreach ( $schedules as $schedule )
|
||||
{
|
||||
$cur_date = $schedule['next_date'];
|
||||
while ( strtotime( $cur_date ) <= strtotime( "now" ) )
|
||||
{
|
||||
echo "$cur_date - ";
|
||||
$bill = array_merge($this->loadFormDefaults(),(array)json_decode($schedule['data']));
|
||||
//echo "Hugo:".$schedule['id'];
|
||||
$bill['id']=0; // to generate a new booking
|
||||
$bill['datum'] = $cur_date;
|
||||
$bill['type'] = $bill['transfer']?'transfer':'multiple';
|
||||
echo $bill['receiver'];
|
||||
$bills = model('App\Models\mBills');
|
||||
$bills->saveBill($bill);
|
||||
$cur_date = $scheduled->calcNextDate( $cur_date, $bill['scheduledNum'], $bill['scheduledType']);
|
||||
echo " - $cur_date <br/>";
|
||||
//log_message('debug','BudgetScheduled:process data: '.logArray($booking->getData()));
|
||||
$scheduled->update($schedule['id'], ['next_date'=>$cur_date ]);
|
||||
}
|
||||
}
|
||||
//$this->showTableBookings();
|
||||
}
|
||||
|
||||
public function viewAccountsTree(){
|
||||
helper('form');
|
||||
$data = $this->accounts->getTreeData();
|
||||
$data['ddlist'] = $this->accounts->getDropDownList( 'all', false,true );
|
||||
return view('accountstree',$data);
|
||||
}
|
||||
|
||||
public function attemptEditAccount(){
|
||||
$rules = [
|
||||
'description' => 'required',
|
||||
'type' => 'required',
|
||||
];
|
||||
if (! $this->validate($rules))
|
||||
{
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
$this->accounts->saveAccount($this->request->getPost());
|
||||
// $this->accounts = model('App\Models\mAccounts', false);
|
||||
return $this->viewAccountsTree();
|
||||
|
||||
}
|
||||
|
||||
public function viewAccountActivities(){
|
||||
helper('form');
|
||||
$data = array();
|
||||
$data['source'] = 0;
|
||||
$data['start'] = session('datum_start') ?? date("d.m.Y", strtotime( "- 2 weeks", strtotime( "now" ) ));
|
||||
$data['ende'] = session('datum_ende') ?? date("d.m.Y", strtotime( "now" ) );
|
||||
$data['source'] = session('source') ?? 0;
|
||||
$data['sourcelist'] = $this->accounts->getDropDownList( 'Acc', TRUE );
|
||||
return view('activities', $data);
|
||||
}
|
||||
|
||||
public function viewScheduled(){
|
||||
helper('form');
|
||||
return view('scheduled');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user