<?php  use Cake\ORM\TableRegistry;
	$companies = TableRegistry::get('Companies');
	$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><?= __('Fixed Deposit Edit/Update') ?></h3></div>
<div class="col-md-6">
<div class="btn-link margintop-fifteen"><?= $this->Html->link(__('Add Fixed Deposit Entry'), ['controller' => 'Fds', 'action' => 'add'],['class'=>'green-btn', 'title' => 'Add New Group', 'type' => 'button']) ?></div> </div>
	<div class="search-wrapper"> 
			<!--<fieldset class="fieldset2">-->
<div class="col-md-12">
            <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>
			<!--</fieldset>-->
          </div>  
        </div>
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
               <th style="width:40px;" scope="col"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Applicant Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('product') ?></th>
               
                 <th scope="col"><?= $this->Paginator->sort('Deposit type') ?></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('MainBroker') ?></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 (months)') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Branch') ?></th>
                
                <th scope="col"><?= $this->Paginator->sort('company') ?></th>
               <th scope="col" class="actions"><?= __('Actions') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php
             $srlno = ($this->request->params['paging']['Fds']['page']-1) * $this->request->params['paging']['Fds']['perPage'];
			 $i=1;$total='';
            foreach ($fds as $fd): $srlno++; ?>
            <tr>
                <td><?= $srlno ?></td>
                <td><?php if($fd->minor == 1) {
                             echo  $fd->minorname.'&nbsp;&nbsp;U/G&nbsp;&nbsp;'.$fd->fapplicantname;
                          }else{
                              echo  $fd->fapplicantname;
                          } ?></td>
               <!--  <td><?= h($fd->panno) ?></td>-->
               <td>
		<?php
		//pr($fd->productcompanyid);//die();
		if($fd->productcompanyid > 0){
		$companiesdata = $companies->find()->where(['id' => $fd->productcompanyid]);
		$data2 = $companiesdata->toArray();
		if($data2){
		echo $companiesname = $data2[0]->company;
		}
		} 
		?>
		</td>
                <td><?= h($fd->typeofdeposit) ?></td>
				
                <td><?= h($fd->planstartdate) ?></td>
               
                <td><?= h($fd->maturitydate) ?></td>
				
                <td><?= $fd->has('broker') ? $this->Html->link($fd->broker->name, ['controller' => 'Brokers', 'action' => 'view', $fd->broker->broker_id]) : '' ?></td> 
                <td><?= h($fd->chequeno) ?></td>
                <td><?= h($fd->amount) ?></td>
                 <td><?= h($fd->tenure) ?></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><?= $fd->has('company') ? $this->Html->link($fd->company->company, ['controller' => 'Companies', 'action' => 'view', $fd->productcompanyid]) : '' ?></td>
                <td class="actions">
                    <?= $this->Html->link(__('View'), ['action' => 'view', $fd->id],['class' => 'view','title'=>__('View')]) ?>
<?php  if($this->request->session()->read('Auth.User.group_id')=='2'){ ?>  
                    <?= $this->Html->link(__('Edit'), ['action' => 'edit', $fd->id],['class' => 'edit','title'=>__('Edit')]) ?>
                   <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $fd->id], ['class' => 'delete','title'=>__('Delete'),'confirm' => __('Are you sure you want to delete # {0}?', $fd->id)]) ?>
<?php } ?>
<?php  if($this->request->session()->read('Auth.User.group_id')=='3'){ ?>  
                    <?= $this->Html->link(__('Edit'), ['action' => 'edit', $fd->id],['class' => 'edit','title'=>__('Edit')]) ?>
                   <!-- <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $fd->id], ['class' => 'delete','title'=>__('Delete'),'confirm' => __('Are you sure you want to delete # {0}?', $fd->id)]) ?>-->
<?php } ?>
                </td>
            </tr>
			<?php $total += $fd->amount; $i++; endforeach; ?>
			<tr class="total">
                <td colspan="8" style="text-align:right"><b>Sub Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="4"></td> 
            </tr> 
			<?php  if($this->request->params['paging']['Fds']['pageCount'] == $this->request->params['paging']['Fds']['page']){?>
			<tr class="total">
                <td colspan="8" style="text-align:right"><b>Grand Total</b></td>
                <td><b><?= $total_amount ?></b></td> 
                <td colspan="4"></td> 
            </tr> 
            <?php } ?>
        </tbody>
    </table>
<div class="btn-link"><input type="button" value="Back" onclick="window.history.back()" class="green-btn" /> </div>
    <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>
