<?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'] != '' ? $_REQUEST['partyId'] : 0;	 
	$to        = $_REQUEST['toDtYear']."-".$_REQUEST['toDtMonth']."-".$_REQUEST['toDtDay'];  
	$from      = $_REQUEST['fromDtYear']."-".$_REQUEST['fromDtMonth']."-".$_REQUEST['fromDtDay'];  

    if(isset($_POST['btn']))
	{
	  $deleteEntry = "DELETE FROM vepari
                        	 WHERE vDate BETWEEN   
						  '".$to."' AND '".$from."'
						  AND partyId = ".$partyId; 
	  $insertClientRes = mysql_query($deleteEntry);
	  if(!$insertClientRes)
	  {
	  	echo "Delete Fail";
	  }
	  else
	  {
	     header("Location:delete.php");
	  }
	  
	}
	
	$k=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'];
	  $k++;
	}
	
	   $selectClientAavk = "SELECT SUM(vkg) AS aKg,SUM(vTotalAmt) AS aTotalAmt
	                      FROM vepari
					   WHERE veTransType = 'A'
				    AND partyId = ".$partyId;
	$selectClientAavkRes = mysql_query($selectClientAavk);
	if($cavakRow = mysql_fetch_assoc($selectClientAavkRes))
	{
      $aKg          = $cavakRow['aKg'];
	  $aTotalAmt    = $cavakRow['aTotalAmt'];  
	}
    
	$selectClientJavak = "SELECT SUM(vkg) AS javakKg,SUM(vTotalAmt) AS javaktotalAmt
	                   FROM vepari
					  WHERE veTransType = 'J'
				AND partyId = ".$partyId;
	$selectClientJavakRes = mysql_query($selectClientJavak);
	if($cjavakRow = mysql_fetch_assoc($selectClientJavakRes))
	{
      $javakKg          = $cjavakRow['javakKg'];
	  $javaktotalAmt    = $cjavakRow['javaktotalAmt'];  
	}
	
	
	$finalKg     = $javakKg       - $aKg;
	$finalAmount = $javaktotalAmt - $aTotalAmt;
	
	
	
	
	include("./bottom.php");
	$smarty->assign("partyId",$partyId);
	$smarty->assign("finalAmount",$finalAmount);
	$smarty->assign("finalKg",$finalKg);
	$smarty->assign("clientArray",$clientArray);
	$smarty->display("delete.tpl");
}
?>