MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/refimac_cafsjobs_com/add_details_bk13aug2017.php
<?php

// Turn off all error reporting
error_reporting(0);

include('dbconnect.php');

include('sms.php');
//session_start();
$user=$_SESSION['clid'];
$perm=$_SESSION['cper'];

$mid=$_REQUEST['mid'];
$smid=$_REQUEST['smid'];
$pid=$_REQUEST['pid'];
$type=$_REQUEST['type'];
//Call Registartion
if($pid=="2_1_1")
{
// add or update your customer
	if($type=="1")
	{	
	$sqlcust_check=mysql_query("select CUSTOMER_CODE from customer where CUSTOMER_CODE='".$_POST['CUSTOMER_CODE']."'");
	if(mysql_num_rows($sqlcust_check)==0)
	{
	$qu2=mysql_query("select CUSTOMER_CODE as custcode from customer order by CUSTOMER_CODE desc limit 0,1");
	$rrows=mysql_fetch_assoc($qu2);
	$custcode_str=$rrows['custcode'];
	//$str = '::f:o:';
    $str = ltrim($custcode_str, 'C');
    $n2 = ltrim($str, '0');
	//$n2
	//echo $n2;
	$n2++;
	if($n2>0&&$n2<=9) $cust_code="C00000".$n2;
	elseif($n2>9&&$n2<=99) $cust_code="C0000".$n2;
	elseif($n2>99&&$n2<=999) $cust_code="C000".$n2;
	elseif($n2>999&&$n2<=9999) $cust_code="C00".$n2;
	elseif($n2>9999&&$n2<=99999) $cust_code="C0".$n2;
	elseif($n2>99999&&$n2<=999999) $cust_code="C".$n2;
	$sqlcustinsertupdate="insert into customer (CUSTOMER_CODE,CUSTOMER_NAME,CUSTOMER_ADDRESS,CUSTOMER_AREA,CUSTOMER_SURROUND_AREA,CUSTOMER_CITY,CUSTOMER_PINCODE,CUSTOMER_PHONE,CUSTOMER_MOBILE,CUSTOMER_CONTACT_PERSON,CUSTOMER_UPDATE,created_by,created_datetime) values ('".$cust_code."','".$_POST['CUSTOMER_NAME']."','".$_POST['CUSTOMER_ADDRESS']."','".$_POST['CUSTOMER_AREA']."','".$_POST['CUSTOMER_SURROUND_AREA']."','".$_POST['CUSTOMER_CITY']."','".$_POST['CUSTOMER_PINCODE']."','".$_POST['CUSTOMER_PHONE']."','".$_POST['CUSTOMER_MOBILE']."','".$_POST['CUSTOMER_CONTACT_PERSON']."','1','$user','".date("Y-m-d H:i:s")."')";
	//echo $sqlcustinsertupdate; die;
	}
	else
	{
	$cust_code=$_POST['CUSTOMER_CODE'];
	$sqlcustinsertupdate="update customer set CUSTOMER_NAME='".$_POST['CUSTOMER_NAME']."',CUSTOMER_ADDRESS='".$_POST['CUSTOMER_ADDRESS']."',CUSTOMER_AREA='".$_POST['CUSTOMER_AREA']."',CUSTOMER_SURROUND_AREA='".$_POST['CUSTOMER_SURROUND_AREA']."',CUSTOMER_CITY='".$_POST['CUSTOMER_CITY']."',CUSTOMER_PINCODE='".$_POST['CUSTOMER_PINCODE']."',CUSTOMER_PHONE='".$_POST['CUSTOMER_PHONE']."',CUSTOMER_MOBILE='".$_POST['CUSTOMER_MOBILE']."',CUSTOMER_CONTACT_PERSON='".$_POST['CUSTOMER_CONTACT_PERSON']."' where CUSTOMER_CODE='".$_POST['CUSTOMER_CODE']."'";
	
	
	//echo $sqlcustinsertupdate;
	}
	//echo $sqlcustinsertupdate; die;
	if(mysql_query($sqlcustinsertupdate)==1)
	{
	echo "1|".$cust_code;
	}
	else
	{
	echo "2|".$cust_code;
	}
	
	}
	
	//add or update your compalint number
	
	if($type=="2")
	{	
	$sql_check=mysql_query("select complaint_no from serviceapp_callreg where complaint_no='".$_POST['complaint_no']."'");
	if(mysql_num_rows($sql_check)==0)
	{
	$qu2=mysql_query("select COUNT(*) as total from serviceapp_callreg where complaint_date='".date("Y-m-d")."' ");
	$rrows=mysql_fetch_assoc($qu2);
	$total=$rrows['total'];
	
    $n1 = $total;
	//$n2
	//echo $n2;
	$n1++;
	$sort_name="REF";
	$year=date("ymd");
	$complaint_no="$sort_name$year";
//echo $complaint_no;
if($n1>=0&&$n1<=9) $complaint_no.="000".$n1;
elseif($n1>9&&$n1<=99) $complaint_no.="00".$n1;
elseif($n1>99&&$n1<=999) $complaint_no.="0".$n1;
elseif($n1>999&&$n1<=9999) $complaint_no.=$n1;
$time_now=time(date('h')+5,date('i')+30,date('s'));
$time=date('h:i:s A',$time_now);

	$sqlcompinsertupdate="insert into serviceapp_callreg (cust_code,CUSTOMER_NAME,CUSTOMER_ADDRESS,CUSTOMER_AREA,CUSTOMER_SURROUND_AREA,CUSTOMER_CITY,CUSTOMER_PINCODE,CUSTOMER_PHONE,CUSTOMER_MOBILE,CUSTOMER_CONTACT_PERSON,complaint_no,complaint_date,complaint_time,call_type,brand_name,product,fault_report,location,service_req_datetime,tech_name,remarks,created_by,created_date,status) values ('".$_POST['CUSTOMER_CODE']."','".$_POST['CUSTOMER_NAME']."','".$_POST['CUSTOMER_ADDRESS']."','".$_POST['CUSTOMER_AREA']."','".$_POST['CUSTOMER_SURROUND_AREA']."','".$_POST['CUSTOMER_CITY']."','".$_POST['CUSTOMER_PINCODE']."','".$_POST['CUSTOMER_PHONE']."','".$_POST['CUSTOMER_MOBILE']."','".$_POST['CUSTOMER_CONTACT_PERSON']."','".$complaint_no."','".date('Y-m-d')."','".$time."','".$_POST['call_type']."','".$_POST['brand_name']."','".$_POST['cust_product']."','".$_POST['fault_report']."','".$_POST['location']."','".$_POST['service_req_datetime']."','".$_POST['tech_name']."','".$_POST['comp_remarks']."','$user','".date("Y-m-d H:i:s")."','1')";
	//echo $sqlcompinsertupdate; die;	
	
	sms('REFMAC',$_POST['CUSTOMER_MOBILE'],'Dear Customer, your Service Call No. '.$complaint_no.' is registered.Your complaint will be attended in 24 to 48Hrs.');
	
	}
	else
	{
	$complaint_no=$_POST['complaint_no'];
	$sqlcompinsertupdate="update serviceapp_callreg set CUSTOMER_NAME='".$_POST['CUSTOMER_NAME']."',CUSTOMER_ADDRESS='".$_POST['CUSTOMER_ADDRESS']."',CUSTOMER_AREA='".$_POST['CUSTOMER_AREA']."',CUSTOMER_SURROUND_AREA='".$_POST['CUSTOMER_SURROUND_AREA']."',CUSTOMER_CITY='".$_POST['CUSTOMER_CITY']."',CUSTOMER_PINCODE='".$_POST['CUSTOMER_PINCODE']."',CUSTOMER_PHONE='".$_POST['CUSTOMER_PHONE']."',CUSTOMER_MOBILE='".$_POST['CUSTOMER_MOBILE']."',CUSTOMER_CONTACT_PERSON='".$_POST['CUSTOMER_CONTACT_PERSON']."',call_type='".$_POST['call_type']."',brand_name='".$_POST['brand_name']."',product='".$_POST['cust_product']."',fault_report='".$_POST['fault_report']."',location='".$_POST['location']."',service_req_datetime='".$_POST['service_req_datetime']."',tech_name='".$_POST['tech_name']."',remarks='".$_POST['comp_remarks']."',updated_by='".$user."',updated_date='".date("Y-m-d H:i:s")."' where complaint_no='".$_POST['complaint_no']."'";
	//echo $sqlcompinsertupdate; die;
	}
	
//	echo $sqlcompinsertupdate; die;
	if(mysql_query($sqlcompinsertupdate)==1)
	{
	$sqlcustinsertupdate="update customer set CUSTOMER_NAME='".$_POST['CUSTOMER_NAME']."',CUSTOMER_ADDRESS='".$_POST['CUSTOMER_ADDRESS']."',CUSTOMER_AREA='".$_POST['CUSTOMER_AREA']."',CUSTOMER_SURROUND_AREA='".$_POST['CUSTOMER_SURROUND_AREA']."',CUSTOMER_CITY='".$_POST['CUSTOMER_CITY']."',CUSTOMER_PINCODE='".$_POST['CUSTOMER_PINCODE']."',CUSTOMER_PHONE='".$_POST['CUSTOMER_PHONE']."',CUSTOMER_MOBILE='".$_POST['CUSTOMER_MOBILE']."',CUSTOMER_CONTACT_PERSON='".$_POST['CUSTOMER_CONTACT_PERSON']."' where CUSTOMER_CODE='".$_POST['CUSTOMER_CODE']."'";
	mysql_query($sqlcustinsertupdate);
	
	echo "1|".$complaint_no."|".$_POST['call_type'];
	}
	else
	{
	echo "2|".$complaint_no."|".$_POST['call_type'];
	}
	
	}
	
	
	
	
	//add or update your machine info.
	
	if($type=="3")
	{		
	
	//print $_POST['sales_ID']; die;
	$sql_check=mysql_query("SELECT SALES_ID,SERVICEMODE_ID,INSTALLATION_DATE FROM sales  where sales_ID='".$_POST['sales_ID']."' order by MATURITY_DATE desc limit 0,1");
	
	//echo "SELECT SALES_ID,SERVICEMODE_ID FROM sales  where sales_ID='".$_POST['sales_ID']."' order by MATURITY_DATE desc limit 0,1"; 
	//$rows_mac=mysql_num_rows($sql_check);
	//echo $rows_mac;
	//die;
	
	if($_POST['mac_model_id']=='0' || $_POST['mac_model_id']=='') {  $mac_model_id=$_POST['mac_model'];} else { $mac_model_id=$_POST['mac_model_id']; }
	
	$qu_sql_check=mysql_fetch_array($sql_check);
	if(mysql_num_rows($sql_check)==0)
	{
	$sqlmacinsertupdate="INSERT INTO sales(CUSTOMER_CODE, MODEL_ID, SERVICEMODE_ID, LOCATION, COMPRESSORNO, INSTALLATION_DATE, MATURITY_DATE, INVOICE_DATE, AMOUNT, REMARKS, INVOICE_NO, NO_OF_SERVICES, CAPACITY, WARRENTY, MAKE_ID, PURCHASE_ID, COMPLETED,comp_wrty) VALUES ('".$_POST['custcode']."','".$mac_model_id."','".$_POST['mac_service_mode']."','".$_POST['mac_location']."','".$_POST['mac_compressor_sno']."','".date("Y-m-d", strtotime($_POST['mac_installdate']))."','".date("Y-m-d", strtotime($_POST['mac_maturitydate']))."','".date("Y-m-d", strtotime($_POST['mac_invoice_date']))."','".$_POST['mac_amount']."','".$_POST['mac_remarks']."','".$_POST['mac_invoice_no']."','".$_POST['mac_service_year']."','".$_POST['mac_capacity']."','".$_POST['mac_wrty']."','".$_POST['mac_brand_name']."','".$_POST['PURCHASE_ID']."','0','".$_POST['comp_wrty']."')";		
	//echo $sqlmacinsertupdate;  die;
	if(mysql_query($sqlmacinsertupdate)==1)
	{
		$sales_id=mysql_insert_id();	 
		$totaldays=365*$_POST['mac_wrty']; 	
		$service_count=$_POST['mac_service_year']*$_POST['mac_wrty'];
		$seperate_days=$totaldays/$service_count;	 
		$service_date="";
		$month="";
		$year="";
		
		for($i=1;$i<=$service_count;$i++)
		{ 
			$seperate_days1=$seperate_days*$i;
			$service_date = date('Y-m-d', strtotime(date("Y-m-d", strtotime($_POST['mac_installdate'])). ' + '.round($seperate_days1,0).' days'));		   
			$service_date_array=explode('-',$service_date);		   
			$month = $service_date_array[1];
			$year = $service_date_array[0];		  
			$sqlserviceinsertupdate="insert into service (SALES_ID,EMPLOYEE_ID,MONTH,YEAR,LIST_INDEX,COMPLETED,servicedate) values('".$sales_id."','0','".$month."','".$year."','".$i."','0','".$service_date."')";			
		   mysql_query($sqlserviceinsertupdate);
			//echo	$sqlserviceinsertupdate; die;
			$service_date="";
			$month="";
			$year="";	      
			
		 }
		 
		 $sql_purchase="update purchase set PURCHASE_DISPLAY='1' where PURCHASE_ID='".$_POST['PURCHASE_ID']."'";
		 
		 mysql_query($sql_purchase);
		 
		 
		 echo "1|".$sales_id;
	}	
	}
	else
	{	
	if($_POST['mac_model']!="")
	{
	$mac_model_id=$_POST['mac_model'];
	}
	else
	{
	$mac_model_id=$_POST['mac_model_id'];
	}
	
	$sqlmacinsertupdate1 ="Update sales set CUSTOMER_CODE='".$_POST['custcode']."',MODEL_ID='".$mac_model_id."',SERVICEMODE_ID='".$_POST['mac_service_mode']."',LOCATION='".$_POST['mac_location']."',COMPRESSORNO='".$_POST['mac_compressor_sno']."',INSTALLATION_DATE='".date("Y-m-d", strtotime($_POST['mac_installdate']))."',MATURITY_DATE='".date("Y-m-d", strtotime($_POST['mac_maturitydate']))."',INVOICE_DATE='".date("Y-m-d", strtotime($_POST['mac_invoice_date']))."',AMOUNT='".$_POST['mac_amount']."',REMARKS='".$_POST['mac_remarks']."',INVOICE_NO='".$_POST['mac_invoice_no']."',NO_OF_SERVICES='".$_POST['mac_service_year']."',CAPACITY='".$_POST['mac_capacity']."',WARRENTY='".$_POST['mac_wrty']."',MAKE_ID='".$_POST['mac_brand_name']."',PURCHASE_ID='".$_POST['PURCHASE_ID']."',comp_wrty='".$_POST['comp_wrty']."' where sales_ID='".$_POST['sales_ID']."'";
	
	//echo $sqlmacinsertupdate1; die;
	
	//echo "df".$qu_sql_check['SERVICEMODE_ID']; die;
	if(mysql_query($sqlmacinsertupdate1)==1)
		{
	
		if(date("Y-m-d", strtotime($_POST['mac_installdate']))!= $qu_sql_check['INSTALLATION_DATE'])
		{
			$sales_id=$_POST['sales_ID'];
			$totaldays=365*$_POST['mac_wrty']; 	
			$service_count=$_POST['mac_service_year']*$_POST['mac_wrty'];
			$seperate_days=$totaldays/$service_count;	 
			$service_date="";
			$month="";
			$year="";
			
			for($i=1;$i<=$service_count;$i++)
			{ 
			$seperate_days1=$seperate_days*$i;
			$service_date = date('Y-m-d', strtotime(date("Y-m-d", strtotime($_POST['mac_installdate'])). ' + '.round($seperate_days1,0).' days'));		   
			$service_date_array=explode('-',$service_date);		   
			$month = $service_date_array[1];
			$year = $service_date_array[0];		  
			$sqlserviceinsertupdate="insert into service (SALES_ID,EMPLOYEE_ID,MONTH,YEAR,LIST_INDEX,COMPLETED,servicedate) values('".$sales_id."','0','".$month."','".$year."','".$i."','0','".$service_date."')";
			//	echo	$sqlserviceinsertupdate;	 		
			mysql_query($sqlserviceinsertupdate);
				//echo	$sqlserviceinsertupdate;
			//$service_date="";
			$month="";
			$year="";	      
			
		 }
		 }
		  echo "1|".$sales_id;
		}	
	}
 }
 
 
     if($type=="4")
	{	
	
$sql="update  service set  servicefileupload='".$_POST['servicefilepath']."',SERIALNO='".$_POST['mac_serial_no']."',EMPLOYEE_ID='".$_POST['tech_name']."',SLIPNO='".$_POST['slip_no']."',COMMENTS='".$_POST['COMMENTS']."',DATE='".date('Y-m-d',strtotime($_POST['dateofcompletion']))."',COMPLETED='Y' where SALES_ID='".$_POST['txtservicesalesid']."' and YEAR='".$_POST['txtservicedate']."' and MONTH='".$_POST['txtservicemonth']."'";

//echo $sql;

		if(mysql_query($sql)==1)
		{
		echo "1|".$cust_code;
		}
		else
		{
		echo "2|".$cust_code;
		}
	
	}
	
	
	if($type=="5")
	{	
	        $sales_id=$_REQUEST['servicevaluedate'];
			$service_date = date('Y-m-d',strtotime($_REQUEST['mac_addservicedate']));		   
			$service_date_array=explode('-',$service_date);		   
			$month = $service_date_array[1];
			$year = $service_date_array[0];		  
			$sql="insert into service (SALES_ID,EMPLOYEE_ID,MONTH,YEAR,LIST_INDEX,COMPLETED,servicedate,status) values('".$sales_id."','0','".$month."','".$year."','0','N','".$service_date."','0')";			
		//	echo $sql; die;		
		if(mysql_query($sql)==1)
		{
		echo "1|".$sales_id;
		}
		else
		{
		echo "2|".$sales_id;
		}
	}	
	
		
	if($type=="6")
	{	
	
	        $sales_id=$_REQUEST['salesid'];					
			$custcode=$_REQUEST['custcode'];		
			$sql="update service set status='2',deleted_by='$user',deleted_date='".date("Y-m-d H:i:s")."' where SALES_ID='".$sales_id."' and MONTH='".$_REQUEST['month']."' and YEAR='".$_REQUEST['year']."' ";	
			//echo $sql; die;		
		if(mysql_query($sql)==1)
		{	
		
		echo "1|".$sales_id."|".$custcode;
		}
		else
		{
		echo "2|".$sales_id."|".$custcode;
		}
	}
	
	
	if($type=="7")
	{	
	
	        $sales_id=$_REQUEST['salesid'];					
			$custcode=$_REQUEST['custcode'];		
			
			$sql_s="select status from sales where SALES_ID='".$sales_id."' ";
			
			$qu_s=mysql_query($sql_s);
			
			$r_s=mysql_fetch_array($qu_s);
				if($r_s["status"]==0)
				{		
			$sql="update sales set status='2',deleted_by='$user',deleted_date='".date("Y-m-d H:i:s")."' where SALES_ID='".$sales_id."'";
			}
			else
			{
			$sql="update sales set status='0',deleted_by='$user',deleted_date='".date("Y-m-d H:i:s")."' where SALES_ID='".$sales_id."'";
			}
				
			//echo $sql; die;		
		if(mysql_query($sql)==1)
		{
		
		$qu_select=mysql_query("select PURCHASE_ID from sales where SALES_ID='".$sales_id."'");
		$r=mysql_fetch_array($qu_select);
		if($r_s["status"]==0)
		{
		mysql_query("update purchase set PURCHASE_DISPLAY='0' where PURCHASE_ID='".$r['PURCHASE_ID']."'");
		}
		else
		{
		mysql_query("update purchase set PURCHASE_DISPLAY='1' where PURCHASE_ID='".$r['PURCHASE_ID']."'");
		}
		
		echo "1|".$sales_id."|".$custcode;
		}
		else
		{
		echo "2|".$sales_id."|".$custcode;
		}
	}
		  	
}


