<?php
require "_header.php";
require "commonincludefiles.php";

ini_set('max_execution_time', 3003);


$a= "select max(time) as da from lms_cust";



$sql = dbQuery($a);  

$qry = dbArray($sql);
//extract($qry);

//print $qry['da'];

$date = strtotime($qry['da']);
$date1 = strtotime("+2 minute", $date);



$page = $_SERVER['PHP_SELF'];
$sec = date('Y-m-d H:i:s', $date1);

//echo $sec; 
?>
<html>
    <head>
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    </head>
    <body>
    
    </body>
</html>

<?php //require "includeGridFilters.php";?>
<?php 
date_default_timezone_set('Asia/Kolkata');
	
 /*$date = date('H:i');
echo $date;*/
//exit;
if ($_SESSION["cUserName"]!="" && isset($_SESSION["cUserName"]) != "") 
{
  $username= $_SESSION["cUserName"];
  $user_id= $_SESSION["cUserId"]; 
}
 
$customer_id1 = Escape($_REQUEST["customer_id"]); 
$cust_id1 = Escape($_REQUEST['cust_id']);

if ($customer_id1!="" && isset($customer_id1) != "") 
	{ 
		
		$mode="edit";	
		$qry = "SELECT 
					lc.*, 
					(SELECT `user_name` FROM `lms_usermaster` WHERE `user_id` = lc.`assign_user_id`  ) as asign_user_name,
					(SELECT `user_name` FROM `lms_usermaster` WHERE `user_id` = lc.`user_id`) as user_name,
					(SELECT `customer_orgname`  FROM `lms_customer` WHERE `customer_id` = lc.`customer_id`) as customer_orgname,
					
					(SELECT SUM(inv.dueamount) FROM lms_customerinvoice inv where inv.status != 'Paid' AND inv.customer_id='".$customer_id1."' group by inv.customer_id ) as dueamount
				FROM 
					lms_cust as lc
				WHERE  lc.customer_id = '".$customer_id1."' AND lc.cust_id='".$cust_id1."'";
				
		//		echo $qry; exit;
	$out = dbQuery($qry);  
	if (dbRows($out)){
		$row = dbArray($out);
		extract($row);			
	} 
	$qry_billchk  = " SELECT * from lms_customerinvoice WHERE customer_id='".$customer_id1."'";	
	$out_billchk = dbQuery($qry_billchk);
	if(dbRows($out_billchk) > 0){
		$qry_product="SELECT 
						inv.customerinvoice_no,
						DATE_FORMAT(inv.customerinvoice_date,'%d-%m-%Y') as date,
						cpm.product_type,
						cpm.product_name,
						cpm.product_type,
						inv.status,
						invp.product_qty,
						invp.product_rate,
						floor(invp.product_qty*invp.product_rate) as due
					 FROM 
						lms_customerinvoice inv,
						lms_customerinvoiceproduct invp,
						lms_productmaster cpm
					where 
						invp.customerinvoice_id = inv.customerinvoice_id AND
						invp.product_id = cpm.product_id AND 
						inv.customer_id='".$customer_id1."' and
						(cpm.product_type = 'AMC' or (cpm.product_type != 'AMC' && inv.status != 'Paid'))";
	
		$out_product = dbQuery($qry_product);
		$data = array();
			//echo "<pre>";
		if (dbRows($out_product)){
			$i=0;
			while($result1 = dbArray($out_product))
			{
				if($result1['product_type'] != 'AMC'){
					$data[$i] = $result1;	
					$data[$i]['total']=  $result1['product_qty']*$result1['product_rate'];
					$data[$i]['calulation']=  $result1['product_qty']." * ".$result1['product_rate']." = ".$data[$i]['total'];
				$i++;	
				}
				else
				{
					if(!(isset($data['AMC']))){
						$data['AMC'] = $result1;
						$data['AMC']['total']= $result1['product_qty']*$result1['product_rate'];
						//$data['AMC']['calulation']=  $data['AMC']['product_qty']." * ".$data['AMC']['product_rate']." = ".$data['AMC']['total'];
					}else{
						$data['AMC']['date'] =  $result1['date'];
						$data['AMC']['product_name'] =  $result1['product_name'];
						$data['AMC']['total'] = $data['AMC']['product_rate'] + $result1['product_rate'];
						//$data['AMC']['calulation']=  $data['AMC']['product_rate']." + ".$result1['product_rate']." = ".$data['AMC']['total'];
					}
				}
			}
			foreach($data as $d){
				$product_name1 .= $d['date']." - ".$d['product_name']." ( ".$d['product_type']." ) ".$d['calulation'].",";
			}
		}else{
			$data=0;
			$product_name1 ="";
		}
	}
	else{
		$product_name1 = "Bill is not Avaible";
	}
	//$amt_desc= str_replace(",","\n",$product_name1);
	//echo str_replace("world","Peter","Hello world!");
	//exit;
}
	
