<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include_once('testtot.php');
$dfrom=$_REQUEST['dfrom'];
$dto=$_REQUEST['dto'];
$type=$_REQUEST['type'];
$dfrom = implode('-', array_reverse(explode('-', $dfrom)));
$dto = implode('-', array_reverse(explode('-', $dto)));
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
$brname= $brrow[brname];
$brcity= $brrow[brcity];
$file =  'form4.prn';
$handle = fopen($file, 'w');
$dss=chr(27).chr(71).chr(N);
$dse=chr(27).chr(72);
$initialized = chr(27).chr(64);
$load = chr(27).chr(25).chr(66);
$bold = chr(27).chr(14);
$unbold = chr(20);
$pagelenth=chr(27).chr(67).chr(36);
$Data = $initialized;
?>
<body bgcolor="#0033FF">


<?php //include('includes/top.php'); ?>
<center>
<style>
.trcls
{
font-family:Calibri;
}
.tbl1{
border: 1px solid black;
border-bottom:0px solid white;
font-family:Calibri;
border-collapse:collapse;
text-align:center;
margin-top:25px;
}
.tbl1 tr{
border-bottom:1px solid black;

}
</style>



<font   > <? print "<B>FORM 4</B> <BR> From ".$dfrom." To ".$dto;?></font>


<link rel="stylesheet" href="style.css" type="text/css" />
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />

<style>
  //tr1{background-color:white}
  th{
            background-color:steelblue;color:white;
            font-weight: normal;
        }

</style>
<center>

