<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
    $date = date('Y-m-d');
	$todayfrom = date('Y-m-d');
	$todayto = date('Y-m-d');
    $partyId = isset($_REQUEST['partyId']) ? $_REQUEST['partyId'] : 0;
	$to        = $_REQUEST['toDtYear']."-".$_REQUEST['toDtMonth']."-".$_REQUEST['toDtDay'];  
	$from      = $_REQUEST['fromDtYear']."-".$_REQUEST['fromDtMonth']."-".$_REQUEST['fromDtDay']; 
    $a = 0;
    $rojmelArray = array();
	if(isset($_REQUEST['submit']))
	{
		///////////////////////////////// RTGS : Start ////////////////////////////////////////	
		
		$g = 0;
		$rtaArray = array();
		$selectRtgs = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						 AND rojmelDate between '".$to."' AND '".$from."'
						  AND amount > 0 
						  AND cash_type = 'R'";
		$selectRtgsRes = mysql_query($selectRtgs);
		while($rtaRow = mysql_fetch_array($selectRtgsRes))
		{
		  $rtaArray[$g]['rojmelId']     = $rtaRow['rojmelId'];
		  $rtaArray[$g]['rojmelDate']   = date('d-m-Y',strtotime($rtaRow['rojmelDate']));
		  $rtaArray[$g]['rojTransType'] = $rtaRow['rojTransType'];
		  $rtaArray[$g]['partyName']    = $rtaRow['partyName'];
		  $rtaArray[$g]['particular']   = $rtaRow['particular'];
		  $rtaArray[$g]['fine']         = $rtaRow['fine'];
		  $rtaArray[$g]['amount']       = $rtaRow['amount'];
		  $rtaArray[$g]['acc_type']     = $rtaRow['acc_type'];
		  $rtaArray[$g]['branch']       = $rtaRow['branch'];
		  $rtaArray[$g]['metal_type']   = $rtaRow['metal_type'];
		  $rtaArray[$g]['cash_type']    = $rtaRow['cash_type'];
		  $g++;
		}
		
		$gg = 0;
		$rtjArray = array();
		$selectRtJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						    AND rojmelDate between '".$to."' AND '".$from."'
						     AND amount > 0 
						     AND cash_type = 'R'";
		$selectRtJavakRes = mysql_query($selectRtJavak);
		while($rtjRow = mysql_fetch_array($selectRtJavakRes))
		{
		  $rtjArray[$gg]['rojmelId']     = $rtjRow['rojmelId'];
		  $rtjArray[$gg]['rojmelDate']   = date('d-m-Y',strtotime($rtjRow['rojmelDate']));
		  $rtjArray[$gg]['rojTransType'] = $rtjRow['rojTransType'];
		  $rtjArray[$gg]['partyName']    = $rtjRow['partyName'];
		  $rtjArray[$gg]['particular']   = $rtjRow['particular'];
		  $rtjArray[$gg]['fine']         = $rtjRow['fine'];
		  $rtjArray[$gg]['amount']       = $rtjRow['amount'];
		  $rtjArray[$gg]['acc_type']     = $rtjRow['acc_type'];
		  $rtjArray[$gg]['branch']       = $rtjRow['branch'];
		  $rtjArray[$gg]['metal_type']   = $rtjRow['metal_type'];
		  $rtjArray[$gg]['cash_type']    = $rtjRow['cash_type'];
		  $gg++;
		}	
		///////////////////////////////// RTGS : End ////////////////////////////////////////	
		
		
		
		 ///////////////////////////////// branch 0 : start ////////////////////////////////////////
	  $selectRojmel = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						  AND rojmelDate between '".$to."' AND '".$from."'
						   AND branch = 0";
		$selectRojmelRes = mysql_query($selectRojmel);
		while($rojmelRow = mysql_fetch_array($selectRojmelRes))
		{
		  $rojmelArray[$a]['rojmelId']     = $rojmelRow['rojmelId'];
		  $rojmelArray[$a]['rojmelDate']   = date('d-m-Y',strtotime($rojmelRow['rojmelDate']));
		  $rojmelArray[$a]['rojTransType'] = $rojmelRow['rojTransType'];
		  $rojmelArray[$a]['partyName']    = $rojmelRow['partyName'];
		  $rojmelArray[$a]['particular']   = $rojmelRow['particular'];
		  $rojmelArray[$a]['fine']         = $rojmelRow['fine'];
		  $rojmelArray[$a]['amount']       = $rojmelRow['amount'];
		  $rojmelArray[$a]['acc_type']     = $rojmelRow['acc_type'];
		  $rojmelArray[$a]['branch']       = $rojmelRow['branch'];
		  $rojmelArray[$a]['metal_type']   = $rojmelRow['metal_type'];
		  $rojmelArray[$a]['cash_type']    = $rojmelRow['cash_type'];
		  $a++;
		}
		
		$kk = 0;
		$javakArray = array();
		$selectJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						  AND rojmelDate between '".$to."' AND '".$from."'
						    AND branch = 0";
		$selectJavakRes = mysql_query($selectJavak);
		while($javakRow = mysql_fetch_array($selectJavakRes))
		{
		  $javakArray[$kk]['rojmelId']     = $javakRow['rojmelId'];
		  $javakArray[$kk]['rojmelDate']   = date('d-m-Y',strtotime($javakRow['rojmelDate']));
		  $javakArray[$kk]['rojTransType'] = $javakRow['rojTransType'];
		  $javakArray[$kk]['partyName']    = $javakRow['partyName'];
		  $javakArray[$kk]['particular']   = $javakRow['particular'];
		  $javakArray[$kk]['fine']         = $javakRow['fine'];
		  $javakArray[$kk]['amount']       = $javakRow['amount'];
		  $javakArray[$kk]['acc_type']     = $javakRow['acc_type'];
		  $javakArray[$kk]['branch']       = $javakRow['branch'];
		  $javakArray[$kk]['metal_type']   = $javakRow['metal_type'];
		  $javakArray[$kk]['cash_type']    = $javakRow['cash_type'];
		  $kk++;
		}	
		///////////////////////////////// branch 0 : End ////////////////////////////////////////
		
		
		///////////////////////////////// branch 1 : start ////////////////////////////////////////
		$aa = 0;
		$rojmelArray1 = array();
		$selectRojmel = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						 AND rojmelDate between '".$to."' AND '".$from."'
						   AND branch = 1";
		$selectRojmelRes = mysql_query($selectRojmel);
		while($rojmelRow = mysql_fetch_array($selectRojmelRes))
		{
		  $rojmelArray1[$aa]['rojmelId']     = $rojmelRow['rojmelId'];
		  $rojmelArray1[$aa]['rojmelDate']   = date('d-m-Y',strtotime($rojmelRow['rojmelDate']));
		  $rojmelArray1[$aa]['rojTransType'] = $rojmelRow['rojTransType'];
		  $rojmelArray1[$aa]['partyName']    = $rojmelRow['partyName'];
		  $rojmelArray1[$aa]['particular']   = $rojmelRow['particular'];
		  $rojmelArray1[$aa]['fine']         = $rojmelRow['fine'];
		  $rojmelArray1[$aa]['amount']       = $rojmelRow['amount'];
		  $rojmelArray1[$aa]['acc_type']     = $rojmelRow['acc_type'];
		  $rojmelArray1[$aa]['branch']       = $rojmelRow['branch'];
		  $rojmelArray1[$aa]['metal_type']   = $rojmelRow['metal_type'];
		  $rojmelArray1[$aa]['cash_type']    = $rojmelRow['cash_type'];
		  $aa++;
		}
		
		$k = 0;
		$javakArray1 = array();
		$selectJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						   AND rojmelDate between '".$to."' AND '".$from."'
						    AND branch = 1";
		$selectJavakRes = mysql_query($selectJavak);
		while($javakRow = mysql_fetch_array($selectJavakRes))
		{
		  $javakArray1[$k]['rojmelId']     = $javakRow['rojmelId'];
		  $javakArray1[$k]['rojmelDate']   = date('d-m-Y',strtotime($javakRow['rojmelDate']));
		  $javakArray1[$k]['rojTransType'] = $javakRow['rojTransType'];
		  $javakArray1[$k]['partyName']    = $javakRow['partyName'];
		  $javakArray1[$k]['particular']   = $javakRow['particular'];
		  $javakArray1[$k]['fine']         = $javakRow['fine'];
		  $javakArray1[$k]['amount']       = $javakRow['amount'];
		  $javakArray1[$k]['acc_type']     = $javakRow['acc_type'];
		  $javakArray1[$k]['branch']       = $javakRow['branch'];
		  $javakArray1[$k]['metal_type']   = $javakRow['metal_type'];
		  $javakArray1[$k]['cash_type']    = $javakRow['cash_type'];
		  $k++;
		}
		
		///////////////////////////////// branch 1 : End ////////////////////////////////////////
		
		
		
		
		$selectRojmel = "SELECT SUM(fine) AS afine,SUM(amount) AS aamount FROM rojmel
							WHERE rojTransType = 'A'";
		$selectRojmelRes = mysql_query($selectRojmel);
		if($row = mysql_fetch_array($selectRojmelRes))
		{
		  $aFine  =  $row['afine'];
		  $aAmount = $row['aamount'];
		}
		
		$selectRojmel = "SELECT SUM(fine) AS jfine,SUM(amount) AS jamount FROM rojmel
							WHERE rojTransType = 'J'";
		$selectRojmelRes = mysql_query($selectRojmel);
		if($row = mysql_fetch_array($selectRojmelRes))
		{
		  $jFine   = $row['jfine'];
		  $jAmount = $row['jamount'];
		}
		
		//////////////////////Branch : Start /////////////////////////////
		$selectBranch0 = "SELECT SUM(fine) AS b0afine,SUM(amount) AS b0aamount FROM rojmel
							WHERE rojTransType = 'A'
							AND branch = 0
							AND rojmelDate between '".$to."' AND '".$from."'";
		$selectBranch0Res = mysql_query($selectBranch0);
		if($row = mysql_fetch_array($selectBranch0Res))
		{
		  $b0afine   =  $row['b0afine'];
		  $b0aamount = $row['b0aamount'];
		}
		
		
		$selectbranch1 = "SELECT SUM(fine) AS b0jfine,SUM(amount) AS b0jamount FROM rojmel
							WHERE rojTransType = 'J'
							 AND branch = 0
							AND rojmelDate between '".$to."' AND '".$from."'";
		$selectbranch1Res = mysql_query($selectbranch1);
		if($row = mysql_fetch_array($selectbranch1Res))
		{
		  $b0jfine   = $row['b0jfine'];
		  $b0jamount = $row['b0jamount'];
		}
		
		$b0NetFine = $b0afine - $b0jfine;
		$b0NetAmt  = $b0aamount - $b0jamount;
		
		
		$selectBranch0 = "SELECT SUM(fine) AS b1afine,SUM(amount) AS b1aamount FROM rojmel
							WHERE rojTransType = 'A'
							AND branch = 1
							AND rojmelDate between '".$to."' AND '".$from."'";
		$selectBranch0Res = mysql_query($selectBranch0);
		if($row = mysql_fetch_array($selectBranch0Res))
		{
		  $b1afine   =  $row['b1afine'];
		  $b1aamount = $row['b1aamount'];
		}
		
		
		$selectbranch1 = "SELECT SUM(fine) AS b1jfine,SUM(amount) AS b1jamount FROM rojmel
							WHERE rojTransType = 'J'
							 AND branch = 1
							 AND rojmelDate between '".$to."' AND '".$from."'";
		$selectbranch1Res = mysql_query($selectbranch1);
		if($row = mysql_fetch_array($selectbranch1Res))
		{
		  $b1jfine   = $row['b1jfine'];
		  $b1jamount = $row['b1jamount'];
		}
		
		
		$b1NetFine = $b1afine - $b1jfine;
		$b1NetAmt  = $b1aamount - $b1jamount;
		
		
		//////////////////////Branch : End /////////////////////////////
		
		
		$netFine   = $aFine - $jFine;
		$netAmount = $aAmount - $jAmount;
	}
	else
	{
	  
		///////////////////////////////// RTGS : Start ////////////////////////////////////////	
		
		$g = 0;
		$rtaArray = array();
		$selectRtgs = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						  AND rojmelDate = '".$date."'
						  AND amount > 0 
						  AND cash_type = 'R'";
		$selectRtgsRes = mysql_query($selectRtgs);
		while($rtaRow = mysql_fetch_array($selectRtgsRes))
		{
		  $rtaArray[$g]['rojmelId']     = $rtaRow['rojmelId'];
		  $rtaArray[$g]['rojmelDate']   = date('d-m-Y',strtotime($rtaRow['rojmelDate']));
		  $rtaArray[$g]['rojTransType'] = $rtaRow['rojTransType'];
		  $rtaArray[$g]['partyName']    = $rtaRow['partyName'];
		  $rtaArray[$g]['particular']   = $rtaRow['particular'];
		  $rtaArray[$g]['fine']         = $rtaRow['fine'];
		  $rtaArray[$g]['amount']       = $rtaRow['amount'];
		  $rtaArray[$g]['acc_type']     = $rtaRow['acc_type'];
		  $rtaArray[$g]['branch']       = $rtaRow['branch'];
		  $rtaArray[$g]['metal_type']   = $rtaRow['metal_type'];
		  $rtaArray[$g]['cash_type']    = $rtaRow['cash_type'];
		  $g++;
		}
		
		$gg = 0;
		$rtjArray = array();
		$selectRtJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						   AND rojmelDate = '".$date."'
						     AND amount > 0 
						     AND cash_type = 'R'";
		$selectRtJavakRes = mysql_query($selectRtJavak);
		while($rtjRow = mysql_fetch_array($selectRtJavakRes))
		{
		  $rtjArray[$gg]['rojmelId']     = $rtjRow['rojmelId'];
		  $rtjArray[$gg]['rojmelDate']   = date('d-m-Y',strtotime($rtjRow['rojmelDate']));
		  $rtjArray[$gg]['rojTransType'] = $rtjRow['rojTransType'];
		  $rtjArray[$gg]['partyName']    = $rtjRow['partyName'];
		  $rtjArray[$gg]['particular']   = $rtjRow['particular'];
		  $rtjArray[$gg]['fine']         = $rtjRow['fine'];
		  $rtjArray[$gg]['amount']       = $rtjRow['amount'];
		  $rtjArray[$gg]['acc_type']     = $rtjRow['acc_type'];
		  $rtjArray[$gg]['branch']       = $rtjRow['branch'];
		  $rtjArray[$gg]['metal_type']   = $rtjRow['metal_type'];
		  $rtjArray[$gg]['cash_type']    = $rtjRow['cash_type'];
		  $gg++;
		}	
		///////////////////////////////// RTGS : End ////////////////////////////////////////	
		
	
	///////////////////////////////// branch 0 : start ////////////////////////////////////////
	  $selectRojmel = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						  AND rojmelDate = '".$date."'
						   AND branch = 0";
		$selectRojmelRes = mysql_query($selectRojmel);
		while($rojmelRow = mysql_fetch_array($selectRojmelRes))
		{
		  $rojmelArray[$a]['rojmelId']     = $rojmelRow['rojmelId'];
		  $rojmelArray[$a]['rojmelDate']   = date('d-m-Y',strtotime($rojmelRow['rojmelDate']));
		  $rojmelArray[$a]['rojTransType'] = $rojmelRow['rojTransType'];
		  $rojmelArray[$a]['partyName']    = $rojmelRow['partyName'];
		  $rojmelArray[$a]['particular']   = $rojmelRow['particular'];
		  $rojmelArray[$a]['fine']         = $rojmelRow['fine'];
		  $rojmelArray[$a]['amount']       = $rojmelRow['amount'];
		  $rojmelArray[$a]['acc_type']     = $rojmelRow['acc_type'];
		  $rojmelArray[$a]['branch']       = $rojmelRow['branch'];
		  $rojmelArray[$a]['metal_type']   = $rojmelRow['metal_type'];
		  $rojmelArray[$a]['cash_type']    = $rojmelRow['cash_type'];
		  $a++;
		}
		
		$kk = 0;
		$javakArray = array();
		$selectJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						   AND rojmelDate = '".$date."'
						    AND branch = 0";
		$selectJavakRes = mysql_query($selectJavak);
		while($javakRow = mysql_fetch_array($selectJavakRes))
		{
		  $javakArray[$kk]['rojmelId']     = $javakRow['rojmelId'];
		  $javakArray[$kk]['rojmelDate']   = date('d-m-Y',strtotime($javakRow['rojmelDate']));
		  $javakArray[$kk]['rojTransType'] = $javakRow['rojTransType'];
		  $javakArray[$kk]['partyName']    = $javakRow['partyName'];
		  $javakArray[$kk]['particular']   = $javakRow['particular'];
		  $javakArray[$kk]['fine']         = $javakRow['fine'];
		  $javakArray[$kk]['amount']       = $javakRow['amount'];
		  $javakArray[$kk]['acc_type']     = $javakRow['acc_type'];
		  $javakArray[$kk]['branch']       = $javakRow['branch'];
		  $javakArray[$kk]['metal_type']   = $javakRow['metal_type'];
		  $javakArray[$kk]['cash_type']    = $javakRow['cash_type'];
		  $kk++;
		}	
		///////////////////////////////// branch 0 : End ////////////////////////////////////////
		
		
		///////////////////////////////// branch 1 : start ////////////////////////////////////////
		$aa = 0;
		$rojmelArray1 = array();
		$selectRojmel = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						  AND rojmelDate = '".$date."'
						   AND branch = 1";
		$selectRojmelRes = mysql_query($selectRojmel);
		while($rojmelRow = mysql_fetch_array($selectRojmelRes))
		{
		  $rojmelArray1[$aa]['rojmelId']     = $rojmelRow['rojmelId'];
		  $rojmelArray1[$aa]['rojmelDate']   = date('d-m-Y',strtotime($rojmelRow['rojmelDate']));
		  $rojmelArray1[$aa]['rojTransType'] = $rojmelRow['rojTransType'];
		  $rojmelArray1[$aa]['partyName']    = $rojmelRow['partyName'];
		  $rojmelArray1[$aa]['particular']   = $rojmelRow['particular'];
		  $rojmelArray1[$aa]['fine']         = $rojmelRow['fine'];
		  $rojmelArray1[$aa]['amount']       = $rojmelRow['amount'];
		  $rojmelArray1[$aa]['acc_type']     = $rojmelRow['acc_type'];
		  $rojmelArray1[$aa]['branch']       = $rojmelRow['branch'];
		  $rojmelArray1[$aa]['metal_type']   = $rojmelRow['metal_type'];
		  $rojmelArray1[$aa]['cash_type']    = $rojmelRow['cash_type'];
		  $aa++;
		}
		
		$k = 0;
		$javakArray1 = array();
		$selectJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						   AND rojmelDate = '".$date."'
						    AND branch = 1";
		$selectJavakRes = mysql_query($selectJavak);
		while($javakRow = mysql_fetch_array($selectJavakRes))
		{
		  $javakArray1[$k]['rojmelId']     = $javakRow['rojmelId'];
		  $javakArray1[$k]['rojmelDate']   = date('d-m-Y',strtotime($javakRow['rojmelDate']));
		  $javakArray1[$k]['rojTransType'] = $javakRow['rojTransType'];
		  $javakArray1[$k]['partyName']    = $javakRow['partyName'];
		  $javakArray1[$k]['particular']   = $javakRow['particular'];
		  $javakArray1[$k]['fine']         = $javakRow['fine'];
		  $javakArray1[$k]['amount']       = $javakRow['amount'];
		  $javakArray1[$k]['acc_type']     = $javakRow['acc_type'];
		  $javakArray1[$k]['branch']       = $javakRow['branch'];
		  $javakArray1[$k]['metal_type']   = $javakRow['metal_type'];
		  $javakArray1[$k]['cash_type']    = $javakRow['cash_type'];
		  $k++;
		}
		
		///////////////////////////////// branch 1 : End ////////////////////////////////////////
		
		
		
		
		$selectRojmel = "SELECT SUM(fine) AS afine,SUM(amount) AS aamount FROM rojmel
							WHERE rojTransType = 'A'";
		$selectRojmelRes = mysql_query($selectRojmel);
		if($row = mysql_fetch_array($selectRojmelRes))
		{
		  $aFine  =  $row['afine'];
		  $aAmount = $row['aamount'];
		}
		
		$selectRojmel = "SELECT SUM(fine) AS jfine,SUM(amount) AS jamount FROM rojmel
							WHERE rojTransType = 'J'";
		$selectRojmelRes = mysql_query($selectRojmel);
		if($row = mysql_fetch_array($selectRojmelRes))
		{
		  $jFine   = $row['jfine'];
		  $jAmount = $row['jamount'];
		}
		
		//////////////////////Branch : Start /////////////////////////////
		$selectBranch0 = "SELECT SUM(fine) AS b0afine,SUM(amount) AS b0aamount FROM rojmel
							WHERE rojTransType = 'A'
							AND branch = 0
							AND rojmelDate = '".$date."'";
		$selectBranch0Res = mysql_query($selectBranch0);
		if($row = mysql_fetch_array($selectBranch0Res))
		{
		  $b0afine   =  $row['b0afine'];
		  $b0aamount = $row['b0aamount'];
		}
		
		
		$selectbranch1 = "SELECT SUM(fine) AS b0jfine,SUM(amount) AS b0jamount FROM rojmel
							WHERE rojTransType = 'J'
							 AND branch = 0
							 AND rojmelDate = '".$date."'";
		$selectbranch1Res = mysql_query($selectbranch1);
		if($row = mysql_fetch_array($selectbranch1Res))
		{
		  $b0jfine   = $row['b0jfine'];
		  $b0jamount = $row['b0jamount'];
		}
		
		$b0NetFine = $b0afine - $b0jfine;
		$b0NetAmt  = $b0aamount - $b0jamount;
		
		
		$selectBranch0 = "SELECT SUM(fine) AS b1afine,SUM(amount) AS b1aamount FROM rojmel
							WHERE rojTransType = 'A'
							AND branch = 1
							AND rojmelDate = '".$date."'";
		$selectBranch0Res = mysql_query($selectBranch0);
		if($row = mysql_fetch_array($selectBranch0Res))
		{
		  $b1afine   =  $row['b1afine'];
		  $b1aamount = $row['b1aamount'];
		}
		
		
		$selectbranch1 = "SELECT SUM(fine) AS b1jfine,SUM(amount) AS b1jamount FROM rojmel
							WHERE rojTransType = 'J'
							 AND branch = 1
							 AND rojmelDate = '".$date."'";
		$selectbranch1Res = mysql_query($selectbranch1);
		if($row = mysql_fetch_array($selectbranch1Res))
		{
		  $b1jfine   = $row['b1jfine'];
		  $b1jamount = $row['b1jamount'];
		}
		
		
		$b1NetFine = $b1afine - $b1jfine;
		$b1NetAmt  = $b1aamount - $b1jamount;
		
		
		//////////////////////Branch : End /////////////////////////////
		
		
		//////////////////////////////All Branch Total : Start /////////////////
		$AllBranch0aavak = "SELECT SUM(fine) AS allb0afine,SUM(amount) AS allb0aamount FROM rojmel
							WHERE rojTransType = 'A'
							AND branch = 0";
		$AllBranch0aavakRes = mysql_query($AllBranch0aavak);
		if($row = mysql_fetch_array($AllBranch0aavakRes))
		{
		  $allb0afine    =  $row['allb0afine'];
		  $allb0aamount  = $row['allb0aamount'];
		}
		
		
		$allbranch0javak = "SELECT SUM(fine) AS allb0jfine,SUM(amount) AS allb0jamount FROM rojmel
							WHERE rojTransType = 'J'
							 AND branch = 0";
		$allbranch0javakRes = mysql_query($allbranch0javak);
		if($row = mysql_fetch_array($allbranch0javakRes))
		{
		  $allb0jfine      = $row['allb0jfine'];
		  $allb0jamount    = $row['allb0jamount'];
		}
		
		$allb0NetFine = $allb0afine   - $allb0jfine;
		$allb0NetAmt  = $allb0aamount - $allb0jamount;
		
		
		$allBranch1aavak = "SELECT SUM(fine) AS allb1afine,SUM(amount) AS allb1aamount FROM rojmel
							WHERE rojTransType = 'A'
							AND branch = 1";
		$allBranch1aavakRes = mysql_query($allBranch1aavak);
		if($row = mysql_fetch_array($allBranch1aavakRes))
		{
		  $allb1afine      =  $row['allb1afine'];
		  $allb1aamount    = $row['allb1aamount'];
		}
		
		
		$allbranch1javak = "SELECT SUM(fine) AS allb1jfine,SUM(amount) AS allb1jamount FROM rojmel
							WHERE rojTransType = 'J'
							 AND branch = 1";
		$allbranch1javakRes = mysql_query($allbranch1javak);
		if($row = mysql_fetch_array($allbranch1javakRes))
		{
		  $allb1jfine   = $row['allb1jfine'];
		  $allb1jamount = $row['allb1jamount'];
		}
		//////////////////////////////All Branch Total : End /////////////////
		
		$netFine   = $aFine - $jFine;
		$netAmount = $aAmount - $jAmount;
	}
	
	
	$z=0;
	$clientArray = array();
	$selectClient = "SELECT partyId,partyName
	                   FROM party";
	$selectClientRes = mysql_query($selectClient);
	while($rojmelRow = mysql_fetch_array($selectClientRes))
	{
	  $clientArray['partyId'][$k]   = $rojmelRow['partyId'];
	  $clientArray['partyName'][$k] = $rojmelRow['partyName'];
	  $z++;
	}
	
		$b1NetFine = $b1afine - $b1jfine;
		$b1NetAmt  = $b1aamount - $b1jamount;
	
	
		$allb0NetFine = $allb0afine   - $allb0jfine;
		$allb0NetAmt  = $allb0aamount - $allb0jamount;
		
		$allb1NetFine = $allb1afine   - $allb1jfine;
		$allb1NetAmt  = $allb1aamount - $allb1jamount;
	
	
	
	include("./bottom.php");
	$smarty->assign("rtjArray",$rtjArray);
	$smarty->assign("rtaArray",$rtaArray);
	$smarty->assign("allb0NetFine",$allb0NetFine);
	$smarty->assign("allb0NetAmt",$allb0NetAmt);
	$smarty->assign("allb1NetFine",$allb1NetFine);
	$smarty->assign("allb1NetAmt",$allb1NetAmt);
	$smarty->assign("b1afine",$b1afine);
	$smarty->assign("b1jfine",$b1jfine);
	$smarty->assign("b1aamount",$b1aamount);
	$smarty->assign("b1jamount",$b1jamount);
	$smarty->assign("b0jamount",$b0jamount);
	$smarty->assign("b0jfine",$b0jfine);
	$smarty->assign("javakArray1",$javakArray1);
	$smarty->assign("rojmelArray1",$rojmelArray1);
	$smarty->assign("b1NetFine",$b1NetFine);
	$smarty->assign("b1NetAmt",$b1NetAmt);
	$smarty->assign("b0NetFine",$b0NetFine);
	$smarty->assign("b0NetAmt",$b0NetAmt);
	$smarty->assign("b0aamount",$b0aamount);
	$smarty->assign("b0afine",$b0afine);
	$smarty->assign("to",$to);
	$smarty->assign("from",$from);
	$smarty->assign("aAmount",$aAmount);
	$smarty->assign("aFine",$aFine);
	$smarty->assign("jFine",$jFine);
	$smarty->assign("jAmount",$jAmount);
	$smarty->assign("javakArray",$javakArray);
	$smarty->assign("partyId",$partyId);
	$smarty->assign("netFine",$netFine);
	$smarty->assign("netAmount",$netAmount);
	$smarty->assign("rojmelArray",$rojmelArray);
	$smarty->assign("clientArray",$clientArray);
	$smarty->display("rojmelList_new.tpl");
}
?>