<?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php


        $startTime = \Carbon\Carbon::createFromFormat('d/m/Y', '01/'.$item->date_action_group)->startOfMonth()->toDateString();
        $endTime = \Carbon\Carbon::createFromFormat('d/m/Y', '01/'.$item->date_action_group)->endOfMonth()->toDateString();

if(!empty($hostelId))
{
$moneyInfoItems = \App\Models\MoneyInfo::where('hostel_id', $hostelId);
} else {
if(auth('backend')->user()->type == \App\User::STAFF)
{
    $hostels = \App\Components\Functions::getHostelArrStaff();
} else {
$hostels = \App\Models\Hostel::where('owner_id', auth('backend')->user()->id)->pluck('id')->toArray();
}

$moneyInfoItems = \App\Models\MoneyInfo::whereIn('hostel_id', $hostels);

}
        $moneyInfoItems = $moneyInfoItems

        ->when($owner->type_display_money_info == \App\User::TYPE_DISPLAY_MONEY_INFO_PREVIOUS_MONTH, function ($q) use ($month) {
                    $q->where(function ($q) use ($month) {
                        $q->orWhere(function ($q) use ($month) {
                            $q->whereBetween('date_action', [
                                $month->copy()->startOfMonth(),
                                $month->copy()->endOfMonth()
                            ]);
                            $q->whereIn('type', [
                                \App\Models\MoneyInfo::VOUCHER_CONTRACT,
                                \App\Models\MoneyInfo::VOUCHER_ROOM_PRICE
                            ]);
                        });

                        $q->orWhere(function ($q) use ($month) {
                            $q->whereBetween('date_action', [
                                $month->copy()->subMonth()->startOfMonth(),
                                $month->copy()->subMonth()->endOfMonth()
                            ]);
                            $q->where('type', \App\Models\MoneyInfo::VOUCHER_SERVICE);
                        });
                    });

                }, function ($q) use ($month) {

                    $q->whereBetween('date_action', [
                        $month->copy()->startOfMonth(),
                        $month->copy()->endOfMonth()
                    ]);

                });


    if(!empty($type))
    {
        if($type == 'paid')
        {
        $moneyInfoItems = $moneyInfoItems->where('remain', 0);

        } else if ($type == 'not-paid')
        {
 $moneyInfoItems = $moneyInfoItems->where('remain', '>', 0);
        }
    }

    if(!empty($contractId))
    {
        $moneyInfoItems = $moneyInfoItems->where('contract_id', $contractId);
    }

    $moneyInfoItems = $moneyInfoItems->get();

    ?> <?php if($moneyInfoItems->count() > 0): ?> <div class="portlet box yellow"> <div class="portlet-title"> <div class="caption">Tháng <?php echo e($item->date_action_group); ?> </div> <div class="tools"> <a href="javascript:;" class="collapse" data-original-title="" title=""> </a> </div> </div> <div class="portlet-body" style="display: block;"> <div class="row"> <div class="col-md-12"> <?php $__currentLoopData = $moneyInfoItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $moneyInfoItem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php
                            $details = \App\Models\MoneyDetail::where('money_info_id', $moneyInfoItem->id)->get();
               $room = $moneyInfoItem->room;

               $dateAction = $item->date_action->format('m/Y');
               $pay = \App\Components\Functions::calculateAmountForOrder($moneyInfoItem->id)['pay'];
               $sum = 0;
                           foreach($details as $detail) {
                           if(!empty($detail->sum_amount))
                           {
                            $sum+= $detail->sum_amount;
                           } else {
                       $sum+= $detail->amount;
                                       }
                        }


                        ?> <div class="portlet box <?php if($sum == ($pay + $moneyInfoItem->discount)): ?> green-jungle <?php elseif($pay == 0): ?> red <?php else: ?> green-steel <?php endif; ?>"> <div class="portlet-title"> <div class="caption"> <?php echo e(!empty($moneyInfoItem->hostel) ? $moneyInfoItem->hostel->name : null); ?> - Phòng <?php echo e(!empty($moneyInfoItem->room) ? $moneyInfoItem->room->name : null); ?> - <?php echo e(!empty($moneyInfoItem->contract) ? $moneyInfoItem->contract->name : null); ?> - <?php if($sum == $pay): ?> Đã thanh toán <?php elseif($pay == 0): ?> Chưa thanh toán <?php else: ?> Đã thanh toán một phần <?php endif; ?></div> </div> <div class="portlet-body"> <?php echo $__env->make('admin2.money.detail', [ 'item' => $moneyInfoItem, 'details' => $details, 'pay' => $pay, 'sum' => $sum], \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?> </div> </div> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> </div> </div> </div> </div> <?php endif; ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>