//Call Completion
elseif($pid=="2_1_3")
{
	if($type=="1")
	{	
	
//print_r($_POST); die;
	$sqlcust_check=mysql_query("select comp_id from serviceapp_callcomp where reg_id='".$_POST['reg_id']."'");
	if(mysql_num_rows($sqlcust_check)==0)
	{
	$sqlcompinsertupdate="insert into serviceapp_callcomp (reg_id,call_type,mac_id,acc_frm_dealer,acc_frm_cust,acc_frm_refimac,acc_frm_techtaken,acc_frm_grandtotal,spar_coper_pipe,spare_stand,spare_gas,call_status,pending_reason,visit_date_time,completion_date_time,service_report_upload,invoice_upload,complaint_remarks,created_by,created_datetime,status) values ('".$_POST['reg_id']."','".$_POST['call_type']."','".$_POST['selectsaleid']."','".$_POST['amtfromdealer']."','".$_POST['amtfromcustomer']."','".$_POST['amtfromrefmimac']."','".$_POST['amttakentech']."','".$_POST['grandtotal']."','".$_POST['spar_coper_pipe']."','".$_POST['spare_stand']."','".$_POST['spare_gas']."','".$_POST['call_status']."','".$_POST['pending_reason']."','".$_POST['visit_date_time']."','".$_POST['completion_date_time']."','".$_POST['hid_service_upload']."','".$_POST['hid_dealer_upload']."','".$_POST['complaint_remarks']."','$user','".date("Y-m-d H:i:s")."','Y')";
	//echo $sqlcustinsertupdate; die;
	$reg_id=$_POST['reg_id'];

	 $callupdatestatus="";

	if($_POST['call_status']=="completed")
	$callupdatestatus="2";

	if($_POST['call_status']=="pending")
	$callupdatestatus="3";

	if($_POST['call_status']=="canceled")
	$callupdatestatus="4";
	//echo $sqlcustinsertupdate;
	$reg_id=$_POST['reg_id'];

	 mysql_query("update serviceapp_callreg set status='".$callupdatestatus."' where reg_id='".$_POST['reg_id']."'");
	}
	else
	{
	//$cust_code=$_POST['CUSTOMER_CODE'];
	$sqlcompinsertupdate="update serviceapp_callcomp set call_type='".$_POST['call_type']."',mac_id='".$_POST['selectsaleid']."',acc_frm_dealer='".$_POST['amtfromdealer']."',acc_frm_cust='".$_POST['amtfromcustomer']."',acc_frm_refimac='".$_POST['amtfromrefmimac']."',acc_frm_techtaken='".$_POST['amttakentech']."',acc_frm_grandtotal='".$_POST['grandtotal']."',spar_coper_pipe='".$_POST['spar_coper_pipe']."',spare_stand='".$_POST['spare_stand']."',spare_gas='".$_POST['spare_gas']."',call_status='".$_POST['call_status']."',pending_reason='".$_POST['pending_reason']."',visit_date_time='".$_POST['visit_date_time']."',completion_date_time='".$_POST['completion_date_time']."',service_report_upload='".$_POST['hid_service_upload']."',invoice_upload='".$_POST['hid_dealer_upload']."',complaint_remarks='".$_POST['complaint_remarks']."'  where reg_id='".$_POST['reg_id']."' and comp_id='".$_POST['comp_id']."'";
       
       $callupdatestatus="";

	if($_POST['call_status']=="completed")
	$callupdatestatus="2";

	if($_POST['call_status']=="pending")
	$callupdatestatus="3";

	if($_POST['call_status']=="canceled")
	$callupdatestatus="4";
	//echo $sqlcustinsertupdate;
	$reg_id=$_POST['reg_id'];

	 mysql_query("update serviceapp_callreg set status='".$callupdatestatus."' where reg_id='".$_POST['reg_id']."'");

	}
	//echo $sqlcompinsertupdate; die;
	if(mysql_query($sqlcompinsertupdate)==1)
	{
	
		//sms('REFMAC',$_POST['CUSTOMER_MOBILE'],'Dear Customer, your Service Call No. '.$complaint_no.' is registered.Your complaint will be attended in 24 to 48Hrs.');
	
	echo "1|".$reg_id;
	}
	else
	{
	echo "2|".$reg_id;
	}
	
	}
}


