Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/ledger.corals.io/Corals/modules/Ledger/Reports/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ledger.corals.io/Corals/modules/Ledger/Reports/BalanceReport.php
<?php

namespace Corals\Modules\Ledger\Reports;

use Corals\Modules\Ledger\Models\Account;
use Corals\Modules\Ledger\Models\Record;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class BalanceReport
{
    use AuthorizesRequests;

    public function getTitle()
    {
        return trans('Ledger::labels.reports.balance-report');
    }

    public function __construct()
    {
        $this->authorize('Administrations::admin.ledger');
    }

    public function getData()
    {
        $result = [];

        foreach (config('ledger.supported_currencies') as $currency) {
            $subQuery = Record::query()
                ->whereColumn('account_id', 'ledger_accounts.id')
                ->where('ledger_records.currency', $currency);

            $creditAmount = (clone $subQuery)
                ->where('ledger_records.type', 'credit')
                ->selectRaw('SUM(ledger_records.amount) AS credit_amount');

            $debitAmount = (clone $subQuery)
                ->where('ledger_records.type', 'debit')
                ->selectRaw('SUM(ledger_records.amount) AS debit_amount');


            $currencyResult = Account::query()
                ->select('ledger_accounts.*')
                ->selectSub($creditAmount->getQuery(), 'credit_amount')
                ->selectSub($debitAmount->getQuery(), 'debit_amount')
                ->orderBy('ledger_accounts.id')
                ->get()->filter(function ($account) {
                    return $account->credit_amount || $account->debit_amount;
                });

            if ($currencyResult->isNotEmpty()) {
                $result[$currency] = $currencyResult;
            }
        }

        return $result;
    }

    public function render()
    {
        $balanceReport = $this;
        return view('Ledger::reports.balance_report')->with(compact('balanceReport'));
    }
}

Spamworldpro Mini