<?php
use Cake\Routing\Router;
use Cake\View\Helper\UrlHelper;
?>
<script>
   $(document).ready(function() {
       $('#productcompanyid').change(function() { 
          var selectedValue = $(this).val();      
            var targeturl = "getplan/"+ '?id=' + selectedValue;
             $.ajax({
                type: 'get',
                url: targeturl,
                beforeSend: function(xhr) {
                   xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                },
                success: function(response) { 
                    document.getElementById("plan-id").innerHTML = response;                                    	
                }
            });      
        });
        
      $('#fdssubmit').click(function(){
         
           if ($("#typeofdeposit").val() != 'renewal') { 
                if($('#bank-id').val() == ''){
                  $('#bank-id').css('border', '1px solid #ff0000');    
                  alert('Bank Name is required');  
                  return false;
                }else{
                   $('#bank-id').css('border', '1px solid #999');   
                }
                
                if($('#chequeno').val() == ''){
                  $('#chequeno').css('border', '1px solid #ff0000');  
                  alert('Chequeno is required');  
                  return false;
                }else{
                   $('#chequeno').css('border', '1px solid #999');   
                }
           }          
        }); 
        
   });
</script>        
<nav class="large-3 medium-4 columns" id="actions-sidebar">
      <?= $this->element('admin_sidebar') ?>
</nav>
<div class="users product-wrapper form large-9 medium-8 columns  add-product-cont content content-wrapper">

    
    <?= $this->Form->create($fd, ['enctype' => 'addfds/form-data','name'=>'addfds']) ?>
    <fieldset class="outer-container">
        <legend><?= __('Add Fixed Deposit') ?></legend>
        <div class="fds-add-top">
            <button type="button" class="btn btn-primary addButton" data-toggle="myModal">Add New Customer</button>
            <?= $this->Html->link(__('List FDs'), ['controller' => 'Fds', 'action' => 'index'],['class' => 'green-btn']) ?> 
        </div>
		<div class="addmenu-col">
                 <fieldset class="fieldset2" >
		<!--<button type="button" class="btn btn-primary addButton" data-toggle="myModal">
                     Add New Customer
                    </button> -->
		<div class="column-box">
                    <?php
                    
                    echo $this->Form->input('mainbrokerid', ['class' => __('add-column'),'label' =>'Main Broker Name:','required' => true,'options' => $mainbrokers,'empty'=>'Choose Main Broker']);
                    
                     echo $this->Form->input('fapplicantname',['id' => 'autocomplete','label' => 'Applicant Name']);
                    ?>
                    <div id="pan-id"> 
                    <?php    
                     echo $this->Form->input('panno',['class' => __('add-column'),'label' => 'Applicant Pan No']);
                     ?> 
                    </div>   
                    <?php   echo $this->Form->input('minor',['class' => __('add-column'),'type'=>'checkbox','label' => 'Minor']);            
                                echo $this->Form->input('minorname',['class' => __('add-column'),'type'=>'text','label' => 'Minor Name']);            
					
				
                                echo $this->Form->input('applicationno', ['class' => __('add-column'),'label' =>'Application No:']);
                                echo $this->Form->input('typeofdeposit', ['class' => __('add-column'),'empty'=>'Choose Type of Deposit','label' =>'Type of Deposit:','options' => $typeofdeposit]);
                                echo $this->Form->input('productcompanyid', ['class' => __('add-column'),'empty'=>'Choose Company Name','label' =>'Company Name:','options' => $productcompanies]);				
				echo $this->Form->input('plan_id', ['class' => __('add-column'),'empty'=>'Choose Plan','label' =>'Plan/Scheme Name:','options' => $plans]);
				/*echo $this->Form->input('tenure', ['class' => __('add-column'),'empty'=>'Choose Tenure','label' =>'Tenure (In Month):','options' => $tenure]);*/
				echo $this->Form->input('tenure',['class' => __('add-column'),'type'=>'text','label' => 'Period (In Month)']);
                                echo $this->Form->input('planstartdate', ['required' => false,						
						   'class'=>'datepicker',
						   'type'=>'text','placeholder'=>'dd/mm/yyyy',
						   'label' =>'Plan Start Date: ']);
				
            echo $this->Form->input('maturitydate', ['required' => false,						
						   'class'=>'datepicker',
						   'type'=>'text','placeholder'=>'dd/mm/yyyy',
						   'label' =>'Maturity Date: ']);
				echo $this->Form->input('amount', ['class' => __('add-column'),'type'=>'text','required' => false,'label' =>'Amount:']); 
                                echo $this->Form->input('mainbrokerid', ['class' => __('add-column'),'label' =>'Main Broker Name:','required' => true,'options' => $mainbrokers,'empty'=>'Choose Main Broker']);
                                echo $this->Form->input('subbroker_id', ['class' => __('add-column'),'label' =>'Sub Broker Name:','required' => false,'options' => $subbrokers,'empty'=>'Choose Sub Broker']);
				echo $this->Form->input('bank_id', ['class' => __('add-column'),'empty'=>'Choose Bank Name','label' =>'Bank Name:','options' => $banks]);
	                        echo $this->Form->input('chequeno', ['class' => __('add-column'),'required' => false,'label' =>'Cheque/DD No:']);
	                        echo $this->Form->input('fdrno',['class' => __('add-column'),'label' => 'FDR no']);
                                echo $this->Form->input('company_id', ['class' => __('add-column'),'label' =>'User Company Name:','options' => $usercompanies,'empty'=>'Choose Company']);
				echo $this->Form->input('branch_id', ['class' => __('add-column'),'label' =>'User Branch Address:','options' => $userbranches,'empty'=>'Choose Branch']);
                                echo $this->Form->input('despatchdate', ['required' => true,						
						   'class'=>'datepicker',
						   'type'=>'text','placeholder'=>'dd/mm/yyyy',
						   'label' =>'Despatch Date: ']);
                                
                                ?> 
                       </div>
                    	
			
		</div>
	
