<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
	
/*
$qry=mysqli_query($db,"select * from sparestock");
while($row=mysqli_fetch_array($qry))
{
	$mitem_code = $row[itemcode];
	$mbrcode = $row[brcode];
	if(strlen($row[item_grp])<=0)
	{
	$brqry="select gname,subgroup from partmaster where partcode = '$mitem_code'";
	$brrs=mysqli_query($db,$brqry);
	$brrw=mysqli_fetch_array($brrs);
	$mgname=$brrw[0];
        $msubgnm=$brrw[1];
	$sql="update sparestock set item_grp = '$mgname',item_subgrp='$msubgnm' where itemcode = '$mitem_code' and brcode='$mbrcode'";
	mysqli_query($db,$sql)or die(mysqli_error($db));
	print $i."==".$sql."<br>";
	}
}


$inv=mysqli_query($db,"select invdate as date,invno,jvno,customer as partic,sum(nettot) as inv_tot,sum(mba) as mba,sum(strbtnml) as strbtnml,sum(strbtspl) as strbtspl,sum(taxamt) as taxamt,pmode,gname,staffdisc,sum(total) as tot from prod_invoice where invno >  4330 group by invno");
while($inv_row=mysqli_fetch_array($inv))
{
	if ($inv_row[pmode]=='CREDIT')
    		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Dr','$inv_row[partic]','$inv_row[inv_tot]','0','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale Credit',' ','','0')";
	else
    		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Dr','Cash','$inv_row[inv_tot]','0','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale Cash',' ','','0')";
	mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
        echo $sql;
        echo "<br>";
	$inv1=mysqli_query($db,"select sum(total) as tot,gname from prod_invoice where invno = '$inv_row[invno]' group by gname");
	while($inv1_row=mysqli_fetch_array($inv1))
	{
        	if($inv1_row[tot]>0)
        	{
          		$mled = $inv1_row[gname].' Sale';
          		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Cr','$mled','0','$inv1_row[tot]','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale',' ','','0')";
          		mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
                         echo $sql;
        echo "<br>";
		}

	}
	$inv1=mysqli_query($db,"select sum(taxamt) as tot,tax from prod_invoice where invno = '$inv_row[invno]' group by tax");
	while($inv1_row=mysqli_fetch_array($inv1))
	{
        	if($inv1_row[tot]>0)
		{
	          	$mled = 'Output Tax - VAT@'.$inv1_row[tax].'%';
          		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Cr','$mled','0','$inv1_row[tot]','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale',' ','','0')";
		       mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
                        echo $sql;
        echo "<br>";
		}
	}
    	if($inv_row[mba]>0)
    	{
      		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Dr','MDA on Item Sale','$inv_row[mba]','0','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale',' ','','0')";
      		mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
                 echo $sql;
        echo "<br>";
    	}
    	if($inv_row[strbtnml]>0)
    	{
      		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Dr','State Rebate(Normal)on Khadi Sale','$inv_row[strbtnml]','0','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale',' ','','0')";
      		mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
                 echo $sql;
        echo "<br>";
    	}
	if($inv_row[strbtspl]>0)
    	{
      		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Dr','State Rebate(Special)on Khadi Sale','$inv_row[strbtspl]','0','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale',' ','','0')";
      		mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
                 echo $sql;
        echo "<br>";
    	}
        if($inv_row[staffdisc]>0)
    	{
		$staff_amt = $inv_row[tot]*$inv_row[staffdisc]/100;
      		$sql="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no) values('$inv_row[date]','$inv_row[jvno]','Dr','Stffdiscount on Khadi Sale','$staff_amt','0','Khadi Counter Sale Inv No.: $inv_row[invno]','PAY005','Counter Sale',' ','','0')";
                mysqli_query($db,$sql) or die('Led Post Err1'.mysqli_error($db));
                 echo $sql;
        //echo "<br>";
    	}
}
*/
?>
