<?php

require 'PHPMailer-master/class.phpmailer.php';
session_start();
if($_SESSION['dbName']==""){
    header("location:../index.php");
} 

include("config.inc.php");
include("function.inc.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");

$querysetup= " select  base1,base2,DecimalBase  from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2,maxperpage,company_name from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

$querymodule=" Select ifNull(Module_ReferenceByCostcenter,0) As Module_ReferenceByCostcenter, ifNull(Module_ReferenceByProject,0) As Module_ReferenceByProject, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_PostToJournal,0) As Module_PostToJournal, ifNull(Module_UniqueManualNo,0) As Module_UniqueManualNo ".
			 " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querySalesSetup="Select TipsMaxBase1,ifnull(TipsMaxBase2,0), ifnull(salesjv_paymentmode,0) as salesjv_paymentmode ,cashcur , cashcur2 ,creditaccount,creditaccount2,cashaccount,cashaccount2,checkaccount,checkaccount2  From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
    extract($rowSalesSetup);
}

$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

mysql_query("SET NAMES 'utf8'"); 
mysql_query('SET CHARACTER SET utf8'); 		
mysql_set_charset('utf8', $connection);

// var_dump($_POST);exit;

$actionmode = $_GET['actionmode']; if ($actionmode == '') { $actionmode = $_POST['actionmode']; }
$fromclient = $_GET['fromclient'];
//$toclient = $_GET['toclient'];


$year= date ("Y");
$fromdate="01/01/".$year;
$todate=date("d/m/Y");
// jp
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

 
if ($mode == "getclientname"){
	
    $query = "SELECT Ledger_number,Ledger_name 
                FROM Ledger ";
                
    if($choice==0)
        $query = $query." WHERE Upper(Ledger_number) like Upper('".str_replace('\\','\\\\',$clientcode)."%') ";
    else
        $query = $query." WHERE Upper(Ledger_name) like Upper('%".str_replace('\\','\\\\',$clientcode)."%') ";
    $result=mysql_query($query,$connection) or die(mysql_error());			
    $row=mysql_fetch_array($result);
    $totalrows = mysql_num_rows($result);
    $ClientCode = $row[0];
    $ClientName = $row[1];
    
    
    if($totalrows>1){
    echo '';
    echo"[BRK]";
    echo '';
    } else {
    
    echo $ClientCode;
    echo"[BRK]";
    echo $ClientName;
    }
exit;
}

 
if ($mode == "getprojectname"){
	
    $query = "SELECT project_code,project_name 
                FROM project ";
                
    if($choice==0)
        $query = $query." WHERE Upper(project_code) like Upper('".str_replace('\\','\\\\',$projectcode)."%') ";
    else
        $query = $query." WHERE Upper(project_name) like Upper('%".str_replace('\\','\\\\',$projectcode)."%') ";
    $result=mysql_query($query,$connection) or die(mysql_error());			
    $row=mysql_fetch_array($result);
    $totalrows = mysql_num_rows($result);
    $projectCode = $row[0];
    $projectName = $row[1];
    
    
    if($totalrows>1){
    echo '';
    echo"[BRK]";
    echo '';
    } else {
    
    echo $projectCode;
    echo"[BRK]";
    echo $projectName;
    }
exit;
}

