From a301e5860995dffe5a7ba98febd7e0c7a90a9526 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 14 Jun 2015 20:30:01 +0300 Subject: [PATCH] Enabled sending payment confirmation email for manual payment entries --- app/Http/Controllers/PaymentController.php | 9 +++++++-- app/Models/Payment.php | 5 +++++ app/Ninja/Mailers/ContactMailer.php | 11 +++++++++-- resources/lang/en/texts.php | 2 ++ resources/views/payments/edit.blade.php | 4 ++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 0719cd0eaf5a..a3103b8b780a 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -733,14 +733,19 @@ class PaymentController extends BaseController ->withErrors($errors) ->withInput(); } else { - $this->paymentRepo->save($publicId, Input::all()); + $payment = $this->paymentRepo->save($publicId, Input::all()); if ($publicId) { Session::flash('message', trans('texts.updated_payment')); return Redirect::to('payments/'); } else { - Session::flash('message', trans('texts.created_payment')); + if (Input::get('email_receipt')) { + $this->contactMailer->sendPaymentConfirmation($payment); + Session::flash('message', trans('texts.created_payment_emailed_client')); + } else { + Session::flash('message', trans('texts.created_payment')); + } return Redirect::to('clients/'.Input::get('client')); } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 89041bba877a..ee382dece1b6 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -22,6 +22,11 @@ class Payment extends EntityModel return $this->belongsTo('App\Models\Client')->withTrashed(); } + public function user() + { + return $this->belongsTo('App\Models\User')->withTrashed(); + } + public function account() { return $this->belongsTo('App\Models\Account'); diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index c9583190c9e2..6c2dad54753a 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -84,8 +84,15 @@ class ContactMailer extends Mailer $data = ['body' => str_replace(array_keys($variables), array_values($variables), $emailTemplate)]; - $user = $payment->invitation->user; - $this->sendTo($payment->contact->email, $user->email, $accountName, $subject, $view, $data); + if ($payment->invitation) { + $user = $payment->invitation->user; + $contact = $payment->contact->email; + } else { + $user = $payment->user; + $contact = $payment->client->contacts[0]; + } + + $this->sendTo($contact->email, $user->email, $accountName, $subject, $view, $data); } public function sendLicensePaymentConfirmation($name, $email, $amount, $license, $productId) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index b7ac26271b32..d9f56e4eddbd 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -694,5 +694,7 @@ return array( 'timezone_unset' => 'Please :link to set your timezone', 'click_here' => 'click here', + 'email_receipt' => 'Email payment receipt to the client', + 'created_payment_emailed_client' => 'Successfully created payment and emailed client', ); diff --git a/resources/views/payments/edit.blade.php b/resources/views/payments/edit.blade.php index 1cd4f51fb6df..97fcb277129b 100644 --- a/resources/views/payments/edit.blade.php +++ b/resources/views/payments/edit.blade.php @@ -32,6 +32,10 @@ {!! Former::text('payment_date')->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') !!} {!! Former::text('transaction_reference') !!} + @if (!$payment) + {!! Former::checkbox('email_receipt')->label(' ')->text(trans('texts.email_receipt')) !!} + @endif +