<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$inno=$_REQUEST['invno'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
include('test.php');
if(1>0)
{
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>PSN</title>	

<style>

body{
  -webkit-print-color-adjust:exact;
}
.printable{ 
      page-break-before: always;

      margin-top:30px;
    }
.tbl
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
text-transform:uppercase;
}
.tbl td
{
border: 0px solid black;
}
#tbl
{
border: 1px solid black;

}
.tble 
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-transform:uppercase;

}
.tble  td{
height:15px;
margin-left:10px;
margin-right:10px;
padding-left:10px;
padding-right:10px;
}

.tble th
{
border:1px solid black;
}
.tbl1{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-align:left;
font-weight: bold;
text-transform:uppercase;
}
.tbl1 td{
border-bottom:1px solid black;
height:10px;
}

#add_td{
font-size:12px;
height:15px;
}
#add_td br{
margin:0px;
padding:0px;
}
.tot_td{
border-bottom:0px solid black;
}
.tot_td1{
border-top:0px solid black;
}
#tot_tbl td{
border:1px solid black;
border-collapse:collapse;
}
body
 {font-family:Arial;
   }

p{
 margin:0px;
 padding:0px;
 }


  @media print
        {
            #head
            {
                background-color:grey;
            }
        }

</style>

<body onload="window.print()" >
    <?
//    $rs1=mysqli_query($db,"select * from dlvrychlnreg where delvno='$inno' and brcode='$brcode'");
//$rw1=mysqli_fetch_array($rs1);
$q_count2=mysqli_query($db,"select count(*) from veh_trans where invno='$inno' and brcode='$brcode'");
  
    $cnt2=mysqli_fetch_array($q_count2);
   

    $count=$cnt2[0];
    if(strlen($count)<=0)
    {
        $count=0;
    }

    //$limit=23;
    $limit=27;
    $pg_no=floor($count/$limit);
    

