Skip to content

Commit

Permalink
New invoices option
Browse files Browse the repository at this point in the history
  • Loading branch information
martinoak committed Mar 26, 2024
1 parent 53399dd commit 4a5a4d7
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 19 deletions.
31 changes: 21 additions & 10 deletions app/Enums/InvoiceTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@

enum InvoiceTypes: string
{
case EARNING = 'Tržba';
case EXPENSE = 'Výdaj';
case SALARY = 'Mzda';
case VOUCHER = 'Poukaz';
case OTHER = 'Ostatní';
case EARNING = 'T';
case EXPENSE = 'V';
case SALARY = 'M';
case VOUCHER = 'P';
case OTHER = 'O';

public function getReadableFormat(): string
{
return match ($this) {
self::EARNING => 'Tržba',
self::EXPENSE => 'Výdaj',
self::SALARY => 'Mzda',
self::VOUCHER => 'Poukaz',
default => 'Ostatní'
};
}

public static function getHtmlSpan(string $type): string
{
return match ($type) {
'T' => '<span class="bg-green-100 text-green-800 dark:bg-green-800 dark:text-white rounded-full px-3 py-1 text-xs font-semibold">'.self::EARNING->value.'</span>',
'V' => '<span class="bg-red-100 text-red-800 dark:bg-red-800 dark:text-white rounded-full px-3 py-1 text-xs font-semibold">'.self::EXPENSE->value.'</span>',
'M' => '<span class="bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100 rounded-full px-3 py-1 text-xs font-semibold">'.self::SALARY->value.'</span>',
'P' => '<span class="bg-[#3056d3] text-white dark:bg-[#3056d3] dark:text-white rounded-full px-3 py-1 text-xs font-semibold">'.self::VOUCHER->value.'</span>',
default => '<span class="bg-gray-300 text-gray-800 dark:bg-gray-600 dark:text-gray-100 rounded-full px-3 py-1 text-xs font-semibold">'.self::OTHER->value.'</span>',
'T' => '<span class="bg-green-100 text-green-800 dark:bg-green-800 dark:text-white rounded-full px-3 py-1 text-xs font-semibold">'.self::EARNING->getReadableFormat().'</span>',
'V' => '<span class="bg-red-100 text-red-800 dark:bg-red-800 dark:text-white rounded-full px-3 py-1 text-xs font-semibold">'.self::EXPENSE->getReadableFormat().'</span>',
'M' => '<span class="bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100 rounded-full px-3 py-1 text-xs font-semibold">'.self::SALARY->getReadableFormat().'</span>',
'P' => '<span class="bg-[#3056d3] text-white dark:bg-[#3056d3] dark:text-white rounded-full px-3 py-1 text-xs font-semibold">'.self::VOUCHER->getReadableFormat().'</span>',
default => '<span class="bg-gray-300 text-gray-800 dark:bg-gray-600 dark:text-gray-100 rounded-full px-3 py-1 text-xs font-semibold">'.self::OTHER->getReadableFormat().'</span>',
};
}
}
12 changes: 12 additions & 0 deletions app/Http/Controllers/InvoicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public function show(string $id): BinaryFileResponse
return response()->download(storage_path('app/public/invoice/'.$id.'.png'));
}

public function create(): View
{
return view('admin.invoices.create');
}

public function store(Request $request): RedirectResponse
{
Invoice::create($request->all());

return to_route('invoices.index')->with('success', 'Faktura byla úspěšně vytvořena.');
}

/**
* Show the form for editing the specified resource.
*/
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/customers/create.latte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</div>
<div class="form-buttons">
<button type="submit" class="form-submit">Odeslat</button>
<button data-modal-hide="new-vin" type="reset" class="form-reset">Vymazat</button>
<button type="reset" class="form-reset">Vymazat</button>
</div>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/customers/edit.latte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</div>
<div class="form-buttons">
<button type="submit" class="form-submit">Odeslat</button>
<button data-modal-hide="new-vin" type="reset" class="form-reset">Vymazat</button>
<button type="reset" class="form-reset">Vymazat</button>
</div>
</form>
</div>
Expand Down
43 changes: 43 additions & 0 deletions resources/views/admin/invoices/create.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{layout '../../layout.latte'}

{block content}
<div class="p-4 sm:ml-64">
<div class="heading justify-start">
<button onclick="history.back()" class="button-indigo" type="button">
<i class="fa-solid fa-arrow-left fa-lg icon"></i> Zpět
</button>
<h1 class="heading-title">Nová faktura</h1>
</div>

