add: all
This commit is contained in:
parent
a15319c4d1
commit
eebf859afa
39 changed files with 2742 additions and 937 deletions
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue