Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

akaunting/akaunting

9348 stars
4 code files
View akaunting/akaunting on GitHub

composer.json

Open in GitHub
{
"name": "akaunting/akaunting",
// ...
"require": {
"php": "^7.3.0",
"ext-bcmath": "*",
"akaunting/laravel-firewall": "^1.2",
// ...
 
"barryvdh/laravel-dompdf": "0.*",
 
// ...
},
}

app/Http/Controllers/Portal/Invoices.php

Open in GitHub
// Controller method to download the PDF invoice
// It builds the PDF on the fly from the Blade View
 
// Trait "Documents" is important, see its content below
use App\Traits\Documents;
 
class Invoices extends Controller
{
use DateTime, Currencies, Documents, Uploads;
 
public function pdfInvoice(Document $invoice, Request $request)
{
$view = view($invoice->template_path, compact('invoice', 'currency_style'))->render();
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
 
$pdf = app('dompdf.wrapper');
$pdf->loadHTML($html);
 
$file_name = $this->getDocumentFileName($invoice);
 
return $pdf->download($file_name);
}
}

app/Traits/Documents.php

Open in GitHub
namespace App\Traits;
 
trait Documents
{
// ... other methods
 
public function getDocumentFileName(Document $document, string $separator = '-', string $extension = 'pdf'): string
{
return $this->getSafeDocumentNumber($document, $separator) . $separator . time() . '.' . $extension;
}
 
public function getSafeDocumentNumber(Document $document, string $separator = '-'): string
{
return Str::slug($document->document_number, $separator, language()->getShortCode());
}
}

routes/portal.php

Open in GitHub
Route::group(['as' => 'portal.'], function () {
// ... other routes
Route::get('invoices/{invoice}/pdf', 'Portal\Invoices@pdfInvoice')->name('invoices.pdf');
});

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.