refactored report listener
This commit is contained in:
@ -6,6 +6,7 @@ use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
|
||||
class AddAccountsToReports extends Listener
|
||||
{
|
||||
@ -13,8 +14,6 @@ class AddAccountsToReports extends Listener
|
||||
'App\Reports\IncomeSummary',
|
||||
'App\Reports\ExpenseSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
'App\Reports\ProfitLoss',
|
||||
'App\Reports\TaxSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -61,4 +60,27 @@ class AddAccountsToReports extends Listener
|
||||
|
||||
$this->applyAccountGroup($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle rows showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if ($this->skipRowsShowing($event, 'account')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($accounts = request('accounts')) {
|
||||
$rows = collect($event->class->filters['accounts'])->filter(function ($value, $key) use ($accounts) {
|
||||
return in_array($key, $accounts);
|
||||
});
|
||||
} else {
|
||||
$rows = $event->class->filters['accounts'];
|
||||
}
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
|
||||
class AddCustomersToReports extends Listener
|
||||
{
|
||||
@ -58,4 +59,27 @@ class AddCustomersToReports extends Listener
|
||||
|
||||
$this->applyCustomerGroup($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle rows showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if ($this->skipRowsShowing($event, 'customer')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($customers = request('customers')) {
|
||||
$rows = collect($event->class->filters['customers'])->filter(function ($value, $key) use ($customers) {
|
||||
return in_array($key, $customers);
|
||||
});
|
||||
} else {
|
||||
$rows = $event->class->filters['customers'];
|
||||
}
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,14 @@ namespace App\Listeners\Common;
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
|
||||
class AddExpenseCategoriesToReports extends Listener
|
||||
{
|
||||
protected $classes = [
|
||||
'App\Reports\ExpenseSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
@ -16,18 +21,11 @@ class AddExpenseCategoriesToReports extends Listener
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\ExpenseSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$categories = !empty($event->class->filters['categories']) ? $event->class->filters['categories'] : [];
|
||||
|
||||
$event->class->filters['categories'] = array_merge($categories, $this->getExpenseCategories());
|
||||
$event->class->filters['categories'] = $this->getExpenseCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,17 +36,33 @@ class AddExpenseCategoriesToReports extends Listener
|
||||
*/
|
||||
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)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle rows showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if ($this->skipRowsShowing($event, 'category')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($categories = request('categories')) {
|
||||
$rows = collect($event->class->filters['categories'])->filter(function ($value, $key) use ($categories) {
|
||||
return in_array($key, $categories);
|
||||
});
|
||||
} else {
|
||||
$rows = $event->class->filters['categories'];
|
||||
}
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,14 @@ namespace App\Listeners\Common;
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
|
||||
class AddIncomeCategoriesToReports extends Listener
|
||||
{
|
||||
protected $classes = [
|
||||
'App\Reports\IncomeSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
@ -16,18 +21,11 @@ class AddIncomeCategoriesToReports extends Listener
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\IncomeSummary',
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$categories = !empty($event->class->filters['categories']) ? $event->class->filters['categories'] : [];
|
||||
|
||||
$event->class->filters['categories'] = array_merge($categories, $this->getIncomeCategories());
|
||||
$event->class->filters['categories'] = $this->getIncomeCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,17 +36,33 @@ class AddIncomeCategoriesToReports extends Listener
|
||||
*/
|
||||
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)) {
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle rows showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if ($this->skipRowsShowing($event, 'category')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($categories = request('categories')) {
|
||||
$rows = collect($event->class->filters['categories'])->filter(function ($value, $key) use ($categories) {
|
||||
return in_array($key, $categories);
|
||||
});
|
||||
} else {
|
||||
$rows = $event->class->filters['categories'];
|
||||
}
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
}
|
||||
}
|
||||
|
108
app/Listeners/Common/AddIncomeExpenseCategoriesToReports.php
Normal file
108
app/Listeners/Common/AddIncomeExpenseCategoriesToReports.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
class AddIncomeExpenseCategoriesToReports extends Listener
|
||||
{
|
||||
/**
|
||||
* Handle filter showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportFilterShowing(ReportFilterShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->filters['categories'] = $this->getIncomeExpenseCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle group showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportGroupShowing(ReportGroupShowing $event)
|
||||
{
|
||||
$classes = [
|
||||
'App\Reports\IncomeExpenseSummary',
|
||||
'App\Reports\ProfitLoss',
|
||||
];
|
||||
|
||||
if (empty($event->class) || !in_array(get_class($event->class), $classes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->class->groups['category'] = trans_choice('general.categories', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle records showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if (
|
||||
empty($event->class)
|
||||
|| empty($event->class->model->settings->group)
|
||||
|| ($event->class->model->settings->group != 'category')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (get_class($event->class)) {
|
||||
case 'App\Reports\ProfitLoss':
|
||||
$categories = Category::type(['income', 'expense'])->orderBy('name')->get();
|
||||
$rows = $categories->pluck('name', 'id')->toArray();
|
||||
|
||||
$this->setRowNamesAndValuesForProfitLoss($event, $rows, $categories);
|
||||
|
||||
break;
|
||||
case 'App\Reports\IncomeExpenseSummary':
|
||||
if ($categories = request('categories')) {
|
||||
$rows = collect($event->class->filters['categories'])->filter(function ($value, $key) use ($categories) {
|
||||
return in_array($key, $categories);
|
||||
});
|
||||
} else {
|
||||
$rows = $event->class->filters['categories'];
|
||||
}
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function setRowNamesAndValuesForProfitLoss($event, $rows, $categories)
|
||||
{
|
||||
foreach ($event->class->dates as $date) {
|
||||
foreach ($event->class->tables as $type_id => $type_name) {
|
||||
foreach ($rows as $id => $name) {
|
||||
$category = $categories->where('id', $id)->first();
|
||||
|
||||
if ($category->type != $type_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$event->class->row_names[$type_name][$id] = $name;
|
||||
$event->class->row_values[$type_name][$id][$date] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
app/Listeners/Common/AddRowsToTaxReport.php
Normal file
33
app/Listeners/Common/AddRowsToTaxReport.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Common;
|
||||
|
||||
use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
|
||||
class AddRowsToTaxReport extends Listener
|
||||
{
|
||||
protected $classes = [
|
||||
'App\Reports\TaxSummary',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle rows showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if ($this->skipThisClass($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = [
|
||||
'income' => trans_choice('general.sales', 2),
|
||||
'expense' => trans_choice('general.purchases', 2),
|
||||
];
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ use App\Abstracts\Listeners\Report as Listener;
|
||||
use App\Events\Common\ReportFilterShowing;
|
||||
use App\Events\Common\ReportGroupApplying;
|
||||
use App\Events\Common\ReportGroupShowing;
|
||||
use App\Events\Common\ReportRowsShowing;
|
||||
|
||||
class AddVendorsToReports extends Listener
|
||||
{
|
||||
@ -58,4 +59,27 @@ class AddVendorsToReports extends Listener
|
||||
|
||||
$this->applyVendorGroup($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle rows showing event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleReportRowsShowing(ReportRowsShowing $event)
|
||||
{
|
||||
if ($this->skipRowsShowing($event, 'vendor')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($vendors = request('vendors')) {
|
||||
$rows = collect($event->class->filters['vendors'])->filter(function ($value, $key) use ($vendors) {
|
||||
return in_array($key, $vendors);
|
||||
});
|
||||
} else {
|
||||
$rows = $event->class->filters['vendors'];
|
||||
}
|
||||
|
||||
$this->setRowNamesAndValues($event, $rows);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user