@extends('layouts.app')

@section('title')
    All Refund Units
@stop

@section('breadcrumb')
    <ol class="breadcrumb pull-right">
        <li><a href="{{ route('home') }}"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">All Refund Units</li>
    </ol>
@stop
@section('css')

    <link href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css" rel="stylesheet">
    <link href="https://cdn.datatables.net/buttons/1.7.0/css/buttons.dataTables.min.css" rel="stylesheet">

    <style>
        table.dataTable thead .sorting_asc {
            background-image: none !important;
        }

        .table.dataTable,
        table.dataTable {
            width: 99.8% !important;
        }
    </style>

@stop

@section('content')


@can('isSuperAdmin')
@php
$society = false;
$high_rise = false;
 if(isset($ids[0])){
    if($ids[0] != 'all'){
        $result=   \App\MultiProject::whereIn('id',$ids)->where('project_type_id',\App\ProjectType::society)->first();
   
        if(!empty( $result))
        {
            $society = true;
           $high_rise = true; 
        }
        else {
            $society = false;
           $high_rise = true; 
        }
    }
    else {
      $r=  \App\MultiProject::where('project_type_id',\App\ProjectType::society)->first();
      if(!empty( $r))
        {
            $society = true;
           $high_rise = true; 
        }
        else {
            $society = false;
           $high_rise = true; 
        }
    }
 }

   
  
@endphp
@elsecannot('isSuperAdmin')
@php
if($cookie_project_type == \App\ProjectType::society)
    {
        $society=true;
        $high_rise = false;
    }
    if($cookie_project_type == \App\ProjectType::high_rise ){
        $high_rise = true;
        $society=false;
    }
   
