<div class="row"> <div class="col-md-12" id="payment-data" style="margin-bottom: 15px"> <p>Tổng số: <?php echo e(\App\Models\MoneyInfo::query() ->when(!empty($contractId), function($q) use ($contractId) { $q->where('contract_id', $contractId); }) ->where('room_id', $roomId) ->whereBetween('date_action', [$startTime, $endTime])->count()); ?> hóa đơn (Đã thanh toán: <?php echo e(\App\Models\MoneyInfo::query() ->when(!empty($contractId), function($q) use ($contractId) { $q->where('contract_id', $contractId); }) ->where('room_id', $roomId)->whereBetween('date_action', [$startTime, $endTime])->where('remain', 0)->count()); ?> hóa đơn. Chưa thanh toán xong: <?php echo e(\App\Models\MoneyInfo::query() ->when(!empty($contractId), function($q) use ($contractId) { $q->where('contract_id', $contractId); }) ->where('room_id', $roomId)->whereBetween('date_action', [$startTime, $endTime])->where('remain','>', 0)->count()); ?> hóa đơn)</p> <?php
            $sum =     \App\Models\MoneyInfo::query()
            ->when(!empty($contractId), function($q) use ($contractId) {
                $q->where('contract_id', $contractId);
            }) ->where('room_id', $roomId)->whereBetween('date_action', [$startTime, $endTime])->sum('amount');
        $paid =     \App\Models\MoneyInfo::query()
            ->when(!empty($contractId), function($q) use ($contractId) {
                $q->where('contract_id', $contractId);
            }) ->where('room_id', $roomId)->whereBetween('date_action', [$startTime, $endTime])->sum('pay');
        $discount =     \App\Models\MoneyInfo::query()
            ->when(!empty($contractId), function($q) use ($contractId) {
                $q->where('contract_id', $contractId);
            }) ->where('room_id', $roomId)->whereBetween('date_action', [$startTime, $endTime])->sum('discount');
        $remain = $sum - $paid - $discount;
        ?> <p>Tổng tiền: <?php echo e(number_format($sum, 0, '.', '.')); ?> (Đã thanh toán: <?php echo e(number_format($paid, 0, '.', '.')); ?>. Số tiền còn lại: <?php echo e(number_format($remain, 0, '.', '.')); ?>)</p> </div> </div> <?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();

         $moneyInfoItems = \App\Models\MoneyInfo::where('room_id', $roomId)
         ->whereBetween('date_action', [$startTime, $endTime]);

     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->orderBy('id', 'desc')->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($detail->sum_amount != 0)
                           {
                             $sum+= $detail->sum_amount;
                           } else {
                       $sum+= $detail->amount;
                       }

                                       }
                        ?> <div class="col-md-12"> <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" style="float: left"><?php echo e($moneyInfoItem->name); ?></div> <div class="caption" style="float: right"> <?php if($sum == ($pay + $moneyInfoItem->discount)): ?> Đã thanh toán <?php elseif($pay == 0): ?> Chưa thanh toán. Tổng số tiền: <?php echo e(number_format($sum - $moneyInfoItem->discount, 0, '.', '.')); ?> <?php else: ?> Đã thanh toán một phần. Số tiền còn lại: <?php echo e(number_format($sum - $pay - $moneyInfoItem->discount, 0, '.', '.')); ?> <?php endif; ?></div> </div> <div class="portlet-body"> <?php if($moneyInfoItem->contract): ?> <?php if($moneyInfoItem->type != \App\Models\MoneyInfo::VOUCHER_CONTRACT): ?> <h5>Hợp đồng: <?php echo e($moneyInfoItem->contract->code); ?></h5> <?php endif; ?> <h5>Người đại diện: <?php echo e($moneyInfoItem->contract->name); ?></h5> <?php endif; ?> <?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> </div> <div class="col-md-12"> <div class="row"> <?php if(in_array($moneyInfoItem->type, [ App\Models\MoneyInfo::VOUCHER_CONTRACT, App\Models\MoneyInfo::VOUCHER_ROOM_PRICE])): ?> <?php if(auth('backend')->user()->can('edit-money-info')): ?> <div class="col-md-3"> <a href="#" class="update-money-info" data-money-info="<?php echo e($moneyInfoItem->id); ?>">Cập nhật hóa đơn</a> </div> <?php endif; ?> <?php endif; ?> <div class="col-md-3"> <a data-money-info="<?php echo e($moneyInfoItem->id); ?>" data-date="<?php echo e($moneyInfoItem->date_action->format('m/Y')); ?>" class="print-money-info" target="_blank" href="<?php echo e(url('admin/money/print', ['id' => $moneyInfoItem->id])); ?>"> In phiếu</a> </div> <div class="col-md-3"> <a href="#" class="money-info-email" data-money-info="<?php echo e($moneyInfoItem->id); ?>">Email thông báo</a> </div> <div class="col-md-3"> <a href="#" class="money-info-message" data-money-info="<?php echo e($moneyInfoItem->id); ?>">Nhắn tin thông báo miễn phí 1</a> </div> </div> </div> <div class="col-md-12" style="margin-top: 15px"> <?php if(isset($pay)): ?> <?php if($pay == 0): ?> <?php if(auth('backend')->user()->can('add-payment')): ?> <button class="btn green-jungle btn-paid" data-money-info="<?php echo e($moneyInfoItem->id); ?>">Thanh toán </button> <?php endif; ?> <?php elseif($pay < $sum): ?> <?php if(auth('backend')->user()->can('add-payment')): ?> <button class="btn green-jungle btn-paid" data-money-info="<?php echo e($moneyInfoItem->id); ?>">Thanh toán bổ sung </button> <?php endif; ?> <?php endif; ?> <a href="#detail-history" data-toggle="modal" data-room="<?php echo e($room->id); ?>" data-money-info="<?php echo e($moneyInfoItem->id); ?>" class="btn purple-plum btn-detail-history">Lịch sử thanh toán</a> <?php endif; ?> </div> <div class="col-md-12 form-paid" id="form-paid-<?php echo e($moneyInfoItem->id); ?>" style="margin-top: 15px; margin-bottom: 15px"> </div> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> </div> </div> </div> </div> <?php endif; ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>