<?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');
?>
<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><?= __('Companywise IPO 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 if(!empty($ipos->toArray())){?>
    <!-- <div> IPO </div> -->
    <div class="search-wrapper">  
    <div class="btn-link">
        <?= $this->Html->link(__('Excel Export'), [
           'controller' => 'Reports', 'action' => 'companywiseipoexcelreport',
           '?' =>['company'=> $company,'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: IPO </div>
</th>			  
              <th scope="col" colspan="3"><b>
			  
			 
			  
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             
                           echo 'Date :  '. $datedform;
                             echo ' - '.$datedto;     
						   }
						   else{
                     echo 'Date : all' ;
                 }
                  ?></b></th>
                 <th scope="col" colspan="3"><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" 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>
  
    
    <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 } ?>
 <script>
function print_function(){
window.print();
}
</script>