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()
{
return 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')
->orderBy('account_types.account_type', 'asc') // 1️⃣ Account Type
->orderBy('account_groups.account_group_name', 'asc') // 2️⃣ Group Name
->orderBy('ledger_heads.ledger_head_name', 'asc') // 3️⃣ Ledger Name
->get();
}
/* 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 === 'Expenditure';})->groupBy('account_group_name');
return view('livewire.report.chartaccount-report-livewire',compact('datatable','org','assets','liabilities','equity','income','expense'));
}
}