<?php 
 class    lms_customerbillMgmt
{ 
public  $invoice_id;
public  $invoice_no;
public  $billdate;
public  $salesby;
public  $customer_name;
public  $address;
public  $product_name;
public  $qty;
public  $rate;
public  $vat;
public  $discount;
public  $tamount;
public $company_id;
public $createdon;
public $remark;

 function getAllRecordsquotation($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
$qry="SELECT * FROM lms_customerquotation 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){
return $out;
}
return $out;
}

function getAllRecordsinvoice($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
$qry="SELECT * FROM lms_operatorinvoice 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){
return $out;
}
return $out;
}



 function getAllRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
$qry="SELECT * FROM lms_customerbill 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){
return $out;
}
return $out;
}
function getCustomername($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
$qry="SELECT distinct customer_name FROM lms_customerbill 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){
return $out;
}
return $out;
}

function getCustomername1($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
$qry="SELECT distinct customer_name FROM lms_customerquotation 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){
return $out;
}
return $out;
}

function getProductname($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
$qry="SELECT distinct product_name FROM lms_operatorinvoice 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){
return $out;
}
return $out;
}

function addquotation(){
	$SQLDateFormat = '%d/%m/%Y';
$Qry1 = "";
$Qry1 .= "invoice_id   ='"  .Escape($this->invoice_id)."',";
$Qry1 .= "invoice_no   ='"  .Escape($this->invoice_no)."',";
$Qry1 .= "billdate   = STR_TO_DATE('".Escape($this->billdate)."','$SQLDateFormat'),";	
$Qry1 .= "salesby   ='"  .Escape($this->salesby)."',";
$Qry1 .= "customer_name   ='"  .Escape($this->customer_name)."',";
$Qry1 .= "address   ='"  .Escape($this->address)."',";
$Qry1 .= "product_name   ='"  .Escape($this->product_name)."',";
$Qry1 .= "qty   ='"  .Escape($this->qty)."',";
$Qry1 .= "rate   ='"  .Escape($this->rate)."',";
$Qry1 .= "vat   ='"  .Escape($this->vat)."',";
$Qry1 .= "discount   ='"  .Escape($this->discount)."',";
$Qry1 .= "tamount   ='"  .Escape($this->tamount)."',";
$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";
$Qry1 .= "createdon  = STR_TO_DATE('".date("d/m/Y")."','$SQLDateFormat'),";
$Qry1 .= "remark   ='"  .Escape($this->remark)."',";
$Qry1 .= "quotation_to   ='"  .Escape($this->quotation_to)."',";

if($Qry1 != ""){
$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
$qry = "insert into lms_customerquotation set " . $Qry1 . " ";
dbQuery($qry);
$this->invoice_id=dbInsertedId();
} 
}

function addoperatorinvoice(){
	$SQLDateFormat = '%d/%m/%Y';
$Qry1 = "";
$Qry1 .= "invoice_id   ='"  .Escape($this->invoice_id)."',";
$Qry1 .= "invoice_no   ='"  .Escape($this->invoice_no)."',";
$Qry1 .= "billdate   = STR_TO_DATE('".Escape($this->billdate)."','$SQLDateFormat'),";	
$Qry1 .= "operator_id   ='"  .Escape($this->operator_id)."',";
$Qry1 .= "product_name   ='"  .Escape($this->product_name)."',";
$Qry1 .= "qty   ='"  .Escape($this->qty)."',";
$Qry1 .= "rate   ='"  .Escape($this->rate)."',";
$Qry1 .= "vat   ='"  .Escape($this->vat)."',";
$Qry1 .= "discount   ='"  .Escape($this->discount)."',";
$Qry1 .= "tamount   ='"  .Escape($this->tamount)."',";
$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";
$Qry1 .= "createdon  = STR_TO_DATE('".date("d/m/Y")."','$SQLDateFormat'),";


if($Qry1 != ""){
$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
$qry = "insert into lms_operatorinvoice set " . $Qry1 . " ";
dbQuery($qry);
$this->invoice_id=dbInsertedId();
} 
}




