<?php  use Cake\ORM\TableRegistry;
    $companies = TableRegistry::get('Companies');
    $branches = TableRegistry::get('Branches');
    $brokers = TableRegistry::get('Brokers');
    $users = TableRegistry::get('Users');
    $mtables = TableRegistry::get('Mtables');   
?>

<STYLE type="text/css">
    .tableTd {
        border-width: 0.5pt;
        border: 0.5px solid;
    }
    .tableTdContent{
        border-width: 0.5pt;
        border: 0.5px solid;
    }
    #titles{
        font-weight: bolder;
        background-color:#ccc;
    }

    table {
        border-spacing:0;
        border-collapse: collapse;
    }

    table th,table td {
        font-size: 10px;
    }




</STYLE>

<div class="">
    <h3><?= __('Fixed Deposit Entry Done') ?></h3>
    <table cellpadding="0" cellspacing="0" style="width: 100%;">
        <thead>
            <tr>
               <th class="tableTd" style="width:40px;" scope="col">Sr No</th>
                <th class="tableTd" scope="col">Applicant Name</th>
                <th class="tableTd" scope="col">Pan No</th>
                <th class="tableTd" scope="col">Referred By</th>
                <th class="tableTd" scope="col">Email</th>
                <th class="tableTd" scope="col">Deposit type</th>
                <th class="tableTd" scope="col">Cheque No / FDR no</th>
                <th class="tableTd" scope="col">amount</th>
                <th class="tableTd" scope="col">period months</th>
                <th class="tableTd" scope="col">Branch</th>
                <th class="tableTd" scope="col">company</th>
                <th class="tableTd" scope="col">created</th>
                <th class="tableTd" scope="col">Created By</th>
               
            </tr>
        </thead>
        <tbody>
            <?php
                $srlno = 0;
             //$srlno = ($this->request->params['paging']['Fds']['page']-1) * $this->request->params['paging']['Fds']['perPage'];
             $i=1;$total='';
            foreach ($fds as $fd): $srlno++; ?><?php //print_r($fd);die();?>
            <tr>
                <td class="tableTdContent"><?php echo $srlno; ?></td>
                <td class="tableTdContent"><?php if($fd->minor == 1) {
                             echo  $fd->minorname.'&nbsp;&nbsp;U/G&nbsp;&nbsp;'.$fd->fapplicantname;
                          }else{
                              echo  $fd->fapplicantname;
                          } ?></td>
               
                <td class="tableTdContent"><?php echo($fd->panno) ?></td>
             <td class="tableTdContent"><?php if($fd->subbroker_id > 0){
                        $subbroker = $brokers->find()->where(['id' => $fd->subbroker_id]);
                        $sbdata = $subbroker->toArray();
                        if($sbdata){
                            echo $subbroker = $sbdata[0]->name;
                         }
                     } ?>
            </td>
             <td class="tableTdContent"><?= h($fd->email) ?></td>
              
                <td class="tableTdContent"><?php 
                if($fd->typeofdeposit == 'onlinerenewal'){
                    echo 'online renewal';
                }else{
                    echo $fd->typeofdeposit ;
                } ?></td>

                <td class="tableTdContent"><?php 
                if($fd->typeofdeposit == 'fresh' || $fd->typeofdeposit == 'onlinefresh' ){
                    echo ($fd->chequeno);
                }elseif($fd->typeofdeposit == 'renewal' || $fd->typeofdeposit == 'onlinerenewal'){
                    echo ($fd->fdrno);
                }else{
                    echo ($fd->chequeno).' / '. ($fd->fdrno);
                } ?></td>

                <!-- <td><?= h($fd->amount) ?></td> -->

                <td class="tableTdContent">
                    <?php 
                    $amt=h($fd->amount);
                    $fdramt=h($fd->fdramount);
                    $totalamt=$amt+$fdramt;
                    echo $totalamt; ?>
                </td>

                <td class="tableTdContent"><?php if($fd->tenure == 0){echo '';} else{echo $fd->tenure;} ?></td>
                <td class="tableTdContent"> <?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 class="tableTdContent">
                        <?php if($fd->productcompanyid > 0) {
                    $productcompanyid = $companies->find()->where(['id' => $fd->productcompanyid]);
                    $data1 = $productcompanyid->toArray();
                    $productcompanyName = $data1[0]->company;
                    }
                    else{
                    $productcompanyName = '';
                    }?>
                    <?=$productcompanyName?>
                </td>
            <td class="tableTdContent"><?php $created = explode(" ", $fd->created);
                    echo $created[0];
                    ?>
            </td>
             <td class="tableTdContent"><?php if($fd->postedby > 0){
                        $posteddata = $users->find()->where(['id' => $fd->postedby]);
                        $data = $posteddata->toArray();
                        if($data){
                            echo $data[0]->username;
                         }
                     } ?>
              </td>
                
            </tr>
            <?php //$total += $fd->amount; 
                $total += $fd->amount + (isset($fd->fdramount) ? $fd->fdramount : 0);
                $i++; endforeach; ?>
            <tr class="total">
                <td class="tableTdContent" colspan="7" style="text-align:right"><b>Sub Total</b></td>
                <td class="tableTdContent"><b><?= $total ?></b></td> 
                <td class="tableTdContent" colspan="6"></td> 
            </tr> 
            <?php  //if($this->request->params['paging']['Fds']['pageCount'] == $this->request->params['paging']['Fds']['page']){?>
            <tr class="total">
                <td class="tableTdContent" colspan="7" style="text-align:right"><b>Grand Total</b></td>
                <td class="tableTdContent"><b><?= $total_amount ?></b></td> 
                <td class="tableTdContent" colspan="6"></td> 
            </tr> 
            <?php //} ?>
        </tbody>
    </table>

</div>
