diff --git a/app/Http/Controllers/Purchases/Bills.php b/app/Http/Controllers/Purchases/Bills.php index 9330d53c1..4660f5753 100644 --- a/app/Http/Controllers/Purchases/Bills.php +++ b/app/Http/Controllers/Purchases/Bills.php @@ -343,7 +343,7 @@ class Bills extends Controller $pdf = app('dompdf.wrapper'); $pdf->loadHTML($html); - $file_name = 'bill_' . time() . '.pdf'; + $file_name = $this->getBillFileName($bill); return $pdf->download($file_name); } diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index 69c608611..aaf7834a0 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -332,7 +332,9 @@ class Invoices extends Controller $pdf = app('dompdf.wrapper'); $pdf->loadHTML($html); - $file = storage_path('app/temp/invoice_'.time().'.pdf'); + $file_name = $this->getInvoiceFileName($invoice); + + $file = storage_path('app/temp/' . $file_name); $invoice->pdf_path = $file; @@ -394,7 +396,7 @@ class Invoices extends Controller //$pdf->setPaper('A4', 'portrait'); - $file_name = 'invoice_'.time().'.pdf'; + $file_name = $this->getInvoiceFileName($invoice); return $pdf->download($file_name); } diff --git a/app/Traits/Purchases.php b/app/Traits/Purchases.php index e5189d469..7532c698a 100644 --- a/app/Traits/Purchases.php +++ b/app/Traits/Purchases.php @@ -2,6 +2,8 @@ namespace App\Traits; +use Illuminate\Support\Str; + trait Purchases { /** @@ -58,4 +60,14 @@ trait Purchases return $statuses; } + + public function getBillFileName($bill, $separator = '-', $extension = 'pdf') + { + return $this->getSafeBillNumber($bill, $separator) . $separator . time() . '.' . $extension; + } + + public function getSafeBillNumber($bill, $separator = '-') + { + return Str::slug($bill->bill_number, $separator, language()->getShortCode()); + } } diff --git a/app/Traits/Sales.php b/app/Traits/Sales.php index abc9e12a3..d20020f30 100644 --- a/app/Traits/Sales.php +++ b/app/Traits/Sales.php @@ -2,6 +2,8 @@ namespace App\Traits; +use Illuminate\Support\Str; + trait Sales { /** @@ -60,4 +62,14 @@ trait Sales return $statuses; } + + public function getInvoiceFileName($invoice, $separator = '-', $extension = 'pdf') + { + return $this->getSafeInvoiceNumber($invoice, $separator) . $separator . time() . '.' . $extension; + } + + public function getSafeInvoiceNumber($invoice, $separator = '-') + { + return Str::slug($invoice->invoice_number, $separator, language()->getShortCode()); + } }