<?php  use Cake\ORM\TableRegistry;
	$companies = TableRegistry::get('Companies'); 
	$brokers = 	 TableRegistry::get('Brokers'); 
	  $branches = TableRegistry::get('Branches');
	   $user1 = $this->request->session()->read('Auth.User'); 
?>
<script>
 $(document).ready(function() { 
   $("form").submit(function(){
   if($('#datedform').val() ==''){
     alert("Please choose Maturity from date for report");
     return false;
    }
   if($('#datedto').val() == ''){
     alert("Please choose Maturity to 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><?= __('Fixed Deposit Maturity Report') ?></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"><input type="button" value="Back" onclick="window.history.back()" class="green-btn" /> </div>
     <!--<div class="btn-link">
        <?= $this->Html->link(__('Excel Export'), [
           'controller' => 'Reports', 'action' => 'fdreports',
           '?' =>['company'=> $company,
            //'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)){ ?>  
    <div id="report">
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
		<tr>
		<th scope="col" colspan="3"><b>
			  
			  <div style="clear: both;">Report: FD Maturity</div>
</th>			  
<th scope="col" colspan="5"><b>
			  	  
			  <?php 
			  if($company != '' && $company != 'all' )
			  {
				$companyid= $companies->find()->where(['id' => $company]);
				 $databr = $companyid->toArray();
				echo 'Company :'. $databr[0]->company;
			  }
			  else{
			  echo 'Company : all' ;
			  }
			  
			  ?></b>
			  </th>
              <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $dated2;
						   echo ' - '.$dated1; 
						   }
						   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('Type') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Period(months)') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Amount') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Branch') ?></th>
				<th  scope="col"><?= $this->Paginator->sort('Mature On') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Mainbroker') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Subbroker') ?></th>
                
                <th scope="col"><?= $this->Paginator->sort('Company') ?></th>
                
               <!--  <th scope="col"><?= $this->Paginator->sort('Cheque No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('FDR No') ?></th>
               
              
                <th scope="col"><?= $this->Paginator->sort('Remark') ?></th> -->
                
            </tr>
        </thead>
        <tbody>
            <?php  $srlno = ($this->request->params['paging']['Fds']['page']-1) * $this->request->params['paging']['Fds']['perPage'];
            $j=1; $k=0; $total=0; $totalamt=0;
            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><?= h($fd->typeofdeposit) ?></td>
			      <td><?= h($fd->tenure) ?></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->maturitydate) ?></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->broker_id > 0){
				$brokersdata = $brokers->find()->where(['id' => $fd->broker_id])->andwhere(['role'=>'Subbroker']);
				$data = $brokersdata->toArray();
			
				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>
                
               
            </tr>
            <?php $total += $fd->amount;
					$k =$j;
					
					
			$j++;
            endforeach; ?>
			<tr class="total">
                <td colspan="5" style="text-align:right"><b>Sub Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="5"></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="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>
    </div>    
<?php } ?>	
</div>
 

<script>
   $(document).ready(function() {     
        $('.addButton').on('click', function() {
          //  var a = $('#report').html(); 
           // $('.modal-body').html(a);
          // $('#myModal').modal('show');
          $('#actions-sidebar,.search-wrapper').toggle();
          $('.fds').css('width','100%');
        });       
  });
</script>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">     
      <div class="modal-body">
            
      </div>
      <div class="modal-footer">
     </div>
    </div>
  </div>
</div>
<script>
function print_function(){
window.print();
}
</script>