$i=1;
//$rs1=mysqli_query($db,"select * from dlvrychlnreg where delvno='$inno' and brcode='$brcode'");
//$rw1=mysqli_fetch_array($rs1);

    $res2=mysqli_query($db,"select * from veh_trans where invno='$inno' and brcode='$brcode'");
   // print "select * from sparetransout where saprefno='$inno' and brcode='$brcode'";
	while($res3=mysqli_fetch_array($res2))
	{
        $slno[$i]=$i;
        $code[$i]=$res3['partcode'];
        $item[$i]=$res3['partname'];
        $qty[$i] =$res3['qty'];
        $rate[$i]=$res3['amount'];
		$ltot+=$res3['amount'];
        		$tot[$i]=$res3['amount']*$res3['qty'];
		$sql1=mysqli_query($db,"select * from partmaster where partcode='$res3[partcode]'");
        $row1=mysqli_fetch_array($sql1);
        $hsn[$i]=$row1['hsncode'];
    
		    $cgstprc[$i]=$row1['tax_sales']/2;
		    $sgstprc[$i]=$row1['tax_sales']/2;
		    $igstprc[$i]=$row1['tax_sales'];

		$prttot+=$res3['amount'];
		$qtytot+=$res3['qty'];
		$ptot+=$tot[$i];
		$i++;
             
	}
	$tot_fill=0;

 for($p=0;$p<=$pg_no;$p++)
 {
   if($p==$pg_no)
      {
       $tot_fill=1;
      }
               /* to fill total amt in last table if it is last print page */
   $lower_lmt=($p*$limit)+1;
    $upper_lmt=($p+1)*$limit;
    

    ?>
<div width=100%>           
 <form id="jforms" name="invoice_form" >

<table width=100% align='center' border='0' <? if($p>0){
           ?>
            class='printable'
           <?
           }
           ?>
           >
<tr>
<td align='center'></td>
</tr>
<?
$query="select brname,braddr,brcity,tin,cstno,brstate from branch where brcode ='$brcode'";
//print $p;
//print "$query";
$rs=mysqli_query($db,$query);
$brw=mysqli_fetch_array($rs);
?>


<table border='0' width='100%' 
<? if($p>=0){
    print "hi";
           ?>
           
            class='printable'
           <?
           }
           ?>
<tr>
	<td align='center' width='100%' id='add_td'> 
<?

	$qry1=mysqli_query($db,"select * from branch where brcode='$brcode'");
	//print "select * from branch where brcode='$brcode'";
	$row1=mysqli_fetch_array($qry1);
		print "<p style='font-size: 20px;'></p>";
	print "<font size='5'><b>PSN AUTOMOTIVE MARKETING PVT LTD</b></font></p>";
	print "<font size='2'><b>Reg. Off: 2/330, Cheranalloor,</b></font><p >Eranakulam-34,<b><br>Phone : 0484-4098309<br>CIN :U50300KL1996PTC010841 ";
	
	//if($row1[11]!='')
	//	print ",".$row1[11]."<br>Web: ".$row1[12];
	//else
		//print "</p><p>Web: ".$row1[12];
		$fromdt1=implode('-', array_reverse(explode('-', $row['entrydate'])));
		
	    //$brcol=substr($row[mnfr_code],0,3).'_ret_spr';
        //$tr = "select $brcol from branch where brcode = '$brcode'";
        //print $tr;
        //$trd=mysqli_query($db,$tr);
        //$trdrow=mysqli_fetch_row($trd);
        ?>
	</td>
<tr>
<tr><td align='center'></td></tr></table>
<?
//$rs1=mysqli_query($db,"select * from dlvrychlnreg where delvno='$inno' and brcode='$brcode'");
//$rw1=mysqli_fetch_array($rs1);
$rs=mysqli_query($db,"select * from veh_trans where invno='$inno' and brcode = '$brcode' ");
$rw=mysqli_fetch_array($rs);

$rsc=mysqli_query($db,"select * from consign_mast where name='$rw[consignee]'  ");
//print "select * from consign_mast where name='$rw[consignee]'  ";
$rwc=mysqli_fetch_array($rsc);
?>
<table border='1' width='100%' style="border-collapse: collapse;"><tr>
	    <td  align='center' width='70%'><H4><b>DELIVERY CHALLAN <br> (Rule 55 of the GST Rules 2017)</td>
	    <td  align='left' width='30%'>
<table style="font-size: 12px;"><tr><td>ORIGINAL for Consignee</td></tr><tr><td>DUPLICATE for Transporter</td></tr><tr><td>TRIPLICATE for Consignor</td></tr></table>
		</td>
	</tr></table>
	<table width=100% class='tbl1' id='tbl' border='1'>
    <tr><td width=40%>
        <table width=100%  border='0'>
           <tr>
            <td >Details of Consigner</td> 
           </tr>
           <tr>
            <td>Name   : PSN AUTOMOTIVE MARKETING PVT LTD</td>  
           </tr>
           <tr>
            <td>Address   :   <? echo $row1['braddr'] ?></td>
            <?
            //$rw1[toaddr]
            ?>
           </tr>
           <tr><td>City :   <? echo $row1['brcity'] ?></td></tr>
	    <tr><td></td></tr>
           <tr>
            <td>GSTIN/Unique ID  :   <? echo $row1['cstno'] ?></td> 
           </tr>
		<tr>
            <td>State      :     <? echo $row1['brstate'] ?></td>
           </tr>
           
           </table> </td><td width=40%>       <table width=100%  border='0'>
           <tr>
            <td >Details of Consignee</td> 
           </tr>
           <tr>
            <td>Name   :  <?echo $rw['consignee'] ?></td>  
           </tr>
           <tr>
            <td>Address   :   <? echo $rwc['addr'] ?></td>
            <?
            //$rw1[toaddr]
            ?>
           </tr>
           <tr><td></td></tr>
	    <tr><td></td></tr>
           <tr>
            <td>GSTIN/Unique ID  :   <? echo $rwc['gstno'] ?></td> 
           </tr>
		<tr>
            <td>State      :     <? echo $rwc['state'] ?></td>
           </tr>
           
           </table> 
    </td>
    
    <td width=30%>
       <table width=100%  border='0'>
           <tr>
            <td colspan=3>Challan No   :   <?echo $rw['invno']?></td>   
           </tr>
           
           <?
           $fromdt1=implode('-', array_reverse(explode('-', $rw['invdate'])));
           ?>
           <tr>
            <td>Challan Date    :   <?echo $fromdt1?></td> 
           </tr>
           <tr>
            <!-- <td>Place Of Supply :    <?echo $rw['consaddr']?></td>  !-->
           </tr>
           <tr>
            <!--             <td>State  :    KERALA</td> !-->
           </tr>
		<tr>
            <!-- <td>State Code  :    KL-32</td>   !-->
           </tr>
		<tr>
            <td>Transportation Mode</td>    
           </tr>

           <tr>
            <td>Vehicle No:   <?echo $rw['vehno']?></td>  
           </tr>
        
            <tr>
            <td>Transporter Id:   <?echo $rw['transid']?></td>  
           </tr>
           <tr>
            <td>Internal Ref. No.:   <?echo $rw['fin']?></td>  
           </tr>
           </table> 
        
    </td>
        
        
        
        
	</tr>
	<tr><td align='left' colspan=2><b>PURPOSE OF TRANSPORTATION :- <?echo $rw['remark']?></td></tr>
	</table>
	
	

<table width=99%   align='center' class='tbl1' border='1' style="text-align: center;">
<tr ><td>SL No.</td><td>Code</td><td>Description of Product</td><td>HSN<br>Code</td><td>Qty</td>
<td>Amount &#8377;</td><td>Applicable <br>CGST Tax%</td><td>Appicable <br>CGST Amount</td>
<td>Appicable <br> SGST Tax%</td><td>Appicable <br>SGST Amount</td><td>Appicable <br> IGST Tax%</td><td>Appicable <br>IGST Amount</td><td>Cess Amount</td>

<td>Total</td></tr>
<?
$mtot_cgst = 0;
$mtot_sgst = 0;
$mtot1_11  = 0;
$i=1;
$rs3=mysqli_query($db,"select * from veh_trans where invno='$inno' and brcode = '$brcode' ");
$mtotqt=0;
$mtotnetamt=0;
$mtotcgstamt=0;
$mtotsgstamt=0;
$mtotigstamt=0;
$mtotamt2=0;
while($res3=mysqli_fetch_array($rs3))
{
	print "<tr><td >$i</td><td></td><td align=left>".$res3['config']."</td>";
	print "<td>$res3[segment]</td><td>$res3[qty]</td><td>$res3[netamt]</td>";
	if($res3['type']=='INTRASTATE')
	{
	 print"<td>".($res3['taxp']/2)."</td><td>$res3[cgstamt]</td><td>".($res3['taxp']/2)."</td><td>$res3[sgstamt]</td><td>0</td><td>0</td><td>$mcesamt</td><td>$res3[amt2]</td></tr>";   
	}
	else
	{
	 print"<td>0</td><td>0</td><td>0</td><td>0</td><td>".($res3['taxp'])."</td><td>$res3[igstamt]</td><td>$mcesamt</td><td>$res3[amt2]</td></tr>";   
	}
	
	$i++;
	$mtotqt+=$res3['qty'];
	$mtotnetamt+=$res3['netamt'];
	$mtotcgstamt+=$res3['cgstamt'];
	$mtotsgstamt+=$res3['sgstamt'];
	$mtotigstamt+=$res3['igstamt'];
	$mtotamt2+=$res3['amt2'];
}
for ($ctr=1;$ctr<=10;$ctr++)
{
	print "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
}
?>

<tr><td colspan='4' align='center'>Net Amount &#8377;</td><td><? echo $mtotqty?></td><td><? echo $mtotnetamt?></td>
<td></td><td><? echo $mtotcgstamt?></td><td>  </td><td><? echo $mtotsgstamt?></td><td></td><td><? echo $mtotigstamt?></td><td><? echo $mcesamt?></td>
<td align='right'><? echo round($mtotamt2,2) ?></td></tr>

</table>
<table  width=100% class='tbl1' id='tbl' border='1' style="text-align: center;">
	<tr><td align='left'  width='60%' ><b>Total Invoice Amount in Word :</b> <? echo word($mtotamt2); ?> </td><td rowspan='8'>

       <table border=0 style='border:0px solid white; ' width=100%>
	<tr>
	<td style='border:0px solid white;text-align:center;text-transform:none;'>Certified that the particulars given above are true and correct.</td>
	<td style='border:0px solid white; text-align:right;'></td>
	</tr>
	<tr>
	<td style='border:0px solid white;text-align:center;text-transform:none;'>FOR, PSN AUTOMOTIVE MARKETING PVT LTD</td>
	<td style='border:0px solid white; text-align:right;'></td>
	</tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:center;text-transform:none;'>Authorised Signatory</td><td style='border:0px solid white; text-align:right;'></td></tr>

	</table>


	</td></tr>

	<tr><td >
	<table border=0 style='border:0px solid white; ' width=100%><tr>
	<td style='border:0px solid white;text-align:left;text-transform:none;'>Terms & Conditions:<?echo $rw1['narr']?></td>
	<td style='border:0px solid white; text-align:right;'> </td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>
	<tr><td style='border:0px solid white;text-align:left;text-transform:none;'></td><td style='border:0px solid white; text-align:right;'></td></tr>

	</table>


	</td>

	</tr></table>
</table>
</div>
 </form>
</body></html>
<?
}
}
?>


