<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	$pendingArray = array();
	$finetotal = 0;
	$fineamount = 0;
	$motiAmount = 0;
	$rhodium = 0;
	$grosstotal = 0;
	$selectParty = "SELECT * FROM party 
	                   WHERE partyType = 'V'
					  ORDER BY partyName";
	$selectPartyRes = mysql_query($selectParty);
	while($row = mysql_fetch_array($selectPartyRes))
	{
	  $pendingArray[$row['partyId']]['partyId']   = $row['partyId'];
	  $pendingArray[$row['partyId']]['partyName'] = $row['partyName'];
	  $pendingArray[$row['partyId']]['kg'] = 0;
	  $pendingArray[$row['partyId']]['totalAmt'] = 0;
	  $pendingArray[$row['partyId']]['openingAmt']     = 0;
	  $pendingArray[$row['partyId']]['openingFine']   = 0;
	  
	   $slectIssue = "SELECT SUM(kg) AS aKg,SUM(totalAmt) AS aTotalAmt
							  FROM vepari
						   WHERE veTransType = 'A'
					AND partyId = ".$row['partyId']."
					 ";
	  $slectIssueRes = mysql_query($slectIssue);
	  while($irow = mysql_fetch_array($slectIssueRes))
	  {
	    $pendingArray[$row['partyId']]['kg']             -= $irow['aKg'];
	    $pendingArray[$row['partyId']]['totalAmt']       -= $irow['aTotalAmt'];
	  }

	  $slectIssue = "SELECT SUM(kg) AS javakKg,SUM(totalAmt) AS javaktotalAmt
						   FROM vepari
						  WHERE veTransType = 'J'
					AND partyId = ".$row['partyId']."
					 ";
	  $slectIssueResi = mysql_query($slectIssue);
	  while($irow = mysql_fetch_array($slectIssueResi))
	  {
	    $pendingArray[$row['partyId']]['kg']           += $irow['javakKg'];
		$pendingArray[$row['partyId']]['totalAmt']     += $irow['javaktotalAmt'];
	  }
	  
	 
	  
	  $kg        += $pendingArray[$row['partyId']]['kg'];
	  $totalAmt  += $pendingArray[$row['partyId']]['totalAmt'];
	  
	  
	}
}
include("./bottom.php");
$smarty->assign("totalAmt",$totalAmt);
$smarty->assign("kg",$kg);
$smarty->assign("pendingArray",$pendingArray);
$smarty->display("vsummary.tpl");
?>