function editquotation(){
	$SQLDateFormat = '%d/%m/%Y';
 $Qry1 = "";
$Qry1 .= "invoice_id   ='"  .Escape($this->invoice_id)."',";
$Qry1 .= "invoice_no   ='"  .Escape($this->invoice_no)."',";
$Qry1 .= "billdate   = STR_TO_DATE('".Escape($this->billdate)."','$SQLDateFormat'),";	
$Qry1 .= "salesby   ='"  .Escape($this->salesby)."',";
$Qry1 .= "customer_name   ='"  .Escape($this->customer_name)."',";
$Qry1 .= "address   ='"  .Escape($this->address)."',";
$Qry1 .= "product_name   ='"  .Escape($this->product_name)."',";
$Qry1 .= "qty   ='"  .Escape($this->qty)."',";
$Qry1 .= "rate   ='"  .Escape($this->rate)."',";
$Qry1 .= "vat   ='"  .Escape($this->vat)."',";
$Qry1 .= "discount   ='"  .Escape($this->discount)."',";
$Qry1 .= "tamount   ='"  .Escape($this->tamount)."',";
$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";
$Qry1 .= "createdon   = STR_TO_DATE('".date("d/m/Y")."','$SQLDateFormat'),";
$Qry1 .= "remark   ='"  .Escape($this->remark)."',";
$Qry1 .= "quotation_to   ='"  .Escape($this->quotation_to)."',";


if($Qry1 != ""){ 
$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
 $qry = "update lms_customerquotation set " . $Qry1 . " where  invoice_id=".$this->invoice_id;
dbQuery($qry);
}
 } 


function editoperatorinvoice(){
	$SQLDateFormat = '%d/%m/%Y';
 $Qry1 = "";
$Qry1 .= "invoice_id   ='"  .Escape($this->invoice_id)."',";
$Qry1 .= "invoice_no   ='"  .Escape($this->invoice_no)."',";
$Qry1 .= "billdate   = STR_TO_DATE('".Escape($this->billdate)."','$SQLDateFormat'),";	
$Qry1 .= "operator_id   ='"  .Escape($this->operator_id)."',";
$Qry1 .= "product_name   ='"  .Escape($this->product_name)."',";
$Qry1 .= "qty   ='"  .Escape($this->qty)."',";
$Qry1 .= "rate   ='"  .Escape($this->rate)."',";
$Qry1 .= "vat   ='"  .Escape($this->vat)."',";
$Qry1 .= "discount   ='"  .Escape($this->discount)."',";
$Qry1 .= "tamount   ='"  .Escape($this->tamount)."',";
$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";
$Qry1 .= "createdon  = STR_TO_DATE('".date("d/m/Y")."','$SQLDateFormat'),";


if($Qry1 != ""){ 
$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
 $qry = "update lms_operatorinvoice set " . $Qry1 . " where  invoice_id=".$this->invoice_id;
dbQuery($qry);
}
 }



function deletequotation() 
{ 
	$qry = "delete from lms_customerquotation where invoice_no = ".$this->invoice_no;
	dbQuery($qry);
} 


function deleteinvoice() 
{ 
	$qry = "delete from lms_operatorinvoice where invoice_no = '$this->invoice_no'";
	//echo $qry; exit;
	dbQuery($qry);
}




function add(){
	$SQLDateFormat = '%d/%m/%Y';
$Qry1 = "";
$Qry1 .= "invoice_id   ='"  .Escape($this->invoice_id)."',";
$Qry1 .= "invoice_no   ='"  .Escape($this->invoice_no)."',";
$Qry1 .= "billdate   = STR_TO_DATE('".Escape($this->billdate)."','$SQLDateFormat'),";	
$Qry1 .= "salesby   ='"  .Escape($this->salesby)."',";
$Qry1 .= "customer_name   ='"  .Escape($this->customer_name)."',";
$Qry1 .= "address   ='"  .Escape($this->address)."',";
$Qry1 .= "product_name   ='"  .Escape($this->product_name)."',";
$Qry1 .= "qty   ='"  .Escape($this->qty)."',";
$Qry1 .= "rate   ='"  .Escape($this->rate)."',";
$Qry1 .= "vat   ='"  .Escape($this->vat)."',";
$Qry1 .= "discount   ='"  .Escape($this->discount)."',";
$Qry1 .= "tamount   ='"  .Escape($this->tamount)."',";
$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";
$Qry1 .= "createdon  = STR_TO_DATE('".date("d/m/Y")."','$SQLDateFormat'),";
$Qry1 .= "remark   ='"  .Escape($this->remark)."',";

if($Qry1 != ""){
$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
$qry = "insert into lms_customerbill set " . $Qry1 . " ";
dbQuery($qry);
$this->invoice_id=dbInsertedId();
} 

}

