<?php
$names = $data['name'];

$amount = !is_array($amount) ? array($amount) : $amount;

                 #echo $gst . '<pre>';print_r($data);die;

                foreach( $names as $n => $name ) :

                    $e = explode(",", $name);

                    if( empty( $e[0] ) ) :

                        continue;

                    endif;

                    

                    $incl_star = count($e) <= 2 ? FALSE : TRUE;

                    $e[1] = !$incl_star && !empty($e[1]) ? tamil($e[1], 'border: none; font-weight: bolder; font-size: 22px;') : $e[1]; 

                ?>

                    <tr>

                        <?php

                        if( $n == 0 ) :

                        ?>

                            <td class="lbl" width="18%">Name<?php echo $incl_star ? ' / Star' : ''; ?><div class="sub-lbl">பெயர்  <?php echo $incl_star ? ' / நட்சத்திரம்' : ''; ?></div></td>

                            <td width="1%">:</td>

                        <?php else : ?>

                            <td colspan="2">&nbsp;</td>

                        <?php endif; ?>

                            <td colspan="5" style="border-bottom:2px dotted #000; font-size: 16px;"><?php echo str_replace("cama", "," ,$e[0]) . ( !empty( $e[1] ) ? $sepr . $e[1] : '') . ( !empty( $e[2] ) ? ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-family: amudham;font-weight: bolder;font-size: 24px;">' . $e[2] . '</span>' . ( !empty($e[3]) ? $sepr . '<span style="color: #999;">'.$e[3].'</span>' : '' ) : ''  ); ?></td>

                    </tr>

                    <tr height="1"></tr>

                <?php

                endforeach; 

                ?>

                <tr>

                    <td class="lbl">Contact No / Email<div class="sub-lbl">தொடர்பு எண் / மின்னஞ்சல்</div></td>

                    <td >:</td>

                    <td colspan="5" style="border-bottom:2px dotted #000; font-size: 16px;" colspan="4"><?php echo $data['contact_no'] . ( !empty($data['email']) ? $sepr.$data['email'] : '' ); ?></td>

                </tr>

                <tr height="1"></tr>

                <?php 

                    if( !empty($data['section']) ) : 

                        

                        foreach( $data['section'] as $ss => $vv ) :

                            $i = 0;

                            $splt = 2;

                            if( !is_array($vv) ) :

                                $splt = 1;

                                $vv = array($ss => $vv);

                            endif;

                            ?>

                            <tr>

                                <?php

                                $len = count($vv);

                                foreach( $vv as $s => $v ) :

                                    ?>

                                        <td class="lbl" width="24%" <?php echo $i % $splt != 0 ? 'align="right"' : '' ?> ><?php echo $s; ?></td>

                                        <td>:</td>

                                        <td width="24%" style="border-bottom:2px dotted #000; font-size: 16px;" colspan="<?php echo $splt == '1' ? 7 : 1; ?>"><?php echo $v; ?></td>

                                    <?php 

                                    echo ++$i % $splt == 0 ? (($i == $len) ? '</tr>' : '</tr><tr height="1"></tr>') : '<td width="3%">&nbsp;</td>'; 

                                    

                                endforeach;

                                ?>

                            </tr><tr height="1"></tr>     

                            <?php

                        endforeach; 

                            

                    endif; 

                ?>

                

                <tr>

                    <td class="lbl">Address<div class="sub-lbl">முகவரி</div></td>

                    <td>:</td>

                    <td style="border-bottom:2px dotted #000; font-size: 16px;" colspan="5"><?php echo $data['address']; ?></td>

                </tr>

                <tr height="1"></tr>

                <tr>

                    <td class="lbl">Description<div class="sub-lbl">விவரம்</div></td>

                    <td>:</td>

                    <td style="border-bottom:2px dotted #000; font-size: 16px;" colspan="5"><?php echo $data['desc']; ?></td>

                </tr>

                <?php if(!empty($data['weight_gms'])) { ?>
                <tr>

                    <td class="lbl">Weight in GMS<div class="sub-lbl">கிராம் எடை</div></td>

                    <td>:</td>

                    <td style="border-bottom:2px dotted #000; font-size: 16px;" colspan="5"><?php echo $data['weight_gms']; ?></td>

                </tr>
                <?php } ?>
				 <?php
				if($data['addData']){
					foreach($data['addData'] as $val){
						if(!empty($val['desc']) && ($val['amuont'] > 0)){
				?>
					<tr height="1"></tr>
					<tr>
						<td class="lbl"><?php echo $val['desc']; ?></td>
						<td>:</td>
						<td style="border-bottom:2px dotted #000; font-size: 16px;"> $<?php echo number_format($val['amuont'],2,'.',''); ?></td>                        
					</tr>
				<?php 
							}
						}				
					} 
				?> 
                <tr height="1"></tr>
            </table>

        </td>

    </tr>

</table>

<?php

    if( !empty( $data['tables'] ) ) :?>

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

	    foreach( $tables as $k => $table ) : 

			if(count($table['body']) > 0) { ?>

			<table>

				<tr height="2"></tr>

			</table>

		<?php } 

		endforeach;

		?>

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

        #echo '<pre>';print_r($tables);

        foreach( $tables as $k => $table ) :

		    if(count($table['body']) > 0) {

            ?>

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

                <table width="<?php echo WIDTH; ?>" 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 class="auto-adj" style="width: 100%; min-height: 10px;">&nbsp;</div>

            <?php

            }

        endforeach; ?>

        <?php 

	    foreach( $tables as $k => $table ) : 

			if(count($table['body']) > 0) { ?>

			<table>

				<tr height="2" class="auto-adj"></tr>

			</table>

		<?php } 

		endforeach;

		?>

   <?php 

    endif; 

?>             

<table width="<?php echo WIDTH; ?>" >

    <tr>

        <td>

            <table border="0" width="100%">

                <?php if(!empty($amount[0]) ) :  

                    

                        if( !empty( $amount[1] ) ) :  ?>

                        <tr>

                            <td style="font-weight:bold; font-size: 15px;" width="40%">Total Pledge Amount / <span class="sub-lbl">மொத்த உறுதி தொகை</span></td>

                            <td width="10%" style="font-size: 15px;" >: $<?php echo number_format($amount[0],2,'.',''); ?></td>

                            <td style="font-weight:bold; font-size: 15px;" width="30%">Paid Amount / <span class="sub-lbl">செலுத்திய தொகை</span></td>

                            <td style="font-size: 15px;" >: $<?php echo number_format($amount[1],2,'.',''); ?></td>

                        </tr>

                        <tr>

                            <td style="font-weight:bold; font-size: 15px;" width="40%">Balance to be pay / <span class="sub-lbl">மீதமுள்ள தொகை</span></td>

                            <td style="font-size: 15px;">: $<?php echo !empty( $amount[3] ) ? number_format($amount[3],2,'.','') : number_format(($amount[0]-$amount[1]), 2, '.', ''); ?></td>

                        </tr>

                        <tr>

                            <td colspan="5" height="5" class="auto-adj"></td>

                        </tr>

                        <tr colspan="5" height="2"></tr>

                    <?php endif; ?>

                    <tr>

                        <td colspan="2" style="font-weight:bold;">S$ <?php echo !empty( $amount[1] ) ? number_format($amount[2],2,'.','') : number_format($amount[0],2,'.',''); ?>/- <?php echo ($gst == 1 ? '<span style="font-size: 12px; color: #999;">(Inclusive of GST)</span>' : '') . $pay_mode_str; ?></td>

                    </tr>

                    <tr height="1" class="auto-adj"></tr>

                    <tr>

                        <td width="20%" colspan="5" ><span style="font-weight:bold;">Amount in Words (S$) :</span> &nbsp;<?php echo convert_amount_to_word( !empty( $amount[1] ) ? $amount[2] : $amount[0] ); ?></td>

                    </tr>

                 
                     <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                    <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                    <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                     <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                     <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                     <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                    
                    
                    
                    <tr>

                        <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;">Gold / Silver Receiver: _______________________________</span></td>
                        <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;">Gold / Silver Checked By: ____________________________</span></td>

                   
                   </tr>
                   
                    
                      <tr>
                            <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                      </tr>
                    <tr>
                          <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                    </tr>
                      <tr>
                            <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;"> </span></td>
                      </tr>
                   

                    <tr>

                        <td width="20%" colspan="5" ><span style="font-weight:bold; font-style:italic; font-size:11px;">***Issued receipts are not exchangeable or refundable</span></td>

                    </tr>
                    
                   
                   
                    <tr height="3" class="auto-adj"></tr>

                <?php endif; ?>