CasperSecurity
<?php
namespace App\Http\Livewire\Report;
use App\Models\AccountGroup;
use App\Models\AccountType;
use App\Models\LedgerHead;
use App\Models\Organisation;
use Livewire\Component;
class ChartaccountReportLivewire extends Component
{
public $search;
public $perPage = 10;
public $orderBy = 'id';
public $orderAsc = '1';
public function closemodalclick()
{
$this->resetValidation();
$this->datatable = [];
}
public function read()
{
$ledger_heads = LedgerHead::select('ledger_heads.*','ledger_heads.ledger_head_name','account_groups.account_group_name','account_types.account_type')
->join('account_groups','ledger_heads.account_group_id','=','account_groups.id')
->join('account_types', 'account_groups.account_type_id', '=', 'account_types.id')
->get('');
return $ledger_heads;
}
/* public function read()
{
$account_types = AccountType::where('id', $this->account_type_id)->latest()->first()
->join('account_groups','ledger_heads.account_group_id','=','account_groups.id')
->join('ledger_heads','ledger_heads.ledger_head_name','=','account_types.id');
return $account_types;
}*/
public function render()
{
$org = Organisation::latest()->first();
$datatable = [];
$datatable = $this->read();
$assets = $datatable->filter(function ($item) {return $item->account_type === 'Assets';})->groupBy('account_group_name');
$liabilities = $datatable->filter(function ($item) {return $item->account_type === 'Liabilities';})->groupBy('account_group_name');
$equity = $datatable->filter(function ($item) {return $item->account_type === 'Equity';})->groupBy('account_group_name');
$income = $datatable->filter(function ($item) {return $item->account_type === 'Income';})->groupBy('account_group_name');
$expense = $datatable->filter(function ($item) {return $item->account_type === 'Expense';})->groupBy('account_group_name');
return view('livewire.report.chartaccount-report-livewire',compact('datatable','org','assets','liabilities','equity','income','expense'));
}
}