Merge pull request #2168 from cuneytsenturk/master
Payment send mail notification add
This commit is contained in:
commit
0bdaea1417
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Transaction;
|
||||
namespace App\Events\Banking;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Transaction;
|
||||
namespace App\Events\Banking;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
@ -65,7 +65,7 @@ class Payments extends Controller
|
||||
*/
|
||||
public function printPayment(Transaction $payment, Request $request)
|
||||
{
|
||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
||||
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||
|
||||
$revenue = $payment;
|
||||
$view = view($payment->template_path, compact('revenue'));
|
||||
@ -82,7 +82,7 @@ class Payments extends Controller
|
||||
*/
|
||||
public function pdfPayment(Transaction $payment, Request $request)
|
||||
{
|
||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
||||
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||
|
||||
$currency_style = true;
|
||||
|
||||
|
@ -275,7 +275,7 @@ class Payments extends Controller
|
||||
// Notify the customer
|
||||
$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();
|
||||
|
||||
@ -291,7 +291,7 @@ class Payments extends Controller
|
||||
*/
|
||||
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'));
|
||||
|
||||
@ -307,7 +307,7 @@ class Payments extends Controller
|
||||
*/
|
||||
public function pdfPayment(Transaction $payment)
|
||||
{
|
||||
event(new \App\Events\Transaction\TransactionPrinting($payment));
|
||||
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||
|
||||
$currency_style = true;
|
||||
|
||||
|
@ -276,7 +276,7 @@ class Revenues extends Controller
|
||||
// Notify the customer
|
||||
$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();
|
||||
|
||||
@ -292,7 +292,7 @@ class Revenues extends Controller
|
||||
*/
|
||||
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'));
|
||||
|
||||
@ -308,7 +308,7 @@ class Revenues extends Controller
|
||||
*/
|
||||
public function pdfRevenue(Transaction $revenue)
|
||||
{
|
||||
event(new \App\Events\Transaction\TransactionPrinting($revenue));
|
||||
event(new \App\Events\Banking\TransactionPrinting($revenue));
|
||||
|
||||
$currency_style = true;
|
||||
|
||||
|
56
app/Listeners/Update/V21/Version2119.php
Normal file
56
app/Listeners/Update/V21/Version2119.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Update\V21;
|
||||
|
||||
use App\Abstracts\Listeners\Update as Listener;
|
||||
use App\Events\Install\UpdateFinished as Event;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Common\EmailTemplate;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class Version21199 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '2.1.19';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->skipThisUpdate($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->updateEmailTemplate();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
}
|
||||
|
||||
protected function updateEmailTemplate()
|
||||
{
|
||||
$company_id = company_id();
|
||||
|
||||
$companies = Company::cursor();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$company->makeCurrent();
|
||||
|
||||
EmailTemplate::create([
|
||||
'company_id' => $company->id,
|
||||
'alias' => 'payment_new_vendor',
|
||||
'class' => 'App\Notifications\Purchase\Payment',
|
||||
'name' => 'settings.email.templates.payment_new_vendor',
|
||||
'subject' => trans('email_templates.payment_new_vendor.subject'),
|
||||
'body' => trans('email_templates.payment_new_vendor.body'),
|
||||
]);
|
||||
}
|
||||
|
||||
company($company_id)->makeCurrent();
|
||||
}
|
||||
}
|
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,
|
||||
'vendor_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}',
|
||||
'{vendor_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
|
||||
if ($this->attach_pdf) {
|
||||
$message->attach($this->storeDocumentPdfAndGetPath($this->revenue), [
|
||||
$message->attach($this->storeTransactionPdfAndGetPath($this->revenue), [
|
||||
'mime' => 'application/pdf',
|
||||
]);
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ class Event extends Provider
|
||||
'App\Listeners\Update\V21\Version2116',
|
||||
'App\Listeners\Update\V21\Version2117',
|
||||
'App\Listeners\Update\V21\Version2118',
|
||||
'App\Listeners\Update\V21\Version2119',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
@ -88,4 +88,24 @@ trait Transactions
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,11 @@ class EmailTemplates extends Seeder
|
||||
'class' => 'App\Notifications\Sale\Revenue',
|
||||
'name' => 'settings.email.templates.revenue_new_customer',
|
||||
],
|
||||
[
|
||||
'alias' => 'payment_new_vendor',
|
||||
'class' => 'App\Notifications\Purchase\Payment',
|
||||
'name' => 'settings.email.templates.payment_new_vendor',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($templates as $template) {
|
||||
|
@ -51,4 +51,9 @@ return [
|
||||
'subject' => '{revenue_date} payment created',
|
||||
'body' => 'Dear {customer_name},<br /><br />We have prepared the following payment. <br /><br />You can see the payment details from the following link: <a href="{revenue_guest_link}">{revenue_date}</a>.<br /><br />Feel free to contact us with any questions..<br /><br />Best Regards,<br />{company_name}',
|
||||
],
|
||||
|
||||
'payment_new_vendor' => [
|
||||
'subject' => '{revenue_date} payment created',
|
||||
'body' => 'Dear {vendor_name},<br /><br />We have prepared the following payment. <br /><br />You can see the payment details from the following link: <a href="{payment_admin_link}">{payment_date}</a>.<br /><br />Feel free to contact us with any questions..<br /><br />Best Regards,<br />{company_name}',
|
||||
],
|
||||
];
|
||||
|
@ -3,7 +3,7 @@
|
||||
@section('title', trans('payments.payment_made'))
|
||||
|
||||
@section('new_button')
|
||||
<x-transactions.show.top-buttons type="expense" :transaction="$payment" hide-button-share hide-button-email />
|
||||
<x-transactions.show.top-buttons type="expense" :transaction="$payment" hide-button-share />
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
Loading…
x
Reference in New Issue
Block a user