vendredi 30 septembre 2016

sum column based on another column laravel

I want to sum column AMOUNT, and the result is fill the column BALANCE. if column TYPE is DEBIT, then it will sum.. but if column TYPE is KREDIT, then it will be minus. this is the table table image

to create that table, i used this query in laravel controller :

$get_result        =  DB::select( DB::raw("SELECT statement.created_at, statement.descript, statement.amount, statement.sign, statement.reference 
                                                    FROM statement,lender 
                                                    WHERE statement.created_at BETWEEN DATE_ADD(' $date_from ',INTERVAL 1 DAY) 
                                                    AND '$date_to' 
                                                    AND statement.lender_id = lender.id 
                                                    AND lender.user_id= $userId ") );

and I used this code in view to display data :

<thead>
                                <tr class="txtcenter">
                                    <th class="all">Date </th>
                                    <th class="all">Description </th>
                                    <th class="all">Amount</th>
                                    <th class="all">Type</th>
                                    <th class="all">Reference</th>
                                    <th class="all">Balance</th>
                                </tr>
                            </thead>
                            <tbody>@foreach($get_period as $statement)
                                    <tr class="accordion">
                                        <td></div>
                                        <td> </div>
                                        <td>IDR   </div> 
                                        <td>  </div>
                                        <td> </div>
                                        <td>  </div>
                                    </tr>@endforeach
                            </tbody>

I do not know how to make the proper code to calculate it all. Please help me. Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2dexI3e
via IFTTT

Aucun commentaire:

Enregistrer un commentaire