<?
$tbl="form4".$brcode.$user;
mysqli_query($db,"drop table $tbl");
mysqli_query($db,"CREATE TABLE $tbl (partcode varchar(200),partname varchar(200),op_inqty_apr double(10,2) default 0,op_inqty double(10,2) default 0,op_outqty double(10,2) default 0, stkadj_in double(10,2) default 0, stkadj_out double(12,2) default 0,purch_in double(12,2) default 0,salertn_in double(12,2) default 0,trans_in double(12,2) default 0,trans_out double(12,2) default 0,sale_out double(12,2) default 0,purchrtn_out double(12,2) default 0,price double(12,2),gname varchar(100),sale_out_apr double(12,2),trans_in_apr double(12,2),trans_out_apr double(12,2),salertn_in_apr double(12,2),sale_amt double(12,2))");
mysqli_query($db,"delete from $tbl");
if($type=='All')
{
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,op_outqty,gname) select partcode,partname,sum(qty),sum(outqty),gname from adjstock where  brcode='$brcode' and entrydate<'$dfrom' group by partcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,price) select partcode,lstprice from spareprmast where brcode='$brcode'") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,gname) select item_code,item,sum(qty),gname from itempurchase where brcode='$brcode' and  invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,op_inqty_apr,gname) select itemcode,itemname,sum(opstk),sum(opstk),item_grp from sparestock where brcode='$brcode' group by itemcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,salertn_in_apr,gname) select item_code,item,sum(rtnqty),sum(rtnqty),gname from salesretn where brcode='$brcode' and invdate<'$dfrom'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty,trans_out_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferout where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,trans_in_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferin where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty,sale_out_apr,gname) select item_code,item,sum(qty),sum(total),gname from prod_invoice where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty,gname) select item_code,item,sum(qty),gname from purchretn where brcode='$brcode' and invdate<'$dfrom' group by item_code") or die('err12'.mysqli_error($db));
//****************************************************************************** in out*******
  mysqli_query($db,"insert into $tbl (partcode,partname,stkadj_in,stkadj_out,gname) select partcode,partname,sum(qty),sum(outqty),gname from adjstock where brcode='$brcode' and entrydate>='$dfrom' and entrydate <='$dto' group by partcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,purch_in,gname) select item_code,item,sum(qty),gname from itempurchase where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,salertn_in,salertn_in_apr,gname) select item_code,item,sum(rtnqty),sum(rtnqty),gname from salesretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,trans_out,trans_out_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferout where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,trans_in,trans_in_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferin where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,sale_out,sale_out_apr,sale_amt,gname) select item_code,item,sum(qty),sum(total),sum(total),gname from prod_invoice where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,purchrtn_out,gname) select item_code,item,sum(qty),gname from purchretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto'  group by item_code") or die('err12'.mysqli_error($db));
}
else
{
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,op_outqty,gname) select partcode,partname,sum(qty),sum(outqty),gname from adjstock where  brcode='$brcode' and entrydate<'$dfrom' and gname = '$type' group by partcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,price) select partcode,lstprice from spareprmast where brcode='$brcode'") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,gname) select item_code,item,sum(qty),gname from itempurchase where brcode='$brcode' and  invdate<'$dfrom' and gname = '$type'  group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,op_inqty_apr,gname) select itemcode,itemname,sum(opstk),sum(opstk),item_grp from sparestock where brcode='$brcode' and item_grp = '$type' group by itemcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,salertn_in_apr,gname) select item_code,item,sum(rtnqty),sum(rtnqty),gname from salesretn where brcode='$brcode' and invdate<'$dfrom' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty,trans_out_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferout where brcode='$brcode' and invdate<'$dfrom' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_inqty,trans_in_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferin where brcode='$brcode' and invdate<'$dfrom' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty,sale_out_apr,gname) select item_code,item,sum(qty),sum(total),gname from prod_invoice where brcode='$brcode' and invdate<'$dfrom' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,op_outqty,gname) select item_code,item,sum(qty),gname from purchretn where brcode='$brcode' and invdate<'$dfrom' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
//****************************************************************************** in out*******
  mysqli_query($db,"insert into $tbl (partcode,partname,stkadj_in,stkadj_out,gname) select partcode,partname,sum(qty),sum(outqty),gname from adjstock where brcode='$brcode' and entrydate>='$dfrom' and entrydate <='$dto' and gname = '$type' group by partcode") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,purch_in,gname) select item_code,item,sum(qty),gname from itempurchase where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,salertn_in,salertn_in_apr,gname) select item_code,item,sum(rtnqty),sum(rtnqty),gname from salesretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,trans_out,trans_out_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferout where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,trans_in,trans_in_apr,gname) select item_code,item,sum(qty),sum(qty),gname from brtransferin where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,sale_out,sale_out_apr,sale_amt,gname) select item_code,item,sum(qty),sum(total),sum(total),gname from prod_invoice where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
  mysqli_query($db,"insert into $tbl (partcode,partname,purchrtn_out,gname) select item_code,item,sum(qty),gname from purchretn where brcode='$brcode' and invdate>='$dfrom' and invdate <='$dto' and gname = '$type' group by item_code") or die('err12'.mysqli_error($db));
}
//**************************************
$re=mysqli_query($db,"select partcode,partname,sum(op_inqty),sum(op_outqty),sum(purch_in),sum(trans_in),sum(salertn_in),sum(stkadj_in),sum(sale_out),sum(trans_out),sum(purchrtn_out),sum(stkadj_out),max(price),max(gname),sum(op_inqty_apr),sum(salertn_in_apr),sum(trans_out_apr),sum(trans_in_apr),sum(sale_out_apr),sum(sale_amt) from $tbl group by partcode");

