added events to manipulate report data

This commit is contained in:
Denis Duliçi 2020-07-02 01:55:45 +03:00
parent a96d6f22bc
commit d22a3e2001
5 changed files with 68 additions and 12 deletions

View File

@ -2,6 +2,8 @@
namespace App\Abstracts; namespace App\Abstracts;
use App\Events\Report\DataLoaded;
use App\Events\Report\DataLoading;
use App\Events\Report\FilterApplying; use App\Events\Report\FilterApplying;
use App\Events\Report\FilterShowing; use App\Events\Report\FilterShowing;
use App\Events\Report\GroupApplying; use App\Events\Report\GroupApplying;
@ -92,12 +94,21 @@ abstract class Report
$this->setDates(); $this->setDates();
$this->setFilters(); $this->setFilters();
$this->setRows(); $this->setRows();
$this->setData(); $this->loadData();
$this->setColumnWidth(); $this->setColumnWidth();
$this->loaded = true; $this->loaded = true;
} }
public function loadData()
{
event(new DataLoading($this));
$this->setData();
event(new DataLoaded($this));
}
public function getDefaultName() public function getDefaultName()
{ {
if (!empty($this->default_name)) { if (!empty($this->default_name)) {

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Report;
use Illuminate\Queue\SerializesModels;
class DataLoaded
{
use SerializesModels;
public $class;
/**
* Create a new event instance.
*
* @param $class
*/
public function __construct($class)
{
$this->class = $class;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Report;
use Illuminate\Queue\SerializesModels;
class DataLoading
{
use SerializesModels;
public $class;
/**
* Create a new event instance.
*
* @param $class
*/
public function __construct($class)
{
$this->class = $class;
}
}

View File

@ -72,17 +72,6 @@ class ProfitLoss extends Report
break; break;
} }
// TODO: move to views
foreach ($this->footer_totals as $table => $dates) {
foreach ($dates as $date => $total) {
if (!isset($this->net_profit[$date])) {
$this->net_profit[$date] = 0;
}
$this->net_profit[$date] += $total;
}
}
} }
public function getFields() public function getFields()

View File

@ -1,3 +1,15 @@
@php
foreach ($class->footer_totals as $table => $dates) {
foreach ($dates as $date => $total) {
if (!isset($class->net_profit[$date])) {
$class->net_profit[$date] = 0;
}
$class->net_profit[$date] += $total;
}
}
@endphp
<div class="table-responsive my-2"> <div class="table-responsive my-2">
<table class="table table-hover align-items-center rp-border-collapse"> <table class="table table-hover align-items-center rp-border-collapse">
<tfoot class="border-top-style"> <tfoot class="border-top-style">