<?php

session_start();

include 'connect.php';

if(isset($_SESSION['adminemail']))

{

$user=$_SESSION['adminemail'];



echo '<link href="css/print.css" rel="stylesheet" type="text/css" />';

echo '<title>INVOICE</title>';



echo"<style>

@page  

{ 

    size: auto;

    margin: 5mm 0mm 5mm 0mm;

} 

.main

{

min-height:500px;

}

.bottom

{

height:50px;

text-align:center;

}

table

{

font-size:11px;

font-family:arial;

}

table tr,th,td

{

border-color:#999;

}

@media print {

    p{page-break-inside: avoid;}	

}

     

</style>";



if(isset($_GET['id']))

	{

		$id=$_GET['id'];

		$digital=$_GET['digital'];

		$copy=$_GET['copy'];

		

		$gtp=mysqli_query($conn,"select * from settings");

		$gtp1=mysqli_fetch_assoc($gtp);



		$get=mysqli_query($conn,"select * from purchase where invoiceno='$id'");

		$get1=mysqli_fetch_assoc($get);

		

		$cus=mysqli_query($conn,"select * from supplier where ID='$get1[supplier]'");

		$cus1=mysqli_fetch_assoc($cus);

		

		$dte=$get1['date'];

		

		$d=date("m",strtotime($dte));

		if($d>03)

		{

		$y=date("Y",strtotime($dte));

		$y1=$y+1;		

		

		$dd=date($y);

		$dd1=date($y1);	

		}

		elseif($d<=03)

		{

		$y1=date("Y",strtotime($dte));

		$y=$y1-1;	

		

		$dd=date($y);

		$dd1=date($y1);	

		}

		

		$fin=$dd.'-'.$dd1;

		

		echo '

		<table border="1" style="width:95%; margin:auto; border-collapse:collapse; border-bottom:none; border-top:none; border-left:1px solid #999; border-right:1px solid #999;">

		<thead>

		<tr><th style="padding:0px; border-top:none;">';

		

		echo"

		

		<table border='1' style='width:100%; margin:auto; border-color:#999; border-collapse:collapse; border:none; border-bottom:none;'>				

		

		<tr><td colspan='2' style='text-align:center; height:35px; border-left:none; border-right:none;'><b style='font-size:18px;'>Purchase</b></td></tr>

			

		<tr><td colspan='2' style='padding:0; border-left:none; border-right:none;'>

		

		<table style='width:100%; border-collapse:collapse;'>

		

		<tr><td style='width:70%; padding:0; border-left:none; border-right:1px solid #999;'>

		

		<table><tr><td valign='top' style='padding-top:5px; border-left:none;'></td>

		<td><table style='padding-left:5px; padding-top:3px;'>";

		

		echo"<tr><td><b style='font-size:17px;'>".$gtp1['company_name']."</b></td></tr>

		

		<tr><td>".$gtp1['address']."</td></tr>

		

		<tr><td>".$gtp1['contact']."</td></tr>";

		

		echo"</table></td></tr></table>



		

		</td><td style='border-right:none; padding:0;'>

		

		<table style='margin-left:5px; width:100%;'>

		

		<tr><td style='width:20%;'>Purchase No. </td><td width='2%'>:</td><td>".$get1['invno']." / ".$fin."</td></tr>

		

		<tr><td style='width:20%;'>Date </td><td width='2%'>:</td><td>".date('d-m-Y',strtotime($get1['date']))."</td></tr>

				

		</table>

		

		</td></tr></table>

		

		</td></tr>

		

		

		<tr><td style='width:50%; padding-left:5px; border-right:none; border-left:none; border-bottom:none;'>

		

		<table style='margin-left:5px; width:100%;'>

		

		<tr><td style='width:20%;'>To</td><td style='width:2%;'>:</td><td><b style='text-transform:uppercase;'>".$cus1['name']."</b></td></tr>

		<tr><td style='width:20%;' valign='top'>Address</td><td style='width:2%;' valign='top'>:</td><td>".$cus1['address']."</td></tr>

		<tr><td style='width:20%;' valign='top'>GST IN</td><td style='width:2%;' valign='top'>:</td><td>".$cus1['gst']."</td></tr>

		<tr><td style='width:20%;' valign='top'>State Code</td><td style='width:2%;' valign='top'>:</td><td>".$cus1['code']."</td></tr>

		

		</table>



		</td>

		

		

		<td colspan='3' style='text-align:right; padding-right:5px; border-left:none; border-right:none; border-bottom:none;'>

				

		</td></tr>

		

		

		</table>";

		

		echo'</th></tr></thead><tbody><tr><td style="padding:0px; border-top:none; height:470px;">';

		

		echo"<table border='1' style='width:100%; margin:auto; height:470px; border-color:#999; border-collapse:collapse; border:1px solid #999; border-top:none; border-left:none; border-right:none; border-bottom:none;'>

		

		<thead>

		

		<tr><th style='width:3%; border-left:none; border-top:none;' rowspan='2'>S.No</th>

		<th style='width:25%; border-top:none;' rowspan='2'>Product</th>

		<th style='width:7%; border-top:none;' rowspan='2'>Qty</th>

		<th style='width:7%; border-top:none;' rowspan='2'>Rate</th>

		<th style='width:7.8%; border-top:none;' rowspan='2'>Amount</th>

		<th style='width:14%; border-top:none;' colspan='2'>CGST</th>

		<th style='width:14%; border-top:none;' colspan='2'>SGST</th>

		<th style='width:14%; border-top:none;' colspan='2'>IGST</th>

		<th style='width:10%; border-top:none; border-right:none;' rowspan='2'>Total</th></tr>

		

		<tr><th>Rate(%)</th><th>Amount</th><th>Rate(%)</th><th>Amount</th><th>Rate(%)</th><th>Amount</th></tr>

		

		<tr><th style='border-bottom:none; border-left:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none;'></th><th style='border-bottom:none; border-right:none;'></th></tr></thead>";

		

		$det=mysqli_query($conn,"select * from purchase where invoiceno='$id' order by ID asc");

		$tot=0;

		$sno=0;

		$wam=0;

		$wwt=0;

		$cgt=0;

		$sgt=0;

		$igt=0;	

		$qt=0;	

		while($det1=mysqli_fetch_assoc($det))

		{

		$sno=$sno+1;

		

		$pr=mysqli_query($conn,"select * from product where ID='$det1[product]'");

		$pr1=mysqli_fetch_assoc($pr);

		

		$rt=$det1['rate']*$det1['qty'];

		

		echo'<tr><td valign="top" style="border-bottom:none; border-left:none; padding:2px 0px 2px 0px; border-top:none; padding-left:11px;">'.$sno.'.</td>

		<td valign="top" style="border-bottom:none; border-left:none; padding:2px 3px 2px 3px; border-top:none;">'.$pr1['product'].'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['qty'].'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.number_format($det1['rate'],2,'.','').'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.number_format($rt,2,'.','').'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['cgst'].'%</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['cgst_amt'].'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['sgst'].'%</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['sgst_amt'].'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['igst'].'%</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; padding:2px 3px 2px 3px; border-top:none;">'.$det1['igst_amt'].'</td>

		<td valign="top" style="border-bottom:none; border-left:none; text-align:right; border-right:none; padding:2px 3px 2px 3px; border-top:none;">'.number_format($det1['total'],2,'.','').'</td></tr>';

		

		$qt=$qt+$det1['qty'];

		$tot=$tot+$rt;

		$wam=$wam+$det1['rate'];

		$wwt=$wwt+$det1['total'];

		$cgt=$cgt+$det1['cgst_amt'];

		$sgt=$sgt+$det1['sgst_amt'];

		$igt=$igt+$det1['igst_amt'];

		}

		

		echo"<tr><td style='height:100%; border-top:none; border-left:none;'></td><td style='height:100%; border-top:none;'></td><td style='height:100%; border-top:none;'></td><td style='height:100%; border-bottom:none; border-top:none;'></td><td style='height:100%; border-bottom:none; border-top:none;'></td><td style='height:100%; border-bottom:none; border-top:none;'></td><td style='height:100%; border-bottom:none; border-top:none;'></td><td style='height:100%; border-bottom:none; border-top:none;'></td><td style='height:100%; border-top:none;'></td><td style='height:100%; border-top:none;'></td><td style='height:100%; border-top:none;'></td><td style='height:100%; border-top:none; border-right:none;'></td></tr>";

		

		$gr=$tot-$get1['discount'];

		

		$grt=$gr;

		

		echo"<tr><td colspan='2' style='text-align:right; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>Total</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'>".number_format($qt,2,'.','')."</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'>".number_format($wam,2,'.','')."</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'>".number_format($tot,2,'.','')."</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'></td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'>".number_format($cgt,2,'.','')."</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'></td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'>".number_format($sgt,2,'.','')."</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'></td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px;'>".number_format($igt,2,'.','')."</td>

		<td style='border-top:1px solid #999; text-align:right; padding-right:3px; border-right:none;'>".number_format($wwt,2,'.','')."</td></tr>";

				

		

		

		echo"<tr><td colspan='8' rowspan='2' style='padding-left:11px; border-left:none;'>Amount in words : ";

		

		$total=number_format($wwt,0,'.','');

		

		include 'num_words.php';

		

		echo"</td>

		

		<td colspan='3' style='text-align:right; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>Total Without Tax</td><td style='border-top:1px solid #999; text-align:right; padding-right:3px; border-right:none;'>".number_format($tot,2,'.','')."</td></tr>";

		

		echo"<tr><td colspan='3' style='text-align:right; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>SGST</td><td style='border-top:1px solid #999; text-align:right; padding-right:3px; border-right:none;'>".number_format($sgt,2,'.','')."</td></tr>";

		

		echo"<tr><td colspan='8' rowspan='4' style='border-bottom:none; border-left:none; padding-left:11px;'><b>Bank Details</b> : 

				

		</td>

		

		<td colspan='3' style='text-align:right; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>CGST</td><td style='border-top:1px solid #999; text-align:right; padding-right:3px; border-right:none;'>".number_format($cgt,2,'.','')."</td></tr>";

				

		echo"<tr><td colspan='3' style='text-align:right; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>IGST</td><td style='border-top:1px solid #999; text-align:right; padding-right:3px; border-right:none;'>".number_format($igt,2,'.','')."</td></tr>";

		

		echo"<tr><td colspan='3' style='text-align:right; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>Discount</td><td style='border-top:1px solid #999; text-align:right; padding-right:3px; border-right:none;'>".number_format($get1['discount'],2,'.','')."</td></tr>";

		

		echo"<tr><td colspan='3' style='text-align:right; border-bottom:none; border-left:none; border-top:1px solid #999; height:21px; padding-right:5px;'>Total (Rounded Off)</td><td style='border-top:1px solid #999; border-right:none; border-bottom:none; text-align:right; padding-right:3px;'>".number_format($wwt,0,'.','').".00</td></tr>

		

		</table>

		

		</td></tr></tbody>

		

		<tfoot>

		

		<tr><td style='padding:0px; border-bottom:none; border-top:none;'>

		

		<table border='1' style='width:100%; margin:auto; border-color:#999; border-collapse:collapse; border:1px solid #999; border-top:none; border-bottom:none; border-left:none; border-right:none;'>				

			

		

		<tr><td style='width:55.2%; border-top:none; padding-top:5px; padding-left:5px; border-left:none;' height='50' valign='top'>

		

		<table>

		

		<tr><td>Declaration : </td></tr>

		

		<tr><td>We declare that this invoice shows the actual price of the goods described and that all particulars are true and correct.</td></tr>

		

		<tr><td valign='bottom' style='padding-top:31px; font-size:11px;'>Note : This is a system generated invoice.</td></tr>

		

		</table>

		

		</td>

		

		

		<td colspan='3' style='width:44.8%; text-align:right; border-top:none; padding-top:7px; border-right:none; padding-right:5px;' valign='bottom'>

		

		<table style='margin:auto;'>

		<tr><td>For ".$gtp1['company_name']."</td></tr>";

		

		if($digital=='1')

		{		

		echo"<tr><td style='padding:7px 0 7px 0;'><img src='img/sign2.jpg' width='125' height='37' /></td></tr>";

		}

		else

		{

		echo"<tr><td style='padding-top:70px;'></td></tr>";

		}

		

		echo"<tr><td valign='bottom' style='padding-bottom:3px;'>Authorised Signatory</td></tr>

		</table>

		

		</td></tr>

		

		</table>

		

		</td></tr>

		

		

		<tr><td colspan='2' style='border-top:none;'>

		

		<table style='width:100%;'>

		

		<tr><td style='width:25%;'></td>

		

		<td style='width:50%;'><table style='font-family:arial; margin:auto; font-size:11px;'>

		

		<tr><td>Thank you for making business with us.</td></tr>

		

		<tr><td style='text-align:center;'>&copy; ".$gtp1['company_name']."</td></tr>

		

		</table></td>

		

		<td style='width:25%; text-align:right; font-size:11px;' valign='top'>E&O.E</td></tr>

				

		</table>		

		

		</td></tr>

		

		

		</tfoot></table>";

		

	}

	

	

}

else

{ // Not logged in

  print "<META HTTP-EQUIV = 'Refresh' Content = '1; URL =login.php'>";

}

?>