<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$custname = $_REQUEST['custname'];
$outstand = $_REQUEST['outstand'];
$summary  = $_REQUEST['summary'];
$frmdt    = $_REQUEST['frmdt'];
$interval = $_REQUEST['interval'];
$dsrname = $_REQUEST['dsrname'];
if(strlen($outstand)>0)$chked = 'checked'; else $chked = '';
if(strlen($summary)>0)$summ = 'checked'; else $summ = '';
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('opendb.php');
include('top.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 ssyr = splv[1]+1;
     var eyr='2025';
     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>
<script type="text/javascript">
$(function(){
    $(".orderto").live("keydown.autocomplete",function(){
$orderto = $(this);
$row = $orderto.parent().parent();
$(this).autocomplete({
		source: function( request, response ) {

		$.ajax({
			url: "searchcust.php",
			dataType: "json",
			data: "key="+$orderto.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label: item.orderto+' | '+  item.partname +' | '+  item.price  +' | '+  item.supqty  ,
						value: item.orderto,
						code:item.partname,
							price:item.price,
							supqty:item.supqty,
							dist:item.shidist,
						    custstt:item.custstt,
						    shippinvl:item.shipin,
						    custtot:item.mrgnprc,

					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {
	$row.find('.orderto').val(ui.item.orderto);


 
 
	//$row.find('.msno').val(ui.item.partname);
	
	//document.f1.addr.value=ui.item.adr;
	//document.f1.tin.value=ui.item.gst;
	//document.f1.shipgst.value=ui.item.gst;
	//document.f1.marginprc.value=ui.item.marginpr;
	//if(ui.item.custstt=='KERALA')
	//{
		//document.f1.vatorcst.value='INTRASTATE';
	//}
	//else
	//{
		//document.f1.vatorcst.value='INTERSTATE';
	//}
	//document.f1.shipdist.value=ui.item.shipdistvl;
	//document.f1.shippin.value=ui.item.shippinvl;
	//document.f1.shipto.value=ui.item.value;
	//vehiclemsno(ui.item.value);
	
	//document.f1.msno.focus();
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});
});
    </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'>Receipt Allocation</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>Outstanding on </td><td><input type ='date' name='frmdt' id='frmdt'></td></tr>
<tr><td>Days Interval</td><td><input type ='number' name='interval' id='interval' size='2'></td></tr>

<tr><td> DSR Name </td>
<td>
<?
$dsrqry="select distinct father from customer where brcode='$brcode' and father!='' and father!='-' ";

$dsrrs=mysqli_query($db,$dsrqry);
print "<select name='dsrname' id='dsrname'>";
if($dsrname>'')
    print "<option>$dsrname</option>";
print "<option>All</option>";
while($dsrrow=mysqli_fetch_array($dsrrs))
{
    print "<option>$dsrrow[0]</option>";
}
?>
</select>
</td>
</tr>

<tr><td colspan='2'> <input type="checkbox" id="outstand" name="outstand" value="outstand" checked>
<label for="prevyear"> Show only outstanding bills</label><br></td>
</tr>
<tr><td colspan='2'> <input type="checkbox" id="summary" name="summary" value="summary" checked >
<label for="prevyear"> Summary Only</label><br></td>
</tr>
<tr><td colspan='2' 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'];
    $custname=$_REQUEST['custname'];
    $invtype='All';
    $outstand=$_REQUEST['outstand'];
    $mfrom_date = $fromdt;
    $mto_date = $todt;
    $mstr='';
    $interval = $_REQUEST['interval'];
    if(strlen($interval)<=0)$interval=1;
    $frmdt = $_REQUEST['frmdt'];
    if(strlen($frmdt)<=0)$frmdt=date('Y-m-d');
    $date1 = $frmdt;
    $date2 = date('Y-m-d', strtotime($date1. ' + '.$interval.' days'));
    $date3 = date('Y-m-d', strtotime($date2. ' + '.$interval.' days'));
    $date4 = date('Y-m-d', strtotime($date3. ' + '.$interval.' days'));
    $date5 = date('Y-m-d', strtotime($date4. ' + '.$interval.' days'));
    $fromdt = implode('-', array_reverse(explode('-', $fromdt)));
    $todt = implode('-', array_reverse(explode('-', $todt)));
    print "<table class='report' border='1' style='width: 100%;'>";
    print "<tr><th COLSPAN=15>Allocation Report for the period from <$mfrom_date> to <$mto_date></th>";
    print "<tr><th>SL No.</th><th>Date</th><th>JV No./ Cr Days</th><th>Customer</th><th>Invoice Type & Number</th><th>Amount</th><th>Payment Received</th><th>Recd.Date</th><th>Adjustment</th><th>Balance Due</th><th>".implode('-', array_reverse(explode('-', $date1)))."</th><th>".implode('-', array_reverse(explode('-', $date2)))."</th><th>".implode('-', array_reverse(explode('-', $date3)))."</th><th>".implode('-', array_reverse(explode('-', $date4)))."</th><th>".implode('-', array_reverse(explode('-', $date5)));
    $i=1;
    $mtot_amt1 = 0;$mtot_amt2 = 0;$mtot_amt3 = 0;$mtot_amt4 = 0;$mtot_amt5 = 0;
    $grtinvamt=0;$grtreceived=0;$grtmbal=0;$grtot_amt1 = 0;$grtot_amt2 = 0;$grtot_amt3 = 0;$grtot_amt4 = 0;$grtot_amt5 = 0;
    $qry21=mysqli_query($db,"select led from ledger where brcode='$brcode' and grp='Sundry Debtors' and ((op > 0 and drcr='Dr')  or (op<0 and drcr='Cr'))  order by led ");        
    while($row21=mysqli_fetch_array($qry21))
    {
        $custres=mysqli_query($db,"select crdays,cramt,father from customer where brcode='$brcode' and acname = '$row21[0]' ");
		$custrow=mysqli_fetch_array($custres);
		if($dsrname=='All' || $dsrname ==$custrow[2]) 
		{
		$mcrdays = $custrow[0];
		$mcramt = $custrow[1];
        $tinvamt=0;$treceived=0;$tmbal=0;
        $brres88=mysqli_query($db,"select op,drcr from ledger where brcode='$brcode' and led = '$row21[0]' ");
    	$brrow88=mysqli_fetch_array($brres88);
		$mop = 0;
		if($brrow88[1]=='Cr')
    	    $mop=$brrow88[0]*-1;
		else
    	    $mop=$brrow88[0];
		$mtot_amt1 = 0;$mtot_amt2 = 0;$mtot_amt3 = 0;$mtot_amt4 = 0;$mtot_amt5 = 0;
		if($mop>0)
		{
            $brres66=mysqli_query($db,"select sum(amtreceived),sum(adjamt),max(crjvno) from allotreceipt where brcode='$brcode' and customer = '$row21[0]' and invno = 'OP'");
		    $brrow66=mysqli_fetch_array($brres66);
		    $brres77=mysqli_query($db,"select acfrom from acperiod");
		    $brrow77=mysqli_fetch_array($brres77);
		    $diff = strtotime(date('Y-m-d')) - strtotime($brrow77[0]); 
            $mdays= abs(round($diff / 86400));    
            $diff = strtotime($date2) - strtotime($brrow77[0]); 
            $mdays2= abs(round($diff / 86400));
            $diff = strtotime($date3) - strtotime($brrow77[0]); 
            $mdays3= abs(round($diff / 86400));
            $diff = strtotime($date4) - strtotime($brrow77[0]); 
            $mdays4= abs(round($diff / 86400));
            $diff = strtotime($date5) - strtotime($brrow77[0]); 
            $mdays5= abs(round($diff / 86400));
            $mdate = substr($brrow77[0],8,2)."-".substr($brrow77[0],5,2)."-".substr($brrow77[0],0,4);
            $adjstment=$brrow66[1];
            $mbal=$mop-$brrow66[0]-$adjstment;
            $mrecdate = '';
		    if(strlen($brrow66[2])>0)
		    {
    		    $brres231=mysqli_query($db,"select date from journal2 where brcode='$brcode' and jvno = $brrow66[2]");
                $brrow231=mysqli_fetch_array($brres231);
		        $mrecdate = substr($brrow231[0],8,2)."-".substr($brrow231[0],5,2)."-".substr($brrow231[0],0,4);
		    }
		    if($mbal>0)
            {
                if($mdays > $mcrdays || $mbal > $mcramt) $mamt1 = $mbal;
                if($mdays2 > $mcrdays || $mbal > $mcramt) $mamt2 = $mbal;
                if($mdays3 > $mcrdays || $mbal > $mcramt) $mamt3 = $mbal;
                if($mdays4 > $mcrdays || $mbal > $mcramt) $mamt4 = $mbal;
                if($mdays5 > $mcrdays || $mbal > $mcramt) $mamt5 = $mbal;
            }
            else
            {
                $mamt1=0;$mamt2=0;$mamt3=0;$mamt4=0;$mamt5=0;
            }
            if($summary)
            {
                $mline1 = "<tr><td align='right'>".$i."</td><td align='right'>$mdate</td><td align='right'>$mcrdays [$mcramt]</td><td>$row21[0]</td><td></td>";
            }
            else
            {
                print "<tr><td align='right'>".$i."</td><td align='right'>$mdate</td><td align='right'>$mcrdays [$mcramt]</td><td>$row21[0]</td><td>OPENING BALANCE</td><td align='right'>$mop</td>";
		        print "<td align='right'>".number_format($brrow66[0],2,".",",")."</td><td>$mrecdate</td><td align='right'>".number_format($brrow66[1],2,".",",")."</td><td align='right'>".number_format($mbal,2,".",",")."</td><td align='right'>".number_format($mamt1,2,".",",")."</td><td align='right'>".number_format($mamt2,2,".",",")."</td><td align='right'>".number_format($mamt3,2,".",",")."</td><td align='right'>".number_format($mamt4,2,".",",")."</td><td align='right'>".number_format($mamt5,2,".",",")."</td>";
                print "</tr>";
            }
            $i++;
            $tinvamt+=$mop;
            $treceived+=$brrow66[0];
            $tmbal+=$mbal;
            //********************
            if($invtype=='All')
                $qry=mysqli_query($db,"select date,jvno,partic,dramt,j_type,narr from journal2 where date between '$fromdt' and '$todt' and brcode='$brcode' and (j_type = 'Spare Invoice' or j_type = 'ServiceCAll' or j_type = 'Warranty Invoice' or j_type = 'JC Spare Invoice' or j_type = 'Spare sale' or j_type ='Asc') and dramt>0 and partic !='Round Off' and partic = '$row21[0]' order by date,narr");
            else
                $qry=mysqli_query($db,"select date,jvno,partic,dramt,j_type,narr from journal2 where date between '$fromdt' and '$todt' and brcode='$brcode' and (j_type = '$invtype') and dramt>0 and partic !='Round Off' $mstr order by date,narr");        
            while($row=mysqli_fetch_array($qry))
            {
                $custname = $row[2];
                $brres22=mysqli_query($db,"select sum(amtreceived),sum(adjamt),max(crjvno) from allotreceipt where brcode='$brcode' and customer = '$custname' and drjvno = '$row[jvno]'");
		        $brrow22=mysqli_fetch_array($brres22);
        		$minvno = trim(substr($row['narr'],12,20));
                $brres23=mysqli_query($db,"select sum(cramt) from journal2 where brcode='$brcode' and partic = '$custname' and no = '$minvno' and against= 'sp invoice'");
                $brrow23=mysqli_fetch_array($brres23);
                $mdate = substr($row[0],8,2)."-".substr($row[0],5,2)."-".substr($row[0],0,4);
		        $mrecdate = '';
		        if(strlen($brrow22[2])>0)
		        {
		            $brres231=mysqli_query($db,"select date from journal2 where brcode='$brcode' and jvno = $brrow22[2]");
                    $brrow231=mysqli_fetch_array($brres231);
		            $mrecdate = substr($brrow231[0],8,2)."-".substr($brrow231[0],5,2)."-".substr($brrow231[0],0,4);
		        }
		        $mdate = substr($row[0],8,2)."-".substr($row[0],5,2)."-".substr($row[0],0,4);
		        $received = $brrow22[0]+$brrow23[0];
		        $adjstment=$brrow22[1];
		        $mbal = $row[3]-$received-$adjstment;
                $diff = strtotime($date1) - strtotime($row[0]); 
                $mdays= abs(round($diff / 86400)); 
                $diff = strtotime($date2) - strtotime($row[0]); 
                $mdays2= abs(round($diff / 86400));
                $diff = strtotime($date3) - strtotime($row[0]); 
                $mdays3= abs(round($diff / 86400));
                $diff = strtotime($date4) - strtotime($row[0]); 
                $mdays4= abs(round($diff / 86400));
                $diff = strtotime($date5) - strtotime($row[0]); 
                $mdays5= abs(round($diff / 86400));
                $mamt1=0;$mamt2=0;$mamt3=0;$mamt4=0;$mamt5=0;
                if($mbal>0)
                {
                    if($mdays > $mcrdays || $mbal > $mcramt) $mamt1 = $mbal;
                    if($mdays2 > $mcrdays || $mbal > $mcramt) $mamt2 = $mbal;
                    if($mdays3 > $mcrdays || $mbal > $mcramt) $mamt3 = $mbal;
                    if($mdays4 > $mcrdays || $mbal > $mcramt) $mamt4 = $mbal;
                    if($mdays5 > $mcrdays || $mbal > $mcramt) $mamt5 = $mbal;
                }
                $mtot_amt1 += $mamt1;$mtot_amt2 += $mamt2;$mtot_amt3 += $mamt3;$mtot_amt4 += $mamt4;$mtot_amt5 += $mamt5;
                if(strlen($outstand)>0)
                {
                    if($mbal>0)
                    {
                        if(!$summary){
                            print "<tr><td align='right'>".$i++."</td><td align='right'>$mdate</td><td align='right'>$row[1]</td><td>$row[2]</td><td>$row[4]-$row[5]</td><td align='right'>$row[3]</td>";
                            print "<td align='right'>".number_format($received,2,".",",")."</td><td>$mrecdate</td><td align='right'>".number_format($adjstment,2,".",",")."</td><td align='right'>".number_format($mbal,2,".",",")."</td><td align='right'>".number_format($mamt1,2,".",",")."</td><td align='right'>".number_format($mamt2,2,".",",")."</td><td align='right'>".number_format($mamt3,2,".",",")."</td><td align='right'>".number_format($mamt4,2,".",",")."</td><td align='right'>".number_format($mamt5,2,".",",")."</td>";                
                            print "</tr>";
                        }
                        $tinvamt+=$row[3];
                        $treceived+=$received;
                        $tmbal+=$mbal;
                    }
                }
                else
                {
                    if($mdays > $mcrdays || $mbal > $mcramt & $mbal > 0)
                    {
                        if(!$summary)
                        {
                            print "<tr><td align='right'>".$i++."</td><td align='right'>$mdate</td><td align='right'>$row[1]</td><td>$row[2]</td><td>$row[4]-$row[5]</td><td align='right'>$row[3]</td>";
	    	                print "<td align='right'>".number_format($received,2,".",",")."</td><td>$mrecdate</td><td align='right'>".number_format($adjstment,2,".",",")."</td><td align='right'>".number_format($mbal,2,".",",")."</td><td align='right'>".number_format($mamt1,2,".",",")."</td><td align='right'>".number_format($mamt2,2,".",",")."</td><td align='right'>".number_format($mamt3,2,".",",")."</td><td align='right'>".number_format($mamt4,2,".",",")."</td><td align='right'>".number_format($mamt5,2,".",",")."</td>";
                        }
                    }
                    else
                    {
                        if(!$summary)
                        {
                            print "<tr><td align='right'>".$i++."</td><td align='right'>$mdate</td><td align='right'>$row[1]</td><td>$row[2]</td><td>$row[4]-$row[5]</td><td align='right'>$row[3]</td>";
		                    print "<td align='right'>".number_format($received,2,".",",")."</td><td>$mrecdate</td><td align='right'>".number_format($adjstment,2,".",",")."</td><td align='right'>".number_format($mbal,2,".",",")."</td><td align='right'>".number_format($mamt1,2,".",",")."</td><td align='right'>".number_format($mamt2,2,".",",")."</td><td align='right'>".number_format($mamt3,2,".",",")."</td><td align='right'>".number_format($mamt4,2,".",",")."</td><td align='right'>".number_format($mamt5,2,".",",")."</td>";          
                        }         
                    }
                    if(!$summary)
                        print "</tr>";
                    $tinvamt+=$row[3];
                    $treceived+=$received;
                    $tmbal+=$mbal;
                }
            }
            if($summary)
            {
                if($tmbal>0)
                {
                    print $mline1."<td align='right'>".number_format($tinvamt,2,".",",")."</td><td align='right'>".number_format($treceived,2,".",",")."</td><td></td><td></td><td align='right'>".number_format($tmbal,2,".",",")."</td><td align='right'>".number_format($mtot_amt1,2,".",",")."</td><td align='right'>".number_format($mtot_amt2,2,".",",")."</td><td align='right'>".number_format($mtot_amt3,2,".",",")."</td><td align='right'>".number_format($mtot_amt4,2,".",",")."</td><td align='right'>".number_format($mtot_amt5,2,".",",")."</td>";
                    
                    $grtinvamt+=$tinvamt;$grtreceived+=$treceived;$grtmbal+=$tmbal;$grtot_amt1+=$mtot_amt1;$grtot_amt2+=$mtot_amt2;$grtot_amt3+=$mtot_amt3;$grtot_amt4+=$mtot_amt4;$grtot_amt5+=$mtot_amt5;
                }
            }
            else
            {
                print "<tr><td colspan='5' align='center'><b> T O T A L</td><td align='right'>".number_format($tinvamt,2,".",",")."</td><td align='right'>".number_format($treceived,2,".",",")."</td><td></td><td></td><td align='right'>".number_format($tmbal,2,".",",")."</td><td align='right'>".number_format($mtot_amt1,2,".",",")."</td><td align='right'>".number_format($mtot_amt2,2,".",",")."</td><td align='right'>".number_format($mtot_amt3,2,".",",")."</td><td align='right'>".number_format($mtot_amt4,2,".",",")."</td><td align='right'>".number_format($mtot_amt5,2,".",",")."</td>";
            }
            //********************
		}
	    }
        
    }
    print "<tr><td colspan='5' align='center'><b>Gr. T O T A L</td><td align='right'><b>".number_format($grtinvamt,2,".",",")."</td><td align='right'><b>".number_format($grtreceived,2,".",",")."</td><td></td><td></td><td align='right'><b>".number_format($grtmbal,2,".",",")."</td><td align='right'><b>".number_format($grtot_amt1,2,".",",")."</td><td align='right'><b>".number_format($grtot_amt2,2,".",",")."</td><td align='right'><b>".number_format($grtot_amt3,2,".",",")."</td><td align='right'><b>".number_format($grtot_amt4,2,".",",")."</td><td align='right'><b>".number_format($grtot_amt5,2,".",",")."</td>";    
    print "</table>";
}
?>
<script>
function ascdetails(jvn,amt,jvtp)
{
	var jvno=jvn;
	var amount=amt;
	var jvtyp=jvtp;
	window.open("ascreceipt.php?jvno="+jvno+"&amount="+amount+"&typ="+jvtyp,'scrollbars=yes','menubar=0,resizable=1,width=550,height=550');
}
function paiddetails(jvn,amt,jvtp)
{
	var jvno=jvn;
	var amount=amt;
	var jvtyp=jvtp;
	window.open("paidreceipt.php?jvno="+jvno+"&amount="+amount+"&typ="+jvtyp,'scrollbars=yes','menubar=0,resizable=1,width=550,height=550');
}
function sparedetails(jvn,amt,jvtp)
{
	var jvno=jvn;
	var amount=amt;
	var jvtyp=jvtp;
	window.open("sparereceipt.php?jvno="+jvno+"&amount="+amount+"&typ="+jvtyp,'scrollbars=yes','menubar=0,resizable=1,width=550,height=550');
}
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>