@extends('adminlte::page')
@section('title', 'Withdraw Funds')
@section('content')
 <?php Fun::lang()?>
 <div class="main-content-wrapper">
     <div class="main-content-wrapper">
        <div class="title-add">
            <div class="page-bar"> 
                <ul class="page-breadcrumb"> 
                    <li> <a class="ng-binding" href="#"><i class="fa fa-dashboard"></i> Dashboard</a> </li>
                    <li><a href="#">Manage Agency Wallet</a></li>
                    <li><a href="#">Send Funds</a></li>
                </ul> 
            </div>
        </div>
	<div class="main-box">
	    <div class="main-content">
	        <div class="main-admin-dashboard">
	            <div class="container">
	                <div class="page-wrapper">
	                    <div class="row">
	                        <div class="col-sm-12 col-xs-12">
	                            <div class="form-wrapper">
	                                @if (count($errors) > 0)
	                                    <div class="alert-message alert-danger">
	                                    <strong>Whoops!</strong> There were some problems with your input.<br><br>
	                                    <ul>
	                                        @foreach ($errors->all() as $error)
	                                            <li>{{ $error }}</li>
	                                        @endforeach
	                                    </ul>
	                                    </div>
	                                @endif

	                                <div style="text-align:center">
	                                    <span class="step">Send Funds  <span class="fa fa-angle-right"></span></span>
	                                    <span class="step">Authorization  <span class="fa fa-angle-right"></span></span>
	                                    <span class="step">Submit Funds  <span class="fa fa-angle-right"></span></span>
	                                </div> 

	                                <div class="form-wrapper"> 
                                        <form id="regForm" class="validate" method="POST" action="{{route('admin.transaction.send_funds_store')}}" enctype="multipart/form-data">
                                            @csrf
                                            <input type="hidden" id="agency_id" name="agency_id" value="{{$agency_id}}">
                                            <div class="row">
                                                <div class="tab">
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Account Name</label>
                                                             {!! Form::text('account_name', $data[0]->account_name, array('class' => 'form-control account_name','readonly')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Account Number</label>
                                                            {!! Form::text('from_account', $data[0]->account_number, array('class' => 'form-control acc_number','readonly')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Available Amount</label>
                                                            {!! Form::text('avaible_amount', $data[0]->balance, array('class' => 'form-control avaible_amount number-only','readonly')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">To Account</label>
                                                            &nbsp<span class="message_to_account label label-danger" style="display: none;" ></span>
                                                            {!! Form::text('to_account', null, array('placeholder' => 'To Account','class' => 'form-control to_account')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Account Name</label>
                                                            {!! Form::text('to_account_name', null, array('placeholder' => 'Account Name','class' => 'form-control to_account_name','readonly')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Amount</label>
                                                              &nbsp<span class="message label label-danger" style="display: none;" ></span>
                                                            {!! Form::text('amount',null, array('Placeholder' => 'Amount','class' => 'form-control credit_amount')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-12">
                                                        <div class="col-3">
                                                            <label for="" class="">Remark</label>
                                                            <textarea name="remark" id=""  rows="3" class="form-control remarks" style="width: 100%"></textarea>
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>  
                                                </div>
                                                <div class="tab">
                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Account Number</label>
                                                            {!! Form::text('account_number', $data[0]->account_number, array('placeholder' => 'Enter funds number','class' => 'form-control','readonly')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>

                                                    <div class="form-group col-sm-6 col-xs-12">
                                                        <div class="col-3">
                                                            <label for="" class="required">Password</label>
                                                            {!! Form::password('password',array('placeholder' => 'Enter funds password','class' => 'form-control')) !!}
                                                            <span class="focus-border"></span>  
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="tab">

                                                    <div class="col-md-6 col-sm-6 col-md-offset-3">
                                                        <div class="list-chart">
                                                            <h4>Sand Funds Info</h4>
                                                            <ul class="personal-info">
                                                                <li><span class="span">Account Name :</span><span class="acc-name"></span></li>
                                                                <li><span class="span">Account Number :</span><span class="acc-number"></span></li>
                                                                <li><span class="span">Available Amount :</span><span class="avai-amount"></span> </li>
                                                                <li><span class="span">Debit Amount :</span><span class="credit-amount"></span> </li>
                                                                <li><span class="span">To Account :</span><span class="to-account"></span> </li>
                                                                <li><span class="span">Account Name :</span><span class="to-account-name"></span> </li>
                                                                <li><span class="span">Remark :</span><span class="remark"></span> </li>
                                                            </ul>
                                                       </div>
                                                    </div>
                                                </div>
                                                <div class="col-sm-12 col-xs-12 text-right  ">
                                                    <div class="form-group">
                                                        <button type="button" id="prevBtn" class="button_danger" onclick="nextPrev(-1)">
                                                            <span class="fa fa-angle-left"></span>  Previous</button>
                                                        <button type="button" id="nextBtn" class="button_warning" onclick="nextPrev(1)">Next</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
	                            </div>
	                        </div>
	                    </div>
	                </div>
	            </div>
	        </div>
	    </div>
	</div>
</div>

 
@endsection

@section('js')
<script type="text/javascript" src="{{asset('assets/controller/step-tab-sand_fund.js')}}"></script>
<script type="text/javascript">
	      
$(document).ready(function() {
	$('input[name="to_account"]').autocomplete({
		source: function(request, response) {
            var agency_id=$("#agency_id").val();
			$.ajax({
                type:'get',
				url: "{{route('admin.fund_account_name')}}",
				dataType: "json",
				data: {
					term : request.term,
                    agency_id :agency_id
				},
				success: function(data) {
					$.each(data, function (index, element) {
						$('input[name="to_account_name"]').val(element.account_name);
					});
					if(data.value == 'no-result'){
						$(".remove").remove();
					}
				}
			});
		},
		minLength: 6,
	});	
});

$(document).on('keyup','.to_account',function(){
	var to_account = $(this).val();
	var acc_number = $('.acc_number').val();
	if(to_account == acc_number){
		$('.message_to_account').html("You can't send to your own account");
		$('.message_to_account').show();
		$('.to_account').val('');
	}
});
	
</script>

@endsection