<?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;

    $a = 0;
    $rojmelArray = array();
 
	 
	    $selectRojmel = "SELECT *,partyName FROM sauda
						 LEFT  JOIN party ON party.partyId = sauda.partyId
						  WHERE rojTransType = 'J'
						  AND mcxcheckStatus = 0
						  ORDER BY partyName";
		$selectRojmelRes = mysql_query($selectRojmel);
		while($rojmelRow = mysql_fetch_array($selectRojmelRes))
		{
		  $rojmelArray[$a]['saudaId']     		= $rojmelRow['saudaId'];
		  $rojmelArray[$a]['saudaDate']   		= date('d-m-Y',strtotime($rojmelRow['saudaDate']));
		  $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]['rate']   	  		= $rojmelRow['rate'];
		  $rojmelArray[$a]['cash_type']    		= $rojmelRow['cash_type'];
		  $rojmelArray[$a]['mcxcheckStatus']    = $rojmelRow['mcxcheckStatus'];
		  $a++;
		}
		
		$k = 0;
		$javakArray = array();
		$selectJavak = "SELECT *,partyName FROM sauda
						LEFT JOIN party ON party.partyId = sauda.partyId
						  WHERE rojTransType = 'A'
						   AND mcxcheckStatus = 0
						   ORDER BY partyName";
		$selectJavakRes = mysql_query($selectJavak);
		while($javakRow = mysql_fetch_array($selectJavakRes))
		{
		  $javakArray[$k]['saudaId']     	= $javakRow['saudaId'];
		  $javakArray[$k]['saudaDate']   	= date('d-m-Y',strtotime($javakRow['saudaDate']));
		  $javakArray[$k]['rojTransType'] 	= $javakRow['rojTransType'];
		  $javakArray[$k]['partyName']    	= $javakRow['partyName'];
		  $javakArray[$k]['particular']   	= $javakRow['particular'];
		  $javakArray[$k]['fine']         	= $javakRow['fine'];
		  $javakArray[$k]['amount']       	= $javakRow['amount'];
		  $javakArray[$k]['acc_type']     	= $javakRow['acc_type'];
		  $javakArray[$k]['rate']   	  	= $javakRow['rate'];
		  $javakArray[$k]['cash_type']   	= $javakRow['cash_type'];
		  $javakArray[$k]['mcxcheckStatus'] = $javakRow['mcxcheckStatus'];
		  $k++;
		}	
		 
		 
		//////////////////////////////////////Rtgs : Start ////////////////////////
		$selectRojmel = "SELECT SUM(fine) AS afine,SUM(amount) AS aamount FROM sauda
							WHERE rojTransType = 'A'
							AND cash_type = 'R'
							AND mcxcheckStatus = 0";
		$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 sauda
							WHERE rojTransType = 'J'
							AND cash_type = 'R'
							AND mcxcheckStatus = 0";
		$selectRojmelRes = mysql_query($selectRojmel);
		if($row = mysql_fetch_array($selectRojmelRes))
		{
		  $jFine   = $row['jfine'];
		  $jAmount = $row['jamount'];
		}
		
		$rtgsfine = $jFine - $aFine ;
		$rtgsAmt = $aAmount - $jAmount;
		
		///////////////////////////////////////Rtgs : End //////////////////////// 
		
		
		//////////////////////////////////////Cash : Start ////////////////////////
		$selectRojmelCash = "SELECT SUM(fine) AS cAavakFine,SUM(amount) AS cAavkamount FROM sauda
							WHERE rojTransType = 'A'
							AND cash_type = 'C'
							AND mcxcheckStatus = 0";
		$selectRojmelCashRes = mysql_query($selectRojmelCash);
		if($rowCash = mysql_fetch_array($selectRojmelCashRes))
		{
		  $cAavakFine  =  $rowCash['cAavakFine'];
		  $cAavkamount = $rowCash['cAavkamount'];
		}
		
		$selectRojmelJavak = "SELECT SUM(fine) AS cJavakFine,SUM(amount) AS cJavkamount FROM sauda
							WHERE rojTransType = 'J'
							AND cash_type = 'C'
						AND mcxcheckStatus = 0";
		$selectRojmelJavakRes = mysql_query($selectRojmelJavak);
		if($row = mysql_fetch_array($selectRojmelJavakRes))
		{
		  $cJavakFine   = $row['cJavakFine'];
		  $cJavkamount  = $row['cJavkamount'];
		}
		
		//////////////////////////////////////Cash : End ////////////////////////
		
		$Cashfine = $cJavakFine - $cAavakFine;
		$CashAmt  = $cAavkamount - $cJavkamount;
		
		 
		
		
		$netFine   = $Cashfine + $rtgsfine;
		$netAmount = $rtgsAmt +  $CashAmt;
	 
	
	
	$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++;
	}
	
	
	
	include("./bottom.php");
	$smarty->assign("CashAmt",$CashAmt);
	$smarty->assign("Cashfine",$Cashfine);
	$smarty->assign("rtgsfine",$rtgsfine);
	$smarty->assign("rtgsAmt",$rtgsAmt);
	$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("pendingsaudaList.tpl");
}
?>