1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Jobs/RunReport.php
David Bomba a9f2d0d855
This PR implements Create/View/Edit permissions based on ENTITY TYPE (ie invoice/expense/client). (#2150)
* migration for new permissions schema

* update permissions across data tables

* refactor migrations to prevent duplicate attribute

* update permissions in views

* Product Permissions

* permissions via controllers

* Refactor to use Laravel authorization gate

* Doc Blocks for EntityPolicy

* check permissions conditional on create new client

* Bug Fixes

* Data table permissions

* working on UI

* settings UI/UX finalised

* Datatable permissions

* remove legacy permissions

* permission fix for viewing client

* remove all instances of viewByOwner

* refactor after PR

* Bug fix for Functional test and implementation of Functional tests for Permissions

* fix for tests
2018-06-07 20:08:34 +10:00

80 lines
2.5 KiB
PHP

<?php
namespace App\Jobs;
use App;
use Str;
use Utils;
use Carbon;
use App\Jobs\Job;
class RunReport extends Job
{
public function __construct($user, $reportType, $config, $isExport = false)
{
$this->user = $user;
$this->reportType = $reportType;
$this->config = $config;
$this->isExport = $isExport;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if (! $this->user->hasPermission('view_reports')) {
return false;
}
$reportType = $this->reportType;
$config = $this->config;
$config['subgroup'] = ! empty($config['subgroup']) ? $config['subgroup'] : false; // don't yet support charts in export
$isExport = $this->isExport;
$reportClass = '\\App\\Ninja\\Reports\\' . Str::studly($reportType) . 'Report';
if (! empty($config['range'])) {
switch ($config['range']) {
case 'this_month':
$startDate = Carbon::now()->firstOfMonth()->toDateString();
$endDate = Carbon::now()->lastOfMonth()->toDateString();
break;
case 'last_month':
$startDate = Carbon::now()->subMonth()->firstOfMonth()->toDateString();
$endDate = Carbon::now()->subMonth()->lastOfMonth()->toDateString();
break;
case 'this_year':
$startDate = Carbon::now()->firstOfYear()->toDateString();
$endDate = Carbon::now()->lastOfYear()->toDateString();
break;
case 'last_year':
$startDate = Carbon::now()->subYear()->firstOfYear()->toDateString();
$endDate = Carbon::now()->subYear()->lastOfYear()->toDateString();
break;
}
} elseif (! empty($config['start_date_offset'])) {
$startDate = Carbon::now()->subDays($config['start_date_offset'])->toDateString();
$endDate = Carbon::now()->subDays($config['end_date_offset'])->toDateString();
} else {
$startDate = $config['start_date'];
$endDate = $config['end_date'];
}
$report = new $reportClass($startDate, $endDate, $isExport, $config);
$report->run();
$params = [
'startDate' => $startDate,
'endDate' => $endDate,
'report' => $report,
];
$report->exportParams = array_merge($params, $report->results());
return $report;
}
}