1
0
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:
Hillel Coren 2015-04-13 15:00:31 +03:00
parent 564d006428
commit 5a6197fbb4
24 changed files with 210 additions and 30 deletions

View 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;
}
}

View File

@ -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'));

View File

@ -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'));

View 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');
}
}
}
}

View File

@ -39,8 +39,8 @@ class UserMailer extends Mailer
return;
}
$view = 'invoice_'.$notificationType;
$entityType = $invoice->getEntityType();
$view = "{$entityType}_{$notificationType}";
$data = [
'entityType' => $entityType,

View File

@ -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;
}

View File

@ -26,6 +26,9 @@ class EventServiceProvider extends ServiceProvider {
'App\Events\InvoicePaid' => [
'App\Listeners\HandleInvoicePaid',
],
'App\Events\QuoteApproved' => [
'App\Listeners\HandleQuoteApproved',
],
];
/**

View File

@ -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');
});
}
}

View File

@ -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.',
);

View File

@ -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.',
);

View File

@ -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.',
);

View File

@ -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.',
);

View File

@ -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.',
);

View File

@ -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.',
);

View File

@ -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.',

View File

@ -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.',
);

View File

@ -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.',

View File

@ -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.',
);

View File

@ -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.',
);

View File

@ -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('&nbsp;')->text(trans('texts.email_sent')) !!}
{!! Former::checkbox('notify_viewed')->label('&nbsp;')->text(trans('texts.email_viewed')) !!}
{!! Former::checkbox('notify_paid')->label('&nbsp;')->text(trans('texts.email_paid')) !!}
{!! Former::checkbox('notify_paid')->label('&nbsp;')->text(trans('texts.email_paid')) !!}
{!! Former::checkbox('notify_approved')->label('&nbsp;')->text(trans('texts.email_approved')) !!}
{!! Former::legend(trans('texts.site_updates')) !!}

View 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>

View 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') }}

View File

@ -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();

View File

@ -24,7 +24,7 @@
@if ($invoice->is_quote)
{!! Button::normal(trans('texts.download_pdf'))->withAttributes(['onclick' => 'onDownloadClick()'])->large() !!}&nbsp;&nbsp;
@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() !!}&nbsp;&nbsp;
@ -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>