add: tests
This commit is contained in:
parent
eebf859afa
commit
ce7f620984
16 changed files with 681 additions and 152 deletions
|
@ -2,49 +2,61 @@
|
|||
|
||||
namespace App\Http\Controllers\CsvController\CsvCostCalc;
|
||||
|
||||
use App\Utils\utils;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use RuntimeException;
|
||||
|
||||
class CsvAgentCost
|
||||
{
|
||||
private $internal_percentage_to_deduct;
|
||||
private $CsvMinuteCostCalc;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
|
||||
$this->internal_percentage_to_deduct = (float) getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT', null);
|
||||
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
|
||||
$this->CsvMinuteCostCalc = new CsvMinuteCostCalc();
|
||||
}
|
||||
|
||||
private function preapare_agents_columns(array $array, array $company_agents)
|
||||
|
||||
|
||||
function prepare_agents_columns(array $array, array $company_agents)
|
||||
{
|
||||
//Add all agents columns
|
||||
foreach ($company_agents as $company_agent) {
|
||||
$array[$company_agent] = '';
|
||||
$array[$company_agent . ' costo'] = 0;
|
||||
try {
|
||||
//Add all agents columns
|
||||
foreach ($company_agents as $company_agent) {
|
||||
$array[$company_agent] = '';
|
||||
$array[$company_agent . ' costo'] = 0;
|
||||
}
|
||||
return $array;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('prepare_agents_columns E-AGENT-COLUMNS - ' . $e->getMessage());
|
||||
throw new RuntimeException("E-AGENT-COLUMNS - " . $e->getMessage() );
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function calculate_agents_cost(array $array, array $agents_time, float $minute_cost)
|
||||
function calculate_agents_cost(array $array, array $agents_time, float $minute_cost)
|
||||
{
|
||||
$minute_cost = utils::round_up_to_two_decimals($minute_cost);
|
||||
foreach ($agents_time as $name => $agent_time) {
|
||||
//Identify agents involved in the issue
|
||||
$agent_cost = utils::round_up_to_two_decimals($agent_time / 60 * $minute_cost);
|
||||
$array[$name] = gmdate('H:i:s', $agent_time);
|
||||
$array[$name . ' costo'] = $agent_time / 60 * $minute_cost;
|
||||
$array[$name . ' costo'] = $agent_cost;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
function agent_cost_calc(array $array, array $company_agents, array $agents_time)
|
||||
{
|
||||
$array = $this->preapare_agents_columns($array, $company_agents);
|
||||
|
||||
//Calculate cost, subtract a % from the minute_cost
|
||||
$minute_cost = $this->CsvMinuteCostCalc->select_correct_cost($array['Request By'], $array['Priority']);
|
||||
$minute_cost = $minute_cost - ($minute_cost / 100 * $this->internal_percentage_to_deduct);
|
||||
|
||||
$array = $this->calculate_agents_cost($array, $agents_time, $minute_cost);
|
||||
|
||||
return $array;
|
||||
try {
|
||||
if(!is_int($this->internal_percentage_to_deduct) && !is_float($this->internal_percentage_to_deduct)) throw new RuntimeException("agent_cost_calc E-AGENT-PERCENTAGE - Internal percentage is not set or NaN");
|
||||
$array = $this->prepare_agents_columns($array, $company_agents);
|
||||
//Calculate cost, subtract a % from the minute_cost
|
||||
$minute_cost = $this->CsvMinuteCostCalc->select_correct_cost($array['Request By'], $array['Priority']);
|
||||
$minute_cost = $minute_cost - ($minute_cost / 100 * $this->internal_percentage_to_deduct);
|
||||
$array = $this->calculate_agents_cost($array, $agents_time, $minute_cost);
|
||||
return $array;
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
throw new RuntimeException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue