From fff1aa69d3bdbc33774e7e3ac405331a48c2d88c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 1 Jan 2014 01:50:13 +0200 Subject: [PATCH] bug fixes --- app/controllers/AccountController.php | 11 +-- app/controllers/ClientController.php | 4 +- app/controllers/CreditController.php | 6 +- app/controllers/InvoiceController.php | 9 +- app/controllers/PaymentController.php | 8 +- app/controllers/ReportController.php | 12 +-- ...11_05_180133_confide_setup_users_table.php | 20 ++--- app/database/seeds/ConstantsSeeder.php | 2 +- app/filters.php | 2 +- app/libraries/utils.php | 35 +++++--- app/ninja/repositories/InvoiceRepository.php | 10 ++- app/routes.php | 11 +-- app/views/credits/edit.blade.php | 7 +- app/views/header.blade.php | 26 ++++-- app/views/invoices/edit.blade.php | 85 +++++++++++++------ app/views/payments/edit.blade.php | 7 +- app/views/reports/report_builder.blade.php | 3 +- public/css/style.css | 10 +-- 18 files changed, 166 insertions(+), 102 deletions(-) diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 762be28a2852..911f70cee45a 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -506,10 +506,10 @@ class AccountController extends \BaseController { public function submitSignup() { $rules = array( - 'first_name' => 'required', - 'last_name' => 'required', - 'password' => 'required|min:6', - 'email' => 'email|required' + 'new_first_name' => 'required', + 'new_last_name' => 'required', + 'new_password' => 'required|min:6', + 'new_email' => 'email|required' ); $validator = Validator::make(Input::all(), $rules); @@ -528,7 +528,8 @@ class AccountController extends \BaseController { $user->save(); $activities = Activity::scope()->get(); - foreach ($activities as $activity) { + foreach ($activities as $activity) + { $activity->message = str_replace('Guest', $user->getFullName(), $activity->message); $activity->save(); } diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index 8f8b381d7e64..a61eba49f334 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -114,11 +114,11 @@ class ClientController extends \BaseController { public function show($publicId) { $client = Client::scope($publicId)->with('contacts', 'client_size', 'client_industry')->firstOrFail(); - Utils::trackViewed($client->name, ENTITY_CLIENT); + Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT); $data = array( 'client' => $client, - 'title' => '- ' . $client->name, + 'title' => '- ' . $client->getDisplayName(), 'hasRecurringInvoices' => Invoice::scope()->where('is_recurring', '=', true)->whereClientId($client->id)->count() > 0 ); diff --git a/app/controllers/CreditController.php b/app/controllers/CreditController.php index 27aa916136fe..4eafdc404004 100755 --- a/app/controllers/CreditController.php +++ b/app/controllers/CreditController.php @@ -85,6 +85,8 @@ class CreditController extends \BaseController { public function edit($publicId) { $credit = Credit::scope($publicId)->firstOrFail(); + $credit->credit_date = Utils::fromSqlDate($credit->credit_date); + $data = array( 'client' => null, 'credit' => $credit, @@ -126,7 +128,7 @@ class CreditController extends \BaseController { $credit = Credit::createNew(); } - $credit->client_id = Input::get('client'); + $credit->client_id = Client::getPrivateId(Input::get('client')); $credit->credit_date = Utils::toSqlDate(Input::get('credit_date')); $credit->amount = floatval(Input::get('amount')); $credit->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null; @@ -134,7 +136,7 @@ class CreditController extends \BaseController { $message = $publicId ? 'Successfully updated credit' : 'Successfully created credit'; Session::flash('message', $message); - return Redirect::to('clients/' . $credit->client_id); + return Redirect::to('clients/' . Input::get('client')); } } diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index a44d869f9215..f4501c4bbbd3 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -300,8 +300,13 @@ class InvoiceController extends \BaseController { public function edit($publicId) { $invoice = Invoice::scope($publicId)->with('account.country', 'client', 'invoice_items')->firstOrFail(); - Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->name, ENTITY_INVOICE); + Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->getDisplayName(), ENTITY_INVOICE); + $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); + $invoice->due_date = Utils::fromSqlDate($invoice->due_date); + $invoice->start_date = Utils::fromSqlDate($invoice->start_date); + $invoice->end_date = Utils::fromSqlDate($invoice->end_date); + $contactIds = DB::table('invitations') ->join('contacts', 'contacts.id', '=','invitations.contact_id') ->where('invitations.invoice_id', '=', $invoice->id) @@ -453,7 +458,7 @@ class InvoiceController extends \BaseController { { $message = ' and created client'; $url = URL::to('clients/' . $client->public_id); - Utils::trackViewed($client->name, ENTITY_CLIENT, $url); + Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url); } if ($action == 'clone') diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index 915f5677b84a..6790f5a3921b 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -89,6 +89,8 @@ class PaymentController extends \BaseController public function edit($publicId) { $payment = Payment::scope($publicId)->firstOrFail(); + $payment->payment_date = Utils::fromSqlDate($payment->payment_date); + $data = array( 'client' => null, 'invoice' => null, @@ -132,9 +134,9 @@ class PaymentController extends \BaseController $payment = Payment::createNew(); } - $invoiceId = Input::get('invoice') && Input::get('invoice') != "-1" ? Input::get('invoice') : null; + $invoiceId = Input::get('invoice') && Input::get('invoice') != "-1" ? Invoice::getPrivateId(Input::get('invoice')) : null; - $payment->client_id = Input::get('client'); + $payment->client_id = Client::getPrivateId(Input::get('client')); $payment->invoice_id = $invoiceId; $payment->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null; $payment->payment_date = Utils::toSqlDate(Input::get('payment_date')); @@ -143,7 +145,7 @@ class PaymentController extends \BaseController $message = $publicId ? 'Successfully updated payment' : 'Successfully created payment'; Session::flash('message', $message); - return Redirect::to('clients/' . $payment->client_id); + return Redirect::to('clients/' . Input::get('client')); } } diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index 7a9f54984bbb..9428a47b11a8 100755 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -8,15 +8,15 @@ class ReportController extends \BaseController { { $groupBy = Input::get('group_by'); $chartType = Input::get('chart_type'); - $startDate = date_create(Input::get('start_date')); - $endDate = date_create(Input::get('end_date')); + $startDate = Utils::toSqlDate(Input::get('start_date'), false); + $endDate = Utils::toSqlDate(Input::get('end_date'), false); } else { $groupBy = 'MONTH'; $chartType = 'Bar'; - $startDate = date_create()->modify('-3 month'); - $endDate = date_create(); + $startDate = Utils::today(false)->modify('-3 month'); + $endDate = Utils::today(false); } $padding = $groupBy == 'DAYOFYEAR' ? 'day' : ($groupBy == 'WEEK' ? 'week' : 'month'); @@ -90,8 +90,8 @@ class ReportController extends \BaseController { 'dateTypes' => $dateTypes, 'chartTypes' => $chartTypes, 'chartType' => $chartType, - 'startDate' => $startDate->format('m/d/Y'), - 'endDate' => $endDate->modify('-1'.$padding)->format('m/d/Y'), + 'startDate' => $startDate->format(Session::get(SESSION_DATE_FORMAT)), + 'endDate' => $endDate->modify('-1'.$padding)->format(Session::get(SESSION_DATE_FORMAT)), 'groupBy' => $groupBy ]; 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 7467daa49a63..7fdc6e95ae11 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 @@ -233,8 +233,8 @@ class ConfideSetupUsersTable extends Migration { $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'); + $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $t->foreign('country_id')->references('id')->on('countries'); $t->foreign('client_industry_id')->references('id')->on('client_industries'); $t->foreign('client_size_id')->references('id')->on('client_sizes'); @@ -262,7 +262,7 @@ class ConfideSetupUsersTable extends Migration { $t->timestamp('last_login'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->unsignedInteger('public_id'); $t->unique( array('account_id','public_id') ); @@ -314,7 +314,7 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('account_id')->references('id')->on('accounts'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->foreign('invoice_status_id')->references('id')->on('invoice_statuses'); $t->foreign('currency_id')->references('id')->on('currencies'); $t->foreign('recurring_invoice_id')->references('id')->on('invoices'); @@ -338,7 +338,7 @@ class ConfideSetupUsersTable extends Migration { $t->timestamp('sent_date'); $t->timestamp('viewed_date'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); @@ -358,7 +358,7 @@ class ConfideSetupUsersTable extends Migration { $t->decimal('rate', 13, 4); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->unsignedInteger('public_id'); $t->unique( array('account_id','public_id') ); @@ -378,7 +378,7 @@ class ConfideSetupUsersTable extends Migration { $t->decimal('qty', 13, 4); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->unsignedInteger('public_id'); $t->unique( array('account_id','public_id') ); @@ -405,7 +405,7 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); $t->foreign('product_id')->references('id')->on('products'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->unsignedInteger('public_id'); $t->unique( array('account_id','public_id') ); @@ -434,7 +434,7 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('account_id')->references('id')->on('accounts'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('contact_id')->references('id')->on('contacts'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->foreign('currency_id')->references('id')->on('currencies'); $t->unsignedInteger('public_id')->index(); @@ -460,7 +460,7 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('account_id')->references('id')->on('accounts'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('contact_id')->references('id')->on('contacts'); - $t->foreign('user_id')->references('id')->on('users'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');; $t->foreign('currency_id')->references('id')->on('currencies'); $t->unsignedInteger('public_id')->index(); diff --git a/app/database/seeds/ConstantsSeeder.php b/app/database/seeds/ConstantsSeeder.php index e77ba168e19a..2fcbf56802a0 100755 --- a/app/database/seeds/ConstantsSeeder.php +++ b/app/database/seeds/ConstantsSeeder.php @@ -83,7 +83,7 @@ class ConstantsSeeder extends Seeder DatetimeFormat::create(array('format' => 'D M jS, Y g:ia', 'label' => 'Mon March 10th, 2013, 6:15 pm')); DateFormat::create(array('format' => 'F j, Y', 'picker_format' => 'MM d, yyyy', 'label' => 'March 10, 2013')); - DateFormat::create(array('format' => 'D M jS, Y', 'picker_format' => 'D MM d, yyyy', 'label' => 'Mon March 10th, 2013')); + DateFormat::create(array('format' => 'D M j, Y', 'picker_format' => 'D MM d, yyyy', 'label' => 'Mon March 10, 2013')); /* d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05. diff --git a/app/filters.php b/app/filters.php index 740b37e4365b..51c8537b298f 100755 --- a/app/filters.php +++ b/app/filters.php @@ -35,7 +35,7 @@ App::after(function($request, $response) Route::filter('auth', function() { - if (Auth::guest()) return Redirect::guest('login'); + if (Auth::guest()) return Redirect::guest('/'); }); diff --git a/app/libraries/utils.php b/app/libraries/utils.php index d79c0e611310..695c697c3f7e 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -107,13 +107,10 @@ class Utils return null; } - /* - $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE); - $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT); - return DateTime::createFromFormat($format, $date, new DateTimeZone($timezone)); - */ + $timezone = Session::get(SESSION_TIMEZONE); + $format = Session::get(SESSION_DATE_FORMAT); - return DateTime::createFromFormat('Y-m-d', $date); + return DateTime::createFromFormat($format, $date, new DateTimeZone($timezone)); } public static function fromSqlDate($date) @@ -123,14 +120,26 @@ class Utils return ''; } - /* - $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE); + $timezone = Session::get(SESSION_TIMEZONE); + $format = Session::get(SESSION_DATE_FORMAT); + return DateTime::createFromFormat('Y-m-d', $date, new DateTimeZone($timezone))->format($format); - */ - - $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT); - - return DateTime::createFromFormat('Y-m-d', $date)->format($format); + } + + public static function today($formatResult = true) + { + $timezone = Session::get(SESSION_TIMEZONE); + $format = Session::get(SESSION_DATE_FORMAT); + $date = date_create(null, new DateTimeZone($timezone)); + + if ($formatResult) + { + return $date->format($format); + } + else + { + return $date; + } } public static function trackViewed($name, $type, $url = false) diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index 1daaff723189..70429fd0e60f 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -93,14 +93,18 @@ class InvoiceRepository $invoice->public_notes = trim($data['public_notes']); $invoice->po_number = trim($data['po_number']); $invoice->currency_id = $data['currency_id']; - $invoice->tax_rate = 0; - + if (isset($data['tax']) && isset($data['tax']->rate) && floatval($data['tax']->rate) > 0) { $invoice->tax_rate = floatval($data['tax']->rate); $invoice->tax_name = trim($data['tax']->name); + } + else + { + $invoice->tax_rate = 0; + $invoice->tax_name = ''; } - + $invoice->save(); $invoice->invoice_items()->forceDelete(); diff --git a/app/routes.php b/app/routes.php index 91bbc3e01993..8440f73a83d1 100755 --- a/app/routes.php +++ b/app/routes.php @@ -47,14 +47,6 @@ Route::post('forgot_password', 'UserController@do_forgot_password'); Route::get('logout', 'UserController@logout'); -Route::filter('auth', function() -{ - if (!Auth::check()) - { - return Redirect::to('/'); - } -}); - Route::group(array('before' => 'auth'), function() { Route::get('home', function() { return View::make('header'); }); @@ -178,7 +170,6 @@ define('SESSION_DATETIME_FORMAT', 'datetimeFormat'); define('DEFAULT_TIMEZONE', 'US/Eastern'); define('DEFAULT_CURRENCY', 1); // US Dollar define('DEFAULT_DATE_FORMAT', 'M j, Y'); -define('DEFAULT_DATE_PICKER_FORMAT', 'yyyy-mm-dd'); +define('DEFAULT_DATE_PICKER_FORMAT', 'M d, yyyy'); define('DEFAULT_DATETIME_FORMAT', 'F j, Y, g:i a'); - define('DEFAULT_QUERY_CACHE', 120); \ No newline at end of file diff --git a/app/views/credits/edit.blade.php b/app/views/credits/edit.blade.php index f92823a5e1b4..127ef900369b 100755 --- a/app/views/credits/edit.blade.php +++ b/app/views/credits/edit.blade.php @@ -16,7 +16,7 @@ @if ($credit) {{ Former::populate($credit) }} @else - {{ Former::populateField('credit_date', date('Y-m-d')) }} + {{ Former::populateField('credit_date', Utils::today()) }} @endif @@ -31,7 +31,7 @@ {{ Former::select('client')->addOption('', '')->addGroupClass('client-select') }} {{ Former::text('amount') }} - {{ Former::text('credit_date')->data_date_format(DEFAULT_DATE_PICKER_FORMAT) }} + {{ Former::text('credit_date')->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT)) }} {{ Former::select('currency_id')->addOption('','')->label('Currency') ->fromQuery($currencies, 'name', 'id')->select(Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY)) }} @@ -68,7 +68,8 @@ $('#credit_date').datepicker({ autoclose: true, - todayHighlight: true + todayHighlight: true, + keyboardNavigation: false }); }); diff --git a/app/views/header.blade.php b/app/views/header.blade.php index 6e25c3a6ee5c..c9bea44aec49 100755 --- a/app/views/header.blade.php +++ b/app/views/header.blade.php @@ -167,7 +167,7 @@ {{ Former::close() }} - Need something changed? We're {{ link_to('https://github.com/hillelcoren/invoice-ninja', 'open source', array('target'=>'_blank')) }}, email us at {{ link_to('mailto:contact@invoiceninja.com', 'contact@invoiceninja.com') }}. + Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice-ninja', 'open source', array('target'=>'_blank')) }}, email us at {{ link_to('mailto:contact@invoiceninja.com', 'contact@invoiceninja.com') }}.

This is a demo site, the data is erased.

@@ -185,15 +185,19 @@
+ {{ Former::open('signup/submit')->addClass('signUpForm') }} + @if (Auth::check()) - {{ Former::populate(Auth::user()) }} + {{ Former::populateField('new_first_name', Auth::user()->first_name); }} + {{ Former::populateField('new_last_name', Auth::user()->last_name); }} + {{ Former::populateField('new_email', Auth::user()->email); }} @endif {{ Former::hidden('path')->value(Request::path()) }} - {{ Former::text('first_name') }} - {{ Former::text('last_name') }} - {{ Former::text('email') }} - {{ Former::password('password') }} + {{ Former::text('new_first_name')->label('First name') }} + {{ Former::text('new_last_name')->label('Last name') }} + {{ Former::text('new_email')->label('Email') }} + {{ Former::password('new_password')->label('Password') }} {{ Former::close() }}
@@ -224,7 +228,7 @@

Are you sure?

-

This will erase all of your data.

+

This will permanently erase your data.