diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 0719cd0eaf..a3103b8b78 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 89041bba87..ee382dece1 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 c9583190c9..6c2dad5475 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 b7ac26271b..d9f56e4edd 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 1cd4f51fb6..97fcb27712 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 +