<?php
/*
 * Author       : Jai K
 * Purpose      : View for Print Format 6 (Common purposes)
 * Created On   : 2016-09-22 18:14
 */

$amount = is_array($amount) ? $amount[0] : $amount;
?>
<tr>
    <?php
    $k = 0;
    if (count($data['fields']) > 0) {
        foreach ($data['fields'] as $label => $value) :
            if ($label == "Type") {
                ?>
                <td colspan="3"><?php echo $value; ?> </td>
            <?php } else {
                ?>
                <td width="18%" class="lbl" style="font-size: 20px;"><?php echo $label; ?></td>
                <td width="1%">:</td>
                <td width="36%" style="<?php echo!IS_SHORT ? 'border-bottom:2px dotted #000;' : ''; ?> font-size: 17px;"><?php
                    if (is_array($value)) {
                        $cn = count($value);
                        $ic = 0;
                        foreach ($value as $nam) {
                            echo $nam;
                            $ic++;
                            if ($ic < $cn) {
                                echo "-";
                            }
                        }
                    } else {
                        echo $value;
                    }
                    ?></td>
                <td width="1%">&nbsp;</td>
                <?php
            }
            echo ++$k % 2 == 0 || IS_SHORT ? '</tr>' : '';

        endforeach;
    }
    ?>
</tr>
</table>
</td>
</tr>
</table>

<?php
if (!empty($data['tables'])) :
    $tables = !empty($data['tables']['head']) ? array($data['tables']) : $data['tables'];
    #echo '<pre>';print_r($tables);
    foreach ($tables as $k => $table) :
        ?>
        <div class="auto-adj" style="width: 100%; min-height: 10px;">&nbsp;</div>
        <table width="<?php echo WIDTH; ?>" id="tdhgt" height="100%" border="1" style="border-collapse:collapse; margin-top: 10px 0px;" cellpadding="5" <?php echo $table['attr']; ?> >
            <tr>
                <?php
                unset($table['attr']);

                $sno = $table['head']['sno'];
                unset($table['head']['sno']);
                if (!(empty($sno)) && !$sno) :
                    ?>
                    <th>S.No</th>
                    <?php
                endif;

                $attr = $table['head']['attr'];
                unset($table['head']['attr']);
                foreach ($table['head'] as $h => $th) :
                    ?>
                    <?php if (!empty($th)) { ?>
                        <th style="font-size: 20px;" <?php echo $attr; ?>><?php echo $th; ?></th>
                    <?php } ?>
                <?php endforeach; ?>
            </tr>

            <?php
            if (count($table['body']) > 0) {
                foreach ($table['body'] as $b => $row) :
                    //$row = explode(',', $row);
                    //echo "<pre>Data: "; print_r($row[0]); die;
                    ?>
                    <tr class="tbl-row">
                        <?php if (!(empty($sno)) && !$sno) : ?>
                            <td style="font-size: 20px;" align="center"><?php echo ++$b; ?></td>
                        <?php endif; ?>
                        <?php
                        $length = count($row);
                        foreach ($row as $t => $td) :
                            if (!empty($td) || $td == 0) {
                                if (!IS_KSK_CMS) {
                                    if ($length == ($t + 1)) :
                                        $align = "align=right";
                                    else :
                                        $align = "align=left";
                                    endif;
                                } else {
                                    if (empty($sno) && $sno) {
                                        if ((($length - 1 ) == ($t + 1)) || (($length - 2 ) == ($t + 1)) || (($length ) == ($t + 1))) {
                                            $align = "align=right";
                                        } elseif ((($length - 3 ) == ($t + 1)) || (($length - 4 ) == ($t + 1))) {
                                            $align = "align=center";
                                        } else {
                                            $align = "align=left";
                                        }
                                    } else {
                                        $align = "align=left";
                                    }
                                }
                                ?><td style="font-size: 20px;" <?php echo $align; ?>><?php echo $td; ?></td><?php
                            }
                        endforeach;
                        ?>
                    </tr>
                    <?php
                endforeach;
            } else {
                ?>
                <tr>
                    <td colspan="<?php echo (count($table['head']) + 1); ?>"><center>No Records Found!</center></td>
            </tr>
        <?php } ?>

        </table>
        <div class="auto-adj" style="width: 100%; min-height: 10px;">&nbsp;</div>

        <?php
    endforeach;
endif;
?>

<?php
if (!empty($data['tablesub'])) :
    $tablesub = !empty($data['tablesub']['head']) ? array($data['tablesub']) : $data['tablesub'];

    foreach ($tablesub as $k => $table) :
        ?>
        <div class="auto-adj" style="width: 100%; min-height: 10px;">&nbsp;</div>
        <table width="<?php echo WIDTH; ?>" id="tdhgt" height="100%" border="1" style="border-collapse:collapse; margin-top: 10px 0px; page-break-before: always;" cellpadding="5" <?php echo $table['attr']; ?> >
           
