<?php

/* 
 * Author       : Jai K
 * Purpose      : View for Print Format 2 (Kattalai Archanai)
 * Created On   : 2016-09-20 18:14
 */

                            $names = $data['name'];
                            $amount = is_array($amount) ? $amount[0] : $amount;
                            foreach( $names as $k => $name ) :
                                $e = explode(',', $name);
                            ?>

                                <tr>
                                    <td width="18%" class="lbl" style="font-size: 15px;"><?php echo $k == 0 ? 'Name / Star<div class="sub-lbl">பெயர்  / நட்சத்திரம்</div>' : '&nbsp;'; ?></td>
                                    <td width="1%">:</td>
                                    <td width="80%" colspan="5" style="border-bottom:2px dotted #000; font-size: 15px;"><?php echo $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 width="18%" style="font-size: 15px;" class="lbl">Date<span class="linear-lbl"> / தேதி</span></td>
                                    <td width="1%">:</td>
                                    <td width="20%" style="border-bottom:2px dotted #000; font-size: 15px;"><?php echo $data['date'][0]; ?></td>
                                    <?php if( !empty( $data['date'][1] ) ) :?>
                                        <td width="5%" style="border-bottom:2px dotted #000; font-size: 15px;">to</td>
                                        <td width="20%" style="border-bottom:2px dotted #000; font-size: 15px;"><?php echo $data['date'][1]; ?></td>
                                        <td width="1%" style="border-bottom:2px dotted #000; font-size: 15px;"></td>
                                        <td width="35%" style="border-bottom:2px dotted #000; font-size: 15px;"></td>
                                    <?php endif; ?>
                                </tr>
                                <tr height="1"></tr>
                                <tr>
                                    <td width="18%" class="lbl" style="font-size: 15px;">Day<span class="linear-lbl"> / நாள் </span></td>
                                    <td width="1%">:</td>
                                    <td width="20%" style="border-bottom:2px dotted #000; font-size: 15px;"><?php echo !empty( $data['day'] ) ? $data['day'] : '-'; ?></td>
                                    <td width="5%" style="border-bottom:2px dotted #000; font-size: 15px;"></td>
                                    <td width="20%" align="center" class="lbl" style="font-size: 15px;">Total Weeks :<div class="sub-lbl">மொத்த வாரம்</div></td>
                                    <td width="1%" style="border-bottom:2px dotted #000; font-size: 15px;"><?php echo !empty( $data['day'] ) ? $data['days'] : '-'; //$data['weeks']; ?></td>
                                    <td width="35%" style="border-bottom:2px dotted #000; font-size: 15px;"></td>
                                </tr>
                                <tr height="1"></tr>
                                <tr>
                                    <td width="18%" class="lbl" style="font-size: 15px;">Total Days<div class="sub-lbl">மொத்த நாட்கள்</div></td>
                                    <td width="1%">:</td>
                                    <td width="20%" style="border-bottom:2px dotted #000; font-size: 15px;"><?php echo $data['days']; ?></td>
                                    <td width="5%"></td>
                                    <td width="20%"></td>
                                    <td width="1%"></td>
                                    <td width="35%"></td>
                                </tr>
                                <tr height="1"></tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <?php if(count($data['items']) > 0) : ?>
                <table width="<?php echo WIDTH; ?>" border="1" style="border-collapse:collapse;" cellpadding="5">
                    <tr>
                    	<th>SI.No<span class="linear-lbl" style="font-size: 14px;"> / வரிசை எண்</span></th>
                        <th>God Name<span class="linear-lbl" style="font-size: 14px;"> / கடவுள்  பெயர்</span></th>
                    </tr>
                    <?php 
						foreach( $data['items'] as $k => $itm ) :
								$str = $itm['name'] . (!empty($itm['tamil_name']) ? $sepr . '<span class="linear-lbl">'. tamil($itm['tamil_name']) .'</span>' : '');
					?>
                            <tr>
                                <td align="center" style="font-size: 14px;"><?php echo $k+1; ?></td>
                                <td align="left" style="font-size: 14px;"><?php echo $str; ?></td>
                            </tr>
                    <?php endforeach;?>
                </table>
                <?php endif; ?>
                
                <?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%" cellpadding="2">
                                <tr height="1"></tr>
                                <tr>
                                    <td colspan="2" style="font-weight:bold; font-size: 14px;">S$ <?php echo number_format($amount,2,'.',''); ?>/- <?php echo $pay_mode_str; //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>
                                    <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>