report fields
This commit is contained in:
		@@ -2,6 +2,10 @@
 | 
			
		||||
 | 
			
		||||
namespace App\Abstracts;
 | 
			
		||||
 | 
			
		||||
use App\Events\Common\ReportFilterShowing;
 | 
			
		||||
use App\Events\Common\ReportFilterApplying;
 | 
			
		||||
use App\Events\Common\ReportGroupApplying;
 | 
			
		||||
use App\Events\Common\ReportGroupShowing;
 | 
			
		||||
use App\Exports\Common\Reports as Export;
 | 
			
		||||
use App\Models\Common\Report as Model;
 | 
			
		||||
use App\Traits\Charts;
 | 
			
		||||
@@ -14,7 +18,13 @@ abstract class Report
 | 
			
		||||
{
 | 
			
		||||
    use Charts, DateTime;
 | 
			
		||||
 | 
			
		||||
    public $report;
 | 
			
		||||
    public $model;
 | 
			
		||||
 | 
			
		||||
    public $default_name = '';
 | 
			
		||||
 | 
			
		||||
    public $category = 'reports.income_expense';
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-chart-pie';
 | 
			
		||||
 | 
			
		||||
    public $year;
 | 
			
		||||
 | 
			
		||||
@@ -28,12 +38,8 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public $totals = [];
 | 
			
		||||
 | 
			
		||||
    public $groups = [];
 | 
			
		||||
 | 
			
		||||
    public $filters = [];
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-chart-pie';
 | 
			
		||||
 | 
			
		||||
    public $indents = [
 | 
			
		||||
        'table_header' => '0px',
 | 
			
		||||
        'table_rows' => '0px',
 | 
			
		||||
@@ -54,15 +60,15 @@ abstract class Report
 | 
			
		||||
        'datasets' => [],
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    public function __construct(Model $report = null, $get_totals = true)
 | 
			
		||||
    public function __construct(Model $model = null, $get_totals = true)
 | 
			
		||||
    {
 | 
			
		||||
        $this->setGroups();
 | 
			
		||||
 | 
			
		||||
        if (!$report) {
 | 
			
		||||
        if (!$model) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->report = $report;
 | 
			
		||||
        $this->model = $model;
 | 
			
		||||
 | 
			
		||||
        $this->setYear();
 | 
			
		||||
        $this->setViews();
 | 
			
		||||
@@ -80,12 +86,16 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function getDefaultName()
 | 
			
		||||
    {
 | 
			
		||||
        if (!empty($this->default_name)) {
 | 
			
		||||
            return trans($this->default_name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Str::title(str_replace('_', ' ', Str::snake((new \ReflectionClass($this))->getShortName())));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCategory()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.income_expense');
 | 
			
		||||
        return trans($this->category);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getIcon()
 | 
			
		||||
@@ -108,7 +118,7 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function getTableRowList()
 | 
			
		||||
    {
 | 
			
		||||
        $group_prl = Str::plural($this->report->group);
 | 
			
		||||
        $group_prl = Str::plural($this->model->settings->group);
 | 
			
		||||
 | 
			
		||||
        if ($group_filter = request($group_prl)) {
 | 
			
		||||
            $rows = collect($this->filters[$group_prl])->filter(function ($value, $key) use ($group_filter) {
 | 
			
		||||
@@ -125,13 +135,13 @@ abstract class Report
 | 
			
		||||
    {
 | 
			
		||||
        $chart = new Chartjs();
 | 
			
		||||
 | 
			
		||||
        $config = $this->chart[$this->report->chart];
 | 
			
		||||
        $config = $this->chart[$this->model->settings->chart];
 | 
			
		||||
 | 
			
		||||
        $default_options = $this->getLineChartOptions();
 | 
			
		||||
 | 
			
		||||
        $options = array_merge($default_options, (array) $config['options']);
 | 
			
		||||
 | 
			
		||||
        $chart->type($this->report->chart)
 | 
			
		||||
        $chart->type($this->model->settings->chart)
 | 
			
		||||
            ->width((int) $config['width'])
 | 
			
		||||
            ->height((int) $config['height'])
 | 
			
		||||
            ->options($options)
 | 
			
		||||
@@ -147,7 +157,7 @@ abstract class Report
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            foreach ($this->totals as $total) {
 | 
			
		||||
                $chart->dataset($this->report->name, 'line', array_values($total))
 | 
			
		||||
                $chart->dataset($this->model->name, 'line', array_values($total))
 | 
			
		||||
                    ->backgroundColor(isset($config['backgroundColor']) ? $config['backgroundColor'] : '#6da252')
 | 
			
		||||
                    ->color(isset($config['color']) ? $config['color'] : '#6da252')
 | 
			
		||||
                    ->options([
 | 
			
		||||
@@ -173,7 +183,7 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function export()
 | 
			
		||||
    {
 | 
			
		||||
        return \Excel::download(new Export($this->views['content'], $this), $this->report->name . '.xlsx');
 | 
			
		||||
        return \Excel::download(new Export($this->views['content'], $this), $this->model->name . '.xlsx');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setYear()
 | 
			
		||||
@@ -208,12 +218,12 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function setDates()
 | 
			
		||||
    {
 | 
			
		||||
        $function = 'sub' . ucfirst(str_replace('ly', '', $this->report->period));
 | 
			
		||||
        $function = 'sub' . ucfirst(str_replace('ly', '', $this->model->settings->period));
 | 
			
		||||
 | 
			
		||||
        $start = $this->getFinancialStart()->copy()->$function();
 | 
			
		||||
 | 
			
		||||
        for ($j = 1; $j <= 12; $j++) {
 | 
			
		||||
            switch ($this->report->period) {
 | 
			
		||||
            switch ($this->model->settings->period) {
 | 
			
		||||
                case 'yearly':
 | 
			
		||||
                    $start->addYear();
 | 
			
		||||
 | 
			
		||||
@@ -260,12 +270,14 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function setFilters()
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Common\ReportFilterShowing($this));
 | 
			
		||||
        event(new ReportFilterShowing($this));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setGroups()
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Common\ReportGroupShowing($this));
 | 
			
		||||
        $this->groups = [];
 | 
			
		||||
 | 
			
		||||
        event(new ReportGroupShowing($this));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setRows()
 | 
			
		||||
@@ -289,7 +301,7 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
            $date = $this->getFormattedDate(Date::parse($item->$date_field));
 | 
			
		||||
 | 
			
		||||
            $id_field = $this->report->group . '_id';
 | 
			
		||||
            $id_field = $this->model->settings->group . '_id';
 | 
			
		||||
 | 
			
		||||
            if (!isset($this->rows[$table][$item->$id_field]) ||
 | 
			
		||||
                !isset($this->rows[$table][$item->$id_field][$date]) ||
 | 
			
		||||
@@ -322,21 +334,21 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function applyFilters($model, $args = [])
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Common\ReportFilterApplying($this, $model, $args));
 | 
			
		||||
        event(new ReportFilterApplying($this, $model, $args));
 | 
			
		||||
 | 
			
		||||
        return $model;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function applyGroups($model, $args = [])
 | 
			
		||||
    {
 | 
			
		||||
        event(new \App\Events\Common\ReportGroupApplying($this, $model, $args));
 | 
			
		||||
        event(new ReportGroupApplying($this, $model, $args));
 | 
			
		||||
 | 
			
		||||
        return $model;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getFormattedDate($date)
 | 
			
		||||
    {
 | 
			
		||||
        switch ($this->report->period) {
 | 
			
		||||
        switch ($this->model->settings->period) {
 | 
			
		||||
            case 'yearly':
 | 
			
		||||
                $i = $date->copy()->format($this->getYearlyDateFormat());
 | 
			
		||||
                break;
 | 
			
		||||
@@ -356,7 +368,7 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
    public function getUrl($action = 'print')
 | 
			
		||||
    {
 | 
			
		||||
        $print_url = 'common/reports/' . $this->report->id . '/' . $action . '?year='. $this->year;
 | 
			
		||||
        $print_url = 'common/reports/' . $this->model->id . '/' . $action . '?year='. $this->year;
 | 
			
		||||
 | 
			
		||||
        collect(request('accounts'))->each(function($item) use(&$print_url) {
 | 
			
		||||
            $print_url .= '&accounts[]=' . $item;
 | 
			
		||||
@@ -372,4 +384,86 @@ abstract class Report
 | 
			
		||||
 | 
			
		||||
        return $print_url;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getFields()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            $this->getGroupField(),
 | 
			
		||||
            $this->getPeriodField(),
 | 
			
		||||
            $this->getBasisField(),
 | 
			
		||||
            $this->getChartField(),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getGroupField()
 | 
			
		||||
    {
 | 
			
		||||
        $this->setGroups();
 | 
			
		||||
 | 
			
		||||
        return [
 | 
			
		||||
            'type' => 'selectGroup',
 | 
			
		||||
            'name' => 'group',
 | 
			
		||||
            'title' => trans('general.group_by'),
 | 
			
		||||
            'icon' => 'folder',
 | 
			
		||||
            'values' => $this->groups,
 | 
			
		||||
            'selected' => 'category',
 | 
			
		||||
            'attributes' => [
 | 
			
		||||
                'required' => 'required',
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getPeriodField()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'type' => 'selectGroup',
 | 
			
		||||
            'name' => 'period',
 | 
			
		||||
            'title' => trans('general.period'),
 | 
			
		||||
            'icon' => 'calendar',
 | 
			
		||||
            'values' => [
 | 
			
		||||
                'monthly' => trans('general.monthly'),
 | 
			
		||||
                'quarterly' => trans('general.quarterly'),
 | 
			
		||||
                'yearly' => trans('general.yearly'),
 | 
			
		||||
            ],
 | 
			
		||||
            'selected' => 'quarterly',
 | 
			
		||||
            'attributes' => [
 | 
			
		||||
                'required' => 'required',
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getBasisField()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'type' => 'selectGroup',
 | 
			
		||||
            'name' => 'basis',
 | 
			
		||||
            'title' => trans('general.basis'),
 | 
			
		||||
            'icon' => 'file',
 | 
			
		||||
            'values' => [
 | 
			
		||||
                'accrual' => trans('general.accrual'),
 | 
			
		||||
                'cash' => trans('general.cash'),
 | 
			
		||||
            ],
 | 
			
		||||
            'selected' => 'accrual',
 | 
			
		||||
            'attributes' => [
 | 
			
		||||
                'required' => 'required',
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getChartField()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'type' => 'selectGroup',
 | 
			
		||||
            'name' => 'chart',
 | 
			
		||||
            'title' => trans_choice('general.charts', 1),
 | 
			
		||||
            'icon' => 'chart-pie',
 | 
			
		||||
            'values' => [
 | 
			
		||||
                '0' => trans('general.disabled'),
 | 
			
		||||
                'line' => trans('reports.charts.line'),
 | 
			
		||||
            ],
 | 
			
		||||
            'selected' => '0',
 | 
			
		||||
            'attributes' => [
 | 
			
		||||
                'required' => 'required',
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,8 +13,8 @@ class $NAME$ extends Provider
 | 
			
		||||
     */
 | 
			
		||||
    public function boot()
 | 
			
		||||
    {
 | 
			
		||||
        $this->loadTranslations();
 | 
			
		||||
        $this->loadViews();
 | 
			
		||||
        $this->loadTranslations();
 | 
			
		||||
        $this->loadMigrations();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ class Reports extends Controller
 | 
			
		||||
    {
 | 
			
		||||
        $classes = $categories = [];
 | 
			
		||||
 | 
			
		||||
        $reports = Report::collect();
 | 
			
		||||
        $reports = Report::all();
 | 
			
		||||
 | 
			
		||||
        foreach ($reports as $report) {
 | 
			
		||||
            if (!Utility::canRead($report->class)) {
 | 
			
		||||
@@ -62,15 +62,7 @@ class Reports extends Controller
 | 
			
		||||
    {
 | 
			
		||||
        $classes = Utility::getClasses();
 | 
			
		||||
 | 
			
		||||
        $groups = Utility::getGroups();
 | 
			
		||||
 | 
			
		||||
        $periods = Utility::getPeriods();
 | 
			
		||||
 | 
			
		||||
        $basises = Utility::getBasises();
 | 
			
		||||
 | 
			
		||||
        $charts = Utility::getCharts();
 | 
			
		||||
 | 
			
		||||
        return view('common.reports.create', compact('classes', 'groups', 'periods', 'basises', 'charts'));
 | 
			
		||||
        return view('common.reports.create', compact('classes'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -111,15 +103,9 @@ class Reports extends Controller
 | 
			
		||||
    {
 | 
			
		||||
        $classes = Utility::getClasses();
 | 
			
		||||
 | 
			
		||||
        $groups = Utility::getGroups();
 | 
			
		||||
        $class = Utility::getClassInstance($report);
 | 
			
		||||
 | 
			
		||||
        $periods = Utility::getPeriods();
 | 
			
		||||
 | 
			
		||||
        $basises = Utility::getBasises();
 | 
			
		||||
 | 
			
		||||
        $charts = Utility::getCharts();
 | 
			
		||||
 | 
			
		||||
        return view('common.reports.edit', compact('report', 'classes', 'groups', 'periods', 'basises', 'charts'));
 | 
			
		||||
        return view('common.reports.edit', compact('report', 'classes', 'class'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -207,11 +193,11 @@ class Reports extends Controller
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get groups of the specified resource.
 | 
			
		||||
     * Get fields of the specified resource.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Response
 | 
			
		||||
     */
 | 
			
		||||
    public function groups()
 | 
			
		||||
    public function fields()
 | 
			
		||||
    {
 | 
			
		||||
        $class = request('class');
 | 
			
		||||
 | 
			
		||||
@@ -219,16 +205,20 @@ class Reports extends Controller
 | 
			
		||||
            return response()->json([
 | 
			
		||||
                'success' => false,
 | 
			
		||||
                'error' => true,
 | 
			
		||||
                'data' => false,
 | 
			
		||||
                'message' => "Class doesn't exist",
 | 
			
		||||
                'message' => 'Class does not exist',
 | 
			
		||||
                'html' => '',
 | 
			
		||||
            ]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $fields = (new $class())->getFields();
 | 
			
		||||
 | 
			
		||||
        $html = view('partials.reports.fields', compact('fields'))->render();
 | 
			
		||||
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'success' => true,
 | 
			
		||||
            'error' => false,
 | 
			
		||||
            'data' => (new $class())->groups,
 | 
			
		||||
            'message' => '',
 | 
			
		||||
            'html' => $html,
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -259,58 +259,38 @@ class Version200 extends Listener
 | 
			
		||||
        $rows = [
 | 
			
		||||
            [
 | 
			
		||||
                'company_id' => $company->id,
 | 
			
		||||
                'class' => 'App\Reports\IncomeSummary',
 | 
			
		||||
                'name' => trans('reports.summary.income'),
 | 
			
		||||
                'description' => trans('demo.reports.income'),
 | 
			
		||||
                'class' => 'App\Reports\IncomeSummary',
 | 
			
		||||
                'group' => 'category',
 | 
			
		||||
                'period' => 'monthly',
 | 
			
		||||
                'basis' => 'accrual',
 | 
			
		||||
                'chart' => 'line',
 | 
			
		||||
                'enabled' => 1,
 | 
			
		||||
                'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'company_id' => $company->id,
 | 
			
		||||
                'class' => 'App\Reports\ExpenseSummary',
 | 
			
		||||
                'name' => trans('reports.summary.expense'),
 | 
			
		||||
                'description' => trans('demo.reports.expense'),
 | 
			
		||||
                'class' => 'App\Reports\ExpenseSummary',
 | 
			
		||||
                'group' => 'category',
 | 
			
		||||
                'period' => 'monthly',
 | 
			
		||||
                'basis' => 'accrual',
 | 
			
		||||
                'chart' => 'line',
 | 
			
		||||
                'enabled' => 1,
 | 
			
		||||
                'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'company_id' => $company->id,
 | 
			
		||||
                'class' => 'App\Reports\IncomeExpenseSummary',
 | 
			
		||||
                'name' => trans('reports.summary.income_expense'),
 | 
			
		||||
                'description' => trans('demo.reports.income_expense'),
 | 
			
		||||
                'class' => 'App\Reports\IncomeExpenseSummary',
 | 
			
		||||
                'group' => 'category',
 | 
			
		||||
                'period' => 'monthly',
 | 
			
		||||
                'basis' => 'accrual',
 | 
			
		||||
                'chart' => 'line',
 | 
			
		||||
                'enabled' => 1,
 | 
			
		||||
                'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'company_id' => $company->id,
 | 
			
		||||
                'class' => 'App\Reports\ProfitLoss',
 | 
			
		||||
                'name' => trans('reports.profit_loss'),
 | 
			
		||||
                'description' => trans('demo.reports.profit_loss'),
 | 
			
		||||
                'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'],
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'company_id' => $company->id,
 | 
			
		||||
                'class' => 'App\Reports\TaxSummary',
 | 
			
		||||
                'name' => trans('reports.summary.tax'),
 | 
			
		||||
                'description' => trans('demo.reports.tax'),
 | 
			
		||||
                'class' => 'App\Reports\TaxSummary',
 | 
			
		||||
                'group' => 'category',
 | 
			
		||||
                'period' => 'quarterly',
 | 
			
		||||
                'basis' => 'accrual',
 | 
			
		||||
                'chart' => '0',
 | 
			
		||||
                'enabled' => 1,
 | 
			
		||||
            ],
 | 
			
		||||
            [
 | 
			
		||||
                'company_id' => $company->id,
 | 
			
		||||
                'name' => trans('reports.profit_loss'),
 | 
			
		||||
                'description' => trans('demo.reports.pl'),
 | 
			
		||||
                'class' => 'App\Reports\ProfitLoss',
 | 
			
		||||
                'group' => 'category',
 | 
			
		||||
                'period' => 'quarterly',
 | 
			
		||||
                'basis' => 'accrual',
 | 
			
		||||
                'chart' => '0',
 | 
			
		||||
                'enabled' => 1,
 | 
			
		||||
                'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual', 'chart' => '0'],
 | 
			
		||||
            ],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,6 @@ use App\Abstracts\Model;
 | 
			
		||||
 | 
			
		||||
class Report extends Model
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    protected $table = 'reports';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -14,5 +13,14 @@ class Report extends Model
 | 
			
		||||
     *
 | 
			
		||||
     * @var array
 | 
			
		||||
     */
 | 
			
		||||
    protected $fillable = ['company_id', 'name', 'description', 'class', 'group', 'period', 'basis', 'chart'];
 | 
			
		||||
    protected $fillable = ['company_id', 'class', 'name', 'description', 'settings'];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The attributes that should be casted to native types.
 | 
			
		||||
     *
 | 
			
		||||
     * @var array
 | 
			
		||||
     */
 | 
			
		||||
    protected $casts = [
 | 
			
		||||
        'settings' => 'object',
 | 
			
		||||
    ];
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@ use App\Utilities\Recurring;
 | 
			
		||||
 | 
			
		||||
class ExpenseSummary extends Report
 | 
			
		||||
{
 | 
			
		||||
    public $default_name = 'reports.summary.expense';
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-shopping-cart';
 | 
			
		||||
 | 
			
		||||
    public $chart = [
 | 
			
		||||
@@ -26,21 +28,11 @@ class ExpenseSummary extends Report
 | 
			
		||||
        ],
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    public function getDefaultName()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.summary.expense');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCategory()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.income_expense');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getTotals()
 | 
			
		||||
    {
 | 
			
		||||
        $payments = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
 | 
			
		||||
        switch ($this->report->basis) {
 | 
			
		||||
        switch ($this->model->settings->basis) {
 | 
			
		||||
            case 'cash':
 | 
			
		||||
                // Payments
 | 
			
		||||
                $this->setTotals($payments, 'paid_at');
 | 
			
		||||
 
 | 
			
		||||
@@ -10,24 +10,16 @@ use App\Utilities\Recurring;
 | 
			
		||||
 | 
			
		||||
class IncomeExpenseSummary extends Report
 | 
			
		||||
{
 | 
			
		||||
    public $default_name = 'reports.summary.income_expense';
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-chart-pie';
 | 
			
		||||
 | 
			
		||||
    public function getDefaultName()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.summary.income_expense');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCategory()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.income_expense');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getTotals()
 | 
			
		||||
    {
 | 
			
		||||
        $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
        $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
 | 
			
		||||
        switch ($this->report->basis) {
 | 
			
		||||
        switch ($this->model->settings->basis) {
 | 
			
		||||
            case 'cash':
 | 
			
		||||
                // Income Transactions
 | 
			
		||||
                $this->setTotals($income_transactions, 'paid_at', true);
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,8 @@ use App\Utilities\Recurring;
 | 
			
		||||
 | 
			
		||||
class IncomeSummary extends Report
 | 
			
		||||
{
 | 
			
		||||
    public $default_name = 'reports.summary.income';
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-money-bill';
 | 
			
		||||
 | 
			
		||||
    public $chart = [
 | 
			
		||||
@@ -26,21 +28,11 @@ class IncomeSummary extends Report
 | 
			
		||||
        ],
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    public function getDefaultName()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.summary.income');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCategory()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.income_expense');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getTotals()
 | 
			
		||||
    {
 | 
			
		||||
        $transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
 | 
			
		||||
        switch ($this->report->basis) {
 | 
			
		||||
        switch ($this->model->settings->basis) {
 | 
			
		||||
            case 'cash':
 | 
			
		||||
                // Transactions
 | 
			
		||||
                $this->setTotals($transactions, 'paid_at');
 | 
			
		||||
 
 | 
			
		||||
@@ -11,20 +11,14 @@ use App\Utilities\Recurring;
 | 
			
		||||
 | 
			
		||||
class ProfitLoss extends Report
 | 
			
		||||
{
 | 
			
		||||
    public $default_name = 'reports.profit_loss';
 | 
			
		||||
 | 
			
		||||
    public $category = 'general.accounting';
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-heart';
 | 
			
		||||
 | 
			
		||||
    public $chart = false;
 | 
			
		||||
 | 
			
		||||
    public function getDefaultName()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.profit_loss');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCategory()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('general.accounting');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setViews()
 | 
			
		||||
    {
 | 
			
		||||
        parent::setViews();
 | 
			
		||||
@@ -73,7 +67,7 @@ class ProfitLoss extends Report
 | 
			
		||||
        $income_transactions = $this->applyFilters(Transaction::type('income')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
        $expense_transactions = $this->applyFilters(Transaction::type('expense')->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
 | 
			
		||||
        switch ($this->report->basis) {
 | 
			
		||||
        switch ($this->model->settings->basis) {
 | 
			
		||||
            case 'cash':
 | 
			
		||||
                // Income Transactions
 | 
			
		||||
                $this->setTotals($income_transactions, 'paid_at', true, $this->tables['income']);
 | 
			
		||||
 
 | 
			
		||||
@@ -15,20 +15,14 @@ class TaxSummary extends Report
 | 
			
		||||
{
 | 
			
		||||
    use Currencies;
 | 
			
		||||
 | 
			
		||||
    public $default_name = 'reports.summary.tax';
 | 
			
		||||
 | 
			
		||||
    public $category = 'general.accounting';
 | 
			
		||||
 | 
			
		||||
    public $icon = 'fa fa-percent';
 | 
			
		||||
 | 
			
		||||
    public $chart = false;
 | 
			
		||||
 | 
			
		||||
    public function getDefaultName()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('reports.summary.tax');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCategory()
 | 
			
		||||
    {
 | 
			
		||||
        return trans('general.accounting');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setViews()
 | 
			
		||||
    {
 | 
			
		||||
        parent::setViews();
 | 
			
		||||
@@ -54,7 +48,7 @@ class TaxSummary extends Report
 | 
			
		||||
 | 
			
		||||
    public function getTotals()
 | 
			
		||||
    {
 | 
			
		||||
        switch ($this->report->basis) {
 | 
			
		||||
        switch ($this->model->settings->basis) {
 | 
			
		||||
            case 'cash':
 | 
			
		||||
                // Invoice Payments
 | 
			
		||||
                $invoices = $this->applyFilters(Transaction::type('income')->isDocument()->with(['invoice', 'invoice.totals'])->isNotTransfer(), ['date_field' => 'paid_at'])->get();
 | 
			
		||||
 
 | 
			
		||||
@@ -41,38 +41,6 @@ class Reports
 | 
			
		||||
        return $classes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function getGroups()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'category' => trans_choice('general.categories', 1),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function getPeriods()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'monthly' => trans('general.monthly'),
 | 
			
		||||
            'quarterly' => trans('general.quarterly'),
 | 
			
		||||
            'yearly' => trans('general.yearly'),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function getBasises()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'accrual' => trans('general.accrual'),
 | 
			
		||||
            'cash' => trans('general.cash'),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function getCharts()
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            '0' => trans('general.disabled'),
 | 
			
		||||
            'line' => trans('reports.charts.line'),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function getClassInstance($model, $get_totals = true)
 | 
			
		||||
    {
 | 
			
		||||
        if (is_string($model)) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user