<?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');  
?>
<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="btn-link col-md-6">
        <?=$this->Html->link(__('Excel Export'), ['controller' => 'Fds', 'action' => 'fdimportexceldata'], ['class' => 'green-btn']);?></div>
<div class="col-md-6">
    <h3><?= __('Verify Uploaded FD Data') ?></h3>
    </div>
<!--<div class="btn-link col-md-6">
        <?= $this->Html->link(__('Excel Export'),['controller' => 'Fds', 'action' => 'fdexceldata'],['class'=>'green-btn']); ?></div>-->
<div class="col-md-12">
    <div class="search-wrapper">
        <div class="search-filter"><?= $this->Search->filterForm($searchFilters) ?></div>         
    </div>
</div>
    <table cellpadding="0" cellspacing="0">
        <thead>
            <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('Principle Investment') ?></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('Change Branch')?></th>
				<th scope="col"><?= $this->Paginator->sort('Action') ?></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++; ?>
            <tr>
                <td><?= $srlno ?></td>
                <td><?= h($mdata->customer_name) ?></td>
                <td><?= h($mdata->pan_no) ?></td>
                <td><?= h($mdata->application_date) ?></td>
				<td><?= h($mdata->payment_mode) ?></td>
				<td><?= h($mdata->cheque_no) ?></td>
				<td><?= h($mdata->utr_fdr_no) ?></td>
				<td><?= h($mdata->principle_investment) ?></td>
				<td><?= h($mdata->period) ?></td>
				<td><?= h($mdata->maturity_date) ?></td>
				<td><?= h($mdata->address) ?> <?= h($mdata->add1) ?> <?= h($mdata->add2) ?> <?= h($mdata->add3) ?></td>
				<td><?= h($mdata->product_name) ?></td>
				<td><?= 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>
				    <?= $this->Form->create() ?>
                    <?=$this->Form->input('Branch', ['class'=>'cbranch','id'=>$mdata->id, 'label' => false ,'empty' => 'Branch', 'options' => $branches]);?>
                    <?= $this->Form->end() ?>
                </td>
				<td class="actions">
                    <?= $this->Html->link(__('Edit'), ['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>


<script>
$(document).ready(function() {
    $('.cbranch').change(function() {
    //$('.bupdate').click(function() {
        var rid = this.id;
        var bid = $(this).val();
        var userid = <?=$userid?>;
        var siteUrl = window.location.host;
        jQuery.ajax({
            type: 'POST',
            url:'/fds/updatebranch',
            beforeSend: function(xhr) {
                    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            },
            //async: true,
            //cache: false,
            data: {
                bid: bid,
                rid: rid,
                userid: userid
            },
            dataType: 'json',
            success: function(data) {
                alert('Branch Updated');
            },
            error: function(jqxhr, status, exception) {
                alert('Exception:', status);
            },
            statusCode: {
                404: function() {
                    alert(message.noPage);
                }
            }
        });
    });
});
</script>


