<?php  use Cake\ORM\TableRegistry;
	   $user1 = $this->request->session()->read('Auth.User'); 
	   $user  = TableRegistry::get('Users');
       $banks = TableRegistry::get('Banks');
	   $filename  = TableRegistry::get('Filenames');
       $companies = TableRegistry::get('Companies');  
	   $branches = TableRegistry::get('Branches');
	   	$scheme = TableRegistry::get('Mffunds');
?>
<?= $this->Html->script('schemeload.js'); ?>
<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">
<div class="col-md-6">
    <h3><?= __('Branch Wise Report') ?></h3>
	</div>
	<div class="col-md-6"><!--
<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>
<div class="search-wrapper">
    <div class="search-filter" style="width: 88%;"><?= $this->Search->filterForm($searchFilters) ?></div>         
</div>
    <?php if(!empty($result)): ?> 
     <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
			<tr>
				<th scope="col" colspan="2"><b><div style="clear: both;"><?php if($company != '' && $company != 'all'){
					$filenameid = $filename->find()->where(['id' => $company]);
					$filenamebr = $filenameid->toArray();echo 'Company Name: '. $filenamebr[0]->fname; }else {
					echo 'Company Name:';} ?></div></th>
				<th scope="col" colspan="1"><b><?php 			 
					if($datedform != '' && $datedto != '' ){echo 'Date :  '. $dated2; echo ' - '.$dated1;}
					else{echo 'Date : all' ;}?></b></th>
				<th scope="col" colspan="3"><b><?php echo 'Branch Name : Andheri';?></b></th> 
			</tr>
			<tr>
                <th scope="col" style="width:40px;"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Company Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Institution Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investment Amount') ?></th>
                <th scope="col"><?= $this->Paginator->sort('No of clients') ?></th>       
            </tr>
        </thead>
        <tbody>
			<?php $j=1; $total=0; $tc=0;
				foreach($result['andheri'] as $key=>$res): ?>
                <?php  foreach($res as $index =>$fd_res): ?>
				<tr>
					<td><?=$j ?></td>
                    <td><?php echo !empty($filenames[$fd_res['csvid']]) ? $filenames[$fd_res['csvid']]:'';?></td>
                    <td><?php echo !empty($this->request->query['institution_name']) && $this->request->query['institution_name'] !='all'  ? $this->request->query['institution_name'] : 'All'?></td>
					<td class="amtrgt"><?php if($fd_res['tamount']){echo $fd_res['tamount'];}else{echo 0;}?></td>
					<td>
                        <?php
                        if($fd_res['cnumber'] > 0){ ?>
                            <?php echo $this->Html->link($fd_res['cnumber'] , ['controller' => 'Fds','action' => 'fdmaturity', '?' =>
                                [ 'fname'=>$fd_res['csvid'],
                                    'institution_name' => !empty($this->request->query['institution_name']) ? $this->request->query['institution_name'] :'',
                                    'datedform'=>!empty($this->request->query['datedform']) ? $this->request->query['datedform'] :'',
                                    'datedto'=>!empty($this->request->query['datedto']) ? $this->request->query['datedto'] :''
                                ]
                            ], ['class' => '','title'=>__('View Clients')]) ?>
                        <?php }else{
                            echo $fd_res['cnumber'];
                        }?>
                    </td>
				</tr>    
			<?php $j++; $total += $fd_res['tamount']; $tc +=$fd_res['0']['cnumber'];

                    endforeach;
				endforeach;?>
				<tr class="total">
					<td colspan="3" style="text-align:right"><b>Grand Total</b></td>
					<td class="amtrgt"><b><?= number_format($total,2) ?></b></td>
					<td><b><?= $tc ?><b></td> 
				</tr> 
        </tbody>
		
    </table>
	
	<table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
			<tr>
				<th scope="col" colspan="2"><b><div style="clear: both;">
				<?php //if($company != '' && $company != 'all'){echo 'Company Name: '. $data[0]->fname; }else {echo 'Company Name:';} ?>
					<?php if($company != '' && $company != 'all'){$filenameid = $filename->find()->where(['id' => $company]);$filenamebr = $filenameid->toArray();echo 'Company Name: '. $filenamebr[0]->fname; }else {echo 'Company Name:';} ?>
					</div></th>			  
				<th scope="col" colspan="1"><b><?php 			 
					if($datedform != '' && $datedto != '' ){echo 'Date :  '. $dated2; echo ' - '.$dated1;}
					else{echo 'Date : all' ;}?></b></th>
				<th scope="col" colspan="3"><b><?php echo 'Branch Name : Bandra';?></b></th> 
			</tr>
			<tr>
                <th scope="col" style="width:40px;"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Company Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Institution Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investment Amount') ?></th>
                <th scope="col"><?= $this->Paginator->sort('No of clients') ?></th>       
            </tr>
        </thead>
        <tbody>
			<?php $j=1; $total=0; $tc=0;
				foreach($result['bandra'] as $key=>$res): ?>
                    <?php  foreach($res as $index =>$fd_res): ?>
                        <tr>
                            <td><?=$j ?></td>
                            <td><?php echo !empty($filenames[$fd_res['csvid']]) ? $filenames[$fd_res['csvid']]:'';?></td>
                            <td><?php echo !empty($this->request->query['institution_name']) && $this->request->query['institution_name'] !='all'  ? $this->request->query['institution_name'] : 'All'?></td>
                            <td class="amtrgt"><?php if($fd_res['tamount']){echo $fd_res['tamount'];}else{echo 0;}?></td>
                            <td>
                                <?php
                                if($fd_res['cnumber'] > 0){ ?>
                                    <?php echo $this->Html->link($fd_res['cnumber'] , ['controller' => 'Fds','action' => 'fdmaturity', '?' =>
                                        [ 'fname'=>$fd_res['csvid'],
                                            'institution_name' => !empty($this->request->query['institution_name']) ? $this->request->query['institution_name'] :'',
                                            'datedform'=>!empty($this->request->query['datedform']) ? $this->request->query['datedform'] :'',
                                            'datedto'=>!empty($this->request->query['datedto']) ? $this->request->query['datedto'] :''
                                        ]
                                    ], ['class' => '','title'=>__('View Clients')]) ?>
                                <?php }else{
                                    echo $fd_res['cnumber'];
                                }?>
                            </td>
                        </tr>
                        <?php $j++; $total += $fd_res['tamount']; $tc +=$fd_res['0']['cnumber'];

                    endforeach;
                endforeach;?>
				<tr class="total">
					<td colspan="3" style="text-align:right"><b>Grand Total</b></td>
					<td class="amtrgt"><b><?= number_format($total,2) ?></b></td>
					<td><b><?= $tc ?><b></td> 
				</tr> 
        </tbody>
		
    </table>
	
	<table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
			<tr>
				<th scope="col" colspan="2"><b><div style="clear: both;">
				<?php //if($company != '' && $company != 'all'){echo 'Product: '. $data[0]->company; }else {echo 'Product';} ?>
				<?php if($company != '' && $company != 'all'){$filenameid = $filename->find()->where(['id' => $company]);$filenamebr = $filenameid->toArray();echo 'Company Name: '. $filenamebr[0]->fname; }else {echo 'Company Name:';} ?>
					</div></th>			  
				<th scope="col" colspan="1"><b><?php 			 
					if($datedform != '' && $datedto != '' ){echo 'Date :  '. $dated2; echo ' - '.$dated1;}
					else{echo 'Date : all' ;}?></b></th>
				<th scope="col" colspan="3"><b><?php echo 'Branch Name : Fort';?></b></th> 
			</tr>
			<tr>
                <th scope="col" style="width:40px;"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Company Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Institution Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investment Amount') ?></th>
                <th scope="col"><?= $this->Paginator->sort('No of clients') ?></th>       
            </tr>
        </thead>
        <tbody>
			<?php $j=1; $total=0; $tc=0;
				foreach($result['fort'] as $key=>$res): ?>
                    <?php  foreach($res as $index =>$fd_res): ?>
                        <tr>
                            <td><?=$j ?></td>
                            <td><?php echo !empty($filenames[$fd_res['csvid']]) ? $filenames[$fd_res['csvid']]:'';?></td>
                            <td><?php echo !empty($this->request->query['institution_name']) && $this->request->query['institution_name'] !='all'  ? $this->request->query['institution_name'] : 'All'?></td>
                            <td class="amtrgt"><?php if($fd_res['tamount']){echo $fd_res['tamount'];}else{echo 0;}?></td>
                            <td>
                                <?php
                                if($fd_res['cnumber'] > 0){ ?>
                                    <?php echo $this->Html->link($fd_res['cnumber'] , ['controller' => 'Fds','action' => 'fdmaturity', '?' =>
                                        [ 'fname'=>$fd_res['csvid'],
                                            'institution_name' => !empty($this->request->query['institution_name']) ? $this->request->query['institution_name'] :'',
                                            'datedform'=>!empty($this->request->query['datedform']) ? $this->request->query['datedform'] :'',
                                            'datedto'=>!empty($this->request->query['datedto']) ? $this->request->query['datedto'] :''
                                        ]
                                    ], ['class' => '','title'=>__('View Clients')]) ?>
                                <?php }else{
                                    echo $fd_res['cnumber'];
                                }?>
                            </td>
                        </tr>
                        <?php $j++; $total += $fd_res['tamount']; $tc +=$fd_res['0']['cnumber'];

                    endforeach;
                endforeach;?>
				<tr class="total">
					<td colspan="3" style="text-align:right"><b>Grand Total</b></td>
					<td class="amtrgt"><b><?= number_format($total,2) ?></b></td>
					<td><b><?= $tc ?><b></td> 
				</tr> 
        </tbody>
    </table>
	 <?php endif; ?>
</div>
   
 <script>
    function print_function(){
       window.print();
    }
</script>