Merge pull request #2257 from sevannerse/basis-default-filter-reports
Basis default filter reports
This commit is contained in:
commit
60f79340fd
@ -114,6 +114,14 @@ abstract class Report
|
|||||||
return $model->pluck('name', 'id')->toArray();
|
return $model->pluck('name', 'id')->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBasis()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'cash' => trans('general.cash'),
|
||||||
|
'accrual' => trans('general.accrual'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function applyDateFilter($event)
|
public function applyDateFilter($event)
|
||||||
{
|
{
|
||||||
$event->model->monthsOfYear($event->args['date_field']);
|
$event->model->monthsOfYear($event->args['date_field']);
|
||||||
@ -127,6 +135,10 @@ abstract class Report
|
|||||||
$search_year = 'year:' . $this->getSearchStringValue('year', '', $input);
|
$search_year = 'year:' . $this->getSearchStringValue('year', '', $input);
|
||||||
$input = str_replace($search_year, '', $input);
|
$input = str_replace($search_year, '', $input);
|
||||||
|
|
||||||
|
// Remove basis as it's handled based on report itself
|
||||||
|
$search_basis = 'basis:' . $this->getSearchStringValue('basis', 'accrual', $input);
|
||||||
|
$input = str_replace($search_basis, '', $input);
|
||||||
|
|
||||||
$event->model->usingSearchString($input);
|
$event->model->usingSearchString($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
app/Listeners/Report/AddBasis.php
Normal file
34
app/Listeners/Report/AddBasis.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners\Report;
|
||||||
|
|
||||||
|
use App\Abstracts\Listeners\Report as Listener;
|
||||||
|
use App\Events\Report\FilterShowing;
|
||||||
|
|
||||||
|
class AddBasis extends Listener
|
||||||
|
{
|
||||||
|
protected $classes = [
|
||||||
|
'App\Reports\IncomeSummary',
|
||||||
|
'App\Reports\ExpenseSummary',
|
||||||
|
'App\Reports\IncomeExpenseSummary',
|
||||||
|
'App\Reports\ProfitLoss',
|
||||||
|
'App\Reports\TaxSummary',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle filter showing event.
|
||||||
|
*
|
||||||
|
* @param $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handleFilterShowing(FilterShowing $event)
|
||||||
|
{
|
||||||
|
if ($this->skipThisClass($event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$event->class->filters['basis'] = $this->getBasis();
|
||||||
|
$event->class->filters['keys']['basis'] = 'basis';
|
||||||
|
$event->class->filters['defaults']['basis'] = $event->class->getSetting('basis', 'accrual');
|
||||||
|
}
|
||||||
|
}
|
@ -112,5 +112,6 @@ class Event extends Provider
|
|||||||
'App\Listeners\Report\AddIncomeExpenseCategories',
|
'App\Listeners\Report\AddIncomeExpenseCategories',
|
||||||
'App\Listeners\Report\AddSearchString',
|
'App\Listeners\Report\AddSearchString',
|
||||||
'App\Listeners\Report\AddRowsToTax',
|
'App\Listeners\Report\AddRowsToTax',
|
||||||
|
'App\Listeners\Report\AddBasis',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,9 @@ class ExpenseSummary extends Report
|
|||||||
{
|
{
|
||||||
$transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
$transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||||
|
|
||||||
switch ($this->getSetting('basis')) {
|
$basis = $this->getSearchStringValue('basis', $this->getSetting('basis'));
|
||||||
|
|
||||||
|
switch ($basis) {
|
||||||
case 'cash':
|
case 'cash':
|
||||||
// Payments
|
// Payments
|
||||||
$payments = $transactions->get();
|
$payments = $transactions->get();
|
||||||
|
@ -18,7 +18,9 @@ class IncomeExpenseSummary extends Report
|
|||||||
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||||
$expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
$expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||||
|
|
||||||
switch ($this->getSetting('basis')) {
|
$basis = $this->getSearchStringValue('basis', $this->getSetting('basis'));
|
||||||
|
|
||||||
|
switch ($basis) {
|
||||||
case 'cash':
|
case 'cash':
|
||||||
// Revenues
|
// Revenues
|
||||||
$revenues = $income_transactions->get();
|
$revenues = $income_transactions->get();
|
||||||
|
@ -32,7 +32,9 @@ class IncomeSummary extends Report
|
|||||||
{
|
{
|
||||||
$transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
$transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||||
|
|
||||||
switch ($this->getSetting('basis')) {
|
$basis = $this->getSearchStringValue('basis', $this->getSetting('basis'));
|
||||||
|
|
||||||
|
switch ($basis) {
|
||||||
case 'cash':
|
case 'cash':
|
||||||
// Revenues
|
// Revenues
|
||||||
$revenues = $transactions->get();
|
$revenues = $transactions->get();
|
||||||
|
@ -37,7 +37,9 @@ class ProfitLoss extends Report
|
|||||||
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
$income_transactions = $this->applyFilters(Transaction::with('recurring')->income()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||||
$expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
$expense_transactions = $this->applyFilters(Transaction::with('recurring')->expense()->isNotTransfer(), ['date_field' => 'paid_at']);
|
||||||
|
|
||||||
switch ($this->getSetting('basis')) {
|
$basis = $this->getSearchStringValue('basis', $this->getSetting('basis'));
|
||||||
|
|
||||||
|
switch ($basis) {
|
||||||
case 'cash':
|
case 'cash':
|
||||||
// Revenues
|
// Revenues
|
||||||
$revenues = $income_transactions->get();
|
$revenues = $income_transactions->get();
|
||||||
|
@ -40,7 +40,9 @@ class TaxSummary extends Report
|
|||||||
|
|
||||||
public function setData()
|
public function setData()
|
||||||
{
|
{
|
||||||
switch ($this->getSetting('basis')) {
|
$basis = $this->getSearchStringValue('basis', $this->getSetting('basis'));
|
||||||
|
|
||||||
|
switch ($basis) {
|
||||||
case 'cash':
|
case 'cash':
|
||||||
// Invoice Payments
|
// Invoice Payments
|
||||||
$invoices = $this->applyFilters(Transaction::with('recurring', 'invoice', 'invoice.totals')->income()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
$invoices = $this->applyFilters(Transaction::with('recurring', 'invoice', 'invoice.totals')->income()->isDocument()->isNotTransfer(), ['date_field' => 'paid_at'])->get();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
$filtered = [];
|
$filtered = [];
|
||||||
|
|
||||||
$skipped = [
|
$skipped = [
|
||||||
'keys', 'names', 'types', 'routes'
|
'keys', 'names', 'types', 'routes', 'defaults'
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($class->filters as $filter_name => $filter_values) {
|
foreach ($class->filters as $filter_name => $filter_values) {
|
||||||
@ -58,6 +58,16 @@
|
|||||||
$url = (is_array($route)) ? route($route[0], $route[1]) : route($route);
|
$url = (is_array($route)) ? route($route[0], $route[1]) : route($route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$default_value = null;
|
||||||
|
|
||||||
|
if (isset($class->filters['defaults']) && !empty($class->filters['defaults'][$filter_name])) {
|
||||||
|
$default_value = $class->filters['defaults'][$filter_name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($key == 'year') {
|
||||||
|
$default_value = \Date::now()->year;
|
||||||
|
}
|
||||||
|
|
||||||
$filters[] = [
|
$filters[] = [
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
@ -66,11 +76,11 @@
|
|||||||
'values' => $filter_values,
|
'values' => $filter_values,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($key == 'year') {
|
if (!is_null($default_value)) {
|
||||||
$filtered[] = [
|
$filtered[] = [
|
||||||
'option' => $key,
|
'option' => $key,
|
||||||
'operator' => '=',
|
'operator' => '=',
|
||||||
'value' => \Date::now()->year,
|
'value' => $default_value,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user