@extends('layouts.app')

@section('title')
    Edit Nominee
@stop

@section('breadcrumb')
    <ol class="breadcrumb pull-right">
        <li><a href="{{ route('home') }}"><i class="fa fa-dashboard"></i> Home</a></li>
         
        @permission('list-customer')
        <li><a href="{{ route('nominee.all') }}">All Nominee</a></li>
    @endpermission
        <li class="active">Edit Nominee</li>
    </ol>
@stop

@section('content')

    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                @if ($errors->any())
                    <div class="white-box">
                        <h2>Errors</h2>
                        <ul>
                            {!! implode('', $errors->all('<li><span class="help-block"><strong>:message</strong></span></li>')) !!}
                        </ul>
                    </div>
                @endif

                <div class="white-box">
                    <h3 class="box-title m-b-0"><i class="icon-user fa-fw"></i> Edit Nominee</h3>
                    <p class="text-muted m-b-30 font-13" style="height: 0px;">Update Information </p>
                    <hr>
                    <form class="form-horizontal" action="{{ route('nominee.update') }}" enctype="multipart/form-data"
                        method="post">
                        {{ csrf_field() }}
                        <br>
                        <input type='hidden' name='id' value="{{$nominee->id}}"> 
                        <div class="form-group">
                            <label for="exampleInputuname" class="col-sm-2 control-label">Customer<span style="color: red">*</span></label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="ti-user"></i></div>
                                    <select class="form-control chosen-select" name="customer_id">

                                    <option>None</option>
                                    @foreach($customer as $cus)
                                    @if($cus->id == $nominee->customer->id)
                                    <option value="{{$cus->id}}" selected>{{$cus->name}} -- {{$cus->cnic}}</option>
                                    @else
                                    <option value="{{$cus->id}}">{{$cus->name}} -- {{$cus->cnic}}</option>
                                    @endif
                                    @endforeach
                                   </select>
                                    @if ($errors->has('customer_id'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('customer_id') }}</strong>
                                        </span>
                                    @endif
                                </div>
                            </div>
                           
                           
                            <div class='form-group'> 
                                <label for="exampleInputuname" class="col-sm-2 control-label">Name of Nominee<span style="color: red">*</span></label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-addon"><i class="ti-user"></i></div>
                                        <input type="text" class="form-control" name="nominee_name"
                                            value="{{$nominee->nominee_name }}" placeholder="Enter Name">
                                        @if ($errors->has('nominee_name'))
                                            <span class="help-block">
                                                <strong>{{ $errors->first('nominee_name') }}</strong>
                                            </span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>        

                        <div class="form-group">
                            <label for="cnic" class="col-sm-2 control-label"  >CNIC <span style="color: red">*</span></label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="icon-credit-card"></i></div>
                                    <input type="text" class="form-control" value="{{$nominee->nominee_cnic }}"
                                        name="nominee_cnic" id="nominee_cnic"
                                        onfocusout="return validateCnic(this)"data-inputmask="'mask': '9999999999999'"
                                        placeholder="XXXXXXXXXXXXX">
                                    @if ($nominee->nominee_cnic_flag == \App\Customer::locally)
                                        <input type="radio" checked="" name="nominee_cnic_flag" value="1">
                                        Locally
                                        <input type="radio" name="nominee_cnic_flag" value="2"> Internationally
                                    @elseif($nominee->nominee_cnic_flag  == \App\Customer::internationally)
                                        <input type="radio" name="nominee_cnic_flag" value="1"> Locally
                                        <input type="radio" checked="" name="nominee_cnic_flag" value="2">
                                        Internationally
                                    @else
                                        <input type="radio" name="nominee_cnic_flag" value="1"> Locally
                                        <input type="radio" name="nominee_cnic_flag" value="2"> Internationally
                                    @endif

                                    <div style="color: red;display: none;" id="cnic_error1">This Member cnic is found in
                                        list of DNFBP. You can't add this Nominee record. </div>

                                    @if ($errors->has('nominee_cnic'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('nominee_cnic') }}</strong>
                                        </span>
                                    @endif
                                </div>
                            </div>
                             <div class="form-group">
                                <label for="exampleInputuname" class="col-sm-2 control-label">S/O, D/O, W/O <span
                                        style="color: red">*</span></label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-addon"><i class="ti-user"></i></div>
                                        <input type="text" class="form-control" name="nominee_so_do_wo"
                                            value="{{ $nominee->nominee_so_do_wo}}" placeholder="Enter S/O - D/O - W/O ">
                                        @if ($nominee->so_do_wo_flag == 1)
                                            <input checked="" type="radio" name="nominee_father_type" value="1">S/O
                                            <input type="radio" name="nominee_father_type" value="2">D/O
                                            <input type="radio" name="nominee_father_type" value="3">W/O
                                        @elseif($nominee->so_do_wo_flag == 2)
                                            <input type="radio" name="nominee_father_type" value="1">S/O
                                            <input checked="" type="radio" name="nominee_father_type" value="2">D/O
                                            <input type="radio" name="nominee_father_type" value="3">W/O
                                        @elseif($nominee->so_do_wo_flag == 3)
                                            <input type="radio" name="nominee_father_type" value="1">S/O
                                            <input type="radio" name="nominee_father_type" value="2">D/O
                                            <input checked="" type="radio" name="nominee_father_type" value="3">W/O
                                        @else
                                            <input type="radio" name="nominee_father_type" value="1">S/O
                                            <input type="radio" name="nominee_father_type" value="2">D/O
                                            <input type="radio" name="nominee_father_type" value="3">W/O
                                        @endif
                                        @if ($errors->has('nominee_so_do_wo'))
                                            <span class="help-block">
                                                <strong>{{ $errors->first('nominee_so_do_wo') }}</strong>
                                            </span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                           
                        </div>

                        <div class="form-group">
                            <label for="cnic" class="col-sm-2 control-label">Passport No.</label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="icon-book-open"></i></div>
                                    <input type="text" class="form-control" value="{{ $nominee->nominee_passport_no}}"
                                        name="nominee_passport_no" id="nominee_passport_no" placeholder="XXXXXXXXX">

                                    @if ($errors->has('nominee_passport_no'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('nominee_passport_no') }}</strong>
                                        </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1" class="col-sm-2 control-label">Email </label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-addon"><i class="ti-email"></i></div>
                                        <input type="text" class="form-control" name="nominee_email"
                                            value="{{$nominee->nominee_email}}" placeholder="Enter Email">
                                        @if ($errors->has('nominee_email'))
                                            <span class="help-block">
                                                <strong>{{ $errors->first('nominee_email') }}</strong>
                                            </span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">Mobile Number </label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="icon-phone"></i></div>
                                    <input type="number" class="form-control" name="nominee_mobile_number"
                                        value="{{ $nominee->nominee_mobile_number }}" placeholder="Enter Mobile Number">
                                    @if ($errors->has('nominee_mobile_number'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('nominee_mobile_number') }}</strong>
                                        </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1" class="col-sm-2 control-label">Residence Number
                                </label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-addon"><i class="icon-phone"></i></div>
                                        <input class="form-control" type='number' name="nominee_res_number"
                                            value="{{ $nominee->nominee_res_number }}" placeholder="Enter Residence Number">
                                        @if($errors->has('nominee_res_number'))
                                            <span class="help-block">
                                                <strong>{{ $errors->first('nominee_res_number') }}</strong>
                                            </span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="exampleInputEmail1" class="col-sm-2 control-label">Relation with Applicant
                                <span style="color: red">*</span></label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="icon-link"></i></div>
                                    <select class="form-control chosen-select" name="nominee_relation">
                                        <option selected>{{$nominee->nominee_relation}}</option>
                                        <option >Brother</option>
                                        <option >Father</option>
                                        <option >Sister</option>
                                        <option >Mother</option>
                                        <option >Friend</option>
                                        <option >Wife</option>
                                        <option >Husband</option>
                                        <option >Son</option>
                                        <option >Daughter</option>
                                        <option >Cousin</option>
                                    </select>
                                    @if ($errors->has('nominee_relation'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('nominee_relation') }}</strong>
                                        </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group" id="nominee_address">
                                <label for="address" class="col-sm-2 control-label" id="nominee_address">Nominee Address
                                    <span style="color: red">*</span></label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-addon"><i class="icon-location-pin"></i></div>
                                        <textarea class="form-control" id="nominee_address"
                                            name="nominee_address">{{ $nominee->nominee_address }}</textarea>
                                        @if($errors->has('nominee_address'))
                                            <span class="help-block">
                                                <strong>{{ $errors->first('nominee_address') }}</strong>
                                            </span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>                           

                        <div class="form-group m-b-0">
                            <div class="col-sm-offset-4 col-sm-4" style="margin-bottom: 25px;">
                                <button type="submit" class="btn btn-info waves-effect waves-light m-t-10"
                                    style="width: 100%; margin-left: 110px;">Save</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!--./row-->

    </div>

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

