Transaction event and notification changes..
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Events\Transaction;
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Events\Transaction;
|
namespace App\Events\Banking;
|
||||||
|
|
||||||
use App\Abstracts\Event;
|
use App\Abstracts\Event;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ class Payments extends Controller
|
|||||||
*/
|
*/
|
||||||
public function printPayment(Transaction $payment, Request $request)
|
public function printPayment(Transaction $payment, Request $request)
|
||||||
{
|
{
|
||||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||||
|
|
||||||
$revenue = $payment;
|
$revenue = $payment;
|
||||||
$view = view($payment->template_path, compact('revenue'));
|
$view = view($payment->template_path, compact('revenue'));
|
||||||
@@ -82,7 +82,7 @@ class Payments extends Controller
|
|||||||
*/
|
*/
|
||||||
public function pdfPayment(Transaction $payment, Request $request)
|
public function pdfPayment(Transaction $payment, Request $request)
|
||||||
{
|
{
|
||||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||||
|
|
||||||
$currency_style = true;
|
$currency_style = true;
|
||||||
|
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ class Payments extends Controller
|
|||||||
// Notify the customer
|
// Notify the customer
|
||||||
$payment->contact->notify(new Notification($payment, 'payment_new_customer', true));
|
$payment->contact->notify(new Notification($payment, 'payment_new_customer', true));
|
||||||
|
|
||||||
event(new \App\Events\Transaction\TransactionSent($payment));
|
event(new \App\Events\Banking\TransactionSent($payment));
|
||||||
|
|
||||||
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.payments', 1)]))->success();
|
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.payments', 1)]))->success();
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ class Payments extends Controller
|
|||||||
*/
|
*/
|
||||||
public function printPayment(Transaction $payment)
|
public function printPayment(Transaction $payment)
|
||||||
{
|
{
|
||||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||||
|
|
||||||
$view = view($payment->template_path, compact('payment'));
|
$view = view($payment->template_path, compact('payment'));
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ class Payments extends Controller
|
|||||||
*/
|
*/
|
||||||
public function pdfPayment(Transaction $payment)
|
public function pdfPayment(Transaction $payment)
|
||||||
{
|
{
|
||||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||||
|
|
||||||
$currency_style = true;
|
$currency_style = true;
|
||||||
|
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ class Revenues extends Controller
|
|||||||
// Notify the customer
|
// Notify the customer
|
||||||
$revenue->contact->notify(new Notification($revenue, 'revenue_new_customer', true));
|
$revenue->contact->notify(new Notification($revenue, 'revenue_new_customer', true));
|
||||||
|
|
||||||
event(new \App\Events\Transaction\TransactionSent($revenue));
|
event(new \App\Events\Banking\TransactionSent($revenue));
|
||||||
|
|
||||||
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.revenues', 1)]))->success();
|
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.revenues', 1)]))->success();
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ class Revenues extends Controller
|
|||||||
*/
|
*/
|
||||||
public function printRevenue(Transaction $revenue)
|
public function printRevenue(Transaction $revenue)
|
||||||
{
|
{
|
||||||
event(new \App\Events\Transaction\TransactionPrinting($revenue));
|
event(new \App\Events\Banking\TransactionPrinting($revenue));
|
||||||
|
|
||||||
$view = view($revenue->template_path, compact('revenue'));
|
$view = view($revenue->template_path, compact('revenue'));
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ class Revenues extends Controller
|
|||||||
*/
|
*/
|
||||||
public function pdfRevenue(Transaction $revenue)
|
public function pdfRevenue(Transaction $revenue)
|
||||||
{
|
{
|
||||||
event(new \App\Events\Transaction\TransactionPrinting($revenue));
|
event(new \App\Events\Banking\TransactionPrinting($revenue));
|
||||||
|
|
||||||
$currency_style = true;
|
$currency_style = true;
|
||||||
|
|
||||||
|
|||||||
117
app/Notifications/Purchase/Payment.php
Normal file
117
app/Notifications/Purchase/Payment.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Purchase;
|
||||||
|
|
||||||
|
use App\Abstracts\Notification;
|
||||||
|
use App\Models\Common\EmailTemplate;
|
||||||
|
use App\Traits\Transactions;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
|
||||||
|
class Payment extends Notification
|
||||||
|
{
|
||||||
|
use Transactions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payment model.
|
||||||
|
*
|
||||||
|
* @var object
|
||||||
|
*/
|
||||||
|
public $payment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The email template.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should attach pdf or not.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $attach_pdf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a notification instance.
|
||||||
|
*
|
||||||
|
* @param object $payment
|
||||||
|
* @param object $template_alias
|
||||||
|
* @param object $attach_pdf
|
||||||
|
*/
|
||||||
|
public function __construct($payment = null, $template_alias = null, $attach_pdf = false)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->payment = $payment;
|
||||||
|
$this->template = EmailTemplate::alias($template_alias)->first();
|
||||||
|
$this->attach_pdf = $attach_pdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
$message = $this->initMessage();
|
||||||
|
|
||||||
|
// Attach the PDF file
|
||||||
|
if ($this->attach_pdf) {
|
||||||
|
$message->attach($this->storeTransactionPdfAndGetPath($this->payment), [
|
||||||
|
'mime' => 'application/pdf',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'template_alias' => $this->template->alias,
|
||||||
|
'payment_id' => $this->payment->id,
|
||||||
|
'customer_name' => $this->payment->contact->name,
|
||||||
|
'amount' => $this->payment->amount,
|
||||||
|
'payment_date' => company_date($this->payment->paid_at),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'{payment_amount}',
|
||||||
|
'{payment_date}',
|
||||||
|
'{payment_admin_link}',
|
||||||
|
'{customer_name}',
|
||||||
|
'{company_name}',
|
||||||
|
'{company_email}',
|
||||||
|
'{company_tax_number}',
|
||||||
|
'{company_phone}',
|
||||||
|
'{company_address}',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTagsReplacement()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
money($this->payment->amount, $this->payment->currency_code, true),
|
||||||
|
company_date($this->payment->paid_at),
|
||||||
|
route('payments.show', $this->payment->id),
|
||||||
|
$this->payment->contact->name,
|
||||||
|
$this->payment->company->name,
|
||||||
|
$this->payment->company->email,
|
||||||
|
$this->payment->company->tax_number,
|
||||||
|
$this->payment->company->phone,
|
||||||
|
nl2br(trim($this->payment->company->address)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,7 +60,7 @@ class Revenue extends Notification
|
|||||||
|
|
||||||
// Attach the PDF file
|
// Attach the PDF file
|
||||||
if ($this->attach_pdf) {
|
if ($this->attach_pdf) {
|
||||||
$message->attach($this->storeDocumentPdfAndGetPath($this->revenue), [
|
$message->attach($this->storeTransactionPdfAndGetPath($this->revenue), [
|
||||||
'mime' => 'application/pdf',
|
'mime' => 'application/pdf',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,4 +88,24 @@ trait Transactions
|
|||||||
|
|
||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function storeTransactionPdfAndGetPath($transaction)
|
||||||
|
{
|
||||||
|
event(new \App\Events\Banking\TransactionPrinting($transaction));
|
||||||
|
|
||||||
|
$view = view($transaction->template_path, ['revenue' => $transaction, 'transaction' => $transaction])->render();
|
||||||
|
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
|
||||||
|
|
||||||
|
$pdf = app('dompdf.wrapper');
|
||||||
|
$pdf->loadHTML($html);
|
||||||
|
|
||||||
|
$file_name = $this->getTransactionFileName($transaction);
|
||||||
|
|
||||||
|
$pdf_path = storage_path('app/temp/' . $file_name);
|
||||||
|
|
||||||
|
// Save the PDF file into temp folder
|
||||||
|
$pdf->save($pdf_path);
|
||||||
|
|
||||||
|
return $pdf_path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user