fix: env vars handled via conf file, add: functional tests

This commit is contained in:
Michael 2024-08-17 18:06:06 +02:00
parent 3d08b14f11
commit 21c4330f16
39 changed files with 416 additions and 172 deletions

View file

@ -17,11 +17,12 @@ class CsvController extends Controller
private $csv_data_handling;
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost');
$this->csv_data_init = new CsvDataInit();
$this->csv_data_handling = new CsvDataHandling();
$this->third_party_integrations_allow = env('THIRD_PARTY_INTEGRATIONS_ALLOW', false);
$this->csv_data_handling = new CsvDataHandling($this->calculate_agent_cost);
$this->third_party_integrations_allow = config('app.third_party_integrations_allow', false);
}
function create_columns(array $issue, array $issue_time, array $company_agents = [])
@ -29,7 +30,7 @@ class CsvController extends Controller
try {
$array = $this->csv_data_init->initialize_csv_data($issue);
$array = $this->csv_data_init->handle_labels($array, $issue['labels']);
$array = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents);
$array = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents, $this->calculate_agent_cost);
return $array;
} catch (Error $e) {
Log::error('E-CSV-COLUMNS - ' . $e->getMessage());

View file

@ -12,8 +12,8 @@ class CsvAgentCost
public function __construct()
{
$this->internal_percentage_to_deduct = (float) getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT', null);
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
$this->internal_percentage_to_deduct = (float) config('app.price_internal_percentage_to_deduct', null);
$this->partner_organitation = strtolower(config('app.gitea_partner_organization'));
$this->CsvMinuteCostCalc = new CsvMinuteCostCalc();
}

View file

@ -8,13 +8,13 @@ class CsvCostCalc
* @var CsvMinuteCostCalc|(CsvMinuteCostCalc&object&\PHPUnit\Framework\MockObject\MockObject)|(CsvMinuteCostCalc&\PHPUnit\Framework\MockObject\MockObject)|(object&\PHPUnit\Framework\MockObject\MockObject)|\PHPUnit\Framework\MockObject\MockObject
*/
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->internal_percentage_to_deduct = getenv('PRICE_INTERNAL_PERCENTAGE_TO_DEDUCT');
$this->partner_organitation = strtolower(getenv('GITEA_PARTNER_ORGANIZATION'));
$this->internal_percentage_to_deduct = config('app.price_internal_percentage_to_deduct');
$this->partner_organitation = strtolower(config('app.gitea_partner_organization'));
$this->CsvAgentCost = new CsvAgentCost();
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
$this->CsvSumTotalsCalc = new CsvSumTotalsCalc();
$this->CsvSumTotalsCalc = new CsvSumTotalsCalc($calculate_agent_cost);
}

View file

@ -10,18 +10,18 @@ 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->internal_percentage_to_deduct = config('app.price_internal_percentage_to_deduct');
$this->partner_organization = strtolower(config('app.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')),
'high' => $this->calculate_minute_cost((int)config('app.price_partner_high')),
'normal' => $this->calculate_minute_cost((int)config('app.price_partner_normal')),
'low' => $this->calculate_minute_cost((int)config('app.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')),
'high' => $this->calculate_minute_cost((int)config('app.price_client_high')),
'normal' => $this->calculate_minute_cost((int)config('app.price_client_normal')),
'low' => $this->calculate_minute_cost((int)config('app.price_client_low')),
'0'=>0,
];
}

View file

@ -7,9 +7,9 @@ class CsvSumTotalsCalc
private $calculate_agent_cost;
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST');
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost');
}
private function sum_total_cost(array $array)

View file

@ -6,9 +6,9 @@ use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
class CsvDataHandling
{
public function __construct()
public function __construct($calculate_agent_cost = false)
{
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST');
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost');
$this->csv_cost_calc = new CsvCostCalc();
}
@ -33,7 +33,7 @@ class CsvDataHandling
return [$total_issue_time, $agents_issue_time];
}
function handle_csv_time(array $array, array $issue, array $issue_time, array $company_agents = [])
function handle_csv_time(array $array, array $issue, array $issue_time, array $company_agents = [], $calculate_agent_cost = false)
{
[$total_time, $agents_time] = $this->get_issue_total_time($issue_time);
$array = $this->csv_cost_calc->total_time_cost($array, $total_time);