From 4746ca830daf7f2ac5ca93154e62f52dc0907165 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 28 Sep 2018 09:51:48 +0300 Subject: [PATCH] API fixes for mobile app --- app/Constants.php | 2 +- .../Controllers/DashboardApiController.php | 22 +++++++++---------- app/Models/Account.php | 11 ++++++++++ .../Transformers/UserAccountTransformer.php | 2 +- docs/conf.py | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/Constants.php b/app/Constants.php index ef540b6662b2..e3b85570e811 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -361,7 +361,7 @@ if (! defined('APP_NAME')) { define('NINJA_APP_URL', env('NINJA_APP_URL', 'https://app.invoiceninja.com')); define('NINJA_DOCS_URL', env('NINJA_DOCS_URL', 'https://invoice-ninja.readthedocs.io/en/latest')); define('NINJA_DATE', '2000-01-01'); - define('NINJA_VERSION', '4.5.4' . env('NINJA_VERSION_SUFFIX')); + define('NINJA_VERSION', '4.5.5' . env('NINJA_VERSION_SUFFIX')); define('NINJA_TERMS_VERSION', '1.0.1'); define('SOCIAL_LINK_FACEBOOK', env('SOCIAL_LINK_FACEBOOK', 'https://www.facebook.com/invoiceninja')); diff --git a/app/Http/Controllers/DashboardApiController.php b/app/Http/Controllers/DashboardApiController.php index afd35bc1cf16..ea48bb40db4c 100644 --- a/app/Http/Controllers/DashboardApiController.php +++ b/app/Http/Controllers/DashboardApiController.php @@ -24,24 +24,24 @@ class DashboardApiController extends BaseAPIController $defaultCurrency = $user->account->currency_id; $dashboardRepo = $this->dashboardRepo; + $activities = $dashboardRepo->activities($accountId, $userId, $viewAll); + + // optimization for new mobile app + if (request()->only_activity) { + return $this->response([ + 'id' => 1, + 'activities' => $this->createCollection($activities, new ActivityTransformer(), ENTITY_ACTIVITY), + ]); + } + $metrics = $dashboardRepo->totals($accountId, $userId, $viewAll); $paidToDate = $dashboardRepo->paidToDate($user->account, $userId, $viewAll); $averageInvoice = $dashboardRepo->averages($user->account, $userId, $viewAll); - $balances = $dashboardRepo->balances($accountId, $userId, $viewAll); - $activities = $dashboardRepo->activities($accountId, $userId, $viewAll); + $balances = $dashboardRepo->balances($user->account, $userId, $viewAll); $pastDue = $dashboardRepo->pastDue($accountId, $userId, $viewAll); $upcoming = $dashboardRepo->upcoming($accountId, $userId, $viewAll); $payments = $dashboardRepo->payments($accountId, $userId, $viewAll); - $hasQuotes = false; - foreach ([$upcoming, $pastDue] as $data) { - foreach ($data as $invoice) { - if ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE) { - $hasQuotes = true; - } - } - } - $data = [ 'id' => 1, 'paidToDate' => (float) ($paidToDate->count() && $paidToDate[0]->value ? $paidToDate[0]->value : 0), diff --git a/app/Models/Account.php b/app/Models/Account.php index 76d6f0441114..1f89f5809f53 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1820,6 +1820,17 @@ class Account extends Eloquent return $this->company->accounts()->orderBy('id')->first(); } + public function financialYearStartMonth() + { + if (! $this->financial_year_start) { + return 1; + } + + $yearStart = Carbon::parse($this->financial_year_start); + + return $yearStart ? $yearStart->month : 1; + } + public function financialYearStart() { if (! $this->financial_year_start) { diff --git a/app/Ninja/Transformers/UserAccountTransformer.php b/app/Ninja/Transformers/UserAccountTransformer.php index 0fd62c895c82..aed350f22b16 100644 --- a/app/Ninja/Transformers/UserAccountTransformer.php +++ b/app/Ninja/Transformers/UserAccountTransformer.php @@ -176,7 +176,7 @@ class UserAccountTransformer extends EntityTransformer 'show_currency_code' => (bool) $account->show_currency_code, 'enable_second_tax_rate' => (bool) $account->enable_second_tax_rate, 'start_of_week' => (int) $account->start_of_week, - 'financial_year_start' => (int) $account->financial_year_start, + 'financial_year_start' => (int) $account->financialYearStartMonth(), 'enabled_modules' => (int) $account->enabled_modules, 'payment_terms' => (int) $account->payment_terms, 'payment_type_id' => (int) $account->payment_type_id, diff --git a/docs/conf.py b/docs/conf.py index 578bc6745ac1..6209356340b2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -59,7 +59,7 @@ author = u'Invoice Ninja' # The short X.Y version. version = u'4.5' # The full version, including alpha/beta/rc tags. -release = u'4.5.4' +release = u'4.5.5' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages.