<?php  use Cake\ORM\TableRegistry;
$user1 = $this->request->session()->read('Auth.User');
$user  = TableRegistry::get('Users');
$banks = TableRegistry::get('Banks');
//$filename  = TableRegistry::get('Filenames');
$companies = TableRegistry::get('Companies');
$branches = TableRegistry::get('Branches');
$scheme = TableRegistry::get('Mffunds');
$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;
        }

    </STYLE>
<?php if(!empty($result)): ?>
    <table>
        <thead>

        <tr>
            <th class="tableTd" style="width:10%;">CLIENT NAME </th><th class="tableTd" style="text-align: left;"><span style="font-weight:normal">
								<?php if($customer_name != '' && $customer_name != 'all'){
                                    echo $customer_name; }else {
                                    echo '';} ?>
								</span></th>
        </tr>
        <tr>
            <th class="tableTd" style="width:10%;">PAN NO</th>
            <th class="tableTd" style="font-weight: normal; text-align: left;">
                <?php if($applicant_pan != '' && $applicant_pan != 'all'){
                    echo $applicant_pan; }
                else {
                    echo '';} ?>
            </th>
        </tr>
        <tr>
            <th class="tableTd" style="width:10%;">ADDRESS</th>
            <th class="tableTd" style="font-weight: normal;text-align: left;">
                <?php if($applicant_pan != '' && $applicant_pan != 'all'){
                    $applicant_pan_no = $mtables->find()->where(['pan_no' => $applicant_pan]);
                    $applicantbr = $applicant_pan_no->toArray();
                    $address_combined = !empty($applicantbr[0]->address) ? $applicantbr[0]->address.', ': '';
                    if(!empty($applicantbr[0]->add1)){
                        $address_combined .= ' '. $applicantbr[0]->add1;
                    }
                    if(!empty($applicantbr[0]->add2)){
                        $address_combined .= ', '. $applicantbr[0]->add2;
                    }
                    if(!empty($applicantbr[0]->add3)){
                        $address_combined .= ', '. $applicantbr[0]->add3;
                    }

                    if(!empty($applicantbr[0]->city)){
                        $address_combined .= ', '. $applicantbr[0]->city;
                    }

                    if(!empty($applicantbr[0]->region)){
                        $address_combined .= ', '. $applicantbr[0]->region;
                    }

                    if(!empty($applicantbr[0]->pin)){
                        $address_combined .= ', '. $applicantbr[0]->pin;
                    }
                    echo  $address_combined; }else {
                    echo '';} ?>
            </th>
        </tr>
        <tr>
            <th class="tableTd" style="width:10%;">MOBILE NO</th>
            <th class="tableTd" style="font-weight: normal;text-align: left;">
                <?php
                echo $applicantbr[0]->mobileno;?>
            </th>
        </tr>
        </thead>
    </table>

    <div class="">

        <div class="">
            <h7><?= __('PORTFOLIO AS ON ').date('d/m/Y'); ?></h7>
        </div>
    </div><br>

    <table>
        <thead>
        <tr>
            <th class="tableTd" style="width:3%;">Sr No</th>
            <!--<th class="tableTd">Company Name</th>-->
            <th class="tableTd">Institution Name</th>
            <th class="tableTd" style="width:10%;">Instrument Type</th>
            <th class="tableTd">Investment Date</th>
            <th class="tableTd">Investment Amount</th>
            <th class="tableTd">Tenure</th>
            <th class="tableTd">Maturity Date</th>
            <th class="tableTd">Investor Remark</th>
        </tr>
        </thead>
        <tbody>
        <?php $j=1; $total=0; $tc=0;
        foreach($result['fd'] as $key=>$res): ?>
            <tr>
                <td class="tableTdContent"><?=$j ?></td>
                <!--<td class="tableTdContent"><?php echo $filenames[$res['csvid']];?></td>-->
                <td class="tableTdContent">
                    <?php echo $res['institution_name']; ?>

                </td>
                <td class="tableTdContent" style="width:10%;"><?php echo wordwrap($res['instrument_type'], 8, "<br />\n"); ?></td>

                <td class="tableTdContent"><?php echo $res['application_date']; ?></td>
                <td class="tableTdContent"><?php echo $res['investment_amount'];?></td>
                <td class="tableTdContent"><?php echo $res['period'];?></td>
                <td class="tableTdContent"><?php echo $res['maturity_date'];?></td>
                <td class="tableTdContent"><?php echo $res['remark'];?></td>
            </tr>
            <?php $j++; endforeach;?>
        </tbody>

    </table>



<?php endif; ?>