<?php

session_start();


if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("function.inc.php");
include("Functions_Synchro.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

//User Access
$querylog=" select ifNull(login_belongstogrp,0) As FI_BelongsToGrp from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Synchro,0) As Module_Synchro From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$query_setup=" Select base1 As base1, base2 as base2, Setup_Branch from setup";
$result= mysql_query($query_setup,$connection) or die( mysql_error());
while($rowsetup=mysql_fetch_array($result)){
	extract($rowsetup);
}

//optionType = 1 -> copy from group; optionType = 2 -> new setup;
$optionType	  = $_GET['optionType'];

if ($optionType == '') $optionType = '2';

$actionmode   = $_GET["actionmode"]; 			if ($actionmode == ""){		$actionmode 	= $_POST["actionmode"];}   
$mode   	  = $_GET["mode"]; 					if ($mode == ""){			$mode 			= $_POST["mode"];}   
$message 	  = $_GET["message"]; 				if ($message == ""){		$message 		= $_POST["message"];}
$Increment    = $_GET["Increment"]; 			if ($Increment == ""){		$Increment 		= $_POST["Increment"];} 
$IncrementId  = $_GET["IncrementId"]; 			if ($IncrementId == ""){	$IncrementId 	= $_POST["IncrementId"];} 
$Increment2   = $_GET["Increment2"]; 			if ($Increment2 == ""){		$Increment2 	= $_POST["Increment2"];} 
$Group_Code2  = $_GET["Group_Code2"]; 			if ($Group_Code2 == ""){	$Group_Code2 	= $_POST["Group_Code2"];} 
$auto   	  = $_GET["auto"]; 					if ($auto == ""){			$auto 			= $_POST["auto"];} 
$showtrans    = $_GET["showtrans"]; 			if ($showtrans == ""){		$showtrans 		= $_POST["showtrans"];} 

$txtKeyword  = $_POST["txtKeyword"]; 			if ($txtKeyword == ""){		$txtKeyword 	= $_GET["txtKeyword"];}   
$txtKeyword2 = $_POST["txtKeyword2"]; 			if ($txtKeyword2 == ""){	$txtKeyword2 	= $_GET["txtKeyword2"];}   
$vTabFocus   = $_POST["vTabFocus"]; 			if ($vTabFocus == ""){		$vTabFocus 		= $_GET["vTabFocus"];} 

$Group_CreationDate	= $_POST["Group_CreationDate"]; 	if ($Group_CreationDate == ""){	$Group_CreationDate = $_GET["Group_CreationDate"];} 
$Group_Code    		= $_POST["Group_Code"]; 			if ($Group_Code == ""){			$Group_Code 		= $_GET["Group_Code"];} 
$Group_Name 		= $_POST["Group_Name"]; 			if ($Group_Name == ""){			$Group_Name 		= $_GET["Group_Name"];} 
$Group_Commission 	= $_POST["Group_Commission"]; 		if ($Group_Commission == ""){	$Group_Commission 	= $_GET["Group_Commission"];} 
$Group_discountPer 	= $_POST["Group_discountPer"]; 		if ($Group_discountPer == ""){	$Group_discountPer 	= $_GET["Group_discountPer"];} 
$inventory_ledger 	= $_POST["inventory_ledger"]; 		if ($inventory_ledger == ""){	$inventory_ledger 	= $_GET["inventory_ledger"];} 
$charge_ledger 		= $_POST["charge_ledger"]; 			if ($charge_ledger == ""){		$charge_ledger 		= $_GET["charge_ledger"];} 
$revenue_ledger 	= $_POST["revenue_ledger"]; 		if ($revenue_ledger == ""){		$revenue_ledger 	= $_GET["revenue_ledger"];} 
$promotion_ledger 	= $_POST["promotion_ledger"]; 		if ($promotion_ledger == ""){	$promotion_ledger 	= $_GET["promotion_ledger"];} 
$discount_ledger 	= $_POST["discount_ledger"]; 		if ($discount_ledger == ""){	$discount_ledger 	= $_GET["discount_ledger"];} 
$vat_ledger 		= $_POST["vat_ledger"]; 			if ($vat_ledger == ""){			$vat_ledger 		= $_GET["vat_ledger"];} 

$transtype 			= $_POST["transtype"]; 				if ($transtype == ""){			$transtype 			= $_GET["transtype"];} 
$vat_account 		= $_POST["vat_account"]; 			if ($vat_account == ""){		$vat_account 		= $_GET["vat_account"];} 
$vat_accountname 	= $_POST["vat_accountname"]; 		if ($vat_accountname == ""){	$vat_accountname 	= $_GET["vat_accountname"];} 
$currency 			= $_POST["currency"]; 				if ($currency == ""){			$currency 			= $_GET["currency"];} 
$rawmat_account 	= $_POST["rawmat_account"]; 		if ($rawmat_account == ""){		$rawmat_account 	= $_GET["rawmat_account"];} 
$rawmat_accountname = $_POST["rawmat_accountname"]; 	if ($rawmat_accountname == ""){	$rawmat_accountname = $_GET["rawmat_accountname"];} 
$nonrawmat_account 	= $_POST["nonrawmat_account"]; 		if ($nonrawmat_account == ""){	$nonrawmat_account 	= $_GET["nonrawmat_account"];} 

$nonrawmat_accountname 		= $_POST["nonrawmat_accountname"]; 		if ($nonrawmat_accountname == ""){		$nonrawmat_accountname 		= $_GET["nonrawmat_accountname"];} 
$rawmatttc_account 			= $_POST["rawmatttc_account"]; 			if ($rawmatttc_account == ""){			$rawmatttc_account 			= $_GET["rawmatttc_account"];} 
$rawmatttc_accountname 		= $_POST["rawmatttc_accountname"]; 		if ($rawmatttc_accountname == ""){		$rawmatttc_accountname 		= $_GET["rawmatttc_accountname"];} 
$nonrawmatttc_account 		= $_POST["nonrawmatttc_account"]; 		if ($nonrawmatttc_account == ""){		$nonrawmatttc_account 		= $_GET["nonrawmatttc_account"];} 
$nonrawmatttc_accountname 	= $_POST["nonrawmatttc_accountname"]; 	if ($nonrawmatttc_accountname == ""){	$nonrawmatttc_accountname 	= $_GET["nonrawmatttc_accountname"];} 
$disc_account 				= $_POST["disc_account"]; 				if ($disc_account == ""){				$disc_account 				= $_GET["disc_account"];} 
$disc_accountname 			= $_POST["disc_accountname"]; 			if ($disc_accountname == ""){			$disc_accountname 			= $_GET["disc_accountname"];} 
$rawmat_account2 			= $_POST["rawmat_account2"]; 			if ($rawmat_account2 == ""){			$rawmat_account2 			= $_GET["rawmat_account2"];} 
$rawmat_accountname2 		= $_POST["rawmat_accountname2"]; 		if ($rawmat_accountname2 == ""){		$rawmat_accountname2 		= $_GET["rawmat_accountname2"];} 
$nonrawmat_account2 		= $_POST["nonrawmat_account2"]; 		if ($nonrawmat_account2 == ""){			$nonrawmat_account2 		= $_GET["nonrawmat_account2"];} 
$nonrawmat_accountname2		= $_POST["nonrawmat_accountname2"]; 	if ($nonrawmat_accountname2 == ""){		$nonrawmat_accountname2 	= $_GET["nonrawmat_accountname2"];} 
$stockcurrency 				= $_POST["stockcurrency"]; 				if ($stockcurrency == ""){				$stockcurrency 				= $_GET["stockcurrency"];} 
$debit_account 				= $_POST["debit_account"]; 				if ($debit_account == ""){				$debit_account 				= $_GET["debit_account"];} 
$debit_accountname 			= $_POST["debit_accountname"]; 			if ($debit_accountname == ""){			$debit_accountname 			= $_GET["debit_accountname"];} 
$credit_account 			= $_POST["credit_account"]; 			if ($credit_account == ""){				$credit_account 			= $_GET["credit_account"];} 
$credit_accountname 		= $_POST["credit_accountname"]; 		if ($credit_accountname == ""){			$credit_accountname 		= $_GET["credit_accountname"];} 
$tips_account 				= $_POST["tips_account"]; 				if ($tips_account == ""){				$tips_account 				= $_GET["tips_account"];} 
$tips_accountname	 		= $_POST["tips_accountname"]; 			if ($tips_accountname == ""){			$tips_accountname 			= $_GET["tips_accountname"];} 
$group_length	 			= $_POST["group_length"]; 				if ($group_length == ""){				$group_length 				= $_GET["group_length"];} 
$chkGeneralAcc				= $_POST["chkGeneralAcc"]; 				if ($chkGeneralAcc == ""){				$chkGeneralAcc 				= $_GET["chkGeneralAcc"];} 
$ledgerCostAcc				= $_POST['ledgerCostAcc'];   		 	if ($ledgerCostAcc == ""){				$ledgerCostAcc 				= $_GET["ledgerCostAcc"];} 
//echo $mode;exit;	
	
$Group_Code=ereg_replace("'", "\'", $Group_Code);
$Group_Name=ereg_replace("'", "\'", $Group_Name);
$Group_Commission=ereg_replace("'", "\'", $Group_Commission);
$Group_discountPer=ereg_replace("'", "\'", $Group_discountPer);
$Group_Parent=ereg_replace("'", "\'", $Group_Parent);


if (empty($group_length)) $group_length = 0;
if (empty($Group_discountPer)) $Group_discountPer = 0;
if (empty($Group_Commission)) $Group_Commission = 0;
if ($chkGeneralAcc == '') $chkGeneralAcc = 0;

if (!empty($Group_CreationDate))	{
	$Group_CreationDate  = explodeword($Group_CreationDate );
	$Group_CreationDate   = "'$Group_CreationDate '";

}	
else {$Group_CreationDate = 'null';}

$Group_Code=trim($Group_Code);


if($mode=='insert'){
		
	$query="Insert into Grouping (Group_Code,Group_Name,Group_Commission, Group_discountPer, Group_BelongsToGroup,Group_CreationDate,inventory_ledger,charge_ledger,revenue_ledger,promotion_ledger,
			discount_ledger,vat_ledger, Owner_Branch,group_length, grouping_pricelist, Group_Export, VATonSale_ledger, costAdjust_ledger)
			values ('".$Group_Code."', '".$Group_Name."', '".$Group_Commission."', '".$Group_discountPer."', $FI_BelongsToGrp, $Group_CreationDate,'".$inventory_ledger."' ,'".$charge_ledger."','".$revenue_ledger."' ,'".$promotion_ledger."' ,'".$discount_ledger."' ,'".$vat_ledger."', 
			'".$Setup_Branch."', '".$group_length."', '$grouping_pricelist', '$Group_Export', '".$VATonSale_ledger."', '".$costAdjust_ledger."')";

	//echo $query;exit;		
	
	
	$result  = mysql_query($query, $connection);
	
	if($config['log_file'] == 1){
		$transType = "I";
		$company = explode("_", $_SESSION['dbName']);
		$currCompany = strtoupper($company[0]);	
		$query_insertToHistory  = "call ".$config['dbName_history'].".InsertToHistory('$transType', '$Group_Code', '".$_SESSION['useraccount']."', now(), '".$_SESSION['dbName']."', 'grouping', '$currCompany')";
		//echo $query_insertToHistory;exit;
		$result_insertToHistory = mysql_query($query_insertToHistory, $connection);
	}
	if($result){
		$Increment=mysql_insert_id();
		
		if ($optionType == '2') {
			insert_transsetup('AD',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			
			insert_transsetup('PI',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			insert_transsetup('PR',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			
			insert_transsetup('PD',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			
			insert_transsetup('SI',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			insert_transsetup('SR',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			
			
			insert_transsetup('TR',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
			insert_transsetup('SE',$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection);
		} 
		if ($optionType == '1') {
			$queryCopy = " insert into transactionsetup (Journal_type, Group_code, Trans_RMAcc, Trans_RMVatAcc, Trans_NonRMAcc, Trans_NonRMVatAcc, Trans_RMTTCIncAcc, Trans_NonRMTTCIncAcc, Trans_Currency, ".
						 " Trans_DefaultCur, Trans_DirectStkDbt, Trans_DirectStkCrd, Trans_DirectStkCur, Synchronized, CEP_CreditAcc, Trans_wasteDebitAcc, Trans_wasteCreditAcc, ".
						 " Trans_wasteDifferenceAcc, Trans_DiscountAcc, Trans_PromotionAcc, IsoDescription, Trans_VATAccount, trans_Purchasepromotionacc, trans_Purchasediscountacc, ".
						 " Trans_TipsAcc, trans_export, chk_GeneralAccount, ledger_costAcc) ".
						 " select Journal_type, '$Group_Code', Trans_RMAcc, Trans_RMVatAcc, Trans_NonRMAcc, Trans_NonRMVatAcc, Trans_RMTTCIncAcc, Trans_NonRMTTCIncAcc, Trans_Currency, ".
						 " Trans_DefaultCur, Trans_DirectStkDbt, Trans_DirectStkCrd, Trans_DirectStkCur, Synchronized, CEP_CreditAcc, Trans_wasteDebitAcc, Trans_wasteCreditAcc, ".
						 " Trans_wasteDifferenceAcc, Trans_DiscountAcc, Trans_PromotionAcc, IsoDescription, Trans_VATAccount, trans_Purchasepromotionacc, trans_Purchasediscountacc, ".
						 " Trans_TipsAcc, trans_export, chk_GeneralAccount, ledger_costAcc from transactionsetup where group_code = '$group_code2' ";
			$resultCopy = mysql_query($queryCopy);
			if (!$resultCopy)
				$message = mysql_error();
		}
		
		if ($Module_Synchro == 1) {
			InsertSynchroLoc($connection,'I','GROUPING','',$Group_Code,$Setup_Branch);
		}
	}
	else	
		$message = mysql_error();
}




if($mode=='delete')
{	
	$query = "select Group_Code from Grouping where Increment='".$IncrementId."'";
	$result=mysql_query($query,$connection);
	$rows=mysql_fetch_row($result);
	$Group_Code=$rows[0];
	
	if($config['log_file'] == 1){
		$transType = "D";
		$company = explode("_", $_SESSION['dbName']);
		$currCompany = strtoupper($company[0]);	
		$query_insertToHistory  = "call ".$config['dbName_history'].".InsertToHistory('$transType', '$Group_Code', '".$_SESSION['useraccount']."', now(), '".$_SESSION['dbName']."', 'grouping', '$currCompany')";
		//echo $query_insertToHistory;exit;
		$result_insertToHistory = mysql_query($query_insertToHistory, $connection);
	}
	
	$query="delete from Grouping where Increment='".$IncrementId."'";
	//echo$query;exit;
	$result  = mysql_query($query, $connection);
	$message = mysql_error();
	$errornum= mysql_errno();
						
	if($errornum=='1451') {
		$message="Delete Not Allowed . Group is used .";
		//echo $message;
	}
	
	if ($result) {
		if ($Module_Synchro == 1) {
			InsertSynchroLoc($connection,'D','GROUPING','',$Group_Code,$Setup_Branch);
		}
	}
}


if($mode=='edit'){
	$query_update=" update Grouping set Group_Code='".$Group_Code."', ".
				  "	Group_Name='".$Group_Name."' , ".
				  "	Group_Commission='".$Group_Commission."' , ".
				  "	Group_discountPer='".$Group_discountPer."' , ".
				  "Group_CreationDate= $Group_CreationDate,".
				  "inventory_ledger='".$inventory_ledger."' , ".
				  "charge_ledger='".$charge_ledger."' , ".
				  "revenue_ledger='".$revenue_ledger."' , ".
				  "promotion_ledger='".$promotion_ledger."' , ".
				  "discount_ledger='".$discount_ledger."' , ".
				  "vat_ledger='".$vat_ledger."'  ".
				   ",group_length='".$group_length."', grouping_pricelist = '$grouping_pricelist', Group_Export = '$Group_Export',  ".
				   "VATonSale_ledger='".$VATonSale_ledger."'  ".
				   "costAdjust_ledger='".$costAdjust_ledger."'  ".
				  "	where Increment='".$Increment."'";
	//echo $query_update;exit;		

	$resultedit = mysql_query($query_update, $connection);
	$message    = mysql_error();
	
	if($config['log_file'] == 1){
		$transType = "U";
		$company = explode("_", $_SESSION['dbName']);
		$currCompany = strtoupper($company[0]);	
		$query_insertToHistory  = "call ".$config['dbName_history'].".InsertToHistory('$transType', '$Group_Code', '".$_SESSION['useraccount']."', now(), '".$_SESSION['dbName']."', 'grouping', '$currCompany')";
		//echo $query_insertToHistory;exit;
		$result_insertToHistory = mysql_query($query_insertToHistory, $connection);
	}
	
	if ($resultedit) {
		if ($Module_Synchro == 1) {
			InsertSynchroLoc($connection,'U','GROUPING','',$Group_Code,$Setup_Branch);
		}
	}	
}



if($actionmode=='submittrans'){
	
	if($auto==''){
		$query="insert into transactionsetup(Group_code,Journal_type,Trans_VATAccount,Trans_RMAcc,Trans_NonRMAcc,Trans_RMTTCIncAcc,Trans_NonRMTTCIncAcc,Trans_RMVatAcc,Trans_NonRMVatAcc,".
				" Trans_DirectStkDbt,Trans_DirectStkCrd,trans_currency,Trans_DirectStkCur,Trans_DiscountAcc,Trans_TipsAcc, chk_GeneralAccount, ".
				" Trans_wasteDifferenceAcc, Trans_wasteDebitAcc, trans_wastecreditacc, trans_export, ledger_costAcc) ".
				" values ('".$Group_Code2."','".$transtype."','".$vat_account."','".$rawmat_account."','".$nonrawmat_account."','".$rawmatttc_account."','".$nonrawmatttc_account."',".
				" '".$rawmat_account2."','".$nonrawmat_account2."','".$debit_account."','".$credit_account."','".$currency."','".$stockcurrency."','".$disc_account."','".$tips_account."', $chkGeneralAcc, ".
				" '".$export_account."', '".$debit_account2."', '".$credit_account2."', '".$trans_export."', ".GetSQLValueString($ledgerCostAcc,'text')." )";
			
		$result= mysql_query($query, $connection);
		$message    = mysql_error();
	}
	else if($auto!=''){
		$query="update transactionsetup set Journal_type='".$transtype."',
				Trans_VATAccount='".$vat_account."',
				Trans_RMAcc='".$rawmat_account."',
				Trans_NonRMAcc='".$nonrawmat_account."',
				Trans_RMTTCIncAcc='".$rawmatttc_account."',
				Trans_NonRMTTCIncAcc='".$nonrawmatttc_account."',
				Trans_RMVatAcc='".$rawmat_account2."',
				Trans_NonRMVatAcc='".$nonrawmat_account2."',
				Trans_DirectStkDbt='".$debit_account."',
				Trans_DirectStkCrd='".$credit_account."',
				trans_currency='".$currency."',
				Trans_DirectStkCur='".$stockcurrency."',
				Trans_DiscountAcc='".$disc_account."', 
				Trans_TipsAcc='".$tips_account."', ".
				" chk_GeneralAccount = '".$chkGeneralAcc."', ".
				" Trans_wasteDifferenceAcc = '".$export_account."', ".
				" Trans_wasteDebitAcc = '".$debit_account2."', ".
				" trans_wastecreditacc = '".$credit_account2."', ".
				" trans_export 	= '".$trans_export."', ".
				" ledger_costAcc = ".GetSQLValueString($ledgerCostAcc,'text')." ".
				" where auto='".$auto."'";			
		//echo$query;exit;		
		$result= mysql_query($query, $connection);
		$message    = mysql_error();
	}
	
	if ($result) {
		if ($Module_Synchro == 1) {
			InsertSynchroLoc($connection,'U','GROUPING','',$Group_Code2,$Setup_Branch);
		}
	}
	
	$vTabFocus='Transaction';
}

	
$message = ereg_replace(' ','%20',$message);

if($mode=='delete')			   
	header ("Location: ./Form_Grouping.php?mode=insert&message=".$message);
else
	header ("Location: ./Form_Grouping.php?Increment=$Increment&Increment2=$Increment2&transtype=$transtype&showtrans=$showtrans&vTabFocus=$vTabFocus&mode=editmode&txtKeyword=$txtKeyword&txtKeyword2=$txtKeyword2&message=".$message);
	

function insert_transsetup($jvtype,$Group_Code, $inventory_ledger, $charge_ledger, $revenue_ledger, $promotion_ledger, $discount_ledger, $vat_ledger, $VATonSale_ledger, $costAdjust_ledger, $base1, $connection){
	
	$query_transaction = "insert into transactionsetup (Journal_type,group_code, Trans_RMAcc, Trans_RMVatAcc, Trans_NonRMAcc, Trans_NonRMVatAcc, Trans_RMTTCIncAcc, Trans_NonRMTTCIncAcc, Trans_Currency,
						Trans_DefaultCur, Trans_DirectStkDbt, Trans_DirectStkCrd, Trans_DirectStkCur, Synchronized, CEP_CreditAcc, Trans_wasteDebitAcc, Trans_wasteCreditAcc, Trans_wasteDifferenceAcc, 
						Trans_DiscountAcc, Trans_PromotionAcc, IsoDescription, Trans_VATAccount, trans_Purchasepromotionacc, trans_Purchasediscountacc, Trans_TipsAcc  ) 
						values('".$jvtype."','".$Group_Code."' ";
	if ($jvtype == 'AD')
		$query_transaction .= " , ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').",
							".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", '$base1', 1, ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($costAdjust_ledger, 'text').",
							'$base1', 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ";
	else if ($jvtype == 'PI' || $jvtype == 'PR')
		$query_transaction .= " , ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').",
							".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", '$base1', 1, ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($costAdjust_ledger, 'text').",
							'$base1', 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ".GetSQLValueString($vat_ledger, 'text').", NULL, NULL, NULL ";
	else if ($jvtype == 'PD')
		$query_transaction .= " , ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').",
							".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').", '$base1', 1, NULL,NULL , NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ";	
	else if ($jvtype == 'SI')
		$query_transaction .= " , ".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').",
							".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').", '$base1', 1, ".GetSQLValueString($charge_ledger, 'text').", ".GetSQLValueString($inventory_ledger, 'text').",
							'$base1', 0, NULL, NULL, NULL, NULL, ".GetSQLValueString($discount_ledger, 'text').", ".GetSQLValueString($promotion_ledger, 'text').", NULL, ".GetSQLValueString($VATonSale_ledger, 'text').", NULL, NULL, NULL ";
	else if ($jvtype == 'SR')
		$query_transaction .= " , ".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').",
							".GetSQLValueString($revenue_ledger, 'text').", ".GetSQLValueString($revenue_ledger, 'text').", '$base1', 1, ".GetSQLValueString($inventory_ledger, 'text').", ".GetSQLValueString($charge_ledger, 'text').",
							'$base1', 0, NULL, NULL, NULL, NULL, ".GetSQLValueString($discount_ledger, 'text').", ".GetSQLValueString($promotion_ledger, 'text').", NULL, ".GetSQLValueString($VATonSale_ledger, 'text').", NULL, NULL, NULL ";						
	else
		$query_transaction .= " , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ";												
	$query_transaction .= " )";
	//echo$query_transaction;
	$result_transaction= mysql_query($query_transaction, $connection);
	$message = mysql_error();
	
}

exit;
mysql_close($connection);

?>