<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='index.php' </script>";
  return;
}
if (date('m') <= 4) {//Upto June 2014-2015
    $fin_year = (date('Y')-1) . '-' . date('y');
} else {//After June 2015-2016
    $fin_year = date('Y') . '-' . (date('y') + 1);
  
}
include('includes/top.php');
include('opendb.php');
?>
<link href="css/form.css" type="text/css" rel="stylesheet" media="screen" />
<html>
<body >
<center>
<title>GST Report</title>

<link type="text/css" href="jquery/jquery-ui.min.css" rel="stylesheet" />	
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="cal/jquery-ui1.js"></script>
<script type="text/javascript" src="jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.min.js"></script>




<script type="text/javascript">
$(function() {
$( "#ref_date" ).datepicker("destroy");
     var fyr=document.getElementById('f_yr').value;
     var splv=fyr.split("-");
     var syr=splv[0];
     var eyr='20'.concat(splv[1]);
     var syr1='01-04-';
     var eyr1='31-03-';
     var stfnyr=syr1.concat(syr);
     var efnyr=eyr1.concat(eyr);
     $("#ref_date").datepicker({ dateFormat: 'dd-mm-yy', minDate: stfnyr, maxDate: efnyr});

$( "#ref_date1" ).datepicker("destroy");
     var fyr=document.getElementById('f_yr').value;
     var splv=fyr.split("-");
     var syr=splv[0];
     var eyr='20'.concat(splv[1]);
     var syr1='01-04-';
     var eyr1='31-03-';
     var stfnyr=syr1.concat(syr);
     var efnyr=eyr1.concat(eyr);
     $("#ref_date1").datepicker({ dateFormat: 'dd-mm-yy', minDate: stfnyr, maxDate: efnyr});
});
</script>
<script>
function valid()
{
}
</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;
}
</style>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
  useMode:2,
  target:"inputField",
  dateFormat:"%Y-%m-%d"
});
new JsDatePick({
  useMode:2,
  target:"inputField1",
  dateFormat:"%Y-%m-%d"
});

};
</script>

<SCRIPT LANGUAGE="JavaScript" SRC="util/PopupWindow.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/AnchorPosition.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/date.js"></SCRIPT>
<script>
var cal1 = new CalendarPopup();
cal1.showYearNavigation();

var cal2 = new CalendarPopup();
cal2.showYearNavigation();

