-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added controller, view and PDF for supplier payouts
- Loading branch information
1 parent
e31075f
commit 699771b
Showing
7 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('/'); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') ?> |