// amc log update
elseif($pid=="2_3_1") 
{
if($type=="1")
	{
			$create_date=date('Y-m-d');
			$amc_date=$_POST['amc_date'];
			$amc_ids=$_POST['amc_ids'];
			$amc_status=$_POST['amc_status'];
			$amc_comments=$_POST['amc_comments'];
      //echo "select amc_ids serviceapp_amclog where amc_ids='".$amc_ids."' and  created_date='".$amc_date."'"; die;
 			$sql_check=mysql_query("select amc_ids from serviceapp_amclog where amc_ids='".$amc_ids."' and amc_date like '%".$amc_date."%'  created_date='".$create_date."'");
     	    $row=mysql_num_rows($sql_check);
			if($row==0)
			{
			$sql="insert into serviceapp_amclog (amc_date,amc_ids,amc_status,amc_comments,created_by,created_date) values('".$amc_date."','".$amc_ids."','".$amc_status."','".$amc_comments."','$user','".date("Y-m-d H:i:s")."')";
			}
			else
			{
				$sql="update serviceapp_amclog  set amc_status='".$amc_status."',amc_comments='".$amc_comments."' where amc_ids='".$amc_ids."' and  created_date='".$create_date."'";
			}
		if(mysql_query($sql)==1)
		{
		echo "1|".$amc_ids;
		}
		else
		{
		echo "2|".$amc_ids;
		}
	}


}

