<?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>SALES ORDER</title>';



echo"<style>

@page  

{ 

    size: auto;

    margin: 5mm 0mm 5mm 0mm;

} 

.main

{

min-height:500px;

}

.bottom

{

height:50px;

text-align:center;

}

table

{

font-size:12px;

font-family:arial;

}

table td

{

	padding:2px 5px;

}

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'];

		$check=$_GET['check'];

		

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

		$gtp1=mysqli_fetch_assoc($gtp);



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

		$get1=mysqli_fetch_assoc($get);

		

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

		$cus1=mysqli_fetch_assoc($cus);



$dis=mysqli_query($conn,"select * from districts where ID='$cus1[district]'");

$dis1=mysqli_fetch_assoc($dis);



$vill=mysqli_query($conn,"select * from villages where ID='$cus1[village]'");

$vill1=mysqli_fetch_assoc($vill);



$tlk=mysqli_query($conn,"select * from taluk where ID='$cus1[taluk]'");

$tlk1=mysqli_fetch_assoc($tlk);



		$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%; border-color:#999; border:1px solid #999; margin:17px auto; border-collapse:collapse;">

		

		<tr><td style="padding:0;">

		

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

		

		<tr><td style="width:33.3%; padding:0 0 0 0px; border-right:1px solid #999;">

		

		<table>

		

		<tr><td style="padding:0;">';

		

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

		$sett1=mysqli_fetch_assoc($sett);

		

		if($sett1['logo']!='')

		{

			echo'<img src="'.$sett1['logo'].'" width="80" height="80" style="margin-right:5px; margin-left:5px;" />';

		}

		

		echo'</td>

		

		<td>

		

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

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

		

		if($sett1['address']!='')

		{

        echo'<tr><td>'.$sett1['address'].'</td></tr>';

		}

				

		if($sett1['contact']!='')

		{

		echo'<tr><td>Contact: '.$sett1['contact'].'</td></tr>';

		}

		

		echo'<tr><td>GST IN: '.$sett1['gst'].'</td></tr>';

		

		echo'</table>

		

		</td></tr>

		

		</table>

		

		</td>

		

		

		<td style="text-align:center; width:33.3%; padding:0 0 0 0px; border-right:1px solid #999;">

		

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

		

		<tr><td colspan="3" style="text-align:center;"><b style="font-size:15px;">SALES ORDER</b></td></tr>

		

		</table>

		

		</td>

		

		

		<td style="text-align:center; width:33.3%;">

		

		<table style="line-height:23px; font-size:13px;">

		

		<tr><td style="padding-left:5px; padding-top:7px;">Order No</td><td style="padding-top:7px;">:</td><td style="padding-top:7px;"><b>'.$fin.'/'.$get1['orderno'].'</b></td></tr>

		

		<tr><td style="padding-left:5px;">Date</td><td>:</td><td>'.date('d-m-Y',strtotime($get1['date'])).'</td></tr>

		

		</table>

		

		</td></tr>

		

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

		

		

		<tr><td style="padding:0; border-bottom:none;">

		

		

		<table border="1" style="width:100%; border:none; margin:auto; line-height:25px; border-collapse:collapse;">

		

		

		<tr><td style="width:33.3%; border-left:none; border-top:none;">Name : '.$cus1['name'].'</td><td style="width:33.3%; border-top:none;">Father Name : '.$cus1['fathername'].'</td><td style="width:33.3%; border-top:none; border-right:none;"></td></tr>

		

		<tr><td style="width:33.3%; border-left:none;">Door No. : '.$cus1['doorno'].'</td><td style="width:33.3%;">Street : '.$cus1['street'].'</td><td style="width:33.3%; border-right:none;">Village : '.$vill1['village'].'</td></tr>

		

		<tr><td style="width:33.3%; border-left:none;">Post &amp; Via : '.$cus1['postcode'].'</td><td style="width:33.3%;">Taluk : '.$tlk1['taluk'].'</td><td style="width:33.3%; border-right:none;">District : '.$dis1['district'].'</td></tr>

		

		<tr><td style="width:33.3%; border-left:none;">Landmark : '.$cus1['landmark'].'</td><td style="width:33.3%;">Mobile 1 : '.$cus1['mobile1'].'</td><td style="width:33.3%; border-right:none;">Mobile 2 : '.$cus1['mobile2'].'</td></tr>



		<tr><td style="width:33.3%; border-bottom:none;">Expected Date : '.$get1['expecteddate'].'</td><td style="width:33.3%; border-bottom:none;">Confirmed Date : '.$get1['confirmeddate'].'</td><td style="width:33.3%; border-right:none; border-bottom:none;"></td></tr>

		

		</table>

		

		

		</td></tr>';

		

		

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

		

		<table style="width:100%; border-collapse:collapse; border:none; height:370px; border-color:#999;" id="invoice" border="1">

		<tr><th style="width:6%; border-left:none;">S.No</th><th style="width:27.3%; border-left:none;">Product</th>

		<th style="width:10%; border-left:none;">HSN SAC</th><th style="width:11%;">Qty</th>

		<th style="width:12%;">Rate</th><th style="width:11%;">Amount</th>

		<th style="width:11%;">Discount</th><th style="width:11.3%; border-right:none;">Taxable Amt</th></tr>';

		

		$list=mysqli_query($conn,"select * from sales_order where orderno='$id' order by ID ASC") or die("unable to get");

		$sno=0;

		$rate=0;

		$qty=0;

		$tvat=0;

		$cgt=0;

		$sgt=0;

		$igt=0;

		$wtt=0;

		while($list1=mysqli_fetch_assoc($list))

		{

			$sno=$sno+1;

			$total=$list1['total'];

			

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

			

			$dis=$list1['discount'];

			

			$rowtotal=$rt-$dis;

			

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

			$pnm1=mysqli_fetch_assoc($pnm);

			

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

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

			<td style="border-bottom:none; padding-bottom:3px; border-top:none;">'.$list1['hsncode'].'</td>

			<td style="border-bottom:none; padding-bottom:3px; padding-right:1px; border-top:none; text-align:right;">'.$list1['qty'].' <b>'.$pnm1['unit'].'</b></td>

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

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

			<td style="border-bottom:none; padding-bottom:3px; border-top:none; text-align:right;">'.$list1['discount'].'</td>

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

			

			$rowt=$rowt+$rt;

			$qty=$qty+$list1['qty'];

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

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

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

			$wtt=$wtt+$rowtotal;

		}

		

		echo"<tr><td style='border-left:none; border-top:none; height:100%;'></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;'></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>";

		

		$sub=$get1['total'];

		

		$totgst=$cgt+$sgt+$igt;

		

		echo '<tr><td colspan="3" style="text-align:right; border-left:none;">Total</td>

		

		<td style="text-align:right; padding-right:2px;">'.$qty.'</td>

		

		<td style="text-align:right;"></td>

		

		<td style="text-align:right;">'.number_format($rowt,2,'.','').'</td>

		

		<td style="text-align:right;"></td><td style="text-align:right; border-right:none; padding-right:5px;">'.number_format($wtt,2,'.','').'</td></tr>';

		

		

		$tot=$get1['total']+$get1['freight']+$get1['loading_charges']+$get1['adjustment'];

				

		if($totgst!=0)

		{

		

		$jj=mysqli_query($conn,"select * from invoice where invoiceno='$id' and (cgst!='0.00' OR sgst!='0.00' OR igst!='0.00')");

		$jj1=mysqli_fetch_assoc($jj);

		

		$sugst=$get1['cgst']+$get1['sgst']+$get1['igst'];

		}

		

		echo'<tr><td colspan="5" valign="top" style="border-left:none; padding-left:7px; width:50%;">

		

		<table style="border:none;">

		

		<tr><td><b>Amount in words :</b> '; $total=number_format($tot,0,'.',''); include 'num_words.php'; echo'</td></tr>';

		

		if($get1['narration']!='')

		{

		echo'<tr><td style="padding:3px 0 0 2px; font-size:10px;"><b>Narration:</b> '.$get1['narration'].'</td></tr>';

		}

			

			

		if($sett1['terms']!='')

		{

					

		echo'<tr><td style="padding:3px 0 0 2px; font-size:10px;"><b>Terms:</b> '.$sett1['terms'].'</td></tr>';

		

		}

		

		echo'</table></td>';

		

		echo'<td colspan="3" rowspan="3" style="text-align:right; border-bottom:none; border-right:none; height:137px;" valign="top">

		

		<table style="width:100%; height:107px; float:right; border:none;">

		

		<tr><td style="text-align:right; width:70%;">Total Taxable Value : </td><td style="text-align:right;">'.number_format($wtt,2,'.','').'</td></tr>';

		

		if($cgt!=0 && $sgt!=0)

		{

		echo"<tr><td style='width:70%; padding:7px 0 0 0;'>

		

		<table style='width:100%; font-size:9px; border:none; border-collapse:collape;'>

		

		<tr><td style='width:60%;'>CGST (".number_format($get1['cgst'],2,'.','')."%) : ".number_format($cgt,2,'.','')."</td>

		<td rowspan='2' style='width:5%;'><img src='assets/images/cl.png' /></td>

		<td rowspan='2' style='width:35%; text-align:right;'><b style='font-size:10px;'>GST: ".$sugst."% : </b></td></tr>

		

		<tr><td>SGST (".number_format($get1['sgst'],2,'.','')."%) : ".number_format($sgt,2,'.','')."</td></tr>

		

		</table>

		

		</td><td style='text-align:right; padding-top:11px;'>".number_format($totgst,2,'.','')."</td></tr>";

		}

		elseif($igt!=0)

		{

		echo"<tr><td style='padding-top:7px;'>IGST (".number_format($get1['igst'],2,'.','')."%) : &nbsp; ".number_format($igt,2,'.','')."</td><td style='text-align:right;'>".number_format($totgst,2,'.','')."</td></tr>";

		}





		echo'<tr><td colspan="2" style="height:100%;"></td></tr></table>



		<table style="width:97%; float:right; border:none; margin-bottom:7px;">

		

		<tr><td style="width:40%; padding-top:15px; padding-left:5px;"><b style="font-size:13px;">Grand Total : </b></td>

		

		<td style="padding-top:11px; text-align:right;"><img src="assets/images/rupee.png" width="12" height="17" />.&nbsp;<b style="font-size:25px;">'.number_format($tot,0,'.','').'.00</b></td></tr>		

		

		<tr><td></td><td style="padding:5px 3px 2px 0; text-align:right;">E&O.E</td></tr>

		

		</table>

		

		</td></tr>

		

		

		<tr><td colspan="2" valign="bottom" style="border-bottom:none; border-right:none; border-left:none; padding-bottom:11px;">

		

		<table style="width:100%; border:none;">



		<tr><td style="text-align:center;">For '.$sett1['name'].'</td></tr>';

		

		if($check==1)

		{

			

		echo'<tr><td style="text-align:center;">';

		

		echo'<img src="assets/images/sign.png" width="60" height="82" />';

		

		echo'</td></tr>';

		

		}

		

		else

		{

			echo'<tr><td style="height:45px;"></td></tr>';

		}

		

		echo'

		

		<tr><td style="text-align:center;">Authorised Signatory</td></tr>

		

		</table>



		</td>



		<td colspan="3" valign="bottom" style="border-bottom:none;">

		

		

		<table style="margin:auto;">

		

		<tr><td style="padding-bottom:7px;">Telemarketing Signatory</td></tr>

		

		</table>

		

		

		</td></tr>

		

		</table>

		

		</td></tr>';



		echo'</table>';

		

	}

	

	

}

else

{ // Not logged in

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

}

?>