@stop

@section('js')

    <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>








    <script>
        function hideFields(self) {

            if (self === 'company') {
                $('#father_name').val('null');
                $('#father_name_parent').hide();
                $('#passport_no').hide()
                $('#date_of_birth').html('Date of Incorporation ')
                $('#cnic_no').html('Incorporation no <span style="color: red">*</span>')
                $('#mobile_number').html('Phone Number <span style="color: red">*</span>')
                $('#res_number').hide()
                $('#phone_number').hide()
                $('#photo_s').hide()
                $('#mailing_label').html('Company Registered Address <span style="color: red">*</span>')
                $('#permanent_address').val($('#mailing_address').val())
                $('#permanent_add').hide()
                $('#occupations').html('Type Of Company <span style="color: red">*</span>')
                $('#imgs_label').html('Certificate  ')
            }

            if (self === 'individual') {
                $('#father_name').val('');
                $('#father_name_parent').show();
                $('#passport_no').show()
                $('#date_of_birth').html('Date of Birth <span style="color: red">*</span>')
                $('#cnic_no').html('Cnic <span style="color: red">*</span>')
                $('#mobile_number').html('Mobile Number <span style="color: red">*</span>')
                $('#res_number').show()
                $('#photo_s').show()
                $('#phone_number').show()
                $('#mailing_label').html('Mailing Address <span style="color: red">*</span>')
                $('#permanent_add').show()
                $('#occupations').html('Occupation <span style="color: red">*</span>')
                $('#imgs_label').html('Passport size photo  <span style="color: red">*</span>')
            }


            return false;
        }

        function validateCnic(self) {
            var cnic = $(self).val();

            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            $.ajax({
                url: "{{ route('validate.dnfbp.cnic') }}",
                method: 'POST',
                dataType: 'json',
                data: {
                    cnic: cnic
                },
                success: function(data) {
                    if (data.response == 'invalid') {
                        $(self).closest('.input-group').find('#cnic_error1').show();
                    }

                }
            })



            return false;
        }


        $(":input").inputmask();



        // Function for copying mailing address to permanent address
        $('input#copy_to_permanent_address').click(function() {
            if ($(this).prop("checked") == true) {
                $('textarea#permanent_address').val($('textarea#mailing_address').val());
            } else if ($(this).prop("checked") == false) {
                $('textarea#permanent_address').val('');
            }
        });

        // Function for copying mailing address to nominee address
        $('input#copy_to_nominee_address').click(function() {
            if ($(this).prop("checked") == true) {
                $('textarea#nominee_address').val($('textarea#mailing_address').val());
            } else if ($(this).prop("checked") == false) {
                $('textarea#nominee_address').val('');
            }
        });
    </script>



@stop
