<?php  use Cake\ORM\TableRegistry;
	$companies = TableRegistry::get('Companies'); 
	$brokers = TableRegistry::get('Brokers'); 
	$plans = TableRegistry::get('Plans');
	$branches = TableRegistry::get('Branches');
?>
<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">
<div class="col-md-6">
    <h3><?= __('Client Fixed Deposit 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' => '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>
    
    <?php if(!empty($fds)){ ?> 
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
		<tr>
		<th scope="col" colspan="4"><b>
			  
			  <div style="clear: both;">Report: Client Fixed Deposit Portfolio</div>
</th>			  
<th scope="col" colspan="4"><b>
			  	  
			  <?php 
			  if($fapplicantname != '')
			  {
				
				echo 'Applicant :'.$fapplicantname;
			  }
			  else{
			  echo 'Applicant : all' ;
			  }
			  
			  ?></b>
			  </th>
              <th scope="col" colspan="5"><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('Period(months)') ?></th>
                 <th scope="col"><?= $this->Paginator->sort('FDR 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('Main Broker') ?></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']['Fds']['page']-1) * $this->request->params['paging']['Fds']['perPage'];
            $j=1; $total=''; $k='';
            foreach ($fds as $fd): $srlno++; ?>
            <tr>
                <td><?=$srlno ?></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>
                <?php 
                if($fd->plan_id > 0) 
		{
			$planid = $plans->find()->where(['id' => $fd->plan_id]);
			$data2 = $planid->toArray();
			if($data2)
			{
		    echo $planname = $data2[0]->Planname;
		    }
		} ?></td> 
                <td><?= h($fd->typeofdeposit) ?></td>
				<td><?= h($fd->tenure) ?></td>
                <td><?= h($fd->fdrno) ?></td>
				<td><?= h($fd->amount) ?></td>
				
				<td><?php	if($fd->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $fd->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                 <td><?= h($fd->chequeno) ?></td>
              <!--  <td><?= $fd->has('broker') ? $this->Html->link($fd->broker->name, ['controller' => 'Brokers', 'action' => 'view', $fd->broker->broker_id]) : '' ?></td> -->
			    <td><?php
				if($fd->mainbrokerid > 0){
				$brokersdata = $brokers->find()->where(['id' => $fd->mainbrokerid]);
				$data = $brokersdata->toArray();
				//pr($data);
				if($data){
					echo $brokername = $data[0]->name;
				}
			} ?></td> 
				<td>
			<?php 
				if($fd->company_id > 0){
				//$user = 'user';
					$companiesdata = $companies->find()->where(['id' => $fd->company_id]);
					$data = $companiesdata->toArray();
					//pr($data);
					if($data){
						echo $companiesname1 = $data[0]->company;
					}
				}
			?>
		</td>  
		<td><?=h($fd->despatchdate)?></td>
            </tr>
            <?php $total += $fd->amount;
					$k =$j;
			$j++;
            endforeach; ?>
			<tr class="total">
                <td colspan="7" style="text-align:right"><b>Sub Total</b></td>
                <td><b><?=$total?></b></td> 
                 <td colspan="5"></td> 
            </tr> 
			<!-- <tr>
                <td colspan="9" style="text-align:right"><b>Total clients</b></td>
                <td><?=$k?></td> 
                 <td colspan="0"></td> 
            </tr>  -->
            <?php  if($this->request->params['paging']['Fds']['pageCount'] == $this->request->params['paging']['Fds']['page']){?>
	    <tr class="total">
                <td colspan="7" 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>