<?php  use Cake\ORM\TableRegistry;
	$companies = TableRegistry::get('Companies');  
?>
<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">
<h3><?= __('MF Client Portfolio') ?></h3>
    <div class="search-wrapper">
    <div class="btn-link">
	<button onclick="print_function()" class="green-btn print-btn">Print</button>
    </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>
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <th style="width:40px;" scope="col"><?= $this->Paginator->sort('Sr.') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Company') ?></th>
                 <th scope="col"><?= $this->Paginator->sort('Product') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Scheme') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Location') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investor') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Type') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Folio No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Cheque No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Amount') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Period(In month)') ?></th>
                <th scope="col"><?= $this->Paginator->sort('App No') ?></th>                
            </tr>
        </thead>
        <tbody>    
            <?php $j=1; $total=''; $k='';
            foreach ($mf as $mutualfund): ?>
            <tr>
                <td style="width:40px;"><?=$j ?></td>
                <td><?= $mutualfund->has('company') ? $this->Html->link($mutualfund->company->company, ['controller' => 'Companies', 'action' => 'view', $mutualfund->productcompanyid]) : '' ?></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_id]) : '' ?></td>
                <td><?= $mutualfund->has('branch') ? $this->Html->link($mutualfund->branch->branchname, ['controller' => 'Branches', 'action' => 'view', $mutualfund->branch->id]) : '' ?></td>               
                <td><?= h($mutualfund->firstapplicantname) ?></td>
                <td><?= h($mutualfund->typeofdeposit) ?></td>
                <td><?= h($mutualfund->customerFolioNo) ?></td>
                <td><?= h($mutualfund->chequeno) ?></td>
                <td><?= h($mutualfund->amount) ?></td>
                <td><?= h($mutualfund->tenure) ?></td>
                <td><?= h($mutualfund->applicationno) ?></td>
            </tr>
           <?php $total += $mutualfund->amount;
					$k =$j;
					$j++;
            endforeach; ?>
			<tr>
                <td colspan="9" style="text-align:right">Total</td>
                <td><?=$total?></td> 
                <td colspan="2"></td> 
            </tr> 
			<tr>
                <td colspan="9" style="text-align:right">Total clients</td>
                <td><?=$k?></td> 
                <td colspan="2"></td> 
            </tr> 
        </tbody>
    </table>
    <div class="paginator">
        <ul class="pagination">
            <?= $this->Paginator->prev('< ' . __('previous')) ?>
            <?= $this->Paginator->numbers() ?>
            <?= $this->Paginator->next(__('next') . ' >') ?>
        </ul>
        <p><?= $this->Paginator->counter() ?></p>
    </div>
</div>
<script>
function print_function(){
window.print();
}
</script>