Skip to content

Commit

Permalink
🔀 Merge pull request #34 from cristianlivella/develop
Browse files Browse the repository at this point in the history
✨ Implemented new methods for RW final value calculation (fix #19)
  • Loading branch information
cristianlivella authored Mar 17, 2022
2 parents 60ac70e + 18ea539 commit 79b3f83
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/app/Controllers/WebAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public static function printModelloRedditi() {
$settings = self::getSelectedReportSettings();
$compensateCapitalLosses = $settings['compensate_losses'] ?? true;
$exchangeSettings = $settings['exchanges'] ?? [];
$finalValueMethod = $settings['rw_final_value_method'] ?? 'average_value';

$reportWrapper = new ReportWrapper(self::getSelectedReportContent(), $exchangeSettings);

echo $reportWrapper->getModelloRedditi($year, $compensateCapitalLosses);
echo $reportWrapper->getModelloRedditi($year, $compensateCapitalLosses, $finalValueMethod);
}

public static function printModelloF24() {
Expand Down Expand Up @@ -122,6 +123,10 @@ public static function setSettings() {
$settings['compensate_losses'] = filter_var($_POST['compensate_losses'] ?? true, FILTER_VALIDATE_BOOLEAN);
}

if (isset($_POST['rw_final_value_method'])) {
$settings['rw_final_value_method'] = $_POST['rw_final_value_method'];
}

self::setCookie('SETTINGS-' . $reportId, base64_encode(json_encode($settings)));
}

Expand Down
13 changes: 11 additions & 2 deletions src/app/Models/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,23 @@ public function getInfoForModelloRedditi() {
*
* @return array
*/
public function getModelloRedditiSectionRwInfo() {
public function getModelloRedditiSectionRwInfo($finalValueMethod = 'average_value') {
if ($finalValueMethod === 'real_value') {
$finalValue = $this->cryptoInfoBag->getTotalValues()['value_end_of_year'];
} elseif ($finalValueMethod === 'real_value_more_incomes') {
$finalValue = $this->cryptoInfoBag->getTotalValues()['value_end_of_year'] + $this->currentYearIncome;
} else {
// fallback to average_value
$finalValue = $this->cryptoInfoBag->getTotalValues()['average_value'];
}

return [
'initial_value' => (
$this->fiscalYear === $this->getFirstYear() ?
$this->transactionsBag->transactions[1]->value :
$this->cryptoInfoBag->getTotalValues()['value_start_of_year']
),
'final_value' => $this->cryptoInfoBag->getTotalValues()['average_value']
'final_value' => $finalValue
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/Models/ReportWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public function getReport($year) {
]);
}

public function getModelloRedditi($year, $compensateCapitalLosses = true) {
public function getModelloRedditi($year, $compensateCapitalLosses = true, $finalValueMethod = 'average_value') {
$this->elaborateReport($year);

$info = $this->report->getInfoForModelloRedditi() + [
'rl' => $this->getSectionRlInfo($year),
'rw' => $this->report->getModelloRedditiSectionRwInfo(),
'rw' => $this->report->getModelloRedditiSectionRwInfo($finalValueMethod),
'rt' => $this->getSectionRtInfo($year, $compensateCapitalLosses),
'rm' => $this->getSectionRmInfo($year)
];
Expand Down

0 comments on commit 79b3f83

Please sign in to comment.