Hoan thien core finance v2 - Calculation Pipeline, Form Templates
This commit is contained in:
51
app/Services/Calculation/CalculationResult.php
Normal file
51
app/Services/Calculation/CalculationResult.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Calculation;
|
||||
|
||||
class CalculationResult
|
||||
{
|
||||
protected array $steps = [];
|
||||
protected array $values = [];
|
||||
|
||||
public function addStep(array $stepResult): void
|
||||
{
|
||||
$this->steps[] = $stepResult;
|
||||
$this->values[$stepResult['output_key']] = $stepResult['rounded_value'];
|
||||
}
|
||||
|
||||
public function get(string $key): ?int
|
||||
{
|
||||
return $this->values[$key] ?? null;
|
||||
}
|
||||
|
||||
public function getSteps(): array
|
||||
{
|
||||
return $this->steps;
|
||||
}
|
||||
|
||||
public function getValues(): array
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'steps' => $this->steps,
|
||||
'final_values' => $this->values,
|
||||
];
|
||||
}
|
||||
|
||||
public function toPriceSheet(): array
|
||||
{
|
||||
$sheet = [];
|
||||
foreach ($this->steps as $step) {
|
||||
$sheet[] = [
|
||||
'description' => $step['name'],
|
||||
'value' => $step['rounded_value'],
|
||||
'is_overridden' => $step['is_overridden'],
|
||||
];
|
||||
}
|
||||
return $sheet;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user