<?php
//mysql_connect("localhost","root","") or die("Error1:".mysql_error());
//mysql_select_db("buda_hotel_dbms") or die("Error2:".mysql_error());
class labClass{
  public  $dbcon;
    //public  $host="localhost";
     //public  $dbname="lpgaspoi_rombodb";
     //public  $user="lpgaspoi_rdbus";
    // public  $pwd="Rombo_star2025";
     public  $host="localhost";
     public  $dbname="budacotz_rombo";
     public  $user="budacotz_budacotzrombo";
     public  $pwd="Rombo_star2025";
    // public  $dbcon;
    // public  $host="localhost";
     //public  $dbname="inventory_oryx";
     // public  $user="aiderste_aiderstech";
     // public  $pwd="Aid@2022_2023";
    // public  $user="root";
    // public  $pwd="";
    // public  $port="3308";


                                      //FUNCTION FOR DATABASE CONNECTION GOES HERE
 
function __construct(){
	
			 //  $this->dbcon = new PDO("mysql:dbname=$this->dbname;host=$this->host;$this->port",$this->user,$this->pwd);
            $this->dbcon = new PDO("mysql:dbname=$this->dbname;host=$this->host;",$this->user,$this->pwd);
          
}


 function cashExDel($id){
        try {
            
             $stmt = $this->dbcon->prepare("DELETE FROM cash_expenses WHERE recID = :id");
              $stmt->bindParam(':id', $id);
              
            return $stmt->execute();
        } catch (PDOException $e) {
            echo "<div class='alert alert-danger p-2'>Error in retrieving record: " . $e->getMessage() . "</div>";
        }

}

 function cashExR(){
        try {
            
             $stmt = $this->dbcon->query("SELECT * FROM cash_expenses ORDER BY sdate DESC, recID DESC");
              $st=$stmt->fetchAll(PDO::FETCH_ASSOC);

            return $st;
        } catch (PDOException $e) {
            echo "<div class='alert alert-danger p-2'>Error in retrieving record: " . $e->getMessage() . "</div>";
        }

}



