@extends('admin.layouts.master')

@section('title')
    Commission Receivables
@stop

@section('style')
    {{--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" />--}}
    <link rel="stylesheet" type="text/css" href="{{asset('/css/jsteps/normalize.css')}}">
    <link rel="stylesheet" type="text/css" href="{{asset('/css/jsteps/jquery.steps.css')}}">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/select2@4.0.12/dist/css/select2.min.css" rel="stylesheet" />

    <style>
        .select2{
                width: 100% !important;
            }
        .select2-container, .select2-dropdown, .select2-search, .select2-results {
        -webkit-transition: none !important;
        -moz-transition: none !important;
        -ms-transition: none !important;
        -o-transition: none !important;
        transition: none !important;
        }
    </style>

    <style>
        /*body{width:615px;}*/
        .tbl-qa{width: 98%;font-size:0.9em;background-color: #f5f5f5;}
        .tbl-qa th.table-header {text-align: left;padding:10px;}
        .tbl-qa .table-row td {padding:10px;background-color: #FDFDFD;}
        .ajax-action-links {color: #09F; margin: 10px 0px;cursor:pointer;}
        .ajax-action-button {border:#094 1px solid;color: #09F; margin: 10px 0px;cursor:pointer;display: inline-block;padding: 10px 20px;}
    </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-user-plus"></span> New Receivable
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-user-plus"></i> Admin Panel</a></li>
                <li class="active">New Receivable</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 10%;">
            <div class="page-header">
                <a href="{{route('commission.receivables')}}" class="btn btn-primary"><i class="fa fa-backward"></i> Back</a>
            </div>

           <form id="frmReceive" method="post" action="{{route('receivables.new')}}" role="form">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <div class="form-group">
                    <h3>Receiving Details</h3>
                    <section>

                    <div class="col-md-6">
                        <div class="form-group has-feedback @if($errors->has('developer_id')) has-error @endif">
                            <label for="developer_id" class="control-label">Developer *:</label>
                            <select name="developer_id" id="developer_id" class="form-control" >
                                <option value="">Select Developer</option>
                                @foreach($devs as $dev)
                                    <option value="{{$dev->developer->id}}">{{$dev->developer->name}}</option>
                                @endforeach
                            </select>
                            <span class="fa form-control-feedback"></span>
                            @if($errors->has('developer_id')) <span class="help-block">{{$errors->first('developer_id')}}</span> @endif
                        </div>

                        <div class="form-group has-feedback @if($errors->has('project_id')) has-error @endif">
                            <label for="project_id" class="control-label">Project</label>
                            <select name="project_id" id="project_id" class="form-control">
                                <option value="">Select Project</option>
                            </select>
                            <span class="fa form-control-feedback"></span>
                            @if($errors->has('project_id')) <span class="help-block">{{$errors->first('project_id')}}</span> @endif
                        </div>

                        <div class="form-group has-feedback @if($errors->has('client_id')) has-error @endif">
                            <label for="client_id" class="control-label">Client</label>
                            <select name="client_id" id="client_id" class="form-control">
                                <option value="">Select Client</option>
                            </select>
                            <span class="fa form-control-feedback"></span>
                            @if($errors->has('client_id')) <span class="help-block">{{$errors->first('client_id')}}</span> @endif
                        </div>

                        {{--<div class="form-group has-feedback @if($errors->has('net_selling_price')) has-error @endif">
                            <label for="net_selling_price" class="control-label">Net Selling Price:</label>
                            <input type="number" name="net_selling_price" id="net_selling_price" class="form-control" style="text-align: right" step="0.1" min="1.0">
                            <span class="glyphicon glyphicon-triangle-right form-control-feedback"></span>
                            @if($errors->has('net_selling_price')) <span class="help-block">{{$errors->first('net_selling_price')}}</span> @endif
                        </div>--}}


                    </div>

                    <div class="col-md-3">
                        <div class="form-group has-feedback @if($errors->has('blk')) has-error @endif">
                            <label for="blk" class="control-label">Block:</label>
                            <select name="blk" id="blk" class="form-control">
                                <option value="">Select Block</option>
                            </select>
                            <span class="glyphicon form-control-feedback"></span>
                           @if($errors->has('blk')) <span class="help-block">{{$errors->first('blk')}}</span> @endif
                        </div>
                    </div>

                    <div class="col-md-3">
                        <div class="form-group has-feedback @if($errors->has('lot')) has-error @endif">
                            <label for="lot" class="control-label">Lot:</label>
                            <select name="lot" id="lot" class="form-control">
                                <option value="">Select Lot</option>
                            </select>
                            <span class="glyphicon form-control-feedback"></span>
                            @if($errors->has('lot')) <span class="help-block">{{$errors->first('lot')}}</span> @endif
                        </div>
                    </div>

                    <div class="col-md-3">
                        <div class="form-group has-feedback @if($errors->has('gross_amount')) has-error @endif">
                            <label for="gross_amount" class="control-label">Gross Receive Amount:</label>
                            <input type="number" name="gross_amount" id="gross_amount" class="form-control" style="text-align: right" step="0.1" min="1.0">
                            <span class="glyphicon glyphicon-triangle-right form-control-feedback"></span>
                            @if($errors->has('gross_amount')) <span class="help-block">{{$errors->first('gross_amount')}}</span> @endif
                        </div>
                    </div>

                    <div class="col-md-3">
                        <div class="form-group has-feedback @if($errors->has('num_month')) has-error @endif">
                            <label for="num_month" class="control-label">No. of Months:</label>
                            <input type="number" name="num_month" id="num_month" class="form-control" style="text-align: right" step="1" min="1" max="24">
                            <span class="glyphicon glyphicon-triangle-right form-control-feedback"></span>
                            @if($errors->has('num_month')) <span class="help-block">{{$errors->first('num_month')}}</span> @endif
                        </div>
                    </div>

                    </section>
                    {{--<h3>Commission Info</h3>
                    <section>

                    <div class="col-md-12">
                        <table class="tbl-qa">
                          <thead>
                            <tr>
                              <th class="table-header">Title</th>
                              <th class="table-header">Description</th>
                              <th class="table-header">Actions</th>
                            </tr>
                          </thead>
                          <tbody id="table-body">
                              <tr class="table-row" id="table-row">
                                <td contenteditable="true"></td>
                                <td contenteditable="true"></td>
                                <td><a class="ajax-action-links">Delete</a></td>
                              </tr>
                          </tbody>
                        </table>
                        <div class="ajax-action-button" id="add-more" onClick="createNew();">Add More</div>
                    </div>

                    </section>
                </div>
            </form>

        </section>--}}
        @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

        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <form method="post" action=""> {{--{{route('gross.new')}}--}}
                    <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">Add New line item</h4>
                        </div>
                        <div class="modal-body text-left">
                            <input type="hidden" id="rcvd_id" name="rcvd_id" value="{{$rcvd->id}}">
                            <div class="form-group">
                                <label for="rcvddate" class="control-label">Date</label>
                                <div class="input-group date datetimepicker1">
                                    <input type="text" class="form-control" id="rcvddate" name="rcvddate"  />
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="pay_mod" class="control-label">Payment Mode</label>
                                <select name="pay_mod" id="pay_mod" class="form-control">
                                    <option value="">Select Paymode</option>
                                    @foreach($paymode as $pm)
                                        <option value="{{$pm}}" selected>{{$pm}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="rls_amt" class="control-label">Release Amount</label>
                                <input value="" type="number" name="rls_amt" id="rls_amt" class="form-control" style="text-align: right" min="1" step="0.1">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                            {{--<button type="submit" class="btn btn-primary">Save</button>--}}
                            <button type="button" id="itmSave" name="itmSave" class="btn btn-primary">Save</button>
                        </div>
                    </div>
                    {{csrf_field()}}
                </form>
            </div>
        </div>

    </div>
@stop

@section('script')

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-steps/1.1.0/jquery.steps.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.0.12/dist/js/select2.min.js"></script>

    {{--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>--}}

<script>
        var form = $("#frmReceive");
        /*form.validate({
            errorPlacement: function errorPlacement(error, element) { element.before(error); },
            rules: {
                confirm: {
                    equalTo: "#password"
                }
            }
        });*/
        form.children("div").steps({
            headerTag: "h3",
            bodyTag: "section",
            transitionEffect: "slideLeft",
            /*onStepChanging: function (event, currentIndex, newIndex)
            {
                form.validate().settings.ignore = ":disabled,:hidden";
                return form.valid();
            },*/
            /*: function (event, currentIndex)
            {
                form.validate().settings.ignore = ":disabled";
                return form.valid();
            },*/
            onFinished: function (event, currentIndex)
            {
                console.log("ready");
                $("#frmReceive").submit();
                //$("#frmSales").submit();
                 //var form = $(this);
                     //form.submit();
            }

        });
    </script>

    <script>
        $(document).ready(function() {
            $('#developer_id').select2();
            $('#project_id').select2();
            $('#client_id').select2();

            $('#addModal').modal('toggle');
            //$('#project_id option:not(:selected)').prop('disabled', true);
            /*$('#datetimepicker1').datetimepicker({
                 format: 'MM/DD/YYYY'
            });*/
        });

        $('#developer_id').on('change', function () {
            var developer_id = $(this).find('option:selected').val();
            //alert(property_id);
            //alert($option.val());
            if(developer_id==''){
                $('#project_id').val('');
                }
                else{
                    //$('#spinner').modal({backdrop: 'static', keyboard: false});
                        $.ajax({
                        url:"{{route('receivables.getRCVDDtls')}}",
                        method: 'get',
                        headers:  {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                        data:{
                          'developer_id':developer_id
                        },
                        dataType:'json',
                        success:function(data){
                            console.log(data);

                            $('#project_id').empty();
                            $('#project_id').append("<option selected disabled>Select Project</option>");
                            data.devs.forEach(function(dev){
                                $('#project_id').append('<option value="'+dev.id+'">'+dev.name+'</option>');
                            });

                            $('#client_id').empty();
                            $('#client_id').append("<option selected disabled>Select Client</option>");
                            data.sales.forEach(function(cl){
                                $('#client_id').append('<option value="'+cl.client.id+'">'+cl.client.client_name+'</option>');
                            });

                            $('#blk').empty();
                            $('#blk').append("<option selected disabled>Select Blk</option>");
                            data.sales.forEach(function(cl){
                                $('#blk').append('<option value="'+cl.blk+'">'+cl.blk+'</option>');
                            });

                            $('#lot').empty();
                            $('#lot').append("<option selected disabled>Select Lot</option>");
                            data.sales.forEach(function(cl){
                                $('#lot').append('<option value="'+cl.lot+'">'+cl.lot+'</option>');
                            });
                            //$('#spinner').modal('toggle');
                    },
                    /*error:function(e){
                      console.log(e);
                    }*/
                    error: function (jqXHR, exception) {
                        console.log(jqXHR);
                    }
                });
                } //end else
            });

        $('#gross').on('keyup', function () {
            var dInput = $('#gross').val();
            //console.log(dInput);
            //if (evt.which != 110 ){//not a fullstop
                    //var n = parseFloat($(this).val().replace(/\,/g,''),10);
                    //$(this).val(n.toLocaleString());
               // }
            /*var rl = $('#release_amount2').val();
            var dInput = $(this).val();
            console.log(dInput);
            if (dInput > rl) {
                $('#release_amount').val(rl)
            }*/
        });
    </script>

@stop