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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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

View File

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