Create invoices in XML Format.
This commit is contained in:
29
app/Http/Controllers/EController.php
Normal file
29
app/Http/Controllers/EController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Option;
|
||||
use App\Models\Invoice;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class EController extends Controller
|
||||
{
|
||||
public function downloadInvoice(int $id): StreamedResponse
|
||||
{
|
||||
$invoice = Invoice::find($id);
|
||||
|
||||
$taxes = [];
|
||||
foreach ($invoice->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']);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user