File: /var/www/vhosts/creativefellows.nl/devries.creativefellows.nl/classes/DevriesController.php
<?php
class DevriesController extends CassetteController{
function __construct($db_connection,$router=null,$view=null,$settings=null)
{
$this->db = $db_connection;
$this->router = $router;
$this->view = $view;
$this->settings = $settings;
$this->config = new BaseController($settings,$client_settings);
}
public function getCosts($request, $response, $args)
{
// get url parameters
$this->entry_id = isset($args["entry"]) ? $args["entry"] : null;
$this->amount = isset($args["amount"]) ? $args["amount"] : null;
// get request contents
$this->model_data = $this->getPage(null,null,$this->entry_id);
// fields of the calculator
$this->calculator_fields = $this->settings["calculator_fields"];
// set array for values
$this->calculator_data = [];
// first year
$this->calculator_data[0]["service_oneotime"] = 0;
$this->calculator_data[0]["service_fee"] = $this->getServiceFee();
$this->calculator_data[0]["service_fee_tax"] = $this->calculator_data[0]["service_fee"] * $this->settings["global_tax"];
$this->calculator_data[0]["bank_transaction_fee"] = $this->getBankTransactionFee();
$this->calculator_data[0]["bank_exp_trans_cost"] = 0;
$this->calculator_data[0]["bank_storage_fee"] = $this->getBankStorageFee();
$this->calculator_data[0]["service_occasional"] = 0;
$this->calculator_data[0]["tools_onetime"] = 0;
$this->calculator_data[0]["model_fee"] = $this->amount * $this->getModelProperty("beheervergoeding_model");
$this->calculator_data[0]["transaction_costs"] = $this->amount * $this->getModelProperty("transactiekosten_model");
$this->calculator_data[0]["auction_costs"] = 0;
$this->calculator_data[0]["tools_occasional"] = 0;
$this->calculator_data[0]["sum_service"] = $this->calculator_data[0]["service_oneotime"] + $this->calculator_data[0]["service_fee"] + $this->calculator_data[0]["service_fee_tax"] + $this->calculator_data[0]["bank_transaction_fee"] + $this->calculator_data[0]["bank_exp_trans_cost"] + $this->calculator_data[0]["bank_storage_fee"] + $this->calculator_data[0]["service_occasional"];
$this->calculator_data[0]["sum_tools"] = $this->calculator_data[0]["tools_onetime"] + $this->calculator_data[0]["model_fee"] + $this->calculator_data[0]["transaction_costs"] + $this->calculator_data[0]["auction_costs"] + $this->calculator_data[0]["tools_occasional"];
$this->calculator_data[0]["sum_total"] = $this->calculator_data[0]["sum_service"] + $this->calculator_data[0]["sum_tools"];
//$this->calculator_data[0]["compare_bank"] = $this->amount * $this->getModelProperty("vergelijk_banken");
//$this->calculator_data[0]["compare_assetmt"] = $this->amount * $this->getModelProperty("vergelijk_vermogensbeheerders");
// years to follow
$this->calculator_data[1]["service_oneotime"] = 0;
$this->calculator_data[1]["service_fee"] = $this->calculator_data[0]["service_fee"];
$this->calculator_data[1]["service_fee_tax"] = $this->calculator_data[0]["service_fee_tax"];
$this->calculator_data[1]["bank_transaction_fee"] = 0;
$this->calculator_data[1]["bank_exp_trans_cost"] = $this->calculator_data[0]["bank_transaction_fee"] * 0.15;
$this->calculator_data[1]["bank_storage_fee"] = $this->calculator_data[0]["bank_storage_fee"];
$this->calculator_data[1]["service_occasional"] = 0;
$this->calculator_data[1]["tools_onetime"] = 0;
$this->calculator_data[1]["model_fee"] = $this->amount * $this->getModelProperty("beheervergoeding_model");
$this->calculator_data[1]["transaction_costs"] = 0;
$this->calculator_data[1]["auction_costs"] = 0;
$this->calculator_data[1]["tools_occasional"] = 0;
$this->calculator_data[1]["sum_service"] = $this->calculator_data[1]["service_oneotime"] + $this->calculator_data[1]["service_fee"] + $this->calculator_data[1]["service_fee_tax"] + $this->calculator_data[1]["bank_transaction_fee"] + $this->calculator_data[1]["bank_exp_trans_cost"] + $this->calculator_data[1]["bank_storage_fee"] + $this->calculator_data[1]["service_occasional"];
$this->calculator_data[1]["sum_tools"] = $this->calculator_data[1]["tools_onetime"] + $this->calculator_data[1]["model_fee"] + $this->calculator_data[1]["transaction_costs"] + $this->calculator_data[1]["auction_costs"] + $this->calculator_data[1]["tools_occasional"];
$this->calculator_data[1]["sum_total"] = $this->calculator_data[1]["sum_service"] + $this->calculator_data[1]["sum_tools"];
//$this->calculator_data[1]["compare_bank"] = $this->amount * $this->getModelProperty("vergelijk_banken");
//$this->calculator_data[1]["compare_assetmt"] = $this->amount * $this->getModelProperty("vergelijk_vermogensbeheerders");
return $response->withHeader('Content-Type', 'application/json')->withStatus(200)->write(json_encode($this->calculator_data));
//echo json_encode($this->calculator_data);
}
private function getBankStorageFee()
{
$binck_bewaarloon = $this->getModelProperty("binck_bewaarloon");
$binck_onder_grenswaarde = $this->getModelProperty("binck_onder_grenswaarde");
$binck_boven_grenswaarde = $this->getModelProperty("binck_boven_grenswaarde");
$binck_bewaarloon_max = $this->getModelProperty("binck_bewaarloon_maximaal");
if($this->amount <= $binck_bewaarloon) $storage_fee = $this->amount * $binck_onder_grenswaarde;
else $storage_fee = $binck_bewaarloon * $binck_onder_grenswaarde + ($this->amount - $binck_bewaarloon) * $binck_boven_grenswaarde;
return $storage_fee > $binck_bewaarloon_max ? intval($binck_bewaarloon_max) : $storage_fee;
}
private function getBankTransactionFee()
{
// get model properties
$bank_variable_cost = $this->getModelProperty("transactiekosten_binck_variabel");
$bank_fixed_cost = $this->getModelProperty("transactiekosten_binck_vast");
$bank_minimal_cost = $this->getModelProperty("transactiekosten_binck_minimaal");
$bank_max_cost = $this->getModelProperty("transactiekosten_binck_maximaal");
$fund_rates = [];
for($i=1;$i<=8;$i++){
$fund_rate = $this->getModelProperty("weging_fonds".$i);
$fund_cost = $bank_variable_cost * $this->amount * $fund_rate + $bank_fixed_cost;
if($fund_rate == 0) $fund_cost = 0;//$bank_fixed_cost;
elseif($fund_cost < $bank_minimal_cost) $fund_cost = $bank_minimal_cost;
elseif($fund_cost > $bank_max_cost) $fund_cost = $bank_max_cost;
$fund_rates["fund$i"] = $fund_cost;
}
return array_sum($fund_rates);
}
private function getServiceFee()
{
$band1 = $band2 = $band3 = $band4 = 0;
$band1_top = $this->getModelProperty("schaal1");
$band2_top = $this->getModelProperty("schaal2");
$band3_top = $this->getModelProperty("schaal3");
$band1_rate = $this->getModelProperty("tarief_schaal1");
$band2_rate = $this->getModelProperty("tarief_schaal2");
$band3_rate = $this->getModelProperty("tarief_schaal3");
$band4_rate = $this->getModelProperty("tarief_schaal4");
$fee_amount = $this->amount;
if($fee_amount > $band3_top){
$band4 = ($fee_amount - $band3_top) * $band4_rate;
$fee_amount = $band3_top;
}
if($fee_amount > $band2_top){
$band3 = ($fee_amount - $band2_top) * $band3_rate;
$fee_amount = $band2_top;
}
if($fee_amount > $band1_top){
$band2 = ($fee_amount - $band1_top) * $band2_rate;
$fee_amount = $band1_top;
}
$band1 = $fee_amount * $band1_rate;
return $band1 + $band2 + $band3 + $band4;
}
private function getModelProperty($scale)
{
return $this->model_data[0]->getProperty($scale);
}
}
?>