@extends('admin.layouts.master')

@section('title')
    Cash Advance Payments
@stop

@section('style')

@stop

@section('content')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-trello"></span> Cash Advance Payments
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-users"></i> Admin Panel</a></li>
                <li class="active">Cash Advance Payments</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 100%;">
            <div class="page-header">
                <a href="{{route('advances.payment.new')}}" class="btn btn-primary"><i class="fa fa-plus-circle"></i> New C/A Payment</a>
                <div class="btn-group dropdown">
                    <button type="button" class="btn btn-info">C/A Balance</button>
                    <button type="button" class="btn btn-info dropdown-toggle" id="mydp" data-toggle="dropdown" aria-haspopup="true" >
                        <span class="caret"></span>
                        <span class="sr-only">Action option</span>
                    </button>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="mydp">
                        <li><a href="{{route('reports.agents.ca-balances')}}" target="_blank">Agents Balance</a></li>
                        <li><a href="{{route('reports.managers.ca-balances')}}" target="_blank">Managers Balance</a></li>
                    </ul>
                </div>
            </div>

            <table class="table table-hover" id="user_table" width="100%">
                <thead>
                <tr style="background: grey ;color:#fff; font-weight: bold">
                    <td>ID</td>
                    <td>Date</td>
                    <td>Agent/Manager Name</td>
                    <td>Amount</td>
                    <td>Remarks</td>
                    <td>Created By</td>                    
                    <td>Actions</td>
                </tr>
                </thead>
                @foreach($cas as $ca)
                    <tr >
                        <td>{{$ca->id}}</td>
                        <td width="12%">{{date("d-M-Y", strtotime($ca->payment_date))}}</td>
                        <td width="22%"><a href="{{ route('advances.payment.edit',[$ca->id]) }}">{{$ca->fullname}}</a></td>
                        <td style="text-align: right">{{number_format($ca->amount,2)}}</td>
                        <td width="25%">{{$ca->remarks}}</td>
                        <td style="text-align: center">{{$ca->user_name}}</td>
                        <td class="btn btn-default ">
                            <a href="{{ route('advances.payment.edit',[$ca->id]) }}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a>
                            <a href="#" data-toggle="modal" data-target="#d{{$ca->id}}" class="text-danger btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                            <!-- Delete Modal -->
                            <div class="modal fade" id="d{{$ca->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <form method="post" action="{{route('advances.payment.delete')}}">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title" id="myModalLabel"><i class="fa fa-warning"></i> confirm deletion</h4>
                                        </div>
                                        <div class="modal-body text-danger">
                                            <input type="hidden" name="id" value="{{$ca->id}}">
                                            Are you sure want to delete record {{$ca->id}}?
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                            <button type="submit" class="btn btn-primary">Confirm</button>
                                        </div>
                                    </div>
                                        {{csrf_field()}}
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                    @endforeach
            </table>
            @if(Session('info'))
                <div class="row">
                    <div class="col-md-6 col-md-offset-3 text-center">
                        <div class="tem alert alert-success navbar-fixed-bottom"><span class="glyphicon glyphicon-ok-circle"></span> {{Session('info')}}</div>
                    </div>
                </div>
            @endif
        </section>

    </div>
@stop

@section('script')
<script>
        $(document).ready(function() {
            $('#user_table').DataTable( {
                "bDestroy": true,
                /*searching: true,
                paging: true,
                lengthChange: true,
                pageLength: 10,
                info: true,
                orderable: true,*/
                "order": [[ 0, "desc" ]]
            } );
        } );

        /*$("#btnAdd").on("click", function(){
            $('#addModal').modal('toggle');
        });*/
    </script>
@stop