From 9dd1b54d4a531526b2f22a0d9d8d778006ef7e44 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 31 Dec 2013 11:43:39 +0200 Subject: [PATCH] bug fixes --- app/commands/SendRecurringInvoices.php | 4 +-- app/controllers/ClientController.php | 3 ++ app/controllers/InvoiceController.php | 3 +- ...11_05_180133_confide_setup_users_table.php | 13 ++++++-- app/database/seeds/ConstantsSeeder.php | 8 ++++- app/models/Account.php | 1 - app/models/AccountGateway.php | 2 -- app/models/Activity.php | 4 +-- app/models/Client.php | 2 -- app/models/Contact.php | 2 -- app/models/Credit.php | 2 +- app/models/Currency.php | 2 +- app/models/EntityModel.php | 2 -- app/models/Invitation.php | 2 -- app/models/Invoice.php | 2 -- app/models/PaymentTerm.php | 7 ++++ app/models/Product.php | 2 +- app/models/TaxRate.php | 1 - app/models/User.php | 2 -- app/ninja/repositories/ClientRepository.php | 3 +- app/views/clients/edit.blade.php | 2 ++ app/views/clients/show.blade.php | 7 ++-- app/views/header.blade.php | 11 ++----- app/views/invoices/edit.blade.php | 33 ++++++++++++++----- app/views/invoices/view.blade.php | 4 +-- public/js/script.js | 9 +++-- 26 files changed, 79 insertions(+), 54 deletions(-) create mode 100755 app/models/PaymentTerm.php diff --git a/app/commands/SendRecurringInvoices.php b/app/commands/SendRecurringInvoices.php index 926e89dda770..38aca636a242 100755 --- a/app/commands/SendRecurringInvoices.php +++ b/app/commands/SendRecurringInvoices.php @@ -42,8 +42,8 @@ class SendRecurringInvoices extends Command { $invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber(); $invoice->amount = $recurInvoice->amount; $invoice->currency_id = $recurInvoice->currency_id; - $invoice->invoice_date = new DateTime(); - $invoice->due_date = new DateTime(); + $invoice->invoice_date = date_create(); + $invoice->due_date = date_create()->modify($invoice->client->payment_terms . ' day'); $invoice->save(); foreach ($recurInvoice->invoice_items as $recurItem) diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index 563c274085d6..8f8b381d7e64 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -88,6 +88,7 @@ class ClientController extends \BaseController { 'title' => '- New Client', 'clientSizes' => ClientSize::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'clientIndustries' => ClientIndustry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), + 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get()); @@ -139,6 +140,7 @@ class ClientController extends \BaseController { 'url' => 'clients/' . $publicId, 'title' => '- ' . $client->name, 'clientSizes' => ClientSize::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'clientIndustries' => ClientIndustry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get()); @@ -187,6 +189,7 @@ class ClientController extends \BaseController { $client->client_size_id = Input::get('client_size_id') ? Input::get('client_size_id') : null; $client->client_industry_id = Input::get('client_industry_id') ? Input::get('client_industry_id') : null; $client->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null; + $client->payment_terms = Input::get('payment_terms'); $client->website = trim(Input::get('website')); $client->save(); diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 3f4572ec634b..38b6853ae9fd 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -116,7 +116,7 @@ class InvoiceController extends \BaseController { public function view($invitationKey) { - $invitation = Invitation::with('user', 'invoice.account', 'invoice.client', 'invoice.invoice_items', 'invoice.client.account.account_gateways') + $invitation = Invitation::with('user', 'invoice.invoice_items', 'invoice.client.account', 'invoice.client.contacts') ->where('invitation_key', '=', $invitationKey)->firstOrFail(); $user = $invitation->user; @@ -350,6 +350,7 @@ class InvoiceController extends \BaseController { 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clientSizes' => ClientSize::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'clientIndustries' => ClientIndustry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'frequencies' => array( 1 => 'Weekly', 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 b018da3b47d0..7e9c948241c2 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 @@ -9,7 +9,8 @@ class ConfideSetupUsersTable extends Migration { * @return void */ public function up() - { + { + Schema::dropIfExists('payment_terms'); Schema::dropIfExists('themes'); Schema::dropIfExists('credits'); Schema::dropIfExists('activities'); @@ -60,6 +61,13 @@ class ConfideSetupUsersTable extends Migration { $t->string('name'); }); + Schema::create('payment_terms', function($t) + { + $t->increments('id'); + $t->integer('num_days'); + $t->string('name'); + }); + Schema::create('timezones', function($t) { $t->increments('id'); @@ -220,6 +228,7 @@ class ConfideSetupUsersTable extends Migration { $t->unsignedInteger('client_industry_id')->nullable(); $t->unsignedInteger('client_size_id')->nullable(); $t->boolean('is_deleted'); + $t->integer('payment_terms'); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $t->foreign('user_id')->references('id')->on('users'); @@ -293,7 +302,6 @@ class ConfideSetupUsersTable extends Migration { $t->date('end_date')->nullable(); $t->timestamp('last_sent_date')->nullable(); $t->unsignedInteger('recurring_invoice_id')->index()->nullable(); - $t->decimal('amount', 13, 4); $t->decimal('balance', 13, 4); @@ -486,6 +494,7 @@ class ConfideSetupUsersTable extends Migration { */ public function down() { + Schema::dropIfExists('payment_terms'); Schema::dropIfExists('themes'); Schema::dropIfExists('credits'); Schema::dropIfExists('activities'); diff --git a/app/database/seeds/ConstantsSeeder.php b/app/database/seeds/ConstantsSeeder.php index fc8693a8b1c7..e77ba168e19a 100755 --- a/app/database/seeds/ConstantsSeeder.php +++ b/app/database/seeds/ConstantsSeeder.php @@ -69,10 +69,16 @@ class ConstantsSeeder extends Seeder ClientSize::create(array('name' => '101 - 500')); ClientSize::create(array('name' => '500+')); + PaymentTerm::create(array('num_days' => 7, 'name' => 'Net 7')); + PaymentTerm::create(array('num_days' => 10, 'name' => 'Net 10')); + PaymentTerm::create(array('num_days' => 14, 'name' => 'Net 14')); + PaymentTerm::create(array('num_days' => 15, 'name' => 'Net 15')); + PaymentTerm::create(array('num_days' => 30, 'name' => 'Net 30')); + PaymentTerm::create(array('num_days' => 60, 'name' => 'Net 60')); + Currency::create(array('name' => 'US Dollar', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.')); Currency::create(array('name' => 'Pound Sterling', 'symbol' => '£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.')); - DatetimeFormat::create(array('format' => 'F j, Y, g:i a', 'label' => 'March 10, 2013, 6:15 pm')); DatetimeFormat::create(array('format' => 'D M jS, Y g:ia', 'label' => 'Mon March 10th, 2013, 6:15 pm')); diff --git a/app/models/Account.php b/app/models/Account.php index 32fb275172a9..b73830c008fd 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -3,7 +3,6 @@ class Account extends Eloquent { protected $softDelete = true; - protected $hidden = array('ip', 'timezone_id', 'created_at', 'updated_at', 'deleted_at', 'key', 'last_login'); public function users() { diff --git a/app/models/AccountGateway.php b/app/models/AccountGateway.php index a9fb45a209c1..a49d922f3e6a 100755 --- a/app/models/AccountGateway.php +++ b/app/models/AccountGateway.php @@ -2,8 +2,6 @@ class AccountGateway extends Eloquent { - protected $hidden = array('config'); - public function gateway() { return $this->belongsTo('Gateway'); diff --git a/app/models/Activity.php b/app/models/Activity.php index 4e6e37193f97..4e5d79743566 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -20,8 +20,6 @@ define("ACTIVITY_TYPE_DELETE_CREDIT", 15); class Activity extends Eloquent { - protected $hidden = array('id'); - public function scopeScope($query) { return $query->whereAccountId(Auth::user()->account_id); @@ -121,7 +119,7 @@ class Activity extends Eloquent $activity->invoice_id = $invitation->invoice_id; $activity->contact_id = $invitation->contact_id; $activity->activity_type_id = ACTIVITY_TYPE_EMAIL_INVOICE; - $activity->message = $userName . ' emailed invoice ' . link_to('invoices/'.$invitation->invoice->public_id, $invitation->invoice->invoice_number) . ' to ' . $invitation->contact->getFullName(); + $activity->message = $userName . ' emailed invoice ' . link_to('invoices/'.$invitation->invoice->public_id, $invitation->invoice->invoice_number) . ' to ' . $invitation->contact->getFullName() . ' - ' . $invitation->contact->email; $activity->balance = $invitation->invoice->client->balance; $activity->adjustment = $adjustment; $activity->save(); diff --git a/app/models/Client.php b/app/models/Client.php index f97fb5b7c5bc..ec0235ec73e9 100755 --- a/app/models/Client.php +++ b/app/models/Client.php @@ -2,8 +2,6 @@ class Client extends EntityModel { - protected $hidden = array('id', 'account_id', 'created_at', 'updated_at', 'deleted_at', 'private_notes', 'last_login'); - public static $fieldName = 'Client - Name'; public static $fieldPhone = 'Client - Phone'; public static $fieldAddress1 = 'Client - Street'; diff --git a/app/models/Contact.php b/app/models/Contact.php index 38760083da2c..0904a3bf232f 100755 --- a/app/models/Contact.php +++ b/app/models/Contact.php @@ -2,8 +2,6 @@ class Contact extends EntityModel { - protected $hidden = array('id', 'cliend_id', 'created_at', 'updated_at', 'deleted_at', 'last_login'); - public static $fieldFirstName = 'Contact - First Name'; public static $fieldLastName = 'Contact - Last Name'; public static $fieldEmail = 'Contact - Email'; diff --git a/app/models/Credit.php b/app/models/Credit.php index 63ae1553e9cb..c96d29fb2bc2 100755 --- a/app/models/Credit.php +++ b/app/models/Credit.php @@ -1,7 +1,7 @@ belongsTo('Invoice'); diff --git a/app/models/Currency.php b/app/models/Currency.php index a024236f3427..83c8c89f1a24 100755 --- a/app/models/Currency.php +++ b/app/models/Currency.php @@ -3,5 +3,5 @@ class Currency extends Eloquent { public $timestamps = false; - protected $softDelete = false; + protected $softDelete = false; } \ No newline at end of file diff --git a/app/models/EntityModel.php b/app/models/EntityModel.php index cc54bec8e784..286cac0c2e01 100755 --- a/app/models/EntityModel.php +++ b/app/models/EntityModel.php @@ -3,8 +3,6 @@ class EntityModel extends Eloquent { protected $softDelete = true; - protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at'); - public static function createNew($parent = false) { $className = get_called_class(); diff --git a/app/models/Invitation.php b/app/models/Invitation.php index b556b1c7ae60..d3097683310c 100755 --- a/app/models/Invitation.php +++ b/app/models/Invitation.php @@ -2,8 +2,6 @@ class Invitation extends EntityModel { - protected $hidden = array('id', 'account_id', 'user_id', 'contact_id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date'); - public function invoice() { return $this->belongsTo('Invoice'); diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 5fc3d8d5674c..0efc28aca0ed 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -2,8 +2,6 @@ class Invoice extends EntityModel { - protected $hidden = array('id', 'account_id', 'client_id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date'); - public function account() { return $this->belongsTo('Account'); diff --git a/app/models/PaymentTerm.php b/app/models/PaymentTerm.php new file mode 100755 index 000000000000..c93379f53de6 --- /dev/null +++ b/app/models/PaymentTerm.php @@ -0,0 +1,7 @@ +where('product_key','=',$key)->first(); diff --git a/app/models/TaxRate.php b/app/models/TaxRate.php index 692686b07f37..c30d0d1d8569 100755 --- a/app/models/TaxRate.php +++ b/app/models/TaxRate.php @@ -2,6 +2,5 @@ class TaxRate extends EntityModel { - } \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index b7f1ab07d827..94da1b98ef52 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -6,9 +6,7 @@ use Zizaco\Confide\ConfideUser; class User extends ConfideUser implements UserInterface, RemindableInterface { - protected $softDelete = true; - protected $hidden = array('created_at', 'updated_at', 'deleted_at', 'password', 'confirmation_code', 'registered', 'confirmed'); public static $rules = array( /* diff --git a/app/ninja/repositories/ClientRepository.php b/app/ninja/repositories/ClientRepository.php index d3a62975d2c8..7b92d376a48e 100755 --- a/app/ninja/repositories/ClientRepository.php +++ b/app/ninja/repositories/ClientRepository.php @@ -31,6 +31,7 @@ class ClientRepository $client->client_size_id = $data['client_size_id'] ? $data['client_size_id'] : null; $client->client_industry_id = $data['client_industry_id'] ? $data['client_industry_id'] : null; $client->currency_id = $data['currency_id'] ? $data['currency_id'] : null; + $client->payment_terms = $data['payment_terms']; $client->website = trim($data['website']); $client->save(); @@ -41,7 +42,7 @@ class ClientRepository { $record = (array) $record; - if (isset($record['public_id']) && $record['public_id']) + if ($publicId != "-1" && isset($record['public_id']) && $record['public_id']) { $contact = Contact::scope($record['public_id'])->firstOrFail(); } diff --git a/app/views/clients/edit.blade.php b/app/views/clients/edit.blade.php index 31444eb2c73a..bd1285cbb1d8 100755 --- a/app/views/clients/edit.blade.php +++ b/app/views/clients/edit.blade.php @@ -44,6 +44,8 @@ {{ Former::legend('Additional Info') }} + {{ Former::select('payment_terms')->addOption('','') + ->fromQuery($paymentTerms, 'name', 'num_days') }} {{ Former::select('currency_id')->addOption('','')->label('Currency') ->fromQuery($currencies, 'name', 'id')->select(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY)) }} {{ Former::select('client_size_id')->addOption('','')->label('Size') diff --git a/app/views/clients/show.blade.php b/app/views/clients/show.blade.php index d498c229a47b..90000042b3ec 100755 --- a/app/views/clients/show.blade.php +++ b/app/views/clients/show.blade.php @@ -35,10 +35,10 @@ -

{{ $client->name }}

+

{{ $client->getDisplayName() }}

@if ($client->last_login > 0)

- Last logged in {{ Utils::timestampToDateTimeString($client->last_login); }} + Last logged in {{ Utils::timestampToDateTimeString(strtotime($client->last_login)); }}

@endif @@ -50,7 +50,8 @@

{{ $client->getPhone() }}

{{ $client->getNotes() }}

{{ $client->getIndustry() }}

-

{{ $client->getWebsite() }} +

{{ $client->getWebsite() }}

+

{{ $client->payment_terms ? "Payment terms: Net " . $client->payment_terms : '' }}

diff --git a/app/views/header.blade.php b/app/views/header.blade.php index 8c38327bcaf7..6e25c3a6ee5c 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -66,13 +66,8 @@ @section('body')
-

-

- Invoice Ninja - -
- -

+

 

+

 

diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index d26d591c5935..d286c0311f62 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -123,16 +123,16 @@ ->raw()->data_bind("value: product_key, valueUpdate: 'afterkeydown'")->addClass('datalist') }} - + - + - + - + @@ -242,6 +242,8 @@
{{ Former::legend('Additional Info') }} + {{ Former::select('payment_terms')->addOption('','')->data_bind('value: payment_terms') + ->fromQuery($paymentTerms, 'name', 'num_days') }} {{ Former::select('currency_id')->addOption('','')->label('Currency')->data_bind('value: currency_id') ->fromQuery($currencies, 'name', 'id') }} {{ Former::select('client_size_id')->addOption('','')->label('Size')->data_bind('value: client_size_id') @@ -274,7 +276,7 @@ @@ -360,7 +362,8 @@ if (clientId > 0) { model.loadClient(clientMap[clientId]); } else { - model.client.public_id(0); // TODO_FIX + //model.client.public_id(0); // TODO_FIX + model.loadClient(new ClientModel()); } refreshPDF(); }).trigger('change'); @@ -408,7 +411,12 @@ }); function applyComboboxListeners() { - var value; + $('.invoice-table input, .invoice-table select, .invoice-table textarea').on('blur', function() { + //if (value != $(this).val()) refreshPDF(); + refreshPDF(); + }); + + var value; $('.datalist').on('focus', function() { value = $(this).val(); }).on('blur', function() { @@ -617,12 +625,18 @@ 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'); } @@ -735,6 +749,7 @@ self.client_industry_id = ko.observable(''); self.currency_id = ko.observable(''); self.website = ko.observable(''); + self.payment_terms = ko.observable(); self.contacts = ko.observableArray(); self.mapping = { diff --git a/app/views/invoices/view.blade.php b/app/views/invoices/view.blade.php index c446212b67cb..f5db4ec1cd9b 100755 --- a/app/views/invoices/view.blade.php +++ b/app/views/invoices/view.blade.php @@ -31,12 +31,10 @@ @endif var doc = generatePDF(invoice); var string = doc.output('datauristring'); - alert(isFirefox); - alert(isChrome); + if (isFirefox || isChrome) { $('#theFrame').attr('src', string).show(); } else { - alert(1); var pdfAsArray = convertDataURIToBinary(string); PDFJS.getDocument(pdfAsArray).then(function getPdfHelloWorld(pdf) { diff --git a/public/js/script.js b/public/js/script.js index 69d6096ac4a4..30e5a44547eb 100755 --- a/public/js/script.js +++ b/public/js/script.js @@ -631,8 +631,13 @@ ko.bindingHandlers.dropdown = { var value = ko.utils.unwrapObservable(valueAccessor()); var id = (value && value.public_id) ? value.public_id() : (value && value.id) ? value.id() : value ? value : false; console.log("combo-update: %s", id); - if (id) $(element).val(id); - $(element).combobox('refresh'); + if (id) { + $(element).val(id); + $(element).combobox('refresh'); + } else { + $(element).combobox('clearTarget'); + $(element).combobox('clearElement'); + } } };