<?php  use Cake\ORM\TableRegistry;
	$companies = TableRegistry::get('Companies'); 
	$scheme = TableRegistry::get('Mffunds');
	$branches = TableRegistry::get('Branches');
?>
<?= $this->Html->script('schemeload.js'); ?>
<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><?= __('Client Mutual Fund Portfolio') ?></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' => 'mfcprofilereports',
               '?' =>['fapplicantname'=> $fapplicantname,
               // 'panno' => $panno,   
                'datedform'=> $datedform,
                'datedto'=> $datedto,
                'company'=> $company
               ]],
				['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>
		<th scope="col" colspan="4"><b>
			  
			  <div style="clear: both;">Report: Client Mutual Fund Portfolio</div>
</th>			  
<th scope="col" colspan="2"><b>
			  	  
			  <?php 
			  if($company != '' &&  $company != 'all')
			  {
				$companyid= $companies->find()->where(['id' => $company]);
				 $databr = $companyid->toArray();
				echo 'Product :'. $databr[0]->company;
			  }
			  else{
			  echo 'Product : all' ;
			  }
			  
			  ?></b>
			  </th>
              <th scope="col" colspan="6"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             echo 'Date :  '.$dated2;
						   echo ' - '.$dated1; 
                          // echo 'Date :  '.$datedform;
						   // echo ' - '.$datedto;     
						   }
						   else{
                     echo 'Date : 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('Product') ?></th>
				 <th scope="col"><?= $this->Paginator->sort('Scheme') ?></th>
				 <th scope="col"><?= $this->Paginator->sort('Type') ?></th>
				 <th scope="col"><?= $this->Paginator->sort('Folio No') ?></th>
				 <th scope="col"><?= $this->Paginator->sort('Amount') ?></th>
				 <th scope="col"><?= $this->Paginator->sort('Branch') ?></th>
                 <th scope="col"><?= $this->Paginator->sort('Cheque No') ?></th>
                 <th scope="col"><?= $this->Paginator->sort('Period(months)') ?></th>
                 <th scope="col"><?= $this->Paginator->sort('Company') ?></th>  
                 <th scope="col"><?= $this->Paginator->sort('despatch date') ?></th>
            </tr>
        </thead>
        <tbody>    
            <?php  $srlno = ($this->request->params['paging']['Mutualfunds']['page']-1) * $this->request->params['paging']['Mutualfunds']['perPage'];
            $j=1; $total=''; $k='';
            foreach ($mf as $mutualfund): $srlno++ ?>
            <tr>
                <td><?=$srlno ?></td>
				 <!-- <td><?= h($mutualfund->firstapplicantname) ?></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><?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->typeofdeposit) ?></td>
                <td><?= h($mutualfund->customerFolioNo) ?></td>
				 <td><?= h($mutualfund->amount) ?></td>
				  <td><?php	if($mutualfund->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $mutualfund->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                <td><?= h($mutualfund->chequeno) ?></td>
                <td><?= h($mutualfund->tenure) ?></td>
               <!-- <td><?= $mutualfund->has('company') ? $this->Html->link($mutualfund->company->company, ['controller' => 'Companies', 'action' => 'view', $mutualfund->companyid]) : '' ?></td>-->  
			   <td>
			<?php 
				if($mutualfund->company_id > 0){
				//$user = 'user';
					$companiesdata = $companies->find()->where(['id' => $mutualfund->company_id]);
					$data = $companiesdata->toArray();
					//pr($data);
					if($data){
						echo $companiesname1 = $data[0]->company;
					}
				}
			?>
		</td>
               
               <!--  <td><?= $mutualfund->has('branch') ? $this->Html->link($mutualfund->branch->branchname, ['controller' => 'Branches', 'action' => 'view', $mutualfund->branch->id]) : '' ?></td>               
               
               
                <td><?= h($mutualfund->chequeno) ?></td>
               
                <td><?= h($mutualfund->applicationno) ?></td> -->
                 <td><?= h($mutualfund->despatchdate) ?></td>
            </tr>
            <?php $total += $mutualfund->amount;
					$k =$j;
					$j++;
            endforeach; ?>
            <tr class="total">
                <td  colspan="6" style="text-align:right"><b>Sub Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="5"></td> 
            </tr>  
            <?php if($this->request->params['paging']['Mutualfunds']['pageCount'] == $this->request->params['paging']['Mutualfunds']['page']){?>
			<tr class="total">
                <td  colspan="6" style="text-align:right"><b>Grand Total</b></td>
                <td><b><?=$total_amount?></b></td> 
                <td colspan="5"></td> 
            </tr> 
			<?php } ?>
			
		
		
        </tbody>
    </table>
    <div class="paginator">
        <ul class="pagination">
             <?= $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')) ?>
		 <?= $this->Paginator->last(__('Last', true), array('class' => 'disabled'));?>
        </ul>
        <p><?= $this->Paginator->counter() ?></p>
    </div>
	<?php } ?>
</div>
<script>
function print_function(){
window.print();
}
</script>