<div class="row"> <div class="col-md-12"> <h3 class="text-center">Danh sách hóa đơn</h3> <h5 class="text-center">Phòng <?php echo e($room->name); ?> - <?php echo e($hostel->name); ?></h5> </div> <div class="col-md-12" style="margin-bottom: 15px"> <form id="form-payment-filter" action="#"> <input type="hidden" name="room_id" value="<?php echo e($room->id); ?>"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Chọn</label> <select class="form-control" name="type"> <option value="all">Tất cả hóa đơn</option> <option value="not-paid">Hóa đơn chưa thanh toán</option> <option value="paid">Hóa đơn đã thanh toán</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Từ tháng</label> <input class="form-control monthpicker" type="text" name="start_time" value="<?php echo e(\Carbon\Carbon::now()->subMonth(3)->format('m/Y')); ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Đến tháng</label> <input class="form-control monthpicker" type="text" name="end_time" value="<?php echo e(\Carbon\Carbon::now()->addMonth(3)->format('m/Y')); ?>"> </div> </div> </div> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Số hóa đơn</label> <input class="form-control" type="text" name="code"> </div> </div> <?php $contracts = \App\Models\Contract::where('room_id', $roomId)->get(); ?> <div class="col-md-4"> <div class="form-group"> <label>Hợp đồng</label> <select class="form-control" name="contract_id" id="payment_contract"> <option value="">Tất cả hợp đồng</option> <?php $__currentLoopData = $contracts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contract): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php if($contractId == $contract->id): ?> <option value="<?php echo e($contract->id); ?>" selected><?php echo e($contract->name); ?></option> <?php else: ?> <option value="<?php echo e($contract->id); ?>"><?php echo e($contract->name); ?></option> <?php endif; ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> </select> </div> </div> </div> </form> <div class="row"> <div class="form-actions"> <div class="row"> <div class="col-md-offset-4 col-md-8"> <button type="button" class="btn blue" id="btn-filter-payment">Tìm kiếm</button> </div> </div> </div> </div> </div> <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 class="col-md-12" id="payment-items"> <?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($contractId)){
                $moneyInfoItems = \App\Models\MoneyInfo::where('room_id', $roomId)->where('contract_id', $contractId)
                ->whereBetween('date_action', [$startTime, $endTime])->orderBy('date_action', 'desc')->get();
                }else{
                $moneyInfoItems = \App\Models\MoneyInfo::where('room_id', $roomId)
                ->whereBetween('date_action', [$startTime, $endTime])->orderBy('date_action', '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"> <?php $__currentLoopData = $moneyInfoItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $moneyInfoItem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> <?php
                                $details = \App\Models\MoneyDetail::query()->where('money_info_id', $moneyInfoItem->id)->orderBy('id', 'desc')->get();
                   $room = $moneyInfoItem->room;

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

                            $sum = $moneyInfoItem->amount;
                            ?> <div class="col-md-12" id="money-info-item-<?php echo e($moneyInfoItem->id); ?>"> <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í</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 - $discount): ?> <?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> <?php endif; ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> </div> </div>