<?php


class VendorMgmt
{
	public $vendor_id;  		    	   	 
	public $company_id;  	 
	public $vendor_orgname; 		  	  	 
	public $vendor_address; 		  	  	 
	public $district_id; 	 	  	 
	public $vendor_phone1; 	 	  	  	 
	public $vendor_phone2; 	  	  	  	 
	public $vendor_email; 	  	  	  	 
	public $vendor_website; 		  	  	 
	public $vendor_balance; 
	public $vendor_baltype;	  	  	  	 
	public $vendor_cpname1; 		  	  	 
	public $vendor_cpdesignation1; 	  	  	  	 
	public $vendor_cpmobile1; 	 	  	  	 
	public $vendor_cpemail1; 
	public $vendor_tinno;	  	  	 
	public $vendor_cstno; 	  	  	  	 
	public $vendor_servicetaxno; 	  	  	  	 
	public $vendor_panno; 
	public $vendor_remark; 		  	  	 
	public $createdby; 	 	  	  	 
	public $createdon; 
   
	
    function VendorMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->inquiry_count=0;
    }

   
	
	/**
     * 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->inquiry_count=0;
		
			$qry = "SELECT lv.*,ld.designation_name
		     from
				lms_vendor lv,
				lms_designation ld			  
			 WHERE 
				lv.company_id   = '".$_SESSION["cCompany_id"]."' 
				AND ld.designation_id = lv.vendor_cpdesignation1"; 
				   					   				
		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";
        }
		
		//print $qry;
		$out=dbQuery($qry);
		
        if (dbRows($out)>0) {
            $this->inquiry_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
		
	 function getCountRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->inquiry_count=0;
		
       	$qry = "SELECT COUNT(*) AS Count
				FROM lms_vendor WHERE 1=1 ";
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->inquiry_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->inquiry_count;
    }	
		
	

    /**
     * This is a function for adding new record for Employee.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
		global $SQLDateFormat;
		
		$Qry1 = "";
		
			$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";	
			$Qry1 .= "vendor_orgname='"	  .Escape($this->vendor_orgname)."',"; 	
			$Qry1 .= "vendor_address='" .replaceHtmlEditor(Escape($this->vendor_address))."',";	 	
			$Qry1 .= "district_id='"	  .Escape($this->district_id)."',"; 	
			$Qry1 .= "vendor_phone1='"	  .Escape($this->vendor_phone1)."',"; 	
			$Qry1 .= "vendor_phone2='"	  .Escape($this->vendor_phone2)."',"; 	
			$Qry1 .= "vendor_email='"	  .Escape($this->vendor_email)."',"; 	
			$Qry1 .= "vendor_website='"	  .Escape($this->vendor_website)."',"; 	
			$Qry1 .= "vendor_balance='"	  .Escape($this->vendor_balance)."',"; 
			$Qry1 .= "vendor_baltype='"	  .Escape($this->vendor_baltype)."',"; 
			$Qry1 .= "vendor_cpname1='"	  .Escape($this->vendor_cpname1)."',"; 	
			$Qry1 .= "vendor_cpdesignation1='"	  .Escape($this->vendor_cpdesignation1)."',"; 	
			$Qry1 .= "vendor_cpmobile1='"	  .Escape($this->vendor_cpmobile1)."',"; 	
			$Qry1 .= "vendor_cpemail1='"	  .Escape($this->vendor_cpemail1)."',"; 	
			$Qry1 .= "vendor_tinno='"	  .Escape($this->vendor_tinno)."',"; 	
			$Qry1 .= "vendor_cstno='"	  .Escape($this->vendor_cstno)."',"; 	
			$Qry1 .= "vendor_servicetaxno='"	  .Escape($this->vendor_servicetaxno)."',"; 	
			$Qry1 .= "vendor_panno='"	  .Escape($this->vendor_panno)."',"; 	
			$Qry1 .= "vendor_remark='" .replaceHtmlEditor(Escape($this->vendor_remark))."',";	 	
			$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_vendor set ". $Qry1 ." ";
		//	echo $qry;		
			dbQuery($qry);
			$this->vendor_id=dbInsertedId();
		}
	}

    /**
     * This is a function for editing a Employee 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 .= "vendor_orgname='"	  .Escape($this->vendor_orgname)."',"; 	
			$Qry1 .= "vendor_address='" .replaceHtmlEditor(Escape($this->vendor_address))."',";	 	
			$Qry1 .= "district_id='"	  .Escape($this->district_id)."',"; 	
			$Qry1 .= "vendor_phone1='"	  .Escape($this->vendor_phone1)."',"; 	
			$Qry1 .= "vendor_phone2='"	  .Escape($this->vendor_phone2)."',"; 	
			$Qry1 .= "vendor_email='"	  .Escape($this->vendor_email)."',"; 	
			$Qry1 .= "vendor_website='"	  .Escape($this->vendor_website)."',"; 	
			$Qry1 .= "vendor_balance='"	  .Escape($this->vendor_balance)."',"; 	
			$Qry1 .= "vendor_baltype='"	  .Escape($this->vendor_baltype)."',"; 
			$Qry1 .= "vendor_cpname1='"	  .Escape($this->vendor_cpname1)."',"; 	
			$Qry1 .= "vendor_cpdesignation1='"	  .Escape($this->vendor_cpdesignation1)."',"; 	
			$Qry1 .= "vendor_cpmobile1='"	  .Escape($this->vendor_cpmobile1)."',"; 	
			$Qry1 .= "vendor_cpemail1='"	  .Escape($this->vendor_cpemail1)."',"; 	
			$Qry1 .= "vendor_tinno='"	  .Escape($this->vendor_tinno)."',"; 	
			$Qry1 .= "vendor_cstno='"	  .Escape($this->vendor_cstno)."',"; 	
			$Qry1 .= "vendor_servicetaxno='"	  .Escape($this->vendor_servicetaxno)."',"; 	
			$Qry1 .= "vendor_panno='"	  .Escape($this->vendor_panno)."',"; 	
			$Qry1 .= "vendor_remark='" .replaceHtmlEditor(Escape($this->vendor_remark))."',";	 	
			$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_vendor set " . $Qry1 . " where vendor_id=".$this->vendor_id. " and company_id = '".$_SESSION['cCompany_id']."' ";
                dbQuery($qry);
            }
	}
	
	/**
     * This is a function for deleting the Employee record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {		
		$qry = "delete from  lms_vendor 
             	where vendor_id in (".$this->deleteId.") 
				and company_id='".$_SESSION["cCompany_id"]."'";
        dbQuery($qry);
   	}
	
	
}
?>