<tr>
         <td align="center" colspan="25" style="font-weight:bold; font-size:18px;"><?php echo $title; ?></td>
         </tr>

		   <tr>
                <?php
                unset($table['attr']);

                $sno = $table['head']['sno'];
                unset($table['head']['sno']);
                if (!(empty($sno)) && !$sno) :
                    ?>
                    <th>S.No</th>
                    <?php
                endif;

                $attr = $table['head']['attr'];
                unset($table['head']['attr']);
                foreach ($table['head'] as $h => $th) :
                    ?>
                    <?php if (!empty($th)) { ?>
                        <th style="font-size: 20px;" <?php echo $attr; ?>><?php echo $th; ?></th>
                    <?php } ?>
                <?php endforeach; ?>
            </tr>

            <?php
            if (count($table['body']) > 0) {
                foreach ($table['body'] as $b => $row) :
                    //$row = explode(',', $row);
                    //echo "<pre>Data: "; print_r($row[0]); die;
                    ?>
                    <tr class="tbl-row">
                        <?php if (!(empty($sno)) && !$sno) : ?>
                            <td style="font-size: 20px;" align="center"><?php echo ++$b; ?></td>
                        <?php endif; ?>
                        <?php
                        $length = count($row);
                        foreach ($row as $t => $td) :
                            if (!empty($td) || $td == 0) {
                                if (!IS_KSK_CMS) {
                                    if ($length == ($t + 1)) :
                                        $align = "align=right";
                                    else :
                                        $align = "align=left";
                                    endif;
                                } else {
                                    if (empty($sno) && $sno) {
                                        if ((($length - 1 ) == ($t + 1)) || (($length - 2 ) == ($t + 1)) || (($length ) == ($t + 1))) {
                                            $align = "align=right";
                                        } elseif ((($length - 3 ) == ($t + 1)) || (($length - 4 ) == ($t + 1))) {
                                            $align = "align=center";
                                        } else {
                                            $align = "align=left";
                                        }
                                    } else {
                                        $align = "align=left";
                                    }
                                }
                                ?><td style="font-size: 20px;" <?php echo $align; ?>><?php echo $td; ?></td><?php
                            }
                        endforeach;
                        ?>
                    </tr>
                    <?php
                endforeach;
            } else {
                ?>
                <tr>
                    <td colspan="<?php echo (count($table['head']) + 1); ?>"><center>No Records Found!</center></td>
            </tr>
        <?php } ?>

        </table>
        <div class="auto-adj" style="width: 100%; min-height: 10px;">&nbsp;</div>

        <?php
    endforeach;
endif;
?>

<?php
if (!empty($data['sub_tables'])) :
    $sub_tables = !empty($data['sub_tables']['head']) ? array($data['sub_tables']) : $data['sub_tables'];

    foreach ($sub_tables as $k => $table) :
        ?>
        <div class="auto-adj" id="subtable" style="width: 100%;">&nbsp;</div>
        <table width="50%" border="1" id="subhht" style="border-collapse:collapse; margin: 0px 0px;" cellpadding="5" align="right">
            <?php
            foreach ($table['body'] as $b => $row) :
                //$row = explode(',', $row);
                //echo "<pre>Data: "; print_r($row[0]); die;
                ?>
                <tr>
                    <?php
                    $length = count($row);
                    foreach ($row as $t => $td) :
                        if ($length == ($t + 1)) :
                            $align = "align=right";
                        else :
                            $align = "align=left";
                        endif;
                        ?><td style="font-size: 20px;" <?php echo $align; ?>><?php echo $td; ?></td><?php
                    endforeach;
                    ?>
                </tr>
            <?php endforeach; ?>
        </table>
        <?php
    endforeach;
endif;
?>


<table width="<?php echo WIDTH; ?>">
    <tr>
        <td>
            <table border="0" width="100%" cellpadding="5">
                <?php if (!empty($amount)) : ?>
                    <tr>
                        <td colspan="2" style="font-weight:bold; font-size: 20px;">S$ <?php echo number_format($amount, 2, '.', ''); ?>/- <?php echo ($gst == 1 ? '(Inclusive of GST)' : '') . $pay_mode_str; ?></td>
                    </tr>
                    <tr height="5" class="no-copy"></tr>
                    <tr>
                        <td style="font-weight:bold; font-size: 20px;" width="20%">Amount in Words (S$):</td>
                        <td width="80%"><?php echo convert_amount_to_word($amount); ?></td>
                    </tr>
                    <tr height="5" class="no-copy"></tr>
                <?php endif; ?>

