From 7a90856025bdd4e9f68ba688d666049b8ea34aa5 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 31 Dec 2013 18:38:49 +0200 Subject: [PATCH] bug fixes --- app/controllers/InvoiceController.php | 24 +++++++++------- ...11_05_180133_confide_setup_users_table.php | 1 + app/models/Activity.php | 4 +++ app/models/Invoice.php | 18 ++++++++++++ app/ninja/repositories/InvoiceRepository.php | 3 +- app/views/invoices/edit.blade.php | 28 +++++-------------- public/js/bootstrap-combobox.js | 4 +++ 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 38b6853ae9fd..b4b4d22cc419 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -117,22 +117,25 @@ class InvoiceController extends \BaseController { public function view($invitationKey) { $invitation = Invitation::with('user', 'invoice.invoice_items', 'invoice.client.account', 'invoice.client.contacts') - ->where('invitation_key', '=', $invitationKey)->firstOrFail(); - + ->where('invitation_key', '=', $invitationKey)->firstOrFail(); + $user = $invitation->user; $invoice = $invitation->invoice; - - if (!$invoice || $invoice->is_deleted) { + + if (!$invoice || $invoice->is_deleted) + { return View::make('invoices.deleted'); } $client = $invoice->client; - if (!$client || $client->is_deleted) { + if (!$client || $client->is_deleted) + { return View::make('invoices.deleted'); } - - if ($invoice->invoice_status_id < INVOICE_STATUS_VIEWED) { + + if ($invoice->invoice_status_id < INVOICE_STATUS_VIEWED) + { $invoice->invoice_status_id = INVOICE_STATUS_VIEWED; $invoice->save(); } @@ -147,9 +150,9 @@ class InvoiceController extends \BaseController { $client->save(); Activity::viewInvoice($invitation); - + $data = array( - 'invoice' => $invoice, + 'invoice' => $invoice->hidePrivateFields(), 'invitation' => $invitation ); @@ -404,7 +407,8 @@ class InvoiceController extends \BaseController { if ($action == 'email' && $invoice->invoice_status_id == INVOICE_STATUS_DRAFT) { $invoice->invoice_status_id = INVOICE_STATUS_SENT; - + $invoice->save(); + $client->balance = $client->balance + $invoice->amount; $client->save(); } 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 7e9c948241c2..68586ff5b374 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 @@ -477,6 +477,7 @@ class ConfideSetupUsersTable extends Migration { $t->unsignedInteger('currency_id')->default(1); $t->text('message'); + $t->text('json_backup'); $t->integer('activity_type_id'); $t->decimal('adjustment', 13, 4); $t->decimal('balance', 13, 4); diff --git a/app/models/Activity.php b/app/models/Activity.php index 4e5d79743566..c7a5dcfc33b2 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -139,6 +139,9 @@ class Activity extends Eloquent return; } + $backupInvoice = Invoice::with('invoice_items', 'client.account', 'client.contacts')->find($invoice->id); + //dd($backupInvoice->hidePrivateFields()->toJSON()); + $client = $invoice->client; $client->balance = $client->balance + $diff; $client->save(); @@ -150,6 +153,7 @@ class Activity extends Eloquent $activity->message = Auth::user()->getFullName() . ' updated invoice ' . link_to('invoices/'.$invoice->public_id, $invoice->invoice_number); $activity->balance = $client->balance; $activity->adjustment = $diff; + $activity->json_backup = $backupInvoice->hidePrivateFields()->toJSON(); $activity->save(); } diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 0efc28aca0ed..8893a8e4a6ad 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -42,6 +42,24 @@ class Invoice extends EntityModel return $this->invoice_status_id >= INVOICE_STATUS_SENT; } + public function hidePrivateFields() + { + $this->setVisible(['invoice_number', 'discount', 'po_number', 'invoice_date', 'due_date', 'terms', 'currency_id', 'public_notes', 'amount', 'balance', 'invoice_items', 'client']); + $this->client->setVisible(['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'work_phone', 'payment_terms', 'contacts']); + + foreach ($this->invoice_items as $invoiceItem) + { + $invoiceItem->setVisible(['product_key', 'notes', 'cost', 'qty', 'tax_name', 'tax_rate']); + } + + foreach ($this->client->contacts as $contact) + { + $contact->setVisible(['first_name', 'last_name', 'email', 'phone']); + } + + return $this; + } + public function shouldSendToday() { $dayOfWeekToday = date('w'); diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index 8f1703c43b4d..5c7a21e768aa 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -73,7 +73,6 @@ class InvoiceRepository if ($publicId) { $invoice = Invoice::scope($publicId)->firstOrFail(); - $invoice->invoice_items()->forceDelete(); } else { @@ -116,6 +115,8 @@ class InvoiceRepository $invoice->balance = $total; $invoice->save(); + $invoice->invoice_items()->forceDelete(); + foreach ($data['invoice_items'] as $item) { if (!$item->cost && !$item->qty && !$item->product_key && !$item->notes) diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index d286c0311f62..e20dcaa13090 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -356,13 +356,11 @@ @endif var $input = $('select#client'); - $input.combobox(); - $('.client_select input.form-control').on('change', function(e) { - var clientId = parseInt($('input[name=client]').val(), 10); + $input.combobox().on('change', function(e) { + var clientId = parseInt($('input[name=client]').val(), 10); if (clientId > 0) { model.loadClient(clientMap[clientId]); } else { - //model.client.public_id(0); // TODO_FIX model.loadClient(new ClientModel()); } refreshPDF(); @@ -609,7 +607,6 @@ return self.client.public_id() ? 'Edit client details' : 'Create new client'; }); - self.showTaxesForm = function() { self.taxBackup = ko.mapping.toJS(self.tax_rates); @@ -621,21 +618,8 @@ $('#taxModal').modal('hide'); } - self.showClientForm = function() { self.clientBackup = ko.mapping.toJS(self.client); - //console.log(self.clientBackup); - - /* - if (self.client.public_id() == 0) { - $('#clientModal input').val(''); - $('#clientModal #payment_terms').val(''); - $('#clientModal #country_id').val(''); - $('#clientModal #currency_id').val(''); - $('#clientModal #client_size_id').val(''); - $('#clientModal #client_industry_id').val(''); - } - */ $('#emailError').css( "display", "none" ); $('#clientModal').modal('show'); @@ -651,7 +635,6 @@ return; } - $('select#client').combobox('setSelected'); if (self.client.public_id() == 0) { self.client.public_id(-1); } @@ -664,11 +647,13 @@ name = email; } + $('.client_select select').combobox('setSelected'); $('.client_select input.form-control').val(name); $('.client_select .combobox-container').addClass('combobox-selected'); $('#emailError').css( "display", "none" ); - $('.client_select input.form-control').focus(); + //$('.client_select input.form-control').focus(); + $('#terms').focus(); refreshPDF(); model.clientBackup = false; @@ -765,7 +750,7 @@ self.addContact = function() { var contact = new ContactModel(); - console.log('num: ' + self.contacts().length); + console.log('add contact: ' + self.contacts().length); if (self.contacts().length == 0) { contact.send_invoice(true); } @@ -1020,6 +1005,7 @@ } @else model.invoice_date('{{ date('Y-m-d') }}'); + model.start_date('{{ date('Y-m-d') }}'); model.invoice_number('{{ $invoiceNumber }}'); model.terms(wordWrapText('{{ $account->invoice_terms }}', 340)); @endif diff --git a/public/js/bootstrap-combobox.js b/public/js/bootstrap-combobox.js index e8bef1f817ac..ce48064fc9d8 100755 --- a/public/js/bootstrap-combobox.js +++ b/public/js/bootstrap-combobox.js @@ -333,9 +333,12 @@ case 37: // left arrow case 36: // home case 35: // end + case 33: // page up + case 34: // page down case 16: // shift case 17: // ctrl case 18: // alt + case 20: // cap lock break; case 9: // tab @@ -350,6 +353,7 @@ break; default: + console.log('keyCode: %s', e.keyCode); this.clearTarget(); this.lookup(); }