<?php
/**
 * This is a class file used for Employee 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 EmployeeMgmt.
 *
 * @category Employee Management System
 * @package  Employee Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class ProductMgmt
{	
	/**
     * @var public $company_id This is the company id.
     */
	public $company_id;
    /**
     * @var public $product_id This is the Employee Id feteched from the database(product_master).
     */
    public $product_id;
	
	/**
     * @var public $product_name This is the Product name.
     */
	public $product_name;
	
	
	public $product_category ;	
	public $product_type; 	
	public $product_warranty; 	
	public $product_warrantytype; 		
	public $product_reorder; 	
	
	public $product_measurement;
	/**
     * @var public $product_price This is the Product Price.
     */
	/**
     * @var public $product_description This is the Product Description.
     */
	public $product_description;
	/**
     * @var public $product_active This is the Product Active.
     */
	public $product_active;
	public $product_opnstock;
	
	public $product_photo;


	/**
     * @var public $employee_email This is the Employee email id.
     */
	 public $createdby;
	
	/**
     * @var public $createdon This is the Product createdon.
     */
	public $createdon;
	
	/**
     * Constructor to inialize product_count to zero
     *
     */
    function ProductMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->employee_count=0;
    }

    function getCountRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->employee_count=0;
		
       	$qry = "SELECT COUNT(*) AS Count
				FROM lms_productmaster WHERE 1=1 ";
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->employee_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->employee_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 getDistinctMeasurement()
    {
		$this->member_count=0;
		
		$qry = "SELECT Distinct product_measurement FROM lms_productmaster  where company_id= '".$_SESSION["cCompany_id"]."' "; 
		
		$out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->member_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
	
	/**
     * 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->product_count=0;
				
		$qry = "SELECT * FROM lms_productmaster 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->product_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
		
    /**
     * This is a function for adding new record for Product.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
		global $SQLDateFormat;
		
		$Qry1 = "";
		$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";	
		$Qry1 .= "product_name='"	  .Escape($this->product_name)."',";
		$Qry1 .= "product_category='"	      .Escape($this->product_category)."',";	
		$Qry1 .= "product_type='"	  .Escape($this->product_type)."',";
		$Qry1 .= "product_warranty='" .Escape($this->product_warranty)."',";
		$Qry1 .= "product_warrantytype='"	  .Escape($this->product_warrantytype)."',";
		$Qry1 .= "product_measurement='" .Escape($this->product_measurement)."',";
		$Qry1 .= "product_reorder='"	  .Escape($this->product_reorder)."',";
		$Qry1 .= "product_description='" .replaceHtmlEditor(Escape($this->product_description))."',";	
		$Qry1 .= "product_active='"  .Escape($this->product_active)."',";	
		$Qry1 .= "product_opnstock='"  .Escape($this->product_opnstock)."',";	
		$Qry1 .= "createdby='"	      .Escape($_SESSION['cUserId'])."',";
		$Qry1 .= "createdon='"	      .Escape(date('Y-m-d h:i:s'))."',";
		
	if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
			$qry = "insert into lms_productmaster set " . $Qry1 . " ";
					
			dbQuery($qry);
			$this->product_id=dbInsertedId();
		}
	}

    /**
     * This is a function for editing a Product record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {
			global $SQLDateFormat;
			
			$Qry1 = "";
			
			$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";	
			$Qry1 .= "product_name='"	  .Escape($this->product_name)."',";
			$Qry1 .= "product_category='"	      .Escape($this->product_category)."',";	
			$Qry1 .= "product_type='"	  .Escape($this->product_type)."',";
			$Qry1 .= "product_warranty='" .Escape($this->product_warranty)."',";
			$Qry1 .= "product_warrantytype='"	  .Escape($this->product_warrantytype)."',";
			$Qry1 .= "product_measurement='" .Escape($this->product_measurement)."',";
			$Qry1 .= "product_reorder='"	  .Escape($this->product_reorder)."',";
			$Qry1 .= "product_description='" .replaceHtmlEditor(Escape($this->product_description))."',";	
			$Qry1 .= "product_active='"  .Escape($this->product_active)."',";	
			$Qry1 .= "product_opnstock='"  .Escape($this->product_opnstock)."',";	
			$Qry1 .= "createdby='"	      .Escape($_SESSION['cUserId'])."',";			
			$Qry1 .= "createdon='"	      .Escape(date('Y-m-d h:i:s'))."',";
				
            if ($Qry1 != "") {
                $Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
           		$qry = "update lms_productmaster set " . $Qry1 . " where product_id=".$this->product_id;
                dbQuery($qry);
            }
	}
	 function delete()
    {		
			 $qry = "delete from  lms_productmaster 
             	where product_id in (".$this->deleteId.") ";
        dbQuery($qry);
   	}
	
	  function updatePhoto()
    {		
		$qry = "update lms_productmaster 
				set product_photo = '".$this->product_photo."'
             	where product_id =   ".$this->product_id." and company_id='".$_SESSION["cCompany_id"]."'";
        dbQuery($qry);
   	}
}
?>