<?php  use Cake\ORM\TableRegistry;
    $bproducts = TableRegistry::get('Branches'); 
    $uproducts = TableRegistry::get('Users');
    $brproducts = TableRegistry::get('Brokers');  	
?>

<?php  //use Cake\ORM\TableRegistry;
    //$products = TableRegistry::get('Filenames');  
$fcustomername = !empty($this->request->query['customer_name']) ? $this->request->query['customer_name'] : 'all'; 
$fcompanyname = !empty($this->request->query['fname']) ? $this->request->query['fname'] : 'all';
$fdatedform = !empty($this->request->query['datedform']) ? $this->request->query['datedform'] : 'all';
$fdatedto = !empty($this->request->query['datedto']) ? $this->request->query['datedto'] : 'all';
if(!empty($fdatedform) && $fdatedform != 'all'){ $fdatedform = date("Y-m-d", strtotime($fdatedform)); }
if(!empty($fdatedto) && $fdatedto != 'all'){ $fdatedto = date("Y-m-d", strtotime($fdatedto)); }
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
      <?= $this->element('admin_sidebar') ?>
</nav>
<div class="customers index large-9 medium-8 columns content">
<div class="col-md-6">
    <h3><?= __('Client Fixed Deposit Portfolio') ?></h3>
    </div>

    <div class="search-wrapper">
<div class="col-md-6">
        <div class="btn-link">
        <?= $this->Html->link(__('Excel Export'),['controller' => 'Reports', 'action' => 'fdportfolioexceldata',$fcustomername,$fcompanyname,$fdatedform,$fdatedto],['class'=>'green-btn']); ?></div> </div>
        <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>         
   
</div>
    <table cellpadding="0" cellspacing="0">
        <thead>
		<tr>
		<th scope="col" colspan="4"><b>
			  
			  <div style="clear: both;">Report: Client Fixed Deposit Portfolio</div>
</th>			  
<th scope="col" colspan="4"><b>
			  	  
			  <?php 
			  if($customer_name != '')
			  {
				
				echo 'Applicant Name :'.$customer_name;
			  }
			  else{
			  echo 'Applicant Name : all' ;
			  }
			  
			  ?></b>
			  </th>
			  <th scope="col" colspan="3"><b>
			  <?php 
			 
                 if($companyname != ''){
                           echo 'Company Name :'.$companyname;
						   }
						   else{
                    echo 'Company Name : all';
                 }
                  ?></b></th>
              <th scope="col" colspan="4"><b>
			  <?php 
			 
                 if($datedform != '' && $datedto != '' ){
                             echo 'Date :  '.$dated2;
						   echo ' - '.$dated1; 
                          // echo 'Date :  '. $datedform;
						   //echo ' - '.$datedto;     
						   }
						   else{
                     echo 'Date : all' ;
                 }
                  ?></b></th>
				  				 
				  </tr>
		
            <tr>
                <th style="width:40px;" scope="col"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Applicant Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Pan No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investment Date') ?></th>
			    <!--<th scope="col"><?= $this->Paginator->sort('Payment Mode') ?></th>-->
				<!--<th scope="col"><?= $this->Paginator->sort('Cheque No') ?></th>-->
				<th scope="col"><?= $this->Paginator->sort('UTR/FDR No') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Investment Amount') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Period') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Maturity Date') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Address') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Product name') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Company Name') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Investment Branch') ?></th>
				<!--<th scope="col"><?//= $this->Paginator->sort('Branch User') ?></th>-->
				<th scope="col"><?= $this->Paginator->sort('Sub Broker Name') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Actions') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php   $srlno = ($this->request->params['paging']['Mtables']['page']-1) * $this->request->params['paging']['Mtables']['perPage'];
            $j=1;
            foreach ($mdatas as $mdata): $srlno++; if(!$mdata->branch_id > 0){ $trstyl = "style='background:#dbefec;'";$tdstyl = "style='color:#000;'"; }else{$trstyl = "style='background:none;'";$tdstyl = "style='color:#000;'";} ?>
            <tr <?= $trstyl ?>>
                <td <?= $tdstyl ?>><?= $srlno ?></td>
                <td <?= $tdstyl ?>><?= h($mdata->customer_name) ?></td>
                <td <?= $tdstyl ?>><?= h($mdata->pan_no) ?></td>
                <td <?= $tdstyl ?>><?= h($mdata->application_date) ?></td>
				<!--<td <?= $tdstyl ?>><?= h($mdata->payment_mode) ?></td>-->
				<!--<td <?= $tdstyl ?>><?= h($mdata->cheque_no) ?></td>-->
				<td <?= $tdstyl ?>><?= h($mdata->utr_fdr_no) ?></td>
				<td <?= $tdstyl ?>><?= h($mdata->principle_investment) ?></td>
				<td <?= $tdstyl ?>><?= h($mdata->period) ?></td>
				<td <?= $tdstyl ?>><?= h($mdata->maturity_date) ?></td>
				<td <?= $tdstyl ?>><?= h($mdata->address) ?></td>
				<td <?= $tdstyl ?>><?= h($mdata->product_name) ?></td>
				<td <?= $tdstyl ?>><?= h($mdata->company_name) ?></td>
				<!--<td><?//= h($mdata->branch_id) ?></td>-->
			    <td>
		<?php
			if($mdata->branch_id > 0){
				
				$bproductids = explode(",",  $mdata["branch_id"]);
				foreach($bproductids as $bproductid){
				$bproductdata = $bproducts->find()->where(['id' => $bproductid]);
				$bdata2 = $bproductdata->toArray();
				echo $bproductname = $bdata2[0]->branchname;
				}
			}
		?>
	            </td>
				<!--<td>
				
				<?php
			if($mdata->modifiedby > 0){
				
				$uproductids = explode(",",  $mdata["modifiedby"]);
				foreach($uproductids as $uproductid){
				$uproductdata = $uproducts->find()->where(['id' => $uproductid]);
				$udata2 = $uproductdata->toArray();
				//echo $uproductname = $udata2[0]->firstname;
				}
			     }
		        ?>
				</td>-->
				
				<td>
				<?php
			if($mdata->sub_broker > 0){
				
				$brproductids = explode(",",  $mdata["sub_broker"]);
				foreach($brproductids as $brproductid){
				$brproductdata = $brproducts->find()->where(['id' => $brproductid]);
				$brdata2 = $brproductdata->toArray();
				echo $brproductname = $brdata2[0]->name;
				}
			     }
		        ?>
				</td>
				
				<td class="actions">
                    <?= $this->Html->link(__('Edit'), ['controller'=>'Fds','action' => 'fdedit', $mdata->id], ['class' => 'edit','title'=>__('Edit')]) ?>
                </td>
               </tr>
            <?php $j++;
            endforeach; ?>
        </tbody>
    </table>
<div class="btn-link"><input type="button" value="Back" onclick="window.history.back()" class="green-btn" /> </div>
    <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>
