Bug fixes

This commit is contained in:
Hillel Coren 2014-04-23 10:20:01 +03:00
parent b11ab39a9f
commit 55a8ef4951
12 changed files with 56 additions and 20 deletions

View File

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

View File

@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
'view_invoice' => 'View invoice',
);

View File

@ -324,7 +324,7 @@ return array(
'field_value' => 'Field Value',
'edit' => 'Edit',
'set_name' => 'Set your company name',
'view_invoice' => 'View invoice',

View File

@ -316,6 +316,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
'view_invoice' => 'View invoice',
);

View File

@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
'view_invoice' => 'View invoice',
);

View File

@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
'view_invoice' => 'View invoice',
);

View File

@ -317,6 +317,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
'view_invoice' => 'View invoice',
);

View File

@ -305,6 +305,6 @@ return array(
'field_label' => 'Field Label',
'field_value' => 'Field Value',
'edit' => 'Edit',
'view_invoice' => 'View invoice',
);

View File

@ -16,4 +16,9 @@ class Invitation extends EntityModel
{
return $this->belongsTo('User');
}
public function getLink()
{
return URL::to('view') . '/' . $this->invitation_key;
}
}

View File

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

View File

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

View File

@ -1245,15 +1245,21 @@
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() + '<br/>';
}
return str + self.email();
});
str += self.email();
if (self.invitation_link()) {
str += '<br/><a href="' + self.invitation_link() + '" target="_blank">{{ trans('texts.view_invoice') }}</a>';
}
return str;
});
if (data) {
ko.mapping.fromJS(data, {}, this);