<table cellspacing="0" style="border-collapse:collapse; height:120px;"> <tbody> <tr> <td style="background-color:#5b9bd5; border:1px solid #000000; height:40px; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Nh&agrave; trọ</span></span></td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Ph&ograve;ng trọ</span></span></td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Hợp đồng</span></span></td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Th&aacute;ng</span></span> </td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Ng&agrave;y chốt</span></span></td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Số điện đầu</span></span> </td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Số điện cuối</span></span> </td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Số nước đầu</span></span> </td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">Số nước cuối</span></span> </td> <td style="background-color:#5b9bd5; border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000">SĐT người chốt</span></span></td> </tr> <?php $__currentLoopData = $hostels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $hostel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php $__currentLoopData = $hostel->contractValids; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contract): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php $room = $contract->room;

$ew = App\Components\Functions::getEwLatestRoom5($contract->room, $contract, $monthCarbon->copy());


 ?> <?php
                 $feeE   = \App\Models\HostelFee::query()
		                   ->where( 'hostel_id', $hostel->id )
		                   ->whereIn('type', [
		                       \App\Models\HostelFee::ELECTRIC,
		                       \App\Models\HostelFee::ELECTRIC_BY_CLOCK
])
		                   ->first();
$feeW   = \App\Models\HostelFee::query()
		                   ->where( 'hostel_id', $hostel->id )
		                   ->whereIn('type', [
		                       \App\Models\HostelFee::WATER,
		                       \App\Models\HostelFee::WATER_BY_CLOCK
])
		                   ->first();

                 $qE = App\Components\Functions::getEwLatestContract($contract, $feeE);
                 $qW = App\Components\Functions::getEwLatestContract($contract, $feeW);
$moneyDetailE = null;
$moneyDetailW=null;
                 if($feeE) {
            $moneyDetailE = \App\Models\MoneyDetail::query()
            ->whereHas('moneyInfo', function($query) use ($monthCarbon, $contract) {
                $query->whereBetween('date_action', [ $monthCarbon->copy()->startOfMonth(), $monthCarbon->copy()->endOfMonth()]);
                 $query->where('type', \App\Models\MoneyInfo::VOUCHER_SERVICE);
                  $query->where('contract_id', $contract->id);

            })

            ->where('hostel_fee_id', $feeE->id)
            ->first();
            }
             if($feeW) {
            $moneyDetailW = \App\Models\MoneyDetail::query()
            ->whereHas('moneyInfo', function($query) use ($monthCarbon, $contract) {
                $query->whereBetween('date_action', [ $monthCarbon->copy()->startOfMonth(), $monthCarbon->copy()->endOfMonth()]);
                 $query->where('type', \App\Models\MoneyInfo::VOUCHER_SERVICE);
                  $query->where('contract_id', $contract->id);

            })

            ->where('hostel_fee_id', $feeW->id)
            ->first();
            }
            ?> <?php if($moneyDetailE): ?> <?php
                    $info = json_decode($moneyDetailE->qty, true);
                           $startElectric = $info['start'];
                          $endElectric = $info['end'];
                ?> <?php endif; ?> <?php if($moneyDetailW): ?> <?php
                    $info = json_decode($moneyDetailW->qty, true);
                          $startWater = $info['start'];
                          $endWater = $info['end'];
                ?> <?php endif; ?> <tr> <td style="border:1px solid #000000; height:40px; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"><?php echo e($hostel->name); ?></span></span></td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"><?php echo e($room->name); ?></span></span></td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"><?php echo e($contract->name); ?></span></span></td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"><?php echo e($monthCarbon->format('m/Y')); ?></span></span></td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"><?php echo e($dateCarbon->format('d/m/Y')); ?></span></span></td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"> <?php if($moneyDetailE): ?> <?php echo e($startElectric); ?> <?php else: ?> <?php if(!empty($ew)): ?> <?php echo e($ew['e']); ?> <?php else: ?> <?php echo e($qE); ?> <?php endif; ?> <?php endif; ?> </span></span> </td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"> <?php if($moneyDetailE): ?> <?php echo e($endElectric); ?> <?php else: ?> 0 <?php endif; ?> </span></span> </td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"> <?php if($moneyDetailW): ?> <?php echo e($startWater); ?> <?php else: ?> <?php if(!empty($ew)): ?> <?php echo e($ew['w']); ?> <?php else: ?> <?php echo e($qW); ?> <?php endif; ?> <?php endif; ?></span></span> </td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal;"> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"> <?php if($moneyDetailW): ?> <?php echo e($endWater); ?> <?php else: ?> 0 <?php endif; ?></span></span> </td> <td style="border:1px solid #000000; text-align:center; vertical-align:middle; white-space:normal; "> <span style="font-family:&quot;Times New Roman&quot;"><span style="color:#000000"><?php echo e(auth('backend')->user()->phone); ?></span></span></td> </tr> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> </tbody> </table>