 function cashEx($category,$source,$amount,$description,$sdate,$user){
        try {
            $stmt = $this->dbcon->prepare("
                INSERT INTO cash_expenses (sdate, source, amount, category, description, user)
                VALUES (:sdate, :source, :amount, :category, :description, :user)
            ");
            $stmt->execute([
                ':sdate' => $sdate,
                ':source' => $source,
                ':amount' => $amount,
                ':category' => $category,
                ':description' => $description,
                ':user' => $user
            ]);
            return $stmt;
        } catch (PDOException $e) {
            echo "<div class='alert alert-danger p-2'>Error saving record: " . $e->getMessage() . "</div>";
        }

}


function excessbalwithdraw($tname, $tPrice,$sdate,$user){
  

    $time="By:".$user."At:".Date("h:i:sa");

   $data=array($tname,$tPrice,$sdate,$time);
        
   try{   

      $Qr=$this->dbcon->prepare("insert into excessmoneywdraw(wreason,amount,dateW,timeAt) values(?,?,?,?)");
      
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function genStatement($whereOther, $whereMiamala, $whereWithdraw, $startDate, $endDate) {
    try {   
        if ($startDate && $endDate) {
            $whereMiamala  = " AND dateR BETWEEN '$startDate' AND '$endDate' ";
            $whereOther    = " AND dateR BETWEEN '$startDate' AND '$endDate' ";
            $whereWithdraw = " AND datew BETWEEN '$startDate' AND '$endDate' ";
        }

        $sql = "
            SELECT * FROM (
                -- deposits from other sources (positive)
                SELECT 
                    dateR AS tdate, 
                    amount, 
                    CONCAT('Deposit - ', descrip) AS description,
                    1 AS type_order  -- deposits should appear first
                FROM othersourceentryrec
                WHERE 1=1 $whereOther

                UNION ALL

                -- only Cash and M-Pesa transactions (positive)
                SELECT 
                    dateR AS tdate, 
                    amount, 
                    transac AS description,
                    1 AS type_order  -- deposits first
                FROM miamala
                WHERE transac IN ('Cash','M-Pesa') $whereMiamala

                UNION ALL

                -- withdrawals (negative)
                SELECT 
                    datew AS tdate, 
                    -amount AS amount, 
                    CONCAT('Withdraw - ', wreason) AS description,
                    2 AS type_order  -- withdrawals appear after deposits
                FROM withdrawrec
                WHERE 1=1 $whereWithdraw
            ) AS combined
            ORDER BY combined.tdate ASC, combined.type_order ASC
        ";

        $stmt = $this->dbcon->prepare($sql);
        $stmt->execute();   
        return $stmt;
    } catch (PDOException $xc) {
        echo "Database Error: " . $xc->getMessage();
    }
}


/*function genStatement($whereOther, $whereMiamala, $whereWithdraw, $startDate, $endDate) {
    try {   
        if ($startDate && $endDate) {
            $whereMiamala  = " AND dateR BETWEEN '$startDate' AND '$endDate' ";
            $whereOther    = " AND dateR BETWEEN '$startDate' AND '$endDate' ";
            $whereWithdraw = " AND datew BETWEEN '$startDate' AND '$endDate' ";
        }

        $sql = "
            SELECT * FROM (
                -- deposits from other sources (positive)
                SELECT 
                    dateR AS tdate, 
                    amount, 
                    CONCAT('Deposit - ', descrip) AS description,
                    2 AS type_order  -- 2 = deposit, appears second
                FROM othersourceentryrec
                WHERE 1=1 $whereOther

                UNION ALL

                -- only Cash and M-Pesa transactions (positive)
                SELECT 
                    dateR AS tdate, 
                    amount, 
                    transac AS description,
                    2 AS type_order  -- 2 = deposit, appears second
                FROM miamala
                WHERE transac IN ('Cash','M-Pesa') $whereMiamala

                UNION ALL

                -- withdrawals (negative, credit first)
                SELECT 
                    datew AS tdate, 
                    -amount AS amount, 
                    CONCAT('Withdraw - ', wreason) AS description,
                    1 AS type_order  -- 1 = withdraw, appears first
                FROM withdrawrec
                WHERE 1=1 $whereWithdraw
            ) AS combined
            ORDER BY combined.tdate ASC, combined.type_order ASC
        ";

        $stmt = $this->dbcon->prepare($sql);
        $stmt->execute();   
        return $stmt;
    } catch (PDOException $xc) {
        echo "Database Error: " . $xc->getMessage();
    }
}
*/

function genOpeningDepo($cID, $startDate){
  try{   
    $stmt = $this->dbcon->prepare("SELECT SUM(depoA) FROM deporec WHERE cID=? AND depoD < ?");
    $stmt->execute([$cID, $startDate]);   
    return $stmt;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

public function genBothTrans($type, $startDate, $endDate, $cID)
{
    try {
        // --- Base WHERE conditions ---
        $whereDeposit = "WHERE cID = :cID";
        $whereWithdraw = "WHERE cID = :cID";

        // --- Optional date filtering ---
        if (!empty($startDate) && !empty($endDate)) {
            $whereDeposit  .= " AND depoD BETWEEN :startDate AND :endDate";
            $whereWithdraw .= " AND depoD BETWEEN :startDate AND :endDate";
        } elseif (!empty($startDate)) {
            $whereDeposit  .= " AND depoD >= :startDate";
            $whereWithdraw .= " AND depoD >= :startDate";
        } elseif (!empty($endDate)) {
            $whereDeposit  .= " AND depoD <= :endDate";
            $whereWithdraw .= " AND depoD <= :endDate";
        }

        // --- Build query depending on report type ---
        if ($type === 'deposit') {
            $sql = "
                SELECT 
                    depoD AS tdate, 
                    depoA AS amount, 
                    CONCAT('Deposit (', cname, ')') AS description
                FROM deporec
                $whereDeposit
                ORDER BY tdate ASC
            ";
        } elseif ($type === 'withdraw') {
            $sql = "
                SELECT 
                    depoD AS tdate, 
                    -depoA AS amount, 
                    CONCAT('Withdraw (', cname, ')') AS description
                FROM cuswithdraw
                $whereWithdraw
                ORDER BY tdate ASC
            ";
        } else { // both
            $sql = "
                SELECT 
                    depoD AS tdate, 
                    depoA AS amount, 
                    CONCAT('Deposit (', cname, ')') AS description
                FROM deporec
                $whereDeposit

                UNION ALL

                SELECT 
                    depoD AS tdate, 
                    -depoA AS amount, 
                    CONCAT('Withdraw (', cname, ')') AS description
                FROM cuswithdraw
                $whereWithdraw

                ORDER BY tdate ASC
            ";
        }

        // --- Prepare statement ---
        $stmt = $this->dbcon->prepare($sql);

        // --- Bind parameters safely ---
        $stmt->bindParam(':cID', $cID, PDO::PARAM_INT);
        if (!empty($startDate)) $stmt->bindParam(':startDate', $startDate);
        if (!empty($endDate))   $stmt->bindParam(':endDate', $endDate);

        $stmt->execute();
        return $stmt;
    } catch (PDOException $e) {
        die("Error generating statement: " . $e->getMessage());
    }
}


/*public function genBothTrans($type, $startDate, $endDate, $cID)
{
    try {
        // --- Base WHERE conditions ---
        $whereDeposit = "WHERE cID = :cID";
        $whereWithdraw = "WHERE cID = :cID";

        // --- Optional date filtering ---
        if (!empty($startDate) && !empty($endDate)) {
            $whereDeposit  .= " AND depoD BETWEEN :startDate AND :endDate";
            $whereWithdraw .= " AND depoD BETWEEN :startDate AND :endDate";
        } elseif (!empty($startDate)) {
            $whereDeposit  .= " AND depoD >= :startDate";
            $whereWithdraw .= " AND depoD >= :startDate";
        } elseif (!empty($endDate)) {
            $whereDeposit  .= " AND depoD <= :endDate";
            $whereWithdraw .= " AND depoD <= :endDate";
        }

        // --- Build query depending on report type ---
        if ($type === 'deposit') {
            $sql = "
                SELECT depoD AS tdate, depoA AS amount, 'Deposit' AS description
                FROM deporec
                $whereDeposit
                ORDER BY tdate ASC
            ";
        } elseif ($type === 'withdraw') {
            $sql = "
                SELECT depoD AS tdate, -depoA AS amount, 'Withdraw' AS description
                FROM cuswithdraw
                $whereWithdraw
                ORDER BY tdate ASC
            ";
        } else { // both
            $sql = "
                SELECT depoD AS tdate, depoA AS amount, 'Deposit' AS description
                FROM deporec
                $whereDeposit

                UNION ALL

                SELECT depoD AS tdate, -depoA AS amount, 'Withdraw' AS description
                FROM cuswithdraw
                $whereWithdraw

                ORDER BY tdate ASC
            ";
        }

        // --- Prepare statement ---
        $stmt = $this->dbcon->prepare($sql);

        // --- Bind parameters safely ---
        $stmt->bindParam(':cID', $cID, PDO::PARAM_INT);
        if (!empty($startDate)) $stmt->bindParam(':startDate', $startDate);
        if (!empty($endDate))   $stmt->bindParam(':endDate', $endDate);

        $stmt->execute();
        return $stmt;
    } catch (PDOException $e) {
        die("Error generating statement: " . $e->getMessage());
    }
}


function genBothTrans($type,$startDate,$endDate,$cID){
  try{
$sqlParts = [];

if ($type === 'deposit' || $type === 'both') {
    $sqlParts[] = "
        SELECT depoD AS tdate, depoA AS amount, depoB AS description, 'Deposit' AS type
        FROM deporec
        WHERE cID = $cID
        AND depoD BETWEEN '$startDate' AND '$endDate'
    ";
}

if ($type === 'withdraw' || $type === 'both') {
    $sqlParts[] = "
        SELECT depoD AS tdate, -depoA AS amount, depoB AS description, 'Withdraw' AS type
        FROM cuswithdraw
        WHERE cID = $cID
        AND depoD BETWEEN '$startDate' AND '$endDate'
    ";
}

if (empty($sqlParts)) {
    die("<p class='text-danger'>Invalid report type selected.</p>");
}

$sql = implode(" UNION ALL ", $sqlParts) . " ORDER BY tdate ASC";
$stmt = $this->dbcon->prepare($sql);
$stmt->execute();

    return $stmt;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}*/

function genopeningWith($cID, $startDate){
  try{   
$stmt  = $this->dbcon->prepare("SELECT SUM(depoA) FROM cuswithdraw WHERE cID=? AND depoD < ?");
$stmt->execute([$cID, $startDate]);   
    return $stmt;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}




function undo_ConfirmCash($pOpt,$sdate){
  try{   
    $sts="Saved";
    $data= array($sts,$pOpt,$sdate);
    
    $ownerH=$this->dbcon->prepare("update  miamala set statusB=? where  transac=?  and dateR=?"); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function updateConfirmCash($pOpt,$sdate){
  try{   
    $sts="Confirmed";
    $data= array($sts,$pOpt,$sdate);
    
    $ownerH=$this->dbcon->prepare("update  miamala set statusB=? where  transac=?  and dateR=?"); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function updatePermit($on_off){
  try{
    $recID=1;
    
$data= array($on_off,$recID);
$ownerH=$this->dbcon->prepare("update  cusregS set on_off=? where  recID=?"); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function updateToDayCash($tPrice,$pOpt,$sdate){
  try{   
    $data= array($tPrice,$pOpt,$sdate);
    
    $ownerH=$this->dbcon->prepare("update  miamala set amount=? where  transac=?  and dateR=?"); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getMuamalaCheckByDt($pOpt,$sdat){
  try{
    $status="Confirmed";
    $data= array($pOpt,$sdat);
    $ownerH=$this->dbcon->prepare("select * from miamala where  transac=?  and dateR=?");  
    $ownerH->execute($data); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}
function getMuamalaCheckConf($pOpt,$sdat){
  try{
    $status="Confirmed";
    $data= array($pOpt,$sdat,$status);
    $ownerH=$this->dbcon->prepare("select * from miamala where  transac=?  and dateR=? and statusB=?");  
    $ownerH->execute($data); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getMuamalaCash($pOpt,$sdate){
  try{
    $data= array($pOpt,$sdate);
    $ownerH=$this->dbcon->prepare("select * from miamala where  transac=?  and dateR=?");  
    $ownerH->execute($data); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getCusDepo(){
  try{
    $ownerH=$this->dbcon->prepare("select * from deporec");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
function addDepo($recID,$cname,$depon,$sdate,$user){
  
 try{
  $regdate=Date("Y-m-d"); $time=$user."At:".Date("h:i:sa");
  $Q=$this->dbcon->prepare("insert into deporec(cID,cname,depoA,depoD,depoB)values(?,?,?,?,?)");
  $Q->execute(array($recID,$cname,$depon,$sdate,$time)); 
  return $Q;   		 
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q->ErrorInfo();
}
}

function withDraw($recID,$cname,$depon,$sdate,$user){
  
 try{
  $regdate=Date("Y-m-d"); $time=$user."At:".Date("h:i:sa");
  $Q=$this->dbcon->prepare("insert into cuswithdraw(cID,cname,depoA,depoD,depoB)values(?,?,?,?,?)");
  $Q->execute(array($recID,$cname,$depon,$sdate,$time)); 
  return $Q;   		 
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q;
}
}


function updateAddDp($bal,$recID){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $Q=$this->dbcon->prepare("update customer set deposit=? where recID=?");
  $Q->execute(array($bal,$recID)); 
  return $Q;   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q->ErrorInfo();
}
}
function getPermit(){
  try{
    $recID=1;
    $ownerH=$this->dbcon->prepare("select * from cusregS where recID=?");
    $ownerH->execute(array($recID)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
 


function getToDayCusDepoWthDrw($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from cuswithdraw where depoD=?");
     
    $ownerH->execute(array($sdate)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getToDayCusDepoWthDrwBdRange($dat1,$dat2){
  try{
    $ownerH=$this->dbcon->prepare("select * from cuswithdraw where depoD=? between ? and ?");
     
    $ownerH->execute(array($dat1,$dat2)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getToDayCusDepoByDrange($dat1,$dat2){
  try{
    $ownerH=$this->dbcon->prepare("select * from deporec where depoD between ? and ?");
     
    $ownerH->execute(array($dat1,$dat2)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}



function getToDayCusDepo($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from deporec where depoD=?");
     
    $ownerH->execute(array($sdate)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
function getCusDepoWithDraw(){
  try{
    $ownerH=$this->dbcon->prepare("select * from cuswithdraw");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
function updateBalanceByAccN($tname,$bal){
  try{   
    $data= array($bal,$tname);
    
    $ownerH=$this->dbcon->prepare("update  cashbalance set cbalance=? where  descrip=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function updateBalance($recID,$bal){
  try{   
    $data= array($bal,$recID);
    
    $ownerH=$this->dbcon->prepare("update  cashbalance set cbalance=? where  ID=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getDreveva(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct descrip from othersourceentryrec");  
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getThisDrOthersourceEntry($dr,$sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from othersourceentryrec where descrip=:dr and dateR=:dt order by recID desc");
     $ownerH->bindParam(":dr",$dr);
    $ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}
function getOthersourceEntrymoneyR($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from othersourceentryrec where dateR=:dt order by recID desc");
    $ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getExcessmoneyRDTrange($dat1,$dat2){
  try{
    $ownerH=$this->dbcon->prepare("select * from excessmoneyrec where dateR between ? and ?");
    //$ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(array($dat1,$dat2)); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getExcessmoneyRbdt($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from excessmoneyrec where dateR=:dt");
    $ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}
function getExcessmoneyR(){
  try{
    $ownerH=$this->dbcon->prepare("select * from excessmoneyrec order by recID desc");
    //$ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getExWithdrawR(){
  try{
    $ownerH=$this->dbcon->prepare("select * from excessmoneywdraw order by recID desc");
    //$ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}


function othersourceentryBdt($dat1,$dat2){
  try{
    $data= array($dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select * from othersourceentryrec where  dateR between ? and ?"); 
    $ownerH->execute($data); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
} 


function getWithdrawRBdt($sourceID,$dat1,$dat2){
  try{
    $data= array($sourceID,$dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select * from withdrawrec where sourceID=? and  dateW between ? and ?"); 
    $ownerH->execute($data); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getWithdrawR($sourceID,$sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from withdrawrec where sourceID=:sd and dateW=:dt");
    $ownerH->bindParam(":sd",$sourceID);
    $ownerH->bindParam(":dt",$sdate); 
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function balwithdraw($recID,$tname, $tPrice,$sdate,$user){
  

    $time="By:".$user."At:".Date("h:i:sa");

   $data=array($recID,$tname,$tPrice,$sdate,$time);
        
   try{   

      $Qr=$this->dbcon->prepare("insert into withdrawrec(sourceID,wreason,amount,dateW,timeAt) values(?,?,?,?,?)");
      
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function updateExcBalance($recID,$bal){
  try{   
    $data= array($bal,$recID);
    
    $ownerH=$this->dbcon->prepare("update  excbalance set cbalance=? where  ID=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getExcBalance($recID){
  try{   
    $data= array($recID);
    
    $ownerH=$this->dbcon->prepare("select * from  excbalance where  ID=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getBalance($recID){
  try{   
    $data= array($recID);
    
    $ownerH=$this->dbcon->prepare("select * from  cashbalance where  ID=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
 
function getPairBalance(){
  try{   
    //$data= array($recID);
    
    $ownerH=$this->dbcon->prepare("select descrip,cbalance from  cashbalance"); 
    $ownerH->execute();   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getAllBalance(){
  try{   
    //$data= array($recID);
    
    $ownerH=$this->dbcon->prepare("select * from  cashbalance"); 
    $ownerH->execute();   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
////////////STORE REQ///////////
function itemStoreQtmpEntry($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into storeqtemp(orderID,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
function getThisStoreqItmLst($orderID){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   storereqlst where orderID=:Id"); 
    $ownerH->bindParam(":Id",$orderID);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getStoreTransTrackR($iname){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  transferstore where  iname=:in"); 
    $ownerH->bindParam(":in",$iname);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getThisStoreItem($iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storeitem where  iname=:Id"); 
    $ownerH->bindParam(":Id",$iname);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 

function getStorePurchaseTrackR($iname){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecordstore where  iname=:in"); 
    $ownerH->bindParam(":in",$iname);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getStoreRqPrevItemBySch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storereq where  cname like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisStrRq($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from storereq where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getThisStoreQ($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from storereq where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}


function getThisTrans($recID){
  try{
      $data=array($recID);
        $ownerH=$this->dbcon->prepare("select * from miamala where recID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  } catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}




function deletrD($recID){
  try{
      $data=array($recID);
        $ownerH=$this->dbcon->prepare("delete from miamala where recID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  } catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}



function deleteStoreTemp($iname)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from storeqtemp where iname=:nm");
  $Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function getItemBySearchStore($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storeitem where  iname like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}



function clearStoreqTemp()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from storeqtemp");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
function regStorerQord($orderID,$cus,$bal,$ptd,$tsprice,$pst,$sdate)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cus,$sdate,$sdate,$tsprice,$ptd,$bal,$pst);   

try{    
$Qr=$this->dbcon->prepare("insert into storereq(orderID,cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}
function storeQItem($orderID,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$user)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$time);   

try{    
$Qr=$this->dbcon->prepare("insert into storereqlst(orderID,itemID,iname,tprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function genStoreID(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storereq");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisTempStoreQ(){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from storeqtemp"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

////////////////PROFORMA///////////////
////lpgaspoi
////wyN15#]YkTD31m
function getThisProfItmLst($orderID){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   profitem where orderID=:Id"); 
    $ownerH->bindParam(":Id",$orderID);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getProfPrevItemBySch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  prof where  cname like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function clearProfTemp()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from temprof");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
function regProf($orderID,$cus,$bal,$ptd,$tsprice,$pst,$sdate)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cus,$sdate,$sdate,$tsprice,$ptd,$bal,$pst);   

try{    
$Qr=$this->dbcon->prepare("insert into prof(orderID,cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}
function getThisProf($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from prof where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
function profItem($orderID,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$user)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$time);   

try{    
$Qr=$this->dbcon->prepare("insert into profitem(orderID,itemID,iname,tprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function itemProfEntry($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into temprof(orderID,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
 
function deleteProfTemp($iname)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from temprof where iname=:nm");
  $Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
 function getThisStaff($recID){
  try{
    $act="Active";
    $ownerH=$this->dbcon->prepare("select * from users where userid=:Id");
    $ownerH->bindParam(":Id",$recID); 
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function genProfID(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  prof");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisTempProf(){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   temprof"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

////////////END PROFORMA////////////

function gettransR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  transferstore where  entryD=:dt"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getDumpingStoreRBdt($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  storedumped where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getStoreDumpsR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  storedumped where  entryD=:dt"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function itemDumpEntryStore($defect,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($defect,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into storedumped(defect,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function getPurchaseStoreRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecordstore where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPurchaseStoreR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecordstore where  entryD=:dt"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getStoreTransRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  transferstore where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getDrugListStore(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storeitem order by iqty desc");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function updateItemDStore($iname,$icat,$ipprice,$isprice,$wsprice,$itemID,$expd){
  try{
      $data=array($iname,$icat,$ipprice,$isprice,$wsprice,$expd,$itemID);
        $ownerH=$this->dbcon->prepare("update storeitem set iname=?,icat=?,ipprice=?,isprice=?,wsprice=?,expd=?  where itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisItemStoreFED($itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storeitem where   iname=:nm and itemID!=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function transferStore($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user,$pOpt)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time,$pOpt);
try{    
$Qr=$this->dbcon->prepare("insert into transferstore(itemID,  iname,ipprice,isprice,eQty,entryD,timeAt ,pOpt 
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
function getThisItemStoreBID($itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storeitem where   iname=:nm and itemID=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function updateItemQStore($iname,$tQty,$itemID){
  try{
      $data=array($tQty,$iname,$itemID);
        $ownerH=$this->dbcon->prepare("update storeitem set iqty=?  where iname=? and itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}
function updateItemQStoreNoID($iname,$tQty){
  try{
      $data=array($tQty,$iname);
        $ownerH=$this->dbcon->prepare("update storeitem set iqty=?  where iname=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}

 
function getThisItemStore($iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  storeitem where  iname=:Id"); 
    $ownerH->bindParam(":Id",$iname);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function itemRegStore($iname,$icat,$ipprice,$wsprice,$isprice,$iQty,$expd)
{
$data=array($iname,$icat,$ipprice,$isprice,$wsprice,$iQty,$expd);
try{    
$Qr=$this->dbcon->prepare("insert into storeitem(iname,icat,ipprice,isprice,wsprice,iqty,expd) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}
function itemPurchaseEntryStore($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into purchaserecordstore(itemID,iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
//transferStore






function getDrTech(){
  try{
    $depart="Doctor";
    $ownerH=$this->dbcon->prepare("select * from users where department=:em"); 
    $ownerH->bindParam(":em",$depart); 
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
 function getPharmExRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  expenditure where  exDate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

 

function getPatientsRecordByDate($dat1,$dat2){
  try{
    
    $data= array($dat1,$dat2);

    $ownerH=$this->dbcon->prepare("select * from patientdetail where regdate between ? and ?");  
      
    $ownerH->execute($data); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
 
 
 
  function getTransacRBSortDt($dat1,$dat2){
  try{
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from miamala where dateR between ?  and ?"); 
    $ownerH->execute($data); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

 
 function getTransacRBsysD($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from miamala where dateR=:sd");
    $ownerH->bindParam(":sd",$sdate);
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


 
 function getExpensesRBsysD($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from expenditure where exDate=:sd");
    $ownerH->bindParam(":sd",$sdate);
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}




function getExpensesR(){
  try{
    $ownerH=$this->dbcon->prepare("select * from expenditure");
    $ownerH->execute(); 
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


///----------------REGISTRATION FORM VALIDATION---------------------
function registerEx($tname, $tPrice,$exDate){
  

   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   $data=array($tname, $tPrice,$exDate);
        
   try{   

      $Qr=$this->dbcon->prepare("insert into expenditure(exReason,exAmount,exDate) values(?,?,?)");
      
      $Qr->execute($data); 

      if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
   

}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function updateCustomer($cname,$phoneno,$address,$ward,$district,$region,$recID){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $Q=$this->dbcon->prepare("update customer set cname=?,phone=?,address=?,ward=?,district=? ,region=? where recID=?");
  $Q->execute(array($cname,$phoneno,$address,$ward,$district,$region,$recID)); 
  return $Q;   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q->ErrorInfo();
}
}

function updateAgent($cname,$phoneno,$address,$ward,$district,$region,$recID){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $Q=$this->dbcon->prepare("update agent set cname=?,phone=?,address=?,ward=?,district=? ,region=? where recID=?");
  $Q->execute(array($cname,$phoneno,$address,$ward,$district,$region,$recID)); 
  return $Q;   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q->ErrorInfo();
}
}
function addAgent($fname,$phoneno,$street,$ward,$district,$region){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $Q=$this->dbcon->prepare("insert into agent(cname,phone,address,ward,district,region,regD)values(?,?,?,?,?,?,?)");
  $Q->execute(array($fname,$phoneno,$street,$ward,$district,$region,$regdate)); 
  return $Q;   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q->ErrorInfo();
}
}
function addCustomer($fname,$phoneno,$street,$ward,$district,$region){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
   $Q=$this->dbcon->prepare("insert into customer(cname,phone,address,ward,district,region,regD)values(?,?,?,?,?,?,?)");
  $Q->execute(array($fname,$phoneno,$street,$ward,$district,$region,$regdate)); 
  return $Q;   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Q->ErrorInfo();
}
}
///////////////////////////
function getCusRecord(){
  try{
    $act="Active";
    $ownerH=$this->dbcon->prepare("select * from customer");
    //$ownerH->bindParam(":Id",$kikundiid);
    //$ownerH->bindParam(":act",$act);
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getThisExist($phoneno){
  try{
    $act="Active";
    $ownerH=$this->dbcon->prepare("select * from customer where phone=:cn");
    $ownerH->bindParam(":cn",$phoneno); 
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}




function getThisCus($cus){
  try{
    $act="Active";
    $ownerH=$this->dbcon->prepare("select * from customer where cname=:cn");
    $ownerH->bindParam(":cn",$cus); 
    $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
////////////////
////////////////

function addUsers($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");
 
  $Q=$this->dbcon->prepare("insert into users(pwd,department,email,fname,mname,lname,gender,occupation,phoneno,citizen,address,dob,dhired)values(?,?,?,?,?,?,?,?,?,?,?,?,?)");

  $Q->execute(array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate)); 

   if($Q->rowCount()>0)
   {
     return $Q;  
    }
   else
   {   
   return $Q->ErrorInfo(); 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function getUsersRecord(){
  try{
    $ownerH=$this->dbcon->prepare("select * from users");  
      $ownerH->execute(); 
      
    return $ownerH;
    

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

 function ilogin($username,$password){
  try{

    $Rs=$this->dbcon->prepare("select * from users where email=:em and ipwd=:psd");
    $Rs->bindParam(":em",$username);
    $Rs->bindParam(":psd",$password);
    $Rs->execute(); 
    
     return $Rs;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

 function login($username,$password){
  try{

    $Rs=$this->dbcon->prepare("select * from users where email=:em and pwd=:psd");
    $Rs->bindParam(":em",$username);
    $Rs->bindParam(":psd",$password);
    $Rs->execute(); 
    
     return $Rs;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getDumpingRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  dumpsrecord where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

 function getSellRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  sellsrecord where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

 
function getPurchaseRBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecord where  entryD between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPurchaseTrackR($iname){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecord where  iname=:in"); 
    $ownerH->bindParam(":in",$iname);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 
function getPurchaseR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  purchaserecord where  entryD=:dt"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisTemOrder(){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   temporder"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThispOrderItemList($orderID){
  try{  
 
    $ownerH=$this->dbcon->prepare("select * from   porderitemlist where orderID=:Id"); 
    $ownerH->bindParam(":Id",$orderID);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getThispOrderUnconfirmed(){
  try{  
     
    $ownerH=$this->dbcon->prepare("select * from   porderitemlist where confrecv is null order by recID desc");
    //$ownerH->bindParam(":Id",$status);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function getThispOrderCbyIn($cname){
  try{  
     
    $ownerH=$this->dbcon->prepare("select * from   porderitemlist where confrecv is null and iname like ? order by recID desc"); 
    $ownerH->execute(array('%'.$cname.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getThisAgInvItemList($orderID,$agentid){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   ainvoiceitemlist where orderID=:Id and agentid=:ag"); 
    $ownerH->bindParam(":Id",$orderID);
    $ownerH->bindParam(":ag",$agentid);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getThisInvItemList($orderID){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   invoiceitemlist where orderID=:Id"); 
    $ownerH->bindParam(":Id",$orderID);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getThisPCreateOrder($user){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   cptemporder where timeAt like ? order by iname asc"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(array('%'.$user.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisPOrderQByID($orderID){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   porderitemlistQ where orderID=:id order by eQty asc"); 
    $ownerH->bindParam(":id",$orderID);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}



function getThisPOrderQ(){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   porderitemlistQ order by eQty asc"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisPTemOrderQtmp(){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from   ptemporderQ order by eQty asc"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisPTemOrder(){
  try{  
 
    //eQty
    $ownerH=$this->dbcon->prepare("select * from   ptemporder order by recID asc"); 
    //$ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}


function getSellsTrackR($iname){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  sellsrecord where  iname=:in"); 
    $ownerH->bindParam(":in",$iname);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
 

function getSellsR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  sellsrecord where  entryD=:dt order by recID asc"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
 
 
function getDumpsR($sdate){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  dumpsrecord where  entryD=:dt"); 
    $ownerH->bindParam(":dt",$sdate);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getDumpsTrackR($iname){
  try{  
 
    
    $ownerH=$this->dbcon->prepare("select * from  dumpsrecord where  iname=:in"); 
    $ownerH->bindParam(":in",$iname);
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
 
function updateChangeP($password,$opassword,$email){
  try{
      $data=array($password,$email,$opassword);
      $ownerH=$this->dbcon->prepare("update users set pwd=? where email=? and pwd=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 

 

 
function updateItemD($iname,$icat,$ipprice,$isprice,$wsprice,$itemID,$expd){
  try{
      $data=array($iname,$icat,$ipprice,$isprice,$wsprice,$expd,$itemID);
        $ownerH=$this->dbcon->prepare("update iteminfo set iname=?,icat=?,ipprice=?,isprice=?,wsprice=?,expd=?  where itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
            
       
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 function updateItemQAg($iname,$agentid,$tQty,$itemID){
  try{
      $data=array($tQty,$iname,$agentid,$itemID);
        $ownerH=$this->dbcon->prepare("update aiteminfo set iqty=?  where iname=? and agentid=? and itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) {
           return $ownerH;
      } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function updateInvItmListD($ds,$us,$iname,$itemID,$orderID){
  try{
      $data=array($ds,$us,$iname,$itemID,$orderID);
        $ownerH=$this->dbcon->prepare("update invoiceitemlist set entryD=?,timeAt=?  where iname=? and itemID=? and orderID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}



function cancelHPOrderD($cname,$bal,$pbal,$orderID){
  try{
      $bal=0;
      $pbal=0;
      $concel="--cancelled--";
      $data=array($concel,$bal,$pbal,$orderID);
        $ownerH=$this->dbcon->prepare("update ordert set cname=?, balance=?,payableA=?  where  orderID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}


function cancelOrderD($cname,$bal,$pbal,$orderID){
  try{
      $concel="--cancelled--".$cname."--cancelled--";
      $data=array($concel,$bal,$pbal,$orderID);
        $ownerH=$this->dbcon->prepare("update ordert set cname=?, balance=?,payableA=?  where  orderID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}




function updateOrderD($bal,$pbal,$orderID){
  try{
      $data=array($bal,$pbal,$orderID);
        $ownerH=$this->dbcon->prepare("update ordert set balance=?,payableA=?  where  orderID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}

function updateSellD($ds,$npOpt,$us,$iname,$itemID,$recID){
  try{
      $data=array($ds,$npOpt,$us,$iname,$itemID,$recID);
        $ownerH=$this->dbcon->prepare("update sellsrecord set entryD=?,popt=?, timeAt=?  where iname=? and itemID=? and recID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}

function delPurchD($ds,$tim,$iname,$itemID,$recID){
  try{
      $data=array($ds,$tim,$iname,$itemID,$recID);
        $ownerH=$this->dbcon->prepare("delete from purchaserecord where entryD=?  and timeAt=?  and iname=? and itemID=? and recID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  } catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function delexD($exD){
  try{
      $data=array($exD);
        $ownerH=$this->dbcon->prepare("delete from expenditure where expID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  } catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}

function getThisexD($exD){
  try{
      $data=array($exD);
        $ownerH=$this->dbcon->prepare("select * from expenditure where expID=?"); 
     
         $ownerH->execute($data); 
        
          return $ownerH;
       
     

  } catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }
}



function delSellVinVD($ds,$tim,$iname,$itemID){
  try{
      $data=array($ds,$tim,$iname,$itemID);
        $ownerH=$this->dbcon->prepare("delete from sellsrecord where entryD=?  and timeAt=?  and iname=? and itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}







function delSellD($ds,$pOpt,$tim,$iname,$itemID,$recID){
  try{
      $data=array($ds,$pOpt,$tim,$iname,$itemID,$recID);
        $ownerH=$this->dbcon->prepare("delete from sellsrecord where entryD=? and popt=? and timeAt=?  and iname=? and itemID=? and recID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}

function delorderitD($ds,$orderID,$tim,$iname,$itemID,$recID){
  try{
      $data=array($ds,$orderID,$tim,$iname,$itemID,$recID);
        $ownerH=$this->dbcon->prepare("delete from invoiceitemlist where entryD=? and orderID=? and timeAt=?  and iname=? and itemID=? and recID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}


function updateItemExBmoney($iname,$tQty){
  try{
      $data=array($tQty,$iname);
        $ownerH=$this->dbcon->prepare("update iteminfo set iqty=?  where iname=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}


function updateItemQTrans($iname,$tQty){
  try{
      $data=array($tQty,$iname);
        $ownerH=$this->dbcon->prepare("update iteminfo set iqty=?  where iname=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}



function updateItemQ($iname,$tQty,$itemID){
  try{
      $data=array($tQty,$iname,$itemID);
        $ownerH=$this->dbcon->prepare("update iteminfo set iqty=?  where iname=? and itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}


function delItem($iname,$itemID){
  try{
      $data=array($iname,$itemID);
        $ownerH=$this->dbcon->prepare("delete from iteminfo where iname=? and itemID=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}





function itemRegAg($agentid,$iname,$icat,$ipprice,$isprice,$iQty,$expd)
{
$data=array($agentid,$iname,$icat,$ipprice,$isprice,$iQty,$expd);
try{    
$Qr=$this->dbcon->prepare("insert into aiteminfo(agentid,iname,icat,ipprice,isprice,iqty,expd) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}


function itemReg($iname,$icat,$ipprice,$wsprice,$isprice,$iQty,$expd)
{
$data=array($iname,$icat,$ipprice,$isprice,$wsprice,$iQty,$expd);
try{    
$Qr=$this->dbcon->prepare("insert into iteminfo(iname,icat,ipprice,isprice,wsprice,iqty,expd) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

function itemDumpEntry($defect,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($defect,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into dumpsrecord(defect,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
 
function itemSellEntryAg($itemID,$agentid,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($itemID,$agentid,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into asellsrecord(itemID,  agentid,iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function itemShTostEntry($itemID,$tim,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=$tim.": By ".$user;
$data=array($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into shopTOstoreTrans(itemID,  iname,ipprice,isprice,eQty,entryD,timeAt 
) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}




function itemSellEntry($itemID,$tim,$iname,$ipprice,$isprice,$nQty,$sdate,$user,$pOpt)
{
  $time=$tim.": By ".$user;
$data=array($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time,$pOpt);
try{    
$Qr=$this->dbcon->prepare("insert into sellsrecord(itemID,  iname,ipprice,isprice,eQty,entryD,timeAt ,pOpt 
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function delCreateOrderTemp($iname)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from cptemporder where iname=:nm");
  $Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function deletepOrderTempQ($iname)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from ptemporderQ where iname=:nm");
  $Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function deletepOrderTemp($iname)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from ptemporder where iname=:nm");
  $Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function deleteInvProcess($iname,$orderID)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from invoiceitemlist where iname=:nm and orderID=:on");
  $Qr->bindParam(":nm",$iname);
  $Qr->bindParam(":on",$orderID);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function deleteOrderTemp($iname)
{  
try{    
  $Qr=$this->dbcon->prepare("delete from temporder where iname=:nm");
  $Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function clearPCreateOrderTemp()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from cptemporder");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function clearPItemListQ()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from porderitemlistQ");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function clearPOrderTempQ()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from ptemporderQ");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function clearPOrderTemp()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from ptemporder");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function clearOrderTemp()
{  
try{    
  $Qr=$this->dbcon->prepare("delete from temporder");
  //$Qr->bindParam(":nm",$iname);
  $Qr->execute();
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}
//cPdebitPRec($orderID,$cus,$cash,$sdate,$user,$pOpt)
function cPdebitPRec($orderID,$cus,$cash,$sdate,$user,$pOpt)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cash,$sdate,$cus,$time,$pOpt);   

try{    
$Qr=$this->dbcon->prepare("insert into cdebitpayrecord(orderID,paidAmount,datePaid,cname,timeP,pOpt   
) values(?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function debitPRec($orderID,$cus,$cash,$sdate,$user,$pOpt)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cash,$sdate,$cus,$time,$pOpt);   

try{    
$Qr=$this->dbcon->prepare("insert into debitpayrecord(orderID,paidAmount,datePaid,cname,timeP,pOpt   
) values(?,?,?,?,?,?)");
  $Qr->execute($data);
   
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function debitNonPurchRec($orderID,$cus,$cash,$sdate,$user,$pOpt)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cash,$sdate,$cus,$time,$pOpt);   

try{    
$Qr=$this->dbcon->prepare("insert into nonpurchpayrec(orderID,paidAmount,datePaid,cname,timeP,pOpt   
) values(?,?,?,?,?,?)");
  $Qr->execute($data);
   
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function regPOrderQ($orderID,$cus,$bal,$ptd,$tsprice,$pst,$sdate,$add){
///$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cus,$sdate,$sdate,$tsprice,$ptd,$bal,$pst,$add);   

try{    
$Qr=$this->dbcon->prepare("insert into pordertQ(orderID,cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus,receivedF  
) values(?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function regPOrder($orderID,$cus,$bal,$ptd,$tsprice,$pst,$sdate,$add){
///$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cus,$sdate,$sdate,$tsprice,$ptd,$bal,$pst,$add);   

try{    
$Qr=$this->dbcon->prepare("insert into pordert(orderID,cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus,receivedF  
) values(?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function regOrderAg($orderID,$agentid,$cus,$bal,$ptd,$tsprice,$pst,$sdate)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$agentid,$cus,$sdate,$sdate,$tsprice,$ptd,$bal,$pst);   

try{    
$Qr=$this->dbcon->prepare("insert into aordert(orderID,agentid,cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus  
) values(?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function updateNonOrder($orderID,$nbal,$ptd,$pst)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($ptd,$nbal,$pst,$orderID);   

try{    
$Qr=$this->dbcon->prepare("update nonpurchdebit set paidtodate=?,balance=?,pstatus=? where orderID=?");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;     
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function updateOrder($orderID,$nbal,$ptd,$pst)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($ptd,$nbal,$pst,$orderID);   

try{    
$Qr=$this->dbcon->prepare("update ordert set paidtodate=?,balance=?,pstatus=? where orderID=?");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;     
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function updatePOrder($orderID,$nbal,$ptd,$pst)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($ptd,$nbal,$pst,$orderID);   

try{    
$Qr=$this->dbcon->prepare("update pordert set paidtodate=?,balance=?,pstatus=? where orderID=?");
  $Qr->execute($data);
   
 return $Qr;     
     
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;//->ErrorInfo();
}
}

function othersourceentryrec($descrip,$user,$tPrice,$sdate)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($descrip,$time,$tPrice,$sdate);   

try{    
$Qr=$this->dbcon->prepare("insert into othersourceentryrec(descrip,timeAt,amount,dateR) values(?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}



function excessmoneyrec($descrip,$user,$tPrice,$sdate)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($descrip,$time,$tPrice,$sdate);   

try{    
$Qr=$this->dbcon->prepare("insert into excessmoneyrec(descrip,timeAt,amount,dateR) values(?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}


function miamala($pOpt,$user,$tPrice,$sdate)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($pOpt,$user,$tPrice,$sdate);   

try{    
$Qr=$this->dbcon->prepare("insert into miamala(transac,tim,amount,dateR  
) values(?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}



function regnonOrder($cname,$bal,$ptd,$tsprice,$pst,$sdate)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($cname,$sdate,$sdate,$tsprice,$ptd,$bal,$pst);   

try{    
$Qr=$this->dbcon->prepare("insert into nonpurchdebit(cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus  
) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}



function regOrder($orderID,$cus,$bal,$ptd,$tsprice,$pst,$sdate)
{
///$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$cus,$sdate,$sdate,$tsprice,$ptd,$bal,$pst);   

try{    
$Qr=$this->dbcon->prepare("insert into ordert(orderID,cname,orderdate,datePaid,payableA,paidtodate,balance,pstatus  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
   
  return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
   
}
catch(PDOException $ex){
  $ex->getMessage();
  //return $Qr;
}
}

function porderItemstfQ($orderID,$itemID,$iname,$tprice,$ipprice,$nQty,$sdate,$user,$pOpt)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$tprice,$ipprice,$nQty,$sdate,$time,$pOpt);   

try{    
$Qr=$this->dbcon->prepare("insert into porderitemlistQ(orderID,itemID,iname,tprice,isprice,eQty,entryD,timeAt,pOpt  
) values(?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function porderItem($orderID,$itemID,$iname,$tprice,$ipprice,$nQty,$sdate,$user,$pOpt)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$tprice,$ipprice,$nQty,$sdate,$time,$pOpt);   

try{    
$Qr=$this->dbcon->prepare("insert into porderitemlist(orderID,itemID,iname,tprice,isprice,eQty,entryD,timeAt,pOpt  
) values(?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function orderItemAg($orderID,$agentid,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$user)
{
$time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$agentid,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$time);   

try{    
$Qr=$this->dbcon->prepare("insert into ainvoiceitemlist(orderID,agentid,itemID,iname,tprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function orderItem($orderID,$tim,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$user)
{
$time=$tim.": By ".$user;
$data=array($orderID,$itemID,$iname,$tprice,$isprice,$nQty,$sdate,$time);   

try{    
$Qr=$this->dbcon->prepare("insert into invoiceitemlist(orderID,itemID,iname,tprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}


function itemCPOrdeEntry($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into cptemporder(orderID,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}



function itemPOrdeEntry($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into ptemporder(orderID,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}





function itemPOrdeEntryQ($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into ptemporderQ(orderID,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function itemOrdeEntry($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($orderID,$itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into temporder(orderID,itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function itemPurchaseEntryAg($itemID,$agentid,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($itemID,$agentid,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into apurchaserecord(itemID,  agentid,iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function itemPurchaseEntry($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user)
{
  $time=Date("H:i:sa").": By ".$user;
$data=array($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$time);
try{    
$Qr=$this->dbcon->prepare("insert into purchaserecord(itemID,  iname,ipprice,isprice,eQty,entryD,timeAt  
) values(?,?,?,?,?,?,?)");
  $Qr->execute($data);
  if($Qr->rowCount()>0)
       {
        return $Qr;// $suc="SUCCESSFULLLY REGISTRERED!";    
       }
      else
      {   
      return $Qr;//->ErrorInfo(); 
      }
}
catch(PDOException $ex){
  $ex->getMessage();
  return $Qr;
}
}

function getThisAgItem($iname,$agentid){
  try{
    $ownerH=$this->dbcon->prepare("select * from  aiteminfo where  iname=:Id and agentid=:aid"); 
    $ownerH->bindParam(":Id",$iname);
    $ownerH->bindParam(":aid",$agentid);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function getThisItem($iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where  iname=:Id"); 
    $ownerH->bindParam(":Id",$iname);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 
function getPorderPrevItemBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  pordert where  cname like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusOrderRecByFrN($cname){
  try{   
    $data= array('%'.$cname.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where cname like ? order by orderdate desc"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisOrderRecBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCorderByDboth($cname,$dat1,$dat2){
  try{   
    $data= array('%'.$cname.'%',$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where cname like ?  and  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
 


function getInVRecBydt($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }
}
function getThisSupDebit($cname,$status){
  try{   
    $data= array('%'.$cname.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where cname like ? and pstatus=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCmpnyDebit($cname,$status){
  try{   
    $data= array('%'.$cname.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where cname like ? and pstatus=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCusNonPurchDebit($cname,$status){
  try{   
    $data= array('%'.$cname.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  nonpurchdebit where cname like ? and pstatus=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCusDebit($cname,$status){
  try{   
    $data= array('%'.$cname.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where cname like ? and pstatus=? "); 
    $ownerH->execute($data);   
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCmpnyPorderByD($cname,$status,$dat1,$dat2){
  try{   
    $data= array('%'.$cname.'%',$status,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where cname like ? and pstatus=? and  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCorderByD($cname,$status,$dat1,$dat2){
  try{   
    $data= array('%'.$cname.'%',$status,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where cname like ? and pstatus=? and  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisDateOrder($sdate){
  try{   
    $data= array($sdate);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where  orderdate=? "); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCusDebitsBsysD($status,$sdate){
  try{   
    $data= array($status,$sdate);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where  pstatus= ? and orderdate=? "); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getThisCompnyDebits($status){
  try{   
    $data= array($status);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where pstatus= ? "); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusNonDebits($status){
  try{   
    $data= array($status);
    
    $ownerH=$this->dbcon->prepare("select * from  nonpurchdebit where pstatus= ? "); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisOnlyOlddbt($cn,$status){
  try{   
    $data= array('%'.$cn.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  nonpurchdebit where cname like ? and pstatus= ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }
}

function getThisOnlyCusdbt($pn,$status){
  try{   
    $data= array('%'.$pn.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where cname like ? and pstatus= ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }
}


function getThisCusDebits($status){
  try{   
    $data= array($status);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where pstatus= ? "); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCompnyPOrderRecBydate($status,$dat1,$dat2){
  try{   
    $data= array($status,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where pstatus= ? and  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusOrderRecBydate($status,$dat1,$dat2){
  try{   
    $data= array($status,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where pstatus= ? and  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusRecByP($phone){
  try{   
    $data= array('%'.$phone.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  customer where phone like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCusRecByR($region){
  try{   
    $data= array('%'.$region.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  customer where region like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusRecByD($district){
  try{   
    $data= array('%'.$district.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  customer where district like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusRecByW($ward){
  try{   
    $data= array('%'.$ward.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  customer where ward  like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisCusRecByS($street){
  try{   
    $data= array('%'.$street.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  customer where address like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisCusRecByN($cname){
  try{   
    $data= array('%'.$cname.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  customer where cname like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
/////////////////////
function getThisAgRecByR($region){
  try{   
    $data= array('%'.$region.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  agent where region like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisAgRecByD($district){
  try{   
    $data= array('%'.$district.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  agent where district like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisAgRecByW($ward){
  try{   
    $data= array('%'.$ward.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  agent where ward  like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getThisAgRecByS($street){
  try{   
    $data= array('%'.$street.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  agent where address like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getAgInVRecBydt($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  aordert where  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }
}



function getThisAgInVRecByN($agentid,$dat1,$dat2){
  try{   
    $data= array($agentid,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  aordert where agentid=? and orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }
}



function getThisAgPhByN($agent){
  try{   
    $data= array('%'.$agent.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  agent where cname like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getThisAgRecByN($cname){
  try{   
    $data= array('%'.$cname.'%');
    
    $ownerH=$this->dbcon->prepare("select * from  agent where cname like ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

/////////////////
function getThisCompDbtPorderBcN($cname){
  try{
    $status="NOT PAID";
    $data= array('%'.$cname.'%',$status);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where cname like ? and pstatus=? order by orderdate desc"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getThisCusPorderRecBydate($cname,$dat1,$dat2){
  try{   
    $data= array('%'.$cname.'%',$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where cname like ? and  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getCompDbtPorderRecBydate($dat1,$dat2){
  try{  
     $status="NOT PAID";
    $data= array($status,$dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where pstatus=? and orderdate between ? and ? order by recID desc"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getPorderRecBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  pordert where  orderdate between ? and ? order by recID desc"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }
}

function getInvRecBydate($dat1,$dat2){
  try{   
    $data= array($dat1,$dat2);
    
    $ownerH=$this->dbcon->prepare("select * from  ordert where  orderdate between ? and ?"); 
    $ownerH->execute($data);  
    return $ownerH;
  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


/////////////////////////


function getAgListBaR(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct region from  agent");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getAgListBaD(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct district from  agent");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getAgListBaW(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct ward from  agent");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getAgListBaS(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct address from  agent");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getAgListBaN(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct cname from  agent");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
//////////////
function getPOrderListBcN(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct cname from  pordert");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getNonOrderListBcN(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct cname from  nonpurchdebit");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getOrderPRecListBcN(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct cname from  debitpayrecord");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getOrderListBcN(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct cname from  ordert");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getCusListBcR(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct region from  customer");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getCusListBcD(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct district from  customer");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getCusListBcW(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct ward from  customer");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getCusListBcS(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct address from  customer");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function blockus($eid,$email,$pwd){
  try{
      $data=array($pwd,$eid,$email);
        $ownerH=$this->dbcon->prepare("update users set pwd=? where userid=? and email=?"); 
     
         $ownerH->execute($data); 
       if ($ownerH->rowCount()>0) 
          {
          return $ownerH;
          } 
      else{
        return $ownerH;
      }
     

  }
  catch(PDOException $xc){
    $xc->getMessage();
    return $ownerH;
  }

}
function getCusListBcP(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct phone from  customer");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getCusListBcN(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct cname from  customer");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}



function getPorderRec(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  pordert order by recID desc");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDebitsPrecBcCdtID($orderID,$dat1,$dat2){
  try{
    $data= array($orderID,$dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select * from  debitpayrecord where orderID=? and datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    return $ownerH;
    $xc->getMessage();
  }
}


function getDebitsPrecBcCdt($cname,$dat1,$dat2){
  try{
    $data= array('%'.$cname.'%',$dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select distinct orderID from  debitpayrecord where cname like ? and datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    return $ownerH;
    $xc->getMessage();
  }
}
function getComPDebitsRecBcCdt($cname,$dat1,$dat2){
  try{
    $data= array('%'.$cname.'%',$dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select distinct orderID from  cdebitpayrecord where cname like ? and datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    return $ownerH;
    $xc->getMessage();
  }
}
function getComPDebitsRecBcCNn($cname){
  try{
    $data= array('%'.$cname.'%');
    $ownerH=$this->dbcon->prepare("select distinct orderID from  cdebitpayrecord where cname like ?  order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    return $ownerH;
    $xc->getMessage();
  }
}
function getDebitsPrecBcCNn($cname){
  try{
    $data= array('%'.$cname.'%');
    $ownerH=$this->dbcon->prepare("select distinct orderID from  debitpayrecord where cname like ?  order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    return $ownerH;
    $xc->getMessage();
  }
}
function getNonDebitsPrecBdt($dat1,$dat2){
  try{
    $data= array($dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select * from  nonpurchpayrec where datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDebitsPrecBdt($dat1,$dat2){
  try{
    $data= array($dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select distinct orderID from  debitpayrecord where datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getComPDebitsRecBdt($dat1,$dat2){
  try{
    $data= array($dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select distinct orderID from  cdebitpayrecord where datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
/*function getDebitsNonPrecBdtRD($dat1,$dat2){
  try{
     $data= array($dat1,$dat2);
    $ownerH=$this->dbcon->prepare("select * from  nonpurchpayrec where datePaid between ? and ? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}*/

function getDebitsNonPrecBsysD($sdate){
  try{
     $data= array($sdate);
    $ownerH=$this->dbcon->prepare("select * from  nonpurchpayrec where datePaid=? order by datePaid desc");
  
     $ownerH->execute($data); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDebitsPrecBsysD($sdate){
  try{
    $ownerH=$this->dbcon->prepare("select distinct orderID from  debitpayrecord order by datePaid desc");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getDebitsPrec(){
  try{
    $ownerH=$this->dbcon->prepare("select distinct orderID from  debitpayrecord order by datePaid desc");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDebitsNonPayListsBsysD($orderID,$sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from  nonpurchpayrec where orderID=:Id and datePaid=:sd order by datePaid asc");
     $ownerH->bindParam(":Id",$orderID);
     $ownerH->bindParam(":sd",$sdate);
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDebitsPayListsBsysD($orderID,$sdate){
  try{
    $ownerH=$this->dbcon->prepare("select * from  debitpayrecord where orderID=:Id and datePaid=:sd order by datePaid asc");
     $ownerH->bindParam(":Id",$orderID);
     $ownerH->bindParam(":sd",$sdate);
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getCmpnyDebP_Rec(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  cdebitpayrecord order by datePaid asc");
     //$ownerH->bindParam(":Id",$orderID);
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getCmpnyDebitsPayLists($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from  cdebitpayrecord where orderID=:Id order by datePaid asc");
     $ownerH->bindParam(":Id",$orderID);
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getDebitsPayLists($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from  debitpayrecord where orderID=:Id order by datePaid asc");
     $ownerH->bindParam(":Id",$orderID);
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getInvRec(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  ordert order by orderdate desc");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getInvPrevItemBySearch($searchValue){
  try{
     $status="NOT PAID";
    $ownerH=$this->dbcon->prepare("select * from  ordert where  cname like ? and pstatus=?");
  
     $ownerH->execute(array('%'.$searchValue.'%',$status)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getAgentItemBySearch($searchValue,$agentid){
  try{
    $ownerH=$this->dbcon->prepare("select * from  aiteminfo where  iname like ? and agentid=?");
  
     $ownerH->execute(array('%'.$searchValue.'%',$agentid)); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getItemBySearch($searchValue){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where  iname like ?");
  
     $ownerH->execute(array('%'.$searchValue.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}
function getDrugList(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo");
  
     $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}


function getCusDepoList(){
  try{
      
    $ownerH=$this->dbcon->prepare("select * from customer order by deposit desc");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getThisCusBId($cID){
  try{
    $ownerH=$this->dbcon->prepare("select * from customer where recID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$cID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getCus(){
  try{
    $ownerH=$this->dbcon->prepare("select * from customer");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getAgent(){
  try{
    $ownerH=$this->dbcon->prepare("select * from agent");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
 

function updatepOrderInvRecvInfo($orderID,$time,$dat){
  try{
      $data=array($time,$dat,$orderID);
        $ownerH=$this->dbcon->prepare("update pordert set recvby=?,invdate=?  where orderID=?");  
         $ownerH->execute($data); 
         return $ownerH; 
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }

}

 function delPurchOrderItem($orderID,$iname){
  try{
      
      $data=array($orderID,$iname);
      $ownerH=$this->dbcon->prepare("delete from porderitemlist   where orderID=? and iname=?");  
      $ownerH->execute($data); 
      return $ownerH; 
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }

}

function updatepOrderItemRecv($orderID,$time,$iname){
  try{
      
      $data=array($time,$orderID,$iname);
      $ownerH=$this->dbcon->prepare("update porderitemlist set confrecv=?  where orderID=? and iname=?");  
      $ownerH->execute($data); 
      return $ownerH; 
  }
  catch(PDOException $xc){
    $xc->getMessage();
     return $ownerH;
  }

}

function getThisItemPorder($orderID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from porderitemlist where  orderID=:Id and iname=:nm"); 
    $ownerH->bindParam(":Id",$orderID);
    $ownerH->bindParam(":nm",$iname);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
/*function getAllPOrderStfQ(){
  try{
    $ownerH=$this->dbcon->prepare("select * from pordertQ order by recID desc");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}*/
function getThisPOrderStfQ($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from pordertQ where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getThisPOrder($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from pordert where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getOrderIDAg($agentid){
  try{
    $ownerH=$this->dbcon->prepare("select * from aordert where   agentid=:ag");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID); 
     $ownerH->bindParam(":ag",$agentid);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}



function getThisOrderAg($orderID,$agentid){
  try{
    $ownerH=$this->dbcon->prepare("select * from aordert where  orderID=:Id and agentid=:ag");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID); 
     $ownerH->bindParam(":ag",$agentid);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
function getThisNonOrder(){
  try{
    $ownerH=$this->dbcon->prepare("select * from nonpurchdebit");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}
function getThisNonOrderDbBID($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from nonpurchdebit where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getThisCancelled($orderID){
  try{
    $ownerH=$this->dbcon->prepare("delete from porderitemlist where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
 $cname="--Cancelled--";
 
$payableA=0; 
$balance=0;
$pstatus="--";
$receivedF="--";
$ownerH=$this->dbcon->prepare("update pordert set cname=?, payableA=?, balance=?,pstatus=?,receivedF=? where  orderID=?");
$ownerH->execute(array($cname,$payableA,$balance,$pstatus,$receivedF,$orderID));
return $ownerH;
}
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}


function getThisCusDBOrder($cname){
  try{
    $ownerH=$this->dbcon->prepare("select * from ordert where  cname like ?");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(array('%'.$cname.'%')); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}




function getThisOrder($orderID){
  try{
    $ownerH=$this->dbcon->prepare("select * from ordert where  orderID=:Id");
    //$ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$orderID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    //$xc->getMessage();
    return $ownerH;
  }

}

function getThisAgItemBID($agentid,$itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  aiteminfo where   iname=:nm and itemID=:Id and agentid=:aid");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);
    $ownerH->bindParam(":aid",$agentid);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisPurchBID($tim,$recID,$itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  purchaserecord where recID=:rD and timeAt=:tm and  iname=:nm and itemID=:Id");
    $ownerH->bindParam(":rD",$recID); 
    $ownerH->bindParam(":tm",$tim);
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisSelVinV($tim,$itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  sellsrecord where timeAt=:tm and  iname=:nm and itemID=:Id");  
    $ownerH->bindParam(":tm",$tim);
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}




function getThisSellBID($tim,$recID,$itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  sellsrecord where recID=:rD and timeAt=:tm and  iname=:nm and itemID=:Id");
    $ownerH->bindParam(":rD",$recID); 
    $ownerH->bindParam(":tm",$tim);
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisItmInvLstBID($tim,$itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  invoiceitemlist where timeAt=:tm and  iname=:nm and itemID=:Id");  
    $ownerH->bindParam(":tm",$tim);
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisItemBID($itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where   iname=:nm and itemID=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }
}

function getThisItemFED($itemID,$iname){
  try{
    $ownerH=$this->dbcon->prepare("select * from  iteminfo where   iname=:nm and itemID!=:Id");
    $ownerH->bindParam(":nm",$iname); 
    $ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

function genPOrderIDQ(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  pordertQ");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}
function genPOrderID(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  pordert");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 function genOrderID(){
  try{
    $ownerH=$this->dbcon->prepare("select * from  ordert");
    //$ownerH->bindParam(":nm",$iname); 
    //$ownerH->bindParam(":Id",$itemID);    
    $ownerH->execute(); 
      
    return $ownerH;

  }
  catch(PDOException $xc){
    $xc->getMessage();
  }

}

 
 // REGISTRATION FUNCTION ENDS
 

function etname($tname) {
   if($iname=="")
                 {

           return $iname="Test name required!..";
                 }
   
   else         {
                return;
                }
   

} 

function etPrice($tPrice) {
   if($tPrice=="")
                 {

           return $tPrice="Item quantity required!..";
                 }
   
   else         {
                return;
                }
   

} 

function vtPrice($tPrice) {
   
  
    if( $tPrice!=""){
      return  $tPrice;
    } 
     else{
      return false;
     }
}



function vIname($iname) {
   
  
    if( $iname!=""){
      return  $iname;
    } 
     else{
      return false;
     }
}  
function vcDr($cDr) {
   
  
    if( $cDr!=""){
      return  $cDr;
    } 
     else{
      return false;
     }
} 
function vcashP($cashP) {
   
  
    if( $cashP!=""){
      return  $cashP;
    } 
     else{
      return false;
     }
} 
function vnhifP($nhifP) {
   
  
    if( $nhifP!=""){
      return  $nhifP;
    } 
     else{
      return false;
     }
} 
function vIqty($iQty) {
   
  
    if( $iQty!=""){
      return  $iQty;
    } 
     else{
      return false;
     }
}

function eIname($iname) {
   if($iname=="")
                 {

           return $iname="Item name required!..";
                 }
   
   else         {
                return;
                }
   

}    

function eIqty($iQty) {
   if($iQty=="")
                 {

           return $iQty="Item quantity required!..";
                 }
   
   else         {
                return;
                }
   

} 

                              //VALIDATE FIRST NAME








function vFname($fname) {
   
  
    if(preg_match("/^[A-Za-z]+$/",$fname)  && $fname!=""){
      return  $fname;
    } 
     else{
      return false;
     }
}  


function eFname($fname) {
   if($fname=="")
                 {

    return $mname="First name required!..";
                 }
  
   else if(!preg_match("/^[A-Za-z]+$/",$fname))
                {
     
        return $fname= "Invalid name!";
              }
   else         {
                return;
              }
   

}                           


                                      //MIDDLE NAME VALIDATION

function vMname($mname) {
   
  
    if(preg_match("/^[A-Za-z]+$/",$mname)  && $mname!=""){
      return  $mname;
    } 
     else{
      return false;
     }
}  


function eMname($mname) {
   if($mname=="")
                 {

    return $mname="Middle name required!..";
                 }
  
   else if(!preg_match("/^[A-Za-z]+$/",$mname))
                {
     
        return $mname= "Invalid name!";
              }
   else         {
                return;
              }
   

}     





                                      //LAST NAME VALIDATION

function vLname($lname) {
   
  
    if(preg_match("/^[A-Za-z]+$/",$lname)  && $lname!=""){
      return  $lname;
    } 
     else{
      return false;
     }
}  


function eLname($lname) {
   if($lname=="")
                 {

    return $lname="Last name required!..";
                 }
  
   else if(!preg_match("/^[A-Za-z]+$/",$lname))
                {
     
        return $lname= "Invalid name!";
              }
   else         {
                return;
              }
   

}




                                      //STREET VALIDATION

function vAddress($address) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$address)  && $address!=""){
      return  $address;
    } 
     else{
      return false;
     }
}  


function eAddress($address) {
   if($address=="")
                 {

    return $address="Address required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$address))
                {
     
        return $addrss= "Invalid address  name!";
              }
   else         {
                return;
              }
   

}




                                      //EMAIL VALIDATION

function vEmail($email) {
   
  
    if(preg_match("/\b[(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)\b/",$email)  && $email!=""){
      return  $email;
    } 
     else{
      return false;
     }
}  


function eEmail($email) {
   if($email=="")
                 {

    return $email="Email required!..";
                 }
  
   else if(!preg_match("/\b[\(A-Za-z)][\w.]\w+@\w+\.(net|com|edu)\b/",$email))
                {
     
        return $email= "Invalid email address!";
              }
   else         {
                return;
              }
   

}               




                            //DATE OF BIRTH VALIDATION

function vDate($dob) {
   
  
    if($dob!=""){
      return  $dob;
    } 
     else{
      return false;
     }
}  



function eDate($dob) {
   if($dob=="")
                 {

    return $dob="Date of birth required!..";
                 }

    
   else         {
                return;
              }
   

}



   //OCCUPATION VALIDATION

function vOccupation($occupation) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$occupation)  && $occupation!=""){
      return  $occupation;
    } 
     else{
      return false;
     }
} 

function vCountry($country) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$country)  && $country!=""){
      return  $country;
    } 
     else{
      return false;
     }
}  


function eCountry($country) {
   if($country=="")
                 {

    return $region="Country required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$country))
                {
     
        return $district= "Invalid country name!";
              }
   else         {
                return;
              }
   

}

   //OCCUPATION VALIDATION

 



function eOccupation($occupation) {
   if($occupation=="")
                 {

    return $occupation="Occupation required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$occupation))
                {
     
        return $district= "Invalid occupation name!";
              }
   else         {
                return;
              }
   

}


function vCategory($category) {
   
  
    if(preg_match("/^[\sA-Za-z]+$/",$category)  && $category!=""){
      return  $category;
    } 
     else{
      return false;
     }
} 


function eCategory($category) {
   if($category=="")
                 {

    return $category="category required!..";
                 }
  
   else if(!preg_match("/^[\sA-Za-z]+$/",$category))
                {
     
        return $category= "Invalid category name!";
              }
   else         {
                return;
              }
   

}
//PASSWORD VALIDATION

function vPassword($password) {
   
  
    if(preg_match("/\w{8,25}/",$password)  && $password!=""){
      return  $password;
    } 
     else{
      return false;
     }
}  


function ePassword($password) {
   if($password=="")
                 {

    return $password="password required!..";
                 }

   
   else if(!preg_match("/\w{8,25}/",$password))
                {
     
        return $password= "Strong password with mixed numeric, upper and lower case required!";
              }
   else         {
                return;
              }
   

}

//PASSWORD VALIDATION

function vNpassword($npassword) {
   
  
    if(preg_match("/\w{8,25}/",$npassword)  && $npassword!=""){
      return  $npassword;
    } 
     else{
      return false;
     }
}  


function eNpassword($npassword) {
   if($npassword=="")
                 {

    return $npassword="password required!..";
                 }

   
   else if(!preg_match("/\w{8,25}/",$npassword))
                {
     
        return $npassword= "Strong password with mixed numeric, upper and lower case required!";
              }
   else         {
                return;
              }
   

}


 

function vNcpassword($npassword,$cpassword) {
   
  
    if($npassword== $cpassword){
      return  $npassword;
    } 
     else{
      return false;
     }
}  



function eNcpassword($npassword,$cpassword) {
   if($npassword!=$cpassword )
                 {

    return $npassword="Password mismatch!..";
                 }

    
   else         {
                return;
              }
   

}


                             //PASSWORD CONFIRMATION

function vCPassword($password,$cpassword) {
   
  
    if($password== $cpassword){
      return  $password;
    } 
     else{
      return false;
     }
}  



function eCPassword($password,$cpassword) {
   if($password!=$cpassword )
                 {

    return $password="Password mismatch!..";
                 }

    
   else         {
                return;
              }
   

}


//PHONE NUMBER VALIDATION

function vPatientID($patientID) {
   
  
    if(preg_match("/\d{1,12}/",$patientID)  && $patientID!=""){
      return  $patientID;
    } 
     else{
      return false;
     }
}  


function ePatientID($patientID) {
   if($patientID=="")
                 {

    return $patientID="Phone number required!..";
                 }

   
   else if(!preg_match("/\d{1,12}/",$patientID))
                {
     
        return $patientID= "Invalid patientID number!..";
              }
   else         {
                return;
              }
   

}
//PHONE NUMBER VALIDATION

function vPhoneno($phoneno) {
   
  
    if(preg_match("/\d{10,12}/",$phoneno)  && $phoneno!=""){
      return  $phoneno;
    } 
     else{
      return false;
     }
}  


function ePhoneno($phoneno) {
   if($phoneno=="")
                 {

    return $phoneno="Phone number required!..";
                 }

   
   else if(!preg_match("/\d{10,12}/",$phoneno))
                {
     
        return $phoneno= "Invalid phone number!..";
              }
   else         {
                return;
              }
   

}


                             //GENDER CONFIRMATION

function vGender($gender) {
   
  
    if($gender!=""){
      return  $gender;
    } 
     else{
      return false;
     }
}  



function eGender($gender) {

   if($gender=="")

                 {

    return $gender="Gender required!..";
                 }

    
   else         {
                return;
              }
   

}

/////////////////////////// 
function addEmployee($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate){
  
 try{
   $regdate=Date("Y-m-d");$time=Date("h:i:sa");

   //$data=array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate);
  
//fname mname lname email phone dob department  citizen address gender  pwd empDate 
  $Q=$this->dbcon->prepare("insert into users(pwd,department,email,fname,mname,lname,gender,occupation,phoneno,citizen,address,dob,dhired)values(?,?,?,?,?,?,?,?,?,?,?,?,?)");

  $Q->execute(array($password,$depart,$email,$fname,$mname,$lname,$gender,$occupation,$phoneno,$country,$address,$dob,$empDate)); 

   if($Q->rowCount()>0)
   {
     return $Q;  
    }
   else
   {   
   return $Q->ErrorInfo(); 
   }
    
}
catch(PDOException $ex){
  $ex->getMessage();
}
}

}
  

?>