if($actionmode == 'closeshipment'){
    // var_dump($_POST);exit;
    foreach($_POST as $key => $value){
        $a[$key]=$value;
        if(strpos($key, "txtchecked") !== false){ 
            $code=substr($key,10);

            $expledger = 'expledger'.$code;
            $expamt = 'expamt'.$code;
            $jourdate = 'jourdate'.$code;
            $ledgercode = 'ledgernum'.$code;
            $projcode = 'projcode'.$code;
            $incledger = 'incledger'.$code;
            $incamt = 'incamt'.$code;
            $cliledger = 'cliledger'.$code;
            $vatchk = 'invvat'.$code;

            if($$jourdate=='')
            $$jourdate = displayToday();
            $jourdate1 = $$jourdate;
            $ndate = explode('/',$$jourdate);
            //$$jourdate = $ndate[2].'-'.$ndate[1].'-'.$ndate[0];
            $$jourdate = insertMySQLDate($$jourdate);
            //exit;
            if($$expledger!='' && $$expamt !='' && $$expamt !=0 ){
                $closingquery = "call shipmentclosing('".$$ledgercode."','".$$projcode."','".$$jourdate."','".$$expledger."','".$$expamt."',
                                    '".$_SESSION['dbName']."','".$_SESSION['dbLabel']."','".$_SESSION['useraccount']."','".$_SESSION['username']."',0,@id)";
            $resultclosing = mysql_query($closingquery,$connection);

            $message = mysql_error();
             //  exit; 
            }
           // echo"<br>vatchk".$$vatchk;
            // echo"<br>incamt".$$incamt;
            // echo"<br>incledger".$$incledger;
//  exit;
            if($$cliledger !='' && $$incamt !='' && $$incamt !=0 && $$incledger !=''){
                $ErrorExists = 0;

                $txtLedgerNo 		= $$incledger;
                $txtDescription1 	= '';
                $txtDescription2 	= '';
                $txtDtCurr 			= $base1;
                $txtDtQty 			= 1;
                $txtDtPrice 		= $$incamt;
                $txtDtDiscPer 		= 0;
                $txtDtTotal 		= $$incamt;
                $txtDtVat 			= $$vatchk;
                $PVatChkbx			= $$vatchk;
                $PProjectCode		= $$projcode;
                $PClientCode		= $$cliledger;
                $txtProjectCodeDt 	= $$projcode;
                $PDate				= $jourdate1;
                 $txtDtCost 			= '';
                 $message ='';
                 $MainCompanyName=explode('_',$_SESSION['dbName']);

                if (!isset($PCurr))   $PCurr = $base1;
            
                $query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$PCurr."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$PCurr."' )";
                $result = selectData($connection, $query);
                $rate_dt = $result[0];
            
                $query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base1."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base1."' )";
                $result = selectData($connection, $query);
                $rate_dt1 = $result[0];
            
                $query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base2."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base2."' )";
                $result = selectData($connection, $query);
                $rate_dt2 = $result[0];
            $PSalesmanCode ='';
                //Insert Master Table
                if ( $ErrorExists == 0){
            
                    if (empty($PDiscountAmt))	$PDiscountAmt = 0;
                    if (empty($PDiscountPer))	$PDiscountPer = 0;
                    if (empty($PVatChkbx))	    $PVatChkbx = 0;
            
                    if (empty($cashcurrency1) ) $cashcurrency1 = 0;
                    if (empty($bankcurrency1) ) $bankcurrency1 = 0;		
                    if (empty($cardcurrency1) ) $cardcurrency1 = 0;		
                    if (empty($cashcurrency2) ) $cashcurrency2 = 0;		
                    if (empty($bankcurrency2) ) $bankcurrency2 = 0;
                    if (empty($cardcurrency2) ) $cardcurrency2 = 0;
            
                    if (empty($PCostCentCode))		$CostCentCode = 'Null';
                    else		$CostCentCode = "'".$PCostCentCode."'";
            
                    if (empty($PProjectCode))	$ProjectCode = 'Null';
                    else		$ProjectCode = "'".$PProjectCode."'";
            
                    if (empty($PSalesmanCode))	$SalesmanCode = 'Null';
                    else	$SalesmanCode = "'".ereg_replace("'", "\'", trim($PSalesmanCode))."'";		
            
                    fbegin();	
                    $vSalesJVId = get_nextsequence('SalesJV_Id','',$connection);	
                    fcommit();
            
                    $Acc_Query = " SELECT VATAccountNonStock, DiscountAccount FROM salessetup ";
                    $Acc_Result = selectData($connection, $Acc_Query);
            
                    //$vVatAccount = $Acc_Result[0];
                    $vVatAccount = $Acc_Result[0];
                    
            
                    $sub_queryVat = " SELECT GetVATAccount('".$PClientCode."','".$vVatAccount."') from dual ";
                    $sub_resultVat = selectData($connection, $sub_queryVat);
                    if ($sub_resultVat[0] != '') $vVatAccount = $sub_resultVat[0];
            
                     /*
                    &cashcurrency1=0&bankcurrency1=0&cardcurrency1=0&cashcurrency2=0&bankcurrency2=0&cardcurrency2=0
                    */
                    fbegin(); //    on begin  insert payment accounts from sales setup 
                    $query = " INSERT INTO SalesJV (SalesJV_ID, SalesJV_Reference, SalesJV_Date, JournalDt_ValueDate, Client_Code, Salesman_Code, Sales_Remark, ".
                             " Currency_Code, Project_Code, Costcenter_Code, SalesJV_Posted, SalesJV_Edit, Sales_Mode, SalesJV_BelongsToGroup, Journal_Type, Journal_Id, ".
                             " SalesJV_Taxable, SalesJV_TaxableBase1, SalesJV_TaxableBase2, SalesJV_NoneTaxable, SalesJV_NoneTaxableBase1, SalesJV_NoneTaxableBase2, ".
                             " SalesJV_Total, SalesJV_TotalBase1, SalesJV_TotalBase2, SalesJV_VAT, SalesJV_VatBase1, SalesJV_VatBase2, SalesJV_VatCheck, SalesJV_DiscountPer, ".
                             " SalesJV_DiscountAmount, SalesJV_DiscountAmount1, SalesJV_DiscountAmount2, SalesJV_VatAccount, SalesJV_DiscountAccount, SalesJv_ManualNo, ".
                             " SalesJv_VatPrefix, User_Account, SalesJv_CashAmmount1,SalesJv_BankAmmount1, SalesJv_CreditCardAmmount1  ,SalesJv_CashAmmount2,SalesJv_BankAmmount2, ".
                             " SalesJv_CreditCardAmmount2 , SalesJv_CashAccount1,SalesJv_CashAccount2,SalesJv_BankAccount1,SalesJv_BankAccount2,SalesJv_CreditCardAccount1,SalesJv_CreditCardAccount2".
                             "  ) ".
                             " VALUES ( ".$vSalesJVId.", Null, '".insertMySQLDate($PDate)."', '".insertMySQLDate($PDate)."', '".ereg_replace("'", "\'", trim($PClientCode))."', ".
                             "          $SalesmanCode, '', '".$PCurr."', $ProjectCode, $CostCentCode, ".
                             "          0, 0, 0, 0, 'JS', Null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, $PVatChkbx, 0, 0, 0, 0, '".$vVatAccount."', '".$Acc_Result[1]."', ".
                             "          '', '', '".$_SESSION['useraccount']."'". 
                             "," .$cashcurrency1 .",".$bankcurrency1 .",".$cardcurrency1 .",".$cashcurrency2 .",".$bankcurrency2 .",".$cardcurrency2 ."";
            
                            // $query = $query . "," .$creditaccount ."," .$creditaccount2 ."," .$cashaccount ."," .$cashaccount2 .",".$checkaccount.",".$checkaccount2;
            
                             $query = $query . "," .GetSQLValueString($cashaccount,'text') ."," .GetSQLValueString($cashaccount2,'text') ."," .GetSQLValueString($checkaccount,'text') .",
                                                " .GetSQLValueString($checkaccount2,'text') .",".GetSQLValueString($creditaccount,'text').",".GetSQLValueString($creditaccount2,'text');
            
                             // Cash Bank Credit
            
                             $query = $query  ."  )";
                             
                            // global $_mode; 
                            // if($_mode == _DEBUG ) trigger_error($$query,E_USER_NOTICE);  // exit;
            
            
                    $result=mysql_query($query,$connection);
                   //  echo $query."<br>";exit;	
            
                    if ($result){
                        $SId = $vSalesJVId;
                        fcommit();
                    }else{
                        $SId = "";
                        $ErrorExists = 1;
                        $message  = mysql_error(); 
                        frollback();
                    }
            
                }
            
                //Insert Detail Tables
                if ($SId != "" && $ErrorExists == 0){
            
                    if (empty($PDiscountAmt))	$PDiscountAmt = 0;
                    if (empty($PDiscountPer))	$PDiscountPer = 0;
                    if (empty($PVatChkbx))	    $PVatChkbx = 0;
            
                    if (empty($txtDtVat))	    $txtDtVat = 0;	
                    if (empty($txtDtPrice))		$txtDtPrice = 0;
                    if (empty($txtDtDiscPer))   $txtDtDiscPer = 0;
                    if (empty($txtDtQty))  	    $txtSaDtQty = 0;      	
                    if (empty($txtDtTotal))     $txtDtTotal = 0;  
            
                    if (empty($PCostCentCode))		$CostCentCode = 'Null';
                    else		$CostCentCode = "'".$PCostCentCode."'";
            
                    if (empty($PProjectCode))	$ProjectCode = 'Null';
                    else		$ProjectCode = "'".$PProjectCode."'";   
            
                    if ($Module_ProjectDt == 1){
                        if (empty($txtProjectCodeDt))	$ProjectCodeDt = 'Null';
                        else	$ProjectCodeDt = "'".$txtProjectCodeDt."'";
                    } else {
                        $ProjectCodeDt = $ProjectCode;
                    }
                    if ($Module_CostCenterDt == 1) {
                        if (empty($txtCostCentCodeDt))	$CostCentCodeDt = 'Null';
                        else	$CostCentCodeDt = "'".$txtCostCentCodeDt."'";
                    } else {
                        $CostCentCodeDt = $CostCentCode;
                    }
            
                    if (empty($txtDtManualNo)) $vDtManualNo = 'Null';
                    else	$vDtManualNo = "'".$txtDtManualNo."'";
            
                    $vDtQty           = 0;
                    $vDtDiscPer       = 0;
                    $vDtTotal         = 0;
                    $vDtPrice         = 0;
                    $vDtPriceBase1    = 0;
                    $vDtPriceBase2    = 0;
                    $vDtDiscAmt       = 0;
                    $vDtDiscAmtBase1  = 0;
                    $vDtDiscAmtBase2  = 0;
            
                    $vDtQty        = $txtDtQty;
                    $vDtDiscPer    = $txtDtDiscPer;
                    $vDtVat        = $txtDtVat;
                    $vDtTotal      = $txtDtTotal;
            
                    $vDtPrice      = $txtDtPrice;
                    $vDtPriceBase1 = ($vDtPrice*$rate_dt)/$rate_dt1;
                    $vDtPriceBase2 = ($vDtPrice*$rate_dt)/$rate_dt2;
            
                    /* Cost HERE */
            
                    $vDtCost          =  $txtDtCost;
                    if ($vDtCost == '') $vDtCost = 0;
                    $vDtCostBase1     = ($vDtCost*$rate_dt)/$rate_dt1;
                    $vDtCostBase2     = ($vDtCost*$rate_dt)/$rate_dt2;
            
                    $vDtDiscAmt       = ((($vDtPrice*$vDtQty) - ($vDtPrice*$vDtQty*$vDtDiscPer/100))*$PDiscountPer)/100;
                    $vDtDiscAmtBase1  = ($vDtDiscAmt*$rate_dt)/$rate_dt1;
                    $vDtDiscAmtBase2  = ($vDtDiscAmt*$rate_dt)/$rate_dt2;				
            
            
                    if ($ErrorExists == 0){
            
                        fbegin();
                        $vSalesJVDtId = get_nextsequence('SalesJVDt_Id','',$connection);	
                        fcommit();
            
                        fbegin();
            
                        // INsert  Income Account , Cost Account , SupplierAccount
            
                         $sub_query= " Select ifNull(AllowLockedPeriod,0) As AllowLockedPeriod, LockedPeriod As LockedPeriodDate, LockedPeriodDays As LockedPeriodDays ".
                            " From ".$_SESSION['dbLabel'].".ListUserDir  ".
                            " Where Usercode='".$_SESSION['useraccount']."' ".
                            " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
                            " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
            
                         $querydflproject="select CostAccount, SupplierAccount from salesjvsetup where IncomeAccount = '".ereg_replace("'", "\'", trim($txtLedgerNo))."'  ";
                         $resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
                           while($rows=mysql_fetch_array($resultdflproject)){
                             extract($rows);
                            }
                  if($salesjv_paymentmode ==1)
                  {
                        $query = " INSERT INTO SalesJVDt (SalesJVDt_Id, SalesJV_Id, SalesJV_Date, Currency_Code, Client_Code, Salesman_Code, Ledger_Number, SalesJVDt_Description, SalesJVDt_Description2, ". 
                                 " Project_Code, Costcenter_Code, SalesJVDt_Quantity, SalesJVDt_Price, SalesJVDt_PriceBase1, SalesJVDt_PriceBase2, SalesJVDt_DiscountPer, SalesJVDt_DiscountAmount, ".
                                 " SalesJVDt_DiscountAmount1, SalesJVDt_DiscountAmount2, SalesJVDTCalcTotal, SalesJVDt_VAT, Journal_Type, SalesJvDt_ManualNo, cost, costbase1, costbase2, costaccount, supplieraccount )  ".
                                 " VALUES ( ".$vSalesJVDtId.", ".$SId.", '".insertMySQLDate($PDate)."', '".$PCurr."', '".ereg_replace("'", "\'", trim($PClientCode))."', ".
                                 "          '".ereg_replace("'", "\'", trim($PSalesmanCode))."', '".ereg_replace("'", "\'", trim($txtLedgerNo))."', '".ereg_replace("'", "\'", trim($txtDescription1))."', ".
                                 "          '".ereg_replace("'", "\'", trim($txtDescription2))."', $ProjectCodeDt, $CostCentCodeDt, $vDtQty, $vDtPrice, $vDtPriceBase1, $vDtPriceBase2, $vDtDiscPer, ".
                                 "          $vDtDiscAmt, $vDtDiscAmtBase1, $vDtDiscAmtBase2, $vDtTotal, $vDtVat, 'JS', $vDtManualNo, $vDtCost, $vDtCostBase1, $vDtCostBase2, '".$CostAccount."' , '".$SupplierAccount."'	) ";		  
                  }
                  else
                  {
                                  $query = " INSERT INTO SalesJVDt (SalesJVDt_Id, SalesJV_Id, SalesJV_Date, Currency_Code, Client_Code, Salesman_Code, Ledger_Number, SalesJVDt_Description, SalesJVDt_Description2, ". 
                                 " Project_Code, Costcenter_Code, SalesJVDt_Quantity, SalesJVDt_Price, SalesJVDt_PriceBase1, SalesJVDt_PriceBase2, SalesJVDt_DiscountPer, SalesJVDt_DiscountAmount, ".
                                 " SalesJVDt_DiscountAmount1, SalesJVDt_DiscountAmount2, SalesJVDTCalcTotal, SalesJVDt_VAT, Journal_Type, SalesJvDt_ManualNo )  ".
                                 " VALUES ( ".$vSalesJVDtId.", ".$SId.", '".insertMySQLDate($PDate)."', '".$PCurr."', '".ereg_replace("'", "\'", trim($PClientCode))."', ".
                                 "          '".ereg_replace("'", "\'", trim($PSalesmanCode))."', '".ereg_replace("'", "\'", trim($txtLedgerNo))."', '".ereg_replace("'", "\'", trim($txtDescription1))."', ".
                                 "          '".ereg_replace("'", "\'", trim($txtDescription2))."', $ProjectCodeDt, $CostCentCodeDt, $vDtQty, $vDtPrice, $vDtPriceBase1, $vDtPriceBase2, $vDtDiscPer, ".
                                 "          $vDtDiscAmt, $vDtDiscAmtBase1, $vDtDiscAmtBase2, $vDtTotal, $vDtVat, 'JS', $vDtManualNo ) ";
                  }
            
            
                        // echo $query."<br>";exit;				
                        $result=mysql_query($query,$connection);
            
                        if ($result){
                            fcommit();
                        } else{
                            $txtDtId = "";
                            $ErrorExists = 1;
                            $message  = mysql_error(); 
                            frollback();
                        }	
            
                        if ($ErrorExists == 0) {
                            //Calculating Master Amounts
                            $CalculateResult = Calculate_MasterAmounts($SId, $PDate, $PVatChkbx, $PDiscountPer, 0, $rate_dt, $rate_dt1, $rate_dt2, $Setup_VatStartDate, $Setup_VatPercentage, 'I', $connection);
                            $message  = $message . $CalculateResult;
                        }
                        
                        fbegin();
						$vRef = get_nextsequence('SalesJV_Reference','',$connection);	
						fcommit();

						$query = " UPDATE SalesJV SET ".
								 " SalesJV_Reference = $vRef ".
								 " WHERE SalesJV_ID = $SId ";

						if (!updateData($connection, $query, true)) 
							$message  = mysql_error();

                            if ($Module_PostToJournal == 1) {
                                $message = Create_SalesJVJv($SId, $_SESSION['dbName'], $_SESSION['dbLabel'], $_SESSION['useraccount'], $_SESSION['username'], 0); 
                            }
                    }
                }
            }
        }           
        //echo"<br>";
    }
    header ("Location: ./Form_shipmentclosing1.php");
} 
else 
if($actionmode == 'generateall'){
//var_dump($_POST);exit;
    $sjv=0;
    foreach($_POST as $key => $value){
        $a[$key]=$value;

        if(strpos($key, "txtchecked") !== false){ 
            $code=substr($key,10);
            $expledger = 'expledger'.$code;
            $expamt = 'expamt'.$code;
            $jourdate = 'jourdate'.$code;
            $ledgercode = 'ledgernum'.$code;
            $projcode = 'projcode'.$code;
            $incledger = 'incledger'.$code;
            $incamt = 'incamt'.$code;
            $cliledger = 'cliledger'.$code;
            $vatchk = 'invvat'.$code;
            if($$cliledger !='' && $$incamt !='' && $$incamt !=0 && $$incledger !=''){
                $ErrorExists = 0;
                
                if($$jourdate=='')
                $$jourdate = displayToday();
                $jourdate1 = $$jourdate;
                $ndate = explode('/',$$jourdate);
                //echo$$jourdate = $ndate[2].'-'.$ndate[1].'-'.$ndate[0];
                //$$jourdate = insertMySQLDate($$jourdate);
                //echo$$jourdate;

                $txtLedgerNo 		= $$incledger;
                $txtDescription1 	= '';
                $txtDescription2 	= '';
                $txtDtCurr 			= $base1;
                $txtDtQty 			= 1;
                $txtDtPrice 		= $$incamt;
                $txtDtDiscPer 		= 0;
                $txtDtTotal 		= $$incamt;
                $txtDtVat 			= $$vatchk;
                $PVatChkbx			= $$vatchk;
                $PProjectCode		= $$projcode;
                $PClientCode		= $$cliledger;
                $txtProjectCodeDt 	= $$projcode;
                $PDate				= $$jourdate;
                 $txtDtCost 			= '';
                 $message ='';
                 $MainCompanyName=explode('_',$_SESSION['dbName']);

                if (!isset($PCurr))   $PCurr = $base1;
            
                $query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$PCurr."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$PCurr."' )";
                $result = selectData($connection, $query);
                $rate_dt = $result[0];
            
                $query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base1."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base1."' )";
                $result = selectData($connection, $query);
                $rate_dt1 = $result[0];
            
                $query = "SELECT Curdt_Rate FROM curdt WHERE Currency_Code = '".$base2."' AND Curdt_date = (SELECT MAX(Curdt_date) FROM curdt WHERE Currency_Code = '".$base2."' )";
                $result = selectData($connection, $query);
                $rate_dt2 = $result[0];
            $PSalesmanCode ='';
                //Insert Master Table

                if ( $ErrorExists == 0 && $sjv==0){
            
                    if (empty($PDiscountAmt))	$PDiscountAmt = 0;
                    if (empty($PDiscountPer))	$PDiscountPer = 0;
                    if (empty($PVatChkbx))	    $PVatChkbx = 0;
            
                    if (empty($cashcurrency1) ) $cashcurrency1 = 0;
                    if (empty($bankcurrency1) ) $bankcurrency1 = 0;		
                    if (empty($cardcurrency1) ) $cardcurrency1 = 0;		
                    if (empty($cashcurrency2) ) $cashcurrency2 = 0;		
                    if (empty($bankcurrency2) ) $bankcurrency2 = 0;
                    if (empty($cardcurrency2) ) $cardcurrency2 = 0;
            
                    if (empty($PCostCentCode))		$CostCentCode = 'Null';
                    else		$CostCentCode = "'".$PCostCentCode."'";
            
                    if (empty($PProjectCode))	$ProjectCode = 'Null';
                    else		$ProjectCode = "'".$PProjectCode."'";
            
                    if (empty($PSalesmanCode))	$SalesmanCode = 'Null';
                    else	$SalesmanCode = "'".ereg_replace("'", "\'", trim($PSalesmanCode))."'";		
            
                    fbegin();	
                    $vSalesJVId = get_nextsequence('SalesJV_Id','',$connection);	
                    fcommit();
            
                    $Acc_Query = " SELECT VATAccountNonStock, DiscountAccount FROM salessetup ";
                    $Acc_Result = selectData($connection, $Acc_Query);
            
                    //$vVatAccount = $Acc_Result[0];
                    $vVatAccount = $Acc_Result[0];
                    
            
                    $sub_queryVat = " SELECT GetVATAccount('".$PClientCode."','".$vVatAccount."') from dual ";
                    $sub_resultVat = selectData($connection, $sub_queryVat);
                    if ($sub_resultVat[0] != '') $vVatAccount = $sub_resultVat[0];
            
                     /*
                    &cashcurrency1=0&bankcurrency1=0&cardcurrency1=0&cashcurrency2=0&bankcurrency2=0&cardcurrency2=0
                    */
                    fbegin(); //    on begin  insert payment accounts from sales setup 
                    $query = " INSERT INTO SalesJV (SalesJV_ID, SalesJV_Reference, SalesJV_Date, JournalDt_ValueDate, Client_Code, Salesman_Code, Sales_Remark, ".
                             " Currency_Code, Project_Code, Costcenter_Code, SalesJV_Posted, SalesJV_Edit, Sales_Mode, SalesJV_BelongsToGroup, Journal_Type, Journal_Id, ".
                             " SalesJV_Taxable, SalesJV_TaxableBase1, SalesJV_TaxableBase2, SalesJV_NoneTaxable, SalesJV_NoneTaxableBase1, SalesJV_NoneTaxableBase2, ".
                             " SalesJV_Total, SalesJV_TotalBase1, SalesJV_TotalBase2, SalesJV_VAT, SalesJV_VatBase1, SalesJV_VatBase2, SalesJV_VatCheck, SalesJV_DiscountPer, ".
                             " SalesJV_DiscountAmount, SalesJV_DiscountAmount1, SalesJV_DiscountAmount2, SalesJV_VatAccount, SalesJV_DiscountAccount, SalesJv_ManualNo, ".
                             " SalesJv_VatPrefix, User_Account, SalesJv_CashAmmount1,SalesJv_BankAmmount1, SalesJv_CreditCardAmmount1  ,SalesJv_CashAmmount2,SalesJv_BankAmmount2, ".
                             " SalesJv_CreditCardAmmount2 , SalesJv_CashAccount1,SalesJv_CashAccount2,SalesJv_BankAccount1,SalesJv_BankAccount2,SalesJv_CreditCardAccount1,SalesJv_CreditCardAccount2".
                             "  ) ".
                             " VALUES ( ".$vSalesJVId.", Null, '".insertMySQLDate($PDate)."', '".insertMySQLDate($PDate)."', '".ereg_replace("'", "\'", trim($PClientCode))."', ".
                             "          $SalesmanCode, '', '".$PCurr."', $ProjectCode, $CostCentCode, ".
                             "          0, 0, 0, 0, 'JS', Null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, $PVatChkbx, 0, 0, 0, 0, '".$vVatAccount."', '".$Acc_Result[1]."', ".
                             "          '', '', '".$_SESSION['useraccount']."'". 
                             "," .$cashcurrency1 .",".$bankcurrency1 .",".$cardcurrency1 .",".$cashcurrency2 .",".$bankcurrency2 .",".$cardcurrency2 ."";
            
                            // $query = $query . "," .$creditaccount ."," .$creditaccount2 ."," .$cashaccount ."," .$cashaccount2 .",".$checkaccount.",".$checkaccount2;
            
                             $query = $query . "," .GetSQLValueString($cashaccount,'text') ."," .GetSQLValueString($cashaccount2,'text') ."," .GetSQLValueString($checkaccount,'text') .",
                                                " .GetSQLValueString($checkaccount2,'text') .",".GetSQLValueString($creditaccount,'text').",".GetSQLValueString($creditaccount2,'text');
            
                             // Cash Bank Credit
            
                             $query = $query  ."  )";
                             
                            // global $_mode; 
                            // if($_mode == _DEBUG ) trigger_error($$query,E_USER_NOTICE);  // exit;
            
            
                    $result=mysql_query($query,$connection);
                    // echo $query."<br>";exit;	
            
                    if ($result){
                        $SId = $vSalesJVId;
                        $sjv=1;
                        fcommit();
                    }else{
                        $SId = "";
                        $ErrorExists = 1;
                        $message  = mysql_error(); 
                        frollback();
                    }
            
                }

                if($PVatChkbx ==1 && $sjv==1){
                    $queryvat = "update salesjv set SalesJV_VatCheck = 1 where SalesJV_ID = ".$vSalesJVId;
                    $resvat = mysql_query($queryvat,$connection);
                }
            
                //Insert Detail Tables
                if ($SId != "" && $ErrorExists == 0){
            
                    if (empty($PDiscountAmt))	$PDiscountAmt = 0;
                    if (empty($PDiscountPer))	$PDiscountPer = 0;
                    if (empty($PVatChkbx))	    $PVatChkbx = 0;
            
                    if (empty($txtDtVat))	    $txtDtVat = 0;	
                    if (empty($txtDtPrice))		$txtDtPrice = 0;
                    if (empty($txtDtDiscPer))   $txtDtDiscPer = 0;
                    if (empty($txtDtQty))  	    $txtSaDtQty = 0;      	
                    if (empty($txtDtTotal))     $txtDtTotal = 0;  
            
                    if (empty($PCostCentCode))		$CostCentCode = 'Null';
                    else		$CostCentCode = "'".$PCostCentCode."'";
            
                    if (empty($PProjectCode))	$ProjectCode = 'Null';
                    else		$ProjectCode = "'".$PProjectCode."'";   
            
                    if ($Module_ProjectDt == 1){
                        if (empty($txtProjectCodeDt))	$ProjectCodeDt = 'Null';
                        else	$ProjectCodeDt = "'".$txtProjectCodeDt."'";
                    } else {
                        $ProjectCodeDt = $ProjectCode;
                    }
                    if ($Module_CostCenterDt == 1) {
                        if (empty($txtCostCentCodeDt))	$CostCentCodeDt = 'Null';
                        else	$CostCentCodeDt = "'".$txtCostCentCodeDt."'";
                    } else {
                        $CostCentCodeDt = $CostCentCode;
                    }
            
                    if (empty($txtDtManualNo)) $vDtManualNo = 'Null';
                    else	$vDtManualNo = "'".$txtDtManualNo."'";
            
                    $vDtQty           = 0;
                    $vDtDiscPer       = 0;
                    $vDtTotal         = 0;
                    $vDtPrice         = 0;
                    $vDtPriceBase1    = 0;
                    $vDtPriceBase2    = 0;
                    $vDtDiscAmt       = 0;
                    $vDtDiscAmtBase1  = 0;
                    $vDtDiscAmtBase2  = 0;
            
                    $vDtQty        = $txtDtQty;
                    $vDtDiscPer    = $txtDtDiscPer;
                    $vDtVat        = $txtDtVat;
                    $vDtTotal      = $txtDtTotal;
            
                    $vDtPrice      = $txtDtPrice;
                    $vDtPriceBase1 = ($vDtPrice*$rate_dt)/$rate_dt1;
                    $vDtPriceBase2 = ($vDtPrice*$rate_dt)/$rate_dt2;
            
                    /* Cost HERE */
            
                    $vDtCost          =  $txtDtCost;
                    if ($vDtCost == '') $vDtCost = 0;
                    $vDtCostBase1     = ($vDtCost*$rate_dt)/$rate_dt1;
                    $vDtCostBase2     = ($vDtCost*$rate_dt)/$rate_dt2;
            
                    $vDtDiscAmt       = ((($vDtPrice*$vDtQty) - ($vDtPrice*$vDtQty*$vDtDiscPer/100))*$PDiscountPer)/100;
                    $vDtDiscAmtBase1  = ($vDtDiscAmt*$rate_dt)/$rate_dt1;
                    $vDtDiscAmtBase2  = ($vDtDiscAmt*$rate_dt)/$rate_dt2;				
            
            
                    if ($ErrorExists == 0){
            
                        fbegin();
                        $vSalesJVDtId = get_nextsequence('SalesJVDt_Id','',$connection);	
                        fcommit();
            
                        fbegin();
            
                        // INsert  Income Account , Cost Account , SupplierAccount
            
                         $sub_query= " Select ifNull(AllowLockedPeriod,0) As AllowLockedPeriod, LockedPeriod As LockedPeriodDate, LockedPeriodDays As LockedPeriodDays ".
                            " From ".$_SESSION['dbLabel'].".ListUserDir  ".
                            " Where Usercode='".$_SESSION['useraccount']."' ".
                            " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
                            " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
            
                         $querydflproject="select CostAccount, SupplierAccount from salesjvsetup where IncomeAccount = '".ereg_replace("'", "\'", trim($txtLedgerNo))."'  ";
                         $resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
                           while($rows=mysql_fetch_array($resultdflproject)){
                             extract($rows);
                            }
                            if($$expamt=='') $$expamt=0;
                  if($salesjv_paymentmode ==1)
                  {
                       $query = " INSERT INTO SalesJVDt (SalesJVDt_Id, SalesJV_Id, SalesJV_Date, Currency_Code, Client_Code, Salesman_Code, Ledger_Number, SalesJVDt_Description, SalesJVDt_Description2, ". 
                                 " Project_Code, Costcenter_Code, SalesJVDt_Quantity, SalesJVDt_Price, SalesJVDt_PriceBase1, SalesJVDt_PriceBase2, SalesJVDt_DiscountPer, SalesJVDt_DiscountAmount, ".
                                 " SalesJVDt_DiscountAmount1, SalesJVDt_DiscountAmount2, SalesJVDTCalcTotal, SalesJVDt_VAT, Journal_Type, SalesJvDt_ManualNo, cost, costbase1, costbase2,
                                  costaccount, supplieraccount,ledger_numbercredit ,ledger_numberdebit ,expencesamt)  ".
                                 " VALUES ( ".$vSalesJVDtId.", ".$SId.", '".insertMySQLDate($PDate)."', '".$PCurr."', '".ereg_replace("'", "\'", trim($PClientCode))."', ".
                                 "          '".ereg_replace("'", "\'", trim($PSalesmanCode))."', '".ereg_replace("'", "\'", trim($txtLedgerNo))."', '".ereg_replace("'", "\'", trim($txtDescription1))."', ".
                                 "          '".ereg_replace("'", "\'", trim($txtDescription2))."', $ProjectCodeDt, $CostCentCodeDt, $vDtQty, $vDtPrice, $vDtPriceBase1, $vDtPriceBase2, $vDtDiscPer, ".
                                 "          $vDtDiscAmt, $vDtDiscAmtBase1, $vDtDiscAmtBase2, $vDtTotal, $vDtVat, 'JS', $vDtManualNo, $vDtCost, $vDtCostBase1, $vDtCostBase2, '".$CostAccount."' , 
                                 '".$SupplierAccount."' , '".$$ledgercode."', '".$$expledger."'	 , '".$$expamt."') ";		  
                  }
                  else
                  {
                   $query = " INSERT INTO SalesJVDt (SalesJVDt_Id, SalesJV_Id, SalesJV_Date, Currency_Code, Client_Code, Salesman_Code, Ledger_Number, SalesJVDt_Description, SalesJVDt_Description2, ". 
                                 " Project_Code, Costcenter_Code, SalesJVDt_Quantity, SalesJVDt_Price, SalesJVDt_PriceBase1, SalesJVDt_PriceBase2, SalesJVDt_DiscountPer, SalesJVDt_DiscountAmount, ".
                                 " SalesJVDt_DiscountAmount1, SalesJVDt_DiscountAmount2, SalesJVDTCalcTotal, SalesJVDt_VAT, Journal_Type, SalesJvDt_ManualNo ,ledger_numbercredit ,ledger_numberdebit ,expencesamt )  ".
                                 " VALUES ( ".$vSalesJVDtId.", ".$SId.", '".insertMySQLDate($PDate)."', '".$PCurr."', '".ereg_replace("'", "\'", trim($PClientCode))."', ".
                                 "          '".ereg_replace("'", "\'", trim($PSalesmanCode))."', '".ereg_replace("'", "\'", trim($txtLedgerNo))."', '".ereg_replace("'", "\'", trim($txtDescription1))."', ".
                                 "          '".ereg_replace("'", "\'", trim($txtDescription2))."', $ProjectCodeDt, $CostCentCodeDt, $vDtQty, $vDtPrice, $vDtPriceBase1, $vDtPriceBase2, $vDtDiscPer, ".
                                 "          $vDtDiscAmt, $vDtDiscAmtBase1, $vDtDiscAmtBase2, $vDtTotal, $vDtVat, 'JS', $vDtManualNo  , '".$$ledgercode."', '".$$expledger."', '".$$expamt."') ";
                  }
            
            
                        // echo $query."<br>";exit;				
                        $result=mysql_query($query,$connection);
            
                        if ($result){
                            fcommit();
                        } else{
                            $txtDtId = "";
                            $ErrorExists = 1;
                            $message  = mysql_error(); 
                            frollback();
                        }	
            

                    }
                }
            }
        }           
        
        //echo"<br>";
    }
   // exit;
    if($sjv==1){
    if ($ErrorExists == 0) {
        //Calculating Master Amounts
        $CalculateResult = Calculate_MasterAmounts($SId, $PDate, $PVatChkbx, $PDiscountPer, 0, $rate_dt, $rate_dt1, $rate_dt2, $Setup_VatStartDate, $Setup_VatPercentage, 'I', $connection);
        $message  = $message . $CalculateResult;
    }
    
    fbegin();
    $vRef = get_nextsequence('SalesJV_Reference','',$connection);	
    fcommit();

    $query = " UPDATE SalesJV SET ".
             " SalesJV_Reference = $vRef ".
             " WHERE SalesJV_ID = $SId ";

    if (!updateData($connection, $query, true)) 
        $message  = mysql_error();

        if ($Module_PostToJournal == 1) {
            $message = Create_SalesJVJv($SId, $_SESSION['dbName'], $_SESSION['dbLabel'], $_SESSION['useraccount'], $_SESSION['username'], 0); 
        }
    }
    header ("Location: ./Form_shipmentclosing1.php");
} 
function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}

