Merge pull request #1413 from denisdulici/master

Added invoice/bill number to pdf filename
This commit is contained in:
Denis Duliçi 2020-04-18 17:20:02 +03:00 committed by GitHub
commit 84631d1f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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());
}
}

View File

@ -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());
}
}