$i=1;
$tprice=0;
$mgname[]='';
$mop[]=0;
$mpurch[]=0;
$mtran_in[]=0;
$msalesrtn[]=0;
$msales[]=0;
$mtran_out[]=0;
$mpurchret[]=0;
$mclose[]=0;
$mop_prog[]=0;
$msalesrtn_prog[]=0;
$mtran_out_prog[]=0;
$mtran_in_prog[]=0;
$msales_prog[]=0;
$ctr=1;
while($row=mysqli_fetch_array($re))
{

  if($row[13])
  {
  $key = array_search($row[13],$mgname);
  if($key)
  {

    $op_qty =($row[2]-$row[3]);
    $mop[$key] += (($row[2]-$row[3])*$row[12]);
    $mpurch[$key] += (($row[4])*$row[12]);
    $mtran_in[$key] += (($row[5])*$row[12]);
    $msalesrtn[$key] += (($row[6])*$row[12]);
//    $msales[$key] += (($row[8])*$row[12]);
    $msales[$key] += $row[19];
    $mtran_out[$key] += (($row[9])*$row[12]);
    $mpurchret[$key] += (($row[10])*$row[12]);
    $close = $op_qty+($row[4]+$row[5]+$row[6]+$row[7])-($row[9]+$row[10]+$row[11]);
    $mclose[$key] +=($close*$row[12])-$row[19]; ;
    $mop_prog[$key] +=(($row[14]*$row[12]));
    $msalesrtn_prog[$key] +=(($row[15]*$row[12]));
    $mtran_out_prog[$key] +=(($row[16]*$row[12]));
    $mtran_in_prog[$key] +=(($row[17]*$row[12]));
    $msales_prog[$key] +=$row[18];
  }
  else
  {
    $mgname[$ctr] = $row[13];
    $op_qty =($row[2]-$row[3]);
    $mop[$ctr] += (($row[2]-$row[3])*$row[12]);
    $mpurch[$ctr] += (($row[4])*$row[12]);
    $mtran_in[$ctr] += (($row[5])*$row[12]);
    $msalesrtn[$ctr] += (($row[6])*$row[12]);
//    $msales[$ctr] += (($row[8])*$row[12]);
    $msales[$ctr] += $row[19];
    $mtran_out[$ctr] += (($row[9])*$row[12]);
    $mpurchret[$ctr] += (($row[10])*$row[12]);
    $close = $op_qty+($row[4]+$row[5]+$row[6]+$row[7])-($row[9]+$row[10]+$row[11]);
       $mclose[$ctr] +=($close*$row[12])-$row[19];
    $mop_prog[$ctr] +=(($row[14]*$row[12]));
    $msalesrtn_prog[$ctr] +=(($row[15]*$row[12]));
    $mtran_out_prog[$ctr] +=(($row[16]*$row[12]));
    $mtran_in_prog[$ctr] +=(($row[17]*$row[12]));
    $msales_prog[$ctr] +=$row[18];
    $ctr++;
  }
  }
}
?>
<?
for ($ctr1=1;$ctr1<=$ctr;$ctr1++)
{
//  print $mgname[$ctr1]."dqqw<br>";
}
?>
<table border="0">
<tr><td align='center'><? echo $brrow[brname] ?></td>
</tr>
<br>
<?$mon = date("M Y", strtotime("$dto"));
$Data .=  "          Monthly Stock Statement for the Month of $mon\n\n";
//<tr><td align='center'>Monthly Stock Statement for the Month of </td>
//</tr>
//</table>
$qr=mysqli_query($db,"select * from branch where brname='$rw[2]'");
$qw=mysqli_fetch_array($qr);
$Data .= chr(15)."\n\n";
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
$Data .= "|         Particulars          | Current Month | Progressive Total |         Particulars          | Current Month | Progressive Total |\n";
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
$Data .= "|         OPENING STOCK        |               |                   |         SALES                |               |                   |\n";
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
?>
<?//<table width=100%   align='center' class='tbl1' border='1'>
//<tr ><td align='left'><b>Particulars</td><td align='right'><b>Current Month</td><td align='right'><b>Progressive Total</td><td align='left'><b>Particulars</td><td align='right'><b>Current Month</td><td align='right'><b>Progressive Total</td></tr>
//<tr><th colspan="3" align="left">OPENING STOCK:</th><th colspan="3" align="left">SALES:</th></tr>?>
<?
$mtot1 = 0;
$mtot2 = 0;
$mptot1 = 0;
$mptot2 = 0;
for ($ctr1=1;$ctr1<=$ctr-1;$ctr1++)
{
  $Data .= "| ".substr($mgname[$ctr1].str_repeat(" ",29),0,29);
  $mnum = number_format($mop[$ctr1], 2, '.', '');
  $mtot1 += $mop[$ctr1];
  $Data .= "| ".substr(str_repeat(" ",14).$mnum,-14);
  $mnum = number_format($mop_prog[$ctr1], 2, '.', '');
  $Data .= "| ".substr(str_repeat(" ",18).$mnum,-18);
  $mptot1 += $mop_prog[$ctr1];
  $Data .= "| ".substr($mgname[$ctr1].str_repeat(" ",29),0,29);
  $mnum = number_format($msales[$ctr1], 2, '.', '');
  $mtot2 += $msales[$ctr1];
  $mptot2 += $msales_prog[$ctr1];
  $Data .= "| ".substr(str_repeat(" ",14).$mnum,-14);
  $mnum = number_format($msales_prog[$ctr1], 2, '.', '');
  $Data .= "| ".substr(str_repeat(" ",18).$mnum,-18)."|\n";
//  print "<tr><td align='left'>&nbsp &nbsp &nbsp".$mgname[$ctr1]."</td><td align='right'>".number_format($mop[$ctr1], 2, '.', ',')."</td><td align='right'>".number_format($mop_prog[$ctr1], 2, '.', ',')."</td>";
//  print "<td align='left'>&nbsp &nbsp &nbsp".$mgname[$ctr1]."</td><td align='right'>".number_format($msales[$ctr1], 2, '.', ',')."</td><td align='right'>".number_format($msales_prog[$ctr1], 2, '.', ',')."</td>";
}
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
$Data .= "|         PURCHASES            |               |                   |         TRANSFER             |               |                   |\n";
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
//<tr><th colspan="3" align="left">PURCHASES:</th><th colspan="3" align="left">TRANSFER:</th></tr>
for ($ctr1=1;$ctr1<=$ctr-1;$ctr1++)
{
  $Data .= "| ".substr($mgname[$ctr1].str_repeat(" ",29),0,29);
  $mnum = number_format($mtran_in[$ctr1], 2, '.', '');
  $mtot1 += $mtran_in[$ctr1];
  $mptot1 += $mtran_in_prog[$ctr1];
  $Data .= "| ".substr(str_repeat(" ",14).$mnum,-14);
  $mnum = number_format($mtran_in_prog[$ctr1], 2, '.', '');
  $Data .= "| ".substr(str_repeat(" ",18).$mnum,-18);

  $Data .= "| ".substr($mgname[$ctr1].str_repeat(" ",29),0,29);
  $mnum = number_format($mtran_out[$ctr1], 2, '.', '');
  $mtot2 += $mtran_out[$ctr1];
  $mptot2 += $mtran_out_prog[$ctr1];
  $Data .= "| ".substr(str_repeat(" ",15).$mnum,-14);
  $mnum = number_format($mtran_out_prog[$ctr1], 2, '.', '');
  $Data .= "| ".substr(str_repeat(" ",15).$mnum,-18)."|\n";
//  print "<tr><td align ='left'>&nbsp &nbsp &nbsp".$mgname[$ctr1]."</td><td align='right'>".number_format($mtran_in[$ctr1], 2, '.', ',')."</td><td align='right'>".number_format($mtran_in_prog[$ctr1], 2, '.', ',')."</td>";
//  print "<td align='left'>&nbsp &nbsp &nbsp".$mgname[$ctr1]."</td><td align='right'>".number_format($mtran_out[$ctr1], 2, '.', ',')."</td><td align='right'>".number_format($mtran_out_prog[$ctr1], 2, '.', ',')."</td>";
}
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
$Data .= "|         SALES RETURN         |               |                   |         CLOSING              |               |                   |\n";
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
//<tr><th colspan="3" align="left">SALES RETURN:</th><th colspan="3" align="left">CLOSING:</th></tr>
for ($ctr1=1;$ctr1<=$ctr-1;$ctr1++)
{
  $Data .= "| ".substr($mgname[$ctr1].str_repeat(" ",29),0,29);
  $mnum = number_format($msalesrtn[$ctr1], 2, '.', '');
  $mtot1 += $msalesrtn[$ctr1];
  $mptot1 += $msalesrtn_prog[$ctr1];
  $Data .= "| ".substr(str_repeat(" ",15).$mnum,-14);
  $mnum = number_format($msalesrtn_prog[$ctr1], 2, '.', '');
  $Data .= "| ".substr(str_repeat(" ",18).$mnum,-18);

  $Data .= "| ".substr($mgname[$ctr1].str_repeat(" ",29),0,29);
  $mnum = number_format($mclose[$ctr1], 2, '.', '');
  $mtot2 += $mclose[$ctr1];
  $mptot2 += $mclose[$ctr1];
  $Data .= "| ".substr(str_repeat(" ",15).$mnum,-14);
  $mnum = number_format($mclose[$ctr1], 2, '.', '');
  $Data .= "| ".substr(str_repeat(" ",18).$mnum,-18)."|\n";
//  print "<tr><td align ='left'>&nbsp &nbsp &nbsp".$mgname[$ctr1]."</td><td align='right'>".number_format($msalesrtn[$ctr1], 2, '.', ',')."</td><td align='right'>".number_format($msalesrtn_prog[$ctr1], 2, '.', ',')."</td>";
//  print "<td align ='left'>&nbsp &nbsp &nbsp".$mgname[$ctr1]."</td><td align='right'>".number_format($mclose[$ctr1], 2, '.', ',')."</td><td align='right'>".number_format($mclose[$ctr1], 2, '.', ',')."</td>";
}
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
$mnum = number_format($mtot1, 2, '.', '');
$mnum1 = number_format($mtot2, 2, '.', '');
$mpnum = number_format($mptot1, 2, '.', '');
$mpnum1 = number_format($mptot2, 2, '.', '');
$Data .= "|          T O T A L           | ".substr(str_repeat(" ",15).$mnum,-14)."|".substr(str_repeat(" ",18).$mpnum,-19)."|         T O T A L            | ".substr(str_repeat(" ",15).$mnum1,-14);
$Data .= "|".substr(str_repeat(" ",18).$mpnum1,-19)."|\n";
$Data .= "|------------------------------|---------------|-------------------|------------------------------|---------------|-------------------|\n";
$Data .= "      Note:-    1)  If any purchase invoices are pending adjustment and the sales there of is included in the \n";
$Data .= "                    above statement a note to that effect is to be given on the statement.          \n\n";
$Data .= "                2)  Figures in the above statement should tally with the actual value of stock and sales of  \n";
$Data .= "                    each item.          \n\n\n";
$Data .= " Name of Centre/Institution  \n";
$Data .= " ".$brname."\n\n";
$Data .= "                                         Signature                              Signature  \n\n\n";
$Data .= "                                         Project Officer                        Manager\n";
$Data .= " Place : $brcity \n\n";
$Data .= " Date  : ".date("j-n-Y")."\n\n\n";
$Data .= " Office Seal  ";

$Data .= chr(18);
$Data .=chr(12);
fwrite($handle, $Data);
fclose($handle);
//print "lp -o media=Custom.10x6in $file";
$output = shell_exec("lp -o media=Custom.10x6in '$file'");
$output=shell_exec("C:\\WINDOWS\\system32\\cmd.exe /c form4.bat");
$fromdt = implode('-', array_reverse(explode('-', $dfrom)));
$todt = implode('-', array_reverse(explode('-', $dto)));


?>
</table>

<script>
  document.location="form4.php?fromdt=<? echo $fromdt ?>&&todt=<? echo $todt ?>&&type=<? echo $type ?>";
 </script>