diff --git a/app/Jobs/LoadPostmarkStats.php b/app/Jobs/LoadPostmarkStats.php index df101c4514e8..f5a508e577b8 100644 --- a/app/Jobs/LoadPostmarkStats.php +++ b/app/Jobs/LoadPostmarkStats.php @@ -27,6 +27,10 @@ class LoadPostmarkStats extends Job */ public function handle() { + if (! auth()->user()->hasPermission('view_all')) { + return $this->response; + } + $this->loadOverallStats(); $this->loadSentStats(); $this->loadPlatformStats(); @@ -50,9 +54,9 @@ class LoadPostmarkStats extends Job $records = []; if ($eventType == 'sent') { - $response = $this->postmark->getOutboundSendStatistics(null, request()->start_date, request()->end_date); + $response = $this->postmark->getOutboundSendStatistics($this->account->account_key, request()->start_date, request()->end_date); } else { - $response = $this->postmark->getOutboundOpenStatistics(null, request()->start_date, request()->end_date); + $response = $this->postmark->getOutboundOpenStatistics($this->account->account_key, request()->start_date, request()->end_date); } foreach ($response->days as $key => $val) { @@ -95,17 +99,18 @@ class LoadPostmarkStats extends Job private function loadSentStats() { $account = $this->account; - $data = $this->postmark->getOutboundOverviewStatistics(null, request()->start_date, request()->end_date); + $data = $this->postmark->getOutboundOverviewStatistics($this->account->account_key, request()->start_date, request()->end_date); + $percent = $data->sent ? ($data->uniqueopens / $data->sent * 100) : 0; $this->response->totals = [ 'sent' => $account->formatNumber($data->sent), - 'opened' => sprintf('%s | %s%%', $account->formatNumber($data->uniqueopens), $account->formatNumber($data->uniqueopens / $data->sent * 100)), + 'opened' => sprintf('%s | %s%%', $account->formatNumber($data->uniqueopens), $account->formatNumber($percent)), 'bounced' => sprintf('%s | %s%%', $account->formatNumber($data->bounced), $account->formatNumber($data->bouncerate, 3)), //'spam' => sprintf('%s | %s%%', $account->formatNumber($data->spamcomplaints), $account->formatNumber($data->spamcomplaintsrate, 3)) ]; } private function loadPlatformStats() { - $data = $this->postmark->getOutboundPlatformStatistics(null, request()->start_date, request()->end_date); + $data = $this->postmark->getOutboundPlatformStatistics($this->account->account_key, request()->start_date, request()->end_date); $account = $this->account; $str = ''; $total = 0; @@ -113,14 +118,15 @@ class LoadPostmarkStats extends Job $total = $data['desktop'] + $data['mobile'] + $data['webmail']; foreach (['mobile', 'desktop', 'webmail'] as $platform) { - $str .= sprintf('%s%s%%', trans('texts.' . $platform), $account->formatNumber($data[$platform] / $total * 100)); + $percent = $total ? ($data[$platform] / $total * 100) : 0; + $str .= sprintf('%s%s%%', trans('texts.' . $platform), $account->formatNumber($percent)); } $this->response->platforms = $str; } private function loadEmailClientStats() { - $data = $this->postmark->getOutboundEmailClientStatistics(null, request()->start_date, request()->end_date); + $data = $this->postmark->getOutboundEmailClientStatistics($this->account->account_key, request()->start_date, request()->end_date); $account = $this->account; $str = ''; $total = 0; @@ -138,7 +144,7 @@ class LoadPostmarkStats extends Job arsort($clients); foreach ($clients as $key => $val) { - $percent = $val / $total * 100; + $percent = $total ? ($val / $total * 100) : 0; if ($percent < 0.5) { continue; } diff --git a/resources/views/reports/emails.blade.php b/resources/views/reports/emails.blade.php index 03250a74f5fe..4be7934a9890 100644 --- a/resources/views/reports/emails.blade.php +++ b/resources/views/reports/emails.blade.php @@ -239,10 +239,12 @@
+ @if (Auth::user()->hasPermission('view_all'))
+ @endif
@@ -257,7 +259,7 @@ {{ trans('texts.platforms') }} -
+
@@ -270,7 +272,7 @@ {{ trans('texts.email_clients') }}
-
+
diff --git a/resources/views/reports/report_builder.blade.php b/resources/views/reports/report_builder.blade.php index 8aa7919b90ff..93d2820f97f0 100644 --- a/resources/views/reports/report_builder.blade.php +++ b/resources/views/reports/report_builder.blade.php @@ -37,7 +37,7 @@ @stop @section('top-right') - @if (config('services.postmark')) + @if (auth()->user()->hasPermission('view_all') && auth()->user()->hasPermission('view_all')) {!! Button::normal(trans('texts.emails')) ->asLinkTo(url('/reports/emails')) ->appendIcon(Icon::create('envelope')) !!}