function edit(){
	$SQLDateFormat = '%d/%m/%Y';
 $Qry1 = "";
$Qry1 .= "invoice_id   ='"  .Escape($this->invoice_id)."',";
$Qry1 .= "invoice_no   ='"  .Escape($this->invoice_no)."',";
$Qry1 .= "billdate   = STR_TO_DATE('".Escape($this->billdate)."','$SQLDateFormat'),";	
$Qry1 .= "salesby   ='"  .Escape($this->salesby)."',";
$Qry1 .= "customer_name   ='"  .Escape($this->customer_name)."',";
$Qry1 .= "address   ='"  .Escape($this->address)."',";
$Qry1 .= "product_name   ='"  .Escape($this->product_name)."',";
$Qry1 .= "qty   ='"  .Escape($this->qty)."',";
$Qry1 .= "rate   ='"  .Escape($this->rate)."',";
$Qry1 .= "vat   ='"  .Escape($this->vat)."',";
$Qry1 .= "discount   ='"  .Escape($this->discount)."',";
$Qry1 .= "tamount   ='"  .Escape($this->tamount)."',";
$Qry1 .= "company_id='"	  .Escape($_SESSION['cCompany_id'])."',";
$Qry1 .= "createdon   = STR_TO_DATE('".date("d/m/Y")."','$SQLDateFormat'),";
$Qry1 .= "remark   ='"  .Escape($this->remark)."',";


if($Qry1 != ""){ 
$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
 $qry = "update lms_customerbill set " . $Qry1 . " where  invoice_id=".$this->invoice_id;
dbQuery($qry);
}

 } 


function delete() 
{ 
	$qry = "delete from lms_customerbill where invoice_id in (".$this->invoice_id.") ";
	dbQuery($qry);
} 


	

	function getBillNo()
    	{	
			$qry = "";
			 $qry = " SELECT MAX(invoice_no) + 1  as invoice_no  FROM lms_customerbill where company_id= '".$_SESSION["cCompany_id"]."' ";
					
			
			$out=dbQuery($qry);
			
			if (dbRows($out)>0){
            	$resut=dbArray($out);
				if($resut["invoice_no"]=="")
				{
					return "1";
				}
				else{		 
					return $resut["invoice_no"];							
				}
        	}
			return $out;
		}

function getBillNo1()
    	{	
			$qry = "";
			 $qry = " SELECT MAX(invoice_no) + 1  as invoice_no  FROM lms_customerquotation where company_id= '".$_SESSION["cCompany_id"]."' ";
					
			
			$out=dbQuery($qry);
			
			if (dbRows($out)>0){
            	$resut=dbArray($out);
				if($resut["invoice_no"]=="")
				{
					return "1";
				}
				else{		 
					return $resut["invoice_no"];							
				}
        	}
			return $out;
		}
		
		
		function getBillNo2()
    	{	
			$qry = "";
			 $qry = " SELECT MAX(invoice_no) + 1  as invoice_no  FROM lms_operatorinvoice where company_id= '".$_SESSION["cCompany_id"]."' ";
					
			
			$out=dbQuery($qry);
			
			if (dbRows($out)>0){
            	$resut=dbArray($out);
				if($resut["invoice_no"]=="")
				{
					return "1";
				}
				else{		 
					return $resut["invoice_no"];							
				}
        	}
			return $out;
		}
		
function getAllRecords_BillNo_Groupwise1($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
	$qry="SELECT * FROM lms_customerquotation where company_id= '".$_SESSION["cCompany_id"]."' group by invoice_no";

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){
return $out;
}
return $out;
}


function getAllRecords_Operator_BillNo_Groupwise1($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
	$qry="SELECT * FROM lms_operatorinvoice where company_id= '".$_SESSION["cCompany_id"]."' group by invoice_no";

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){
return $out;
}
return $out;
}


