<?php  use Cake\ORM\TableRegistry;
       $banks = TableRegistry::get('Banks');
       $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">
    <h3><?= __('Daily Report') ?></h3>
<div class="btn-link">
	<button onclick="print_function()" class="green-btn print-btn">Print</button>
      </div> 
     <div class="search-wrapper">
        <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>         
   </div>
 <?php $product = ((isset($_REQUEST['Product']))? $_REQUEST['Product'] : '');
          if($product == 1 || $product==''){?>
    <?php if(!empty($mutualfunds->toArray())){?>
        
    <div class="search-wrapper">  
      <div class="btn-link">
        <?= $this->Html->link(__('Excel Export'), [
           'controller' => 'Reports', 'action' => 'dailymfexcelreport',
           '?' =>['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="4"><b>
			  
			  <div style="clear: both;">Product: Mutual Funds </div>
</th>			  
              <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $datedform;     
						   }
						   else{
                     echo 'Date : Today' ;
                 }
                  ?></b></th>
				  <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
                 if($branch != ''){
                             $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" style="width:40px;"><?= $this->Paginator->sort('Sr') ?></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('Cheque No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Folio No') ?></th>                
                <th scope="col"><?= $this->Paginator->sort('Bank Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Company') ?></th>    
            </tr>
        </thead>
        <tbody>
            <?php $i=1; $total = '';
            foreach ($mutualfunds as $mf): //pr($mf);?>
            <tr>
                <td><?=$i ?></td>                
                 <td><?= h($mf->firstapplicantname) ?></td>
                <td><?= h($mf->typeofdeposit) ?></td>
              
                <td>
		<?php
		if($mf->productcompanyid > 0){
		$companiesdata = $companies->find()->where(['id' => $mf->productcompanyid]);
		$data2 = $companiesdata->toArray();
		if($data2){
		echo $companiesname = $data2[0]->company;
		}
		} 
		?>
		</td>
                <td><?= $mf->has('mffund') ? $this->Html->link($mf->mffund->fundname, ['controller' => 'Mffunds', 'action' => 'view', $mf->mffund_id]) : '' ?></td>       
                <td><?php echo (($mf->swichall == 1)? 'All' : $mf->amount) ?></td>
                <td><?= h($mf->chequeno) ?></td>
                <td><?= h($mf->customerFolioNo) ?></td>
               
                <td><?php

                    if($mf->typeofdeposit != 'Switch'){ 
                        if($mf->bank_id > 0){
                             $banksid = $banks->find()->where(['id' => $mf->bank_id]);
                             $data1 = $banksid->toArray();
                             if($data1){
                           echo  $banksName = $data1[0]->banks;
                           }
                        } 
                    }
                ?></td> 
              <td><?= $mf->has('company') ? $this->Html->link($mf->company->company, ['controller' => 'Companies', 'action' => 'view', $mf->productcompanyid]) : '' ?></td>
            </tr>
             <?php $total += $mf->amount;
                    $i++;
            endforeach; ?>
<tr>
                <td colspan="5" style="text-align:right">Total</td>
                <td><?=$total?></td> 
                <td colspan="4"></td> 
            </tr> 
        </tbody>
    </table>
    <?php }} ?>
    <?php if($product == 2 || $product==''){?> 
    <?php if(!empty($fds->toArray())){?>
   <!--  <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="4"><b>
			  
			  <div style="clear: both;">Product: Fixed Deposit </div>
</th>			  
              <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $datedform;     
						   }
						   else{
                     echo 'Date : Today' ;
                 }
                  ?></b>
                 <th scope="col" colspan="3"><b><?php 
                 if($branch != ''){
                             $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" style="width:40px;"><?= $this->Paginator->sort('Sr') ?></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('Cheque No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Folio/FDR No') ?></th>                
               
                <th scope="col"><?= $this->Paginator->sort('Bank Name') ?></th>
<th scope="col"><?= $this->Paginator->sort('Company') ?></th> 
            </tr>
        </thead>
        <tbody>
            <?php $i=1;$total=' ';
            foreach ($fds as $fd):?>
            <tr>
                <td><?=$i ?></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><?= h($fd->amount) ?></td>
                <td> <?= h($fd->chequeno) ?> </td>
                <td><?= h($fd->fdrno) ?></td>
                
                <td><?= $fd->has('bank') ? $this->Html->link($fd->bank->banks, ['controller' => 'Banks', 'action' => 'view', $fd->bank_id]) : '' ?></td>       
               <td><?= $fd->has('company') ? $this->Html->link($fd->company->company, ['controller' => 'Companies', 'action' => 'view', $fd->productcompanyid]) : '' ?></td>   
            </tr>
            <?php $total += $fd->amount;
              $i++;
            endforeach; ?>
<tr>
                <td colspan="5" style="text-align:right">Total</td>
                <td><?=$total?></td> 
                <td colspan="4"></td> 
            </tr> 

        </tbody>
    </table>
    <?php }} ?>
     <?php if($product == 5 || $product==''){?> 
    <?php if(!empty($ncds->toArray())){?>
    <!-- <div> Ncds </div> -->
    <div class="search-wrapper">  
    <div class="btn-link">
        <?= $this->Html->link(__('Excel Export'), [
           'controller' => 'Reports', 'action' => 'dailyncdexcelreport',
           '?' =>['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="4">
				  <div style="clear: both;">Product: NCDS </div>
</th>			  
              <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $datedform.'-'.$datedto;     
						   }
						   else{
                     echo 'Date : Today' ;
                 }
                  ?></b></th>
                 <th scope="col" colspan="3"><b><?php 
                 if($branch != ''){
                             $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" style="width:40px;"><?= $this->Paginator->sort('Sr') ?></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('Cheque No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Folio/FDR No') ?></th>                
                
                <th scope="col"><?= $this->Paginator->sort('Bank Name') ?></th>
<th scope="col"><?= $this->Paginator->sort('Company') ?></th> 
            </tr>
        </thead>
        <tbody>
            <?php $i=1;$total = '';
            foreach ($ncds as $ncd): //pr($ncd);?>
            <tr>
                <td><?=$i ?></td>   
             
                
                           <td><?= h($ncd->firstapplicantname) ?></td>     
 
                <td><?= h($ncd->typeofdeposit) ?></td>
                
                <td>
		<?php
		if($ncd->productcompanyid > 0){
			$companiesdata = $companies->find()->where(['id' => $ncd->productcompanyid]);
			$data2 = $companiesdata->toArray();
			if($data2){
			echo $companiesname = $data2[0]->company;
			}
		} 
		?>
		</td>
		
                <!--<td><?= h($ncd->plan->Planname); ?></td> -->  
               <td><?= $ncd->has('plan') ? $this->Html->link($ncd->plan->Planname, ['controller' => 'Plans', 'action' => 'view', $ncd->plan_id]) : '' ?></td>
                <td><?= h($ncd->amount) ?></td>
                <td><?= h($ncd->chequeno) ?></td>
                <td><?= h($ncd->fdrno) ?></td>
               
                <td><?= $ncd->has('bank') ? $this->Html->link($ncd->bank->banks, ['controller' => 'Banks', 'action' => 'view', $ncd->bank_id]) : '' ?></td>       
 <td><?= $ncd->has('company') ? $this->Html->link($ncd->company->company, ['controller' => 'Companies', 'action' => 'view', $ncd->productcompanyid]) : '' ?></td>
            </tr>
            <?php $total += $ncd->amount; $i++;
            endforeach; ?>
<tr>
                <td colspan="5" style="text-align:right">Total</td>
                <td><?=$total?></td> 
                <td colspan="4"></td> 
            </tr> 
        </tbody>
    </table>
    <?php } } ?>
    <?php if($product == 4 || $product==''){?> 
    <?php if(!empty($ipos->toArray())){?>
    <!-- <div> IPO </div> -->
    <div class="search-wrapper">  
    <div class="btn-link">
        <?= $this->Html->link(__('Excel Export'), [
           'controller' => 'Reports', 'action' => 'dailyipoexcelreport',
           '?' =>['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="4">
 <div style="clear: both;">Product: Fixed Deposit </div>
</th>			  
              <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $datedform;     
						   }
						   else{
                     echo 'Date : Today' ;
                 }
                  ?></b></th>
                 <th scope="col" colspan="3"><b><?php 
                 if($branch != ''){
                             $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" style="width:40px;"><?= $this->Paginator->sort('Sr') ?></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('Cheque No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Folio/FDR No') ?></th>                
                
                <th scope="col"><?= $this->Paginator->sort('Bank Name') ?></th>
 <th scope="col"><?= $this->Paginator->sort('Company') ?></th> 
            </tr>
        </thead>
        <tbody>
            <?php $i=1;$total = '';
            foreach ($ipos as $ipo): //pr($ipo);?>
            <tr>
                <td><?=$i ?></td>                
                  <td><?= h($ipo->biddername) ?></td>
                <td><?= h($ipo->typeofdeposit) ?></td>
               
                <td>
		<?php
		if($ipo->productcompanyid > 0){
			$companiesdata = $companies->find()->where(['id' => $ipo->productcompanyid]);
			$data2 = $companiesdata->toArray();
			if($data2){
			echo $companiesname = $data2[0]->company;
			}
		} 
		?>
		</td>
		
               <!--<td><?= h($ipo->plan->Planname); ?></td> -->
                <td><?= $ipo->has('plan') ? $this->Html->link($ipo->plan->Planname, ['controller' => 'Plans', 'action' => 'view', $ipo->plan_id]) : '' ?></td>
                <td><?= h($ipo->amount) ?></td>
                <td><?= h($ipo->chequeno) ?></td>
                <td><?= h($ipo->fdrno) ?></td>
                
                <td><?= $ipo->has('bank') ? $this->Html->link($ipo->bank->banks, ['controller' => 'Banks', 'action' => 'view', $ipo->bank_id]) : '' ?></td>       
               <td><?= $ipo->has('company') ? $this->Html->link($ipo->company->company, ['controller' => 'Companies', 'action' => 'view', $ipo->productcompanyid]) : '' ?></td>     
            </tr>
            <?php $total += $ipo->amount; $i++;
            endforeach; ?>
<tr>
                <td colspan="5" style="text-align:right">Total</td>
                <td><?=$total?></td> 
                <td colspan="4"></td> 
            </tr> 
        </tbody>
    </table>
    <?php } } ?>
    
    <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>