<?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');
	   $brokers = 	 TableRegistry::get('Brokers'); 
	   $scheme = TableRegistry::get('Mffunds');
?>
<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 MutualFund 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">
		<div class="mul">
		<?= $this->Search->filterForm($searchFilters) ?></div> </div>        
   </div>

 <?php if(!empty($mutualfunds)){ ?> 
        
    <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="5"><b>
			  
			  <div style="clear: both;">Product: Mutual Funds </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>
				  <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 No') ?></th> 
                <th scope="col"><?= $this->Paginator->sort('Despatch Date') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Sub Broker') ?></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']['Mutualfunds']['page']-1) * $this->request->params['paging']['Mutualfunds']['perPage'];
            $i=1; $total = ''; 
            
            foreach ($mutualfunds as $mf):$srlno++; ?>
            <tr>
                <td><?=$srlno ?></td>                
               <td><?= h($mf->firstapplicantname) ? $this->Html->link($mf->firstapplicantname, ['controller' => 'Mutualfunds', 'action' => 'view', $mf->id]) : ''  ?></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 
				if($mf->mffund_id > 0){
				$schemedata = $scheme->find()->where(['id' => $mf->mffund_id]);
				$data = $schemedata->toArray();
				if($data){
					echo $schemename = $data[0]->fundname;
				}
			} ?></td>
                <td><?php echo (($mf->swichall == 1)? 'All' : $mf->amount) ?></td>
                <td><?php	if($mf->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $mf->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                <td><?= h($mf->chequeno) ?></td>
                <td><?= h($mf->customerFolioNo) ?></td>
                <td><?= h($mf->despatchdate) ?></td>
             <td><?php
				if($mf->broker_id > 0){
				$brokersdata = $brokers->find()->where(['id' => $mf->broker_id])->andwhere(['role'=>'Subbroker']);
				$data = $brokersdata->toArray();
				if($data){
					echo $brokername = $data[0]->name;
				}
			} ?></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->company_id]) : '' ?></td> -->
              <td>
              <?php 
				if($mf->company_id > 0){
			
					$companiesdata = $companies->find()->where(['id' => $mf->company_id]);
					$data = $companiesdata->toArray();
				
					if($data){
						echo $companiesname1 = $data[0]->company;
					}
				}
			?>
			</td>
            </tr>
             <?php $total += $mf->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="7"></td> 
            </tr> 
			<?php  if($this->request->params['paging']['Mutualfunds']['pageCount'] == $this->request->params['paging']['Mutualfunds']['page']){?>
			<tr class="total">
                <td colspan="5" style="text-align:right"><b>Grand Total</b></td>
                <td><b><?=$total_amount?></b></td> 
                <td colspan="7"></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>