//Page Master
elseif($pid=="6_1_5")
{
$menu=$_POST['menu'];
$menu1=$_POST['menu1'];
$submenu=$_POST['submenu'];
$submenu1=$_POST['submenu1'];
$page_name=$_POST['page_name'];
$but_add=$_POST['but_add'];
$but_upd=$_POST['but_upd'];
$but_del=$_POST['but_del'];
$but_view=$_POST['but_view'];
$but_admin=$_POST['but_admin'];
$refer=$_POST['refer'];
$ap_id=$_POST['ap_id'];
$remarks=$_POST['remarks'];
$open_date=date("Y-m-d",strtotime($_POST['open_date']));


if($menu=="Other") $menu_name=$menu1;else $menu_name=$menu;
if($submenu=="Other") $submenu_name=$submenu1;else $submenu_name=$submenu;

$ava_trans=$but_add."|".$but_upd."|".$but_del."|".$but_view."|".$but_admin;

$time_now=time(date('h')+5,date('i')+30,date('s'));
$time=date('h:i:s A',$time_now);
$from1=date("d-M-Y");
$update_time=$from1.", ".$time;

$sql="insert into serviceapp_pages (menu_name, submenu_name, page_name, ava_trans, refer_name, ap_id, remarks, update_by, update_date, status) values ('".$menu_name."','".$submenu_name."','".$page_name."','".$ava_trans."','".$refer."','".$ap_id."','".$remarks."','".$user."','".date("Y-m-d")."','Y')";
//echo $sql;

if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//User Creation
elseif($pid=="6_1_2")
{
$user_name=$_POST['user_name'];
$password=$_POST['password'];
$permission=$_POST['permission'];
$img_auth=$_POST['img_auth'];

//$permission1=$_POST['permission1'];

if($_POST['permission']=="Others") $perm=$_POST['permission1']; else $perm=$_POST['permission'];

$pids=$_POST['pids'];
$pid1="";
$trans="";
foreach($pids as $key=>$value)
{
	//Collect the Page Ids
	if($pid1!="") $pid1=$pid1.",".$value; else $pid1=$value;
	
	//Collect the Page Transactions
	$con1="opt".$value;
	$t1=$_POST[$con1];
	if(count($t1)>0)
	{
	foreach($t1 as $key1=>$value1)
	{
		if($trans!="") $trans=$trans.",".$value1; else $trans=$value1;
	}
	}
	$con2="opt".$value."1";
	$t2=$_POST[$con2];
	if(count($t2)>0)
	{
	foreach($t2 as $key1=>$value1)
	{
		if($trans!="") $trans=$trans.",".$value1; else $trans=$value1;
	}
	}
}
//echo $pid1;
$time_now=time(date('h')+5,date('i')+30,date('s'));
$time=date('h:i:s A',$time_now);
$from1=date("d-M-Y");
$update_time=$from1.", ".$time;

$sql="insert into serviceapp_login (user_name, password, mid, sid, pid, trans, status, per, hidden, update_user, update_date, update_time) values ('".$user_name."','".$password."','".$mids."','".$sids."','".$pid1."','".$trans."','Allowed','".$perm."','N','".$user."','".date("Y-m-d")."','".$update_time."')";
//echo $sql; die;	

if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}

}

