<?php  use Cake\ORM\TableRegistry;
    $bproducts = TableRegistry::get('Branches'); 
    $uproducts = TableRegistry::get('Users');
    $brproducts = TableRegistry::get('Brokers'); 
    //$filenames = TableRegistry::get('filenames');
?>
<?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">
    <?php
    $export = array_merge($this->request->query,array('export' => 'xls'));
    ?>
    <div class="btn-link col-md-6">
        <?=$this->Html->link(__('Excel Export'), ['controller' => 'Fds', 'action' => 'fdimportexceldata','?'=>$export], ['class' => 'green-btn']);?></div>
<div class="col-md-6">
    <!--<h3><?= __('Verify Uploaded FD Data') ?></h3>-->
    <h3><?= __('Raw 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 scope="col" colspan="4"><b>
              
              <div style="clear: both;">Raw Uploaded FD Data</div>
</th>             
<th scope="col" colspan="2"><b>
                  
              <?php 
              if($keyword != '')
              {
                
                echo 'Keyword :'.$keyword;
              }
              else{
              echo 'Keyword : all' ;
              }
              
              ?></b>
              </th>
              <th scope="col" colspan="2"><b>
              
             
              
              <?php 
             
                 if($companyname != ''){
                           echo 'Company Name :'.$companyname;
                           }
                           else{
                    echo 'Company Name : all';
                 }
                  ?></b></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>
                                 
                  </tr>
            <tr>
                <th style="width:40px;" scope="col"><?= $this->Paginator->sort('Sr No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investor Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Pan No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investment Amount') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Mobile No') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Investment Date') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Tenure') ?></th>
			    <th scope="col"><?= $this->Paginator->sort('Maturity Date') ?></th>
				<th scope="col"><?= $this->Paginator->sort('Institution Name') ?></th>
                <th scope="col"><?= $this->Paginator->sort('Company Name') ?></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) ?>-->
                    <?php
                    $rowid = $mdata->id;
                    $pannofieldidedit = $rowid.'___pan_no___edittext';
                    $pannofieldid = $rowid.'___pan_no';
                    $pannovalue = '';
                    $panvaluetext = $rowid.'___pan_no___valuetext';
                    $pannofieldideditsubbutton = $rowid.'___pan_no___textfieldeditsubbutton';
                    if(!empty($mdata->pan_no)){
                        $pannovalue = $mdata->pan_no;
                    }
                    echo "<span id='$panvaluetext'>".$pannovalue."</span>"."<input class='edittextfield' type='text'  value='".$pannovalue."' id='".$pannofieldidedit."'  maxlength='10' style='display:none'/><a class='edit editbutton' id='".$pannofieldid."' title='Edit'></a><a class='green-btn submitedittextfieldbutton' id = '".$pannofieldideditsubbutton."' href='javascript:void(0)' style='display:none;'>Update</a>"; ?>
                    
                </td>
                <td><?= h($mdata->investment_amount) ?></td>
                <td><?= h($mdata->mobileno) ?></td>
                <td><?= h($mdata->application_date) ?></td>
                <td><?= h($mdata->period) ?></td>
				<td><?= h($mdata->maturity_date) ?></td>
				<td>
				    <?php
                    /*$defaultInstitutionCompany = array(3,17,19);
                    if(in_array(h($mdata->csvid),$defaultInstitutionCompany)){
                        echo $filenames[h($mdata->csvid)];
                    }else {
                        echo h($mdata->institution_name);
                    }*/
                    echo h($mdata->institution_name);
                    ?>
				</td>
				<!--<td><?php //$FormatName = $filenames->find()->where(['id' => $mdata->csvid])->first()->toArray(); echo $FormatName['fname']; ?></td>-->
				<td><?= $filenames[h($mdata->csvid)] ?></td>
				<td class="actions">
                    <!--<?= $this->Html->link(__('Edit'), ['action' => 'fdedit', $mdata->id], ['class' => 'edit','title'=>__('Edit')]) ?>-->
                    <?= $this->Html->link(__('View'), ['action' => 'fdview', $mdata->id], ['class' => 'view','title'=>__('View')]) ?>
                </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() {
    
    
    /*---------Quick Edit---------*/
    $('.editbutton').click(function() {
        //alert('test');
        var idname = $(this).attr('id');
        var idspec = '#' + idname + '___edittext';
        $(idspec).fadeToggle();

        var idbuttonspec = '#' + idname + '___textfieldeditsubbutton';
        $(idbuttonspec).fadeToggle();
    });

    $(".submitedittextfieldbutton").click(function() {
        var inputfieldid = $(this).attr('id');

        var res = inputfieldid.split("___");
        var rowid = res[0];
        var fieldname =  res[1];
        var idinputspec = '#'+rowid+'___'+fieldname+'___edittext';
        var valueofinput = $(idinputspec).val();
        var idspanspec = '#'+rowid+'___'+fieldname+'___valuetext';
        var siteUrl = '<?php echo $this->Url->build('/', true) ?>';
        if(valueofinput==''){
            alert('Please enter value first!');
            return false;
        }
        if(fieldname == 'pan_no' && valueofinput.length!=10){
            alert('Please enter correct Pan No');
            return false;
        }
        jQuery.ajax({
            type: 'POST',
            url: siteUrl+'fds/updatefielddata',
            data: {
                rowid: rowid,
                fieldname: fieldname,
                valueofinput: valueofinput
            },
            success: function(data) { //console.log(data);
                //alert('Data Updated');
                //window.location.reload()
                $(idinputspec).fadeToggle();
                $('#'+inputfieldid).fadeToggle();
                $(idspanspec).html(valueofinput);
            },
            error: function(jqxhr, status, exception) {
                alert('Exception:', status);
            },
            statusCode: {
                404: function() {
                    alert(message.noPage);
                }
            }
        });
    });

    /*---------Quick Edit End---------*/
    
    $('.cbranch').change(function() {
    //$('.bupdate').click(function() {
        var rid = this.id;
        var bid = $(this).val();
        var userid = <?=$userid?>;
        //alert(rid);
        //alert(bid);
        //alert(userid);
        var siteUrl = window.location.host;
        jQuery.ajax({
            type: 'POST',
            url:'/fds/updatebranch',
            //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);
                }
            }
        });
    });
    
     $("form").submit(function() {
        // e.preventDefault();

        if (($('#datedform').val() && $('#datedto').val()) && ($('#inv-datedform').val() && $(
                '#inv-datedto').val())) {
            alert("Please Select Maturity or Investment  Date");
            return false;
        }

        if ($('#datedform').val()) {
            if ($('#datedto').val() == '') {
                alert("Please choose End date for report");
                return false;
            }
        }

        if ($('#inv-datedform').val()) {
            if ($('#inv-datedto').val() == '') {
                alert("Please choose End date for report");
                return false;
            }
        }
    });
});
</script>


