30 lines
961 B
PHP
30 lines
961 B
PHP
<?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']);
|
|
|
|
}
|
|
}
|