function Create_SalesJVJv($PId, $DbName, $DbLabel, $UserAccount, $UserName, $BelongsToGrp) {

	include("config.inc.php");
	
	$conn = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
	mysql_select_db($DbName, $conn) or die("Could not find DB");

	fbegin();
	$resultvars = mysql_query("set @id :=0 ", $conn);

	$query = " call Create_SalesJVAutoJv(".$PId.", 0, '".$DbName."', '".$DbLabel."', '".$UserAccount."', '".$UserName."', '".$BelongsToGrp."', @id) ";
	//echo $query; exit;
	$result = mysql_query($query,$conn);
    $error = mysql_error();
	
	$query1 = " select @id from dual ";
	$result1 = mysql_query($query1,$conn) or die(mysql_error());
	$cur1 = mysql_fetch_row($result1);
	

	fcommit();
	
	
    if ($cur1[0] == -2)
	   $error = 'Error In Procedure Create_SalesJVAutoJv: '.$error;
	else if  ($cur1[0] == -1)  
	   $error = 'Error In Procedure Create_Jv: '.$error;   
	else if  ($error != '')  
		$error = 'Error In Function Create_SalesJVJv: '.$error;

	Return $error;
	

}

function Calculate_MasterAmounts($PId, $PDate, $PVatChk, $PDiscPer, $PDiscAmt, $PRate, $PRate1, $PRate2, $PSetupVatStartDate, $PSetupVatPercentage, $PMode, $connection) {

	$vDtTotal  = 0;
	$vDtVatChk = 0;

	$vTaxable        = 0;
	$vNoneTaxable    = 0;
	$vGrossTotal     = 0;
	$vDiscountAmt    = 0;
	$vDiscountPer    = 0;
	$vVatAmt      = 0;
	$vVatAmtBase1 = 0;
	$vVatAmtBase2 = 0;

	$vDiscountPer = $PDiscPer;

	// In Case Not Save, Then Get The Vat CheckBox From Table Sorder
	if ($PMode != 'P') {
		$sub_query = "Select ifNull(SalesJV_VatCheck, 0) From SalesJV Where SalesJV_ID = '".$PId."'";
		//echo "<br><br>".$sub_query;
		$sub_result = selectData($connection, $sub_query);
		$PVatChk    = $sub_result[0];

	}

	//Calculating Master Amounts
	$sub_query = " Select Ledger_Number, ((ifNull(SalesJVDt_Quantity,0)*ifNull(SalesJVDt_Price,0))-((ifNull(SalesJVDt_Quantity,0)*ifNull(SalesJVDt_Price,0)*ifNull(SalesJVDt_DiscountPer,0))/100)) As Total, ".
				 " ifNull(SalesJVDt_VAT,0),  SalesJVDt_Quantity, ifNull(SalesJVDt_DiscountAmount,0) ".
				 " From SalesJVDt ".
				 " Where SalesJV_ID = ".$PId;

	//echo $sub_query;
	$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
	while($sub_rows=mysql_fetch_array($sub_result)){

		$vDtTotal   = $sub_rows[1];
		$vDtVatChk  = $sub_rows[2];

		$tax_flag = 0;
		$notax_flag = 1;
		if ($vDtVatChk > 0){
			$tax_flag = 1;
			$notax_flag = 0;
		}	

		$vTaxable     = $vTaxable     + ($vDtTotal*$tax_flag);
		$vNoneTaxable = $vNoneTaxable + ($vDtTotal*$notax_flag);

		// Calculation of Vat Amount
		if ((insertDate($PDate) > $PSetupVatStartDate && $PSetupVatPercentage > 0)  && $PVatChk == 1 && $vDtVatChk == 1 && $vDtTotal > 0)
			$vVatAmt = $vVatAmt + (($vDtTotal - $sub_rows[4])*$PSetupVatPercentage/100);

	}			

	$vGrossTotal = $vTaxable + $vNoneTaxable;

	// Calculation of Discount Amount	

	if ($PMode == 'P') {
		$vDiscountAmt      = $PDiscAmt;					
	} else {
		if ($vDiscountPer > 0) {
			$vDiscountAmt     = (($vGrossTotal * $vDiscountPer) / 100);
		}	
	}

	$vNetTotal         = $vGrossTotal + $vVatAmt - $vDiscountAmt;
	$vTaxableBase1     = ($vTaxable*$PRate)/$PRate1;
	$vTaxableBase2     = ($vTaxable*$PRate)/$PRate2;
	$vNoneTaxableBase1 = ($vNoneTaxable*$PRate)/$PRate1;
	$vNoneTaxableBase2 = ($vNoneTaxable*$PRate)/$PRate2;
	$vDiscountAmtBase1 = ($vDiscountAmt*$PRate)/$PRate1;
	$vDiscountAmtBase2 = ($vDiscountAmt*$PRate)/$PRate2;
	$vGrossTotalBase1  = ($vGrossTotal*$PRate)/$PRate1;
	$vGrossTotalBase2  = ($vGrossTotal*$PRate)/$PRate2;
	$vVatAmtBase1 	   = ($vVatAmt*$PRate)/$PRate1;
	$vVatAmtBase2 	   = ($vVatAmt*$PRate)/$PRate2;
$error='';
	fbegin();

	$sub_query1 = " UPDATE SalesJV SET ".
				  " SalesJV_Taxable = $vTaxable, SalesJV_TaxableBase1 = $vTaxableBase1, SalesJV_TaxableBase2 = $vTaxableBase2, ".
				  " SalesJV_NoneTaxable = $vNoneTaxable, SalesJV_NoneTaxableBase1 = $vNoneTaxableBase1, SalesJV_NoneTaxableBase2 = $vNoneTaxableBase2, ".
				  " SalesJV_DiscountAmount = $vDiscountAmt, SalesJV_DiscountAmount1 = $vDiscountAmtBase1, SalesJV_DiscountAmount2 = $vDiscountAmtBase2, ".
				  " SalesJV_DiscountPer = $vDiscountPer, SalesJV_VAT = $vVatAmt, SalesJV_VatBase1 = $vVatAmtBase1, SalesJV_VatBase2 = $vVatAmtBase2, ".
				  " SalesJV_VatCheck = $PVatChk, ".
				  " SalesJV_Total = $vGrossTotal, SalesJV_TotalBase1 = $vGrossTotalBase1, SalesJV_TotalBase2 = $vGrossTotalBase2 ".
				  " WHERE SalesJV_ID = ".$PId;

	$sub_result1=mysql_query($sub_query1,$connection);
	//echo $sub_query1."<br>";exit;
	if ($sub_result1){
		fcommit();

	}else{
		$message  = mysql_error(); 
		$error = 'Error In Function Calculate_MasterAmounts: '.$message;
		frollback();
	}

	Return $error;		

}

function selectData($conn, $query){
	$result = mysql_query($query, $conn);
	$cur = mysql_fetch_row($result);		
	return $cur;
}

function fbegin()
{
	mysql_query("START TRANSACTION");
}
function fcommit(){
	mysql_query("COMMIT");
}
function frollback()
{
	mysql_query("ROLLBACK");
}
function insertMySQLDate($data){
	$data = insertDate($data);
	return substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2)." ".strftime("%H").":".strftime("%M").":".strftime("%S");;
}

function insertDate($data){
	return substr($data, 6, 4) . substr($data, 3, 2) . substr($data, 0, 2);
}

function updateData($conn, $query, $commit){
	if (mysql_query($query, $conn)){				
		return true;
	}else{
		return false;
	}
}

?>