<?php

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

$amount = is_array($amount) ? $amount[0] : $amount;
?>
                                <tr>
                                <?php 
                                    $k = 0;
                                    if(!empty($data['fields']) && is_array($data['fields'])) {
                                    foreach( $data['fields'] as $label => $value ) :
                                            
                                ?>

                                        <td width="18%" class="lbl"><?php echo $label; ?></td>
                                        <td width="1%">:</td>
                                        <td width="36%" style="border-bottom:2px dotted #000;"><?php echo $value; ?></td>
                                        <td width="1%">&nbsp;</td>
                                <?php 
                                        echo ++$k % 2 == 0 ? '</tr><tr height="5"></tr><tr>' : '';
                                    endforeach; 
                                    }
                                ?>                                
                                </tr>        
                            </table>
                        </td>
                    </tr>
                </table>
                
                <?php
                   /*  if( !empty( $data['tables'] ) ) :
                        $tables = !empty( $data['tables']['head'] ) ? array($data['tables']) : $data['tables'];
                        foreach( $tables as $k => $table ) :
                            ?>
                                <table width="<?php echo WIDTH; ?>" border="1" style="border-collapse:collapse; margin: 20px 0px;" cellpadding="5">
                                    <tr>
                                        <th>&nbsp;</th>
                                    </tr>
                                    <tr>
                                        <th width="5%">S.No</th>
                                    <?php foreach( $table['head'] as $h => $th ) : ?>
                                        <th><?php echo $th; ?></th>
                                    <?php endforeach; ?>
                                    </tr> 
                                    
                                    <?php if(!empty($table['body']) && is_array($table['body'])) {
                                        
                                        foreach( $table['body'] as $b => $row ) : 
                                            ?>
                                            <tr>
                                                <?php foreach( $row as $t => $th ) : ?>
                                                    <td colspan="3"><?php echo $th;?></td>
                                                <?php endforeach;?>
                                            </tr>
                                            <?php foreach($row as $i => $td) {?>
                                                <tr>
                                                    <td align="center"><?php echo ++$b; ?></td>
                                                <?php foreach( $td as $k => $col ) :
                                                    ?><td><?php echo $col; ?></td><?php
                                                endforeach;
                                                ?>
                                                </tr>
                                            <?php } ?>
                                    <?php endforeach;

                                        } else { ?>
                                            <tr>
                                                <td colspan="<?php echo (count($table['head']) + 1);?>"><center>No Records Found!</center></td>
                                            </tr> 
                                    <?php } ?>
                                        
                                </table>
                            <?php
                            
                        endforeach;
                    endif; */ 
                ?>
                
                <?php 
                    if( !empty( $data['tables'] ) ) :
                        $tables = !empty( $data['tables']['head'] ) ? array($data['tables']) : $data['tables'];
                        foreach( $tables as $k => $table ) : $first_ind = key($table['body']); ?>
                            <?php foreach( $table['body'] as $b => $row ) : ?>
                                    <span style="font-size: 16px;"><b>
                                    <?php  
                                        foreach($row as $i => $td) { #echo count($row[++$i]);
                                            if($i > 0 &&  $i == 1){
                                                echo $row[0];
                                            } /* else if($table['body'][]) {
                                                echo '<span style="font-size: 16px; text-align: center;"><b>No Records Found!</b></span>';
                                            } */
                                        }
                                    ?>
                                    
                                    </b></span>
                                        <?php unset($row[0]) ; $ii = 0; ?>
                                        <?php if(count($row)) { ?>
                                            <table width="<?php echo WIDTH; ?>" border="1" style="border-collapse:collapse; margin: 20px 0px;" cellpadding="5">
                                                <tr>
                                                    <th width="5%">S.No</th>
                                                <?php foreach( $table['head'] as $h => $th ) : ?>
                                                    <th width="42.5%" style="border-bottom: 1px"><?php echo $th; ?></th>
                                                <?php endforeach; ?>
                                                </tr>
                                                <?php
                                                #if(count($row) > 0) {
                                                    foreach($row as $i => $td) :?>
                                                        <tr>
                                                            <td align="center"><?php echo ++$ii; ?></td>
                                                        <?php foreach( $td as $k => $col ) :
                                                            ?><td><?php echo $col; ?></td><?php
                                                        endforeach;
                                                        ?>
                                                        </tr>
                                                    
                                                    <?php endforeach; ?>
                                                <?php #else : ?>
                                                    <!--<tr>
                                                        <td colspan="3"><center>No Records Found!</center></td>
                                                    </tr>-->
                                                <?php #endif;?>
                                            </table>
                                        <?php } else {?>
                                            <?php
                                               /* if($first_ind == $b){
                                                    echo '<span style="font-size: 16px; text-align: center;"><b><center>No Records Found!</center></b></span>';
                                                }*/
                                            ?>
                                        <?php } ?>
                                    <?php
                                endforeach; //die;
                            ?>
                            
                        <?php endforeach; 
                    endif;
                ?>
                
                <table width="<?php echo WIDTH; ?>">
                    <tr>
                        <td>
                            <table border="0" width="100%" cellpadding="5">
                                <tr height="5"></tr>
                                <?php if(!empty( $amount )) : ?>
                                <tr>
                                    <td colspan="2" style="font-weight:bold;">S$ <?php echo number_format($amount,2,'.',''); ?>/-  <?php echo  $pay_mode_str; ?></td>
                                </tr>
                                <tr height="5"></tr>
                                <tr>
                                    <td style="font-weight:bold;" width="20%">Amount in Words (S$):</td>
                                    <td width="80%"><?php echo convert_amount_to_word( $amount ); ?></td>
                                </tr>
                                <?php endif; ?>
                
                