diff --git a/application/controllers/monfin2/Monfin2overzicht.php b/application/controllers/monfin2/Monfin2overzicht.php index 613e563..3c20875 100644 --- a/application/controllers/monfin2/Monfin2overzicht.php +++ b/application/controllers/monfin2/Monfin2overzicht.php @@ -42,6 +42,13 @@ class Monfin2overzicht extends MY_Controller{ $basis = $this->Finbestemmingen_model->get_bestemmingen($orgid, $kalenderjaarnr,"BASIS"); $extra = $this->Finbestemmingen_model->get_bestemmingen($orgid, $kalenderjaarnr,"EXTRA"); +// echo json_encode([ +// 'basis' => $basis, +// 'extra' =>$extra +// ]); +// +// return; + $sombasisperuitgavetype = $this->get_som_per_uitgavetype($basis, $uitgavetypes); $somextraperuitgavetype = $this->get_som_per_uitgavetype($extra, $uitgavetypes); $totsomperuitgavetype = $this->sommeer_per_uitgavetype($sombasisperuitgavetype,$somextraperuitgavetype, $uitgavetypes); @@ -291,12 +298,12 @@ class Monfin2overzicht extends MY_Controller{ $budgetsom = 0; foreach($subsoort->uitgavetypes ? : [] as $uitgavetype){ if ($uitgavetype->bedrag){ - $som += $uitgavetype->bedrag; + $som += isset($uitgavetype->bedrag) && floatval($uitgavetype->bedrag) > 0 ? floatval($uitgavetype->bedrag): 0; $uitgavetype->bedrag = number_format($uitgavetype->bedrag,0,',','.'); } if ($uitgavetype->budget){ - $budgetsom += $uitgavetype->budget; - $uitgavetype->budget = number_format($uitgavetype->budget,0,',','.'); + $budgetsom += is_numeric($uitgavetype->budget) ? $uitgavetype->budget: 0; + $uitgavetype->budget =is_numeric($uitgavetype->budget) ? number_format($uitgavetype->budget,0,',','.'): '0,00'; } } $subsoort->uitgavetypes[3]= new stdClass; @@ -371,50 +378,48 @@ class Monfin2overzicht extends MY_Controller{ return $somtot; } - function get_som_per_uitgavetype($basis,$uitgavetypes){ - $sombasis = []; - if ($uitgavetypes){ - foreach($uitgavetypes as $uitgavetype) { - $sombasis[$uitgavetype->code] = new stdClass; - $sombasis[$uitgavetype->code]->naam = $uitgavetype->naam; - $sombasis[$uitgavetype->code]->som = 0; - $sombasis[$uitgavetype->code]->budgetsom = 0; + function get_som_per_uitgavetype($basis,$uitgavetypes){ + $sombasis = []; + if ($uitgavetypes){ + foreach($uitgavetypes as $uitgavetype){ + $sombasis[$uitgavetype->code]= new stdClass; + $sombasis[$uitgavetype->code]->naam= $uitgavetype->naam; + $sombasis[$uitgavetype->code]->som=0; + $sombasis[$uitgavetype->code]->budgetsom =0; - - foreach ($basis ? $basis : [] as $soort) { - foreach ($soort->subsoorten ? $soort->subsoorten : [] as $subsoort) { - foreach ($subsoort->uitgavetypes ? $subsoort->uitgavetypes : [] as $uitgavetype) { - - $sombasis[$uitgavetype->code]->som += ($uitgavetype->bedrag ?: 0); - $sombasis[$uitgavetype->code]->budgetsom += ($uitgavetype->budget ?: 0); - } //foreach - }//foreach subsoort - }//foreach basis } - } // if uitgavetypes - $somasarray=[]; - $index = 0; - $regelsom=0; - $regelsom2 = 0; - foreach($uitgavetypes as $uitgavetype){ - $somasarray[$index ] = new stdClass; - $somasarray[$index]->code = $uitgavetype->code; - $somasarray[$index]->naam = $sombasis[$uitgavetype->code]->naam; - $somasarray[$index ]->som = round($sombasis[$uitgavetype->code]->som,0); - $somasarray[$index ]->budgetsom = round($sombasis[$uitgavetype->code]->budgetsom,0); - $index += 1; - }; - $regelsom = $somasarray[0]->som; - $regelsom2 = $somasarray[0 ]->budgetsom; - $somasarray[$index] = new stdClass; - $somasarray[$index]->code ="REGELSOM"; - $somasarray[$index]->naam = "Som"; - $somasarray[$index]->som = $regelsom; + foreach($basis ? $basis : [] as $soort){ + foreach ($soort->subsoorten ? $soort->subsoorten : [] as $subsoort){ + foreach($subsoort->uitgavetypes ? $subsoort->uitgavetypes :[] as $kostenpost) { + $sombasis[$uitgavetype->code]->som += is_numeric($kostenpost->bedrag)? floatval($kostenpost->bedrag): 0; + $sombasis[$uitgavetype->code]->budgetsom += is_numeric($kostenpost->budget) ? floatval($kostenpost->budget): 0; + } //foreach + }//foreach subsoort + }//foreach basis + } // if uitgavetypes + $somasarray=[]; + $index = 0; + $regelsom=0; + $regelsom2 = 0; + foreach($uitgavetypes as $uitgavetype){ + $somasarray[$index ] = new stdClass; + $somasarray[$index]->code = $uitgavetype->code; + $somasarray[$index]->naam = $sombasis[$uitgavetype->code]->naam; + $somasarray[$index ]->som = round($sombasis[$uitgavetype->code]->som,0); + $somasarray[$index ]->budgetsom = round($sombasis[$uitgavetype->code]->budgetsom,0); + $regelsom += $somasarray[$index ]->som; + $regelsom2 += $somasarray[$index ]->budgetsom; + $index += 1; + }; + $somasarray[$index] = new stdClass; + $somasarray[$index]->code ="REGELSOM"; + $somasarray[$index]->naam = "Som"; + $somasarray[$index]->som = $regelsom; $somasarray[$index]->budgetsom = $regelsom2; - - return $somasarray; - } + + return $somasarray; + } function getbestuursbedragen(){ $targetorgid = $this->clean_input('orgid'); diff --git a/application/models/monfin2/Finbestemmingen_model.php b/application/models/monfin2/Finbestemmingen_model.php index 7e6388b..027b72e 100644 --- a/application/models/monfin2/Finbestemmingen_model.php +++ b/application/models/monfin2/Finbestemmingen_model.php @@ -64,26 +64,26 @@ class Finbestemmingen_model extends MY_Model{ foreach($soort->subsoorten as $index =>$subsoort){ // haal per uitgavetypes de bedragen op if ($uitgavetypes) { - $restant = 0; + $restantbudget = 0; foreach ($uitgavetypes as $uitgavetype) { $subsoort->uitgavetypes[] = $this->get_bedrag_per_type($orgID, $jaarnr, $subsoort->subsoortID, $uitgavetype->code); } if (count($subsoort->uitgavetypes) > 0) { - $restant = number_format(0, 2); $restantbudget = floatval(str_replace(',' , '' , $subsoort->uitgavetypes[0]->budget)) - floatval(str_replace(',' , '' , $subsoort->uitgavetypes[1]->budget)) - floatval(str_replace(',' , '' , $subsoort->uitgavetypes[2]->budget)) - floatval(str_replace(',' , '' , $subsoort->uitgavetypes[3]->budget)); $restantbudget = number_format($restantbudget, 2); } - $subsoort->uitgavetypes[] = [ - 'id' => '0', - 'bedrag' => $restant, - 'budget' => $restantbudget, - 'code' => 'RESTANT', - ]; + $restant = new stdClass(); + $restant->id = '0'; + $restant->bedrag = '0.00'; + $restant->budget = $restantbudget; + $restant->code = 'RESTANT'; + + $subsoort->uitgavetypes[] = $restant; } } diff --git a/application/views/monpas/pages/monfin2/overzicht.php b/application/views/monpas/pages/monfin2/overzicht.php index e5b6692..787bf00 100644 --- a/application/views/monpas/pages/monfin2/overzicht.php +++ b/application/views/monpas/pages/monfin2/overzicht.php @@ -76,22 +76,39 @@