<?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');
    $scheme = TableRegistry::get('Mffunds');
    $plans = TableRegistry::get('Plans');
?>
<?= $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%');
            }
        }); 
  });
</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><?= __('Client Portfolio 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"><?= $this->Search->filterForm($searchFilters) ?></div>         
    </div>

    <?php if(!empty($customer)){ ?>        
    <div class="search-wrapper">
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
    			<th scope="col" colspan="11"><b>			  
    			  <div style="clear: both;text-align: center;">Product: Mutual Funds </div></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('Company') ?></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('Period(months)') ?></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>
            </tr>
        </thead>
        <tbody>
            <?php $i=1; $total = '';
            foreach ($customer->mutualfunds as $mf): ?>
            <?php if($user1['group_id'] == '3'){ 
                    if($user1['branch_id'] == $mf->branch_id){
                        //Branch manager restriction
            ?>
            <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 
        				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->tenure) ?></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> 
            </tr>
             <?php
                $total += $mf->amount;
                $i++;
            }} //Branch manager restriction
            
            
           if($user1['group_id'] == '2'){ 
                        //Admin Permission
            ?>
            <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 
        				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->tenure) ?></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> 
            </tr>
             <?php
                $total += $mf->amount;
                $i++;
            } //Admin Permission
                
                endforeach; ?>
           <tr class="total">
                <td colspan="5" style="text-align:right"><b>Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="5"></td> 
            </tr> 
        </tbody>
    </table> 
<!-----------------------------------------------------------------------Fixed Deposit--------------------------------------------------------------------------------------->      
    <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
          <tr>
            <th scope="col" colspan="11"><b>
			  <div style="clear: both;text-align: center;">Product: Fixed Deposit </div>
            </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('Company') ?></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('Period(months)') ?></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>
            </tr>
        </thead>
        <tbody>
            <?php $i=1;$total=' ';
            foreach ($customer->fds as $fd): //pr($fd);?>
            
            <?php if($user1['group_id'] == '3'){ 
                    if($user1['branch_id'] == $fd->branch_id){
                        //Branch manager restriction
            ?>
            <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>
        		<?php
            		if($fd->plan_id > 0){
                		$plandata = $plans->find()->where(['id' => $fd->productcompanyid]);
                		$data2 = $plandata->toArray();
                		if($data2){
                		    echo $schemename = $data2[0]->scheme;
                		}
            		} 
        		?>
        		</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->tenure) ?></td>
                <td><?= h($fd->chequeno) ?></td>
                <td><?= h($fd->fdrno) ?></td>
                <td><?php
                    if($fd->typeofdeposit != 'renewal'){ 
                        if($fd->bank_id > 0){
                            $banksid = $banks->find()->where(['id' => $fd->bank_id]);
                            $data1 = $banksid->toArray();
                            echo  $banksName = $data1[0]->banks;
                        } 
                    }
                ?></td>
            </tr>
            <?php $total += $fd->amount;
              $i++;
            }} //Branch manager restriction
            
            
           if($user1['group_id'] == '2'){ 
                        //Admin Permission
            ?>  
            
            <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>
        		<?php
            		if($fd->plan_id > 0){
                		$plandata = $plans->find()->where(['id' => $fd->productcompanyid]);
                		$data2 = $plandata->toArray();
                		if($data2){
                		    echo $schemename = $data2[0]->scheme;
                		}
            		} 
        		?>
        		</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->tenure) ?></td>
                <td><?= h($fd->chequeno) ?></td>
                <td><?= h($fd->fdrno) ?></td>
                <td><?php
                    if($fd->typeofdeposit != 'renewal'){ 
                        if($fd->bank_id > 0){
                            $banksid = $banks->find()->where(['id' => $fd->bank_id]);
                            $data1 = $banksid->toArray();
                            echo  $banksName = $data1[0]->banks;
                        } 
                    }
                ?></td>
            </tr>
            <?php $total += $fd->amount;
              $i++;
           } //Admin Permission
            endforeach; ?>
            <tr class="total">
                <td colspan="5" style="text-align:right"><b>Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="5"></td> 
            </tr> 

        </tbody>
    </table>
<!-----------------------------------------------------------------------NCD--------------------------------------------------------------------------------------->    
     <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
              <tr>
                <th scope="col" colspan="11">
                   <div style="clear: both;text-align: center;">Product: NCDS </div>
                </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('Company') ?></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('Period(months)') ?></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>
            </tr>
        </thead>
        <tbody>
            <?php $i=1;$total = '';
            foreach ($customer->ncds as $ncd): //pr($ncd);?>
            <?php if($user1['group_id'] == '3'){ 
                    if($user1['branch_id'] == $ncd->branch_id){
                        //Branch manager restriction
            ?>
            <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><?php	if($ncd->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $ncd->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                <td><?= h($ncd->tenure) ?></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>
            </tr>
            <?php $total += $ncd->amount; $i++;
                    }} //Branch manager restriction
            
            
           if($user1['group_id'] == '2'){ 
                        //Admin Permission
            ?> 
            <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><?php	if($ncd->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $ncd->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                <td><?= h($ncd->tenure) ?></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>
            </tr>
            <?php $total += $ncd->amount; $i++;
                    } //Admin Permission
            endforeach; ?>
           <tr class="total">
                <td colspan="5" style="text-align:right"><b>Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="5"></td> 
            </tr> 
        </tbody>
    </table>
    
 <!-----------------------------------------------------------------------IPO--------------------------------------------------------------------------------------->    
     <table class="tbl-wrapper" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
             <th scope="col" colspan="11">
            <div style="clear: both;text-align:center">Product: IPO </div>
           </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('Company') ?></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('Period(months)') ?></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>
            </tr>
        </thead>
        <tbody>
            <?php $i=1;$total = '';
            foreach ($customer->ipos as $ipo): //pr($ipo);?>
            
            <?php if($user1['group_id'] == '3'){ 
                    if($user1['branch_id'] == $ipo->branch_id){
                        //Branch manager restriction
            ?>
            
            <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><?php	if($ipo->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $ipo->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                <td><?= h($ipo->tenure) ?></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> 
            </tr>
            <?php $total += $ipo->amount; $i++;
            
            }} //Branch manager restriction

           if($user1['group_id'] == '2'){ 
                        //Admin Permission
            ?> 
            
            <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><?php	if($ipo->branch_id > 0){
        				$branchdata = $branches->find()->where(['id' => $ipo->branch_id]);
        				$data = $branchdata->toArray();
        				if($data){
        					echo $branchdata = $data[0]->branchname;
        				 }
    			     } ?>
                 </td>
                <td><?= h($ipo->tenure) ?></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> 
            </tr>
            <?php $total += $ipo->amount; $i++;
                  } //Admin Permission
            endforeach; ?>
            <tr class="total">
                <td colspan="5" style="text-align:right"><b>Total</b></td>
                <td><b><?=$total?></b></td> 
                <td colspan="5"></td> 
            </tr> 
        </tbody>
    </table>
    
    
    
</div>
    <?php } ?>
 <script>
    function print_function(){
       window.print();
    }
</script>