mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-17 16:42:48 +01:00
Added notification email when quote is approved
This commit is contained in:
parent
564d006428
commit
5a6197fbb4
23
app/Events/QuoteApproved.php
Normal file
23
app/Events/QuoteApproved.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php namespace App\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class QuoteApproved extends Event {
|
||||
|
||||
use SerializesModels;
|
||||
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
}
|
@ -554,6 +554,7 @@ class AccountController extends BaseController
|
||||
$user->notify_sent = Input::get('notify_sent');
|
||||
$user->notify_viewed = Input::get('notify_viewed');
|
||||
$user->notify_paid = Input::get('notify_paid');
|
||||
$user->notify_approved = Input::get('notify_approved');
|
||||
$user->save();
|
||||
|
||||
Session::flash('message', trans('texts.updated_settings'));
|
||||
|
@ -6,7 +6,8 @@ use Redirect;
|
||||
use Utils;
|
||||
use View;
|
||||
use Cache;
|
||||
|
||||
use Event;
|
||||
use Session;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\Country;
|
||||
@ -17,10 +18,13 @@ use App\Models\PaymentTerm;
|
||||
use App\Models\Product;
|
||||
use App\Models\Size;
|
||||
use App\Models\TaxRate;
|
||||
use App\Models\Invitation;
|
||||
use App\Models\Activity;
|
||||
use App\Ninja\Mailers\ContactMailer as Mailer;
|
||||
use App\Ninja\Repositories\InvoiceRepository;
|
||||
use App\Ninja\Repositories\ClientRepository;
|
||||
use App\Ninja\Repositories\TaxRateRepository;
|
||||
use App\Events\QuoteApproved;
|
||||
|
||||
class QuoteController extends BaseController
|
||||
{
|
||||
@ -187,7 +191,9 @@ class QuoteController extends BaseController
|
||||
$invoice = $invitation->invoice;
|
||||
|
||||
if ($invoice->is_quote && !$invoice->quote_invoice_id) {
|
||||
Activity::approveQuote($invitation);
|
||||
Event::fire(new QuoteApproved($invoice));
|
||||
Activity::approveQuote($invitation);
|
||||
|
||||
$invoice = $this->invoiceRepo->cloneInvoice($invoice, $invoice->id);
|
||||
Session::flash('message', trans('texts.converted_to_invoice'));
|
||||
|
||||
|
42
app/Listeners/HandleQuoteApproved.php
Normal file
42
app/Listeners/HandleQuoteApproved.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php namespace App\Listeners;
|
||||
|
||||
use App\Events\QuoteApproved;
|
||||
use App\Ninja\Mailers\UserMailer;
|
||||
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldBeQueued;
|
||||
|
||||
class HandleQuoteApproved {
|
||||
|
||||
protected $userMailer;
|
||||
|
||||
/**
|
||||
* Create the event handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(UserMailer $userMailer)
|
||||
{
|
||||
$this->userMailer = $userMailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param QuoteApproved $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(QuoteApproved $event)
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
|
||||
foreach ($invoice->account->users as $user)
|
||||
{
|
||||
if ($user->{'notify_approved'})
|
||||
{
|
||||
$this->userMailer->sendNotification($user, $invoice, 'approved');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -39,8 +39,8 @@ class UserMailer extends Mailer
|
||||
return;
|
||||
}
|
||||
|
||||
$view = 'invoice_'.$notificationType;
|
||||
$entityType = $invoice->getEntityType();
|
||||
$view = "{$entityType}_{$notificationType}";
|
||||
|
||||
$data = [
|
||||
'entityType' => $entityType,
|
||||
|
@ -223,6 +223,17 @@ class InvoiceRepository
|
||||
|
||||
$account = \Auth::user()->account;
|
||||
|
||||
if ((isset($data['set_default_terms']) && $data['set_default_terms'])
|
||||
|| (isset($data['set_default_footer']) && $data['set_default_footer'])) {
|
||||
if (isset($data['set_default_terms']) && $data['set_default_terms']) {
|
||||
$account->invoice_terms = trim($data['terms']);
|
||||
}
|
||||
if (isset($data['set_default_footer']) && $data['set_default_footer']) {
|
||||
$account->invoice_footer = trim($data['invoice_footer']);
|
||||
}
|
||||
$account->save();
|
||||
}
|
||||
|
||||
$invoice->client_id = $data['client_id'];
|
||||
$invoice->discount = round(Utils::parseFloat($data['discount']), 2);
|
||||
$invoice->is_amount_discount = $data['is_amount_discount'] ? true : false;
|
||||
@ -360,17 +371,6 @@ class InvoiceRepository
|
||||
$invoice->invoice_items()->save($invoiceItem);
|
||||
}
|
||||
|
||||
if ((isset($data['set_default_terms']) && $data['set_default_terms'])
|
||||
|| (isset($data['set_default_footer']) && $data['set_default_footer'])) {
|
||||
if (isset($data['set_default_terms']) && $data['set_default_terms']) {
|
||||
$account->invoice_terms = trim($data['terms']);
|
||||
}
|
||||
if (isset($data['set_default_footer']) && $data['set_default_footer']) {
|
||||
$account->invoice_footer = trim($data['invoice_footer']);
|
||||
}
|
||||
$account->save();
|
||||
}
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,9 @@ class EventServiceProvider extends ServiceProvider {
|
||||
'App\Events\InvoicePaid' => [
|
||||
'App\Listeners\HandleInvoicePaid',
|
||||
],
|
||||
'App\Events\QuoteApproved' => [
|
||||
'App\Listeners\HandleQuoteApproved',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddNotifyApproved extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function($table)
|
||||
{
|
||||
$table->boolean('notify_approved')->default(true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function($table)
|
||||
{
|
||||
$table->dropColumn('notify_approved');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -580,5 +580,9 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
);
|
||||
|
@ -571,6 +571,10 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
);
|
||||
|
@ -578,6 +578,9 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
);
|
||||
|
@ -550,7 +550,11 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
|
||||
);
|
@ -571,6 +571,10 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
);
|
@ -573,6 +573,10 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
);
|
||||
|
@ -581,6 +581,10 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
|
||||
|
@ -580,5 +580,9 @@ return array(
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
);
|
@ -574,6 +574,10 @@ return array(
|
||||
'send_email' => 'Verstuur email',
|
||||
'set_password' => 'Stel wachtwoord in',
|
||||
'converted' => 'Omgezet',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
|
||||
|
@ -574,6 +574,10 @@ return array(
|
||||
'send_email' => 'Send email',
|
||||
'set_password' => 'Set Password',
|
||||
'converted' => 'Converted',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
);
|
||||
|
@ -577,6 +577,10 @@ return array(
|
||||
'send_email' => 'Skicka mail',
|
||||
'set_password' => 'Ange lösenord',
|
||||
'converted' => 'Konvertera',
|
||||
|
||||
'email_approved' => 'Email me when a quote is <b>approved</b>',
|
||||
'notification_quote_approved_subject' => 'Quote :invoice was approved by :client',
|
||||
'notification_quote_approved' => 'The following client :client approved Quote :invoice for :amount.',
|
||||
|
||||
|
||||
);
|
||||
|
@ -8,11 +8,13 @@
|
||||
{{ Former::populateField('notify_sent', intval(Auth::user()->notify_sent)) }}
|
||||
{{ Former::populateField('notify_viewed', intval(Auth::user()->notify_viewed)) }}
|
||||
{{ Former::populateField('notify_paid', intval(Auth::user()->notify_paid)) }}
|
||||
{{ Former::populateField('notify_approved', intval(Auth::user()->notify_approved)) }}
|
||||
|
||||
{!! Former::legend(trans('texts.email_notifications')) !!}
|
||||
{!! Former::checkbox('notify_sent')->label(' ')->text(trans('texts.email_sent')) !!}
|
||||
{!! Former::checkbox('notify_viewed')->label(' ')->text(trans('texts.email_viewed')) !!}
|
||||
{!! Former::checkbox('notify_paid')->label(' ')->text(trans('texts.email_paid')) !!}
|
||||
{!! Former::checkbox('notify_paid')->label(' ')->text(trans('texts.email_paid')) !!}
|
||||
{!! Former::checkbox('notify_approved')->label(' ')->text(trans('texts.email_approved')) !!}
|
||||
|
||||
{!! Former::legend(trans('texts.site_updates')) !!}
|
||||
|
||||
|
18
resources/views/emails/quote_approved_html.blade.php
Normal file
18
resources/views/emails/quote_approved_html.blade.php
Normal file
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
@include('emails.view_action', ['link' => $invoiceLink, 'entityType' => $entityType])
|
||||
{{ trans('texts.email_salutation', ['name' => $userName]) }} <p/>
|
||||
|
||||
{{ trans("texts.notification_{$entityType}_approved", ['amount' => $invoiceAmount, 'client' => $clientName, 'invoice' => $invoiceNumber]) }} <p/>
|
||||
|
||||
{{ trans('texts.email_signature') }} <br/>
|
||||
{{ trans('texts.email_from') }} <p/>
|
||||
|
||||
{{ trans('texts.user_email_footer') }} <p/>
|
||||
|
||||
</body>
|
||||
</html>
|
8
resources/views/emails/quote_approved_text.blade.php
Normal file
8
resources/views/emails/quote_approved_text.blade.php
Normal file
@ -0,0 +1,8 @@
|
||||
{{ trans('texts.email_salutation', ['name' => $userName]) }}
|
||||
|
||||
{{ trans("texts.notification_{$entityType}_approved", ['amount' => $invoiceAmount, 'client' => $clientName, 'invoice' => $invoiceNumber]) }}
|
||||
|
||||
{{ trans('texts.email_signature') }}
|
||||
{{ trans('texts.email_from') }}
|
||||
|
||||
{{ trans('texts.user_email_footer') }}
|
@ -1181,8 +1181,8 @@
|
||||
self.totals.rawSubtotal = ko.computed(function() {
|
||||
var total = 0;
|
||||
for(var p=0; p < self.invoice_items().length; ++p) {
|
||||
var item = self.invoice_items()[p];
|
||||
total += item.totals.rawTotal();
|
||||
var item = self.invoice_items()[p];
|
||||
total += item.totals.rawTotal();
|
||||
}
|
||||
return total;
|
||||
});
|
||||
@ -1526,12 +1526,12 @@
|
||||
var cost = roundToTwo(NINJA.parseFloat(self.cost()));
|
||||
var qty = roundToTwo(NINJA.parseFloat(self.qty()));
|
||||
var taxRate = NINJA.parseFloat(self.tax_rate());
|
||||
var value = cost * qty;
|
||||
if (taxRate > 0) {
|
||||
value += value * (taxRate/100);
|
||||
}
|
||||
return value ? roundToTwo(value) : '';
|
||||
});
|
||||
var value = cost * qty;
|
||||
if (taxRate > 0) {
|
||||
value += value * (taxRate/100);
|
||||
}
|
||||
return value ? roundToTwo(value) : 0;
|
||||
});
|
||||
|
||||
this.totals.total = ko.computed(function() {
|
||||
var total = self.totals.rawTotal();
|
||||
|
@ -24,7 +24,7 @@
|
||||
@if ($invoice->is_quote)
|
||||
{!! Button::normal(trans('texts.download_pdf'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}
|
||||
@if (!$isConverted)
|
||||
{!! Button::success(trans('texts.approve'))->asLinkTo('approve/' . $invitation->invitation_key)->large() !!}
|
||||
{!! Button::success(trans('texts.approve'))->asLinkTo('/approve/' . $invitation->invitation_key)->large() !!}
|
||||
@endif
|
||||
@elseif ($invoice->client->account->isGatewayConfigured() && !$invoice->isPaid() && !$invoice->is_recurring)
|
||||
{!! Button::normal(trans('texts.download_pdf'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}
|
||||
@ -39,10 +39,10 @@
|
||||
['url' => URL::to("payment/{$invitation->invitation_key}?use_paypal=false"), 'label' => trans('texts.pay_with_card')]
|
||||
])->addClass('btn-lg') !!}
|
||||
@else
|
||||
{!! Button::success(trans('texts.pay_now'))->asLinkTo(URL::to('payment/' . $invitation->invitation_key))->large() !!}
|
||||
{!! Button::success(trans('texts.pay_now'))->asLinkTo('/payment/' . $invitation->invitation_key)->large() !!}
|
||||
@endif
|
||||
@else
|
||||
{!! Button::success('Download PDF')->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}
|
||||
{!! Button::normal('Download PDF')->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user