From c20a3bcdcfab1b8c724c860963d9ecdd34e4575c Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 7 Jan 2025 12:52:25 +0100 Subject: [PATCH] Create invoices in XML Format. --- app/Http/Controllers/EController.php | 29 ++++ app/Http/Controllers/PdfController.php | 10 +- app/Http/Option.php | 17 +++ resources/views/components/e-icon.blade.php | 23 +++ resources/views/components/pdf-icon.blade.php | 2 +- resources/views/invoice/show.blade.php | 9 +- resources/views/xml/ToDos | 4 + resources/views/xml/invoice.blade.php | 133 ++++++++++++++++++ routes/web.php | 4 +- 9 files changed, 217 insertions(+), 14 deletions(-) create mode 100644 app/Http/Controllers/EController.php create mode 100644 app/Http/Option.php create mode 100644 resources/views/components/e-icon.blade.php create mode 100644 resources/views/xml/ToDos create mode 100644 resources/views/xml/invoice.blade.php diff --git a/app/Http/Controllers/EController.php b/app/Http/Controllers/EController.php new file mode 100644 index 0000000..85822fb --- /dev/null +++ b/app/Http/Controllers/EController.php @@ -0,0 +1,29 @@ +items as $item) { + if (!isset($taxes[$item->tax])) { + $taxes[$item->tax] = ['tax' => 0, 'taxable' => 0]; + } + $taxes[$item->tax]['tax'] += round($item->price * $item->amount * $item->tax / 100, 2, PHP_ROUND_HALF_UP); + $taxes[$item->tax]['taxable'] += $item->price * $item->amount; + } + + return response()->streamDownload(function () use ($invoice, $taxes) { + echo view('xml.invoice', ['invoice' => $invoice, 'options' => Option::optionsAsObject(), 'taxes' => $taxes]); + }, 'test.xml', ['Content-Type' => 'application/xml']); + + } +} diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index 2daaa06..1bbea51 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers; +use App\Http\Option; use App\Models\Invoice; -use App\Models\Option; use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Http\Response; @@ -12,13 +12,7 @@ class PdfController extends Controller public function downloadInvoice(int $invoice_id): Response { $invoice = Invoice::find($invoice_id); - $all_options = Option::all(['name', 'value']); - $options = new \stdClass(); - foreach ($all_options as $option) { - $key = $option->name; - $options->$key = $option->value; - } - return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => $options])->stream(); + return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => Option::optionsAsObject()])->stream(); } } diff --git a/app/Http/Option.php b/app/Http/Option.php new file mode 100644 index 0000000..fc0c0fa --- /dev/null +++ b/app/Http/Option.php @@ -0,0 +1,17 @@ +name; + $options->$key = $option->value; + } + return $options; + } +} diff --git a/resources/views/components/e-icon.blade.php b/resources/views/components/e-icon.blade.php new file mode 100644 index 0000000..1a50ece --- /dev/null +++ b/resources/views/components/e-icon.blade.php @@ -0,0 +1,23 @@ +merge(['class' => 'size-8 p-1']) }}> + + + e + diff --git a/resources/views/components/pdf-icon.blade.php b/resources/views/components/pdf-icon.blade.php index 3fe1517..81a87fa 100644 --- a/resources/views/components/pdf-icon.blade.php +++ b/resources/views/components/pdf-icon.blade.php @@ -1,3 +1,3 @@ -merge(['class' => 'size-8 p-1']) }}>> +merge(['class' => 'size-8 p-1']) }}> diff --git a/resources/views/invoice/show.blade.php b/resources/views/invoice/show.blade.php index bf17129..4229406 100644 --- a/resources/views/invoice/show.blade.php +++ b/resources/views/invoice/show.blade.php @@ -1,11 +1,12 @@ -
-

+
+

{{ __('invoice.Invoice') }} {{ $invoice->number }}

-

- +

+ +

diff --git a/resources/views/xml/ToDos b/resources/views/xml/ToDos new file mode 100644 index 0000000..16be82d --- /dev/null +++ b/resources/views/xml/ToDos @@ -0,0 +1,4 @@ +resources/views/xml/invoice.blade.php + BuyerReference = Leitweg-ID (BT-10) + PaymentMeansCode = Bezahlarten + InvoicedQuantity unitCode="C62" diff --git a/resources/views/xml/invoice.blade.php b/resources/views/xml/invoice.blade.php new file mode 100644 index 0000000..fb3a96b --- /dev/null +++ b/resources/views/xml/invoice.blade.php @@ -0,0 +1,133 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + {{ $invoice->number }} + {{ \Carbon\Carbon::parse($invoice->created_at)->format('Y-m-d') }} + {{ \Carbon\Carbon::parse($invoice->created_at)->addDays(14)->format('Y-m-d') }} + {{ $invoice->type }} + EUR + 0 + + + {{ $options->email }} + + 0 + + + {{ $options->company_name }} + + + {{ $options->address }} + {{ $options->city }} + {{ $options->zip }} + + DE + + +@if (isset ($options->UStID)) + + {{ $options->UStID }} + + VAT + + + @endif + + {{ $options->tax_number }} + + FC + + + + {{ $options->company_name }} + + + {{ $options->representative }} + {{ $options->phone }} + {{ $options->email }} + + + + + + {{ $invoice->address->email }} + + {{ $invoice->address->name }} + + + {{ $invoice->address->address }} + {{ $invoice->address->city }} + {{ $invoice->address->zip }} + + DE + + + + {{ $invoice->address->name }} + + + + + 58 + + {{ str_replace(' ', '', $options->iban_1) }} + {{ $options->representative }} + + {{ $options->bic_1 }} + + + + + Zahlbar bis spätestens {{ \Carbon\Carbon::parse($invoice->created_at)->addDays(14)->format('d.m.Y') }}. + + + {{ $invoice->tax }} +@foreach($taxes as $tax_rate => $tax) + + {{ $tax['taxable'] }} + {{ $tax['tax'] }} + + S + {{ $tax_rate }} + + VAT + + + + @endforeach + + + {{ $invoice->sum - $invoice->tax }} + {{ $invoice->sum - $invoice->tax }} + {{ $invoice->sum }} + 0.00 + 0 + {{ $invoice->sum }} + +@foreach($invoice->items as $item) + + 1 + {{ $item->amount }} + {{ $item->amount * $item->price }} + + {{ $item->description }} + {{ $item->name }} + + S + {{ $item->tax }} + + VAT + + + + + {{ $item->price }} + + + @endforeach + diff --git a/routes/web.php b/routes/web.php index f70e08c..c57574f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ group(function () { Route::resource('/taxrate', TaxrateController::class)->only(['index', 'create', 'edit']); Route::resource('/invoice', InvoiceController::class)->only(['index', 'create', 'show', 'edit']); Route::get('/option', [OptionController::class, 'index'])->name('option.index'); - Route::get('/invoice/{id}/download', [PdfController::class, 'downloadInvoice'])->name('invoice.download'); + Route::get('/invoice/{id}/pdf-download', [PdfController::class, 'downloadInvoice'])->name('invoice.pdfDownload'); + Route::get('/invoice/{id}/xml-download', [EController::class, 'downloadInvoice'])->name('invoice.eDownload'); }); require __DIR__.'/auth.php';