diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php
index 21c16f96a931..190ce3c455a3 100755
--- a/app/controllers/InvoiceController.php
+++ b/app/controllers/InvoiceController.php
@@ -156,7 +156,7 @@ class InvoiceController extends \BaseController {
public function edit($publicId)
{
- $invoice = Invoice::scope($publicId)->withTrashed()->with('account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail();
+ $invoice = Invoice::scope($publicId)->withTrashed()->with('invitations', 'account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail();
Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->getDisplayName(), ENTITY_INVOICE);
$invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date);
@@ -165,13 +165,13 @@ class InvoiceController extends \BaseController {
$invoice->end_date = Utils::fromSqlDate($invoice->end_date);
$invoice->is_pro = Auth::user()->isPro();
- $contactIds = DB::table('invitations')
- ->join('contacts', 'contacts.id', '=','invitations.contact_id')
- ->where('invitations.invoice_id', '=', $invoice->id)
- ->where('invitations.account_id', '=', Auth::user()->account_id)
- ->where('invitations.deleted_at', '=', null)
- ->select('contacts.public_id')->lists('public_id');
-
+ $contactIds = DB::table('invitations')
+ ->join('contacts', 'contacts.id', '=','invitations.contact_id')
+ ->where('invitations.invoice_id', '=', $invoice->id)
+ ->where('invitations.account_id', '=', Auth::user()->account_id)
+ ->where('invitations.deleted_at', '=', null)
+ ->select('contacts.public_id')->lists('public_id');
+
$data = array(
'showBreadcrumbs' => false,
'account' => $invoice->account,
@@ -183,6 +183,27 @@ class InvoiceController extends \BaseController {
'title' => '- ' . $invoice->invoice_number,
'client' => $invoice->client);
$data = array_merge($data, self::getViewModel());
+
+ // Set the invitation link on the client's contacts
+ $clients = $data['clients'];
+ foreach ($clients as $client)
+ {
+ if ($client->id == $invoice->client->id)
+ {
+ foreach ($invoice->invitations as $invitation)
+ {
+ foreach ($client->contacts as $contact)
+ {
+ if ($invitation->contact_id == $contact->id)
+ {
+ $contact->invitation_link = $invitation->getLink();
+ }
+ }
+ }
+ break;
+ }
+ }
+
return View::make('invoices.edit', $data);
}
@@ -311,6 +332,10 @@ class InvoiceController extends \BaseController {
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
$invitation->save();
}
+ else if (!in_array($contact->id, $sendInvoiceIds) && $invitation)
+ {
+ $invitation->delete();
+ }
}
$message = trans($publicId ? 'texts.updated_invoice' : 'texts.created_invoice');
diff --git a/app/lang/de/texts.php b/app/lang/de/texts.php
index 585468e3bc95..5f6c98f50465 100644
--- a/app/lang/de/texts.php
+++ b/app/lang/de/texts.php
@@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
-
+ 'view_invoice' => 'View invoice',
);
diff --git a/app/lang/en/texts.php b/app/lang/en/texts.php
index ce09b67aa86f..edfa403453b8 100644
--- a/app/lang/en/texts.php
+++ b/app/lang/en/texts.php
@@ -324,7 +324,7 @@ return array(
'field_value' => 'Field Value',
'edit' => 'Edit',
'set_name' => 'Set your company name',
-
+ 'view_invoice' => 'View invoice',
diff --git a/app/lang/es/texts.php b/app/lang/es/texts.php
index be773a49c3ae..416420c15164 100644
--- a/app/lang/es/texts.php
+++ b/app/lang/es/texts.php
@@ -316,6 +316,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
-
+ 'view_invoice' => 'View invoice',
);
diff --git a/app/lang/fr/texts.php b/app/lang/fr/texts.php
index bee14daf1011..350485881be4 100644
--- a/app/lang/fr/texts.php
+++ b/app/lang/fr/texts.php
@@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
-
+ 'view_invoice' => 'View invoice',
);
diff --git a/app/lang/it/texts.php b/app/lang/it/texts.php
index 27c98416486f..d179fa9d0514 100644
--- a/app/lang/it/texts.php
+++ b/app/lang/it/texts.php
@@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
-
+ 'view_invoice' => 'View invoice',
);
diff --git a/app/lang/nl/texts.php b/app/lang/nl/texts.php
index fd12717c2247..263e2c86ded7 100644
--- a/app/lang/nl/texts.php
+++ b/app/lang/nl/texts.php
@@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
-
+ 'view_invoice' => 'View invoice',
);
diff --git a/app/lang/pt_BR/texts.php b/app/lang/pt_BR/texts.php
index 2fed2a0de56f..75e8c6360f4a 100644
--- a/app/lang/pt_BR/texts.php
+++ b/app/lang/pt_BR/texts.php
@@ -305,6 +305,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
-
+ 'view_invoice' => 'View invoice',
);
diff --git a/app/models/Invitation.php b/app/models/Invitation.php
index d3097683310c..e5b36f886553 100755
--- a/app/models/Invitation.php
+++ b/app/models/Invitation.php
@@ -16,4 +16,9 @@ class Invitation extends EntityModel
{
return $this->belongsTo('User');
}
+
+ public function getLink()
+ {
+ return URL::to('view') . '/' . $this->invitation_key;
+ }
}
\ No newline at end of file
diff --git a/app/ninja/mailers/ContactMailer.php b/app/ninja/mailers/ContactMailer.php
index 37be8e02ed04..c63b45a7b9ee 100755
--- a/app/ninja/mailers/ContactMailer.php
+++ b/app/ninja/mailers/ContactMailer.php
@@ -29,7 +29,7 @@ class ContactMailer extends Mailer {
$invitation->save();
$data = [
- 'link' => URL::to('view') . '/' . $invitation->invitation_key,
+ 'link' => $invitation->getLink(),
'clientName' => $invoice->client->getDisplayName(),
'accountName' => $invoice->account->getDisplayName(),
'contactName' => $invitation->contact->getDisplayName(),
diff --git a/app/ninja/repositories/AccountRepository.php b/app/ninja/repositories/AccountRepository.php
index 67bf34d9debb..f17f96a9b3a4 100755
--- a/app/ninja/repositories/AccountRepository.php
+++ b/app/ninja/repositories/AccountRepository.php
@@ -174,8 +174,8 @@ class AccountRepository
$user->username = $random;
$user->first_name = 'Invoice';
$user->last_name = 'Ninja';
- $user->notify_sent = false;
- $user->notify_paid = false;
+ $user->notify_sent = true;
+ $user->notify_paid = true;
$account->users()->save($user);
$accountGateway = new AccountGateway();
diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php
index b7fe9a8d506b..b04f3953ec02 100755
--- a/app/views/invoices/edit.blade.php
+++ b/app/views/invoices/edit.blade.php
@@ -1245,16 +1245,22 @@
self.email = ko.observable('');
self.phone = ko.observable('');
self.send_invoice = ko.observable(false);
+ self.invitation_link = ko.observable('');
self.email.display = ko.computed(function() {
var str = '';
if (self.first_name() || self.last_name()) {
str += self.first_name() + ' ' + self.last_name() + '
';
}
- return str + self.email();
+ str += self.email();
+
+ if (self.invitation_link()) {
+ str += '
{{ trans('texts.view_invoice') }}';
+ }
+
+ return str;
});
-
if (data) {
ko.mapping.fromJS(data, {}, this);
}