@endphp 
@endcan





    <div class="container-fluid">
        <!-- /row -->

        @can('isSuperAdmin')
            @include('partial.multiproject_select')
        @endcan
        <div id='updatecontent'>
            <div class="row" id="update-table" style="margin-top: 25px;">
                <div class="col-sm-12">
                    <div class="white-box">
                        <div class="pull-right">

                        </div>

                        <h3 class="box-title">Refund Units </h3>

                        <!-- Nav tabs -->
                        <div class="container">

                            <ul class="nav customtab nav-tabs" role="tablist">

                                <li role="presentation" class="active"><a href="#close_file" aria-controls="home"
                                        role="tab" data-toggle="tab" aria-expanded="true"><span class="visible-xs"><i
                                                class="ti-home"></i></span><span class="hidden-xs">Close Unit</span></a>
                                </li>
                                @if ($society)
                                <li role="presentation" class=""><a href="#open_file" aria-controls="profile"
                                        role="tab" data-toggle="tab" aria-expanded="false"><span class="visible-xs"><i
                                                class="ti-user"></i></span> <span class="hidden-xs">Open File </span></a>
                                </li>
                                @endif

                            </ul>

                            <div class="tab-content">
                                <div id="close_file" class="tab-pane fade in active">

                                    <ul class="nav nav-tabs">
                                        <li class="active"><a data-toggle="tab" href="#home">Refunded
                                                ({{ number_format($statement_count_refunded) }})</a></li>
                                        <li><a data-toggle="tab" href="#menu1">Pending Refunds
                                                ({{ number_format($statementCount) }}) </a></li>
                                        <li><a data-toggle="tab" href="#menu2">Decline ({{ $statement_count_decline }})</a>
                                        </li>

                                    </ul>

                                    <div class="tab-content">
                                        <div id="home" class="tab-pane fade in active">
                                            <h3>Refunded Units </h3>
                                            <div class="table-responsive">
                                                <table id="myTable" class="table table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Project</th>
                                                            <th style="width: 66px;">Unit #</th>
                                                            <th>Member Name</th>
                                                            <th>Received Amount</th>
                                                            <th>Total Refund</th>
                                                            <th>Total Deduction</th>
                                                            <th>Total Deduction Percentage</th>
                                                            <th>Status</th>
                                                            <th>
                                                                Action
                                                            </th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $count = 1; ?>



                                                        @permission('view-cancellation')
                                                            <?php $view_membership = true; ?>
                                                        @else
                                                            <?php $view_membership = false; ?>
                                                        @endpermission

                                                        @permission('edit-refund')
                                                            <?php $edit_refund = true; ?>
                                                        @else
                                                            <?php $edit_refund = false; ?>
                                                        @endpermission



                                                        @foreach ($allStatementsRefunded as $statementrefunded)
                                                            <tr>
                                                                <td>{{ $count++ }}</td>
                                                                <td>{{ $statementrefunded->multiProject ? $statementrefunded->multiProject->name : ' ' }}</td>

                                                                <td>{{ $statementrefunded->inventory->unit_number }}</td>

                                                                <td>{{ $statementrefunded->customer ? $statementrefunded->customer->name : '' }}<br><b>Dealer:
                                                                    </b>{{ $statementrefunded->dealer ? $statementrefunded->dealer->name : '' }}
                                                                </td>


                                                                <td><b>{{ number_format($statementrefunded->unitRefundHistory->total_amount) }}</b>
                                                                </td>

                                                                <td><b>{{ number_format($statementrefunded->unitRefundHistory->total_refund) }}</b>
                                                                </td>

                                                                <td><b>{{ number_format($statementrefunded->unitRefundHistory->total_deduct) }}</b>
                                                                </td>


                                                                <td><b>{{ round($statementrefunded->unitRefundHistory->total_deduct_percentage, 3) }}
                                                                        %</b></td>

                                                                @if ($statementrefunded->cancelProperty->after_cancellation_status == 'pending')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statementrefunded->cancelProperty->after_cancellation_status == 'adjust-pending')
                                                                    <td><span
                                                                            class="label label-success">Adjust/Pending</span>
                                                                    </td>
                                                                @elseif($statementrefunded->cancelProperty->after_cancellation_status == 'refund-pending')
                                                                    <td><span
                                                                            class="label label-success">Refund/Pending</span>
                                                                    </td>
                                                                @elseif($statementrefunded->cancelProperty->after_cancellation_status == 'adjusted')
                                                                    <td><span class="label label-success">Adjusted</span>
                                                                    </td>
                                                                @elseif($statementrefunded->cancelProperty->after_cancellation_status == 'refunded')
                                                                    <td><span class="label label-success">Refunded</span>
                                                                    </td>
                                                                @endif




                                                                <td class="text-nowrap">
                                                                    <center>

                                                                        @if ($view_membership)
                                                                            <a href="{{ route('property.refund.history', ['id' => $statementrefunded->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="View"> <i
                                                                                    class="fa fa-eye text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif


                                                                        @if ($edit_refund && $statementrefunded->cancelProperty->after_cancellation_status == 'pending')
                                                                            <a href="{{ route('property.refund.edit', ['id' => $statementrefunded->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="Edit"> <i
                                                                                    class="fa fa-pencil text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif
                                                                       




                                                                    </center>
                                                                </td>

                                                            </tr>
                                                        @endforeach




                                                    </tbody>
                                                </table>
                                                <div style="float: right;">{{ $allStatementsRefunded->links() }} </div>
                                            </div>
                                        </div>
                                        <div id="menu1" class="tab-pane fade">
                                            <h3>Pending Refunds Units</h3>
                                            <div class="table-responsive">
                                                <table id="myTable" class="table table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Project</th>

                                                            <th style="width: 58px;">Unit #</th>
                                                            {{-- <th>Size</th> --}}
                                                            <th>Member Name</th>
                                                            <th>Net Amount</th>

                                                            <th>Received Amount</th>

                                                            {{-- <th>Booking Date</th> --}}
                                                            <th>Cancel Date</th>
                                                            <th>Cancel Fee(pkr)</th>
                                                            <th>Request Status</th>
                                                            <th>Unit Status</th>
                                                            <th>After Cancellation Decision Request</th>
                                                            <th>
                                                                Action
                                                            </th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $count = 1; ?>



                                                        @permission('view-cancellation')
                                                            <?php $view_membership = true; ?>
                                                        @else
                                                            <?php $view_membership = false; ?>
                                                        @endpermission

                                                        @permission('edit-refund')
                                                            <?php $edit_refund = true; ?>
                                                        @else
                                                            <?php $edit_refund = false; ?>
                                                        @endpermission





                                                        @foreach ($allStatements as $statement)
                                                            <tr>
                                                                <td>{{ $count++ }}</td>
                                                                <td>{{ $statement->multiProject ? $statement->multiProject->name : '' }}</td>


                                                                <td>{{ $statement->inventory->unit_number }}</td>
                                                                {{-- <td>
                                                    @if ($statement->inventory)
                                                        @if ($statement->inventory->size)
                                                            {{ $statement->inventory->size->name }} {{ env('SIZE') }}
                                                        @endif
                                                    @endif
                                                </td> --}}
                                                                <td>{{ $statement->customer ? $statement->customer->name : '' }}<br><b>Dealer:
                                                                    </b>{{ $statement->dealer ? $statement->dealer->name : '' }}
                                                                </td>

                                                                <td><b>{{ number_format($statement->net_pay) }}</b></td>


                                                                <td><b>{{ number_format($receivedAmt[$statement->id]) }}</b>
                                                                </td>



                                                                {{-- <td>{{ date('d-m-Y', strtotime($statement->booking_date)) }}</td> --}}

                                                                <td>{{ date('d-m-Y', strtotime($statement->cancel_date)) }}
                                                                </td>
                                                                <td>{{ $statement->cancelProperty->fee }} </td>

                                                                @if ($statement->cancelProperty->status == 0)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statement->cancelProperty->status == 1)
                                                                    <td><span class="label label-success">Approved</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif


                                                                @if ($statement->status == \App\CustomerProperty::pending)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#cd703d;">Pending</span>
                                                                    </td>
                                                                @elseif($statement->status == \App\CustomerProperty::approved)
                                                                    <td><span class="label label-success">Approved</span>
                                                                    </td>
                                                                @elseif($statement->status == \App\CustomerProperty::cancel)
                                                                    <td><span class="label label-danger">Canceled</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif

                                                                @if ($statement->cancelProperty->after_cancellation_status == 'pending')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statement->cancelProperty->after_cancellation_status == 'adjust-pending')
                                                                    <td><span
                                                                            class="label label-success">Adjust/Pending</span>
                                                                    </td>
                                                                @elseif($statement->cancelProperty->after_cancellation_status == 'refund-pending')
                                                                    <td><span
                                                                            class="label label-success">Refund/Pending</span>
                                                                    </td>
                                                                @elseif($statement->cancelProperty->after_cancellation_status == 'adjusted')
                                                                    <td><span class="label label-success">Adjusted</span>
                                                                    </td>
                                                                @elseif($statement->cancelProperty->after_cancellation_status == 'refunded')
                                                                    <td><span class="label label-success">Refunded</span>
                                                                    </td>
                                                                @endif




                                                                <td class="text-nowrap">
                                                                    <center>

                                                                        @if ($view_membership)
                                                                            <a href="{{ route('statement.detail', ['id' => $statement->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="View"> <i
                                                                                    class="fa fa-eye text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif


                                                                        @if ($edit_refund)
                                                                            <a href="{{ route('property.refund.edit', ['id' => $statement->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="Edit"> <i
                                                                                    class="fa fa-pencil text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif





                                                                    </center>
                                                                </td>

                                                            </tr>
                                                        @endforeach

                                                    </tbody>
                                                </table>
                                                <div style="float: right;">{{ $allStatements->links() }}</div>
                                            </div>
                                        </div>

                                        <div id="menu2" class="tab-pane fade">
                                            <h3>Decline Refunds Units</h3>
                                            <div class="table-responsive">
                                                <table id="myTable" class="table table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>

                                                            <th>Project</th>
                                                            <th>Unit #</th>
                                                            {{-- <th>Size</th> --}}
                                                            <th>Member Name</th>
                                                            <th>Net Amount</th>


                                                            {{-- <th>Booking Date</th> --}}
                                                            <th>Cancel Date</th>
                                                            <th>Cancel Fee(pkr)</th>
                                                            <th>Request Status</th>
                                                            <th>Unit Status</th>
                                                            <th>After Cancellation Decision Request</th>
                                                            <th>
                                                                Action
                                                            </th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $count = 1; ?>



                                                        @permission('view-cancellation')
                                                            <?php $view_membership = true; ?>
                                                        @else
                                                            <?php $view_membership = false; ?>
                                                        @endpermission

                                                        @permission('edit-refund')
                                                            <?php $edit_refund = true; ?>
                                                        @else
                                                            <?php $edit_refund = false; ?>
                                                        @endpermission


                                                        @foreach ($allStatementsdecline as $statementdecline)
                                                            <tr>
                                                                <td>{{ $count++ }}</td>

                                                                <td>{{ $statementdecline->multiProject->name }}</td>
                                                                <td>{{ $statementdecline->inventory->unit_number }}</td>
                                                                {{-- <td>
                                               @if ($statement->inventory)
                                                   @if ($statement->inventory->size)
                                                       {{ $statement->inventory->size->name }} {{ env('SIZE') }}
                                                   @endif
                                               @endif
                                           </td> --}}
                                                                <td>{{ $statementdecline->customer ? $statementdecline->customer->name : '' }}<br><b>Dealer:
                                                                    </b>{{ $statementdecline->dealer ? $statementdecline->dealer->name : '' }}
                                                                </td>

                                                                <td><b>{{ number_format($statementdecline->net_pay) }}</b>
                                                                </td>





                                                                {{-- <td>{{ date('d-m-Y', strtotime($statement->booking_date)) }}</td> --}}

                                                                <td>{{ date('d-m-Y', strtotime($statementdecline->cancel_date)) }}
                                                                </td>
                                                                <td>{{ $statementdecline->cancelProperty->fee }} </td>

                                                                @if ($statementdecline->cancelProperty->status == 0)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->status == 1)
                                                                    <td><span class="label label-success">Approved</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif


                                                                @if ($statementdecline->status == \App\CustomerProperty::pending)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#cd703d;">Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->status == \App\CustomerProperty::approved)
                                                                    <td><span class="label label-success">Approved</span>
                                                                    </td>
                                                                @elseif($statementdecline->status == \App\CustomerProperty::cancel)
                                                                    <td><span class="label label-danger">Canceled</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif

                                                                @if ($statementdecline->cancelProperty->after_cancellation_status == 'pending')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'adjust-pending')
                                                                    <td><span
                                                                            class="label label-success">Adjust/Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'refund-pending')
                                                                    <td><span
                                                                            class="label label-success">Refund/Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'adjusted')
                                                                    <td><span class="label label-success">Adjusted</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'refunded')
                                                                    <td><span class="label label-success">Refunded</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'decline')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#f80808;;">Decline</span>
                                                                    </td>
                                                                @endif




                                                                <td class="text-nowrap">
                                                                    <center>

                                                                        @if ($view_membership)
                                                                            <a href="{{ route('statement.detail', ['id' => $statementdecline->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="View"> <i
                                                                                    class="fa fa-eye text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif


                                                                        @if ($edit_refund)
                                                                            <a href="{{ route('property.refund.edit', ['id' => $statementdecline->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="Edit"> <i
                                                                                    class="fa fa-pencil text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif





                                                                    </center>
                                                                </td>

                                                            </tr>
                                                        @endforeach




                                                    </tbody>
                                                </table>
                                                <div style="float: right;">{{ $allStatementsdecline->links() }}</div>
                                            </div>
                                        </div>

                                    </div>
                                </div>

                                @if ($society)
                                <div id="open_file" class="tab-pane fade  ">

                                    <ul class="nav nav-tabs">
                                        <li class="active"><a data-toggle="tab" href="#openfilehome">Refunded
                                                ({{ number_format($refundedapprovedcount) }})</a></li>
                                        <li><a data-toggle="tab" href="#openfilemenu1">Pending Refunds
                                                ({{ number_format($OpenFileDealerInfocount) }}) </a></li>
                                        {{-- <li><a data-toggle="tab" href="#openfilemenu2">Decline ({{$statement_count_decline}})</a></li> --}}

                                    </ul>

                                    <div class="tab-content">
                                        <div id="openfilehome" class="tab-pane fade in active">
                                            <h3>Refunded Units </h3>
                                            <div class="table-responsive">
                                                <table id="myTable" class="table table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Project</th>
                                                            <th>Unit #</th>
                                                            <th>Dealer Name</th>
                                                            <th>Received Amount</th>
                                                            <th>Total Refund</th>
                                                            <th>Total Deduction</th>
                                                            <th>Total Deduction Percentage</th>
                                                            <th>Status</th>

                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $count = 1; ?>



                                                        @permission('view-cancellation')
                                                            <?php $view_membership = true; ?>
                                                        @else
                                                            <?php $view_membership = false; ?>
                                                        @endpermission

                                                        @permission('edit-refund')
                                                            <?php $edit_refund = true; ?>
                                                        @else
                                                            <?php $edit_refund = false; ?>
                                                        @endpermission



                                                        @foreach ($OpenFileDealerInfo_approved_refund as $openrefunded)
                                                            <tr>
                                                                <td>{{ $count++ }}</td>
                                                                <td>{{ $openrefunded->inventory->multiProject ? $openrefunded->inventory->multiProject->name : ''}}</td>


                                                                <td>{{ $openrefunded->inventory->unit_number }}</td>

                                                                <td>{{ $openrefunded->dealer->code }}
                                                                    {{ $openrefunded->dealer->name }}
                                                                </td>


                                                                <td><b>{{ number_format($openrefunded->cancelOpenFile->openFileRefunded->total_amount) }}</b>
                                                                </td>

                                                                <td><b>{{ number_format($openrefunded->cancelOpenFile->openFileRefunded->total_refund) }}</b>
                                                                </td>

                                                                <td><b>{{ number_format($openrefunded->cancelOpenFile->openFileRefunded->total_deduct) }}</b>
                                                                </td>


                                                                <td><b>{{ round($openrefunded->cancelOpenFile->openFileRefunded->total_deduct_percentage, 3) }}
                                                                        %</b></td>

                                                                @if ($openrefunded->cancelOpenFile->after_cancellation_status == 'pending')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($openrefunded->cancelOpenFile->after_cancellation_status == 'adjust-pending')
                                                                    <td><span
                                                                            class="label label-success">Adjust/Pending</span>
                                                                    </td>
                                                                @elseif($openrefunded->cancelOpenFile->after_cancellation_status == 'refund-pending')
                                                                    <td><span
                                                                            class="label label-success">Refund/Pending</span>
                                                                    </td>
                                                                @elseif($openrefunded->cancelOpenFile->after_cancellation_status == 'adjusted')
                                                                    <td><span class="label label-success">Adjusted</span>
                                                                    </td>
                                                                @elseif($openrefunded->cancelOpenFile->after_cancellation_status == 'refunded')
                                                                    <td><span class="label label-success">Refunded</span>
                                                                    </td>
                                                                @endif
                                                            </tr>
                                                        @endforeach




                                                    </tbody>
                                                </table>
                                                <div style="float: right;">
                                                    {{ $OpenFileDealerInfo_approved_refund->links() }} </div>
                                            </div>
                                        </div>
                                        <div id="openfilemenu1" class="tab-pane fade">
                                            <h3>Pending Refunds Units</h3>
                                            <table id="myTable2" class="table table-striped">
                                                <thead>
                                                    <tr>
                                                        <th>#</th>
                                                        <th>Project</th>
                                                        <th>Package Name</th>
                                                        <th>Unit #</th>

                                                        <th>Dealer Name</th>
                                                        <th>Dealer Code</th>


                                                        <th>Cancel Date</th>
                                                        <th>Cancel Fee(pkr)</th>
                                                        <th>Request Status</th>
                                                        <th>Open File<br/>Status</th>
                                                        <th>After Cancellation Decision Request</th>
                                                        <th>
                                                        <!-- style="width: 185px!important;" -->
                                                            <center>Action</center>
                                                        </th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php $count = 1; ?>


                                                    @permission('approve-cancellation')
                                                        <?php $reopen_membership = true; ?>
                                                    @else
                                                        <?php $reopen_membership = false; ?>
                                                    @endpermission

                                                    @permission('view-cancellation')
                                                        <?php $view_membership = true; ?>
                                                    @else
                                                        <?php $view_membership = false; ?>
                                                    @endpermission

                                                    @permission('edit-cancellation')
                                                        <?php $edit_membership = true; ?>
                                                    @else
                                                        <?php $edit_membership = false; ?>
                                                    @endpermission

                                                    @permission('delete-cancellation')
                                                        <?php $delete_membership = true; ?>
                                                    @else
                                                        <?php $delete_membership = false; ?>
                                                    @endpermission
                                                                    


                                                    @foreach ($OpenFileDealerInfo_pending_refund as $openfile)
                                                        <tr>
                                                            <td>{{ $count++ }}</td>
                                                            <td>{{ $openfile->inventory->multiProject ? $openfile->inventory->multiProject->name : ''}}</td>

                                                            <td>
                                                                @if ($openfile->dealerPackage)
                                                                    <a
                                                                        href='{{ route('openfile.detail', $openfile->dealerPackage->id) }}'>
                                                                        {{ $openfile->dealerPackage->package->name }}
                                                                    </a>
                                                                @endif

                                                            </td>
                                                            <td>{{ $openfile->inventory->unit_number }}</td>
                                                            <td>{{ $openfile->dealer->name }}</td>
                                                            <td>{{ $openfile->dealer->code }}</td>





                                                            <td>{{ date('d-m-Y', strtotime($openfile->cancelOpenFile->created_at)) }}
                                                            </td>
                                                            <td>{{ $openfile->cancelOpenFile->fee }} </td>

                                                            @if ($openfile->cancelOpenFile->status == 0)
                                                                <td><span class="label label-primary"
                                                                        style="background-color:#4871c6;;">Pending</span>
                                                                </td>
                                                            @elseif($openfile->cancelOpenFile->status == 1)
                                                                <td><span class="label label-success">Approved</span></td>
                                                            @else
                                                                <td></td>
                                                            @endif



                                                            @role('admin')
                                                                <?php $admin = true; ?>
                                                            @else
                                                                <?php $admin = false; ?>
                                                            @endrole
                                                            @if ($admin)
                                                                @if ($openfile->inventory->status == \App\Inventory::open)
                                                                    <td><span class="label label-success">Open</span></td>
                                                                @elseif($openfile->inventory->status == \App\Inventory::package_open_file)
                                                                    <td><span class="label label-success">Open/Dealer
                                                                            Package File</span></td>
                                                                @elseif($openfile->inventory->status == \App\Inventory::sold)
                                                                    <td><span class="label label-danger">Sold</span></td>
                                                                @elseif($openfile->inventory->status == \App\Inventory::hold_client)
                                                                    <td><span class="label label-primary">Client
                                                                            Hold</span></td>
                                                                @elseif($openfile->inventory->status == \App\Inventory::hold_company)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#cd703d;">Company
                                                                            Hold</span></td>
                                                                @elseif($openfile->inventory->status == \App\Inventory::token_hold)
                                                                    <td><span class="label label-primary">Token Hold</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif
                                                            @else
                                                                @if ($openfile->inventory->status == \App\Inventory::open)
                                                                    <td><span class="label label-success">Open</span></td>
                                                                @else
                                                                    <td><span class="label label-danger">Sold</span></td>
                                                                @endif
                                                            @endif

                                                            @if ($openfile->cancelOpenFile->after_cancellation_status == 'pending')
                                                                <td><span class="label label-primary"
                                                                        style="background-color:#4871c6;;">Pending</span>
                                                                </td>
                                                            @elseif($openfile->cancelOpenFile->after_cancellation_status == 'adjust-pending')
                                                                <td><span class="label label-success">Adjust/Pending</span>
                                                                </td>
                                                            @elseif($openfile->cancelOpenFile->after_cancellation_status == 'refund-pending')
                                                                <td><span class="label label-success">Refund/Pending</span>
                                                                </td>
                                                            @elseif($openfile->cancelOpenFile->after_cancellation_status == 'adjusted')
                                                                <td><span class="label label-success">Adjusted</span></td>
                                                            @elseif($openfile->cancelOpenFile->after_cancellation_status == 'refunded')
                                                                <td><span class="label label-success">Refunded</span></td>
                                                            @elseif($openfile->cancelOpenFile->after_cancellation_status == 'decline')
                                                                <td><span class="label label-primary"
                                                                        style="background-color:#f80808;;">Decline</span>
                                                                </td>
                                                            @elseif($openfile->cancelOpenFile->after_cancellation_status == 'swap-pending')
                                                                <td><span class="label label-success">Swap/Pending</span>
                                                                </td>
                                                            @endif




                                                            <td>

                                                                @if ($edit_refund)
                                                                    <a href="{{ route('openfile.refund.edit', ['id' => $openfile->id]) }}"
                                                                        data-toggle="tooltip" data-original-title="Edit">
                                                                        <i
                                                                            class="fa fa-pencil text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                @endif

                                                            </td>

                                                        </tr>
                                                    @endforeach

                                                </tbody>
                                            </table>
                                        </div>

                                        <div id="openfilemenu2" class="tab-pane fade">
                                            <h3>Decline Refunds Units</h3>
                                            <div class="table-responsive">
                                                <table id="myTable" class="table table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Project</th>

                                                            <th>Unit #</th>
                                                            {{-- <th>Size</th> --}}
                                                            <th>Member Name</th>
                                                            <th>Net Amount</th>


                                                            {{-- <th>Booking Date</th> --}}
                                                            <th>Cancel Date</th>
                                                            <th>Cancel Fee(pkr)</th>
                                                            <th>Request Status</th>
                                                            <th>Unit Status</th>
                                                            <th>After Cancellation Decision Request</th>
                                                            <th>
                                                                Action
                                                            </th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $count = 1; ?>



                                                        @permission('view-cancellation')
                                                            <?php $view_membership = true; ?>
                                                        @else
                                                            <?php $view_membership = false; ?>
                                                        @endpermission

                                                        @permission('edit-refund')
                                                            <?php $edit_refund = true; ?>
                                                        @else
                                                            <?php $edit_refund = false; ?>
                                                        @endpermission


                                                        @foreach ($allStatementsdecline as $statementdecline)
                                                            <tr>
                                                                <td>{{ $count++ }}</td>

                                                                <td>{{ $statementdecline->inventory->multiProject->name }}
                                                                </td>
                                                                <td>{{ $statementdecline->inventory->unit_number }}</td>
                                                                {{-- <td>
                                                 @if ($statement->inventory)
                                                     @if ($statement->inventory->size)
                                                         {{ $statement->inventory->size->name }} {{ env('SIZE') }}
                                                     @endif
                                                 @endif
                                             </td> --}}
                                                                <td>{{ $statementdecline->customer ? $statementdecline->customer->name : '' }}<br><b>Dealer:
                                                                    </b>{{ $statementdecline->dealer ? $statementdecline->dealer->name : '' }}
                                                                </td>

                                                                <td><b>{{ number_format($statementdecline->net_pay) }}</b>
                                                                </td>





                                                                {{-- <td>{{ date('d-m-Y', strtotime($statement->booking_date)) }}</td> --}}

                                                                <td>{{ date('d-m-Y', strtotime($statementdecline->cancel_date)) }}
                                                                </td>
                                                                <td>{{ $statementdecline->cancelProperty->fee }} </td>

                                                                @if ($statementdecline->cancelProperty->status == 0)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->status == 1)
                                                                    <td><span class="label label-success">Approved</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif


                                                                @if ($statementdecline->status == \App\CustomerProperty::pending)
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#cd703d;">Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->status == \App\CustomerProperty::approved)
                                                                    <td><span class="label label-success">Approved</span>
                                                                    </td>
                                                                @elseif($statementdecline->status == \App\CustomerProperty::cancel)
                                                                    <td><span class="label label-danger">Canceled</span>
                                                                    </td>
                                                                @else
                                                                    <td></td>
                                                                @endif

                                                                @if ($statementdecline->cancelProperty->after_cancellation_status == 'pending')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#4871c6;;">Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'adjust-pending')
                                                                    <td><span
                                                                            class="label label-success">Adjust/Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'refund-pending')
                                                                    <td><span
                                                                            class="label label-success">Refund/Pending</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'adjusted')
                                                                    <td><span class="label label-success">Adjusted</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'refunded')
                                                                    <td><span class="label label-success">Refunded</span>
                                                                    </td>
                                                                @elseif($statementdecline->cancelProperty->after_cancellation_status == 'decline')
                                                                    <td><span class="label label-primary"
                                                                            style="background-color:#f80808;;">Decline</span>
                                                                    </td>
                                                                @endif




                                                                <td class="text-nowrap">
                                                                    <center>

                                                                        @if ($view_membership)
                                                                            <a href="{{ route('statement.detail', ['id' => $statementdecline->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="View"> <i
                                                                                    class="fa fa-eye text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif


                                                                        @if ($edit_refund)
                                                                            <a href="{{ route('property.refund.edit', ['id' => $statementdecline->id]) }}"
                                                                                data-toggle="tooltip"
                                                                                data-original-title="Edit"> <i
                                                                                    class="fa fa-pencil text-inverse m-r-10"></i>&nbsp;&nbsp;</a>
                                                                        @endif





                                                                    </center>
                                                                </td>

                                                            </tr>
                                                        @endforeach




                                                    </tbody>
                                                </table>
                                                <div style="float: right;">{{ $allStatementsdecline->links() }}</div>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                                @endif
                            </div>


                        </div>
                        <!-- Tab panes -->


                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->


