fixed #40
This commit is contained in:
parent
9243ed34e3
commit
79b3467bdd
@ -20,11 +20,13 @@ use App\Models\Item\Item;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Notifications\Income\Invoice as Notification;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\Modules;
|
||||
use Date;
|
||||
use File;
|
||||
|
||||
class Invoices extends Controller
|
||||
{
|
||||
@ -407,6 +409,48 @@ class Invoices extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the PDF file of invoice.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function emailInvoice(Invoice $invoice)
|
||||
{
|
||||
$invoice = $this->prepareInvoice($invoice);
|
||||
|
||||
$html = view($invoice->template_path, compact('invoice'))->render();
|
||||
|
||||
$pdf = \App::make('dompdf.wrapper');
|
||||
$pdf->loadHTML($html);
|
||||
|
||||
$file = storage_path('app/temp/invoice_'.time().'.pdf');
|
||||
|
||||
$invoice->pdf_path = $file;
|
||||
|
||||
// Save the PDF file into temp folder
|
||||
$pdf->save($file);
|
||||
|
||||
// Notify the customer
|
||||
$invoice->customer->notify(new Notification($invoice));
|
||||
|
||||
// Delete temp file
|
||||
File::delete($file);
|
||||
|
||||
unset($invoice->paid);
|
||||
unset($invoice->template_path);
|
||||
unset($invoice->pdf_path);
|
||||
|
||||
// Mark invoice as sent
|
||||
$invoice->invoice_status_code = 'sent';
|
||||
$invoice->save();
|
||||
|
||||
flash(trans('invoices.messages.email_sent'))->success();
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the invoice.
|
||||
*
|
||||
@ -416,19 +460,7 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function printInvoice(Invoice $invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$invoice->paid = $paid;
|
||||
|
||||
$invoice->template_path = 'incomes.invoices.invoice';
|
||||
|
||||
event(new InvoicePrinting($invoice));
|
||||
$invoice = $this->prepareInvoice($invoice);
|
||||
|
||||
return view($invoice->template_path, compact('invoice'));
|
||||
}
|
||||
@ -442,25 +474,15 @@ class Invoices extends Controller
|
||||
*/
|
||||
public function pdfInvoice(Invoice $invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$invoice->paid = $paid;
|
||||
|
||||
$invoice->template_path = 'incomes.invoices.invoice';
|
||||
|
||||
event(new InvoicePrinting($invoice));
|
||||
$invoice = $this->prepareInvoice($invoice);
|
||||
|
||||
$html = view($invoice->template_path, compact('invoice'))->render();
|
||||
|
||||
$pdf = \App::make('dompdf.wrapper');
|
||||
$pdf->loadHTML($html);
|
||||
|
||||
//$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
$file_name = 'invoice_'.time().'.pdf';
|
||||
|
||||
return $pdf->download($file_name);
|
||||
@ -591,6 +613,25 @@ class Invoices extends Controller
|
||||
return redirect('incomes/invoices');
|
||||
}
|
||||
|
||||
protected function prepareInvoice(Invoice $invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
foreach ($invoice->payments as $item) {
|
||||
$item->default_currency_code = $invoice->currency_code;
|
||||
|
||||
$paid += $item->getDynamicConvertedAmount();
|
||||
}
|
||||
|
||||
$invoice->paid = $paid;
|
||||
|
||||
$invoice->template_path = 'incomes.invoices.invoice';
|
||||
|
||||
event(new InvoicePrinting($invoice));
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
protected function addTotals($invoice, $request, $taxes, $sub_total, $tax_total)
|
||||
{
|
||||
$sort_order = 1;
|
||||
|
@ -46,9 +46,18 @@ class Invoice extends Notification implements ShouldQueue
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage)
|
||||
->line('You are receiving this email because you have an upcoming ' . money($this->invoice->amount, $this->invoice->currency_code, true) . ' invoice to ' . $this->invoice->customer->name . ' customer.')
|
||||
->action('Pay Now', url('customers/invoices', $this->invoice->id, true));
|
||||
$message = (new MailMessage)
|
||||
->line(trans('invoices.notification.message', ['amount' => money($this->invoice->amount, $this->invoice->currency_code, true), 'customer' => $this->invoice->customer->name]))
|
||||
->action(trans('invoices.notification.button'), url('customers/invoices', $this->invoice->id, true));
|
||||
|
||||
// Attach the PDF file if available
|
||||
if (isset($this->invoice->pdf_path)) {
|
||||
$message->attach($this->invoice->pdf_path, [
|
||||
'mime' => 'application/pdf',
|
||||
]);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,13 @@ return [
|
||||
],
|
||||
|
||||
'messages' => [
|
||||
'email_sent' => 'Invoice email has been sent successfully!',
|
||||
'marked_sent' => 'Invoice marked as sent successfully!',
|
||||
],
|
||||
|
||||
'notification' => [
|
||||
'message' => 'You are receiving this email because you have an upcoming :amount invoice to :customer customer.',
|
||||
'button' => 'Pay Now',
|
||||
],
|
||||
|
||||
];
|
||||
|
@ -161,7 +161,7 @@
|
||||
@permission('update-incomes-invoices')
|
||||
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/sent') }}">{{ trans('invoices.mark_sent') }}</a></li>
|
||||
@endpermission
|
||||
<li><a href="#" id="button-email">{{ trans('invoices.send_mail') }}</a></li>
|
||||
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/email') }}">{{ trans('invoices.send_mail') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="{{ url('incomes/invoices/' . $invoice->id . '/pdf') }}">{{ trans('invoices.download_pdf') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user