add: all
This commit is contained in:
parent
a15319c4d1
commit
eebf859afa
39 changed files with 2742 additions and 937 deletions
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\CsvController\CsvCostCalc;
|
||||
|
||||
class CsvAgentCost
|
||||
{
|
||||
private $internal_percentage_to_deduct;
|
||||
private $CsvMinuteCostCalc;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
|
||||
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
|
||||
$this->CsvMinuteCostCalc = new CsvMinuteCostCalc();
|
||||
}
|
||||
|
||||
private function preapare_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;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function calculate_agents_cost(array $array, array $agents_time, float $minute_cost)
|
||||
{
|
||||
foreach ($agents_time as $name => $agent_time) {
|
||||
//Identify agents involved in the issue
|
||||
$array[$name] = gmdate('H:i:s', $agent_time);
|
||||
$array[$name . ' costo'] = $agent_time / 60 * $minute_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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\CsvController\CsvCostCalc;
|
||||
|
||||
class CsvCostCalc
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
|
||||
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
|
||||
$this->CsvAgentCost = new CsvAgentCost();
|
||||
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
|
||||
$this->CsvSumTotalsCalc = new CsvSumTotalsCalc();
|
||||
}
|
||||
|
||||
|
||||
function total_time_cost(array $array, int $total_time)
|
||||
{
|
||||
return $this->CsvTotalCostCalc->total_time_cost($array, $total_time);
|
||||
}
|
||||
|
||||
function agent_cost_calc(array $array, array $company_agents, array $agents_time)
|
||||
{
|
||||
return $this->CsvAgentCost->agent_cost_calc($array, $company_agents, $agents_time);
|
||||
}
|
||||
|
||||
function sum_costs(array $data, array $company_agents = [])
|
||||
{
|
||||
return $this->CsvSumTotalsCalc->sum_costs($data, $company_agents);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\CsvController\CsvCostCalc;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CsvMinuteCostCalc
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
|
||||
$this->partner_organization = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
|
||||
$this->price_partner = [
|
||||
'high' => $this->calculate_minute_cost((int)getenv('PRICE_PARTNER_HIGH')),
|
||||
'normal' => $this->calculate_minute_cost((int)getenv('PRICE_PARTNER_NORMAL')),
|
||||
'low' => $this->calculate_minute_cost((int)getenv('PRICE_PARTNER_LOW')),
|
||||
'0'=>0,
|
||||
];
|
||||
$this->price_client = [
|
||||
'high' => $this->calculate_minute_cost((int)getenv('PRICE_CLIENT_HIGH')),
|
||||
'normal' => $this->calculate_minute_cost((int)getenv('PRICE_CLIENT_NORMAL')),
|
||||
'low' => $this->calculate_minute_cost((int)getenv('PRICE_CLIENT_LOW')),
|
||||
'0'=>0,
|
||||
];
|
||||
}
|
||||
|
||||
private function calculate_minute_cost(int $hourly_cost)
|
||||
{
|
||||
return $hourly_cost / 60;
|
||||
}
|
||||
|
||||
private function extract_string_from_label($label)
|
||||
{
|
||||
return strtolower(substr($label, strpos($label, '/') + 1));
|
||||
}
|
||||
|
||||
function select_correct_cost($requested_by, $priority)
|
||||
{
|
||||
$requested_by = $this->extract_string_from_label($requested_by);
|
||||
$priority = $this->extract_string_from_label($priority);
|
||||
|
||||
$requested_by_partner = str_contains($requested_by, strtolower($this->partner_organization));
|
||||
try {
|
||||
$priority = match ($priority) {
|
||||
'critical', 'high' => 'high',
|
||||
'medium' => 'normal',
|
||||
'low' => 'low',
|
||||
default =>'0'
|
||||
};
|
||||
} catch (Exception $e) {
|
||||
Log::error('E-CSV-MINUTECOSTCALC - '. $e->getMessage());
|
||||
}
|
||||
if ($requested_by_partner) {
|
||||
return $this->price_partner[$priority];
|
||||
}
|
||||
return $this->price_client[$priority];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\CsvController\CsvCostCalc;
|
||||
|
||||
class CsvSumTotalsCalc
|
||||
{
|
||||
|
||||
private $calculate_agent_cost;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST');
|
||||
}
|
||||
|
||||
private function sum_total_cost(array $array)
|
||||
{
|
||||
(float)$total = 0;
|
||||
|
||||
foreach ($array as $issue_total) {
|
||||
$issue_total_cost = $issue_total['Costo totale'];
|
||||
$total += $issue_total_cost;
|
||||
}
|
||||
|
||||
$totalSumCsvLine = array(
|
||||
'Progetto' => '',
|
||||
'#' => '',
|
||||
'Titolo' => '',
|
||||
'URL' => '',
|
||||
'Aperto_il' => '',
|
||||
'Chiuso_il' => '',
|
||||
'Etichette' => '',
|
||||
'Kind' => '',
|
||||
'Request By' => '',
|
||||
'Priority' => '',
|
||||
'Tempo totale' => '',
|
||||
'Costo totale' => $total,
|
||||
);
|
||||
|
||||
array_push($array, $totalSumCsvLine);
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function add_agents_csv_line($agent_struct, $last_csv_line)
|
||||
{
|
||||
$agents_csv_line = $last_csv_line;
|
||||
foreach ($agent_struct as $agent_name => $agent_sum) {
|
||||
$agents_csv_line[$agent_name] = '';
|
||||
$agents_csv_line[$agent_name . ' costo'] = $agent_sum;
|
||||
}
|
||||
return $agents_csv_line;
|
||||
}
|
||||
|
||||
private function init_agents_struct($company_agents){
|
||||
return array_combine($company_agents, array_fill(0, count($company_agents), 0));
|
||||
}
|
||||
|
||||
private function extract_agent_cost(array $array,array $agent_struct){
|
||||
$i=0;
|
||||
$issue_length = count( $array );
|
||||
foreach ($array as $issue) {
|
||||
if(++$i == $issue_length) break;
|
||||
foreach ($agent_struct as $agent_name => $agent_sum) {
|
||||
$agent_cost = $issue[$agent_name . ' costo'];
|
||||
$agent_struct[$agent_name] += $agent_cost;
|
||||
}
|
||||
}
|
||||
return $agent_struct;
|
||||
}
|
||||
private function sum_agents_cost($array, $company_agents)
|
||||
{
|
||||
$agent_struct = $this->init_agents_struct($company_agents);
|
||||
$agent_struct = $this->extract_agent_cost($array, $agent_struct);
|
||||
$agents_csv_line = $this->add_agents_csv_line($agent_struct, end($array));
|
||||
$array[key($array)] = $agents_csv_line;
|
||||
return $array;
|
||||
}
|
||||
|
||||
function sum_costs(array $array, $company_agents = [])
|
||||
{
|
||||
$array = $this->sum_total_cost($array);
|
||||
|
||||
if ($this->calculate_agent_cost) {
|
||||
$array = $this->sum_agents_cost($array, $company_agents);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\CsvController\CsvCostCalc;
|
||||
|
||||
class CsvTotalCostCalc
|
||||
{
|
||||
private $CsvMinuteCostCalc;
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->CsvMinuteCostCalc = new CsvMinuteCostCalc();
|
||||
}
|
||||
|
||||
function total_time_cost(array $array, int $total_time)
|
||||
{
|
||||
$minute_cost = $this->CsvMinuteCostCalc->select_correct_cost($array['Request By'], $array['Priority']);
|
||||
$total_cost = $total_time / 60 * $minute_cost;
|
||||
$array['Tempo totale'] = gmdate('H:i:s', $total_time);
|
||||
$array['Costo totale'] = $total_cost;
|
||||
return $array;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue