From ef81549694cb9e013ba4698bcdceb39467c6dcbf Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 11 Sep 2016 20:05:59 +0300 Subject: [PATCH] Working on the dashboard --- app/Http/Middleware/DuplicateSubmissionCheck.php | 6 +----- app/Ninja/Repositories/DashboardRepository.php | 9 +++++---- docs/index.rst | 2 +- docs/{charts_and_reports.rst => reports.rst} | 0 resources/views/dashboard.blade.php | 2 ++ tests/acceptance/AllPagesCept.php | 4 ++-- tests/functional/SettingsCest.php | 16 ++++++++-------- 7 files changed, 19 insertions(+), 20 deletions(-) rename docs/{charts_and_reports.rst => reports.rst} (100%) diff --git a/app/Http/Middleware/DuplicateSubmissionCheck.php b/app/Http/Middleware/DuplicateSubmissionCheck.php index cffa06ecf9f4..aa128bbc439a 100644 --- a/app/Http/Middleware/DuplicateSubmissionCheck.php +++ b/app/Http/Middleware/DuplicateSubmissionCheck.php @@ -22,10 +22,6 @@ class DuplicateSubmissionCheck $path = $request->path(); - if (strpos($path, 'charts_and_reports') !== false) { - return $next($request); - } - if (in_array($request->method(), ['POST', 'PUT', 'DELETE'])) { $lastPage = session(SESSION_LAST_REQUEST_PAGE); $lastTime = session(SESSION_LAST_REQUEST_TIME); @@ -40,4 +36,4 @@ class DuplicateSubmissionCheck return $next($request); } -} \ No newline at end of file +} diff --git a/app/Ninja/Repositories/DashboardRepository.php b/app/Ninja/Repositories/DashboardRepository.php index ca212d1cd2ea..5b04fbc03969 100644 --- a/app/Ninja/Repositories/DashboardRepository.php +++ b/app/Ninja/Repositories/DashboardRepository.php @@ -111,8 +111,8 @@ class DashboardRepository $timeframe = 'concat(YEAR('.$entityType.'_date), '.$groupBy.'('.$entityType.'_date))'; $records = DB::table($entityType.'s') - ->join('clients', 'clients.id', '=', $entityType.'s.client_id') - ->where('clients.is_deleted', '=', false) + ->leftJoin('clients', 'clients.id', '=', $entityType.'s.client_id') + ->whereRaw('(clients.id IS NULL OR clients.is_deleted = 0)') ->where($entityType.'s.account_id', '=', $accountId) ->where($entityType.'s.is_deleted', '=', false) ->where($entityType.'s.'.$entityType.'_date', '>=', $startDate->format('Y-m-d')) @@ -320,13 +320,14 @@ class DashboardRepository ->where('invoices.is_deleted', '=', false) ->where('clients.is_deleted', '=', false) ->where('contacts.deleted_at', '=', null) - ->where('contacts.is_primary', '=', true); + ->where('contacts.is_primary', '=', true) + ->whereNotIn('payments.payment_status_id', [PAYMENT_STATUS_VOIDED, PAYMENT_STATUS_FAILED]); if (!$viewAll){ $payments = $payments->where('payments.user_id', '=', $userId); } - return $payments->select(['payments.payment_date', 'payments.amount', 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id']) + return $payments->select(['payments.payment_date', DB::raw('(payments.amount - payments.refunded) as amount'), 'invoices.public_id', 'invoices.invoice_number', 'clients.name as client_name', 'contacts.email', 'contacts.first_name', 'contacts.last_name', 'clients.currency_id', 'clients.public_id as client_public_id', 'clients.user_id as client_user_id']) ->orderBy('payments.payment_date', 'desc') ->take(50) ->get(); diff --git a/docs/index.rst b/docs/index.rst index 0898ae43a9e1..aa61e20225e1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,7 +31,7 @@ Want to find out everything there is to know about how to use your Invoice Ninja email_settings templates_and_reminders client_portal - charts_and_reports + reports data_visualizations api_tokens user_management diff --git a/docs/charts_and_reports.rst b/docs/reports.rst similarity index 100% rename from docs/charts_and_reports.rst rename to docs/reports.rst diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 732974276ee2..766a1d9c932c 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -22,6 +22,7 @@ if (window.myChart) { window.myChart.config.data = data; window.myChart.config.options.scales.xAxes[0].time.unit = chartGropuBy.toLowerCase(); + window.myChart.config.options.scales.xAxes[0].time.round = chartGropuBy.toLowerCase(); window.myChart.update(); } else { $('#progress-div').hide(); @@ -63,6 +64,7 @@ type: 'time', time: { unit: 'day', + round: 'day', }, gridLines: { display: false, diff --git a/tests/acceptance/AllPagesCept.php b/tests/acceptance/AllPagesCept.php index 7c07f4c2f343..8ea3a7c71080 100644 --- a/tests/acceptance/AllPagesCept.php +++ b/tests/acceptance/AllPagesCept.php @@ -81,8 +81,8 @@ $I->see('Invoice Design'); $I->amOnPage('/settings/templates_and_reminders'); $I->see('Invoice Email'); -$I->amOnPage('/settings/charts_and_reports'); -$I->see('Data Visualizations'); +$I->amOnPage('/settings/reports'); +$I->see('Report Settings'); //try to logout //$I->click('#myAccountButton'); diff --git a/tests/functional/SettingsCest.php b/tests/functional/SettingsCest.php index 9d53fed2f695..030449410066 100644 --- a/tests/functional/SettingsCest.php +++ b/tests/functional/SettingsCest.php @@ -36,7 +36,7 @@ class SettingsCest $I->seeRecord('accounts', array('name' => $name)); } */ - + public function userDetails(FunctionalTester $I) { $I->wantTo('update the user details'); @@ -96,7 +96,7 @@ class SettingsCest $I->seeRecord('products', array('product_key' => $productKey)); } - public function updateProduct(FunctionalTester $I) + public function updateProduct(FunctionalTester $I) { return; @@ -128,7 +128,7 @@ class SettingsCest $I->seeRecord('accounts', array('invoice_terms' => $terms)); } */ - + public function updateInvoiceSettings(FunctionalTester $I) { $I->wantTo('update invoice settings'); @@ -163,12 +163,12 @@ class SettingsCest public function runReport(FunctionalTester $I) { $I->wantTo('run the report'); - $I->amOnPage('/settings/charts_and_reports'); + $I->amOnPage('/settings/reports'); $I->click('Run'); $I->seeResponseCodeIs(200); } - + public function createUser(FunctionalTester $I) { $I->wantTo('create a user'); @@ -213,7 +213,7 @@ class SettingsCest $I->fillField(['name' => '23_apiKey'], $apiKey); $I->click('Save'); - + $I->seeResponseCodeIs(200); $I->see('Successfully created gateway'); $I->seeRecord('account_gateways', array('gateway_id' => 23)); @@ -224,12 +224,12 @@ class SettingsCest // $I->amOnPage('/gateways/1/edit'); // $I->click('Save'); - + // $I->seeResponseCodeIs(200); // $I->see('Successfully updated gateway'); // $I->seeRecord('account_gateways', array('config' => '{"apiKey":"ASHHOWAH"}')); } */ - + }