Skip to content

Commit

Permalink
Added statistic for price development
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
MasterZydra committed Mar 17, 2024
1 parent 4231b69 commit e4e7b80
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 4 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ Types of changes: `Added`, `Changed`, `Deprecate`, `Removed`, `Fixed`, `Secruity

## [Unreleased]

## v2.5.0 - 17.03.2024 - Added statistic for amount and price development

### Added
- Added component for line chart #59
- Added statistic for amount development #31
- Added component for line chart
- Added statistic for amount development
- Added statistic for price development

## v2.4.0 - 11.03.2024 - Added revenue and profit statistic

Expand Down
38 changes: 38 additions & 0 deletions app/Http/Controllers/PriceDevelopmentStatsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers;

use App\Models\Price;
use Framework\Authentication\Auth;
use Framework\Routing\BaseController;
use Framework\Routing\ControllerInterface;

class PriceDevelopmentStatsController extends BaseController implements ControllerInterface
{
public function execute(): void
{
Auth::checkRole('Maintainer');

$prices = Price::all(Price::getQueryBuilder()->orderBy('productId')->orderBy('recipientId')->orderBy('year'));

$dataPrice = [];
$dataPricePayout = [];
/** @var \App\Models\Price $price */
foreach ($prices as $price) {
$productName = $price->getProduct()->getName() . ' - ' . $price->getRecipient()->getName();

if (!key_exists($productName, $dataPrice)) {
$dataPrice[$productName] = [];
}
$dataPrice[$productName][$price->getYear()] = $price->getPrice();

if (!key_exists($productName, $dataPricePayout)) {
$dataPricePayout[$productName] = [];
}
$dataPricePayout[$productName][$price->getYear()] = $price->getPricePayout();
}

view('statistics.priceDevelopment', ['dataPrice' => $dataPrice, 'dataPricePayout' => $dataPricePayout]);
}

}
2 changes: 2 additions & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Http\Controllers\OpenVolumeDistributionsController;
use App\Http\Controllers\PlotController;
use App\Http\Controllers\PriceController;
use App\Http\Controllers\PriceDevelopmentStatsController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\RecipientController;
use App\Http\Controllers\SettingController;
Expand Down Expand Up @@ -71,6 +72,7 @@
Router::addController('showVolumeDistribution', new VolumeDistributionPdfController(), 'POST');
Router::addController('financialRevenueProfitStats', new FinancialRevenueProfitStatsController());
Router::addController('amountDevelopmentStats', new AmountDevelopmentStatsController());
Router::addController('priceDevelopmentStats', new PriceDevelopmentStatsController());
}

if (Auth::hasRole('Administrator')) {
Expand Down
1 change: 1 addition & 0 deletions resources/Lang/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
'Plot' => 'Flurstück',
'PostalCode' => 'Postleitzahl',
'Price' => 'Preis',
'PriceDevelopment' => 'Preisentwicklung',
'Product' => 'Produkt',
'Profit' => 'Gewinn',
'Provider' => 'Anbieter',
Expand Down
1 change: 1 addition & 0 deletions resources/Lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
'Plot' => 'Plot',
'PostalCode' => 'Postal code',
'Price' => 'Price',
'PriceDevelopment' => 'Price development',
'Product' => 'Product',
'Profit' => 'Profit',
'Provider' => 'Provider',
Expand Down
2 changes: 1 addition & 1 deletion resources/Views/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<table class="scrollable">
<tr>
<td>Bio-Manager Version</td>
<td class="right">2.4.0</td>
<td class="right">2.5.0</td>
</tr>
<tr>
<td><?= __('Developer') ?></td>
Expand Down
3 changes: 2 additions & 1 deletion resources/Views/auth/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@

<div class="box">
<strong><?= __('Finances') ?></strong><br>
<a href="financialRevenueProfitStats"><?= __('RevenueAndProfit') ?></a>
<a href="financialRevenueProfitStats"><?= __('RevenueAndProfit') ?></a><br>
<a href="priceDevelopmentStats"><?= __('PriceDevelopment') ?></a>
</div>

<?php }
Expand Down
42 changes: 42 additions & 0 deletions resources/Views/statistics/priceDevelopment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php use Framework\Facades\Format; ?>
<?= component('layout.header') ?>

<h1><?= __('PriceDevelopment') ?></h1>

<table class="scrollable">
<tr>
<th class="center"><?= __('Product') ?></th>
<th class="center"><?= __('Year') ?></th>
<th class="center"><?= __('Price') ?> (<?= __('XPerY', setting('currencyUnit'), setting('massUnit')) ?>)</th>
<th class="center"><?= __('Payout') ?> (<?= __('XPerY', setting('currencyUnit'), setting('massUnit')) ?>)</th>
</tr>
<?php foreach ($dataPrice as $product => $prices): ?>
<?php foreach ($prices as $year => $price): ?>
<tr>
<td><?= $product ?></td>
<td class="center"><?= $year ?></td>
<td class="center"><?= Format::currency($price) ?></td>
<td class="center"><?= Format::currency($dataPricePayout[$product][$year]) ?></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
</table>

<?php
$chartCount = 0;
foreach (array_keys($dataPrice) as $product) {
?><h3><?= $product ?></h3><?php
component('chart.line', [
'chartName' => 'priceDevelopment' . $chartCount,
'xTitle' => __('Year'),
'yTitle' => __('XPerY', setting('currencyUnit'), setting('massUnit')),
'dataSet' => [
['label' => __('Price'), 'data' => $dataPrice[$product]],
['label' => __('Payout'), 'data' => $dataPricePayout[$product]],
],
]);
$chartCount += 1;
}
?>

<?= component('layout.footer') ?>

0 comments on commit e4e7b80

Please # to comment.