bug fixes

This commit is contained in:
Hillel Coren 2013-12-31 18:38:49 +02:00
parent 9dd1b54d4a
commit 7a90856025
7 changed files with 50 additions and 32 deletions

View File

@ -122,17 +122,20 @@ class InvoiceController extends \BaseController {
$user = $invitation->user; $user = $invitation->user;
$invoice = $invitation->invoice; $invoice = $invitation->invoice;
if (!$invoice || $invoice->is_deleted) { if (!$invoice || $invoice->is_deleted)
{
return View::make('invoices.deleted'); return View::make('invoices.deleted');
} }
$client = $invoice->client; $client = $invoice->client;
if (!$client || $client->is_deleted) { if (!$client || $client->is_deleted)
{
return View::make('invoices.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->invoice_status_id = INVOICE_STATUS_VIEWED;
$invoice->save(); $invoice->save();
} }
@ -149,7 +152,7 @@ class InvoiceController extends \BaseController {
Activity::viewInvoice($invitation); Activity::viewInvoice($invitation);
$data = array( $data = array(
'invoice' => $invoice, 'invoice' => $invoice->hidePrivateFields(),
'invitation' => $invitation 'invitation' => $invitation
); );
@ -404,6 +407,7 @@ class InvoiceController extends \BaseController {
if ($action == 'email' && $invoice->invoice_status_id == INVOICE_STATUS_DRAFT) if ($action == 'email' && $invoice->invoice_status_id == INVOICE_STATUS_DRAFT)
{ {
$invoice->invoice_status_id = INVOICE_STATUS_SENT; $invoice->invoice_status_id = INVOICE_STATUS_SENT;
$invoice->save();
$client->balance = $client->balance + $invoice->amount; $client->balance = $client->balance + $invoice->amount;
$client->save(); $client->save();

View File

@ -477,6 +477,7 @@ class ConfideSetupUsersTable extends Migration {
$t->unsignedInteger('currency_id')->default(1); $t->unsignedInteger('currency_id')->default(1);
$t->text('message'); $t->text('message');
$t->text('json_backup');
$t->integer('activity_type_id'); $t->integer('activity_type_id');
$t->decimal('adjustment', 13, 4); $t->decimal('adjustment', 13, 4);
$t->decimal('balance', 13, 4); $t->decimal('balance', 13, 4);

View File

@ -139,6 +139,9 @@ class Activity extends Eloquent
return; return;
} }
$backupInvoice = Invoice::with('invoice_items', 'client.account', 'client.contacts')->find($invoice->id);
//dd($backupInvoice->hidePrivateFields()->toJSON());
$client = $invoice->client; $client = $invoice->client;
$client->balance = $client->balance + $diff; $client->balance = $client->balance + $diff;
$client->save(); $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->message = Auth::user()->getFullName() . ' updated invoice ' . link_to('invoices/'.$invoice->public_id, $invoice->invoice_number);
$activity->balance = $client->balance; $activity->balance = $client->balance;
$activity->adjustment = $diff; $activity->adjustment = $diff;
$activity->json_backup = $backupInvoice->hidePrivateFields()->toJSON();
$activity->save(); $activity->save();
} }

View File

@ -42,6 +42,24 @@ class Invoice extends EntityModel
return $this->invoice_status_id >= INVOICE_STATUS_SENT; 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() public function shouldSendToday()
{ {
$dayOfWeekToday = date('w'); $dayOfWeekToday = date('w');

View File

@ -73,7 +73,6 @@ class InvoiceRepository
if ($publicId) if ($publicId)
{ {
$invoice = Invoice::scope($publicId)->firstOrFail(); $invoice = Invoice::scope($publicId)->firstOrFail();
$invoice->invoice_items()->forceDelete();
} }
else else
{ {
@ -116,6 +115,8 @@ class InvoiceRepository
$invoice->balance = $total; $invoice->balance = $total;
$invoice->save(); $invoice->save();
$invoice->invoice_items()->forceDelete();
foreach ($data['invoice_items'] as $item) foreach ($data['invoice_items'] as $item)
{ {
if (!$item->cost && !$item->qty && !$item->product_key && !$item->notes) if (!$item->cost && !$item->qty && !$item->product_key && !$item->notes)

View File

@ -356,13 +356,11 @@
@endif @endif
var $input = $('select#client'); var $input = $('select#client');
$input.combobox(); $input.combobox().on('change', function(e) {
$('.client_select input.form-control').on('change', function(e) {
var clientId = parseInt($('input[name=client]').val(), 10); var clientId = parseInt($('input[name=client]').val(), 10);
if (clientId > 0) { if (clientId > 0) {
model.loadClient(clientMap[clientId]); model.loadClient(clientMap[clientId]);
} else { } else {
//model.client.public_id(0); // TODO_FIX
model.loadClient(new ClientModel()); model.loadClient(new ClientModel());
} }
refreshPDF(); refreshPDF();
@ -609,7 +607,6 @@
return self.client.public_id() ? 'Edit client details' : 'Create new client'; return self.client.public_id() ? 'Edit client details' : 'Create new client';
}); });
self.showTaxesForm = function() { self.showTaxesForm = function() {
self.taxBackup = ko.mapping.toJS(self.tax_rates); self.taxBackup = ko.mapping.toJS(self.tax_rates);
@ -621,21 +618,8 @@
$('#taxModal').modal('hide'); $('#taxModal').modal('hide');
} }
self.showClientForm = function() { self.showClientForm = function() {
self.clientBackup = ko.mapping.toJS(self.client); 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" ); $('#emailError').css( "display", "none" );
$('#clientModal').modal('show'); $('#clientModal').modal('show');
@ -651,7 +635,6 @@
return; return;
} }
$('select#client').combobox('setSelected');
if (self.client.public_id() == 0) { if (self.client.public_id() == 0) {
self.client.public_id(-1); self.client.public_id(-1);
} }
@ -664,11 +647,13 @@
name = email; name = email;
} }
$('.client_select select').combobox('setSelected');
$('.client_select input.form-control').val(name); $('.client_select input.form-control').val(name);
$('.client_select .combobox-container').addClass('combobox-selected'); $('.client_select .combobox-container').addClass('combobox-selected');
$('#emailError').css( "display", "none" ); $('#emailError').css( "display", "none" );
$('.client_select input.form-control').focus(); //$('.client_select input.form-control').focus();
$('#terms').focus();
refreshPDF(); refreshPDF();
model.clientBackup = false; model.clientBackup = false;
@ -765,7 +750,7 @@
self.addContact = function() { self.addContact = function() {
var contact = new ContactModel(); var contact = new ContactModel();
console.log('num: ' + self.contacts().length); console.log('add contact: ' + self.contacts().length);
if (self.contacts().length == 0) { if (self.contacts().length == 0) {
contact.send_invoice(true); contact.send_invoice(true);
} }
@ -1020,6 +1005,7 @@
} }
@else @else
model.invoice_date('{{ date('Y-m-d') }}'); model.invoice_date('{{ date('Y-m-d') }}');
model.start_date('{{ date('Y-m-d') }}');
model.invoice_number('{{ $invoiceNumber }}'); model.invoice_number('{{ $invoiceNumber }}');
model.terms(wordWrapText('{{ $account->invoice_terms }}', 340)); model.terms(wordWrapText('{{ $account->invoice_terms }}', 340));
@endif @endif

View File

@ -333,9 +333,12 @@
case 37: // left arrow case 37: // left arrow
case 36: // home case 36: // home
case 35: // end case 35: // end
case 33: // page up
case 34: // page down
case 16: // shift case 16: // shift
case 17: // ctrl case 17: // ctrl
case 18: // alt case 18: // alt
case 20: // cap lock
break; break;
case 9: // tab case 9: // tab
@ -350,6 +353,7 @@
break; break;
default: default:
console.log('keyCode: %s', e.keyCode);
this.clearTarget(); this.clearTarget();
this.lookup(); this.lookup();
} }