mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 07:34:34 -04:00
Add Quote Approved Notification
This commit is contained in:
parent
050ebb8141
commit
4e127fab2d
86
app/Listeners/Quote/QuoteApprovedNotification.php
Normal file
86
app/Listeners/Quote/QuoteApprovedNotification.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Quote Ninja (https://quoteninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/quoteninja/quoteninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Quote Ninja LLC (https://quoteninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Listeners\Quote;
|
||||||
|
|
||||||
|
use App\Jobs\Mail\NinjaMailer;
|
||||||
|
use App\Jobs\Mail\NinjaMailerJob;
|
||||||
|
use App\Jobs\Mail\NinjaMailerObject;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Mail\Admin\EntityCreatedObject;
|
||||||
|
use App\Mail\Admin\QuoteApprovedObject;
|
||||||
|
use App\Notifications\Admin\EntitySentNotification;
|
||||||
|
use App\Utils\Traits\Notifications\UserNotifies;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class QuoteApprovedNotification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use UserNotifies;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param object $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
MultiDB::setDb($event->company->db);
|
||||||
|
|
||||||
|
$first_notification_sent = true;
|
||||||
|
|
||||||
|
$quote = $event->quote;
|
||||||
|
|
||||||
|
$nmo = new NinjaMailerObject;
|
||||||
|
$nmo->mailable = new NinjaMailer( (new QuoteApprovedObject($quote, $event->company))->build() );
|
||||||
|
$nmo->company = $quote->company;
|
||||||
|
$nmo->settings = $quote->company->settings;
|
||||||
|
|
||||||
|
/* We loop through each user and determine whether they need to be notified */
|
||||||
|
foreach ($event->company->company_users as $company_user) {
|
||||||
|
|
||||||
|
/* The User */
|
||||||
|
$user = $company_user->user;
|
||||||
|
|
||||||
|
if(!$user)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* This is only here to handle the alternate message channels - ie Slack */
|
||||||
|
// $notification = new EntitySentNotification($event->invitation, 'quote');
|
||||||
|
|
||||||
|
/* Returns an array of notification methods */
|
||||||
|
$methods = $this->findUserNotificationTypes($quote->invitations()->first(), $company_user, 'quote', ['all_notifications', 'quote_approved', 'quote_approved_all']);
|
||||||
|
|
||||||
|
/* If one of the methods is email then we fire the EntitySentMailer */
|
||||||
|
if (($key = array_search('mail', $methods)) !== false) {
|
||||||
|
unset($methods[$key]);
|
||||||
|
|
||||||
|
|
||||||
|
$nmo->to_user = $user;
|
||||||
|
|
||||||
|
NinjaMailerJob::dispatch($nmo);
|
||||||
|
|
||||||
|
/* This prevents more than one notification being sent */
|
||||||
|
$first_notification_sent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override the methods in the Notification Class */
|
||||||
|
// $notification->method = $methods;
|
||||||
|
|
||||||
|
// Notify on the alternate channels
|
||||||
|
// $user->notify($notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
103
app/Mail/Admin/QuoteApprovedObject.php
Normal file
103
app/Mail/Admin/QuoteApprovedObject.php
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Mail\Admin;
|
||||||
|
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Quote;
|
||||||
|
use App\Utils\Ninja;
|
||||||
|
use App\Utils\Number;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
class QuoteApprovedObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public $quote;
|
||||||
|
|
||||||
|
public $company;
|
||||||
|
|
||||||
|
public $settings;
|
||||||
|
|
||||||
|
public function __construct(Quote $quote, Company $company)
|
||||||
|
{
|
||||||
|
$this->quote = $quote;
|
||||||
|
$this->company = $company;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
|
if(!$this->quote)
|
||||||
|
return;
|
||||||
|
|
||||||
|
App::forgetInstance('translator');
|
||||||
|
/* Init a new copy of the translator*/
|
||||||
|
$t = app('translator');
|
||||||
|
/* Set the locale*/
|
||||||
|
App::setLocale($this->company->getLocale());
|
||||||
|
/* Set customized translations _NOW_ */
|
||||||
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||||
|
|
||||||
|
$mail_obj = new stdClass;
|
||||||
|
$mail_obj->amount = $this->getAmount();
|
||||||
|
$mail_obj->subject = $this->getSubject();
|
||||||
|
$mail_obj->data = $this->getData();
|
||||||
|
$mail_obj->markdown = 'email.admin.generic';
|
||||||
|
$mail_obj->tag = $this->company->company_key;
|
||||||
|
|
||||||
|
return $mail_obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getAmount()
|
||||||
|
{
|
||||||
|
return Number::formatMoney($this->quote->amount, $this->quote->client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSubject()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
ctrans(
|
||||||
|
"texts.notification_quote_approved_subject",
|
||||||
|
[
|
||||||
|
'client' => $this->quote->client->present()->name(),
|
||||||
|
'invoice' => $this->quote->number,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getData()
|
||||||
|
{
|
||||||
|
$settings = $this->quote->client->getMergedSettings();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'title' => $this->getSubject(),
|
||||||
|
'message' => ctrans(
|
||||||
|
"texts.notification_quote_approved",
|
||||||
|
[
|
||||||
|
'amount' => $this->getAmount(),
|
||||||
|
'client' => $this->quote->client->present()->name(),
|
||||||
|
'invoice' => $this->quote->number,
|
||||||
|
]
|
||||||
|
),
|
||||||
|
'url' => $this->quote->invitations->first()->getAdminLink(),
|
||||||
|
'button' => ctrans("texts.view_quote"),
|
||||||
|
'signature' => $settings->email_signature,
|
||||||
|
'logo' => $this->company->present()->logo(),
|
||||||
|
'settings' => $settings,
|
||||||
|
'whitelabel' => $this->company->account->isPaid() ? true : false,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@ -222,6 +222,9 @@ class RecurringInvoice extends BaseModel
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlog("frequency = $this->frequency_id");
|
||||||
|
nlog("frequency = $this->next_send_date");
|
||||||
|
|
||||||
$offset = $this->client->timezone_offset();
|
$offset = $this->client->timezone_offset();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -171,6 +171,7 @@ use App\Listeners\Payment\PaymentEmailedActivity;
|
|||||||
use App\Listeners\Payment\PaymentNotification;
|
use App\Listeners\Payment\PaymentNotification;
|
||||||
use App\Listeners\Payment\PaymentRestoredActivity;
|
use App\Listeners\Payment\PaymentRestoredActivity;
|
||||||
use App\Listeners\Quote\QuoteApprovedActivity;
|
use App\Listeners\Quote\QuoteApprovedActivity;
|
||||||
|
use App\Listeners\Quote\QuoteApprovedNotification;
|
||||||
use App\Listeners\Quote\QuoteApprovedWebhook;
|
use App\Listeners\Quote\QuoteApprovedWebhook;
|
||||||
use App\Listeners\Quote\QuoteArchivedActivity;
|
use App\Listeners\Quote\QuoteArchivedActivity;
|
||||||
use App\Listeners\Quote\QuoteCreatedNotification;
|
use App\Listeners\Quote\QuoteCreatedNotification;
|
||||||
@ -437,6 +438,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
ReachWorkflowSettings::class,
|
ReachWorkflowSettings::class,
|
||||||
QuoteApprovedActivity::class,
|
QuoteApprovedActivity::class,
|
||||||
QuoteApprovedWebhook::class,
|
QuoteApprovedWebhook::class,
|
||||||
|
QuoteApprovedNotification::class,
|
||||||
],
|
],
|
||||||
QuoteWasCreated::class => [
|
QuoteWasCreated::class => [
|
||||||
CreatedQuoteActivity::class,
|
CreatedQuoteActivity::class,
|
||||||
|
@ -75,7 +75,7 @@ class SubscriptionService
|
|||||||
$recurring_invoice = $this->convertInvoiceToRecurring($payment_hash->payment->client_id);
|
$recurring_invoice = $this->convertInvoiceToRecurring($payment_hash->payment->client_id);
|
||||||
$recurring_invoice_repo = new RecurringInvoiceRepository();
|
$recurring_invoice_repo = new RecurringInvoiceRepository();
|
||||||
|
|
||||||
$recurring_invoice->next_send_date = now();
|
$recurring_invoice->next_send_date = now()->format('Y-m-d');
|
||||||
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
|
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
|
||||||
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
||||||
$recurring_invoice->auto_bill = $this->subscription->auto_bill;
|
$recurring_invoice->auto_bill = $this->subscription->auto_bill;
|
||||||
@ -594,7 +594,7 @@ class SubscriptionService
|
|||||||
|
|
||||||
$recurring_invoice = $this->convertInvoiceToRecurring($old_recurring_invoice->client_id);
|
$recurring_invoice = $this->convertInvoiceToRecurring($old_recurring_invoice->client_id);
|
||||||
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
|
$recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice);
|
||||||
$recurring_invoice->next_send_date = now();
|
$recurring_invoice->next_send_date = now()->format('Y-m-d');
|
||||||
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
||||||
|
|
||||||
/* Start the recurring service */
|
/* Start the recurring service */
|
||||||
@ -722,7 +722,9 @@ class SubscriptionService
|
|||||||
$recurring_invoice->auto_bill = $client->getSetting('auto_bill');
|
$recurring_invoice->auto_bill = $client->getSetting('auto_bill');
|
||||||
$recurring_invoice->auto_bill_enabled = $this->setAutoBillFlag($recurring_invoice->auto_bill);
|
$recurring_invoice->auto_bill_enabled = $this->setAutoBillFlag($recurring_invoice->auto_bill);
|
||||||
$recurring_invoice->due_date_days = 'terms';
|
$recurring_invoice->due_date_days = 'terms';
|
||||||
|
$recurring_invoice->next_send_date = now()->format('Y-m-d');
|
||||||
|
$recurring_invoice->next_send_date = $recurring_invoice->nextSendDate();
|
||||||
|
|
||||||
return $recurring_invoice;
|
return $recurring_invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1027,7 +1029,7 @@ class SubscriptionService
|
|||||||
'subscription' => $this->subscription->hashed_id,
|
'subscription' => $this->subscription->hashed_id,
|
||||||
'recurring_invoice' => $recurring_invoice_hashed_id,
|
'recurring_invoice' => $recurring_invoice_hashed_id,
|
||||||
'client' => $invoice->client->hashed_id,
|
'client' => $invoice->client->hashed_id,
|
||||||
'contact' => $invoice->client->primary_contact()->first() ? $invoice->client->primary_contact()->first(): $invoice->client->contacts->first(),
|
'contact' => $invoice->client->primary_contact()->first() ? $invoice->client->primary_contact()->first()->hashed_id: $invoice->client->contacts->first()->hashed_id,
|
||||||
'invoice' => $invoice->hashed_id,
|
'invoice' => $invoice->hashed_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user