refactored report listeners
This commit is contained in:
parent
c64dfdac1e
commit
c208c336eb
@ -2,10 +2,6 @@
|
||||
|
||||
namespace App\Abstracts\Listeners;
|
||||
|
||||
use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Setting\Category;
|
||||
@ -16,7 +12,7 @@ abstract class Report
|
||||
{
|
||||
use Contacts;
|
||||
|
||||
protected $class = '';
|
||||
protected $classes = [];
|
||||
|
||||
protected $events = [
|
||||
'App\Events\Common\ReportFilterShowing',
|
||||
@ -25,9 +21,9 @@ abstract class Report
|
||||
'App\Events\Common\ReportGroupApplying',
|
||||
];
|
||||
|
||||
public function checkClass($event)
|
||||
public function skipThisClass($event)
|
||||
{
|
||||
return (get_class($event->class) == $this->class);
|
||||
return (empty($event->class) || !in_array(get_class($event->class), $this->classes));
|
||||
}
|
||||
|
||||
public function getYears()
|
||||
@ -137,70 +133,6 @@ abstract class Report
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['years'] = $this->getYears();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle filter applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterApplying(ReportFilterApplying $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply date
|
||||
$this->applyDateFilter($event);
|
||||
|
||||
// Apply search
|
||||
$this->applySearchStringFilter($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupApplying(ReportGroupApplying $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyAccountGroup($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the listeners for the subscriber.
|
||||
*
|
||||
|
@ -3,14 +3,19 @@
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
|
||||
class ExpenseSummaryReport extends Listener
|
||||
class AddAccountsToReports extends Listener
|
||||
{
|
||||
protected $class = 'App\Reports\ExpenseSummary';
|
||||
protected $classes = [
|
||||
'App\Reports\IncomeSummary',
|
||||
'App\Reports\ExpenseSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
'App\Reports\ProfitLoss',
|
||||
'App\Reports\TaxSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
@ -20,14 +25,11 @@ class ExpenseSummaryReport extends Listener
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['years'] = $this->getYears();
|
||||
$event->class->filters['accounts'] = $this->getAccounts();
|
||||
$event->class->filters['categories'] = $this->getExpenseCategories();
|
||||
$event->class->filters['vendors'] = $this->getVendors();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,28 +40,25 @@ class ExpenseSummaryReport extends Listener
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
$event->class->groups['account'] = trans_choice('general.accounts', 1);
|
||||
$event->class->groups['vendor'] = trans_choice('general.vendors', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group applyinh event.
|
||||
* Handle group applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupApplying(ReportGroupApplying $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyVendorGroup($event);
|
||||
$this->applyAccountGroup($event);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,14 +3,16 @@
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
|
||||
class IncomeExpenseSummaryReport extends Listener
|
||||
class AddCustomersToReports extends Listener
|
||||
{
|
||||
protected $class = 'App\Reports\IncomeExpenseSummary';
|
||||
protected $classes = [
|
||||
'App\Reports\IncomeSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
@ -20,15 +22,11 @@ class IncomeExpenseSummaryReport extends Listener
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['years'] = $this->getYears();
|
||||
$event->class->filters['accounts'] = $this->getAccounts();
|
||||
$event->class->filters['categories'] = $this->getIncomeExpenseCategories();
|
||||
$event->class->filters['customers'] = $this->getCustomers();
|
||||
$event->class->filters['vendors'] = $this->getVendors();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,14 +37,11 @@ class IncomeExpenseSummaryReport extends Listener
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
$event->class->groups['account'] = trans_choice('general.accounts', 1);
|
||||
$event->class->groups['customer'] = trans_choice('general.customers', 1);
|
||||
$event->class->groups['vendor'] = trans_choice('general.vendors', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,12 +52,10 @@ class IncomeExpenseSummaryReport extends Listener
|
||||
*/
|
||||
public function handleReportGroupApplying(ReportGroupApplying $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyCustomerGroup($event);
|
||||
$this->applyVendorGroup($event);
|
||||
$this->applyAccountGroup($event);
|
||||
}
|
||||
}
|
||||
}
|
49
app/Listeners/Common/AddDateToReports.php
Normal file
49
app/Listeners/Common/AddDateToReports.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
|
||||
class AddDateToReports 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 handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['years'] = $this->getYears();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle filter applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterApplying(ReportFilterApplying $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply date
|
||||
$this->applyDateFilter($event);
|
||||
}
|
||||
}
|
54
app/Listeners/Common/AddExpenseCategoriesToReports.php
Normal file
54
app/Listeners/Common/AddExpenseCategoriesToReports.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
|
||||
class AddExpenseCategoriesToReports extends Listener
|
||||
{
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\ExpenseSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$categories = !empty($event->class->filters['categories']) ? $event->class->filters['categories'] : [];
|
||||
|
||||
$event->class->filters['categories'] = array_merge($categories, $this->getExpenseCategories());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\ExpenseSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
'App\Reports\ProfitLoss',
|
||||
'App\Reports\TaxSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
}
|
||||
}
|
54
app/Listeners/Common/AddIncomeCategoriesToReports.php
Normal file
54
app/Listeners/Common/AddIncomeCategoriesToReports.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
|
||||
class AddIncomeCategoriesToReports extends Listener
|
||||
{
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\IncomeSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$categories = !empty($event->class->filters['categories']) ? $event->class->filters['categories'] : [];
|
||||
|
||||
$event->class->filters['categories'] = array_merge($categories, $this->getIncomeCategories());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\IncomeSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
'App\Reports\ProfitLoss',
|
||||
'App\Reports\TaxSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
}
|
||||
}
|
49
app/Listeners/Common/AddSearchToReports.php
Normal file
49
app/Listeners/Common/AddSearchToReports.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
|
||||
class AddSearchToReports 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 handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//$event->class->filters['search'] = $this->getSearch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle filter applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterApplying(ReportFilterApplying $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply date
|
||||
$this->applySearchStringFilter($event);
|
||||
}
|
||||
}
|
61
app/Listeners/Common/AddVendorsToReports.php
Normal file
61
app/Listeners/Common/AddVendorsToReports.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
|
||||
class AddVendorsToReports extends Listener
|
||||
{
|
||||
protected $classes = [
|
||||
'App\Reports\ExpenseSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['vendors'] = $this->getVendors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['vendor'] = trans_choice('general.vendors', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupApplying(ReportGroupApplying $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyVendorGroup($event);
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterApplying;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
|
||||
class IncomeSummaryReport extends Listener
|
||||
{
|
||||
protected $class = 'App\Reports\IncomeSummary';
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['years'] = $this->getYears();
|
||||
$event->class->filters['accounts'] = $this->getAccounts();
|
||||
$event->class->filters['categories'] = $this->getIncomeCategories();
|
||||
$event->class->filters['customers'] = $this->getCustomers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle filter applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterApplying(ReportFilterApplying $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply date
|
||||
$this->applyDateFilter($event);
|
||||
|
||||
// Apply search
|
||||
$this->applySearchStringFilter($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
$event->class->groups['account'] = trans_choice('general.accounts', 1);
|
||||
$event->class->groups['customer'] = trans_choice('general.customers', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group applying event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupApplying(ReportGroupApplying $event)
|
||||
{
|
||||
if (!$this->checkClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyCustomerGroup($event);
|
||||
$this->applyAccountGroup($event);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
|
||||
class ProfitLossReport extends Listener
|
||||
{
|
||||
protected $class = 'App\Reports\ProfitLoss';
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
|
||||
class TaxSummaryReport extends Listener
|
||||
{
|
||||
protected $class = 'App\Reports\TaxSummary';
|
||||
}
|
@ -59,10 +59,12 @@ class Event extends Provider
|
||||
* @var array
|
||||
*/
|
||||
protected $subscribe = [
|
||||
'App\Listeners\Common\IncomeSummaryReport',
|
||||
'App\Listeners\Common\ExpenseSummaryReport',
|
||||
'App\Listeners\Common\IncomeExpenseSummaryReport',
|
||||
'App\Listeners\Common\TaxSummaryReport',
|
||||
'App\Listeners\Common\ProfitLossReport',
|
||||
'App\Listeners\Common\AddDateToReports',
|
||||
'App\Listeners\Common\AddAccountsToReports',
|
||||
'App\Listeners\Common\AddCustomersToReports',
|
||||
'App\Listeners\Common\AddVendorsToReports',
|
||||
'App\Listeners\Common\AddExpenseCategoriesToReports',
|
||||
'App\Listeners\Common\AddIncomeCategoriesToReports',
|
||||
'App\Listeners\Common\AddSearchToReports',
|
||||
];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user