</script>
<style>
th{
    // background-color: grey;
    font-weight: bold;
    color: white;
    border:1px solid #D7D7D1;
    border-collapse:collapse;
background: rgb(181,189,200); /* Old browsers */
background: -moz-linear-gradient(top, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,189,200,1)), color-stop(36%,rgba(130,140,149,1)), color-stop(100%,rgba(40,52,59,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */
}
.ro_settled td
{
background: #6bba70; /* Old browsers */
background: -moz-linear-gradient(top, #6bba70 0%, #6bba70 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6bba70), color-stop(100%,#6bba70)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* IE10+ */
background: linear-gradient(to bottom, #6bba70 0%,#6bba70 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6bba70', endColorstr='#6bba70',GradientType=0 ); /* IE6-9 */
color:white;
}
.ro_settl td
{
background: #6bba70; /* Old browsers */
background: -moz-linear-gradient(top, #6bba70 0%, #6bba70 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6bba70), color-stop(100%,#6bba70)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* IE10+ */
background: linear-gradient(to bottom, #6bba70 0%,#6bba70 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6bba70', endColorstr='#6bba70',GradientType=0 ); /* IE6-9 */
color:red;
}
</style>
<body background="back_ground.jpg">
<?php //include('logo2.php'); ?>
<?php //include('includes/top.php'); ?>
<form action='<?print $PHP_SELF?>' name="f1" method='post' >
<br>
<table class="container"><tr><td>
<br>
<center>
<?
$brqry="select brname from branch where brcode='$brcode'";
$brrs=mysqli_query($db,$brqry);
$brrw=mysqli_fetch_array($brrs);
$brnchnm=$brrw[0];
?>

<table class="form" style="width:auto;" >
<tr><th style="background:grey;" colspan=2>GST REPORT</th><input type=hidden name='f_yr' id='f_yr' value='<? echo $fin_year ?>'></tr>
<?
$yeardat=explode('-',$fin_year);
$startingyr=$yeardat[0];
$mgrp="";
?>
<tr><td>Date from </td><td><input type="text" id="ref_date" value="<?echo '01-04-'.$startingyr;?>" name="fromdt" readonly></td>
</tr>
<tr><td> To </td>
<td><input type="text" id="ref_date1" value="<?echo date('d-m-Y');?>" name="todt" readonly></td>
</tr>

<tr><td align='center'>Taxtype :  </td>
<td><select name='taxtype' id='taxtype' onchange='showitem(this.value)'>
<option>INTRASTATE</option>
<option>INTERSTATE</option>
</select>
</td></tr>

<tr><td align='center'>
<input type='submit' name='show' value='Show' >
</td>
</tr></form>
</table>
<br><br>
<?
if(isset($_POST['show']))
{
    $fromdt=$_REQUEST['fromdt'];
    $todt=$_REQUEST['todt'];
    $taxtype=$_REQUEST['taxtype'];
    $mfrom_date = $fromdt;
    $mto_date = $todt;
    $fromdt = implode('-', array_reverse(explode('-', $fromdt)));
    $todt = implode('-', array_reverse(explode('-', $todt)));
  //$tbl='sales_summ'.$brcode.$user;
  //mysqli_query($db,"delete from $tbl");
  //mysqli_query($db,"create table $tbl(gname varchar(50),total double(14,2),mba double(14,2),strbtnml double(14,2),strbtspl double(14,2),redct double(14,2),befrtx double(14,2),taxamt double(14,2),nettot double(14,2),dbttot double(14,2))");

    $qry=mysqli_query($db,"select exp_no,vendrinvdt,expense_head,vendor,sum(before_tax),cgstp,sum(cgstamt),sgstp,sum(sgstamt),igstp,sum(igstamt),sum(expense_amount),vendrinvno,date,hsncode,sum(kfcamt) from gst_expense where date between '$fromdt' and '$todt' and brcode='$brcode' and txtype='$taxtype' group by refno,cgstp,igstp");
    $sql="select exp_no,vendrinvdt,expense_head,vendor,sum(before_tax),cgstp,sum(cgstamt),sgstp,sum(sgstamt),igstp,sum(igstamt),sum(expense_amount),vendrinvno,date,hsncode,sum(kfcamt) from gst_expense where date between '$fromdt' and '$todt' and brcode='$brcode' and txtype='$taxtype' group by expense_head";
    //echo "select exp_no,vendrinvdt,expense_head,vendor,sum(before_tax),cgstp,sum(cgstamt),sgstp,sum(sgstamt),igstp,sum(igstamt),sum(expense_amount),vendrinvno,date,hsncode,sum(kfcamt) from gst_expense where date between '$fromdt' and '$todt' and brcode='$brcode' and txtype='$taxtype' group by refno,cgstp,igstp";
	
    print "<table class='report' border='1' style='width: 100%;'>";
    print "<tr><th COLSPAN=17>GST Report for the period from <$mfrom_date> to <$mto_date></th>";
    print "<tr><th>ExpNo</th><th>Vendor</th><th>GST NO<th>Invoice No</th><th>Inv Date</th><th>BeforeTax</th>";
    if($taxtype=='INTRASTATE')
    print "<th>CGST Amt</th><th>SGST Amt</th><th>KFC Amt</th>";
    else
    print "<th>IGST Amt</th>";
    print "<th>Total</th><th>GST%</th><th>HSN Code</th><th>Entry Date</th><th>Exp Head</th>";
    while($row=mysqli_fetch_array($qry))
    {
        $qry1=mysqli_query($db,"select * from sup_master where supname='$row[vendor]'");
	    $row_cus=mysqli_fetch_array($qry1);	
        print "<tr><td>".$row[0]."</td><td>$row[3]</td><td>$row_cus[tin]</td><td>".$row[12]."</td><td align='right'>$row[1]</td><td align='right'>".number_format($row[4],2,'.','')."</td>";
        if($taxtype=='INTRASTATE')
            print "<td align='right'>".number_format($row[6],2,'.','')."</td><td align='right'>".number_format($row[8],2,'.','')."</td><td align='right'>".number_format($row[15],2,'.','')."</td>";
        else
            print "<td align='right'>".number_format($row[10],2,'.','')."</td>";
        $mgstper=$row['cgstp']+$row['sgstp']+$row['igstp'];
        print "<td align='right'>".number_format($row[11],2,'.','')."</td><td>$mgstper%</td><td>".$row['hsncode']."</td><td>".$row['date']."</td><td>$row[2]</td></tr>";
  
    }
    $mgr_cot +=  $mtot_cot;
    $mgr_pol +=  $mtot_pol;
    $mgr_rel +=  $mtot_rel;
    $mgr_spu +=  $mtot_spu;
    $mgr_vip +=  $mtot_vip;
    $mgr_woo +=  $mtot_woo;
    $mgr_oth +=  $mtot_oth;
    $mgr_mba+=  $mtot_mba;
    $mgr_strbtnml +=  $mtot_strbtnml;
    $mgr_strbtspl +=  $mtot_strbtspl;
    $mgr_redct +=  $mtot_redct;
    $mgr_befrtx +=  $mtot_befrtx;
    $mgr_taxamt +=  $mtot_taxamt;
    $mgr_nettot +=  $mtot_nettot;
    $mgr_dbtrs +=  $mtot_dbtrs;

    //print "<tr><td>$minvno</td><td align='right'>".number_format($mtot_cot,2,'.','')."</td><td align='right'>".number_format($mtot_pol,2,'.','')."</td><td align='right'>".number_format($mtot_rel,2,'.','')."</td><td align='right'>".number_format($mtot_spu,2,'.','')."</td><td align='right'>".number_format($mtot_vip,2,'.','')."</td><td align='right'>".number_format($mtot_woo,2,'.','')."</td><td align='right'>".number_format($mtot_oth,2,'.','')."</td><td align='right'>".number_format($mtot_mba,2,'.','')."</td><td align='right'>".number_format($mtot_strbtnml,2,'.','')."</td><td align='right'>".number_format($mtot_strbtspl,2,'.','')."</td></tr>";
    //print "<tr><td><b>Grand Total</b></td><td align='right'><b>".number_format($mgr_cot,2)."</b></td><td align='right'><b>".number_format($mgr_pol,2)."</b></td><td align='right'><b>".number_format($mgr_rel,2)."</b></td><td align='right'><b>".number_format($mgr_spu,2)."</b></td><td align='right'><b>".number_format($mgr_vip,2)."</b></td><td align='right'><b>".number_format($mgr_woo,2)."</b></td><td align='right'><b>".number_format($mgr_oth,2)."</b></td><td align='right'><b>".number_format($mgr_mba,2)."</b></td><td align='right'><b>".number_format($mgr_strbtnml,2)."</b></td><td align='right'><b>".number_format($mgr_strbtspl,2)."</b></td></tr>";
    print "</table>";

}
?>
<script>
function billexc()
    {
   var dfrom=document.f1.fromdt.value;
   var dto=document.f1.todt.value;
   //var url="sale_summ_billwise.php?fromdt="+dfrom+"&&todt="+dto;
   //alert(url);
          document.location="sale_summ_billwise.php?dfrom="+dfrom+"&&dto="+dto,true;
    }
 function conslfn()
    {
        var dfrom=document.f1.fromdt.value;
        var dto=document.f1.todt.value;
        window.open("sale_summ_print.php?fromdt="+dfrom+"&&todt="+dto,true);

    }
  function pdfexc()
        {
            var dfrom=document.f1.fromdt.value;
            var dto=document.f1.todt.value;
            window.open("paypdf/sale_summ_billwise_pdf.php?fromdt="+dfrom+"&&todt="+dto,true);
        }
function dirprint()
    {
            var dfrom=document.f1.fromdt.value;
            var dto=document.f1.todt.value;
   //var url="sale_summ_billwise.php?fromdt="+dfrom+"&&todt="+dto;
   //alert(url);
            document.location="sale_summ_newprn.php?fromdt="+dfrom+"&&todt="+dto,true;
    }
   function print_laser()
    {
            var dfrom=document.f1.fromdt.value;
            var dto=document.f1.todt.value;
   //var url="sale_summ_billwise.php?fromdt="+dfrom+"&&todt="+dto;
   //alert(url);
            window.open("sale_summ_prn.php?fromdt="+dfrom+"&&todt="+dto,true);
    }
</script>