Add email template..
This commit is contained in:
parent
19a417791e
commit
43e31fd647
@ -15,6 +15,7 @@ use App\Models\Banking\Transaction;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Notifications\Sale\Revenue as Notification;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Utilities\Modules;
|
||||
|
56
app/Listeners/Update/V21/Version2118.php
Normal file
56
app/Listeners/Update/V21/Version2118.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 Version2118 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '2.1.18';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->skipThisUpdate($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->updateEmailTemplate();
|
||||
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
}
|
||||
|
||||
protected function updateCompanies()
|
||||
{
|
||||
$company_id = company_id();
|
||||
|
||||
$companies = Company::cursor();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$company->makeCurrent();
|
||||
|
||||
EmailTemplate::create([
|
||||
'company_id' => $company->id,
|
||||
'alias' => 'revenue_new_customer',
|
||||
'class' => 'App\Notifications\Sale\Revenue',
|
||||
'name' => 'settings.email.templates.revenue_new_customer',
|
||||
'subject' => trans('email_templates.revenue_new_customer.subject'),
|
||||
'body' => trans('email_templates.revenue_new_customer.body'),
|
||||
]);
|
||||
}
|
||||
|
||||
company($company_id)->makeCurrent();
|
||||
}
|
||||
}
|
121
app/Notifications/Sale/Revenue.php
Normal file
121
app/Notifications/Sale/Revenue.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Sale;
|
||||
|
||||
use App\Abstracts\Notification;
|
||||
use App\Models\Common\EmailTemplate;
|
||||
use App\Traits\Transactions;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class Revenue extends Notification
|
||||
{
|
||||
use Transactions;
|
||||
|
||||
/**
|
||||
* The revenue model.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $revenue;
|
||||
|
||||
/**
|
||||
* The email template.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template;
|
||||
|
||||
/**
|
||||
* Should attach pdf or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $attach_pdf;
|
||||
|
||||
/**
|
||||
* Create a notification instance.
|
||||
*
|
||||
* @param object $revenue
|
||||
* @param object $template_alias
|
||||
* @param object $attach_pdf
|
||||
*/
|
||||
public function __construct($revenue = null, $template_alias = null, $attach_pdf = false)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->revenue = $revenue;
|
||||
$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->storeDocumentPdfAndGetPath($this->revenue), [
|
||||
'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,
|
||||
'revenue_id' => $this->revenue->id,
|
||||
'customer_name' => $this->revenue->contact->name,
|
||||
'amount' => $this->revenue->amount,
|
||||
'revenue_date' => company_date($this->revenue->paid_at),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
{
|
||||
return [
|
||||
'{revenue_amount}',
|
||||
'{revenue_date}',
|
||||
'{revenue_guest_link}',
|
||||
'{revenue_admin_link}',
|
||||
'{revenue_portal_link}',
|
||||
'{customer_name}',
|
||||
'{company_name}',
|
||||
'{company_email}',
|
||||
'{company_tax_number}',
|
||||
'{company_phone}',
|
||||
'{company_address}',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTagsReplacement()
|
||||
{
|
||||
return [
|
||||
money($this->revenue->amount, $this->revenue->currency_code, true),
|
||||
company_date($this->revenue->paid_at),
|
||||
URL::signedRoute('signed.payments.show', [$this->revenue->id]),
|
||||
route('revenues.show', $this->revenue->id),
|
||||
route('portal.payments.show', $this->revenue->id),
|
||||
$this->revenue->contact->name,
|
||||
$this->revenue->company->name,
|
||||
$this->revenue->company->email,
|
||||
$this->revenue->company->tax_number,
|
||||
$this->revenue->company->phone,
|
||||
nl2br(trim($this->revenue->company->address)),
|
||||
];
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ class Event extends Provider
|
||||
'App\Listeners\Update\V21\Version2114',
|
||||
'App\Listeners\Update\V21\Version2116',
|
||||
'App\Listeners\Update\V21\Version2117',
|
||||
'App\Listeners\Update\V21\Version2118',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
@ -72,6 +72,11 @@ class EmailTemplates extends Seeder
|
||||
'class' => 'App\Notifications\Purchase\Bill',
|
||||
'name' => 'settings.email.templates.bill_recur_admin',
|
||||
],
|
||||
[
|
||||
'alias' => 'revenue_new_customer',
|
||||
'class' => 'App\Notifications\Sale\Revenue',
|
||||
'name' => 'settings.email.templates.revenue_new_customer',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($templates as $template) {
|
||||
|
@ -47,4 +47,8 @@ return [
|
||||
'body' => 'Hello,<br /><br />Based on {vendor_name} recurring circle, <strong>{bill_number}</strong> bill has been automatically created.<br /><br />You can see the bill details from the following link: <a href="{bill_admin_link}">{bill_number}</a>.<br /><br />Best Regards,<br />{company_name}',
|
||||
],
|
||||
|
||||
'revenue_new_customer' => [
|
||||
'subject' => '{revenue_date} payment created',
|
||||
'body' => 'Dear {customer_name},<br /><br />We have prepared the following payment. <br /><br />You can see the invoice details and proceed with the payment from the following link: <a href="{revenue_guest_link}">{revenue_date}</a>.<br /><br />Feel free to contact us for any question.<br /><br />Best Regards,<br />{company_name}',
|
||||
],
|
||||
];
|
||||
|
10
resources/views/sales/revenues/print_default.blade.php
Normal file
10
resources/views/sales/revenues/print_default.blade.php
Normal file
@ -0,0 +1,10 @@
|
||||
@extends('layouts.print')
|
||||
|
||||
@section('title', trans_choice('general.revenues', 1) . ': ' . $revenue->id)
|
||||
|
||||
@section('content')
|
||||
<x-transactions.template.ddefault
|
||||
type="revenue"
|
||||
:transaction="$revenue"
|
||||
/>
|
||||
@endsection
|
Loading…
x
Reference in New Issue
Block a user