I'm building a financial system using Laravel (school assignment) but I'm stuck. How do I get the remaining balance for each region using Laravel?
I have two tables. first table "keuangan" its mean "finance" in english. the second is region. have many to many relationships
In my "keuangan" table keuangan table
to get income data, i use this. By the way, i am sorry if this is difficult to understand -- i used Indonesian language in my column name
$dataPemasukan = Region::addSelect(['totalPendapatan' => Keuangan::selectRaw('sum(jumlah) as total') ->whereColumn('region_id', 'regions.id') ->Where('status', 'Lunas') ->where('tipe_transaksi', 'pemasukan') ->groupBy('region_id')]) ->orderBy('totalPendapatan', 'DESC')->get();
its return region income region income data
for expense data i do the same thing, but I just changed where('tipe_transaksi', 'pengeluaran') its mean 'type_transaction', 'expense'.
to get the remaining balance. should just subtracting (income - expense) rigth?..
thats my problems.
in blade view i try like this
@foreach ($dataPemasukan as $d) @foreach ($dataPengeluaran as $p) <tr> <td></td> <td style="color: #42a4ff">-Rp.@convert($d->totalPendapatan - $p->totalPengeluaran)</td> </tr> @endforeach @endforeach
it turns out like this blade view
so How do I get financial balance of the region in laravel using eloquent? thank you...
https://stackoverflow.com/questions/66948647/how-to-get-financial-balance-of-the-region-laravel-eloquent April 05, 2021 at 01:33PM
没有评论:
发表评论