@stop

@section('js')

    <script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.7.0/js/buttons.print.min.js"></script>

    <script>
        function callItBack() {
            function confirmReopen(val) {

                var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');



                Swal.fire({
                        title: "Are you sure?",
                        text: "You want to reopen the Unit!",
                        icon: "warning",
                        buttons: true,
                        dangerMode: true,
                        showCancelButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Yes, Sure!'
                    })
                    .then((result) => {
                        if (result.isConfirmed) {
                            $('.preloader').fadeIn();
                            $.ajax({
                                /* the route pointing to the post function */
                                url: '{{ route('reopen.cancel') }}',
                                type: 'POST',
                                /* send the csrf-token and the input to the controller */
                                data: {
                                    _token: CSRF_TOKEN,
                                    id: val
                                },
                                dataType: 'JSON',
                                /* remind that 'data' is the response of the AjaxController */
                                success: function(data) {
                                    $('.preloader').fadeOut();
                                    Swal.fire("Poof! Unit Reopened Successfully!", {

                                        confirmButtonColor: '#3085d6',
                                        cancelButtonColor: '#d33',
                                        confirmButtonText: 'Yes, Sure!'
                                    }).then((result) => {
                                        location.reload();
                                    });
                                }
                            });
                        } else {
                            $('.preloader').fadeOut();
                            Swal.fire("OK! Action Revert");
                        }
                    });




                // return false;
                // if (confirm('Are you sure you want to reopen this property.')) 
                // {
                //    return true; 
                // }
                // else
                // {
                //     return false;
                // }
                $('.preloader').fadeOut();
            }
        }
        $(function() {
            $('#myTable').DataTable({
                'pageLength': 25,
                'paging': false,
                'searching': false,
                'info': false,
                'dom': 'Bfrtip',
                'buttons': [
                    'copy', 'csv', 'excel', 'pdf', 'print'
                ]
            });
        });

        callItBack();

        function updateStatus(value) {
            $('.preloader').fadeIn();

            if (value === 'search') {

                $('.preloader').fadeOut();
                return false;
            }
            var data = {
                'multipro_id': value,
            };
            $.get('{{ route('property.refund') }}', data, function(data) {
                $('.preloader').fadeOut();
                $('#myTable tbody').empty();

                $('.chosen-select').chosen('destroy');

                document.getElementById('updatecontent').innerHTML = data;
                $('.chosen-select').trigger('chosen:updated');
                callItBack();
                $('#myTable').DataTable({
                    'pageLength': 50,
                    'paging': false,
                    'searching': false,
                    'info': true,
                    'dom': 'Bfrtip',
                    'buttons': [
                        'copy', 'csv', 'excel', 'pdf', 'print'
                    ]
                });

                toastr.success("Search updated.");


                $('.preloader').fadeOut();
            });

        }
    </script>

@stop
