Skip to content

Commit

Permalink
Added controller, view and PDF for volume distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterZydra committed Feb 21, 2024
1 parent eaf8016 commit 98f5a00
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 3 deletions.
38 changes: 38 additions & 0 deletions app/Http/Controllers/VolumeDistributionPdfController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers;

use App\Models\DeliveryNote;
use App\Models\Invoice;
use Framework\Database\Query\ColType;
use Framework\Database\Query\Condition;
use Framework\Facades\Http;
use Framework\PDF\PDF;
use Framework\Routing\BaseController;
use Framework\Routing\ControllerInterface;

class VolumeDistributionPdfController extends BaseController implements ControllerInterface
{
public function execute(): void
{
if (Http::requestMethod() === 'GET') {
view('statistics.volumeDistribution');
return;
}

if (Http::requestMethod() === 'POST') {
if (Http::param('invoiceYear', '') === '') {
Http::redirect('showSupplierPayouts');
}

$filename = 'Mengenverteilung ' . Http::param('invoiceYear');

(new PDF())
->createPDF(setting('invoiceAuthor'), $filename, $filename, render('pdf.volumeDistribution', ['year' => Http::param('invoiceYear')]))
->showInBrowser($filename);
return;
}

Http::redirect('/');
}
}
4 changes: 4 additions & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use App\Http\Controllers\User\LoginController;
use App\Http\Controllers\User\LogoutController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\VolumeDistributionPdfController;
use Framework\Authentication\Auth;
use Framework\Cli\Controllers\WebCliController;
use Framework\Facades\Http;
Expand Down Expand Up @@ -68,6 +69,9 @@
Router::addController('showSupplierPayouts', new SupplierPayoutsController());
Router::addController('showSupplierPayouts', new SupplierPayoutsController(), 'POST');

Router::addController('showVolumeDistribution', new VolumeDistributionPdfController());
Router::addController('showVolumeDistribution', new VolumeDistributionPdfController(), 'POST');

if (Auth::hasRole('Administrator')) {
Router::addModel('user', new UserController());
}
Expand Down
8 changes: 7 additions & 1 deletion framework/Facades/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public static function IBAN(string $IBAN): string
/** Format the given value to e.g. `X.XXX,XX EUR` */
public static function Currency(float $value): string
{
return number_format($value, 2, ',', '.') . ' ' . setting('currencyUnit');
return self::Decimal($value) . ' ' . setting('currencyUnit');
}

/** Format the given value to e.g. `X.XXX,XX` */
public static function Decimal(float $value): string
{
return number_format($value, 2, ',', '.');
}
}
1 change: 1 addition & 0 deletions resources/Lang/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
'ShowAllSuppliers' => 'Alle Lieferanten anzeigen',
'ShowAllUsers' => 'Alle Benutzer anzeigen',
'ShowPayouts' => 'Auszahlungen anzeigen',
'ShowVolumeDistribution' => 'Mengenverteilung anzeigen',
'Street' => 'Straße',
'Subdistrict' => 'Gemarkung',
'Supplier' => 'Lieferant',
Expand Down
1 change: 1 addition & 0 deletions resources/Lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
'ShowAllUsers' => 'Show all users',
'ShowDeliveryNotes' => 'Show all delivery notes',
'ShowPayouts' => 'Show payouts',
'ShowVolumeDistribution' => 'Show volume distribution',
'Street' => 'Street',
'Subdistrict' => 'Subdistrict',
'Supplier' => 'Supplier',
Expand Down
5 changes: 4 additions & 1 deletion resources/Views/Components/invoiceYearSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// Optional passed variables:
// $selected => Id that should be selected
// $notEmpty => Do not show the "Please select" entry

$dataSet = Database::executeBuilder(QueryBuilder::new('invoices')->select('DISTINCT year')->orderBy('year', SortOrder::Desc));

Expand All @@ -19,7 +20,9 @@
?>
<label for="invoiceYear"><?= __('InvoiceYear') ?>:</label><br>
<select id="invoiceYear" name="invoiceYear">
<option value=""><?= __('PleaseSelect') ?></option>
<?php if (!isset($notEmpty)) { ?>
<option value=""><?= __('PleaseSelect') ?></option>
<?php } ?>
<?php foreach ($years as $year) { ?>
<option value="<?= $year ?>" <?php
if (isset($selected) && $year === $selected) { ?>selected<?php } ?>
Expand Down
2 changes: 1 addition & 1 deletion resources/Views/auth/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<div class="box">
<strong><?= __('DeliveryNote') ?></strong><br>
<a href="showDeliveryNote_OpenVolumeDistribution.php">Offene Mengenverteilungen</a><br>
<a href="showCropVolumeDistribution.php">Mengenverteilung anzeigen</a>
<a href="showVolumeDistribution"><?= __('ShowVolumeDistribution') ?></a>
</div>

<?php }
Expand Down
68 changes: 68 additions & 0 deletions resources/Views/pdf/volumeDistribution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/** @var string $year */

use Framework\Database\Database;
use Framework\Facades\Format;
use Framework\Facades\Http;
use Framework\Message\Message;
use Framework\Message\Type;

?>

<table cellpadding="5" cellspacing="0" style="width: 100%;">
<tr>
<td width="100%">

<h1 style="text-align: center;">Mengenverteilung <?= $year ?></h1><br>

<table cellpadding="5" cellspacing="0" style="width: 100%;" border="0">

<tr style="background-color: #4a8a16; padding:5px; color:white;">
<td style="padding:5px;"><b>Flurstück</b></td>
<td><b>Name</b></td>
<td><b>Menge in <?= setting('massUnit') ?></b></td>
</tr>

<?php

$dataSet = Database::prepared(
'SELECT plots.nr, plots.name, SUM(volumeDistributions.amount) AS amount ' .
'FROM deliveryNotes ' .
'RIGHT JOIN volumeDistributions ON deliveryNotes.id = volumeDistributions.deliveryNoteId ' .
'LEFT JOIN plots ON volumeDistributions.plotId = plots.id ' .
'WHERE deliveryNotes.year = ? ' .
'GROUP BY plots.nr',
'i',
$year
);

if ($dataSet === false) {
Message::setMessage('An unkown error occured while creating the PDF', Type::Error);
Http::redirect('/showVolumeDistribution');
}

$totalAmount = 0;

while ($row = $dataSet->fetch_assoc()) {
$totalAmount += $row['amount'];
?>
<tr>
<td style="text-align: left;"><?= $row['nr'] ?></td>
<td style="text-align: left;"><?= $row['name'] ?></td>
<td style="text-align: right;"><?= Format::Decimal($row['amount']) ?></td>
</tr>
<?php } ?>

</table>

</td></tr></table>

<hr>

<table cellpadding="5" cellspacing="0" style="width: 100%;" border="0">
<tr>
<td colspan="3"><b>Gesamtmenge in <?= setting('massUnit') ?>: </b></td>
<td style="text-align: right;"><b><?= Format::Decimal($totalAmount) ?></b></td>
</tr>
</table>
11 changes: 11 additions & 0 deletions resources/Views/statistics/volumeDistribution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?= component('layout.header') ?>

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

<form method="post">
<?= component('invoiceYearSelect', ['notEmpty' => '']) ?><br>

<button><?= __('Show') ?></button>
</form>

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

0 comments on commit 98f5a00

Please sign in to comment.