<?php defined('BASEPATH') OR exit('No direct script access allowed'); 

$from_date = isset($from_date) ? date("d/m/Y", strtotime($from_date)) : '';
$to_date = isset($to_date) ? date("d/m/Y", strtotime($to_date)) : '';	

	///$head_map = array('B2B','B2CL','B2CS','EXP','RD','URD','AT','ATADJ','HSN');

	//$head_map = array('31a','31b','31c','31d','31e','32a','32b','4a','4a1','4a2','4a3','4a4','4a5','41b','42b','4c','4d','41d','42d','51a','51b');
//print_R($head_map);
$hcnt = count($head_map);
$tcnt = count($items);

$colspan = 0;
if(!empty($heading)) {
	$des_width = 100/count($heading);
	
	$des_width = 'width:'.$des_width.'%';
}
//print_R($head_map);exit;
//print_R($items);exit;
$doc_name = array(
	'B2B' => 'B2B Invoices-4A,4B,4C,6B,6C',
	'B2CL' => 'B2C(Large) Invoices-5A,5B',
	'B2CS' => 'B2C(Small) Invoices-5A,5B',
	'EXP' => 'Exports Invoices-6A',
	'RD' => 'Credit/Debit Notes(Registered)-9B',
	'URD' => 'Credit/Debit Notes(Unregistered)-9B',
	'AT' => 'Tax Liability(Advances Received)-11A(1),11A(2)',
	'ATADJ' => 'Adjustment of Advances-11B(1),11B(2)',
	'HSN' => 'HSN-wise Summary of Outward Supplies-12',
	'DOC_ISSUE' => 'Summary of documents issued during the tax period (13)',
	'EXEMP' => 'Nil rated, exempted and non GST outward Supplies-8',
	'31a' => '(a) Outward taxable supplies (other than zero rated, nil rated and exempted)',
	'31b' => '(b) Outward taxable supplies (zero rated)',
	'31c' => '(c) Other outward supplies, (Nil rated, exempted)',
	'31d' => '(d) Inward supplies (liable to reverse charge)',
	'31e' => '(e) Non GST outward supplies',
	'32a' => '(e) Non GST outward supplies',
	'4a' => '(A) ITC Available (whether in full or part)',
	'4a1' => '(1) Import of goods',
	'4a2' => '(2) Import of services',
	'4a3' => '(3) Inward supplies liable to reverse charge',
	'4a4' => '(4) Inward supplies from ISD',
	'45a' => '(5) All other ITC',
	'4a5' => '(5) All other ITC',
	'4b' => '(B) ITC Reversed',
	'41b' => '(1) As per rules 42 & 43 of CGST Rules',
	'42b' => '(2) Others',
	'4c' => '(C) Net ITC Available (A) – (B)',
	'4d' => '(D) Ineligible ITC',
	'41d' => '(1) As per section 17(5)',
	'42d' => 'Others',
	'51a' => 'From a supplier under composition scheme, Exempt and Nil rated supply',
	'51b' => 'Non GST supply'
);
$doc_name_gstr4 = array(
	'4B' => 'B2B Invoices gstr4.4B',
	'4C' => 'B2BUR Invoices gstr4.4C',
	'4D' => 'IMPS gstr4.4D',
	'5B' => 'CDNR gstr4.5B',
	'5BC' => 'CDNUR gstr4.5BC',
	'6A' => 'TXOS gstr4.6A',
	'8A' => 'AT gstr4.8A',
	'8B' => 'ATAD gstr4.8B'
);
$extraHead = array(
	'31a' => '3.1 Detail of Outward Supplies and Inward supplies liable to reverse charges',
	'32a' => '3.2 Of the supplies shown in 3.1 (a) above, details of inter-State supplies made to unregistered persons,composition taxable persons and UIN holders',
	'4a' => '4 Eligible ITC',
	'51a' => '5 Values of exempt, nil-rated and non-GST inward supplies'
);
$gstr9_head = array(
	'4' => '4. Outward',
	'5' => '5. Outward',
	'6' => '6. ITC Availed',
	'7' => '7. ITC Reversal',
	'8' => '8. Other ITC',
	'9' => '9. Tax Paid',
	'10' => '10. Py',
	'14' => '14. Differential Tax',
	'15' => '15. Demands & refunds',
	'16' => '16. Comp ds & refunds',
	'17' => '17. HSN outward',
	'18' => '18. HSN Inward'
);
?>
<page>
	<div class="header">
		<table cellspacing="0" cellpadding="0" style="width:100%;" class="pdf_head">
			<tr>
				<td style="width:50%;text-align:center;font-size:15px;" ><b><?php echo $compName; ?></b></td>
			</tr>
			<tr>
				<td style="width:50%;text-align:center;font-size:11px;" >GSTIN-<?php echo $gstin; ?></td>
			</tr>
			
			<tr>
				<td style="width:50%;text-align:center;font-size:15px;"><?php echo !empty($title) ? $title : '';?>&nbsp;
				<?php echo isset($rangePeriod) ? $rangePeriod : ''; ?>  <?php echo isset($rangeDate) ? '-' . $rangeDate : ''; ?></td>
			</tr>
			<?php 
				if($type == 'gstr9'){
			?>
			<tr>
				<td style="width:50%;text-align:center;font-size:11px;" ><?php echo $from_date. ' - ' .  $to_date; ?></td>
			</tr>
			<?php 
				}
			?>
		</table><br>
	   <div style="padding:3px;border-top:0.5px solid black;"></div>
	</div>
	<?php 
		// print_r($items);
		// exit;
		if($type == 'gstr9'){
	?>
	<?php if(!empty($export_data)) { 
			foreach($export_head as $key => $gstr9item){
	?>
				<br><div style="font-weight:bold;font-style:italic;color:grey;font-size:13px;"> <?php echo $gstr9_head[$key]; ?></div><br>
			
			<?php
				if(isset($export_head[$key])){
					echo '<table border="0" cellspacing="0" cellpadding="0" style="width:100%" >';
					echo "<tbody>";					
						$tb17head_added = false;
						$tb18head_added = false;
						foreach($export_data[$key] as $key_data => $item_data)
						{ 	
							
							if($key == '17' && !$tb17head_added){
								echo "<tr class='head2'>";
								echo "<th width='".$gstr9item['hsn_sc']['wid']. "' class='headgst' style='padding:3px;text-align: left;'>".$gstr9item['hsn_sc']['name']."</th>";
								// echo "<th width='".$gstr9item['desc']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['desc']['name']."</th>";
								echo "<th width='".$gstr9item['uqc']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['uqc']['name']."</th>";
								echo "<th width='".$gstr9item['qty']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['qty']['name']."</th>";
								echo "<th width='".$gstr9item['txval']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['txval']['name']."</th>";
								echo "<th width='".$gstr9item['taxRate']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['taxRate']['name']."</th>";
								echo "<th width='".$gstr9item['iamt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['iamt']['name']."</th>";
								echo "<th width='".$gstr9item['camt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['camt']['name']."</th>";
								echo "<th width='".$gstr9item['samt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['samt']['name']."</th>";
								echo "<th width='".$gstr9item['csamt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['csamt']['name']."</th>";
								$tb17head_added = true;
								echo"</tr>";
							}else if($key == '18' && !$tb18head_added){
								echo "<tr class='head2'>";
								echo "<th width='".$gstr9item['itemHS']['wid']. "' class='headgst' style='padding:3px;text-align: left;'>".$gstr9item['itemHS']['name']."</th>";
								// echo "<th width='".$gstr9item['itemDesc']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['itemDesc']['name']."</th>";
								echo "<th width='".$gstr9item['unit']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['unit']['name']."</th>";
								echo "<th width='".$gstr9item['qty']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['qty']['name']."</th>";
								echo "<th width='".$gstr9item['taxamt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['taxamt']['name']."</th>";
								echo "<th width='".$gstr9item['taxRate']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['taxRate']['name']."</th>";
								echo "<th width='".$gstr9item['igst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['igst']['name']."</th>";
								echo "<th width='".$gstr9item['cgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['cgst']['name']."</th>";
								echo "<th width='".$gstr9item['sgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['sgst']['name']."</th>";
								echo "<th width='".$gstr9item['cess']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['cess']['name']."</th>";
								echo"</tr>";
								$tb18head_added = true;
							}else if($key != '17' && $key != '18'){
								echo "<tr class='head'>";
								echo "<th width='".$gstr9item['name']['wid']. "' class='headgst' style='padding:3px;text-align: left;'>".$gstr9item['name']['name']."</th>";
								if($key == '6')
									echo "<th width='".$gstr9item['type']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['type']['name']."</th>";
								if($key != '6' && $key != '7' && $key != '8' && $key != '15')
									echo "<th width='".$gstr9item['taxableAmount']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['taxableAmount']['name']."</th>";
								if($key == '9' || $key == '14')
									echo "<th width='".$gstr9item['taxPaid']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['taxPaid']['name']."</th>";
								if($key != '14'){
									echo "<th width='".$gstr9item['igst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['igst']['name']."</th>";
									echo "<th width='".$gstr9item['cgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['cgst']['name']."</th>";
									echo "<th width='".$gstr9item['sgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['sgst']['name']."</th>";
									echo "<th width='".$gstr9item['cess']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['cess']['name']."</th>";
								}
								if($key == '15'){
									echo "<th width='".$gstr9item['interest']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['interest']['name']."</th>";
									echo "<th width='".$gstr9item['penalty']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['penalty']['name']."</th>";
									echo "<th width='".$gstr9item['latefee']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$gstr9item['latefee']['name']."</th>";
								}
								echo"</tr>";
							}
							if($key == '17'){
								echo '<tr>';
								echo "<td width='".$gstr9item['hsn_sc']['wid']. "' class='headgst' style='padding:3px;text-align: left;'>".$item_data['hsn_sc']."</td>";
								// echo "<td width='".$gstr9item['desc']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['desc']."</td>";
								echo "<td width='".$gstr9item['uqc']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['uqc']."</td>";
								echo "<td width='".$gstr9item['qty']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['qty']."</td>";
								echo "<td width='".$gstr9item['txval']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['txval']."</td>";
								echo "<td width='".$gstr9item['taxRate']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['taxRate']."</td>";
								echo "<td width='".$gstr9item['iamt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['iamt']."</td>";
								echo "<td width='".$gstr9item['camt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['camt']."</td>";
								echo "<td width='".$gstr9item['samt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['samt']."</td>";
								echo "<td width='".$gstr9item['csamt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['csamt']."</td>";
								echo "</tr>";
							}else if($key == '18'){
								echo '<tr>';
								echo "<td width='".$gstr9item['itemHS']['wid']. "' class='headgst' style='padding:3px;text-align: left;'>".$item_data['itemHS']."</td>";
								// echo "<td width='".$gstr9item['itemDesc']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['itemDesc']."</td>";
								echo "<td width='".$gstr9item['unit']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['unit']."</td>";
								echo "<td width='".$gstr9item['qty']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['qty']."</td>";
								echo "<td width='".$gstr9item['taxamt']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['taxamt']."</td>";
								echo "<td width='".$gstr9item['taxRate']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['taxRate']."</td>";
								echo "<td width='".$gstr9item['igst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['igst']."</td>";
								echo "<td width='".$gstr9item['cgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['cgst']."</td>";
								echo "<td width='".$gstr9item['sgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['sgst']."</td>";
								echo "<td width='".$gstr9item['cess']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['cess']."</td>";
								echo "</tr>";
							}else{
								echo '<tr class="head">';
								echo "<td width='".$gstr9item['name']['wid']. "' class='headgst' style='padding:3px;text-align: left;'>".$item_data['name']."</td>";
								if($key == '6')
									echo "<td width='".$gstr9item['type']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['type']."</td>";
								if($key != '6' && $key != '7' && $key != '8' && $key != '15')
									echo "<td width='".$gstr9item['taxableAmount']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['taxableAmount']."</td>";
								if($key == '9' || $key == '14')
									echo "<td width='".$gstr9item['taxPaid']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['taxPaid']."</td>";
								if($key != '14'){
									echo "<td width='".$gstr9item['igst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['igst']."</td>";
									echo "<td width='".$gstr9item['cgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['cgst']."</td>";
									echo "<td width='".$gstr9item['sgst']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['sgst']."</td>";
									echo "<td width='".$gstr9item['cess']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['cess']."</td>";
								}
								if($key == '15'){
									echo "<td width='".$gstr9item['interest']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['interest']."</td>";
									echo "<td width='".$gstr9item['penalty']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['penalty']."</td>";
									echo "<td width='".$gstr9item['latefee']['wid']. "' class='headgst' style='padding:3px;text-align: right;'>".$item_data['latefee']."</td>";
								}
								echo "</tr>";
							} 
							
							if(isset($export_detail[$key][$key_data]) && count($export_detail[$key][$key_data]) > 0){
								// echo "<tr>";
								// echo "<td colspan='6'>";
								echo '</tbody></table>';
								echo '<table border="0" cellspacing="0" cellpadding="0" style="width:100%" class="alltable" autosize="1">';
								echo '<tbody>';
								
								foreach ($export_detail[$key][$key_data] as $itemdetail) {
									if($key != '6'){
										echo '<tr>';
										echo "<td style='text-align: left'>". $itemdetail['idt'] ."</td>";
										echo "<td style='text-align: left'>". $itemdetail['inum'] ."</td>";
										echo "<td style='text-align: left'>". $itemdetail['cname'] ."</td>";
										echo "<td style='text-align: left'>". $itemdetail['conTaxNo'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['txval'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['rt'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['igst'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['cgst'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['sgst'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['cess'] ."</td>";
										if(isset($itemdetail['itemTotal'])){
											echo "<td style='text-align: right'>". $itemdetail['itemTotal'] ."</td>";
										}
										echo "<td style='text-align: right'>". $itemdetail['val'] ."</td>";
										echo '</tr>';
									}
									if($key =='6'){
										echo '<tr>';
										echo "<td style='text-align: left'>". $itemdetail['tDate'] ."</td>";
										echo "<td style='text-align: left'>". $itemdetail['inum'] ."</td>";
										echo "<td style='text-align: left'>". $itemdetail['conName'] ."</td>";
										// echo "<td style='text-align: left'>". $itemdetail['conTaxNo'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['txval'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['rt'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['igst'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['cgst'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['sgst'] ."</td>";
										echo "<td style='text-align: right'>". $itemdetail['cess'] ."</td>";
										// if(isset($itemdetail['itemTotal'])){
										// 	echo "<td style='text-align: right'>". $itemdetail['itemTotal'] ."</td>";
										// }
										// echo "<td style='text-align: right'>". $itemdetail['val'] ."</td>";
										echo '</tr>';
									}
								}
								echo "<tr class='borderbttom'><td colspan='12'></td></tr>";
								echo '</tbody></table>';
								// echo '</td></tr>';
								echo '<table border="0" cellspacing="0" cellpadding="0" style="width:100%" class="alltable" autosize="1">';
							}
						}
					echo '</tbody></table>';
					// echo '</tbody>';
				}
				// echo '</table>';
				
			}
		}
		
	}else{
			if($hcnt) {
				foreach($head_map as $h_map => $head) {
					// print_r($head);
					// exit;
					echo '<div class="content">';
					
					echo '<table border="0" cellspacing="0" cellpadding="0" style="width:100%" class="alltable" autosize="1">';
					
					if($tcnt) {
						
						echo "<tbody>";
						if($file_name == 'gstr3') {
							foreach($extraHead as $ext => $extVal) {
							
								if( $ext == $head) {
									
									echo '<tr>';	
										echo '<td colspan="10">';
											echo  '<span class="exthead"><b style="font-size:13px;">'.$extVal.'</td></span>';
										echo '</td>';
									echo '</tr>';
									
									
									if($head == '32a') {
										echo '<tr><td colspan="2" rowspan="2" class="head_bod boright" >Place of Supply (State/UT)</td>
												<td colspan="3" class="head_bod boright" style="text-align:center">Supplies made to Unregistered Persons</td>
												<td colspan="3" class="head_bod boright" style="text-align:center">Supplies made to Composition Taxable Persons</td>
												<td colspan="2" class="head_bod" style="text-align:center">Supplies made to UIN Holders</td>
												<td colspan="1" class="head_bod"></td>
										</tr>';
										echo '<tr>
												<td class="head_bod">Total Taxable Value</td>
												<td class="head_bod boright" colspan="2">Amount of Integrated Tax </td>
												<td style="text-align:right" colspan="2" class="head_bod">Total Taxable Value</td>
												<td class="head_bod boright ar"  >Amount of Integrated Tax </td>
												<td  class="head_bod ar">Total Taxable Value</td>
												<td class="head_bod ar"  colspan="2">Amount of Integrated Tax </td>
												
										</tr>';
									}
									else if($head == '51a'){
										echo '<tr><td colspan="5" ><b>Nature of supplies</b></td>
											<td colspan="2"  class="ar"><b></b></td>
											
											<td  class="ar" ><b>Inter state supplies</b></td>
											<td  class="ar"><b>Intra state supplies</b></td>
											<td class="ar"><b></b></td>
											<td colspan="1"></td>
											
										</tr>';
									}
									else{
										echo '<tr><td colspan="5" ><b>Nature of supplies</b></td>
											<td colspan="2"  class="ar"><b>Taxable Value</b></td>
											<td class="ar"><b>Total IGST</b></td>
											<td  class="ar" ><b>Total CGST</b></td>
											<td  class="ar"><b>Total SGST</b></td>
											<td colspan="1"></td>
											
										</tr>';
									}
								}
							}
						}
							
						if($file_name == 'gstr1') {
							if(!empty($head) && ($head == 'EXEMP')) {
								echo '<tr><td colspan="3"><b>Document Details</b></td>
									<td colspan="3"><b>No. of Records</b></td>
									<td class="ar"><b>Total Nil amount</b></td>
									<td class="ar"><b>Total Exempted amount</b></td>
									<td class="ar" colspan=2><b >Total Non-GST amount</b></td>
									</tr>'; 
							}
							else if(!empty($head) && ($head == 'DOC_ISSUE')) {
								echo '<tr><td colspan="4"></td>
									<td colspan="2" ><b>Total Number</b></td>
									<td class="ar" ><b>Cancelled</b></td>
									<td class="ar"><b></b></td>
									<td class="ar"><b></b></td>
									</tr>'; 
							}
							else{
								echo '<tr><td colspan="3"><b>Document Details</b></td>
									<td ><b>No. of Records</b></td>
									<td ><b>Taxable Value</b></td>
									<td></td>
									<td class="ar"><b>Total IGST</b></td>
									<td class="ar"><b>Total CGST</b></td>
									<td class="ar"><b>Total SGST</b></td>
									<td class="ar"><b>Cess</b></td>
									<td colspan="2" class="ar"><b>Invoice Value</b></td>
									
									</tr>'; 
							}
							
							foreach($list as $lst_key=> $lst_val) {
								if( $head == $lst_val['categoryCode']) {
									
									echo '<tr class="head"><td colspan="3" class="ital"><b>'.$doc_name[$lst_val['categoryCode']].'</b></td>
									<td >'.$lst_val['inv_cnt'].'</td>
									<td  class="ar">'.(!empty($lst_val['tottaxable']) ? $lst_val['tottaxable'] : '').'</td>
									<td></td>
									<td class="ar">'.$lst_val['igst'].'</td>
									<td class="ar">'.$lst_val['cgst'].'</td>
									<td class="ar">'.$lst_val['sgst'].'</td>
									<td class="ar">'.(!empty($lst_val['cess']) ? $lst_val['cess'] : '').'</td>
									<td colspan="2" class="ar">'.(!empty($lst_val['totinv']) ? $lst_val['totinv'] : '').'</td>
									</tr>'; 
								}
								
							}
						}else if($file_name == 'gstr4'){
							// echo $head;
							// echo ' : ' . $doc_name_gstr4[$head];
							echo '<tr><td calss="ar" colspan="2"><b>Document Details</b></td>
									<td class="ar"><b>No. of Suppliers</b></td>
									<td class="ar"><b>No. of Notes</b></td>
									<td class="ar"><b>No. of Invoices</b></td>
									<td class="ar"><b>Total Invoice Value</b></td>
									<td class="ar"><b>Total Taxable Value</b></td>
									<td class="ar"><b>Total IGST</b></td>
									<td class="ar"><b>Total CGST</b></td>
									<td class="ar"><b>Total SGST</b></td>
									<td class="ar"><b>Total Cess</b></td>
									<td colspan="2"></td>
									</tr>'; 
							foreach($list as $lst_key=> $lst_val) {
								// print_r($lst_val);
								// echo $doc_name_gstr4['4B'];
								// exit;
							if($lst_val['inv_cnt'] > 0){
								if( $head == $lst_val['code']) {
									// echo $lst_val['code'];
									// exit;
										echo '<tr class="head"><td style="text-align:left" colspan="2" class="ar">' .$doc_name_gstr4[$lst_val['code']]. '</td>
										<td class="ar">' .$lst_val['con_cnt']. '</td>
										<td class="ar">' .$lst_val['notes_cnt']. '</td>
										<td class="ar">' .$lst_val['inv_cnt']. '</td>
										<td class="ar">' .$lst_val['totAmount']. '</td>
										<td class="ar">' .$lst_val['taxableAmount']. '</td>
										<td class="ar">' .$lst_val['igst']. '</td>
										<td class="ar">' .$lst_val['cgst']. '</td>
										<td class="ar">' .$lst_val['sgst']. '</td>
										<td class="ar">' .$lst_val['cess']. '</td>
										<td colspan="2"></td>
										</tr>'; 
									}
								}
							}
							// print_r($heading);
							// exit;
							// print_r($items);
							// 	exit;
							// exit;
						}
						else {
							foreach($list as $lst_key=> $lst_val) {
									$doc_name[$lst_val['doc']] = !empty($doc_name[$lst_val['doc']]) ? $doc_name[$lst_val['doc']] : '';
									if( $head == $lst_val['doc']) {
										if($head == '32a' || $head == '32b' || $head == '32c') {
											echo '<tr class="head"><td class="ital" colspan="2" ><b>'.$lst_val['name'].'</b></td>';
											echo '<td >'.(!empty($lst_val['taxRate']) ? $lst_val['taxRate'] : '').'</td>';
											echo '<td colspan="2" >'.(!empty($lst_val['taxableAmount']) ? $lst_val['taxableAmount'] : '').'</td>';
										}
										else {
											echo '<tr class="head"><td colspan="5" class="ital" ><b>'.$doc_name[$lst_val['doc']].'</b></td>';
										}
										echo '<td colspan="2" style="text-align:right;">'.(($head != '32a') ? $lst_val['amount'] : '').'</td>
										<td style="text-align:right"  style="text-align:right;">'.$lst_val['IGSTtaxValue'].'</td>
										<td style="text-align:right"  style="text-align:right;">'.$lst_val['CGSTtaxValue'].'</td>
										<td style="text-align:right"  style="text-align:right;">'.$lst_val['SGSTtaxValue'].'</td>
										<td colspan="2"></td>
										</tr>'; 
									}
									
								}
								
						}
						if(!empty($items)) {
							
							// print_r($items);exit;
							foreach($items as $ite => $itm) {
								// print_r($itm);
								// echo '<br/>';
								// exit;
								
								$bohead  = '';
								if(!empty($itm['isDetail']) && ($type == 'gstr3all')) {
									$bohead = 'style="border-bottom:1px solid grey;border-top:1px solid grey;"';
								}

								if(!empty($itm['doc_code']) && ($type == 'gstr3all')) {
									$bohead = 'style="background:#f6f5f5 !important;"';
								}
								if($type == 'gstr1all') {
									
									if(!empty($itm) && (!empty($itm['categoryCode'])) )	{ 
										$itm['categoryCode'] = !empty($itm['categoryCode']) ? $itm['categoryCode'] : ((!empty($itm['tType']) ? $itm['tType'] : ''));
										$bohead=preg_match('/<b class="[^"]*sumHead[^"]*">/', $itm['categoryCode'])? 'style="background:#f6f5f5 !important;border-bottom:1px solid grey;"' :(preg_match('/<span class="[^"]*detHead[^"]*">/', $itm['categoryCode']) ? 'style="border-bottom:1px solid grey;"' : '') ;
									}
								}
								// echo $itm['code'] .' : ' . $head . ' : ' . strip_tags($itm['code']) . '<br/>';
								if((!empty($itm) && !empty($itm['code'])) && (($head == strip_tags($itm['code'])) ) || ($head == $itm['code']) || (!empty($itm['32code']) && $head == $itm['32code']))  {
									$class = '';
									
									echo '<tr>';
									
									foreach($heading as $key=> &$val) {
										if($file_name == 'gstr4' && ($key == 'code' || !isset($itm[$key]))){
											continue;
										}
										// echo $key . " : " . $val;
										// echo '<br/>';
										// //if(!empty($key) && ($key== 'txval')||($key == 'val')|| ($key =='igst')||($key=='cgst')||($key =='sgst')||($key=='cess')||($key =='amount')||($key == 'IGSTtaxValue')|| ($key =='CGSTtaxValue')||($key =='SGSTtaxValue')||($key=='CESS')||($key=='rt') || ($key=='taxRate') || ($key == 'CESStaxValue')){
										if(!empty($key) && (in_array($key , array('txval','val','igst','cgst','sgst','cess','amount','IGSTtaxValue','CGSTtaxValue','SGSTtaxValue','CESS','rt','taxRate','CESStaxValue','itemTotal','pos','iamt','camt','samt','csamt')))){
											$bodyalign ="text-align: right";
										}else{
											$bodyalign ="text-align: left";
										}
										/*if($itm['categoryCode'] != strip_tags($itm['categoryCode'])) {
											$colspan = 4;
										}*/
										echo "<td  class='k ".$class."' width=".$val['wid']." ".$bohead." style='".$bodyalign."'>".$itm[$key]."</td>";
									}
									echo '</tr>';
								}
								echo '<tr colspan="'.count($heading).'" align="right" style="text-align:right;">[[page_cu]]/[[page_nb]]</tr>';
							} 
							// exit;
						}
						echo '</tbody>';
			
					}
					echo '</table><div style="padding:3px;border-top:0.5px solid black;"></div></div>';
				}
			}
		}
		// exit;
	?>	
	<div class="footer">
		<page_footer></page_footer>
	</div>
	<style>
		.alltable{
			color:#000;
			width: 100%;
			height: 60%;
		}	
		
		.alltable td{
			
			/*white-space: nowrap !important;*/
			padding-right:10px;
			padding: 4px;
			border-color: 0.5px  solid black;
		}
		.ital {	
			font-style: italic;
			color: black;
		}
		td {
			overflow: hidden; 
    text-overflow: ellipsis; 
    word-wrap: break-word;
			/*border:1px solid grey !important;*/
		}
		table {
			
			width:100% !important; 
			table-layout: fixed !important;
		}
		.borderbttom td {
			border-bottom:0.5px solid !important;
		}
		.head td,.head2 th {
			
			border-bottom:2px solid !important;
		}
		.head_bod {
			border-top:1px solid #000000;
			border-bottom:1px solid #000000;
		}
		.ar {
			text-align: right !important;
		}
		.boright {	
			border-right:1px solid grey !important;
		}
		
		table { table-layout:fixed;  page-break-inside: avoid !important;}
		table td { overflow: hidden; }
		.exthead b{			
			font-size:15px !important;
			
		}
	</style>
</page>

