<?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 CustomerSupportMgmt
{	
	/**
     * @var public $company_id This is the company id.
     */
	public $company_id;
    /**
     * @var public $support_id This is the Employee Id feteched from the database(product_master).
     */
    public $support_id;
	
	/**
     * @var public $customer_id This is the Product name.
     */
	public $customer_id;

				  
	/**
     * @var public $support_date This is the Product Price.
     */
	public $support_date;
	/**
     * @var public $support_stime This is the product vat.
     */
	public $support_stime;
	/**
     * @var public $support_etime This is the product vat.
     */
	public $support_etime;
	/**
     * @var public $support_charge This is the Product service tax.
     */
	public $support_charge;

	/**
     * @var public $support_close This is the Product Description.
     */
	public $support_close;
	/**
     * @var public $nextsupport_date This is the Product Active.
     */
	public $nextsupport_date;

	/**
     * @var public $employee_email This is the Employee email id.
     */
	public $nextsupport_time;
	
	public $support_work;
	
	public $support_pending;
		
	 public $createdby;
	
	/**
     * @var public $createdon This is the Product createdon.
     */
	public $createdon;

	public $courier_no;

    public $invoice_date;

    public $invoice_no;
	
	
	/**
     * Constructor to inialize product_count to zero
     *
     */
    function CustomerSupportMgmt()
    {
        $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_customersupport 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 getAllRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {

		$this->product_count=0;
				
		$qry = "SELECT * from lms_customersupport,csc_customer 
				WHERE lms_customersupport.customer_id=csc_customer.customer_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";
        }
		// echo $qry;
		// exit;
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->product_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
	
	function cscordercount($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		$qry = "SELECT Count(*) AS Count from lms_customersupport,csc_customer 
				WHERE lms_customersupport.customer_id=csc_customer.customer_id ";
	
		
		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;	
    }
	
	
	    function getAllRecordscustomer($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {

		$this->product_count=0;
				
		$qry = "SELECT * from csc_customer 
				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='".$_SESSION['cCompany_id']."',";
		$Qry1 .= "customer_id='"	  .Escape($this->customer_id)."',";
		$Qry1 .= "support_date=    STR_TO_DATE('".Escape($this->support_date)."','$SQLDateFormat'),";			
		$Qry1 .= "support_stime='"	  .Escape($this->support_stime)."',";
		$Qry1 .= "support_etime='"	  .Escape($this->support_etime)."',";
		$Qry1 .= "support_distance='"	  .Escape($this->support_distance)."',";	
		$Qry1 .= "support_charge='"	  .Escape($this->support_charge)."',";	
		$Qry1 .= "support_close='"  .Escape($this->support_close)."',";	
		$Qry1 .= "nextsupport_date=    STR_TO_DATE('".Escape($this->nextsupport_date)."','$SQLDateFormat'),";			
	    $Qry1 .= "nextsupport_time='"  .Escape($this->nextsupport_time)."',";
		$Qry1 .= "support_work='" .replaceHtmlEditor(Escape($this->support_work))."',";
		$Qry1 .= "support_pending='"  .replaceHtmlEditor(Escape($this->support_pending))."',";
		$Qry1 .= "courier_no='"  .replaceHtmlEditor(Escape($this->courier_no))."',";
		$Qry1 .= "invoice_no='"	.Escape($this->invoice_no)."',";
		$Qry1 .= "invoice_date=    STR_TO_DATE('".Escape($this->invoice_date)."','$SQLDateFormat'),";	
		$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_customersupport set " . $Qry1 . " ";

		
			dbQuery($qry);
			$this->support_id=dbInsertedId();


			 $qry_status_update="update csc_customer set invoice_status='Printed' where customer_id=$this->customer_id";
			//echo $qry_status_update;
			dbQuery($qry_status_update);

			
				
				
			
			
		}
	}

    /**
     * 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='".$_SESSION['cCompany_id']."',";
		$Qry1 .= "customer_id='"	  .Escape($this->customer_id)."',";
		$Qry1 .= "support_date=    STR_TO_DATE('".Escape($this->support_date)."','$SQLDateFormat'),";			
		$Qry1 .= "support_stime='"	  .Escape($this->support_stime)."',";
		$Qry1 .= "support_etime='"	  .Escape($this->support_etime)."',";
		$Qry1 .= "support_charge='"	  .Escape($this->support_charge)."',";	
		$Qry1 .= "support_close='"  .Escape($this->support_close)."',";	
		$Qry1 .= "nextsupport_date=    STR_TO_DATE('".Escape($this->nextsupport_date)."','$SQLDateFormat'),";			
	    $Qry1 .= "nextsupport_time='"  .Escape($this->nextsupport_time)."',";
		$Qry1 .= "support_work='" .replaceHtmlEditor(Escape($this->support_work))."',";
		$Qry1 .= "support_pending='"  .replaceHtmlEditor(Escape($this->support_pending))."',";
		$Qry1 .= "courier_no='"  .replaceHtmlEditor(Escape($this->courier_no))."',";
		//  $Qry1 .= "invoice_no='"  .replaceHtmlEditor(Escape($this->invoice_no))."',";
		$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_customersupport set " . $Qry1 . " where support_id=".$this->support_id;
                dbQuery($qry);
            }
	}
	 function delete()
    {		
			 $qry = "delete from  lms_customersupport 
             	where support_id in (".$this->deleteId.") ";
        dbQuery($qry);
   	}
	
		function getInvoiceNo()
    	{	
			$qry = "";
			 $qry = " SELECT MAX(invoice_no) + 1  as invoice_no  FROM lms_customersupport where company_id= '".$_SESSION["cCompany_id"]."' and `invoice_date` >= '2023-04-01'";
					
			 if($this->support_id != "" && $this->support_id != "0")
			 {
				 $qry = " SELECT invoice_no  FROM lms_customersupport where support_id = ".$this->support_id." and company_id= '".$_SESSION["cCompany_id"]."' and `invoice_date` >= '2023-04-01'";

			 }
			
			$out=dbQuery($qry);
			
			if (dbRows($out)>0){
            	$resut=dbArray($out);
				if($resut["invoice_no"]=="")
				{
					return "1";
				}
				else{
				
					return $resut["invoice_no"];							
				}
        	}
			return $out;
		}
	
}
?>