//Access Level Creation
elseif($pid=="6_1_1")
{

$per1=$_POST['permission'];


$pids=$_POST['pids'];
$pid1="";
$trans="";
foreach($pids as $key=>$value)
{
	//Collect the Page Ids
	if($pid1!="") $pid1=$pid1.",".$value; else $pid1=$value;
	
	//Collect the Page Transactions
	$con1="opt".$value;
	$t1=$_POST[$con1];
	if(count($t1)>0)
	{
	foreach($t1 as $key1=>$value1)
	{
		if($trans!="") $trans=$trans.",".$value1; else $trans=$value1;
	}
	}
	$con2="opt".$value."1";
	$t2=$_POST[$con2];
	if(count($t2)>0)
	{
	foreach($t2 as $key1=>$value1)
	{
		if($trans!="") $trans=$trans.",".$value1; else $trans=$value1;
	}
	}
}
//echo $pid1;
$time_now=time(date('h')+5,date('i')+30,date('s'));
$time=date('h:i:s A',$time_now);
$from1=date("d-M-Y");
$update_time=$from1.", ".$time;

$sql="insert into serviceapp_levels (level_name, pid, trans, update_by, update_time, status) values ('".$per1."','".$pid1."','".$trans."','".$user."','".$update_time."','Y')";
//echo $sql;


if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//Employee Master
elseif($pid=="7_1_1")
{
//echo "hai"; die;
$emp_code=$_POST['EMP_CODE'];
$EMP_NAME=$_POST['EMP_NAME'];
$EMP_MOBILE=$_POST['EMP_MOBILE'];
$EMP_DOJ=date("Y-m-d", strtotime($_POST['EMP_DOJ']));
//echo "select EMP_CODE from employee where EMP_CODE='".$emp_code."'"; die;
	$sql_check=mysql_query("select EMP_CODE from employee where EMP_CODE='".$emp_code."'");
	
	if(mysql_num_rows($sql_check)==0)
	{
	$qu2=mysql_query("select COUNT(*) as total from employee ");
	$rrows=mysql_fetch_assoc($qu2);
	$total=$rrows['total'];
	
    $n1 = $total;
	//$n2
	//echo $n2;
	$n1++;
	$sort_name="E";
	$emp_code="$sort_name";
	//echo $complaint_no;
	//E000001
	if($n1>=0&&$n1<=9) $emp_code.="00000".$n1;
	elseif($n1>9&&$n1<=99) $emp_code.="0000".$n1;
	elseif($n1>99&&$n1<=999) $emp_code.="000".$n1;
	elseif($n1>999&&$n1<=9999) $emp_code.="00".$n1;
	elseif($n1>9999&&$n1<=99999) $emp_code.="0".$n1;
	elseif($n1>99999&&$n1<=999999) $emp_code.=$n1;
	
	$time_now=time(date('h')+5,date('i')+30,date('s'));
	$time=date('h:i:s A',$time_now);
	$sql="insert into employee (EMP_CODE,EMP_NAME,EMP_MOBILE,EMP_DOJ,EMP_UPDATE,created_by,created_date) values ('".$emp_code."','".$EMP_NAME."','".$EMP_MOBILE."','".$EMP_DOJ."','1','".$user."','".date("Y-m-d H:i:s")."')";
	//echo $sql; die;
}
else
{
$sql="update employee set EMP_NAME='".$EMP_NAME."',EMP_MOBILE='".$EMP_MOBILE."',EMP_DOJ='".$EMP_DOJ."',updated_by='".$user."',updated_date='".date("Y-m-d H:i:s")."' where EMP_CODE='".$emp_code."'";
}

//echo $sql; die;
if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//Customer Master 
elseif($pid=="7_1_2")
{

$sql="select * from etaapp_employee";
$qu=mysql_query($sql);
$n1=mysql_num_rows($qu);
$n1++;
if($n1>=1 && $n1<=9)
$emp_id="ETA000".$n1;
elseif($n1>=10 && $n1<=99)
$emp_id="ETA00".$n1;
elseif($n1>=100 && $n1<=999)
$emp_id="ETA0".$n1;
elseif($n1>=1000 && $n1<=9999)
$emp_id="ETA".$n1;

$emp_name=$_POST['emp_name'];
$region=$_POST['oper_incharge'];
$branch=$_POST['store_incharge'];
$dob=date("Y-m-d",strtotime($_POST['dob']));
$doj=date("Y-m-d",strtotime($_POST['doj']));
$department=$_POST['department'];
$designation=$_POST['designation'];
$address=$_POST['address'];
$area_name=$_POST['area_name'];
$pincode=$_POST['pincode'];
$state_name=$_POST['state_name'];
$mobile=$_POST['mobile'];
$email_id=$_POST['email_id'];
$norms=$_POST['norms'];
$bike_status=$_POST['bike_status'];
$group_leader=$_POST['group_leader'];
$emp_status=$_POST['emp_status'];
$sms_status=$_POST['sms_status'];

$time_now=time(date('h')+5,date('i')+30,date('s'));
$time=date('h:i:s A',$time_now);
$from1=date("d-M-Y");
$update_time=$from1.", ".$time;

$sql="insert into etaapp_employee (emp_id, emp_name, region_name, branch_name, dob, doj, department, designation, address, area_name, pincode, state_name, mobile, email_id, norms, bike_status, group_leader, act_status, sms_status, update_by, update_time, status) values ('".$emp_id."','".$emp_name."','".$region_name."','".$branch_name."','".$dob."','".$doj."','".$department."','".$designation."','".$address."','".$area_name."','".$pincode."','".$state_name."','".$mobile."','".$email_id."','".$norms."','".$bike_status."','".$group_leader."','".$act_status."','".$sms_status."','".$user."','".$update_time."','Y')";
//echo $sql;

if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//Area Master
elseif($pid=="7_1_3")
{
$AREA_ID=$_POST['AREA_ID'];
$AREA_NAME=$_POST['AREA_NAME'];

	$sql_check=mysql_query("select AREA_ID from area where AREA_ID='".$AREA_ID."'");
	if(mysql_num_rows($sql_check)==0)
	{
	
	$time_now=time(date('h')+5,date('i')+30,date('s'));
	$time=date('h:i:s A',$time_now);
	$sql="insert into area (AREA_NAME,AREA_UPDATE,created_by,created_date) values ('".$AREA_NAME."','1','".$user."','".date("Y-m-d H:i:s")."')";
	//echo $sql;
}
else
{
$sql="update area set AREA_NAME='".$AREA_NAME."',updated_by='".$user."',updated_date='".date("Y-m-d H:i:s")."' where AREA_ID='".$AREA_ID."'";
}

//echo $sql; die;
if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//Model Master

elseif($pid=="7_1_4")
{

$MODEL_ID=$_POST['MODEL_ID'];
$MODEL_NAME=$_POST['MODEL_NAME'];
$MAKE_ID=$_POST['MAKE_ID'];

	$sql_check=mysql_query("select MODEL_ID from model where MODEL_ID='".$MODEL_ID."'");
	if(mysql_num_rows($sql_check)==0)
	{
	
	$time_now=time(date('h')+5,date('i')+30,date('s'));
	$time=date('h:i:s A',$time_now);
	$sql="insert into model (MODEL_NAME,MAKE_ID,created_by,created_date,status) values ('".$MODEL_NAME."','".$MAKE_ID."','".$user."','".date("Y-m-d H:i:s")."','1')";
	//echo $sql;
	}
else
{
$sql="update model set MODEL_NAME='".$MODEL_NAME."',MAKE_ID='".$MAKE_ID."',updated_by='".$user."',updated_date='".date("Y-m-d H:i:s")."' where MODEL_ID='".$MODEL_ID."'";
}

//echo $sql; die;
if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//Brand Master
elseif($pid=="7_1_5")
{
$MAKE_ID=$_POST['MAKE_ID'];
$MAKE_NAME=$_POST['MAKE_NAME'];

	$sql_check=mysql_query("select MAKE_ID from make where MAKE_ID='".$MAKE_ID."'");
	if(mysql_num_rows($sql_check)==0)
	{	
	$time_now=time(date('h')+5,date('i')+30,date('s'));
	$time=date('h:i:s A',$time_now);
	$sql="insert into make (MAKE_NAME,created_by,created_date,status) values ('".$MAKE_NAME."','".$user."','".date("Y-m-d H:i:s")."','1')";
	//echo $sql; die;
	}
else
{
$sql="update make set MAKE_NAME='".$MAKE_NAME."',updated_by='".$user."',updated_date='".date("Y-m-d H:i:s")."' where MAKE_ID='".$MAKE_ID."'";
}

//echo $sql; die;
if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//Purchase Serial No Upload Details
elseif($pid=="7_1_6")
{
$opt=$_REQUEST['opt'];

//Upload to Temp Table
if($opt==1)
{
	$total_rec=0;
	//Upload Bult Data deom Excel Format
	//require_once 'Excel/reader.php';
	require_once 'Excel/excel_reader2.php';
	// ExcelFile($filename, $encoding);
	$data = new Spreadsheet_Excel_Reader();
	// Set output Encoding.
	$data->setOutputEncoding('CP1251');
	
	//Upload Excel File
	function findexts ($filename)
	{
	$filename = strtolower($filename);
	$exts = split("[/\\.]", $filename);
	$n = count($exts)-1;
	$exts = $exts[$n];
	return $exts;
	}
	
	$target_path = "Excel/SAP_Upload";
	$entry_date=date("d-m-Y, H:i:s");
	//Get the Extension  
	//$ext = findexts($_FILES['upfile']['name']) ;
	
	$filename=$_FILES['uploadfile']['name'];
	//echo $filename;
	$base1=basename($filename);
	//echo $base1;
	$exts = explode(".", $base1);
	
	$target = $target.".".$exts[1];
	
	$target_path = $target_path.$target; 
	//echo $target_path;


	//$file_name= $_FILES["uploadfile"]["name"];
	$file_name="Excel/".$_FILES["uploadfile"]["name"];
	if(move_uploaded_file($_FILES["uploadfile"]["tmp_name"],"Excel/".$_FILES["uploadfile"]["name"]))
	{
		//Open and Access Excel File
		$data->read($file_name);
		error_reporting(E_ALL ^ E_NOTICE);
		$full_data="";
		for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
		$data_line="";
			for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
				//echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
				$data_line=$data_line.$data->sheets[0]['cells'][$i][$j]."|";
			}
			$full_data=$full_data.$data_line."^";
		}
		
		//delete previous Orderdata from the Temp Table
		$qu1=mysql_query("delete from serviceapp_tpurchase where update_by='".$user."'");
		
		//Split Each Line in full data
		//get 
		
		$line_split=explode("^",$full_data);
		foreach($line_split as $value)
		{
			$data_split=explode("|",$value);
			$data1="";
			if(trim($data_split[0])!="Purchase No")
			{
				//$amount_split=explode(",",$data_split[6]);
				//$amount1=$amount_split[0].$amount_split[1];
				
				//$date_split=explode("/",$data_split[1]);
				//$order_date=$date_split[0]."-".$date_split[1]."-".$date_split[2];
				if(trim($data_split[3])!="")
				{
				$remove[] = "'";
				
				$sql_model="select sss_model,(select MODEL_ID from model where MODEL_NAME=sss_model and status=1) as modelid from serviceapp_apx where apx_model='".str_replace( $remove, "", trim($data_split[3]))."' and status=1";
				
				//echo $sql_model; die;
			    $qu_model=mysql_query($sql_model);
				$m_val=mysql_fetch_array($qu_model);
				$date=explode('/',str_replace( $remove, "", trim($data_split[1])));
				//echo $date[2].'-'.$date[1].'-'.$date[0];		die;
			   
								
				$sql="insert into serviceapp_tpurchase (PURCHASE_INVOICENUMBER,PURCHASE_DATE,PURCHASE_SERIALNUMBER,PURCHASE_MODEL_ID,PURCHASE_DISPLAY,update_by,update_time,status) values ('".str_replace( $remove, "", trim($data_split[0]))."','".$date[2].'-'.$date[1].'-'.$date[0]."','".str_replace( $remove, "", trim($data_split[2]))."','".$m_val['modelid']."','1','".$user."','".$entry_date."','Y')";
				//echo $sql; die;
				$qu=mysql_query($sql);
				$total_rec++; 	
				}
			
			}
		}
		header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1&total=$total_rec&con=1");
	}
	else
	{
	header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
	}
	header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1&total=$total_rec&con=4");
}


//Upload to Original Table
elseif($opt==2)
{
$_SESSION['$items']="";
	//Updated as per total Table record count
	$total_rec=0;
	$rej_rec=0;
	$sql1="select * from serviceapp_tpurchase where update_by='".$user."' and status='Y'";
	$qu1=mysql_query($sql1);
	while($r1=mysql_fetch_array($qu1))
	{
		$sql2="select PURCHASE_SERIALNUMBER from purchase where PURCHASE_MODEL_ID='".$r1['PURCHASE_MODEL_ID']."' and PURCHASE_SERIALNUMBER='".$r1['PURCHASE_SERIALNUMBER']."' and (status='Y' or status IS NULL)";
		$qu2=mysql_query($sql2);
		if(mysql_num_rows($qu2)==0)
		{
		$entry_date=date("d-m-Y, H:i:s");
		
		$sql="insert into purchase (PURCHASE_INVOICENUMBER,PURCHASE_DATE,PURCHASE_SERIALNUMBER,PURCHASE_MODEL_ID,PURCHASE_DISPLAY,update_by,update_time,status) values ('".$r1['PURCHASE_INVOICENUMBER']."','".$r1['PURCHASE_DATE']."','".$r1['PURCHASE_SERIALNUMBER']."','".$r1['PURCHASE_MODEL_ID']."','0','".$user."','".$entry_date."','Y')";	
		
		//echo $sql; die;	
		$qu=mysql_query($sql);
		$total_rec++;
		}
		else
		{
		$rej_rec++;
		$items.=$r1['PURCHASE_INVOICENUMBER'].'-'.$r1['PURCHASE_SERIALNUMBER']."-".$r1['PURCHASE_DATE']."^";
		}
		$_SESSION['$items']=$items;
	}
	header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=3&total=$total_rec&rej=$rej_rec&con=4");
	
	
}

}


//Tax Master
elseif($pid=="7_1_7")
{
$tax_id=$_POST['tax_id'];
$from_date=$_POST['from_date'];
$to_date=$_POST['to_date'];
$to_date=$_POST['to_date'];
$tax_val=$_POST['tax_val'];

	$sql_check=mysql_query("select tax_id from serviceapp_tax where tax_id='".$tax_id."'");
	if(mysql_num_rows($sql_check)==0)
	{	
	$time_now=time(date('h')+5,date('i')+30,date('s'));
	$time=date('h:i:s A',$time_now);
	$sql="insert into serviceapp_tax (from_date,to_date,tax_val,created_by,created_date,status) values ('".$from_date."','".$to_date."','".$tax_val."','".$user."','".date("Y-m-d H:i:s")."','1')";
	//echo $sql; die;
	}
else
{
$sql="update serviceapp_tax set from_date='".$from_date."',to_date='".$to_date."',tax_val='".$tax_val."',updated_date='".date("Y-m-d H:i:s")."',updated_by='".$user."' where tax_id='".$tax_id."'";
}


//echo $sql; die;
if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

//sales Serial No Upload Details
elseif($pid=="7_1_8")
{
$opt=$_REQUEST['opt'];

//Upload to Temp Table
if($opt==1)
{
	$total_rec=0;
	//Upload Bult Data deom Excel Format
	//require_once 'Excel/reader.php';
	require_once 'Excel/excel_reader2.php';
	// ExcelFile($filename, $encoding);
	$data = new Spreadsheet_Excel_Reader();
	// Set output Encoding.
	$data->setOutputEncoding('CP1251');
	
	//Upload Excel File
	function findexts ($filename)
	{
	$filename = strtolower($filename);
	$exts = split("[/\\.]", $filename);
	$n = count($exts)-1;
	$exts = $exts[$n];
	return $exts;
	}
	
	$target_path = "Excel/Sales_Upload";
	$entry_date=date("d-m-Y, H:i:s");
	//Get the Extension  
	//$ext = findexts($_FILES['upfile']['name']) ;
	
	$filename=$_FILES['uploadfile']['name'];
	//echo $filename;
	$base1=basename($filename);
	//echo $base1;
	$exts = explode(".", $base1);
	
	$target = $target.".".$exts[1];
	
	$target_path = $target_path.$target; 
	//echo $target_path;


	//$file_name= $_FILES["uploadfile"]["name"];
	$file_name="Excel/".$_FILES["uploadfile"]["name"];
	if(move_uploaded_file($_FILES["uploadfile"]["tmp_name"],"Excel/".$_FILES["uploadfile"]["name"]))
	{
		//Open and Access Excel File
		$data->read($file_name);
		error_reporting(E_ALL ^ E_NOTICE);
		$full_data="";
		for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
		$data_line="";
			for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
				//echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
				$data_line=$data_line.$data->sheets[0]['cells'][$i][$j]."|";
			}
			$full_data=$full_data.$data_line."^";
		}
		
		//delete previous Orderdata from the Temp Table
		$qu1=mysql_query("delete from serviceapp_tsales where update_by='".$user."'");
		
		//Split Each Line in full data
		//get 
		$_SESSION['sales']="";
		$line_split=explode("^",$full_data);
		foreach($line_split as $value)
		{
			$data_split=explode("|",$value);
			$data1="";
			if(trim($data_split[0])!="sales_INVOICENUMBER")
			{
				//$amount_split=explode(",",$data_split[6]);
				//$amount1=$amount_split[0].$amount_split[1];
				
				//$date_split=explode("/",$data_split[1]);
				//$order_date=$date_split[0]."-".$date_split[1]."-".$date_split[2];
				if(trim($data_split[4])!="")
				{
				$remove[] = "'";
				
				$sql_model="select sss_model,(select MODEL_ID from model where MODEL_NAME=sss_model and status=1 limit 0,1) as modelid  from serviceapp_apx where apx_model='".str_replace( $remove, "", trim($data_split[4]))."' and status=1";
				
				//echo $sql_model; die;
			    $qu_model=mysql_query($sql_model);
				$m_val=mysql_fetch_array($qu_model);
				
				$date=explode('/',str_replace( $remove, "", trim($data_split[1])));
								
				$sql="insert into serviceapp_tsales (sales_INVOICENUMBER, sales_DATE, sales_SERIALNUMBER, sales_MODEL_ID, sales_customer, update_by, update_time, status) values ('".str_replace( $remove, "", trim($data_split[0]))."','".$date[2].'-'.$date[1].'-'.$date[0]."','".str_replace( $remove, "", trim($data_split[2]))."','".$m_val['modelid']."','".str_replace( $remove, "", trim($data_split[3]))."','".$user."','".$entry_date."','Y')";
				//echo $sql; die;
				//$qu=mysql_query($sql);
				if(mysql_query($sql)==1)
				{
				$total_rec++;
				}
				else
				{
			//	echo "select sss_model,(select MODEL_ID from model where MODEL_NAME=sss_model and status=1 limit 0,1) as modelid  from serviceapp_apx where apx_model='".str_replace( $remove, "", trim($data_split[4]))."' and status=1";
				
				$sales.= str_replace( $remove, "", trim($data_split[0])).'-'.str_replace( $remove, "", trim($data_split[2])).'-'.str_replace( $remove, "", trim($data_split[4])).",";
				}
				}
			
			}
		}
		$_SESSION['sales']=$sales;
		//header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1&total=$total_rec&con=1");
	}
	else
	{
	header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
	}
	header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1&total=$total_rec&con=4");
}


//Upload to Original Table
elseif($opt==2)
{
//$items = array();
	//Updated as per total Table record count
	
	$_SESSION['items']="";
	$total_rec=0;
	$rej_rec=0;
	$sql1="select * from serviceapp_tsales where update_by='".$user."' and status='Y'";
	$qu1=mysql_query($sql1);
	while($r1=mysql_fetch_array($qu1))
	{
		$sql2="select PURCHASE_SERIALNUMBER from purchase where PURCHASE_SERIALNUMBER='".$r1['sales_SERIALNUMBER']."' and PURCHASE_MODEL_ID='".$r1['sales_MODEL_ID']."'";
		$qu2=mysql_query($sql2);
		if(mysql_num_rows($qu2)>=1)
		{
		$entry_date=date("d-m-Y, H:i:s");
		
		$sql="update  purchase set sales_invoiceno='".$r1['sales_INVOICENUMBER']."',sales_date='".$r1['sales_DATE']."',client_name='".$r1['sales_customer']."',sales_createddate='".$entry_date."',sales_updatedby='".$user."' where PURCHASE_SERIALNUMBER='".$r1['sales_SERIALNUMBER']."' and PURCHASE_MODEL_ID='".$r1['sales_MODEL_ID']."'";		
		
		//echo $sql;
				
		$qu=mysql_query($sql);
		$total_rec++;
		}
		else
		{
		$rej_rec++;
		//echo $r1['sales_INVOICENUMBER']; 
		$items.=$r1['sales_INVOICENUMBER']."-".$r1['sales_SERIALNUMBER'].",";
		}
		
		$_SESSION['items']=$items;
	}
	header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=3&total=$total_rec&rej=$rej_rec&con=4");
	
}

}


elseif($pid=="7_1_9")
{
if($type==1)
{
$current_date=date('Y-m-d');
$Purchase_invoiceno=$_POST['PURCHASE_INVOICENUMBER'];
$Purchase_date=$_POST['PURCHASE_DATE'];
$Purchase_serialno=$_POST['PURCHASE_SERIALNUMBER'];
$Purchase_model_id=$_POST['PURCHASE_MODEL_ID'];
$date = date('Y-m-d H:i:s');
$Purchase_display=$_POST['PURCHASE_DISPLAY'];
$sales_invoiceno=$_POST['sales_invoiceno'];
$sales_date=$_POST['sales_date'];
$client_name=$_POST['client_name'];
if($_POST['PURCHASE_ID']==0)
{
	$sql="INSERT into purchase (PURCHASE_INVOICENUMBER,PURCHASE_DATE,PURCHASE_SERIALNUMBER,PURCHASE_MODEL_ID,PURCHASE_DISPLAY,sales_invoiceno,sales_date,client_name) VALUES ('$Purchase_invoiceno','".date('Y-m-d',strtotime(trim($Purchase_date)))."','$Purchase_serialno','$Purchase_model_id','0','$sales_invoiceno','".date('Y-m-d',strtotime(trim($sales_date)))."','$client_name') ";

//echo $sql; die;
}
else
{
$sql="update purchase set PURCHASE_INVOICENUMBER='".trim($Purchase_invoiceno)."', PURCHASE_DATE='".date('Y-m-d',strtotime(trim($Purchase_date)))."', PURCHASE_SERIALNUMBER='".trim($Purchase_serialno)."', PURCHASE_MODEL_ID='".trim($Purchase_model_id)."',update_time='".date("Y-m-d H:i:s")."', sales_invoiceno='".trim($sales_invoiceno)."', sales_date='".date('Y-m-d',strtotime(trim($sales_date)))."', client_name='".trim($client_name)."' where PURCHASE_ID='".trim($_POST['PURCHASE_ID'])."'";
//echo $sql;die;
}
if(mysql_query($sql)==1)
{
	echo "1|".trim($Purchase_invoiceno);

}
else
{
	echo "2|";

}
}

if($type==2)
{
$Purchase_invoiceno=$_POST['purchaseinvoice'];

$sql="update purchase set status='N' where PURCHASE_INVOICENUMBER='".trim($Purchase_invoiceno)."'";
//echo $sql;die;

if(mysql_query($sql)==1)
{
	echo "1|".trim($Purchase_invoiceno);

}
else
{
	echo "2|";

}
}

}

elseif($pid=="7_1_10")
{
//echo "hai"; die;
$apx_modelid=$_POST['apx_modelid'];
$apx_model=$_POST['apx_model'];
$sss_model=$_POST['sss_model'];

//echo "select EMP_CODE from employee where EMP_CODE='".$emp_code."'"; die;
	$sql_check=mysql_query("select apx_modelid from serviceapp_apx where apx_modelid='".$emp_code."'");

	if(mysql_num_rows($sql_check)==0)
	{

	$sql="insert into serviceapp_apx (apx_model,sss_model,status) values ('".$apx_model."','".$sss_model."','1')";
//	echo $sql; die;
}
else
{
$sql="update serviceapp_apx set apx_model='".$apx_model."',sss_model='".$sss_model."' where apx_modelid='".$emp_code."'";
}

//echo $sql; die;
if(mysql_query($sql)==1)
{
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo mysql_error();
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

elseif($pid=="7_1_11")
{

//$employee_id=$_POST['employee_id'];
$model_name=$_POST['model_name'];
$MAKE_ID=$_POST['MAKE_ID'];
$product_name=$_POST['product_name'];
$tonage=$_POST['tonage'];
$lamount=$_POST['lamount'];
$excomp=$_POST['excomp'];
$comp=$_POST['comp'];
$wlamount=$_POST['wlamount'];
$wexamount=$_POST['wexamount'];

$time_now=time(date('h')+5,date('i')+30,date('s'));
$time=date('Y-m-d h:i:s',$time_now);

$sql="insert into amc_model_list (model_no, make, product, tonage, lamount, excomp, comp, wlamount, wexamount,inserted_by,inserted_date,status) values ('".$model_name."','".$MAKE_ID."','".$product_name."','".$tonage."','".$lamount."','".$excomp."','".$comp."','".$wlamount."','".$wexamount."','".$user."','".$time."','Y')";


if(mysql_query($sql)==1)
{
	//echo"success";
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=1");
}
else
{
//echo"failure";
header("Location:landing.php?mid=$mid&smid=$smid&pid=$pid&nav=2");
}
}

?>