<?php
/**
 * This is a class file used for account operations.
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */

/**
 * This is a class named AccountMgmt.
 *
 * @category School Management System
 * @package  School Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class TransactionDetailMgmt
{
   
   /**
     * @var public $trans_id This is the trans_id feteched from the database
	.
     */
	 
    public $trandetail_id;
   
    /**
     * @var public $trans_id This is the trans_id feteched from the database
	.
     */
	 
    public $trans_id;
	
	 /**
     * @var public $sms_mobileno This is the account GroupId feteched from the database(ams_accountmaster).
     */
    public $sms_mobileno;
		
	/**
     * @var public $sms_submittime This is the account type.
     */
	 
	 public $sms_apimessageid;
	 
	 
    public $sms_submittime;
			
	/**
     * @var public $sms_senttime This is the account type.
     */
    public $sms_senttime;

		
	/**
     * @var public $sms_deliverytime This is the account type.
     */
    public $sms_deliverytime;

	/**
     * @var public $sms_credit This is the account type.
     */
    public $sms_credit;
	
	/**
     * @var public $sms_status This is the account type.
     */
    public $sms_status;
	
	/**
     * @var public $sms_reason This is the account type.
     */
    public $sms_reason;
	/**
     * @var public $bullet This is the account bullet.
     */
    public $bullet;
	

    /**
     * Constructor to inialize trans_count to zero
     *
     */
    function TransactionDetailMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->trans_count=0;
    }
		
	/**
     * This is a function for getting the total no of records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Total Records Found
     */
    function getCountRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	
		$this->trans_count=0;
		
        $qry = "SELECT Count(*) AS Count FROM transactiondetail where 1=1 ";
		
		if ($condition != ""){
            $qry.= $condition;
        }
		
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->trans_count=$Count;            
			dbResult($out);
        }
		return $this->trans_count;
    }
	
	/**
     * This is a function for getting the all records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Mix Result Set
     */
    function getAllRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->trans_count=0;

        $qry = "SELECT
					trandetail_id, 
					trans_id,
					sms_mobileno,
					sms_submittime,
					sms_senttime,
					sms_deliverytime,
					sms_credit,
					sms_status,
					sms_reason,
					sms_details
				FROM 
					transactiondetail where 1=1 ";
		
		if ($condition != "" ) {
           $qry.= $condition;
        }
		
	
		if ($order_field !="" && $order_type !="") {
			   $qry.= " order by $order_field $order_type";
        }

        if (intval($limit) > 0 && intval($start) >=0) {
            $qry.= " Limit $start , $limit";
        }
		
		$out=dbQuery($qry);
		
        if (dbRows($out)>0) {
            $this->trans_count=dbRows($out);
            return $out;
        }
		
        return $out;							
		
    }
		
	/**
     * This is a function for adding new record for account.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
		global $SQLDateFormat;

		$Qry1 = "";
		$Qry1 .= "trans_id='"	.Escape($this->trans_id)."',";
		$Qry1 .= "sms_mobileno='"	.Escape($this->sms_mobileno)."',";
		$Qry1 .= "sms_apimessageid='"	.Escape($this->sms_apimessageid)."',";
		$Qry1 .= "sms_credit='"		.Escape($this->sms_credit)."',";
		$Qry1 .= "sms_reason='"		.Escape($this->sms_reason)."',";		
		$Qry1 .= "sms_details='"	.Escape($this->sms_details)."',";
                $Qry1 .= "sms_status='"         .Escape($this->sms_status)."',";
                $Qry1 .= "sms_submittime ='"	.Escape(date('Y-m-d h:i:s'))."',";
                $Qry1 .= "sms_senttime ='"	.Escape(date('Y-m-d h:i:s'))."',";
                $Qry1 .= "sms_deliverytime ='"	.Escape(date('Y-m-d h:i:s'))."',";                		
                
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
			$qry = "insert into transactiondetail set " . $Qry1 . " ";
			dbQuery($qry);
			$this->trandetail_id=dbInsertedId();
		}

	}
	
	/**
     * This is a function for editing a Account record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {

		$Qry1 .= "trans_id='"	.Escape($this->trans_id)."',";
		$Qry1 .= "sms_mobileno='"	.Escape($this->sms_mobileno)."',";
		$Qry1 .= "sms_apimessageid='"	.Escape($this->sms_apimessageid)."',";
		$Qry1 .= "sms_credit='"		.Escape($this->sms_credit)."',";
		$Qry1 .= "sms_reason='"		.Escape($this->sms_reason)."',";		
		$Qry1 .= "sms_details='"	.Escape($this->sms_details)."',";
                $Qry1 .= "sms_status='"         .Escape($this->sms_status)."',";
                $Qry1 .= "sms_submittime ='"	.Escape(date('Y-m-d h:i:s'))."',";
                $Qry1 .= "sms_senttime ='"	.Escape(date('Y-m-d h:i:s'))."',";
                $Qry1 .= "sms_deliverytime ='"	.Escape(date('Y-m-d h:i:s'))."',";       
						
        if ($Qry1 != "") {
        	$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
            $qry = "update transactiondetail set " . $Qry1 . " 
			where  trandetail_id='".$this->trandetail_id."' ";
           
		    dbQuery($qry);
      	}
	}

	/**
     * This is a function for deleting the Account record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {
	    $qry = "delete from  transactiondetail 
             	where  trandetail_id=".$this->trandetail_id." ";
		dbQuery($qry);
	}
	
	function getdistincmesaageid()
    {
		
        $qry = "SELECT distinct trans_id,sms_apimessageid FROM transactiondetail where sms_status=''";
		
		if ($condition != "" ) {
           $qry.= $condition;
        }
		
	
		if ($order_field !="" && $order_type !="") {
			   $qry.= " order by $order_field $order_type";
        }

        if (intval($limit) > 0 && intval($start) >=0) {
            $qry.= " Limit $start , $limit";
        }
		$out=dbQuery($qry);
		
        if (dbRows($out)>0) {
            $this->trans_count=dbRows($out);
            return $out;
        }
		
        return $out;							
		
    }

}
?>