<?php  use Cake\ORM\TableRegistry;
	$companies = TableRegistry::get('Companies');  
	$brokers = 	 TableRegistry::get('Brokers'); 
	$scheme = TableRegistry::get('Mffunds');
	  $branches = TableRegistry::get('Branches');
	 $user1 = $this->request->session()->read('Auth.User'); 
?>
<?= $this->Html->script('schemeload.js'); ?>
<script>
 $(document).ready(function() { 
  $("form").submit(function(){
 if($('#datedform').val() ==''){
                 alert("Please choose Maturity from date for report");
                 return false;
                }
                if($('#datedto').val() == ''){
                 alert("Please choose Maturity to date for report");
                 return false;
                } 
				}); 
  });
</script>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
      <?= $this->element('admin_sidebar') ?>
</nav>
<div class="mutualfunds index large-9 medium-8 columns content">
<div class="col-md-6">
<h3><?= __('Mutual Fund STP Maturity Report') ?></h3>
</div>
    <div class="search-wrapper">
<div class="col-md-6">
    <div class="btn-link">
	<button onclick="print_function()" class="green-btn print-btn">Print</button>
    </div> 
    <div class="btn-link"><input type="button" value="Back" onclick="window.history.back()" class="green-btn" /> </div>
</div>
    <!--<div class="btn-link">
            <?= $this->Html->link(__('Excel Export'), [
               'controller' => 'Reports', 'action' => 'mfreports',
               '?' =>[//'fapplicantname'=> $fapplicantname,
              //  'panno' => $panno,   
                'datedform'=> $datedform,
                'datedto'=> $datedto,
                'company'=> $company,
				'scheme'=>$scheme,
				'branch'=>$branch,
				
               // 'subbroker'=> $subbroker,
               // 'typeofdeposit'=>$typeofdeposit,
                'page'=>((isset($page))? $page :1) ]],['class'=>'green-btn']); ?></div>--> 
	
        <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>       
  
    </div>
	<?php if(!empty($mf)){ ?>
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
    <thead>
	<tr>
		<th scope="col" colspan="4"><b>
			  
			  <div style="clear: both;">Report: Mutual Funds STP Maturity</div>
</th>			  
<th scope="col" colspan="2"><b>
			  	  
			  <?php 
			  if($company != '' && $company != 'all')
			  {
				$companyid= $companies->find()->where(['id' => $company]);
				 $databr1 = $companyid->toArray();
				echo 'Product :'. $databr1[0]->company;
			  }
			  else{
			  echo 'Product : all' ;
			  }
			  
			  ?></b>
			  </th>
              <th scope="col" colspan="4"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $dated2;
						   echo ' - '.$dated1;     
						   }
						   else{
                     echo 'Date : all' ;
                 }
                  ?></b></th>
				  				  <th scope="col" colspan="3"><b>
			 
			 
			  <?php 
			  if($user1['group_id'] == '3')
			  {
			   $branchesid1 = $branches->find()->where(['id' => $user1['branch_id']]);
                             $databr = $branchesid1->toArray();
			  echo 'Branch Name :'. $databr[0]->branchname;;
			  }
			  else{
                 if($branch != '' && $branch != 'all'){
                             $branchesid = $branches->find()->where(['id' => $branch]);
                             $databr = $branchesid->toArray();
                           echo 'Branch Name :  '. $databr[0]->branchname;
                 }else{
                     echo 'Branch Name : All';
                 }
				 }
                  ?></b></th>
				  </tr>
	
            <tr>
                <th scope="col"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investor') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Mutual Fund') ?></th> 
                <th scope="col"><?= $this->Paginator->sort('Mf Scheme') ?></th> 
				<th scope="col"><?= $this->Paginator->sort('LumpSum Amount') ?></th>
				<th scope="col"><?= $this->Paginator->sort('STP Amount') ?></th>
				<th scope="col"><?= $this->Paginator->sort('STP To Scheme') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Start Date') ?></th>
                <th scope="col"><?= $this->Paginator->sort('End Date') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Period') ?></th>
    
                <th scope="col"><?= $this->Paginator->sort('Deposit Type') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Sub-broker') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Branch') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php  $srlno = ($this->request->params['paging']['Mutualfunds']['page']-1) * $this->request->params['paging']['Mutualfunds']['perPage'];
            $j=1; $total=0; $k=''; 
			
            foreach ($mf as $mutualfund): $srlno++;
			//debug($mutualfund);
			?>
            <tr>
                <td><?=$srlno ?></td>
                <td><?= h($mutualfund->firstapplicantname) ? $this->Html->link($mutualfund->firstapplicantname, ['controller' => 'Mutualfunds', 'action' => 'view', $mutualfund->id]) : ''  ?></td>
                <td>
		<?php
			if($mutualfund->productcompanyid > 0){
				$companiesdata = $companies->find()->where(['id' => $mutualfund->productcompanyid]);
				$data = $companiesdata->toArray();
				if($data){
					echo $companiesname = $data[0]->company;
				}
			}
		?>
		</td>
                <!--<td><?= $mutualfund->has('mffund') ? $this->Html->link($mutualfund->mffund->fundname, ['controller' => 'Mffunds', 'action' => 'view', $mutualfund->mffund->mffund_id]) : '' ?></td> -->
				<td><?php 
				if($mutualfund->mffund_id > 0){
				$schemedata = $scheme->find()->where(['id' => $mutualfund->mffund_id]);
				$data = $schemedata->toArray();
				if($data){
					echo $schemename = $data[0]->fundname;
				}
			} ?></td>
				<td><?= h($mutualfund->amount) ?></td>
				<td><?= h($mutualfund->stpamount) ?></td>
				<td><?php 
				if($mutualfund->newstpscheme > 0){
				$schemedata = $scheme->find()->where(['id' => $mutualfund->newstpscheme]);
				$data = $schemedata->toArray();
				if($data){
					echo $schemename = $data[0]->fundname;
				}
			} ?></td>
               <td><?= h($mutualfund->planstartdate) ?></td>
               <td><?= h($mutualfund->maturitydate) ?></td>
               <td><?= h($mutualfund->tenure) ?></td>
                
               <td><?= h($mutualfund->typeofdeposit) ?></td>
              <!-- <td><?= $mutualfund->has('broker') ? $this->Html->link($mutualfund->broker->name, ['controller' => 'Brokers', 'action' => 'view', $mutualfund->broker->broker_id]) : '' ?></td> -->
               <td><?php
				if($mutualfund->broker_id > 0){
				$brokersdata = $brokers->find()->where(['id' => $mutualfund->broker_id])->andwhere(['role'=>'Subbroker']);
				$data = $brokersdata->toArray();
			
				if($data){
					echo $brokername = $data[0]->name;
				}
			} ?></td>
               
               <!--<td><?= $mutualfund->has('branch') ? $this->Html->link($mutualfund->branch->branchname, ['controller' => 'Branches', 'action' => 'view', $mutualfund->branch->branch_id]) : '' ?></td> -->
			   <td><?php 
			   if($mutualfund->branch_id > 0){
                             $branchesid = $branches->find()->where(['id' => $mutualfund->branch_id]);
							
                             $data = $branchesid->toArray();
							 
							 if($data)
							 {
								echo $branchname = $data[0]->branchname;
						     }
                 }
				 ?></td> 
               
            </tr>
			 <?php 
			 $total += $mutualfund->amount;
					$k =$j;
                    $j++;
            
            endforeach; ?>
			<tr class="total">
                <td colspan="4" style="text-align:right"><b>Sub Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="8"></td> 
            </tr> 
		
			<?php if($this->request->params['paging']['Mutualfunds']['pageCount'] == $this->request->params['paging']['Mutualfunds']['page']){?>
			<tr class="total">
                <td colspan="4" style="text-align:right"><b>Grand Total</b></td>
                <td><b><?=$total_amount?></b></td> 
                <td colspan="8"></td> 
            </tr> 
		
			 <?php } ?>
        </tbody>
    </table>
    <div class="paginator">
        <ul class="pagination">
            <?php echo $this->Paginator->first(__('First', true), array('class' => 'disabled'));?>
            <?= $this->Paginator->prev('< ' . __('previous',true), array('class' => 'disabled')) ?>
            <?= $this->Paginator->numbers() ?>
            <?= $this->Paginator->next(__('next' . ' >',true), array('class' => 'disabled')) ?>
		 <?php echo $this->Paginator->last(__('Last', true), array('class' => 'disabled'));?>
        </ul>
        <p><?= $this->Paginator->counter() ?></p>
    </div>
	<?php } ?>
</div>
<script> 
function print_function(){
window.print();
}
</script>
