I have a sketch of calculation like this
+------------+---------------+-------------+-------------+
Name IN OUT SALDO
+------------+---------------+-------------+-------------+
Cash 8% $50 - $50
Cash 4% $20 - $70
Cash 12% $70 - $140
Claimed - $60 $80
Claimed - $20 $60
+------------------------------------------+-------------+
TOTAL SALDO $60
+------------------------------------------+-------------+
The table above is what I am expecting to have. However this is the result what I got for now:
+------------+---------------+-------------+-------------+
Name IN OUT SALDO
+------------+---------------+-------------+-------------+
Cash 8% $50 - 0
Cash 4% $20 - $50
Cash 12% $70 - $70
Claimed - $60 $140
Claimed - $20 $80
+------------------------------------------+-------------+
TOTAL SALDO $60
+------------------------------------------+-------------+
The problem is it give the 0 saldo in the first row even though the calculation is correct.
Here is my full code
if ($saldo->num_rows > 0) {
while($objek = $saldo->fetch_object()) {
$i++;
if ($objek->eight_percent)
{
$sourceCash = $totalTwelve + $totalEight + $totalFour + $totalTwo - $totalClaim - $totalCashout;
$totalEight = $totalEight + $objek->eight_percent;
echo "<tr>
<td>Cashback 8%</td>
<td> - </td>
<td>".$sourceCash."</td>
</tr>";
}
Thanks in advance for the help.