diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index e468d62e0a34..37c4be420181 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -35,14 +35,17 @@ class DashboardController extends BaseController $metrics = $dashboardRepo->totals($accountId, $userId, $viewAll); $paidToDate = $dashboardRepo->paidToDate($account, $userId, $viewAll); $averageInvoice = $dashboardRepo->averages($account, $userId, $viewAll); - $balances = $dashboardRepo->balances($accountId, $userId, $viewAll); + $balances = $dashboardRepo->balances($accountId, $userId, $viewAll); $activities = $dashboardRepo->activities($accountId, $userId, $viewAll); $pastDue = $dashboardRepo->pastDue($accountId, $userId, $viewAll); $upcoming = $dashboardRepo->upcoming($accountId, $userId, $viewAll); $payments = $dashboardRepo->payments($accountId, $userId, $viewAll); $expenses = $dashboardRepo->expenses($accountId, $userId, $viewAll); $tasks = $dashboardRepo->tasks($accountId, $userId, $viewAll); - $showBlueVinePromo = !$account->bluevine_status && env('BLUEVINE_PARTNER_UNIQUE_ID'); + + $showBlueVinePromo = ! $account->bluevine_status + && env('BLUEVINE_PARTNER_UNIQUE_ID') + && $account->created_at <= date( 'Y-m-d', strtotime( '-1 month' )); // check if the account has quotes $hasQuotes = false; @@ -95,10 +98,10 @@ class DashboardController extends BaseController 'showBlueVinePromo' => $showBlueVinePromo, ]; - if($showBlueVinePromo){ + if ($showBlueVinePromo) { $usdLast12Months = 0; - - $paidLast12Months = $dashboardRepo->paidLast12Months( $account, $userId, $viewAll ); + $pastYear = date( 'Y-m-d', strtotime( '-1 year' )); + $paidLast12Months = $dashboardRepo->paidToDate( $account, $userId, $viewAll, $pastYear ); foreach ( $paidLast12Months as $item ) { if ( $item->currency_id == null ) { diff --git a/app/Ninja/Repositories/DashboardRepository.php b/app/Ninja/Repositories/DashboardRepository.php index a02589db6f3b..325ee77c5611 100644 --- a/app/Ninja/Repositories/DashboardRepository.php +++ b/app/Ninja/Repositories/DashboardRepository.php @@ -47,7 +47,7 @@ class DashboardRepository $count += $item->count; $balance += isset($item->balance) ? $item->balance : 0; }, $records); - + $padding = $groupBy == 'DAYOFYEAR' ? 'day' : ($groupBy == 'WEEK' ? 'week' : 'month'); $endDate->modify('+1 '.$padding); $interval = new DateInterval('P1'.substr($groupBy, 0, 1)); @@ -181,7 +181,7 @@ class DashboardRepository return $metrics->groupBy('accounts.id')->first(); } - public function paidToDate($account, $userId, $viewAll) + public function paidToDate($account, $userId, $viewAll, $startDate = false) { $accountId = $account->id; $select = DB::raw( @@ -195,13 +195,16 @@ class DashboardRepository ->where('payments.account_id', '=', $accountId) ->where('clients.is_deleted', '=', false) ->where('invoices.is_deleted', '=', false) + ->where('payments.is_deleted', '=', false) ->whereNotIn('payments.payment_status_id', [PAYMENT_STATUS_VOIDED, PAYMENT_STATUS_FAILED]); if (!$viewAll){ $paidToDate->where('invoices.user_id', '=', $userId); } - if ($account->financial_year_start) { + if ($startDate) { + $paidToDate->where('payments.payment_date', '>=', $startDate); + } elseif ($account->financial_year_start) { $yearStart = str_replace('2000', date('Y'), $account->financial_year_start); $paidToDate->where('payments.payment_date', '>=', $yearStart); } @@ -211,34 +214,6 @@ class DashboardRepository ->get(); } - public function paidLast12Months($account, $userId, $viewAll) - { - $accountId = $account->id; - $select = DB::raw( - 'SUM('.DB::getQueryGrammar()->wrap('payments.amount', true).' - '.DB::getQueryGrammar()->wrap('payments.refunded', true).') as value,' - .DB::getQueryGrammar()->wrap('clients.currency_id', true).' as currency_id' - ); - $paidLast12Months = DB::table('payments') - ->select($select) - ->leftJoin('invoices', 'invoices.id', '=', 'payments.invoice_id') - ->leftJoin('clients', 'clients.id', '=', 'invoices.client_id') - ->where('payments.account_id', '=', $accountId) - ->where('clients.is_deleted', '=', false) - ->where('invoices.is_deleted', '=', false) - ->where('payments.is_deleted', '=', false) - ->whereNotIn('payments.payment_status_id', [PAYMENT_STATUS_VOIDED, PAYMENT_STATUS_FAILED]); - - if (!$viewAll){ - $paidLast12Months->where('invoices.user_id', '=', $userId); - } - - $paidLast12Months->where( 'payments.payment_date', '>=', date( 'Y-m-d', strtotime( '-1 year' ) ) ); - - return $paidLast12Months->groupBy('payments.account_id') - ->groupBy(DB::raw('CASE WHEN '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' IS NULL THEN '.($account->currency_id ?: DEFAULT_CURRENCY).' ELSE '.DB::getQueryGrammar()->wrap('clients.currency_id', true).' END')) - ->get(); - } - public function averages($account, $userId, $viewAll) { $accountId = $account->id; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index cdb376fdb04e..cfa1ec7ef434 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2195,8 +2195,7 @@ $LANG = array( 'bluevine_promo' => 'Get flexible business lines of credit and invoice factoring using BlueVine.', 'bluevine_modal_label' => 'Sign up with BlueVine', 'bluevine_modal_text' => '

Fast funding for your business. No paperwork.

-', +', 'bluevine_create_account' => 'Create an account', 'quote_types' => 'Get a quote for', 'invoice_factoring' => 'Invoice factoring', @@ -2219,7 +2218,7 @@ $LANG = array( 'bluevine_weekly_discount_rate' => 'Weekly Discount Rate', 'bluevine_minimum_fee_rate' => 'Minimum Fee', 'bluevine_line_of_credit' => 'Line of Credit', - 'bluevine_interest_Rate' => 'Interest Rate', + 'bluevine_interest_rate' => 'Interest Rate', 'bluevine_weekly_draw_rate' => 'Weekly Draw Rate', 'bluevine_continue' => 'Continue to BlueVine', 'bluevine_completed' => 'BlueVine signup completed', diff --git a/resources/views/partials/bluevine_promo.blade.php b/resources/views/partials/bluevine_promo.blade.php index b37c507a85fe..0de1fa157654 100644 --- a/resources/views/partials/bluevine_promo.blade.php +++ b/resources/views/partials/bluevine_promo.blade.php @@ -1,5 +1,5 @@
- {{ trans('texts.bluevine_promo') }} + {{ trans('texts.bluevine_promo') }}    {{ trans('texts.learn_more') }} {{ trans('texts.hide') }} @@ -15,8 +15,9 @@