Skip to content

Commit

Permalink
Added controller, view and PDF for supplier payouts
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterZydra committed Feb 21, 2024
1 parent e31075f commit 699771b
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 2 deletions.
52 changes: 52 additions & 0 deletions app/Http/Controllers/SupplierPayoutsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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 SupplierPayoutsController extends BaseController implements ControllerInterface
{
public function execute(): void
{
if (Http::requestMethod() === 'GET') {
view('statistics.supplierPayouts');
return;
}

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

$invoice = null;
$filename = 'Auszahlungen_';
$queryBuilder = DeliveryNote::getQueryBuilder()->orderBy('supplierId')->orderBy('id');

if (Http::param('invoiceId', '') !== '') {
$queryBuilder->where(ColType::Int, 'invoiceId', Condition::Equal, Http::param('invoiceId'));
$invoice = Invoice::findById(Http::param('invoiceId'));
$filename .= $invoice->getYear() . '_' . $invoice->getNr();
} elseif (Http::param('invoiceYear', '') !== '') {
$queryBuilder->where(ColType::Int, 'year', Condition::Equal, Http::param('invoiceYear'));
$filename .= Http::param('invoiceYear');
}

$deliveryNotes = DeliveryNote::all($queryBuilder);

(new PDF())
->createPDF(setting('invoiceAuthor'), $filename, $filename, render('pdf.supplierPayouts', ['deliveryNotes' => $deliveryNotes, 'invoice' => $invoice]))
->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 @@ -20,6 +20,7 @@
use App\Http\Controllers\RecipientController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\SupplierController;
use App\Http\Controllers\SupplierPayoutsController;
use App\Http\Controllers\User\ChangePasswordController;
use App\Http\Controllers\User\LoginController;
use App\Http\Controllers\User\LogoutController;
Expand Down Expand Up @@ -64,6 +65,9 @@
Router::addController('editInvoiceSettings', new EditInvoiceSettingsController());
Router::addController('editInvoiceSettings', new EditInvoiceSettingsController(), 'POST');

Router::addController('showSupplierPayouts', new SupplierPayoutsController());
Router::addController('showSupplierPayouts', new SupplierPayoutsController(), 'POST');

if (Auth::hasRole('Administrator')) {
Router::addModel('user', new UserController());
}
Expand Down
24 changes: 24 additions & 0 deletions resources/Views/Components/invoiceSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use App\Models\Invoice;
use Framework\Database\Query\SortOrder;

// Optional passed variables:
// $selected => Id that should be selected

$invoices = Invoice::all(Invoice::getQueryBuilder()
->orderBy('year', SortOrder::Desc)
->orderBy('nr', SortOrder::Desc)
);

?>
<label for="invoiceId"><?= __('Invoice') ?>:</label><br>
<select id="invoiceId" name="invoiceId">
<option value=""><?= __('PleaseSelect') ?></option>
<?php /** @var \App\Models\Invoice $invoice */
foreach ($invoices as $invoice) { ?>
<option value="<?= $invoice->getId() ?>" <?php
if (isset($selected) && $invoice->getId() === $selected) { ?>selected<?php } ?>
><?= $invoice->getYear() ?> <?= $invoice->getNr() ?></option>
<?php } ?>
</select>
28 changes: 28 additions & 0 deletions resources/Views/Components/invoiceYearSelect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Framework\Database\Database;
use Framework\Database\Query\SortOrder;
use Framework\Database\QueryBuilder;

// Optional passed variables:
// $selected => Id that should be selected

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

$years = [];
if ($dataSet !== false) {
while ($row = $dataSet->fetch_assoc()) {
$years[] = $row['year'];
}
}

?>
<label for="invoiceYear"><?= __('InvoiceYear') ?>:</label><br>
<select id="invoiceYear" name="invoiceYear">
<option value=""><?= __('PleaseSelect') ?></option>
<?php foreach ($years as $year) { ?>
<option value="<?= $year ?>" <?php
if (isset($selected) && $year === $selected) { ?>selected<?php } ?>
><?= $year ?></option>
<?php } ?>
</select>
4 changes: 2 additions & 2 deletions resources/Views/auth/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
<div class="box">
<strong><?= __('Supplier') ?></strong><br>
<a href="activeSuppiers" target="_blank"><?= __('ShowActiveSuppliers') ?></a><br>
<a href="showSupplierPayments.php">Auszahlungen anzeigen</a><br>
<a href="showSupplierPayouts"><?= __('ShowPayouts') ?></a><br>
</div>

<div class="box">
<strong>Lieferschein</strong><br>
<strong><?= __('DeliveryNote') ?></strong><br>
<a href="showDeliveryNote_OpenVolumeDistribution.php">Offene Mengenverteilungen</a><br>
<a href="showCropVolumeDistribution.php">Mengenverteilung anzeigen</a>
</div>
Expand Down
83 changes: 83 additions & 0 deletions resources/Views/pdf/supplierPayouts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/** @var array $deliveryNotes */

use Framework\Facades\Format;

/** @var ?\App\Models\Invoice $invoice */

$docName = '';
if (isset($invoice)) {
$docName = 'Auszahlung für Rechnung ' . $invoice->getYear() . ' ' . $invoice->getNr();
} else {
$docName = 'Auszahlung für das Jahr ' . $deliveryNotes[0]->getYear();
}

?>

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

<tr><td width="100%">
<h1 style="text-align: center;"><?= $docName ?></h1><br>

<?php
$lastSupplier = null;
$sumAmount = 0;
$sumPayout = 0;
/** @var \App\Models\DeliveryNote $deliveryNote */
foreach ($deliveryNotes as $deliveryNote) {
if ($deliveryNote->getSupplier()->getHasNoPayout()) continue;
if ($deliveryNote->getSupplier()->getId() !== $lastSupplier) {
if ($lastSupplier !== null) { ?>

<tr style="height:2px;"><td style="height:2px;" colspan="4"><hr></td></tr>
<tr>
<td></td>
<td style="text-align: right;">Summe:</td>
<td style="text-align: right;"><?= $sumAmount ?></td>
<td style="text-align: right;"><?= Format::Currency($sumPayout) ?></td>
</tr>
</table><br><br>

<?php }
$lastSupplier = $deliveryNote->getSupplier()->getId();
$sumAmount = 0;
$sumPayout = 0;
?>

<i><?= $deliveryNote->getSupplier()->getName() ?></i><br>
<table>
<tr>
<th style="text-align: center;"><strong>Lieferschein-Nr.</strong></th>
<th style="text-align: center;"><strong>Lieferdatum</strong></th>
<th style="text-align: center;"><strong>Menge in <?= setting('massUnit')?></strong></th>
<th style="text-align: center;"><strong>x Preis in <?= setting('currencyUnit') ?></strong></th>
</tr>

<?php } ?>

<tr>
<?php
$price = $deliveryNote->getSupplier()->getHasFullPayout() ?
$deliveryNote->getPrice()->getPrice() : $deliveryNote->getPrice()->getPricePayout();
$sumAmount += $deliveryNote->getAmount();
$sumPayout += $price * $deliveryNote->getAmount();
?>
<td style="text-align: right;"><?= $deliveryNote->getNr() ?></td>
<td style="text-align: center;"><?= date("d.m.Y", strtotime($deliveryNote->getDeliveryDate())) ?></td>
<td style="text-align: right;"><?= $deliveryNote->getAmount() ?></td>
<td style="text-align: right;">x <?= $price ?> = <?= Format::Currency($price * $deliveryNote->getAmount()) ?></td>
</tr>

<?php } ?>

<tr style="height:2px;"><td style="height:2px;" colspan="4"><hr></td></tr>
<tr>
<td></td>
<td style="text-align: right;">Summe:</td>
<td style="text-align: right;"><?= $sumAmount ?></td>
<td style="text-align: right;"><?= Format::Currency($sumPayout) ?></td>
</tr>
</table><br><br>

</td></tr></table>
17 changes: 17 additions & 0 deletions resources/Views/statistics/supplierPayouts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?= component('layout.header') ?>

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

<form method="post">
<?= component('invoiceSelect') ?><br>

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

<?= __('Or') ?><br><br>

<?= component('invoiceYearSelect') ?><br>

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

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

0 comments on commit 699771b

Please sign in to comment.