<?php  use Cake\ORM\TableRegistry;
	   $user1 = $this->request->session()->read('Auth.User'); 
	   $user  = TableRegistry::get('Users');
       $banks = TableRegistry::get('Banks');
       $companies = TableRegistry::get('Companies');  
	   $branches = TableRegistry::get('Branches');
	   $plans = TableRegistry::get('Plans');
?>
<script>
   $(document).ready(function() {     
        $('.printButton').on('click', function() {
          var visible =  $('#actions-sidebar,.search-wrapper').toggle().is(":visible");
            if(visible){
               $('.daily').css('width','83%');
            }else{
               $('.daily').css('width','100%');
            }
        }); 
        
      $("form").submit(function(){
           // e.preventDefault();
            if($('#branch').val() ==''){
                alert("Please choose the branch for report");
                return false;
            }
            if($('#branch').val() =='all'){
                if($('#datedform').val() ==''){
                 alert("Please choose Start date for report");
                 return false;
                }
                if($('#datedto').val() == ''){
                 alert("Please choose End date for report");
                 return false;
                } 
            }
      }); 
  });
  </script>
<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><?= __('Date Range Wise Fixed Deposit Report') ?></h3>
<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 class="search-wrapper">
        <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>         
   </div>

    <?php if(!empty($fds)){?>
   <!--  <div> Fixed Deposit </div> -->
    <div class="search-wrapper">  
     <!--<div class="btn-link">
        <?= $this->Html->link(__('Excel Export'), [
           'controller' => 'Reports', 'action' => 'dailyfdsexcelreport',
           '?' =>['branch'=> $branch,   
            'datedform'=> $datedform,
            'datedto'=> $datedto]],['class'=>'green-btn']); ?></div> -->
    </div>
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
<tr>
<th scope="col" colspan="5"><b>
			  
			  <div style="clear: both;">Product: Fixed Deposit Daily Report</div>
</th>			  
              <th scope="col" colspan="3"><b>

			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                            echo 'Date :  '.$dated2;
						   echo ' - '.$dated1;  
                          // echo 'Date :  '. $datedform;   
                           //  echo ' - '.$datedto;     
						   }
						   else{
                     echo 'Date : all' ;
                 }
                  ?></b>
                 <th scope="col" colspan="5"><b><?php 
				 if($user1['group_id'] == '3')
			  {
			   $branchesid1 = $branches->find()->where(['id' => $user1['branch_id']]);
                             $databr = $branchesid1->toArray();
			  echo 'Branch Name :'. $databr[0]->branchname;;
			  }
			  else{
                 if($branch != '' && $branch != 'all' ){
                             $branchesid = $branches->find()->where(['id' => $branch]);
                             $databr = $branchesid->toArray();
                           echo 'Branch Name :  '. $databr[0]->branchname;
                 }else{
                     echo 'Branch Name : All';
                 }
				 }
                  ?></b></th>
             </tr> 
            <tr>
                <th scope="col"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Type of Deposit') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Product') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Scheme') ?></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('Folio/FDR No') ?></th>                
               <th scope="col"><?= $this->Paginator->sort('Despatch Date') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Bank Name') ?></th>
<th scope="col"><?= $this->Paginator->sort('Company') ?></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><?= h($fd->fapplicantname) ? $this->Html->link($fd->fapplicantname, ['controller' => 'Fds', 'action' => 'view', $fd->id]) : ''  ?></td>
                   <!--<td><?= h($fd->fapplicantname) ?></td>-->
                <td><?= h($fd->typeofdeposit) ?></td>
                
                <td>
		<?php
			if($fd->productcompanyid > 0){
			$companiesdata = $companies->find()->where(['id' => $fd->productcompanyid]);
			$data2 = $companiesdata->toArray();
			if($data2){
			echo $companiesname = $data2[0]->company;
			}
			} 
		?>
		</td>
                <!--<td><?= $fd->has('plan') ? $this->Html->link($fd->plan->Planname, ['controller' => 'Plans', 'action' => 'view', $fd->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->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><?= h($fd->fdrno) ?></td>
                 <td><?= h($fd->despatchdate) ?></td>
                <td><?php

                    if($fd->typeofdeposit != 'renewal'){ 
                        if($fd->bank_id > 0){
                             $banksid = $banks->find()->where(['id' => $fd->bank_id]);
                             $data1 = $banksid->toArray();
                           echo  $banksName = $data1[0]->banks;
                        } 
                    }
                ?></td>       
               <!--<td><?= $fd->has('company') ? $this->Html->link($fd->company->company, ['controller' => 'Companies', 'action' => 'view', $fd->productcompanyid]) : '' ?></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>
            </tr>
            <?php $total += $fd->amount;
              $i++;
            endforeach; ?>
<tr class="total">
                <td colspan="5" style="text-align:right"><b>Sub Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="6"></td> 
            </tr> 
<?php  if($this->request->params['paging']['Fds']['pageCount'] == $this->request->params['paging']['Fds']['page']){?>
	    <tr class="total">
                <td colspan="5" style="text-align:right"><b>Grand Total</b></td>
                <td><b><?= $total_amount ?></b></td> 
                <td colspan="6"></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>