<?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="fds index large-9 medium-8 columns content">
    <h3><?= __('FD 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' => 'fdreports',
           '?' =>['fapplicantname'=> $fapplicantname,
            //'panno' => $panno,   
            'datedform'=> $datedform,
            'datedto'=> $datedto,
            'typeofdeposit'=>$typeofdeposit]],['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 scope="col"><?= $this->Paginator->sort('Sr') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investor') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Product') ?></th>
                 <th scope="col"><?= $this->Paginator->sort('Fund+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('Option') ?></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('Amount') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php $j=1; $total=''; $k='';
            foreach ($fds as $fd): ?>
            <tr>
                <td><?=$j ?></td>
                <td><?= h($fd->fapplicantname) ?></td>
                <td>
		<?php
			if($fd->productcompanyid > 0){
				$companiesdata = $companies->find()->where(['id' => $fd->productcompanyid]);
				$data = $companiesdata->toArray();
				if($data){
					echo $companiesname = $data[0]->company;
				}
			}
		?>
		</td>
                <td><?= $fd->has('plan') ? $this->Html->link($fd->plan->Planname, ['controller' => 'Plans', 'action' => 'view', $fd->plan->plan_id]) : '' ?></td>
                <td><?= h($fd->typeofdeposit) ?></td>
                <td><?= h($fd->fdrno) ?></td>
                <td><?= h($fd->fdrno) ?></td>
                <td><?= h($fd->planstartdate) ?></td>
                <td><?= h($fd->maturitydate) ?></td>
                <td><?= h($fd->amount) ?></td>
            </tr>
             <?php $total += $fd->amount;
			$k =$j;
			$j++;
            endforeach; ?>
			<tr>
                <td colspan="9" style="text-align:right">Total</td>
                <td><?=$total?></td> 
               <!--  <td colspan="0"></td>  -->
            </tr> 
			<tr>
                <td colspan="9" style="text-align:right">Total clients</td>
                <td><?=$k?></td> 
               <!--  <td colspan="0"></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>