Initial
This commit is contained in:
0
app/Models/.gitkeep
Normal file
0
app/Models/.gitkeep
Normal file
207
app/Models/mAccounts.php
Normal file
207
app/Models/mAccounts.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class mAccounts extends Model {
|
||||
protected $table = 'budget_accounts';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $allowedFields = ['parent_id','type','bookable','description','LKZ'];
|
||||
|
||||
protected $useTimestamps = false;
|
||||
private $mAccountList = array();
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$result = $this->findAll();
|
||||
foreach ($result as $value) {
|
||||
$this->mAccountList[$value->id] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Erstellt DropDownListe aus gegeben array
|
||||
* @param array liste der daten
|
||||
* @param bool wenn true wird auch ein 0-Eintrag erstellt
|
||||
* @return mixed
|
||||
*/
|
||||
private function createDropDownList($data,$withnull = true,$key=0)
|
||||
{
|
||||
$liste = array();
|
||||
if ($withnull)
|
||||
$liste[$key] = '-----';
|
||||
foreach ( $data as $row )
|
||||
{
|
||||
$liste[$row->id] = $row->description;
|
||||
}
|
||||
asort( $liste );
|
||||
return $liste;
|
||||
}
|
||||
|
||||
/**
|
||||
* holt Text vom gegebenen Element
|
||||
* @param int id des gewünschten Elements
|
||||
* @return string Full Name of Entry
|
||||
*/
|
||||
public function getDropDownEntry($id){
|
||||
$element = $this->mAccountList[$id];
|
||||
$description = $element->description;
|
||||
$id = $element->parent_id;
|
||||
while ( $id > 0 )
|
||||
{
|
||||
$description = $this->mAccountList[$id]->description .'-'.$description;
|
||||
$id = $this->mAccountList[$id]->parent_id;
|
||||
}
|
||||
return $description;;
|
||||
}
|
||||
|
||||
/**
|
||||
* liefert DropDown Liste mit gegeben Suchparametern
|
||||
* @param string Kontotyp "InOut,In,Out,Acc"
|
||||
* @param bool ob bookable gesetzt sein muss
|
||||
* @return bool ob LKZ Flag gesetzt sein darf
|
||||
*/
|
||||
public function getDropDownList($type, $bookable = true, $lkz = false )
|
||||
{
|
||||
if ($bookable == true)
|
||||
$this->where('bookable',1);
|
||||
if ($lkz == false) $this->where('lkz',NULL);
|
||||
if ( $type == 'InOut' ) $this->where('type !=','account');
|
||||
elseif ( $type == 'Acc' ) $this->where('type','account');
|
||||
elseif ( $type == 'In' ) $this->where('type','output');
|
||||
elseif ( $type == 'Out' ) $this->where('type','input');
|
||||
$this->orderBy('description');
|
||||
$result = $this->findAll();
|
||||
$parent = array();
|
||||
foreach ( $result as &$element )
|
||||
{
|
||||
$id = $element->parent_id;
|
||||
while ( $id > 0 )
|
||||
{
|
||||
$element->description = $this->mAccountList[$id]->description .'-'.$element->description;
|
||||
if ($this->mAccountList[$id]->parent_id == 0){
|
||||
$parent[] = (object)['id' => $element->id,'description' => $element->description ];
|
||||
}
|
||||
$id = $this->mAccountList[$id]->parent_id;
|
||||
}
|
||||
}
|
||||
return $this->createDropDownList($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* liefert 2 DropDown Listen mit gegeben Suchparametern
|
||||
* parent für Vorselektion, subs für Untereinträge
|
||||
* @param string Kontotyp "InOut,In,Out,Acc"
|
||||
* @param bool ob bookable gesetzt sein muss
|
||||
* @return bool ob LKZ Flag gesetzt sein darf
|
||||
*/
|
||||
public function getDropDownLists($type, $bookable = true, $lkz = false )
|
||||
{
|
||||
if ($bookable == true) $this->where('bookable',1);
|
||||
if ($lkz == false) $this->where('lkz',null);
|
||||
if ( $type == 'InOut' ) $this->where('type !=','account');
|
||||
elseif ( $type == 'Acc' ) $this->where('type','account');
|
||||
elseif ( $type == 'In' ) $this->where('type','output');
|
||||
elseif ( $type == 'Out' ) $this->where('type','input');
|
||||
$this->orderBy('description');
|
||||
$result = $this->findAll();
|
||||
|
||||
$parent = array();
|
||||
$listen = array();
|
||||
foreach ( $result as &$element )
|
||||
{
|
||||
$id = $element->parent_id;
|
||||
while ( $id > 0 )
|
||||
{
|
||||
if ($this->mAccountList[$id]->LKZ == 1) continue 2;
|
||||
if ($this->mAccountList[$id]->parent_id == 0){
|
||||
if (!array_key_exists($id, $parent))
|
||||
$parent[$id] = (object)['id' => $id,'description' => $this->mAccountList[$id]->description ];
|
||||
$listen[$id][$element->id] = (object)['id' => $element->id,'description' => $element->description ];
|
||||
}
|
||||
else{
|
||||
$element->description = $this->mAccountList[$id]->description .'-'.$element->description;
|
||||
}
|
||||
$id = $this->mAccountList[$id]->parent_id;
|
||||
}
|
||||
}
|
||||
$subs = array();
|
||||
$subs[0] = $this->createDropDownList(array());
|
||||
foreach ( $listen as $key => $element ){
|
||||
$subs[$key] = $this->createDropDownList($element,$this->mAccountList[$key]->bookable, $key);
|
||||
}
|
||||
return array('parent'=> $this->createDropDownList($parent),'subs'=>(object)$subs);
|
||||
}
|
||||
|
||||
/**
|
||||
* liefert parent id für category
|
||||
* @param int account id
|
||||
* @return int parent id
|
||||
*/
|
||||
public function getParent($sid){
|
||||
if ($sid == 0) return 0;
|
||||
$result = $sid;
|
||||
$id = $this->mAccountList[$sid]->parent_id;
|
||||
while ( $id > 0 )
|
||||
{
|
||||
$result = $id;
|
||||
$id = $this->mAccountList[$id]->parent_id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* liefert array für jedes sub element und level
|
||||
* @return mixed array for each level element
|
||||
*/
|
||||
public function getTreeData(){
|
||||
helper('array');
|
||||
$parents = array();
|
||||
$subs = array();
|
||||
foreach ( $this->mAccountList as $element )
|
||||
{
|
||||
if ($element->parent_id == 0)
|
||||
$parents[$element->id] = $element;
|
||||
}
|
||||
foreach ( $this->mAccountList as $element )
|
||||
{
|
||||
// if ($element->parent_id > 0)
|
||||
// echo "".$parents[$element->parent_id]->id;
|
||||
if (($element->parent_id > 0) && array_key_exists($element->parent_id , $parents))
|
||||
$parents[$element->parent_id]->subs[$element->id] = $element;
|
||||
}
|
||||
array_sort_by_multiple_keys($parents, ['description' => SORT_ASC]);
|
||||
return ['parents'=>$parents,'subs'=>$subs, 'all'=>$this->mAccountList];
|
||||
}
|
||||
|
||||
/**
|
||||
* erstellt oder updatet den gegeben Account
|
||||
* @var array formulardaten
|
||||
*/
|
||||
public function saveAccount($data){
|
||||
$this->set('parent_id',$data['parent']);
|
||||
$this->set('type', $data['type']);
|
||||
$this->set('bookable', array_key_exists('bookable', $data) ? 1 : 0);
|
||||
$this->set('description', $data['description']);
|
||||
$this->set('LKZ', (array_key_exists('lkz', $data) ? 1 : null));
|
||||
if ($data['id'] == 0)
|
||||
$this->insert();
|
||||
else
|
||||
$this->update($data['id']);
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
|
||||
public function checkType($id, $type){
|
||||
return ($this->mAccountList[$id]->type == $type);
|
||||
}
|
||||
};
|
||||
|
||||
?>
|
||||
86
app/Models/mBillDetails.php
Normal file
86
app/Models/mBillDetails.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class mBillDetails extends Model {
|
||||
protected $table = 'budget_billdetails';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $allowedFields = ['bill_id','comment','account_id','subamount','LKZ'];
|
||||
|
||||
protected $useTimestamps = false;
|
||||
|
||||
// public function getEntries($id){
|
||||
// $this->select('mw_budget_bookingdetails.*,mw_budget_categories.description');
|
||||
// $this->join('mw_budget_categories', 'mw_budget_categories.id = mw_budget_bookingdetails.account_id', 'left');
|
||||
// $result = $this->orderBy('id','asc')->where('bill_id',$id)->findAll();
|
||||
// foreach ($result as $key => $value) {
|
||||
|
||||
// // $value->datum = date( "d.m.Y", strtotime( $value->datum ));
|
||||
// // $value->amount = number_format( $value->amount , 2, ',', '.' );
|
||||
// }
|
||||
// return $result;
|
||||
// }
|
||||
|
||||
public function getDetails($ids){
|
||||
$quelle = model('App\Models\mAccounts');
|
||||
$rows = $this->whereIn('bill_id', $ids)->findAll();
|
||||
$result = array();
|
||||
foreach($rows as $row){
|
||||
$row->description = $quelle->getDropDownEntry($row->account_id);
|
||||
$result[$row->bill_id][] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function getEntriesForForm($billId, &$result, $accounts){
|
||||
$this->select('budget_billdetails.*,budget_accounts.description');
|
||||
$this->join('budget_accounts', 'budget_accounts.id = budget_billdetails.account_id', 'left');
|
||||
$data = $this->orderBy('id','asc')->where('bill_id',$billId)->findAll();
|
||||
$amount = 0.0;
|
||||
foreach ($data as $key => $row){
|
||||
$result['sid'][$key]= $row->id;
|
||||
$result['category'][$key]= $row->account_id;
|
||||
$result['category_parent'][$key]= $accounts->getParent($result['category'][$key]);
|
||||
$result['input'][$key]= ($row->subamount >= 0.0)?number_format( abs( $row->subamount ), 2, ',', '' ):'';
|
||||
$result['output'][$key]= ($row->subamount < 0.0)?number_format( abs( $row->subamount ), 2, ',', '' ):'';
|
||||
$result['comment'][$key]= $row->comment;
|
||||
$amount += $row->subamount;
|
||||
// $value->datum = date( "d.m.Y", strtotime( $value->datum ));
|
||||
// $value->amount = number_format( $value->amount , 2, ',', '.' );
|
||||
}
|
||||
if (count($data) > 1){
|
||||
$result['multi'] = 'on';
|
||||
$result['total_in']= ($amount >= 0.0)?number_format( abs( $amount ), 2, ',', '' ):'';
|
||||
$result['total_out']= ($amount < 0.0)?number_format( abs( $amount ), 2, ',', '' ):'';
|
||||
}
|
||||
else if ($accounts->checkType($result['category'][0],'account'))
|
||||
$result['transfer'] = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function saveEntries($data, $billId){
|
||||
for ($i=0;$i<10;$i++){
|
||||
if ($data['category'][$i] > 0){
|
||||
$this->set('subamount', floatval($data['input'][$i])-floatval($data['output'][$i])); //floatval($data['total_in'])-floatval($data['total_out']));
|
||||
$this->set('comment', $data['comment'][$i]);
|
||||
$this->set('account_id', $data['category'][$i]);
|
||||
$this->set('bill_id', $billId);
|
||||
if ( 0 == $data['sid'][$i] ){
|
||||
$this->insert();
|
||||
}
|
||||
else{
|
||||
$this->update($data['sid'][$i]);
|
||||
}
|
||||
}
|
||||
else if (0 < $data['sid'][$i]) {
|
||||
$this->delete(['id' => $data['sid'][$i]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
212
app/Models/mBills.php
Normal file
212
app/Models/mBills.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use App\Models\Mbookingdetails;
|
||||
use App\Models\Mcategories;
|
||||
|
||||
class mBills extends Model {
|
||||
protected $table = 'budget_bills';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $returnType = 'object';
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $allowedFields = ['renummer','datum','receiver','source_id','amount','type','comment','validate','LKZ'];
|
||||
|
||||
protected $useTimestamps = false;
|
||||
|
||||
|
||||
/**
|
||||
* liefert Buchungen für Aktivitätenliste
|
||||
* @return mixed Datensätze für Tabelle
|
||||
*/
|
||||
public function getEntriesDet($start, $ende, $source){
|
||||
$details = model('App\Models\mBillDetails');
|
||||
$quelle = model('App\Models\mAccounts');
|
||||
$this->where('datum >=', date( 'Y-m-d', strtotime($start)));
|
||||
$this->where('datum <=', date( 'Y-m-d', strtotime($ende)));
|
||||
if ($source > 0) {
|
||||
$subs = $details->select('bill_id')->where('account_id',$source)->findAll();
|
||||
$keys=array();
|
||||
foreach ($subs as $value) {
|
||||
$keys[] = intval($value->bill_id);
|
||||
}
|
||||
$this->groupStart();
|
||||
$this->where('source_id', $source );
|
||||
$this->orWhereIn('id', $keys );
|
||||
$this->groupEnd();
|
||||
}
|
||||
$result = $this->orderBy('datum','desc')->where('LKZ',null)->findAll();
|
||||
$keys=array();
|
||||
foreach ($result as $value) {
|
||||
$keys[] = intval($value->id);
|
||||
}
|
||||
$ergebnis = $details->getDetails($keys);
|
||||
|
||||
foreach ($result as $value) {
|
||||
$value->details = $ergebnis[$value->id]??null;
|
||||
$value->datum = date( "d.m.Y", strtotime( $value->datum ));
|
||||
$value->source = $quelle->getDropDownEntry($value->source_id);
|
||||
// $value->amount = number_format( $value->amount , 2, ',', '.' );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* liefert Buchungen für Übersichtstabelle
|
||||
* @return mixed Datensätze für Tabelle
|
||||
*/
|
||||
function getEntries(){
|
||||
$details = model('App\Models\mBillDetails');
|
||||
$quelle = model('App\Models\mAccounts');
|
||||
$result = $this->orderBy('datum','desc')->where('validate',0)->where('LKZ',null)->findAll(10);
|
||||
$keys=array();
|
||||
foreach ($result as $value) {
|
||||
$keys[] = intval($value->id);
|
||||
}
|
||||
//$ergebnis = $details->whereIn('bill_id', $keys)->asArray()->findAll();
|
||||
$ergebnis = $details->getDetails($keys);
|
||||
// print_r($ergebnis);
|
||||
|
||||
foreach ($result as $value) {
|
||||
$value->details = $ergebnis[$value->id]??null;//$details->getEntries($value->id);
|
||||
$value->datum = date( "d.m.Y", strtotime( $value->datum ));
|
||||
$value->quelle = $quelle->getDropDownEntry($value->source_id);
|
||||
// $value->amount = number_format( $value->amount , 2, ',', '.' );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* liefert gegebene Buchung inkl. Details im Formularformat
|
||||
* @param int id der Buchung
|
||||
* @return mixed Datenstruktur für Formular
|
||||
*/
|
||||
function getEntry($id, &$result, $accounts){
|
||||
$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['receiver'] = $data->receiver;
|
||||
$result['source'] = $data->source_id;
|
||||
$result['validate'] = $data->validate;
|
||||
$result['id'] = $id;
|
||||
$result = array_merge($result, $details->getEntriesForForm($id, $result, $accounts));
|
||||
$result['transfer'] = $result['transfer'] || ($data->type == 'transfer');
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getToDos(){
|
||||
$details = model('App\Models\mBillDetails');
|
||||
$quelle = model('App\Models\mAccounts');
|
||||
$result = $this->orderBy('datum','desc')->where('validate',1)->where('LKZ',null)->findAll();
|
||||
$keys=array();
|
||||
foreach ($result as $value) {
|
||||
$keys[] = intval($value->id);
|
||||
}
|
||||
$ergebnis = $details->getDetails($keys);
|
||||
|
||||
foreach ($result as $value) {
|
||||
$value->details = $ergebnis[$value->id]??null;
|
||||
//$value->details = $details->getEntries($value->id);
|
||||
$value->datum = date( "d.m.Y", strtotime( $value->datum ));
|
||||
$value->quelle = $quelle->getDropDownEntry($value->source_id);;
|
||||
// $value->amount = number_format( $value->amount , 2, ',', '.' );
|
||||
}
|
||||
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',0);
|
||||
$result1 = $this->where('budget_bills.LKZ',null)->findAll();
|
||||
$assoc1 = array();
|
||||
foreach ($result1 as $value) {
|
||||
$assoc1[$value['idd']] = $value;
|
||||
}
|
||||
// $this->select('SUM((-1)*amount) as amount, target_id as idd, mw_budget_categories.description',FALSE);
|
||||
// $this->groupby('target_id')->asArray();
|
||||
// $this->join('mw_budget_categories', 'mw_budget_categories.id = mw_budget_bookings.target_id', 'left');
|
||||
// $this->where('mw_budget_categories.type','account');
|
||||
// $this->where('mw_budget_categories.LKZ',NULL);
|
||||
// $result2 = $this->where('mw_budget_bookings.LKZ',NULL)->findAll();
|
||||
// $assoc2 = array();
|
||||
// foreach ($result2 as $value) {
|
||||
// $assoc2[$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',0);
|
||||
$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;
|
||||
}
|
||||
return $sums;
|
||||
}
|
||||
|
||||
public function saveBill($data){
|
||||
$details = model('App\Models\mBillDetails');
|
||||
$accounts = model('App\Models\mAccounts');
|
||||
$this->set('datum', date( "Y-m-d", strtotime($data['datum'] ) ));
|
||||
|
||||
$this->set('source_id', $data['source']);
|
||||
$total = floatval($data['total_in'])-floatval($data['total_out']);
|
||||
if ($total == 0)
|
||||
$total = floatval($data['input'][0])-floatval($data['output'][0]);
|
||||
$this->set('amount', $total);
|
||||
$this->set('validate', $data['validate']??0);
|
||||
if ($data['transfer']==1){
|
||||
$this->set('receiver', $accounts->getDropDownEntry($data['category'][0]));
|
||||
$this->set('type', 'transfer');
|
||||
|
||||
}
|
||||
else{
|
||||
$this->set('receiver', $data['receiver']);
|
||||
$this->set('type', 'multiple');
|
||||
}
|
||||
//$tabdata['type']
|
||||
if ( 0 == $data['id'] ){
|
||||
$this->insert();
|
||||
$billId = $this->getInsertID();
|
||||
//insert
|
||||
}
|
||||
else{
|
||||
$billId = $data['id'];
|
||||
$this->update($data['id']);
|
||||
}
|
||||
$details->saveEntries($data, $billId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* löscht gegebene Buchung inkl. Details
|
||||
* @param int id der Buchung
|
||||
* @return mixed Datenstruktur für Formular
|
||||
*/
|
||||
function deleteEntry($id){
|
||||
$details = model('App\Models\mBillDetails');
|
||||
if ($id > 0){
|
||||
$this->delete($id);
|
||||
$details->where('bill_id',$id)->delete();
|
||||
}
|
||||
}
|
||||
};
|
||||
?>
|
||||
83
app/Models/mScheduled.php
Normal file
83
app/Models/mScheduled.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class mScheduled extends Model {
|
||||
protected $table = 'budget_scheduled';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $allowedFields = ['creat_date','next_date','data'];
|
||||
protected $useTimestamps = false;
|
||||
protected $skipValidation = false;
|
||||
|
||||
public function calcNextDate($date, $num, $type)
|
||||
{
|
||||
$start = strtotime( $date );
|
||||
$period = $num .' '. $type;
|
||||
$future = strtotime( '+' . $period, $start );
|
||||
$check = strtotime( '-' . $num .' '. $type, $future );
|
||||
if ( $check > $start )
|
||||
$future = strtotime( 'last day of previous month', $future );
|
||||
return date( "Y-m-d", $future );
|
||||
}
|
||||
|
||||
public function getEntry($id){
|
||||
$accounts = model('App\Models\mAccounts');
|
||||
$data = $this->asObject()->find($id);
|
||||
$result = (array)json_decode($data->data);
|
||||
$result['id'] = $id;
|
||||
$result['datum'] = date( "d.m.Y", strtotime($data->next_date));
|
||||
for ($i=0;$i<10;$i++){
|
||||
$result['category_parent'][$i]= $accounts->getParent($result['category'][$i]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getEntries(){
|
||||
$quelle = model('App\Models\mAccounts');
|
||||
$result = $this->asObject()->findAll();
|
||||
foreach ($result as $value) {
|
||||
$details = json_decode($value->data);
|
||||
for ($i=0;$i<10;$i++){
|
||||
if ((floatval($details->input[$i]) == 0.0) && (floatval($details->output[$i]) == 0.0))
|
||||
continue;
|
||||
$value->details[] = ['comment'=>$details->comment[$i], 'description'=>$quelle->getDropDownEntry($details->category[$i]), 'subamount'=>(floatval($details->input[$i])-floatval($details->output[$i]))];
|
||||
}
|
||||
//$value->details = null;
|
||||
$value->datum = date( "d.m.Y", strtotime( $value->next_date ));
|
||||
$value->source = $quelle->getDropDownEntry($details->source);
|
||||
$value->receiver = $details->receiver;
|
||||
$value->amount = floatval($details->total_in)-floatval($details->total_out);
|
||||
// $value->amount = number_format( $value->amount , 2, ',', '.' );
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function saveBill($data){
|
||||
$data['validate'] = true;
|
||||
$data['scheduled'] = true;
|
||||
$data['renummer'] = isset($data['renummer']);
|
||||
$data['multi'] = isset($data['multiple']);
|
||||
$data['transfer'] = false;
|
||||
unset($data['openamount']);
|
||||
unset($data['category_parent']);
|
||||
$data['datum'] = date( "Y-m-d", strtotime($data['datum'] ) );
|
||||
$this->set('next_date', $data['datum']);
|
||||
|
||||
$data['total_in'] = 0;
|
||||
$data['total_out'] = 0;
|
||||
for ($i=0;$i<10;$i++){
|
||||
if ($data['category'][$i] > 0){
|
||||
$data['total_in'] += floatval($data['input'][$i]);
|
||||
$data['total_out'] += floatval($data['output'][$i]);
|
||||
}
|
||||
}
|
||||
$this->set('data',json_encode($data));
|
||||
|
||||
if ( 0 == $data['id']) $this->insert();
|
||||
else $this->update($data['id']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user