function ChipsLog ($p_szDesc, $p_szDetail)
{
$szFileName = "R:/Trash/Logs/ChipsLog".date ( "YmdH" ).".log";
$pFile = fopen ( $szFileName, "a" );
if ( $pFile )
{
$szData = sprintf ( "[%s - %-25.25s] %s\r\n", date ( "i:s" ), $p_szDesc, $p_szDetail );
fwrite ( $pFile, $szData );
fclose ( $pFile );
}
return 0;
}
//*****************class seperator*************************
class sql
{
var $sqlsvr,$sqlusr,$sqlpwd,$reterror="",$linkident,$db,$result,$count;
//------------function seperator-------------------------
// ---- Local Machine
function sql ($sql="127.0.0.1", $usr="sa", $pwd="Qwerty123", $db="DevTNGWebPos")
{
$this->sqlsvr = $sql;
$this->sqlusr = $usr;
$this->sqlpwd = $pwd;
$this->db = $db;
$this->connect ();
}
//--------connects to server and selects database------------------------------
function connect ()
{
if ( !isset ( $this->linkident ) )
if ( ( $this->linkident = mssql_connect ( $this->sqlsvr, $this->sqlusr, $this->sqlpwd ) ) == false )
{
$this->reterror = "Error. Couldn't connect to $sqlsvr using $sqlusr!";
return $this->linkident;
}
else
{
if ( mssql_select_db ( $this->db, $this->linkident ) == false )
$this->reterror = "\nError. Unable to select DB";
return $this->linkident;
}
return $this->linkident;
}
//--------------------------------------
function getlasterror ()
{
return $this->reterror;
}
//--------------------------------------
function setsvr ($svr)
{
$this->sqlsvr = $svr;
}
//------------------------------------
function setusr ($usr, $pwd)
{
$this->sqlusr = $usr;
$this->sqlpwd = $pwd;
}
//------------------------------------
function setdb ($db)
{
$this->db=$db;
}
//------------------------------------
function setall($svr,$usr,$pwd,$db)
{
$this->sqlsvr = $svr;
$this->sqlusr = $usr;
$this->sqlpwd = $pwd;
$this->db = $db;
}
//------------------------------------
function getident ()
{
return $this->linkident;
}
//------------------------------------
function query ($q)
{
$this->result = mssql_query ( $q, $this->linkident );
return $this->result;
}
//------------------------------------
function count ()
{
$this->count = mssql_num_rows ( $this->result );
return $this->count;
}
//------------------------------------
function result ()
{
return $this->result;
}
};
//*******************************************************
class session extends sql
{
var $passhash,$sessionerror;
//----------------------------------------------
function session ()
{
$this->sql ();
session_start ();
}
//-----------------------------------------------
function start ($username, $password)
{
global $hidd_SPID, $hidd_locationID, $hidd_termno, $username, $hidd_termid;
$this->connect ();
$szPwdHash = md5 ( $password );
$szToday = date ( "m/d/y" );
$result = $this->query ( "select TNGUserID, EncPassword, LoginCount, PasswordAge, DATEDIFF(d,LastPwdChange,'$szToday') as datediff from TNGUser where LoginID = '$username' and status = 1" );
if ( $result )
{
if ( $this->count () == 1 )
{
$iLoginCount = intval ( mssql_result ( $this->result, 0, "LoginCount" ) );
if ( $iLoginCount < 1 )
{
$result2 = $this->query ( "update TNGUser set LoginCount = $iLoginCount - 1 where LoginID = '$username' and status = 1" );
$this->sessionerror = "Account has been locked out!!";
return false;
}
if ( $szPwdHash != mssql_result ( $this->result, 0, "EncPassword" ) )
{
$result2 = $this->query ( "update TNGUser set LoginCount = $iLoginCount - 1 where LoginID = '$username' and status = 1" );
if ( $iLoginCount > 1 )
$this->sessionerror = "Invalid Password!!";
else
$this->sessionerror = "Account has been locked out!!";
return false;
}
$iPasswordAge = intval ( mssql_result ( $this->result, 0, "PasswordAge" ) );
$iAge = intval ( mssql_result ( $this->result, 0, "datediff" ) );
$result2 = $this->query ( "update TNGUser set LoginCount = 3 where LoginID = '$username' and EncPassword = '$szPwdHash' and status = 1" );
if ( $iPasswordAge > 0 )
{
if ( $iAge > $iPasswordAge )
{
$this->sessionerror = "Your password has been expired!!\\nPlease change it.";
return false;
}
}
@session_start();
$readersql = new sql ();
$readersql->query ( "select DISTINCT R.AccessKey from Reader R,Terminal T,POSLocation PL where R.ReaderID=T.ReaderID and T.TerminalNumber=$hidd_termno and T.POSID=PL.POSID and PL.LocationID='$hidd_locationID' and PL.SPID='$hidd_SPID'" );
if ( $readersql->result )
{
$accesskey = "";
if ( $readersql->count () > 0 )
$accesskey = mssql_result ( $readersql->result, 0, "AccessKey" );
session_register ( "accesskey" );
}
$id = session_id ();
$string = $szPwdHash.$id;
$this->passhash = md5 ( $string );
if ( session_register ( "username" ) == false )
{
$this->sessionerror = "Unable to register username!";
return false;
}
return $this->passhash;
}
else
{
$this->sessionerror = "Invalid User Name or Account Status!!!";
return false;
}
}
else
{
$this->sessionerror="DataBase error!";
return false;
}
}
//-----------------------------------------------
function continuesession ()
{
global $passx,$username,$accesskey;
@session_register ( "accesskey" );
if ( @session_register ( "passx" ) == false )
{
$this->sessionerror="\n
Unable to retrive password hash!";
return false;
}
if ( @session_register ( "username" ) == false )
{
$this->sessionerror = "\n
Unable to retrive username!";
return false;
}
$this->sql();
$this->connect();
$this->query("select EncPassword from TNGUser where LoginID='$username'");
if($this->count()!=1)
{
$this->sessionerror = "\n
Error getting password from DB!";
return false;
}
else
{
$id = session_id ();
$result = $this->result ();
$password = mssql_result ( $result, 0, "EncPassword" );
$string = $password.$id;
$DBhash = md5 ( $string );
if ( $DBhash == $passx )
return true;
else
{
$this->sessionerror = "\n
Error. Password doesn't match.
$DBhash\n
$passx";
return false;
}
}
}
//-----------------------------------------------
function geterror ()
{
return $this->sessionerror;
}
//-----------------------------------------------
function destroy ()
{
session_destroy ();
}
};
//*******************************************************
class user
{
var $idno,$login,$name,$status,$lastlogin,$datecreated,$createrid,$roles,$error,$rolescount;
//-----------------------------------------------
function user ()
{
global $username;
if ( !isset ( $username ) )
// if ( session_register ( "username" ) == false )
{
$this->error = "\n
Unable to retrive username from session!";
return false;
}
$sql = new sql ();
$sql->connect ();
$sql->query ( "select * from TNGUser where LoginID='$username'" );
if ( $sql->count () > 1 || $sql->count () < 1 )
{
$this->error = "\n
Error in retriving user data.";
return false;
}
$this->idno = mssql_result ( $sql->result, 0, "TNGUserID" );
$this->login = mssql_result ( $sql->result, 0, "LoginID" );
$this->name = mssql_result ( $sql->result, 0, "UserName" );
$this->status = mssql_result ( $sql->result, 0, "Status" );
$this->lastlogin = mssql_result ( $sql->result, 0, "LastLogin" );
$this->datecreated = mssql_result ( $sql->result, 0, "DateCreated" );
$this->createrid = mssql_result ( $sql->result, 0, "CreatorTNGUserID" );
// $this->roles = new Array();
$sql->query ( "select TNGR.RoleCode from TNGRole TNGR, TNGUserRole TNGUR where TNGUR.TNGUserID ='$this->idno' AND TNGR.TNGRoleID=TNGUR.TNGRoleID" );
if ( $sql->count == 0 )
{
$this->error = "\n
Error in retriving roles.";
return false;
}
$this->rolescount = $sql->count ();
for ( $x = 0; $x < $sql->count; $x++ )
$this->roles [$x] = mssql_result ( $sql->result, $x, "RoleCode" );
}
//-----------------------------------------------
function writelogin ($terminaldbid=0)
{
$sql = new sql();
$todaysdate = date ( "m/d/y g:i:s A" );
$sql->query ( "update TNGUser set LastLogin='$todaysdate' where TNGUserID=$this->idno" );
$sql->query ( "update POSUserLocation set LastUserLogin='$todaysdate' where TNGUserID=$this->idno and TerminalID=$terminaldbid" );
return $sql->reterror;
}
//-----------------------------------------------
function validlocation ($hidd_SPID, $hidd_termID, $hidd_locationID)
{
$sqlquery = new sql();
$q = "select TNGUserLocID from POSUserLocation A, POSLocation B, Terminal T where A.TNGUserID=$this->idno and B.SPID='$hidd_SPID' and A.POSID=B.POSID and B.LocationID='$hidd_locationID' and A.TerminalID=T.TerminalID AND T.POSID=B.POSID AND T.TerminalNumber=$hidd_termID and A.UsageStatus=1";
$sqlquery->query ( $q );
if ( $sqlquery->count () == 1 )
return mssql_result($sqlquery->result,0,"TNGUserLocID");
else
return false;
}
//-----------------------------------------------
// Dalina - 31/03/05 - BNM Audit requirement
function firstLogin ($username)
{
$sqlfirstlogin = new sql ();
$q = "select NewLoginStatus from TNGUser where LoginID='$username'";
$sqlfirstlogin->query ( $q );
if ( $sqlfirstlogin->count () ==1 )
{
$newloginstat = mssql_result ( $sqlfirstlogin->result, 0, "NewLoginStatus" );
if ( $newloginstat == 1 )
{
// echo "window.alert($newloginstat);";
return $newloginstat;
}
else
return false;
}
else
return false;
}
// Dalina - End update 31/03/05
//-----------------------------------------------
function countroles ()
{
return $this->rolescount;
}
//-----------------------------------------------
function reterror ()
{
return $this->error;
}
//-----------------------------------------------
function checkroles ($role_to_check)
{
for ( $i = 0; $i < $this->rolescount; $i++ )
if($this->roles[$i] == $role_to_check)
return true;
return false;
}
//-----------------------------------------------
function thisterminal ($SPID, $locationid, $termno)
{
$sql = new sql ();
$query = "select TerminalID from Terminal A,POSLocation B where A.POSID =B.POSID and A.TerminalNumber=$termno and B.SPID ='$SPID' and B.locationid='$locationid' ";
$sql->query ( $query );
if ( $sql->count () == 1 )
return chop ( mssql_result ( $sql->result, 0, "TerminalID" ) );
else
return 0;
}
};
//*******************************************************
class termInstaller
{
var $SPID,$LocationID,$TermNo,$passwd,$TermID,$error;
//-----------------------------------------------
function termInstaller ($SPID = "null", $LocationID = "null", $TermNO = "null", $passwd = "null")
{
$this->SPID = $SPID;
$this->LocationID = $LocationID;
$this->TermNo = $TermNO;
$this->passwd = $passwd;
}
//-----------------------------------------------
function findterminal ()
{
$thedb = new sql ();
$query = "select TerminalID from Terminal A,POSLocation B where A.POSID =B.POSID and A.TerminalNumber=$this->TermNo and B.SPID ='$this->SPID' and B.locationid='$this->LocationID' and A.terminalpassword ='$this->passwd' ";
$thedb->query ( $query );
if ( $thedb->count () == 0 )
{
$this->error = $thedb->getlasterror ();
return false;
}
else
{
if ( $thedb->count > 1 )
{
$this->error = "ERROR! There are Duplicated Terminals in DB!";
return false;
}
else
{
$this->TermID = mssql_result ( $thedb->result, 0, "TerminalID" );
return $this->TermID;
}
}
}
//-----------------------------------------------
function updateterminal()
{
$termid = $this->findterminal ();
if ( $termid != false )
{
$db = new sql ();
$date = date ( "m/d/y" );
$db->query ( "update Terminal set InstalledDate='$date' where TerminalID=$termid" );
}
return $termid;
}
};
//*******************************************************
class batch
{
//-----------------------------------------------
function batch ()
{
}
//-----------------------------------------------
function isbatchclosed ($termdbid)
{
$sql = new sql ();
$sql->query ( "select CONVERT (char(20),P.BOJDateTime,1) AS BOJ from TMPPOSBatchMaster P where P.EOJDateTime=null and P.TerminalID=$termdbid");
if ( $sql->result )
if ( $sql->count () == 1) //see if session is closed properly 1=no
return "notclosed";
else
return "ok";
return "sqlerror";
}
//-----------------------------------------------
function posbatchid ($termdbid, $batchno)
{
$sql = new sql ();
$sql->query ( "select PosBatchId from TMPPosBatchMaster where TerminalID=$termdbid AND EOJDateTime=null AND BatchNo=$batchno" );
if ( $sql->count () >0)
return mssql_result ( $sql->result, 0, "PosBatchId" );
else
return 0;
}
//-----------------------------------------------
function batchgendatetime ($termdbid, $batchno)
{
$sql = new sql ();
$sql->query ( "select BOJDateTime from TMPPosBatchMaster where TerminalID=$termdbid AND EOJDateTime=null AND BatchNo=$batchno" );
if ( $sql->count() > 0 )
{
return mssql_result ( $sql->result, 0, "BOJDateTime" );
}
else
return "01/01/1900";
}
//-----------------------------------------------
function batchno ($termid)
{
$sql = new sql ();
$sql->query ( "select batchno from Terminal where TerminalID=$termid" );
return chop ( mssql_result ( $sql->result, 0, "batchno" ) );
}
//-----------------------------------------------
function jobno ($termid)
{
$sql = new sql ();
$sql->query ( "select jobno from Terminal where TerminalID=$termid" );
return chop ( mssql_result ( $sql->result, 0, "jobno" ) );
}
//-----------------------------------------------
function checkBIS ($SPID=0, $locationID=0)
{
$sql = new sql ();
$sql->query ( "select POSID from POSLocation where SPID='$SPID' and LocationID='$locationID'" );
if ( $sql->count () == 0 )
return false;
else
$POSID = mssql_result ( $sql->result, 0, "POSID" );
$today = date ( "m/d/Y" );
$sql->query ( "select CONVERT (varchar(10),MAX(distinct P.LastUserLogin),101) AS LastUserLogin from POSUserLocation P,TNGUserRole T where P.POSID=$POSID AND P.TNGUserID=T.TNGUserID AND T.TNGRoleID<>3 AND T.TNGRoleID<>1" );
if ( $sql->count () == 0 )
return false;
else
$lastuserlogin = mssql_result ( $sql->result, 0, "LastUserLogin" );
if ( $lastuserlogin == $today || $lastuserlogin == "" )
return true;
else
{
$sql->query ( "select count(P.POSBatchID) as count from POSBatchMaster P, BatchCashDec BCD where CONVERT (varchar(10),P.BOJDateTime,101)='$lastuserlogin' AND P.CashDeclarationDate is not null AND BCD.BISID is not null AND BCD.POSBatchID=P.POSBatchID AND P.POSID=$POSID" );
if ( mssql_result ( $sql->result, 0, "count" ) > 0 )
return true;
else
return true;
}
/*
// $sql->query ( "Select count(BCD.POSBatchID) as count from BatchCashDec BCD,BISDeclaration B, POSBatchMaster P where BISPOSID=$POSID AND BCD.POSBatchID=P.POSBatchID AND CONVERT (varchar(10),P.BOJDateTime,101)='$lastuserlogin'" );
// $sql->query ( "select count(POSBatchID) as count from POSBatchMaster where CashDeclarationDate" );
$sql->query ( "Select distinct BISID from BISDeclaration where BISPOSID=$POSID AND CONVERT (varchar(10),BISDatetime,101)='$lastuserlogin'" );
if ( $sql->count () > 0 )
{
$sql->query ( "select count(P.POSBatchID) as count from POSBatchMaster P,BatchCashDec BCD where P.POSBatchID=BCD.POSBatchID AND CashDeclarationDate" );
if ( mssql_result ( $sql->result, 0, "count" ) > 0 )
return true;
else
return false;
}
else
return false;
*/
}
//-----------------------------------------------
function closebatch ($hidd_termdbid)
{
global $hidd_SPID,$hidd_locationID,$hidd_termno,$username,$hidd_termid;
$closesql = new sql ();
if ( isset ( $hidd_termno ) && $hidd_termno > 0 )
$hidd_termid = $hidd_termno;
$termid = $hidd_termdbid;
$todaysdate = date ( "m/d/y g:i:s A" );
$closesql->query ( "select Jobno,Batchno from Terminal where TerminalID=$termid" );
$jobno = mssql_result ( $closesql->result, 0, "Jobno" );
$batchno = mssql_result ( $closesql->result, 0, "Batchno" );
$jobno = chop ( $jobno );
$batchno = chop ( $batchno );
//---- print eoj ---
$sql = new sql ();
$sql->query ( "select count(TerminalID) as count from TMPPOSBatchMaster where EOJDateTime=null and TerminalID=$termid ");
if ( mssql_result ( $sql->result, 0, "count" ) == 1 )
{
$fields = "CONVERT(VARCHAR(10),BOJDateTime,103) as BOJDate,CONVERT(VARCHAR(10),BOJDateTime,14) as BOJTime,(SCashSalesQty+SChqSalesQty) as mancardsoldqty,(SCashSaleAmt+SChqSaleAmt)as mancardsoldamt";
$fields .= ",(SCashDepAmt+SChqDepAmt) as mancarddep,(SCashRefillQty+SChqRefillQty)as manrefcardqty,(SCashRefillAmt+SChqRefillAmt) as manrefcardamt";
$fields .= ",SaleCancelqty,SaleCancelAmt,SaleCancelDep,SCardReturnReg,SCardModification";
$fields .= ",SCardReturnQty,SCardReimburseQty,(obucashsalesqty+obuchqsalesqty+obuccasalesqty) as soldstagqty";
$fields .= ",(obucashsaleamt+obuchqsaleamt+obuccasaleamt) as soldstagamt,obureplaceqty,obuSaleCancelqty";
$fields .= ",scardrefundqty, scardrefundamt+scardrefunddep as refundamt";
$sql->query ( "select $fields from TMPPOSBatchMaster where EOJDateTime=null and TerminalID=$termid" );
$bojdate = mssql_result ( $sql->result, 0, "BOJDate" );
$bojtime = mssql_result ( $sql->result, 0, "BOJTime" );
$bojdatetime = "$bojdate $bojtime";
$mancardsoldqty = mssql_result ( $sql->result, 0, "mancardsoldqty" );
$mancardsoldamt = mssql_result ( $sql->result, 0, "mancardsoldamt" );
$mancardsold = padstr ( $mancardsoldqty, $mancardsoldamt );
$mancarddep = mssql_result ( $sql->result, 0, "mancarddep" );
$mancarddep = padstr(" ",$mancarddep );
$manrefcardqty = mssql_result ( $sql->result, 0, "manrefcardqty" );
$manrefcardamt = mssql_result ( $sql->result, 0, "manrefcardamt" );
$manrefcard = padstr ( $manrefcardqty, $manrefcardamt );
$saleCancelqty = mssql_result ( $sql->result, 0, "SaleCancelqty" );
$saleCancelAmt = mssql_result ( $sql->result, 0, "SaleCancelAmt" );
$SaleCancel = padstr ( $saleCancelqty, $saleCancelAmt );
$saleCancelDep = mssql_result ( $sql->result, 0, "SaleCancelDep" );
$SaleCancelDep = padstr ( " ", $saleCancelDep );
$SCardReturnReg = mssql_result ( $sql->result, 0, "SCardReturnReg" );
$SCardModification = mssql_result ( $sql->result, 0, "SCardModification" );
$SCardReturnQty = mssql_result ( $sql->result, 0, "SCardReturnQty" );
$SCardReimburseQty = mssql_result ( $sql->result, 0, "SCardReimburseQty" );
$soldstagqty = mssql_result ( $sql->result, 0, "soldstagqty" );
$soldstagamt = mssql_result ( $sql->result, 0, "soldstagamt" );
$soldstag = padstr ( $soldstagqty, $soldstagamt );
$obureplaceqty = mssql_result ( $sql->result, 0, "obureplaceqty" );
$obuSaleCancelqty = mssql_result ( $sql->result, 0, "obuSaleCancelqty" );
$refundqty = mssql_result ( $sql->result, 0, "scardrefundqty");
$refundamt = mssql_result ( $sql->result, 0, "refundamt");
$refund = padstr ( $refundqty,$refundamt);
$myuser=new user();
$nill=" 0 RM0.00";
if ($myuser->checkroles("2") ==true && $hidd_SPID!='20')
{
$mancardsold= " $mancardsoldqty";
$mancarddep = " ";
$manrefcard= " $manrefcardqty";
$SaleCancel= " $saleCancelqty";
$SaleCancelDep= " ";
$soldstag= " $soldstagqty";
$refund=" $refundqty";
$nill=" 0";
}
echo "document.TNGX.PrintDate='",date("d/m/Y H:i:s"),"';";
echo "\ndocument.TNGX.PrintEndOfJob(0,'$hidd_SPID','$hidd_locationID','$hidd_termid','$username'";
echo ",'$jobno','$batchno','$bojdatetime','$mancardsold','$mancarddep','$nill','$nill'";
echo ",'$manrefcard','$nill','$SaleCancel','$SaleCancelDep',' $SCardReturnReg'";
echo ",' $SCardModification',' $SCardReturnQty',' $SCardReimburseQty','$refund'";
echo ",'$nill','$soldstag',' $obureplaceqty',' $obuSaleCancelqty');\n";
}
//---- end print eoj ---
@$closesql->query("insert into PosStockTransaction select * from TempPosStockTransaction where TerminalID=$termid and Jobno=$jobno and Batchno=$batchno");
if($closesql->result)
{
$closesql->query("delete from TempPosStockTransaction where TerminalID=$termid and Jobno=$jobno and Batchno=$batchno");
$closesql->query("update TMPPosBatchMaster set PosStockID=(select TOP 1 PosStockId from PosStockTransaction where TerminalID=$termid and Jobno=$jobno and Batchno=$batchno ) where Terminalid=$termid and JobNo=$jobno and BatchNo=$batchno");
}
@$closesql->query("update TMPPOSBatchMaster set EOJDateTime = '$todaysdate' where TerminalID=$termid and JobNo=$jobno and BatchNo=$batchno");
@$closesql->query ("insert into POSBatchMaster select * from TMPPOSBatchMaster where EOJDateTime='$todaysdate' and TerminalID=$termid and JobNo=$jobno and BatchNo=$batchno");
if($closesql->result)
$closesql->query ("delete from TMPPOSBatchMaster where EOJDateTime='$todaysdate' and TerminalID=$termid and JobNo=$jobno and BatchNo=$batchno");
@$closesql->query("insert into POSTransaction select * from TempPosTransaction where Terminalid=$termid");
if($closesql->result)
$closesql->query("delete from TempPosTransaction where Terminalid=$termid");
@$closesql->query("insert into OBUTransaction select * from TempOBUTransaction where Terminalid=$termid");
if($closesql->result)
$closesql->query("delete from TempOBUTransaction where Terminalid=$termid");
@$closesql->query("insert into PosTransactionErrorLog select * from Temp2PosTransaction where Terminalid=$termid");
if($closesql->result)
$closesql->query("delete from Temp2PosTransaction where Terminalid=$termid");
}
//-----------------------------------------------
function writebatch($termno,$SPID,$locationid)
{
$sql=new sql();
//-- get term id --
$sql->query("select TerminalID from Terminal where TerminalNumber=$termno and POSID=(select POSID from POSLocation where Locationid='$locationid' and SPID='$SPID')");
if ($sql->count()==1)
{
$termid = mssql_result ( $sql->result, 0, "TerminalID");
}
else return false;
$todaysdate=date("m/d/y g:i:s A");
//echo "select T.LastAccessed ,P.BOJDateTime AS BOJ from Terminal T, TMPPOSBatchMaster P where T.TerminalID=$termid and T.TerminalID = P.TerminalID and P.EOJDateTime=''";
//$sql->query("select CONVERT (char(20),T.LastAccessed,1)as LastAccessed ,CONVERT (char(20),P.BOJDateTime,1) AS BOJ from Terminal T, TMPPOSBatchMaster P where P.EOJDateTime=null and P.TerminalID=$termid");
$sql->query("select CONVERT (char(20),P.BOJDateTime,1) AS BOJ from TMPPOSBatchMaster P where P.EOJDateTime=null and P.TerminalID=$termid");
/*
if ($sql->count() !=0)
$lastaccessed = mssql_result ( $sql->result, 0, "LastAccessed");
else break;
echo "\ntest up to lastaccessed\n=$lastaccessed";
*/
if ($sql->count() ==1) //see if session is closed properly 1=no
{
$this->closebatch($termid);
$flag=false;
$date1 = mssql_result ( $sql->result, 0, "BOJ");
}else
{
$flag=true;
$sql->query("select CONVERT (char(20),LastAccessed,1)as LastAccessed from Terminal where TerminalID=$termid");
$date1 = mssql_result ( $sql->result, 0, "LastAccessed");
}
//-- set job and batch no --
if (isnextday($date1,date("m/d/y")))
{
//echo "\njobno 0";
$sql->query("update Terminal set Batchno=Batchno+1, Jobno=1 where TerminalID=$termid");
//echo "\njobno 0";
}
else
{
//echo "\njobno 1";
$sql->query("update Terminal set Batchno=Batchno+1, Jobno=Jobno+1 where TerminalID=$termid");
//echo "\njobno 1";
}
//open new session
$sql->query("select P.SPID as SPID from POSLocation P,Terminal T where P.POSID = T.POSID and TerminalID=$termid");
$spid = mssql_result ( $sql->result, 0, "SPID");
$sql->query("select POSID from Terminal where TerminalID=$termid");
$posid = mssql_result ( $sql->result, 0, "POSID");
$user=new user();
$sql->query("select Jobno,Batchno from Terminal where TerminalID=$termid");
$jobno = mssql_result ( $sql->result, 0, "Jobno");
$batchno = mssql_result ( $sql->result, 0, "Batchno");
$jobno=chop($jobno);
$batchno=chop($batchno);
// -- write stock batch --
$values="'$spid',$posid,$termid,$jobno,$batchno";
$sql->query("insert into TempPosStockTransaction (SPID,POSID,TerminalID,Jobno,Batchno) values ($values)");
//-- end write stock batch--
//echo "insert into TMPPOSBatchMaster (SPID,POSID,TerminalID,JobNo,BatchNo,BOJDateTime,TNGUserId) Values ('$spid','$posid',$termid,$jobno,$batchno,'$todaysdate',$user->idno)";
//$sql->query("Select PosBatchID from BatchID");
//$posbatchid = mssql_result ( $sql->result, 0, "PosBatchID");
$sql->query("insert into TMPPOSBatchMaster (SPID,POSID,TerminalID,JobNo,JobType,BatchNo,BOJDateTime,TNGUserId) Values ('$spid','$posid',$termid,$jobno,'N',$batchno,'$todaysdate',$user->idno)"); //,$posbatchid+1)");
//$sql->query("update BatchID set PosBatchID=PosBatchID+1");
//echo "\nend1\n";
//echo "update Terminal set LastAccessed = $todaysdate where TerminalID=$termid";
$sql->query("update Terminal set LastAccessed = '$todaysdate' where TerminalID=$termid");
//echo "\nend\n";
return $flag;
}
}
//*******************************************************
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function isnextday($date1,$date2,$format=1)
{ //assuming 12/24/2001 , mm/dd/yyyy for format 1 else dd/mm/yyyy.
$date1=explode("/",$date1);
$date2=explode("/",$date2);
$tmpdate=explode (" ",$date1[2]);
if($tmpdate!=false)
$date1[2]=$tmpdate[0];
$tmpdate=explode (" ",$date2[2]);
if($tmpdate!=false)
$date2[2]=$tmpdate[0];
if ($format ==1)
{
if ($date1[1] < $date2[1])
return true;
else if ($date1[0] < $date2[0])
return true;
else if ($date1[2]< $date2[2])
return true;
return false;
}else
{
if ($date1[0] < $date2[0])
return true;
else if ($date1[1] < $date2[1])
return true;
else if ($date1[2]< $date2[2])
return true;
return false;
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function swapDM($date1,$time=0)
{ //assuming $date1 is mmddyyyy return ddmmyyyy
$date1=explode("/",$date1);
//--- if time is to be removed ----
if ($time==1)
{
$tmpdate=explode (" ",$date1[2]);
if($tmpdate!=false)
$date1[2]=$tmpdate[0];
}
return $date1[1]."/".$date1[0]."/".$date1[2];
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function activecode ($sysid,$manufacno,$termdbid)
{
$mlen=strlen($manufacno);
$activecode=0;
for ($A=1;$A < $mlen;$A=$A+2)
{
$activecode +=$manufacno[$A]*2;
}
$actsql=new sql();
$actsql->query("select R.SysId from Reader R,Terminal T where R.ReaderID=T.ReaderID AND TerminalID=$termdbid");
if ($actsql->count() == 1)
{
$sysid = mssql_result ( $actsql->result,0,"SysId");
}else $sysid=0;
$slen=strlen($sysid);
for ($A=$slen-5;$A < $slen ; $A++)
{
$activecode+=$sysid[$A];
}
$date=date("dmY");
$datelen=strlen($date);
for ($A=0; $A < $datelen ;$A= $A+2)
{
$activecode+=$date[$A];
}
for ($A=1; $A < $datelen ; $A=$A+2)
{
$activecode+=$date[$A]*2;
}
return $activecode;
}
//*******************************************************
function padstr($qty,$amt)
{
for ($i=strlen($qty);$i< 3;$i++)
$qty.=" ";
$ret=" $qty RM".sprintf("%01.2f",$amt);
return $ret;
}
//*******************************************************
?>