</fieldset>   
	<div class = "add-button">
		<?= $this->Form->button(__('Submit'),['id'=>'fdssubmit','class' => __('green-btn')]) ?>
	</div>
<div class="btn-link"><input type="button" value="Back" onclick="window.history.back()" class="green-btn" /> </div>
    </div>                          
    <?= $this->Form->end() ?>
</div>


<script>
$("#autocomplete").autocomplete(
        {
            search: function () {},
            source: function (request, response)
            {
                $.ajax(
                {
                    source: "/Mutualfunds/getuserinfo",
                    dataType: "json",
                    data:
                    {
                        term: request.term,
                    },
                    success: function (data)
                    {
                        response(data);
                        //console.log(data);
                    }
                });
            },
            minLength: 1
        });
        
   $(document).ready(function() {     
        $('.addButton').on('click', function() {
           $('#myModal').modal('show');
        });
        $('#cancelcustomer').on('click', function() {
           $('#myModal').modal('hide');
        });
       $('#savecustomer').on('click', function() { 
         $.ajax({
                type: 'get',
                url:  "saveCustomer",
                data: $('form#addcustomer').serialize(),
                beforeSend: function(xhr) {
                      xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                },
                success: function(response) {  
                    alert(response);
                    if(response == 'The Customer has been saved.'){
                     $('#myModal').modal('hide');
                    }                   
                },
                error: function(e) {
                       // alert("An error occurred: " + e.responseText.message);
                       // console.log(e);
                }
            });
       });
       
  });
  
  $('#tenure').keyup(function(){
	  if($(this).val() > 120){
		  alert('Period should not be greater than 120');
		  $(this).val(120);
	  }
  });
  
</script>



<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">     
      <div class="modal-body">
          <form id="addcustomer" name="addcustomer" method="POST" action="#">
             Customer Name: <input type="text" name="cname" value="">
             Pan Number:  <input type="text" name="panno" value="">
             <input type="button" value="Save" id="savecustomer" class="btn btn-primary">
             <input type="button" value="cancel" id="cancelcustomer" class="btn btn-primary">
          </form>    
      </div>
      <div class="modal-footer">
     </div>
    </div>
  </div>
</div>