<style> .red { color: #eb4034; } .uppercase { text-transform: uppercase } .header-ew { font-weight: bold; } <?php if(isset($isExcel)): ?> #tb td, #tb th { border: 1px solid #000000; } td { text-align: center; } th { text-align: center; } <?php endif; ?> </style> <table class="table table-striped table-bordered table-hover" id="tb"> <tr> <th colspan="9" class="uppercase">Báo cáo tình hình sử dụng điện nước nhà <?php echo e($hostel->name); ?></th> </tr> <tr> </tr> <tr> <th>Ngày đọc</th> <th>Phòng</th> <th>Khách hàng</th> <th>SĐT</th> <th>Chỉ số đầu</th> <th>Chỉ số cuối</th> <th>Số sử dụng</th> <th>Đơn giá</th> <th>Thành tiền</th> </tr> <tr> <td colspan="9" class="header-ew uppercase">Điện</td> </tr> <?php $sumDeltaElectric = 0; $sumDeltaWater = 0; $sumElectric = 0; $sumWater = 0;?> <?php $__currentLoopData = $hostel->rooms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $room): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php
                $startElectric = $room->ewMonth($month)->sum('start_electric');
if(empty($startElectric))
    {
        $startElectric = $room->ewMonth($month->copy()->subMonth())->sum('end_electric');
    }
        $endElectric = $room->ewMonth($month)->sum('end_electric');
        $item = $room->ewMonth($month)->first();
        $dateAction = null;
        $dateExecution = null;
        $priceElectric = 0;
        $priceWater = 0;
        if($item)
        {
         $priceElectric = $item->price_electric;
    $priceWater = $item->price_water;
        if($item->date_execution) {
        $dateExecution = $item->date_execution->format('m');
        }
         if($item->date_action) {
            $dateAction = $item->date_action->format('d/m/Y');
            if(empty($dateExecution))
            {
            $dateExecution = $item->date_action->subMonth()->format('m');
            }
            }
        }

        $sumDeltaElectric += ($endElectric - $startElectric);
        $sumElectric += ($endElectric - $startElectric) * $priceElectric;
                ?> <tr> <td><?php echo e($dateAction); ?></td> <td><?php echo e($room->name); ?></td> <td><?php echo e(optional($room->contract)->name); ?></td> <td></td> <td><?php echo e($startElectric); ?></td> <td><?php echo e($endElectric); ?></td> <td><?php echo e($endElectric - $startElectric); ?></td> <td><?php echo e(number_format($priceElectric, 0, '.', ',')); ?></td> <td><?php echo e(number_format(($endElectric - $startElectric) * $priceElectric, 0, '.', ',')); ?></td> </tr> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> <tr> <td colspan="6" class="header-ew uppercase" style=" text-align: left;">Tổng tòa nhà</td> <td><strong> <?php echo e($sumDeltaElectric); ?></strong></td> <td></td> <td><strong><?php echo e(number_format($sumElectric, 0, '.', '.')); ?></strong></td> </tr> <tr> <td colspan="9" class="header-ew uppercase">Nước</td> </tr> <?php $__currentLoopData = $hostel->rooms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $room): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php
            $startWater = $room->ewMonth($month->copy())->sum('start_water');
//if(empty($startWater))
  //  {
    //    $startWater = $room->ewMonth($month->copy()->subMonth())->sum('end_water');
    //}
    $endWater = $room->ewMonth($month->copy())->sum('end_water');
    $item = $room->ewMonth($month->copy())->first();
    $dateAction = null;
    $dateExecution = null;
    $priceElectric = 0;
    $priceWater= 0;

    if($item)
    {
  $priceElectric = $item->price_electric;
    $priceWater = $item->price_water;
    if($item->date_execution) {
    $dateExecution = $item->date_execution->format('d/m/Y');
    }
     if($item->date_action) {
        $dateAction = $item->date_action->format('d/m/Y');
        if(empty($dateExecution))
            {
            $dateExecution = $item->date_action->subMonth()->format('m');
            }
        }
    }
         $sumDeltaWater += ($endWater - $startWater);
      $sumWater += ($endWater - $startWater) * $priceWater;
        ?> <tr> <td><?php echo e($dateAction); ?></td> <td><?php echo e($room->name); ?></td> <td><?php echo e(optional($room->contracts->first())->name); ?></td> <td></td> <td><?php echo e($startWater); ?></td> <td><?php echo e($endWater); ?></td> <td><?php echo e($endWater - $startWater); ?></td> <td><?php echo e(number_format($priceWater, 0, '.', ',')); ?></td> <td><?php echo e(number_format(($endWater - $startWater) * $priceWater, 0, '.', ',')); ?></td> </tr> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> <tr> <td colspan="6" class="header-ew uppercase" style=" text-align: left;">Tổng tòa nhà</td> <td> <strong><?php echo e($sumDeltaWater); ?></strong></td> <td></td> <td><strong><?php echo e(number_format($sumWater, 0, '.', '.')); ?></strong></td> </tr> </table>