?> 

<style type="text/css">
.img-contact
{
	vertical-align: middle;
	margin: 0px 0px 0px 0px;
	width:75px;
	height:100px;
}
.x-fieldset
{
	border-style: solid none none none;
	border-width: 1px;
	border-color: #B5B8C8;
	padding: 10px;
	margin-bottom: 10px;
	margin-right: 20px;
	display: block;
}
label.myBold
{
   font-weight: bold;
   color:#666667;
   font-size: 12px;
   
}
    </style>	 

 <script type="text/javascript" language="javascript"> 
var formMode = '<?php echo $mode;?>';

var user_name = '<?php echo $username;?>';
var user_id = '<?php echo $user_id;?>';
var desc= '<?php echo $product_name1;?>';

</script>
<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
 <!--<script type="text/javascript" src="js/addedit-customer.js"></script>-->
<script type="text/javascript" language="javascript"> 
 
var customerstore = new Ext.data.Store({
		url: 'data/getcust.php',          
		reader: new Ext.data.JsonReader({			
	fields: ['customer_id','cust_id','cpmail1','date1','customer_orgname','address','commu_person','mobno','phoneNo','problem_det','completed_det','status','pending_reason','cp_mobno','pending_work','user_id','customer_id','user_name','amount_desc','dueamount','assign_user_id','amount_desc','support_sdate','support_edate','support_timefrom','support_timeto','ticket'],
			root: 'rows1'
		}),autoLoad:true
	}); 


var custname_store = new Ext.data.Store({
		url: 'data/getcustomername1.php',          
		reader: new Ext.data.JsonReader({			
		fields: ['customer_id','customer_orgname','customer_address','amount_desc','dueamount'],
		root: 'rows'
		}),autoLoad:true
	});



  
var userstore = new Ext.data.Store({
		url: 'data/getusername.php',          
		reader: new Ext.data.JsonReader({			
			fields: ['user_id','user_name'],
			root: 'rows'
		}),autoLoad:true
	}); 


 


var labelArray;
	
	labelArray = [
		['Date :<span class="comp">*</span>'],
		['Customer Name :<span class="comp">*</span>'],
		['Address : '],
		['Communicated Person <span class="comp">*</span>'],
		['Mobile No '],
		['Landline No '],		
		['Problem Detail'],
		['Completed Work Detail'],
		['Status:'],
		['User Name :<span class="comp">*</span>'],	
		['Assign To:'],
		['Amount Desc. :']	
		
	];
	
var xg = Ext.grid;	
	
Ext.QuickTips.init();
	
