<style>
#tdhgt2 th:first-child {
    width: 200px !important;
}
#tdhgt2 th:nth-child(2) {
    width: 100px !important;
}
#tdhgt2 td:nth-child(1), #tdhgt2 td:nth-child(2) {
    font-size: 16px !important;
    font-weight: 600;
}
</style>
<?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 ) :
                            
                ?>

                        <td width="18%" class="lbl" style="font-size: 17px;"><?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 echo $value; ?></td>
                        <td width="1%">&nbsp;</td>
                <?php 
                        echo ++$k % 2 == 0 || IS_SHORT ? '</tr><tr height="1"></tr><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 style="width: 100%; min-height: 5px;">&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: 16px;" <?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: 16px;" 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: 16px;" <?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 style="width: 100%; min-height: 5px;">&nbsp;</div>-->
                
            <?php
            
        endforeach;
    endif; 
?>

<?php
    if( !empty( $data['in_tables'] ) ) :
        $tables = !empty( $data['in_tables']['head'] ) ? array($data['in_tables']) : $data['in_tables'];
?>
		<div style="width: 100%; min-height: 5px;">&nbsp;</div>
<?php
        #echo '<pre>';print_r($tables);
        foreach( $tables as $k => $table ) :
            ?>
                <!--<div style="width: 100%; min-height: 5px;">&nbsp;</div>-->
                <table width="<?php echo WIDTH; ?>" id="tdhgt2" 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: 16px; min-width: 30px; width: auto; height: 220px;" <?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: 16px;" align="center"><?php echo ++$b; ?></td>
                                <?php endif;?>
                            <?php $length = count($row);
                            foreach( $row as $t => $td ) : //echo "<pre>Data: "; print_r($td); //die;
                            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: 16px;" <?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 style="width: 100%; min-height: 5px;">&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'];
?>
		<div id="subtable" style="width: 100%;">&nbsp;</div>
<?php
        foreach( $sub_tables as $k => $table ) :
            ?>  
                <!--<div 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 #error_log(print_r($table['body'],1)); 
                        $cc = count($table['body']);
                        foreach( $table['body'] as $b => $row ) : 
                            //$row = explode(',', $row);
                        //echo "<pre>Data: "; print_r($row[0]); die;
                          if($cc == ($b + 1)) { 
                            ?>
                            <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: 16px;" <?php echo $align;?>><?php echo $td; ?></td><?php
                            endforeach;
                            ?>
                            </tr>
                            
                          <?php  } ?>
                         <?php endforeach;
                         
                         foreach( $table['body'] as $b => $row ) :
                          if($cc != ($b + 1)) { 
                            ?>
                            <tr> 
                            <?php $length = count($row);
                            foreach( $row as $t => $td ) :
                                if($length == ($t + 1)) :
                                    $align  = "align=right";
									$wth	= "";
                                else :
                                    $align = "align=left";
									$wth	= "width: 300px;";
                                endif;
                               ?>
                                <td style="font-size: 16px;<?php echo $wth; ?>" <?php echo $align;?>><?php echo $td; ?></td><?php
                            endforeach;
                            ?>
                            </tr>
                            
                          <?php  } ?>
                         <?php endforeach; ?>
                </table>
            <?php
            
        endforeach;
    endif; 
?>

<?php
	if(!empty($footer_txt)){
		echo $footer_txt;
	}
?>


<table width="<?php echo WIDTH; ?>">
    <tr>
        <td>
            <table border="0" width="100%" cellpadding="2">
                <?php if(!empty( $amount )) : ?>
                <tr>
                    <td colspan="2" style="font-weight:bold; font-size: 14px;">S$ <?php echo number_format($amount,2,'.',''); ?>/- <?php echo ($gst == 1 ? '(Inclusive of GST)' : '') . $pay_mode_str; ?></td>
                </tr>
                <tr height="1"></tr>
                <tr>
                    <td style="font-weight:bold; font-size: 14px;" width="20%">Amount in Words (S$):</td>
                    <td width="80%"><?php echo convert_amount_to_word( $amount ); ?></td>
                </tr>
                <tr height="1"></tr>
                <tr>
                    <td colspan="2" ><span style="font-weight:bold; font-style:italic; font-size:11px;">***Issued receipts are not exchangeable or refundable</span></td>
                </tr>
                <tr height="1"></tr>
                <?php else : ?>
               
                <tr>
                    <td colspan="2" ><span style="font-weight:bold; font-style:italic; font-size:11px;">***The booking is recorded without payment. Please ensure payment is made well before the function date; otherwise, the booking will not be considered valid.</span></td>
                </tr>
                <tr height="1"></tr>
                <?php endif; ?>