<?php
use Cake\Routing\Router;
use Cake\View\Helper\UrlHelper;
?>
<script>
   $(document).ready(function() {
       $('#productcompanyid').change(function() { 
          var selectedValue = $(this).val();      
            var targeturl = "getschemeinfo/"+ '?company_id=' + selectedValue;
             $.ajax({
                type: 'get',
                url: targeturl,
                beforeSend: function(xhr) {
                        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                },
                success: function(response) { 
                    document.getElementById("mffund-id").innerHTML = response;                                      	
                }
            });      
        });
        
        $('#newproductcompanyid').change(function() { 
          var selectedValue = $(this).val();      
            var targeturl = "getschemeinfo/"+ '?company_id=' + selectedValue;
             $.ajax({
                type: 'get',
                url: targeturl,
                beforeSend: function(xhr) {
                        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                },
                success: function(response) { 
                    document.getElementById("newmfid").innerHTML = response;                                      	
                }
            });      
        });
        
        $('#newstpfund').change(function() { 
          var selectedValue = $(this).val();      
            var targeturl = "getschemeinfo/"+ '?company_id=' + selectedValue;
             $.ajax({
                type: 'get',
                url: targeturl,
                beforeSend: function(xhr) {
                        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                },
                success: function(response) { 
                    document.getElementById("newstpscheme").innerHTML = response;                                      	
                }
            });      
        });
        
        $('#mfsubmit').click(function(){
          if($('#autocomplete').val() == ''){
            $('#autocomplete').css('border', '1px solid #ff0000');  
            alert('Applicant Name is required');  
            return false;
          }else{
             $('#autocomplete').css('border', '1px solid #999');   
          } 
          if($('#panno').val() == ''){
            $('#panno').css('border', '1px solid #ff0000');  
            alert('Applicant Pan no is required');  
            return false;
          }else{
             $('#panno').css('border', '1px solid #999');   
          }
           if ($("#typeofdepositmf").val() == 'Additional'  || $("#typeofdepositmf").val() == 'Switch' || $("#typeofdepositmf").val() == 'SIP - Renewal' || $("#typeofdepositmf").val() == 'STP') {   
                if($('#customerfoliono').val() == ''){
                  $('#customerfoliono').css('border', '1px solid #ff0000');  
                  alert('Customer folio no is required');  
                  return false;
                }else{
                   $('#customerfoliono').css('border', '1px solid #999');   
                }
           }
           if ($("#typeofdepositmf").val() == 'Additional' || $("#typeofdepositmf").val() == 'Fresh' || $("#typeofdepositmf").val() == 'SIP') {   
                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');   
                }
           }
           
        });
    });
</script> 
  
<nav class="large-3 medium-4 columns" id="actions-sidebar">
      <?= $this->element('admin_sidebar') ?>
</nav>
<div class="mutualfunds mutualfunds-wrapper form large-9 medium-8 columns content">
    <?= $this->Form->create($mutualfund,['name'=>'mfadd']) ?>
    <fieldset>
        <legend><?= __('Add Mutual Fund') ?></legend>
        <div class="btn-link"><?= $this->Html->link(__('Today Mutual Funds entries'), ['action' => 'index'],['class'=>'green-btn', 'title' => 'List Mutual Funds', 'type' => 'button']) ?></div>
		<button type="button" class="btn btn-primary addButton" data-toggle="myModal">
          Add New Customer
        </button>  
		<div class="addmenu-col">
		<div class="column-box">
      <?php
        echo $this->Form->input('firstapplicantname',['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('typeofdeposit', ['class' => __('add-column'),'id'=>'typeofdepositmf','empty'=>'Choose Type of Deposit','label' =>'Type of Deposit:','options' => $typeofdeposit]);
        echo $this->Form->input('productcompanyid',['class' => __('add-column'),'empty'=>'Mutual fund','label' => 'Mutual Fund','options' => $productcompanies]);
        echo $this->Form->input('mffund_id',['class' => __('add-column'),'empty'=>'Choose MF Scheme','label' => 'MF Scheme','options' => $mffunds]);

        echo $this->Form->input('bank_id',['class' => __('add-column'),'empty'=>'Choose Bank','label' => 'Bank Name','options' => $banks]);
        echo $this->Form->input('chequeno',['class' => __('add-column'),'label' => 'Cheque Number']);
        echo $this->Form->input('swichall',['class' => __('add-column'),'type'=>'checkbox','label' => 'Switch all']);            
        echo $this->Form->input('amount',['class' => __('add-column'),'type'=>'text','label' => 'Amount']);
        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',
						   'label' =>'Start Date: ']);
				
        echo $this->Form->input('maturitydate', ['required' => false,						
						   'class'=>'datepicker',
						   'type'=>'text',
						   'label' =>'Maturity Date: ']);
        echo $this->Form->input('noofunit',['class' => __('add-column'),'type'=>'text','label' => 'Number of Unit']);  
        echo $this->Form->input('newproductcompanyid',['class' => __('add-column'),'empty'=>'New Mutual fund','label' => 'New Mutual Fund','options' => $productcompanies]);
        echo $this->Form->input('newmfid',['class' => __('add-column'),'empty'=>'Choose MF Scheme','label' => 'New MF Scheme','options' => $mffunds]);
        echo $this->Form->input('customerFolioNo',['class' => __('add-column'),'label' => 'Folio Number.']);  

        echo $this->Form->input('stpdate', ['required' => false,						
						   'class'=>'datepicker',
						   'type'=>'text',
						   'label' =>'STP Date: ']);
        echo $this->Form->input('stpamount',['class' => __('add-column'),'type'=>'text','label' => 'STP Amount']);
        echo $this->Form->input('newstpfund',['class' => __('add-column'),'label' => ' STP To Fund','options' => $productcompanies]);
        echo $this->Form->input('newstpscheme',['class' => __('add-column'),'label' => ' STP To Scheme','options' => $mffunds]);
        echo $this->Form->input('applicationno',['class' => __('add-column'),'label' => 'Application No']);
        echo $this->Form->input('subbroker_id', ['class' => __('add-column'),'label' =>'Referred by:','required' => false,'options' => $subbrokers,'empty'=>'Choose Referred by']);
        echo $this->Form->input('company_id', ['class' => __('add-column'),'empty'=>'Choose Company Name','label' => 'User Company Name','options' => $usercompanies]);
       // echo $this->Form->input('branch_id', ['class' => __('add-column'),'empty'=>'Choose Company Branch','label' => 'Company Branch','options' => $branches]);
        echo $this->Form->input('euni_id',['class' => __('add-column'),'empty'=>'Choose Euni No','label' => 'EUIN No.','options' => $eunis]);
        echo $this->Form->input('despatchdate', ['required' => true,						
						   'class'=>'datepicker',
						   'type'=>'text',
						   'label' =>'Despatch Date: ']);
            ?>
       </div></div>
    </fieldset>   
	<div class = "add-button">
		<?= $this->Form->button(__('Submit'),['id'=>'mfsubmit','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);
                }
            });
       });
       
  });
</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>