From fe1362eef4ba1dad6ea4782d3f74c409ea4cda28 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sat, 7 Jul 2018 22:13:02 +0300 Subject: [PATCH] Changes for mobile app --- app/Http/Controllers/AccountApiController.php | 5 +- app/Http/Controllers/BaseAPIController.php | 2 +- .../Controllers/ClientPortalController.php | 2 +- app/Libraries/Utils.php | 34 ++++++- app/Models/Account.php | 5 ++ .../Transformers/UserAccountTransformer.php | 90 ++++++++++++++++++- resources/lang/en/texts.php | 1 + resources/views/accounts/management.blade.php | 2 + resources/views/clients/show.blade.php | 2 +- .../views/invoices/view_borderless.blade.php | 79 ++++++++++++++++ 10 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 resources/views/invoices/view_borderless.blade.php diff --git a/app/Http/Controllers/AccountApiController.php b/app/Http/Controllers/AccountApiController.php index 612c39856c1f..0b32f7bc4376 100644 --- a/app/Http/Controllers/AccountApiController.php +++ b/app/Http/Controllers/AccountApiController.php @@ -89,16 +89,17 @@ class AccountApiController extends BaseAPIController { // Create a new token only if one does not already exist $user = Auth::user(); + $account = $user->account; $this->accountRepo->createTokens($user, $request->token_name); $users = $this->accountRepo->findUsers($user, 'account.account_tokens'); - $transformer = new UserAccountTransformer($user->account, $request->serializer, $request->token_name); + $transformer = new UserAccountTransformer($account, $request->serializer, $request->token_name); $data = $this->createCollection($users, $transformer, 'user_account'); if (request()->include_static) { $data = [ 'accounts' => $data, - 'static' => Utils::getStaticData(), + 'static' => Utils::getStaticData($account->getLocale()), 'version' => NINJA_VERSION, ]; } diff --git a/app/Http/Controllers/BaseAPIController.php b/app/Http/Controllers/BaseAPIController.php index c534d6ae43ad..6b7c8bc4d77e 100644 --- a/app/Http/Controllers/BaseAPIController.php +++ b/app/Http/Controllers/BaseAPIController.php @@ -74,7 +74,7 @@ class BaseAPIController extends Controller $entity = $request->entity(); $action = $request->action; - if (! in_array($action, ['archive', 'delete', 'restore', 'mark_sent'])) { + if (! in_array($action, ['archive', 'delete', 'restore', 'mark_sent', 'markSent', 'emailInvoice', 'markPaid'])) { return $this->errorResponse("Action [$action] is not supported"); } diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 316508d6a2de..b774030b97c2 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -182,7 +182,7 @@ class ClientPortalController extends BaseController } } - return View::make('invoices.view', $data); + return View::make(request()->borderless ? 'invoices.view_borderless' : 'invoices.view', $data); } private function getPaymentTypes($account, $client, $invitation) diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 511d751c1180..8c4478567cc2 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -501,7 +501,7 @@ class Utils } } - public static function getStaticData() + public static function getStaticData($locale = false) { $data = []; @@ -510,6 +510,38 @@ class Utils $data[$name] = Cache::get($name); } + if ($locale) { + $data['industries'] = Cache::get('industries')->each(function ($industry) { + $industry->name = trans('texts.industry_'.$industry->name); + })->sortBy(function ($industry) { + return $industry->name; + }); + + $data['countries'] = Cache::get('countries')->each(function ($country) { + $country->name = trans('texts.country_'.$country->name); + })->sortBy(function ($country) { + return $country->name; + }); + + $data['paymentTypes'] = Cache::get('paymentTypes')->each(function ($pType) { + $pType->name = trans('texts.payment_type_'.$pType->name); + })->sortBy(function ($pType) { + return $pType->name; + }); + + $data['languages'] = Cache::get('languages')->each(function ($lang) { + $lang->name = trans('texts.lang_'.$lang->name); + })->sortBy(function ($lang) { + return $lang->name; + }); + + $data['currencies'] = Cache::get('currencies')->each(function ($currency) { + $currency->name = trans('texts.currency_' . Str::slug($currency->name, '_')); + })->sortBy(function ($currency) { + return $currency->name; + }); + } + return $data; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 6e2644ea05e0..9aa5c61f716a 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1500,6 +1500,11 @@ class Account extends Eloquent return $this->getGatewayConfig($gatewayId); } + public function getLocale() + { + return $this->language_id && $this->language ? $this->language->locale : DEFAULT_LOCALE; + } + /** * @return bool */ diff --git a/app/Ninja/Transformers/UserAccountTransformer.php b/app/Ninja/Transformers/UserAccountTransformer.php index 5d3b5d3acecd..e681b29e623d 100644 --- a/app/Ninja/Transformers/UserAccountTransformer.php +++ b/app/Ninja/Transformers/UserAccountTransformer.php @@ -7,10 +7,61 @@ use App\Models\User; class UserAccountTransformer extends EntityTransformer { + /** + * @SWG\Property(property="account_key", type="string", example="123456") + * @SWG\Property(property="name", type="string", example="John Doe") + * @SWG\Property(property="token", type="string", example="Token") + * @SWG\Property(property="default_url", type="string", example="http://www.example.com") + * @SWG\Property(property="plan", type="string", example="Plan") + * @SWG\Property(property="logo", type="string", example="Logo") + * @SWG\Property(property="logo_url", type="string", example="http://www.example.com/logo.png") + * @SWG\Property(property="currency_id", type="integer", example=1) + * @SWG\Property(property="timezone_id", type="integer", example=1) + * @SWG\Property(property="date_format_id", type="integer", example=1) + * @SWG\Property(property="datetime_format_id", type="integer", example=1) + * @SWG\Property(property="invoice_terms", type="string", example="Terms") + * @SWG\Property(property="invoice_taxes", type="boolean", example=false) + * @SWG\Property(property="invoice_item_taxes", type="boolean", example=false) + * @SWG\Property(property="invoice_design_id", type="integer", example=1) + * @SWG\Property(property="quote_design_id", type="integer", example=1) + * @SWG\Property(property="language_id", type="integer", example=1) + * @SWG\Property(property="country_id", type="integer", example=1) + * @SWG\Property(property="invoice_footer", type="string", example="Footer") + * @SWG\Property(property="invoice_labels", type="string", example="Labels") + * @SWG\Property(property="show_item_taxes", type="boolean", example=false) + * @SWG\Property(property="military_time", type="boolean", example=false) + * @SWG\Property(property="tax_name1", type="string", example="VAT") + * @SWG\Property(property="tax_name2", type="string", example="Upkeep") + * @SWG\Property(property="tax_rate1", type="number", format="float", example="17.5") + * @SWG\Property(property="tax_rate2", type="number", format="float", example="30.0") + * @SWG\Property(property="quote_terms", type="string", example="Labels") + * @SWG\Property(property="show_currency_code", type="boolean", example=false) + * @SWG\Property(property="enable_second_tax_rate", type="boolean", example=false) + * @SWG\Property(property="start_of_week", type="string", example="Monday") + * @SWG\Property(property="financial_year_start", type="string", example="January") + * @SWG\Property(property="enabled_modules", type="integer", example=1) + * @SWG\Property(property="payment_terms", type="integer", example=1) + * @SWG\Property(property="payment_type_id", type="integer", example=1) + * @SWG\Property(property="task_rate", type="number", format="float", example="17.5") + * @SWG\Property(property="inclusive_taxes", type="boolean", example=false) + * @SWG\Property(property="convert_products", type="boolean", example=false) + * @SWG\Property(property="custom_invoice_taxes1", type="string", example="Value") + * @SWG\Property(property="custom_invoice_taxes2", type="string", example="Value") + * @SWG\Property(property="custom_fields", type="string", example="Value") + */ protected $defaultIncludes = [ 'user', ]; + /** + * @var array + */ + protected $availableIncludes = [ + 'tax_rates', + 'expense_categories', + 'account_email_settings', + ]; + protected $tokenName; public function __construct(Account $account, $serializer, $tokenName) @@ -27,6 +78,42 @@ class UserAccountTransformer extends EntityTransformer return $this->includeItem($user, $transformer, 'user'); } + /** + * @param Account $account + * + * @return \League\Fractal\Resource\Collection + */ + public function includeAccountEmailSettings(User $user) + { + $transformer = new AccountEmailSettingsTransformer($this->account, $this->serializer); + + return $this->includeItem($this->account->account_email_settings, $transformer, 'account_email_settings'); + } + + /** + * @param Account $account + * + * @return \League\Fractal\Resource\Collection + */ + public function includeExpenseCategories(User $user) + { + $transformer = new ExpenseCategoryTransformer($this->account, $this->serializer); + + return $this->includeCollection($this->account->expense_categories, $transformer, 'expense_categories'); + } + + /** + * @param Account $account + * + * @return \League\Fractal\Resource\Collection + */ + public function includeTaxRates(User $user) + { + $transformer = new TaxRateTransformer($this->account, $this->serializer); + + return $this->includeCollection($this->account->tax_rates, $transformer, 'tax_rates'); + } + public function transform(User $user) { $account = $user->account; @@ -49,6 +136,7 @@ class UserAccountTransformer extends EntityTransformer 'invoice_design_id' => (int) $account->invoice_design_id, 'quote_design_id' => (int) $account->quote_design_id, 'language_id' => (int) $account->language_id, + 'country_id' => (int) $account->country_id, 'invoice_footer' => $account->invoice_footer ?: '', 'invoice_labels' => $account->invoice_labels ?: '', 'show_item_taxes' => (bool) $account->show_item_taxes, @@ -66,7 +154,7 @@ class UserAccountTransformer extends EntityTransformer 'payment_terms' => (int) $account->payment_terms, 'payment_type_id' => (int) $account->payment_type_id, 'task_rate' => (float) $account->task_rate, - 'inclusive_taxes' => (bool) $account->inclusiveu_taxes, + 'inclusive_taxes' => (bool) $account->inclusive_taxes, 'convert_products' => (bool) $account->convert_products, 'custom_invoice_taxes1' => (bool) $account->custom_invoice_taxes1, 'custom_invoice_taxes2' => (bool) $account->custom_invoice_taxes1, diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 8996450aafec..5331403c94e2 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2848,6 +2848,7 @@ $LANG = array( 'send_notifications_for' => 'Send Notifications For', 'all_invoices' => 'All Invoices', 'my_invoices' => 'My Invoices', + 'mobile_refresh_warning' => 'If you\'re using the mobile app you may need to do a full refresh.', ); diff --git a/resources/views/accounts/management.blade.php b/resources/views/accounts/management.blade.php index 0b35db0c4ed6..9bda2dc1e0e3 100644 --- a/resources/views/accounts/management.blade.php +++ b/resources/views/accounts/management.blade.php @@ -271,6 +271,8 @@

{{ trans('texts.purge_data_message') }}


+

{{ trans('texts.mobile_refresh_warning') }}

+
diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index 920ade1efefb..d748ef5cc449 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -434,7 +434,7 @@ sweetConfirm(function() { $('#action').val('purge'); $('.mainForm').submit(); - }, "{{ trans('texts.purge_client_warning') . "\\n\\n" . trans('texts.no_undo') }}"); + }, "{{ trans('texts.purge_client_warning') . "\\n\\n" . trans('texts.mobile_refresh_warning') . "\\n\\n" . trans('texts.no_undo') }}"); } function showEmailHistory(email) { diff --git a/resources/views/invoices/view_borderless.blade.php b/resources/views/invoices/view_borderless.blade.php new file mode 100644 index 000000000000..db565d2fa1c8 --- /dev/null +++ b/resources/views/invoices/view_borderless.blade.php @@ -0,0 +1,79 @@ +@extends('master') + +@section('head') + @parent + + @include('money_script') + + @foreach ($invoice->client->account->getFontFolders() as $font) + + @endforeach + + + +@stop + +@section('body') + + + @include('invoices.pdf', ['account' => $invoice->client->account]) +@stop