<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
    $partyId = isset($_REQUEST['partyId']) ? $_REQUEST['partyId'] : 0;
    $k = 0;
    $vepariDetail = array();
    $selectClient = "SELECT * FROM vepari
	                 WHERE vepari.partyId = ".$partyId;
	$selectClientRes = mysql_query($selectClient);
	while($clientRow = mysql_fetch_array($selectClientRes))
	{
	  $vepariDetail[$k]['vepariId']    = $clientRow['vepariId'];
	  $vepariDetail[$k]['veTransType'] = $clientRow['veTransType'];
	  $vepariDetail[$k]['vDate']       =  date('d-m-Y',strtotime($clientRow['vDate']));
	  $vepariDetail[$k]['vParti']      = $clientRow['vParti'];
	  $vepariDetail[$k]['vRate']       = $clientRow['vRate'];
	  $vepariDetail[$k]['vDiff']       = $clientRow['vDiff'];
	  $vepariDetail[$k]['vDiffAmt']    = $clientRow['vDiffAmt'];
	  $vepariDetail[$k]['vTotal']      = $clientRow['vTotal'];
	  $vepariDetail[$k]['vTax']        = $clientRow['vTax'];
	  $vepariDetail[$k]['vkg']         = $clientRow['vkg'];
	  $vepariDetail[$k]['vTotalAmt']   = $clientRow['vTotalAmt'];
	  $k++;
	}
	
	$z=0;
	$clientArray = array();
	$selectClient = "SELECT partyId,partyName
	                   FROM party
					WHERE partyType = 'V'";
	$selectClientRes = mysql_query($selectClient);
	while($clientRow = mysql_fetch_array($selectClientRes))
	{
	  $clientArray['partyId'][$k]   = $clientRow['partyId'];
	  $clientArray['partyName'][$k] = $clientRow['partyName'];
	  $z++;
	}
	if($partyId > 0)
	{
		$selectve = "SELECT SUM(vkg) AS aavkKg,SUM(vTotalAmt) AS aavakvTotalAmt 
					   FROM vepari
					 WHERE veTransType = 'A'";
		$res = mysql_query($selectve);
		if($row = mysql_fetch_array($res))
		{
		  $aavkKg         = $row['aavkKg'];
		  $aavakvTotalAmt = $row['aavakvTotalAmt'];
		}
    
		$selectve = "SELECT SUM(vkg) AS javakKg,SUM(vTotalAmt) AS javakvTotalAmt 
					   FROM vepari
					 WHERE veTransType = 'J'";
		$res = mysql_query($selectve);
		if($row = mysql_fetch_array($res))
		{
		  $javakKg        = $row['javakKg'];
		  $javakvTotalAmt = $row['javakvTotalAmt'];
		}
		
		$finalkg  = $aavkKg - $javakKg;
		$finalAmt = $aavakvTotalAmt - $javakvTotalAmt;
	}	
	include("./bottom.php");
	$smarty->assign("finalAmt",$finalAmt);
	$smarty->assign("finalkg",$finalkg);
	$smarty->assign("partyId",$partyId);
	$smarty->assign("vepariDetail",$vepariDetail);
	$smarty->assign("clientArray",$clientArray);
	$smarty->display("vepariList.tpl");
}
?>