diff --git a/README.md b/README.md index 870ba42feb..0ac0a63e76 100755 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Clone the Github project cd ninja Install Laravel packages using Composer +Note: you may be prompted for your Github user/pass due to their API limits. composer install diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index e14db64eb2..cd55ed0158 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -427,6 +427,8 @@ class AccountController extends \BaseController { $account->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null; $account->invoice_terms = Input::get('invoice_terms'); + $account->email_footer = Input::get('email_footer'); + $account->save(); $user = Auth::user(); diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index c74c075568..fb92ca9b67 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -270,8 +270,8 @@ class InvoiceController extends \BaseController { } $invoice->save(); - - Event::fire('invoice.paid', $invoice); + + Event::fire('invoice.paid', $payment); Session::flash('message', 'Successfully applied payment'); return Redirect::to('view/' . $payment->invitation->invitation_key); @@ -345,7 +345,7 @@ class InvoiceController extends \BaseController { { return [ 'account' => Auth::user()->account, - 'products' => Product::scope()->get(array('product_key','notes','cost','qty')), + 'products' => Product::scope()->orderBy('id')->get(array('product_key','notes','cost','qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), diff --git a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php index 48dc191861..b501d7fbc3 100755 --- a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php +++ b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php @@ -143,6 +143,7 @@ class ConfideSetupUsersTable extends Migration { $t->string('postal_code'); $t->unsignedInteger('country_id')->nullable(); $t->text('invoice_terms'); + $t->text('email_footer'); $t->unsignedInteger('industry_id')->nullable(); $t->unsignedInteger('size_id')->nullable(); diff --git a/app/handlers/InvoiceEventHandler.php b/app/handlers/InvoiceEventHandler.php index c7952f77ef..243d096dcd 100755 --- a/app/handlers/InvoiceEventHandler.php +++ b/app/handlers/InvoiceEventHandler.php @@ -1,14 +1,17 @@ mailer = $mailer; + $this->userMailer = $userMailer; + $this->contactMailer = $contactMailer; } public function subscribe($events) @@ -28,18 +31,20 @@ class InvoiceEventHandler $this->sendNotifications($invoice, 'viewed'); } - public function onPaid($invoice) + public function onPaid($payment) { - $this->sendNotifications($invoice, 'paid'); + $this->contactMailer->sendPaymentConfirmation($payment); + + $this->sendNotifications($payment->invoice, 'paid', $payment); } - private function sendNotifications($invoice, $type) + private function sendNotifications($invoice, $type, $payment = null) { foreach ($invoice->account->users as $user) { if ($user->{'notify_' . $type}) { - $this->mailer->sendNotification($user, $invoice, $type); + $this->userMailer->sendNotification($user, $invoice, $type, $payment); } } } diff --git a/app/libraries/utils.php b/app/libraries/utils.php index 8b15f9b2c2..903d383ea4 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -23,7 +23,7 @@ class Utils $data = [ 'context' => $context, 'user_id' => Auth::check() ? Auth::user()->id : 0, - 'url' => Input::get('url'), + 'url' => Input::get('url', Request::url()), 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'ip' => Request::getClientIp(), 'count' => Session::get('error_count', 0) diff --git a/app/models/Account.php b/app/models/Account.php index 58ced9dfa2..41b3fd9518 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -73,6 +73,19 @@ class Account extends Eloquent } } + public function getDisplayName() + { + if ($this->name) + { + return $this->name; + } + + $this->load('users'); + $user = $this->users()->first(); + + return $user->getDisplayName(); + } + public function getTimezone() { if ($this->timezone) diff --git a/app/models/Payment.php b/app/models/Payment.php index 0756cab952..fd81faf146 100755 --- a/app/models/Payment.php +++ b/app/models/Payment.php @@ -17,6 +17,16 @@ class Payment extends EntityModel return $this->belongsTo('Client'); } + public function account() + { + return $this->belongsTo('Account'); + } + + public function contact() + { + return $this->belongsTo('Contact'); + } + public function getName() { return ''; diff --git a/app/ninja/mailers/ContactMailer.php b/app/ninja/mailers/ContactMailer.php index b4efb77cde..82530d3d72 100755 --- a/app/ninja/mailers/ContactMailer.php +++ b/app/ninja/mailers/ContactMailer.php @@ -1,20 +1,22 @@ invoice_number; - $invoice->load('invitations'); + $invoice->load('invitations', 'client', 'account'); foreach ($invoice->invitations as $invitation) { @@ -26,7 +28,15 @@ class ContactMailer extends Mailer { $invitation->sent_date = \Carbon::now()->toDateTimeString(); $invitation->save(); - $data = array('link' => URL::to('view') . '/' . $invitation->invitation_key); + $data = [ + 'link' => URL::to('view') . '/' . $invitation->invitation_key, + 'clientName' => $invoice->client->getDisplayName(), + 'accountName' => $invoice->account->getDisplayName(), + 'contactName' => $invitation->contact->getDisplayName(), + 'invoiceAmount' => Utils::formatMoney($invoice->amount, $invoice->client->currency_id), + 'emailFooter' => $invoice->account->email_footer + ]; + $this->sendTo($invitation->contact->email, $invitation->user->email, $subject, $view, $data); Activity::emailInvoice($invitation); @@ -40,4 +50,19 @@ class ContactMailer extends Mailer { \Event::fire('invoice.sent', $invoice); } + + public function sendPaymentConfirmation(Payment $payment) + { + $view = 'payment_confirmation'; + $subject = 'Payment confirmation'; + + $data = [ + 'accountName' => $payment->account->getDisplayName(), + 'clientName' => $payment->client->getDisplayName(), + 'emailFooter' => $payment->account->email_footer, + 'paymentAmount' => Utils::formatMoney($payment->amount, $payment->client->currency_id) + ]; + + $this->sendTo($payment->contact->email, $payment->invitation->user->email, $subject, $view, $data); + } } \ No newline at end of file diff --git a/app/ninja/mailers/UserMailer.php b/app/ninja/mailers/UserMailer.php index 78d2f1fd53..3ae01e1407 100755 --- a/app/ninja/mailers/UserMailer.php +++ b/app/ninja/mailers/UserMailer.php @@ -1,22 +1,38 @@ email) { return; } - $view = 'invoice'; - //$data = array('link' => URL::to('view') . '/' . $invoice->invoice_key); - $data = ['link' => '']; - $subject = 'Notification - Invoice ' . $type; + $view = 'invoice_' . $type; + + $data = [ + 'clientName' => $invoice->client->getDisplayName(), + 'accountName' => $invoice->account->getDisplayName(), + 'userName' => $user->getDisplayName(), + 'invoiceAmount' => Utils::formatMoney($invoice->amount, $invoice->client->currency_id), + 'invoiceNumber' => $invoice->invoice_number, + 'invoiceLink' => "http://www.invoiceninja.com/invoices/{$invoice->public_id}" + ]; + + if ($payment) + { + $data['paymentAmount'] = Utils::formatMoney($payment->amount, $invoice->client->currency_id); + } + + $prep = $type == 'sent' ? 'to' : 'by'; + $subject = "Invoice {$invoice->invoice_number} was $type $prep {$invoice->client->getDisplayName()}"; $this->sendTo($user->email, CONTACT_EMAIL, $subject, $view, $data); } diff --git a/app/views/accounts/settings.blade.php b/app/views/accounts/settings.blade.php index d8f703e1d4..2626242222 100755 --- a/app/views/accounts/settings.blade.php +++ b/app/views/accounts/settings.blade.php @@ -61,8 +61,9 @@ {{ Former::checkbox('notify_viewed')->label(' ')->text('Email me when an invoice is viewed') }} {{ Former::checkbox('notify_paid')->label(' ')->text('Email me when an invoice is paid') }} - {{ Former::legend('Invoice Terms') }} - {{ Former::textarea('invoice_terms')->label('Terms') }} + {{ Former::legend('Custom messages') }} + {{ Former::textarea('invoice_terms') }} + {{ Former::textarea('email_footer') }} {{ Former::actions( Button::lg_primary_submit('Save') ) }} {{ Former::close() }} diff --git a/app/views/emails/invoice_html.blade.php b/app/views/emails/invoice_html.blade.php index 7e51669b09..4bdf2e6bcf 100755 --- a/app/views/emails/invoice_html.blade.php +++ b/app/views/emails/invoice_html.blade.php @@ -4,9 +4,19 @@
-