From ef24ac2c367438648cd998dc2378a66acdb29c6c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 29 Dec 2013 19:40:11 +0200 Subject: [PATCH] working on currency support --- README.md | 3 +- app/controllers/AccountController.php | 2 + app/controllers/ActivityController.php | 2 +- app/controllers/ClientController.php | 6 +- app/controllers/CreditController.php | 9 +- app/controllers/InvoiceController.php | 7 +- app/controllers/PaymentController.php | 7 +- ...11_05_180133_confide_setup_users_table.php | 61 ++- app/database/seeds/ConstantsSeeder.php | 4 + app/handlers/UserEventHandler.php | 1 + app/libraries/utils.php | 9 + app/models/Activity.php | 9 + app/models/Currency.php | 7 + app/ninja/repositories/AccountRepository.php | 1 + app/ninja/repositories/ClientRepository.php | 1 + app/ninja/repositories/InvoiceRepository.php | 7 +- app/routes.php | 2 + app/views/accounts/settings.blade.php | 4 +- app/views/clients/edit.blade.php | 2 + app/views/credits/edit.blade.php | 5 +- app/views/datatable.blade.php | 3 +- app/views/header.blade.php | 200 +-------- app/views/invoices/edit.blade.php | 21 +- app/views/payments/edit.blade.php | 6 +- public/css/style.css | 72 ++- public/js/accounting.js | 412 ++++++++++++++++++ public/js/script.js | 33 +- 27 files changed, 605 insertions(+), 291 deletions(-) create mode 100755 app/models/Currency.php create mode 100755 public/js/accounting.js diff --git a/README.md b/README.md index 0e2e66b4f660..204b31126349 100755 --- a/README.md +++ b/README.md @@ -57,4 +57,5 @@ Configure config/database.php and then initialize the database * [briannesbitt/Carbon](https://github.com/briannesbitt/Carbon) - A simple API extension for DateTime with PHP 5.3+ * [thomaspark/bootswatch](https://github.com/thomaspark/bootswatch) - Themes for Bootstrap * [mozilla/pdf.js](https://github.com/mozilla/pdf.js) - PDF Reader in JavaScript -* [nnnick/Chart.js](https://github.com/nnnick/Chart.js) - Simple HTML5 Charts using the tag \ No newline at end of file +* [nnnick/Chart.js](https://github.com/nnnick/Chart.js) - Simple HTML5 Charts using the tag +* [josscrowcroft/accounting.js](https://github.com/josscrowcroft/accounting.js) - A lightweight JavaScript library for number, money and currency formatting \ No newline at end of file diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index fef5820e2573..52cfa0e5a655 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -92,6 +92,7 @@ class AccountController extends \BaseController { 'timezones' => Timezone::orderBy('location')->get(), 'dateFormats' => DateFormat::all(), 'datetimeFormats' => DatetimeFormat::all(), + 'currencies' => Currency::orderBy('name')->get(), ]; foreach ($data['gateways'] as $gateway) @@ -406,6 +407,7 @@ class AccountController extends \BaseController { $account->timezone_id = Input::get('timezone_id') ? Input::get('timezone_id') : null; $account->date_format_id = Input::get('date_format_id') ? Input::get('date_format_id') : null; $account->datetime_format_id = Input::get('datetime_format_id') ? Input::get('datetime_format_id') : null; + $account->currency_id = Input::get('currency_id') ? Input::get('currency_id') : null; $account->invoice_terms = Input::get('invoice_terms'); $account->save(); diff --git a/app/controllers/ActivityController.php b/app/controllers/ActivityController.php index 69404ab6277e..fe006a653c18 100755 --- a/app/controllers/ActivityController.php +++ b/app/controllers/ActivityController.php @@ -9,7 +9,7 @@ class ActivityController extends \BaseController { return Datatable::collection(Activity::scope()->where('client_id','=',$clientId)->get()) ->addColumn('date', function($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); }) ->addColumn('message', function($model) { return $model->message; }) - ->addColumn('balance', function($model) { return '$' . $model->balance; }) + ->addColumn('balance', function($model) { return Utils::formatMoney($model->balance, $model->account->currency_id); }) ->orderColumns('date') ->make(); } diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index ca59143bad4f..a8c778226c47 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -26,7 +26,7 @@ class ClientController extends \BaseController { ->where('clients.account_id', '=', Auth::user()->account_id) ->where('clients.deleted_at', '=', null) ->where('contacts.is_primary', '=', true) - ->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','clients.work_phone','contacts.email'); + ->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','clients.work_phone','contacts.email','clients.currency_id'); $filter = Input::get('sSearch'); if ($filter) @@ -51,7 +51,7 @@ class ClientController extends \BaseController { ->addColumn('email', function($model) { return $model->email ? HTML::mailto($model->email, $model->email) : ''; }) ->addColumn('work_phone', function($model) { return Utils::formatPhoneNumber($model->work_phone); }) ->addColumn('last_login', function($model) { return Utils::timestampToDateString($model->last_login); }) - ->addColumn('balance', function($model) { return '$' . $model->balance; }) + ->addColumn('balance', function($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) ->addColumn('dropdown', function($model) { return '