@extends('layouts.app')

@section('title')
All Pending Development Charges 
@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 Pending Development Charges</li>
      </ol>
@stop

@section('css')

@stop

@section('content')
@php
$size='';
if($projectType->id == \App\ProjectType::society){
$size=\App\ProjectType::society_size;
}
else {
    $size=\App\ProjectType::high_rise_size;  
}
@endphp

            <div class="container-fluid">

                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-info">
                            <div class="panel-heading"> Development Charges</div>
                            <div class="panel-wrapper collapse in" aria-expanded="true">
                                <div class="panel-body">
                                    <form >
                                        <div class="form-body">
                                            {{-- <div class="row">
                                                
                                                <!--/span-->
                                                <div class="col-md-3">
                                                    <div class="form-group has-success" style="margin-bottom: 15px">
                                                        <label class="control-label">By Unit No.</label>

                                                        <select id="unit" class="form-control chosen-select">
                                                            <option  value="0">None</option>
                                                            @foreach($unitNumbers as $p)
                                                                <option value="{{$p->id}}">{{$p->unit_number}}</option>
                                                            @endforeach
                                                        </select> </div>
                                                </div>
                                                <!--/span-->
                                                <!--/span-->
                                                <div class="col-md-3">
                                                    <div class="form-group has-success" style="margin-bottom: 15px">
                                                        <label class="control-label">By Customer</label>

                                                        <select id="customer" class="form-control chosen-select">
                                                            <option  value="0">None</option>
                                                            @foreach($customers as $c)
                                                                <option value="{{$c->id}}">{{$c->name}}</option>
                                                            @endforeach
                                                        </select> </div>
                                                </div>
                                                <!--/span-->

                                                <!--/span-->
                                                <div class="col-md-3">
                                                    <div class="form-group has-success" style="margin-bottom: 15px">
                                                        <label class="control-label">By Dealer</label>

                                                        <select id="dealer" class="form-control chosen-select">
                                                            <option  value="0">None</option>
                                                            @foreach($dealers as $d)
                                                                <option value="{{$d->id}}">{{$d->name}}-{{$d->code}}</option>
                                                            @endforeach
                                                        </select> </div>
                                                </div>
                                                <!--/span-->

                                                <!--/span-->
                                                <div class="col-md-3">
                                                    <div class="form-group has-success" style="margin-bottom: 15px">
                                                        <label class="control-label">By status</label>
                                                        <select id="status" class="form-control chosen-select">
                                                            <option  value="0">None</option>
                                                            <option  value="{{\App\CustomerProperty::pending}}">Pending</option><option value="{{\App\CustomerProperty::cancel}}">Cancelled</option>

                                                        </select> </div>
                                                </div>
                                                <!--/span-->
                                                <div class="col-md-3">
                                                    <div class="form-actions" style="margin-top: 26px">
                                                        <button type="button" class="btn btn-success search-customer"> <i class="fa fa-check" ></i> Search</button>

                                                    </div>
                                                </div>
                                            </div> --}}


                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /row -->
                <div class="row" id="update-table">
                    <div class="col-sm-12">
                        <div class="white-box">

                            <h3 class="box-title">Pending Development Charges ({{count($deve_charges)}})</h3>

                            <div class="table-responsive">
                                <table id="myTable" class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                           
                                            <th>Unit #</th>
                                            <th>Size</th>
                                            <th>Customer</th>
                                            <th>Requested Development Amount</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $count =1;?>
                                        @foreach($deve_charges as $statement)
                                        <tr >
                                            <td>{{$count++}}</td>
                                        
                                            <td>{{$statement->customerProperty ? $statement->customerProperty->inventory->unit_number : '' }}</td>
                                            <td>@if($statement->customerProperty->inventory)
                                              @if($statement->customerProperty->inventory->size)
                                              
                                              {{$statement->customerProperty->inventory->size->name}} {{$size}} 
                                              @endif
                                              @endif
                                          </td>
                                              <td>{{$statement->customer->name}} -- {{$statement->customer->cnic}}</td>
                                              <td>{{number_format($receivedAmt[$statement->id])}} PKR</td>
                                            <td class="text-nowrap">
                                                {{-- <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> </a> --}}

                                                <a href="{{route('development-charges.editPendingView',['id'=>$statement->id])}}" data-toggle="tooltip" data-original-title="Approve charges"> <i class="fa fa-sun-o text-inverse m-r-10"></i> </a>


                                                {{-- <a href="{{route('statement.delete',['id'=>$statement->id])}}" data-toggle="confirmation" data-placement="left" data-title="Are you sure to delete?" > <i class="fa fa-close text-danger"></i> </a> --}}
                                            </td>

                                        </tr>

                                        @endforeach

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

@stop

@section('js')
<script>
    $(function() {
        $('#myTable').DataTable();

        var table = $('#example').DataTable({
            "columnDefs": [{
                "visible": false,
                "targets": 2
            }],
            "order": [
                [2, 'asc']
            ],
            "displayLength": 25,
            "drawCallback": function(settings) {
                var api = this.api();
                var rows = api.rows({
                    page: 'current'
                }).nodes();
                var last = null;
                api.column(2, {
                    page: 'current'
                }).data().each(function(group, i) {
                    if (last !== group) {
                        $(rows).eq(i).before('<tr class="group"><td colspan="5">' + group + '</td></tr>');
                        last = group;
                    }
                });
            }
        });
        // Order by the grouping
        $('#example tbody').on('click', 'tr.group', function() {
            var currentOrder = table.order()[0];
            if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
                table.order([2, 'desc']).draw();
            } else {
                table.order([2, 'asc']).draw();
            }
        });
    });
    $('.search-customer').on('click',function(){
        $('.preloader').fadeIn();
        unit = $('#unit').val();
        customer = $('#customer').val();
        dealer = $('#dealer').val();
        status = $('#status').val();

        if(unit == 0 && customer== 0 && status == 0 && dealer == 0) {
            toastr.warning("please select any option.");
            return false;
        }

        var data = {'unit':unit,'customer':customer,'dealer':dealer,'status':status};
        $.get('/pending-statement/updateTable',data,function(data){
            document.getElementById('update-table').innerHTML = data;

            $('#myTable').DataTable({
                'pageLength':50,
                'paging':false,
                'searching':false,
                'info':true
            });
            toastr.success("Search updated.");


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



    </script>
@stop