function getAllRecords_BillNo_Groupwise($limit=0,$start=0,$condition="",$order_field="",$order_type="")
{
	$qry="SELECT * FROM lms_customerbill where company_id= '".$_SESSION["cCompany_id"]."' group by invoice_no";

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){
return $out;
}
return $out;
}

}/* Code For EXTJS START \n{
 xtype: 'textfield',
name: 'invoice_id',
id:'invoice_id',
allowBlank:false,
tabIndex:1,
labelSeparator:'',
fieldLabel :'invoice_id:',
width:100
},
{
 xtype: 'textfield',
name: 'invoice_no',
id:'invoice_no',
allowBlank:false,
tabIndex:2,
labelSeparator:'',
fieldLabel :'invoice_no:',
width:100
},
{
 xtype: 'textfield',
name: 'date',
id:'date',
allowBlank:false,
tabIndex:3,
labelSeparator:'',
fieldLabel :'date:',
width:100
},
{
 xtype: 'textfield',
name: 'salesby',
id:'salesby',
allowBlank:false,
tabIndex:4,
labelSeparator:'',
fieldLabel :'salesby:',
width:100
},
{
 xtype: 'textfield',
name: 'customer_name',
id:'customer_name',
allowBlank:false,
tabIndex:5,
labelSeparator:'',
fieldLabel :'customer_name:',
width:100
},
{
 xtype: 'textfield',
name: 'address',
id:'address',
allowBlank:false,
tabIndex:6,
labelSeparator:'',
fieldLabel :'address:',
width:100
},
{
 xtype: 'textfield',
name: 'product_name',
id:'product_name',
allowBlank:false,
tabIndex:7,
labelSeparator:'',
fieldLabel :'product_name:',
width:100
},
{
 xtype: 'textfield',
name: 'qty',
id:'qty',
allowBlank:false,
tabIndex:8,
labelSeparator:'',
fieldLabel :'qty:',
width:100
},
{
 xtype: 'textfield',
name: 'rate',
id:'rate',
allowBlank:false,
tabIndex:9,
labelSeparator:'',
fieldLabel :'rate:',
width:100
},
{
 xtype: 'textfield',
name: 'vat',
id:'vat',
allowBlank:false,
tabIndex:10,
labelSeparator:'',
fieldLabel :'vat:',
width:100
},
{
 xtype: 'textfield',
name: 'discount',
id:'discount',
allowBlank:false,
tabIndex:11,
labelSeparator:'',
fieldLabel :'discount:',
width:100
},
{
 xtype: 'textfield',
name: 'tamount',
id:'tamount',
allowBlank:false,
tabIndex:12,
labelSeparator:'',
fieldLabel :'tamount:',
width:100
},
Code For EXTJS END */




/* Code For Save File START 


$objlms_customerbillMgmt= new lms_customerbillMgmt();
$objlms_customerbillMgmt->invoice_id=$_POST['invoice_id'];
$objlms_customerbillMgmt->invoice_no=$_POST['invoice_no'];
$objlms_customerbillMgmt->date=$_POST['date'];
$objlms_customerbillMgmt->salesby=$_POST['salesby'];
$objlms_customerbillMgmt->customer_name=$_POST['customer_name'];
$objlms_customerbillMgmt->address=$_POST['address'];
$objlms_customerbillMgmt->product_name=$_POST['product_name'];
$objlms_customerbillMgmt->qty=$_POST['qty'];
$objlms_customerbillMgmt->rate=$_POST['rate'];
$objlms_customerbillMgmt->vat=$_POST['vat'];
$objlms_customerbillMgmt->discount=$_POST['discount'];
$objlms_customerbillMgmt->tamount=$_POST['tamount'];
if($objlms_customerbillMgmt->invoice_id == "0" ||  $objlms_customerbillMgmt->invoice_id== ""){ 
$objlms_customerbillMgmt->add(); 
} 
else{
if($_REQUEST[act] == "del")
 {$objlms_customerbillMgmt->delete();
 }else
 {$objlms_customerbillMgmt->edit();
}
echo'{"success":"true"}'; 
 }

Code For Save File END */

  ?>