Ext.onReady(function() {
 	
	var local = false; 
	var createColModel = function (finish, start) {
        var columns = [ 
		{
			width:70,
			dataIndex: 'date1',
			header: 'Date',
			 renderer: Ext.util.Format.dateRenderer('d-m-Y')
            
        },{
			width:180,
            dataIndex: 'customer_orgname',
			header: 'customer name'
        },{ 
			id:'status',
			dataIndex: 'status',
			header: 'Status ',
			align: 'left',
		
			 renderer: function(v, params, record){
				var price=record.get('status');
				if(v =='Completed'){
					return '<span style="color:green;">' + v + '</span>';
				}
				else if(v =='Pending'){
					return '<span style="color:red;">' + v + '</span>';
				}else{
					return '<span style="color:blue;">' + v + '</span>';
				}
			},
			width:60
		},
		{
			width:70,
			dataIndex: 'mobno',
			header: 'Mobile No'
            
        },
        {
			width:70,
			dataIndex: 'ticket',
			header: 'Ticket No',
			hidden:true
            
        },
		{
			width:70,
            
			dataIndex: 'cp_mobno',
			header: 'Commu.NO'
        }];
		return new Ext.grid.ColumnModel({
            columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    };
	var grid1 = new Ext.grid.GridPanel({
	     	store: customerstore,	
        colModel: createColModel(500), 
        loadMask: true, 
		frame:true,
		height: 480,    
        width: 480, 
		stripeRows: true,
		columnLines:true,
    	selModel: new Ext.grid.RowSelectionModel({
		singleSelect:true, 
				 listeners: {
				 	
					rowselect: function(sm, row, rec)  
					{  						
						Ext.getCmp("supportinquiryForm").getForm().loadRecord(rec); 
						Ext.getCmp("SearchByPhone").reset(); 
						Ext.getCmp('btnDelete').enable();	
						Ext.getCmp('pending_reason').enable();
						Ext.getCmp('pending_work').enable();					  
					}
				 }
		 }) ,
		 tbar: [
		  new Ext.form.TriggerField({
                xtype: 'triggerfield',
				id:'searchtrigger',
                triggerClass: 'x-form-clear-trigger',
               	emptyText:'Search Customer Name',
				width:160,
				enableKeyEvents: true,
				listeners: {
							 keyup: function(){
								 customerstore.filter('customer_orgname',this.getValue(),true);}
				 },
				onTriggerClick : function(){
					this.reset();
					customerstore.filter('customer_orgname','',true)			
				  } 
            }),
     		  new Ext.form.TriggerField({
                xtype: 'triggerfield',
				id:'searchmobile',
                triggerClass: 'x-form-clear-trigger',
               	emptyText:'Search Mobile No',
				width:130,
				enableKeyEvents: true,
				listeners: {
							 keyup: function(){
								 customerstore.filter('cp_mobno',this.getValue(),true);}
				 },
				onTriggerClick : function(){
					this.reset();
					customerstore.filter('cp_mobno','',true)			
				  } 
            }),       
            
            
            
		 new Ext.form.TriggerField({
                xtype: 'triggerfield',
                triggerClass: 'x-form-clear-trigger',
               	emptyText:'Search Ticket no',
				width:130,
				enableKeyEvents: true,
				listeners: {
							 keyup: function(){
									 customerstore.filter('ticket',this.getValue(),true); 
									 customerstore.filter('ticket',this.getValue(),true); 
								 }
				},
				onTriggerClick : function(){
					this.reset();
					customerstore.filter('mobno','',true)
					customerstore.filter('cp_mobno','',true) 
				  } 
            }) ] 
    });
	
	var supportclosestore = new Ext.data.ArrayStore({
           fields: ['status'],
	       data: [['Pending'],['Completed'],['on work']]
	}); 
 
var nameAndCompany = {
	columnWidth: 1,
    layout: 'column',
	labelWidth: 140,
    style: 'padding:0px 10px',
    items: [{
			columnWidth: .60,
			layout: 'form',	
			items:[{
				xtype: 'hidden',
				name: 'cust_id',
				id:'cust_id',
				hidden:true,
				dataIndex: 'cust_id',
			}, {
				xtype:'hidden',
				id:'returnId',
				name:'returnId',
				hidden:true
			},{
				columnWidth: 1, 
				xtype: 'textfield',
				name: 'SearchByPhone',
				id: 'SearchByPhone',
				fieldLabel:'Search ',
				tabIndex:1,
				width:170,
                listeners:{ 
					blur: function() 
					{ 
						customerstore.on('load', function () 
						{ 
							customerstore.each(function(r)
							{ 
								custname_store.add(r.copy());
							}); 
		                }); 
						        custname_store.load({    					
							    params: {phone:Ext.getCmp('SearchByPhone').getValue()}																
						       });	 
					}
				}
			},{
				columnWidth: 1, 
				xtype: 'datefield',
				name: 'date1',
				labelSeparator:'',	
				fieldLabel :labelArray[0], 
				width:170,
				allowBlank:false,
				tabIndex:2,
				id: 'date1',
				formate:'d/m/Y',
				vtype: 'daterange',
				value:new Date() 
				
			},{ 
				columnWidth: 1,
			     layout: 'column',	
				 
			     items:[{
					 columnWidth: .90,
					 layout: 'form',	
					 items:[{	
						xtype: 'combo',
						name: 'customer_id', 
						//dataIndex:'customer_id',
						id:'customer_id',
						autoLoad:true,
						hiddenName: 'customer_idhedden',
						forceSelection:true,
						tabIndex:3,
						labelSeparator:'',	
						fieldLabel :labelArray[1] ,
						displayField:'customer_orgname',
						valueField: 'customer_id', 
						width: 230,
						blankText: '',
						emptyText:'Customer Name',
						allowBlank:false,
						triggerAction:'all', 
						mode:'local',			
						selectOnFocus: true,	
						store:custname_store,
						autoLoad:true, 
						editable:true,	
						listeners:{select:{fn:function(combo, value) 
						{	  	
						 			  
           this.store.filter('customer_orgname', this.getRawValue(), true, false);
     
							 var varcustid=0; 
							 varcustid=combo.getValue('customer_id'); 											      
							 var custid = supportinquiryForm.getForm().findField('customer_id').getValue(); 
							 Ext.Ajax.request({
											  loadMask: true,
											  sync : true,
											  url:'data/getaddress.php',
											  params: {customer_id: custid},
											  waitMsg:'Loading',
											  failure: function() {
													 Ext.MessageBox.show({
														   title: 'Error',
														   msg: 'Invalid ',
														   buttons: Ext.MessageBox.OK,
														   icon:Ext.MessageBox.ERROR
														  });
											  },
											  success: function(resp) 
													{ 
														varcsno=Ext.decode(resp.responseText).add;
														if(varcsno != "")
														{ 
														supportinquiryForm.getForm().findField('address').setValue(varcsno); 			
														}
														else
														{	  
															 Ext.getCmp("address").reset();											     
														}
														
														varper=Ext.decode(resp.responseText).per;
														if(varper != "")
														{ 
														supportinquiryForm.getForm().findField('commu_person').setValue(varper); 			
														}
														else
														{	 
															 Ext.getCmp("commu_person").reset();											     
														} 
														varcp_no=Ext.decode(resp.responseText).per_no;
														if(varcp_no != "")
														{ 
														supportinquiryForm.getForm().findField('cp_mobno').setValue(varcp_no); 			
														}
														else
														{	 
															 Ext.getCmp("cp_mobno").reset();											     
														} 
														varmob=Ext.decode(resp.responseText).mob1;
														if(varmob != "")
														{ 
														supportinquiryForm.getForm().findField('mobno').setValue(varmob); 			
														}
														else
														{	  
															 Ext.getCmp("mobno").reset(); 
														}
														 
																		varemail=Ext.decode(resp.responseText).cpmail1;
														if(varemail != "")
														{ 
														supportinquiryForm.getForm().findField('cpmail1').setValue(varemail); 			
														}
														else
														{	  
															 Ext.getCmp("cpmail1").reset(); 
														}
														
 
														 
														varphoneNo=Ext.decode(resp.responseText).ph;
														if(varphoneNo != "")
														{ 
														supportinquiryForm.getForm().findField('phoneNo').setValue(varphoneNo); 			
														}
														else
														{	
															   Ext.getCmp("phoneNo").reset(); 
														} 
														
														vardueamount=Ext.decode(resp.responseText).dueamount;
														if(vardueamount != "")
														{ 
														supportinquiryForm.getForm().findField('dueamount').setValue(vardueamount); 			
														}
														else
														{	
															   Ext.getCmp("dueamount").reset(); 
														}
														
														varproduct_name = Ext.decode(resp.responseText).product_name;
														if(varproduct_name != "")
														{ 
															varproduct_name = varproduct_name.replace(new RegExp(",","g"), "\n");
														supportinquiryForm.getForm().findField('amount_desc').setValue(varproduct_name); 			
														}
														else
														{	
															   Ext.getCmp("amount_desc").reset(); 
														}
													}				
										});
										//customerstore.reload(); 
								}	
							}
						} 
					   },{
							columnWidth: 1, 
							width:170,
							xtype: 'textarea',
							name: 'address',
							id: 'address',
							growAppend: "",
							// allowBlank:false,
							fieldLabel :labelArray[2] ,
							tabIndex:4,	
							labelSeparator:'' 
					}]
				 	},{
						columnWidth: .10,
						layout: 'form',	
						items:[{		
								xtype:'button',
								id:'Add',
								iconCls:'icon-add',
								handler: function()
								{  
								   returnId = 1;
								   window.location = 'addedit-customer.php?returnId='+ returnId;  										   
								   CustomergridForm.getForm().reset();
								   grid.getSelectionModel().clearSelections();
										//grid.removeButton.disable();
								   store.load(); 
								   custname_store.reload();
								}
						},{
							xtype:'button',
							text: 'Edit',
							id:'add_cust',	
							
							handler: function () {
								returnId = 1;
								var c_id= Ext.getCmp("customer_id").getValue();
								if (c_id != ''){
									window.location = 'addedit-customer.php?customer_id='+c_id+'&returnId='+ returnId;
								}
								else {
									Ext.MessageBox.show({
									   title: 'Error',
									   msg: 'Please Select Customer First !',
									   buttons: Ext.MessageBox.OK,
									   icon:Ext.MessageBox.ERROR
									  });
									  Ext.getCmp('customer_id').focus(true,500);
								}
							
							}
			}]
				}]
				
			},{
				columnWidth: 1, 
				width:170,
				xtype: 'textfield',
				name: 'mobno',
				id: 'mobno',
				fieldLabel:labelArray[4], 
				tabIndex:5,
				minLength:10,
				maxLength:10,					
				autoCreate: {tag: 'input', type: 'text', maxlength: '13'},
				enableKeyEvents: true,
				listeners:{
								keyup: validphoneno
						   }  													
			},
			{
				columnWidth: 1, 
				width:170,
				xtype: 'textfield',
				name: 'cpmail1',
				id: 'cpmail1',
				fieldLabel:'Email', 
				tabIndex:5,
								
				//autoCreate: {tag: 'input', type: 'text', maxlength: '13'},
				enableKeyEvents: true,
																
			},
			
			{
				columnWidth: 1, 
				width:170,
				xtype: 'textfield',
				name: 'phoneNo',
				id: 'phoneNo',
				//allowBlank:false,
				fieldLabel:labelArray[5],
				autoCreate: {tag: 'input', type: 'text',  maxlength: '13'},
				enableKeyEvents: true,
				minLength:6,						 
				maxLength:11,						 
				tabIndex:6,
				listeners:{
								keyup: validphoneno
							}   
			},{ 
				columnWidth: 1, 
				width:170,
				xtype: 'textfield',
				name: 'commu_person',
				id: 'commu_person',
				fieldLabel :labelArray[3],
				allowBlank:false,
				tabIndex:7 
			},{
				columnWidth: 1, 
				width:170,
				xtype: 'textfield',
				name: 'cp_mobno',
				id: 'cp_mobno',
				fieldLabel:'Commu. Person No. ', 
				tabIndex:8,
				minLength:10,
				maxLength:10,					
				autoCreate: {tag: 'input', type: 'text', maxlength: '13'},
				enableKeyEvents: true,
				listeners:{
								keyup: validphoneno
						   }  													
			},{
				columnWidth: 1,  
				xtype: 'combo', 
				name: 'user_id',
				id:'user_id',
				autoLoad:true, 
				hiddenName: 'user_idhedden',
				forceSelection:true,
				tabIndex:9,
				labelSeparator:'',	
				fieldLabel :labelArray[9] , 
				displayField:'user_name',
				valueField: 'user_id',				
				width: 170, 
				//value:user_name,
				allowBlank:false,
				triggerAction:'all',
				mode:'local',			
				selectOnFocus: true,	
				store:userstore, 
				editable:false						 
			},{
				columnWidth: 1,  
				xtype: 'combo', 
				name: 'assign_user_id',
				id:'assign_user_id',
				autoLoad:true, 
				hiddenName: 'assign_user_idhedden',
				forceSelection:true,
				tabIndex:10,
				labelSeparator:'',	
				fieldLabel :labelArray[10] , 
				displayField:'user_name',
				valueField: 'user_id',				
				width: 170, 
				//value:user_name,
				//allowBlank:false,
				triggerAction:'all',
				mode:'local',			
				selectOnFocus: true,	
				store:userstore, 
				editable:false						 
			},{
				xtype: 'textfield',
				name: 'dueamount',
				id: 'dueamount',
				width:170,
				readOnly:true,
				value:0,
				//allowBlank:false,
				fieldLabel:'Due Amount',
				listeners: {
					   beforeRender: function(e) {
							   e.style = "font-weight: bold; color:#f40925;";
					   }
				}
				
             },{
					columnWidth: 1,
					layout: 'column',	 
					items:[{columnWidth: .67,
							layout: 'form',
							//labelWidth: 85,
							items: [{
									columnWidth: 1, 
									xtype: 'datefield',
									name: 'support_sdate',
									id: 'support_sdate',
									labelSeparator:'',	
									fieldLabel :'Support Date From : ', 
									width:91,
									allowBlank:false,
									tabIndex:11,
									formate:'d/m/Y',
									value:new Date(), 
									emptyText:'Start',
									/*vtype: 'daterange',
									endDateField:'support_edate'*/
									
							}]
					},{
						columnWidth: .33,
						layout: 'form',
						labelWidth: 1,
						items: [{
							
									xtype: 'timefield',
									name: 'support_timefrom',
									id: 'support_timefrom',
									labelSeparator:'',	
									//fieldLabel :'Support Time :', 
									width:70
									,tabIndex:13
									,emptyText:'Start'
									,allowBlank:false
									,format: 'H:i'
									,value:new Date() 
									//, increment  : 60 
									//,default:datetime.now().time
									
						}]	
							
				}]
			},{
					columnWidth: 1,
					layout: 'column',	 
					items:[{columnWidth: .67,
							layout: 'form',
							//labelWidth: 85,
							items: [{
									columnWidth: 1,
									fieldLabel :'Support Date To:',
									xtype: 'datefield',
									name: 'support_edate',
									labelSeparator:'',
									width:91,
									tabIndex:12,
									forceSelection:true,
									value:new Date(),
									id:'support_edate',
									/*vtype:'daterange',
									startDateField:'support_sdate'*/
									

							}]
					},{
						columnWidth: .33,
						layout: 'form',
						labelWidth: 1,
						items: [{
									xtype: 'timefield',
									name: 'support_timeto'
									,width:70
									,tabIndex:14
									,emptyText:'End'
									,format: 'H:i'
									//,allowBlank:false
									,id: 'support_timeto'
						}]	
							
				}]
			}]
		},{
			columnWidth: .40,
			labelWidth: 61,
			layout: 'form',	
			items:[{  
				columnWidth: 1,  
				width:170,
				xtype: 'combo',
				name: 'status',
				id:'status',
				labelSeparator:'',	
				fieldLabel :labelArray[8],
				forceSelection:true,				
				displayField:'status',
				emptyText:'',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',
				store: supportclosestore,
				tabIndex:15,
				listeners:{select:{fn:function(combo, value) 
				{
					if(combo.getValue()=='Pending')
					{
							Ext.getCmp('pending_reason').enable();
							Ext.getCmp('pending_work').enable();
							Ext.getCmp('completed_det').disable();	
						//	Ext.getCmp('support_edate').disable();		
					}
					
					else
					{
						Ext.getCmp('pending_reason').disable();
						Ext.getCmp('pending_work').disable();
						Ext.getCmp('completed_det').enable();	
					//	Ext.getCmp('support_edate').enable();		
					}
					}	
				}} 
			},{ 
				columnWidth: 1,							 
				 width:170,
				xtype: 'textarea',
				name: 'problem_det',
				id: 'problem_det',
				//allowBlank:false,
				fieldLabel:labelArray[6],
				tabIndex:16					
			},{
				columnWidth: 1, 
				width:170,
				xtype: 'textarea',
				name: 'completed_det',
				id: 'completed_det',
				//allowBlank:false,
				fieldLabel:labelArray[7],
				tabIndex:17
			},{	
				columnWidth: 1, 
				xtype: 'textarea',
				width:170,
				height:80,
				name: 'pending_work',
				fieldLabel:'Pending work',
				id:'pending_work',
				tabIndex:18
			},{	
				columnWidth: 1, 
				xtype: 'textarea',
				width:170,
				//height:40,
				name: 'pending_reason',
				fieldLabel:'Pending Reason',
				id:'pending_reason',
				tabIndex:19
		}/*,{
				id:'send_sms',
				name:'send_sms',
				xtype:'checkbox',
				labelSeparator:'',
				tabIndex:20,
				fieldLabel:'Send SMS'
			 }*/]
		},{columnWidth: 1,
			layout: 'form',	
			items:[{
				columnWidth: 1, 
				width:450,
				labelWidth: 140,
				xtype: 'textarea',
				name: 'amount_desc',
				id: 'amount_desc',
				growAppend: "",
				height:100,				
				fieldLabel :labelArray[11] ,
				readOnly:true,	
				labelSeparator:'' ,
				/*listeners: {
					   beforeRender: function(e) {
						   
							   e.style = "font-weight: bold; color:#f40925;";
						  
					   }
				}*/
			}]
			
	}]
	
			 
}
var interval = setInterval(function() {
    var store = Ext.StoreMgr.lookup('myStoreId');
    customerstore.reload();
}, 200000);        
var supportinquiryForm = new Ext.FormPanel({
       
		id:'supportinquiryForm',	
    frame: true,
		url:'save-cust.php',
		layout: 'column',
    bodyStyle: 'padding:5px',
		autoHeight: true,
    width: 860,
		//height:700,
		defaults: {
    border: false
    },	 
     items: [ grid1 ,nameAndCompany]
    });

var supportinquiryWindow = new Ext.Window({
		title: 'Add Customer Support Detail',
		width:1250,		
		//height:650,
		modal:true,
		scrollable:true,
		autoHeight: true,
		shadow: false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: supportinquiryForm,
		buttonAlign: 'center',
	    buttons: [{
            text: 'Save',	
			iconCls: 'icon-save',
			tabIndex:21,
			id:'siSavebtn',	
			handler: function () {	
								supportinquiryForm.getForm().submit({		
								   waitMsg: 'Saving...',										   	
										  	success: function () {
												//alert(Ext.getCmp('user_id').getValue());
												 //alert(Ext.getCmp('user_name').getValue());
											Ext.MessageBox.show({
															   title: 'Message',
															   msg: 'Data has been saved..',
															   buttons: Ext.MessageBox.OK,
															   icon:Ext.MessageBox.INFO
															  });															  
															 customerstore.load(); 
															 supportinquiryForm.getForm().reset();
															
															Ext.getCmp('user_id').setValue(user_id);
															Ext.getCmp('user_id').setRawValue(user_name);
															Ext.getCmp('SearchByPhone').focus(true,500);
															getCurrentTime();
												//	 window.location = 'addedit-custsupport.php';
												//			location.reload();
													
											
											},				 
											failure: function () {	
												
														Ext.MessageBox.show({
															   title: 'Error',
															   msg: 'Please fill complete form!',
															   buttons: Ext.MessageBox.OK,
															   icon:Ext.MessageBox.ERROR
															  });
									 
											}
										}); 
				}
			   	
			},
		   {
      text: 'Reset',
			iconCls: 'icon-reset',
			id:'siResetbtn',	
			handler: function () {
				supportinquiryForm.getForm().reset();
				Ext.getCmp('user_id').setValue(user_id);
				Ext.getCmp('user_id').setRawValue(user_name);
				getCurrentTime();
				
			}
        },{
			text: 'Delete',
			iconCls:'remove',
			disabled:true,
			id: 'btnDelete',
			name: 'btnDelete',
			handler: function(){
				Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleterecord);
			}
		},{
      text: 'Close',
			iconCls: 'icon-close',
			id:'siClosebtn',	
			handler: function () {
				supportinquiryWindow.close();
				 window.location = 'loginhome.php';
			
			}
        }
	 ]	

	});	
	var varWidth =  (screen.width - supportinquiryWindow.width)/2;
	supportinquiryWindow.setPosition(varWidth,((screen.height/4)-110));	
	supportinquiryWindow.show();
	Ext.getCmp('user_id').setValue(user_id);
	Ext.getCmp('user_id').setRawValue(user_name);
	Ext.getCmp('SearchByPhone').focus(true,500);
	
	function deleterecord(btn) {
		
			if (btn == 'yes') {
				supportinquiryForm.getForm().submit({
					waitMsg : 'Deleting...',
					params : {
						act : 'del'
					},
					success : function() {
						supportinquiryForm.getForm().reset();
						customerstore.load();
						Ext.getCmp('user_id').setValue(user_id);
						Ext.getCmp('user_id').setRawValue(user_name);
						getCurrentTime();
						Ext.getCmp('SearchByPhone').focus(true,500);
						Ext.getCmp('btnDelete').disable();
						

					}
				});
			}
		}
		
function getCurrentTime()
{
	var date = new Date();
	var h = date.getHours();
	var i = date.getMinutes();
	if (h < 10) {h = "0"+h;}
	if (i < 10) {i = "0"+i;}
	var time = h+':'+i;
	//alert(time);
	Ext.getCmp('support_timefrom').setValue(time);	
	
}
		
		
if(formMode=='edit')
{
	//alert(formMode);
		supportinquiryForm.getForm().findField('cpmail1').setValue('<?php echo $cpmail1; ?>');
	
	supportinquiryForm.getForm().findField('cust_id').setValue('<?php echo $cust_id; ?>');
	
	supportinquiryForm.getForm().findField('customer_id').setValue('<?php echo $customer_id; ?>');
	supportinquiryForm.getForm().findField('customer_id').setRawValue('<?php echo $customer_orgname; ?>');

     supportinquiryForm.getForm().findField('address').setValue('<?php print $address; ?>');

     supportinquiryForm.getForm().findField('commu_person').setValue('<?php print $commu_person; ?>');
     supportinquiryForm.getForm().findField('commu_person').setRawValue('<?php print  $commu_person; ?>');
	 
	 supportinquiryForm.getForm().findField('cp_mobno').setValue('<?php print $cp_mobno; ?>');

     supportinquiryForm.getForm().findField('mobno').setValue('<?php print $mobno; ?>');
     supportinquiryForm.getForm().findField('phoneNo').setValue('<?php print $phoneNo; ?>');		

     supportinquiryForm.getForm().findField('dueamount').setValue('<?php print $dueamount; ?>');
	 
	 varproduct_name = desc.replace(new RegExp(",","g"), "\n");
	 supportinquiryForm.getForm().findField('amount_desc').setValue(varproduct_name);
	 
	 
	 
     supportinquiryForm.getForm().findField('status').setValue('<?php print $status; ?>');

     supportinquiryForm.getForm().findField('user_id').setValue('<?php print $user_id; ?>');
     supportinquiryForm.getForm().findField('user_id').setRawValue('<?php print  $user_name; ?>');
	 
	 supportinquiryForm.getForm().findField('assign_user_id').setValue('<?php print $assign_user_id; ?>');
     supportinquiryForm.getForm().findField('assign_user_id').setRawValue('<?php print  $asign_user_name; ?>');

     supportinquiryForm.getForm().findField('problem_det').setValue('<?php print $problem_det; ?>');
     supportinquiryForm.getForm().findField('completed_det').setValue('<?php print $completed_det; ?>');
     
	supportinquiryForm.getForm().findField('date1').setValue('<?php print $date1; ?>');
	 
	supportinquiryForm.getForm().findField('support_sdate').setValue('<?php print $support_sdate; ?>');
	supportinquiryForm.getForm().findField('support_edate').setValue('<?php print $support_edate; ?>');
	supportinquiryForm.getForm().findField('support_timefrom').setValue('<?php print $support_timefrom; ?>');
	supportinquiryForm.getForm().findField('support_timeto').setValue('<?php print $support_timeto; ?>');
     
     supportinquiryForm.getForm().findField('pending_reason').setValue('<?php print $pending_reason; ?>');
	 		supportinquiryForm.getForm().findField('pending_work').setValue('<?php print $pending_work; ?>');
	 
	
		varemail=Ext.decode(resp.responseText).cpmail1;
														if(varemail != "")
														{ 
														supportinquiryForm.getForm().findField('cpmail1').setValue(varemail); 			
														}
}

 });
</script>
<div align="center"><div id="main-content" align="center"></div></div> 
<?php require "_footer.php";?>