<form method="post" action="{route('invoices.store')}">
{csrf_field()|noescape}
<div class="mb-5">
<label for="name" class="form-label">Název faktury <i class="fa-solid fa-asterisk text-red-600"></i></label>
<input type="text" name="name" id="name" value="{old('name')}" class="form-input" required>
</div>
<div class="mb-5">
<label for="type" class="form-label">Typ faktury <i class="fa-solid fa-asterisk text-red-600"></i></label>
<select name="type" id="type" class="form-input" required>
{foreach App\Enums\InvoiceTypes::cases() as $case}
<option value="{$case->value}" {if old('variant') === $case->value}selected{/if}>
{$case->getReadableFormat()}
</option>
{/foreach}
</select>
</div>
<div class="mb-5">
<label for="price" class="form-label">Částka <i class="fa-solid fa-asterisk text-red-600"></i></label>
<input name="price" id="price" class="form-input" type="number" inputmode="numeric" pattern="[0-9]*" value="{old('price')}" required>
</div>
<div class="mb-5">
<label for="date" class="form-label">Datum <i class="fa-solid fa-asterisk text-red-600"></i></label>
<input type="date" name="date" id="date" value="{old('term', \Illuminate\Support\Carbon::parse(time())->toDateString())}" class="form-input" required>
</div>
<input type="hidden" name="worker" value="S">
<div class="form-buttons">
<button type="submit" class="form-submit">Odeslat</button>
<button type="reset" class="form-reset">Vymazat</button>
</div>
</form>
</div>
{/block}
2 changes: 1 addition & 1 deletion resources/views/admin/invoices/edit.latte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</div>
<div class="form-buttons">
<button type="submit" class="form-submit">Odeslat</button>
<button data-modal-hide="new-vin" type="reset" class="form-reset">Vymazat</button>
<button type="reset" class="form-reset">Vymazat</button>
</div>
</form>
</div>
Expand Down
7 changes: 5 additions & 2 deletions resources/views/admin/invoices/index.latte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<div class="heading">
<div>
<h1 class="heading-title">Faktury</h1>
<a href="{route('invoices.export')}"><button class="button-green"><i class="fa-regular fa-file-excel fa-lg text-white icon"></i>Export</button></a>
<aside class="flex gap-4">
<a href="{route('invoices.export')}"><button class="button-green"><i class="fa-regular fa-file-excel fa-lg text-white icon"></i>Export</button></a>
<a href="{route('invoices.create')}" class="button-black"><i class="fa-solid fa-plus fa-lg icon"></i> Faktura</a>
</aside>
</div>
</div>
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
Expand Down Expand Up @@ -46,7 +49,7 @@
</td>
<td class="px-6 py-4 flex gap-2">
{if $invoice->type === 'P' && file_exists(storage_path('app/public/voucher/').$invoice->name.'.png')}
<a href="{route('vouchers.show', [voucher => $invoice->name])}" aria-valuemax="storage_path('app/public/voucher').$invoice->name.'.png'" class="cursor-pointer text-white bg-amber-700 hover:bg-amber-800 font-medium rounded-lg text-sm p-2.5 text-center inline-flex items-center me-2 dark:bg-amber-600 dark:hover:bg-amber-700" {if !file_exists(storage_path('app/public/voucher/').$invoice->name.'png')}disabled{/if}>
<a href="{route('vouchers.show', [voucher => $invoice->name])}" class="cursor-pointer text-white bg-amber-700 hover:bg-amber-800 font-medium rounded-lg text-sm p-2.5 text-center inline-flex items-center me-2 dark:bg-amber-600 dark:hover:bg-amber-700" {if !file_exists(storage_path('app/public/voucher/').$invoice->name.'png')}disabled{/if}>
<i class="fa-solid fa-eye"></i>
</a>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/vin/edit.latte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="form-buttons">
<button type="submit" class="form-submit">Odeslat</button>
<button data-modal-hide="new-vin" type="reset" class="form-reset">Vymazat</button>
<button type="reset" class="form-reset">Vymazat</button>
</div>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/vin/index.latte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">
Nové VIN
</h3>
<button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide="new-vin">
<button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white">
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
</svg>
Expand All @@ -37,7 +37,7 @@
</div>
<div class="form-buttons">
<button type="submit" class="form-submit">Odeslat</button>
<button data-modal-hide="new-vin" type="reset" class="form-reset">Vymazat</button>
<button type="reset" class="form-reset">Vymazat</button>
</div>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Route::group(['middleware' => 'auth', 'prefix' => 'admin'], function () {
Route::get('/', [AdminController::class, 'dashboard'])->name('dashboard');

Route::resource('invoices', InvoicesController::class)->except('create','store','destroy');
Route::resource('invoices', InvoicesController::class)->except('destroy');

Route::resource('customers', CustomersController::class)->except('show');
Route::group(['prefix' => 'customers'], function () {
Expand Down

0 comments on commit 4a5a4d7

Please sign in to comment.