我试图在刀片中复制银行状态的外观到目前为止,我可以使用以下代码正确显示信用和借记,但我未能掌握如何创建运行总计
<tbody>
@foreach($customers['$resources'] as $resource)
<tr>
<td class="date"> {{-- */$date = $resource['date'];
preg_match( "#/Date\((\d{10})\d{3}(.*?)\)/#", $date, $match );/*--}}{{date( 'd/m/Y', $match[1] )}} </td>
<td>{{$resource['reference']}}</td>
@if ($resource['amountNet'] >=0.1)
<td class="currency">
<span>£{{number_format((float)$resource['amountPaid'], 2, '.', '')}} </span>
</td>
<td class="currency">
<span> </span>
</td>
<td class="currency">
<span> £{{-- */
$runningTotal = $resource['amountNet'];
if ($resource['amountNet'] < 0) {
$runningTotal = $runningTotal - $resource['amountNet'];
} else {
$runningTotal = $runningTotal + $resource['amountNet'];
} /*--}}{{$runningTotal}}
</span>
</td>
@elseif($resource['amountNet'] <= 1 )
<td class="currency">
<span> </span>
</td>
<td class="currency">
<span>£{{number_format((float)$resource['amountPaid'], 2, '.', '')}} </span>
</td>
<td class="currency">
<span> £ </span>
</td>
@endif
</tr>
@endforeach
</tbody>
“$ resource ['amountNet']”是一个带符号的值,因为“$ resource ['amountPaid']”只是一个我无法访问数据库来修改它的值。到目前为止,第一行是期初余额,因此第一行余额应该等于该余额但是它是双倍的,下一个余额应该是+/-取决于是否可以获得任何帮助的信用卡或借记卡
答案 0 :(得分:2)
看起来您在for循环的每次迭代中都覆盖了$ runningTotal变量。
您需要设置for循环范围的 变量,然后在for循环中更新它:
<tbody>
{{$runningTotal = 0}}
@foreach($customers['$resources'] as $resource)
...
£{{ $runningTotal += $resource['amountNet'] }}
...
@endforeach
</tbody>