<?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 VoucherDetailMgmt
{
    /**
     * @var public $company_id This is the company_id.
     */
    public $company_id;
	
	/**
       * @var public $company_id This is the voucher GroupId feteched from the database(ams_vouchermaster).
     */
    public $voucher_id;
	
	/**
     * @var public $voucher_no This is the voucher_no .
     */
    public $voucherdetail_id;
	
	/**
     * @var public $receipt_no This is the voucher receipt_no.
     */
    public $account_id;
	
	/**
     * @var public $voucher_type This is the voucher_type.
     */
    public $voucher_creditamount;
	
	/**
     * @var public $voucher_check This is the voucher_check.
     */
    public $voucher_debitamount;
	
	/**
     * @var public $voucher_date This is the voucher_date.
     */
    public $login_id;
	
	/**
     * @var public $voucher_totalamount This is the voucher_totalamount.
     */
    public $createdon;
	
	/**
     * @var public $bullet This is the account bullet.
     */
    public $bullet;
	
	 /**
     * @var public $deleteId List of Id's to be deleted.
     */
    public $deletevoucher_Id;
	
	/**
     * @var public $account_msg This is the account message.
     */
    public $voucherdetail_msg;

    /**
     * Constructor to inialize voucher_count to zero
     *
     */
    function VoucherDetailMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->voucher_count=0;
    }

    /**
     * This function is used to get a particular record.
     *
     * @param integer $account_groupid This is the database account_groupid.
     *
     * @return array
     */
    function getRecordById($voucherdetail_id)
    {
        $qry = "select * from ams_voucherdetail where 1=1 ";

        if ($voucher_id!="") {
            $qry.=" and voucherdetail_id=$voucherdetail_id ";
        }

        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->voucherdetail_count=1;

            $row=dbArray($out);
            extract($row);
			
            $this->company_id=($company_id);
	    	$this->voucher_id=($account_id);
			$this->account_id=($account_id);
			$this->voucher_creditamount=($voucher_creditamount);
			$this->voucher_debitamount=($voucher_debitamount);
			$this->login_id = ($login_id);
			$this->createdon = ($createdon);
			
			dbFreeResult($out);
        }
    }
	
	/**
     * 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->voucherdetail_count=0;
		
        $qry = "SELECT Count(*) AS Count FROM ams_voucherdetail where company_id= '".$_SESSION["cCompany_id"]."' ";
		
		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) {
			$row=dbArray($out);
            extract($row);		
            $this->voucherdetail_count=$Count;            
			dbFreeResult($out);
        }
		return $this->voucherdetail_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->voucher_count=0;
		
        $qry = "SELECT 
					voudet.*,
					accmas.account_name
				FROM 
					ams_voucherdetail voudet,
					ams_vouchermaster voumas,
					ams_accountmaster accmas
				WHERE 
					voudet.account_id = accmas.account_id AND
					voudet.voucher_id = voumas.voucher_id ";
		
		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->voucherdetail_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()
    {
		$Qry1 = "";
	
		$Qry1 .= "company_id='"	                 .Escape($_SESSION['cCompany_id'])."',";		
	   	$Qry1 .= "voucher_id='"			         .Escape($this->voucher_id)."',";
		$Qry1 .= "account_id ='"			         .Escape($this->account_id)."',";				
		$Qry1 .= "voucher_creditamount='"	     .Escape($this->voucher_creditamount)."',";			
		$Qry1 .= "voucher_debitamount='"		 .Escape($this->voucher_debitamount)."',";			
    	$Qry1 .= "login_id='"					 .Escape($_SESSION['cUserId'])."',";			
		$Qry1 .= "createdon='"					 .Escape(date('Y-m-d h:i:s'))."',";	
		$Qry1 .= "blnBackup = '0',";
			
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
		    $qry = "insert into ams_voucherdetail set " . $Qry1 . " ";
			dbQuery($qry);
			$this->voucherdetail_id=dbInsertedId();
		}

		$this->voucherdetail_msg = "<strong>".$this->bullet." Voucherdetail Inserted Successfully.</strong>";
	}
	
	/**
     * This is a function for editing a Account record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {
        $Qry1 = "";
        //$Qry1 .= "company_id='"	                 .Escape($_SESSION['cCompany_id'])."',";		
		//$Qry1 .= "voucher_id='"			         .Escape($this->voucher_id)."',";
		//$Qry1 .= "voucherdetail_id='"	         .Escape($this->voucherdetail_id)."',";			
		$Qry1 .= "account_id='"			         .Escape($this->account_id)."',";			
		$Qry1 .= "voucher_creditamount='"	     .Escape($this->voucher_creditamount)."',";			
		$Qry1 .= "voucher_debitamount='"		 .Escape($this->voucher_debitamount)."',";			
    	//$Qry1 .= "login_id='"					 .Escape($_SESSION['cUserId'])."',";			
		//$Qry1 .= "createdon='"					 .Escape(date('Y-m-d h:i:s'))."',";		
		$Qry1 .= "blnBackup = '0',";				
        if ($Qry1 != "") {
        	$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
            $qry = "update ams_voucherdetail set " . $Qry1 . " 
			where voucher_id = ".$this->voucher_id." and company_id='".$_SESSION["cCompany_id"]."'";
            dbQuery($qry);
      	}
		$this->voucher_msg= "<strong>".$this->bullet." Voucherdetail updated successfully.</strong>";
	}
	
	/**
     * This is a function for deleting the Account record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
	 function getvoucherDates($limit=0,$start=0,$condition="",$order_field="",$order_type="")
	{
	  $qry = "SELECT GROUP_CONCAT( voucher_id ) AS voucher_id
	           FROM ams_voucherdetail 
			   WHERE company_id ='".$_SESSION['cCompany_id']."'";
	   
	   if($condition != ""){
	   		$qry .= $condition ;
	   }
	   
	   $qry .= "GROUP BY voucher_date" ;
	
	   $out=dbQuery($qry);

        if (dbRows($out)>0) {
            return $out;
		}
		return 0 ;
	} 

	function delete()
    {
	    $qry = "delete from ams_voucherdetail 
             	where voucher_id in (".$this->voucher_id.") 
				and company_id='".$_SESSION["cCompany_id"]."'";
		dbQuery($qry);
	}
	

}
?>