<?php require "_header.php"; ?>
<?php require "includeGridFilters.php";?> 
<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>

 
 <?php 
 require "commonincludefiles.php";

$customer_id = Escape($_REQUEST["customer_id"]);
 	if ($customer_id !="" && isset($customer_id)){
		$mode="edit";
		if($EDIT == "false")
		{   
		    redirectToPage();
		}
		 
	$rs = "SELECT lc.*, 
(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, 
lci.dueamount 
FROM lms_cust as lc 
INNER JOIN lms_customerinvoice as lci ON lc.customer_id= lci.customer_id 
WHERE lc.customer_id = '".$customer_id."'";
		$out = dbQuery($rs);  
		if (dbRows($out)){
			$row = dbArray($out);
			extract($row);			
		} 
	}else{
		$mode="add";
		if ($ADD == "false")
		{
			 redirectToPage();
		}
		echo $mode;
		echo $cust_id;
		$customer_id=0;
	}
	
	 
?>

 
<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 formMode = '<?php echo $mode;?>';
var customer_id = '<?php  echo $customer_id; ?>';
var add = '<?php echo $_REQUEST["add"]; ?>';

var customerstore = new Ext.data.Store({
		url: 'data/getcust.php',          
		reader: new Ext.data.JsonReader({			
	fields: ['cust_id','date1','customer_orgname','address','commu_person','mobno','phoneNo','problem_det','completed_det','status','pending_reason','pending_work','user_id','customer_id','user_name'],
			root: 'rows1'
		}),autoLoad:true
	});
//end 
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 custname_store = new Ext.data.Store({
		url: 'data/getcustomername1.php',          
		reader: new Ext.data.JsonReader({			
			fields: ['customer_id','customer_orgname'],
			root: 'rows'
		}),autoLoad:true
	});

var labelArray;
	
	labelArray = [
		['Date :<span class="comp">*</span>'],
		['Customer Name :<span class="comp">*</span>'],
		['Address :<span class="comp">*</span>'],
		['Communicated Person:<span class="comp">*</span>'],
		['Mobile No '],
		['Landline No '],		
		['Problem Detail:<span class="comp">*</span>'],
		['Completed Work Detail:<span class="comp">*</span>'],
		['Status:<span class="comp">*</span>'],
		['User Name:<span class="comp">*</span>']		
		
	];
	
	
	if(customer_id==""){
	customer_id = 0;
	
}
   Ext.QuickTips.init();
Ext.onReady(function() {
	// var xg = Ext.grid;	 
	var encode = false;
	var local = false;
 
var createColModel = function (finish, start) {
        var columns = [		
	 	{
			width:150,
            dataIndex: 'pending_reason',
			header: 'pending reason',
			tabIndex:11
			//hidden:true
        }, {
			width:150,
            dataIndex: 'pending_work',
			header: 'pending work',
			tabIndex:12
        }];
		return new Ext.grid.ColumnModel({
            columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    };
	  
 	
var supportclosestore = new Ext.data.ArrayStore({
           fields: ['status'],
	       data: [['Pending'],['Completed'],['on work']]
}); 
var work = {
	columnWidth: 0.5,
     layout: 'form',
	//labelWidth: 220,
    style: 'padding:0px 10px',
	
     items: [
	 			{   
				 width:170,
				xtype: 'combo',
				name: 'status',
				id:'status',
				labelSeparator:'',	
				fieldLabel :labelArray[8],
				forceSelection:true,				
				displayField:'status',
				valueField: 'status',
				emptyText:'',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',
				store: supportclosestore,
				tabIndex:7,
   				listeners:{'select':function(combo, value) 
                					{
					//alert(Ext.getCmp('status').getRawValue());
										if(Ext.getCmp('status').getRawValue() == 'Pending')
										{
												Ext.getCmp('pending_reason').enable();
												Ext.getCmp('pending_work').enable();
										}
										else
										{
											Ext.getCmp('pending_reason').disable();
											Ext.getCmp('pending_work').disable();											
										}
									}	
							}

				},
	 			{ width:170,
					xtype: 'textarea',
					name: 'problem_det',
					id: 'problem_det',
					allowBlank:false,
					tabIndex:8,
					fieldLabel:labelArray[6]
				 },
				 {
				    width:170,
					xtype: 'textarea',
					name: 'completed_det',
					id: 'completed_det',
					allowBlank:false,
					tabIndex:9,
					fieldLabel:labelArray[7]
				 },
				
				{
				 		 
				xtype: 'combo',
			   	name: 'user_id',
			   	id:'user_id',
				hiddenName: 'user_idhedden',
				forceSelection:true,
				tabIndex:10,
				labelSeparator:'',	
				fieldLabel :labelArray[9] ,
				displayField:'user_name',
				valueField: 'user_id',				
				width: 170,
				blankText: '',
				emptyText:'user_name',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',			
				selectOnFocus: false,	
				store:userstore ,
				readOnly: true,
			 	editable:false,
				//disable:true
				},
				 
	            
				{	xtype: 'textarea',
						width:230,
						height:40,
						name: 'pending_reason',
						fieldLabel:'Pending Reason',
				     	id:'pending_reason',
						tabIndex:11
			     },
				 {	xtype: 'textarea',
						width:230,
						height:40,
						name: 'pending_work',
						fieldLabel:'Pending work',
						id:'pending_work',
						tabIndex:12
				 }
			]
		//}]
}
var nameAndCompany = {
	// columnWidth: 1,
	 columnWidth: 0.5,
    layout: 'form',
	labelWidth: 110,
    style: 'padding:0px 10px',
    items: [	 
				{		
				xtype: 'hidden',
				name: 'cust_id',
				id:'cust_id',
				hidden:true,
			   store:customerstore,
				dataIndex: 'cust_id',
				//displayField:'cust_id',
				//valueField: 'cust_id',
				//value:cust_id
				}, 
				
			 {
				xtype: 'datefield',
				name: 'date1',
				labelSeparator:'',	
				fieldLabel :labelArray[0], 
				width:170, 
				tabIndex:1,
				allowBlank:false,
				id: 'date1',
				vtype: 'daterange',
				value:new Date()

			  },
			{
 
				xtype: 'combo',
				name: 'customer_orgname',
			   	id:'customer_orgname',
				hiddenName: 'customer_idhedden',
				forceSelection:true,
				tabIndex:2,
				labelSeparator:'',	
				fieldLabel :labelArray[1] ,
				displayField:'customer_orgname',
				valueField: 'customer_id',
				width: 170,
				blankText: '',
				emptyText:'customer_orgname',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',			
				selectOnFocus: true,	
				store:custname_store ,
   				editable:false ,
				listeners:{select:{fn:function(combo, value) 
				{			
										var varcustid=0;
										varcustid=combo.getValue('customer_id'); 		
										 								      
										var custid = supportinquiryForm.getForm().findField('customer_orgname').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
											{	
												// alert("This schoold name record is empty");	
											     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();											     
											} 
											
											varmob=Ext.decode(resp.responseText).mob1;
											if(varmob != "")
											{ 
											supportinquiryForm.getForm().findField('mobno').setValue(varmob); 			
											}
											else
											{	  
												 Ext.getCmp("mobno").reset(); 
											}
											 
											varphoneNo=Ext.decode(resp.responseText).ph;
											if(varphoneNo != "")
											{ 
											supportinquiryForm.getForm().findField('phoneNo').setValue(varphoneNo); 			
											}
											else
											{	
												   Ext.getCmp("phoneNo").reset(); 
											}


											dueamount = Ext.decode(resp.responseText).due;
											if(dueamount != "")
											{ 
											supportinquiryForm.getForm().findField('dueamount').setValue(dueamount); 			
											}
											else
											{	
												   Ext.getCmp("dueamount").reset(); 
											}


											
										}				
									});
								}}
				 } 
			
			},{
				  width:170,
				  xtype: 'textarea',
				  name: 'address',
				  id: 'address',
				  allowBlank:false,
				  fieldLabel :labelArray[2] ,
                  tabIndex:3,	
		      },{ 
			        width:170,
					xtype: 'textfield',
					name: 'commu_person',
					id: 'commu_person',
					fieldLabel:labelArray[3],
					allowBlank:false,
					tabIndex:4
					
				 },
				 { width:170,
					xtype: 'textfield',
					name: 'mobno',
					id: 'mobno',
					minLength:10,
					maxLength:10,	
					fieldLabel:labelArray[4],
					//allowBlank:false,
					tabIndex:5,
					autoCreate: {tag: 'input', type: 'text',  maxlength: '13'},
                    enableKeyEvents: true
					,listeners:{
									keyup: validphoneno
					           }  								
			
					
				 },
				 { 
					xtype: 'textfield',
					name: 'phoneNo',
					id: 'phoneNo',
					width:170,
					minLength:8,
					maxLength:11,	
					//allowBlank:false,
					fieldLabel:labelArray[5],
					autoCreate: {tag: 'input', type: 'text',  maxlength: '13'},
                    enableKeyEvents: true,
					tabIndex:6,
					listeners:{
									keyup: validphoneno
					           } 
				 },
				 {
					xtype: 'textfield',
					name: 'dueamount',
					id: 'dueamount',
					width:170,
					readOnly:true,
					allowBlank:false,
					fieldLabel:'Dueamount',
					//autoCreate: {tag: 'input', type: 'text',  maxlength: '13'},
					listeners: {
					       beforeRender: function(e) {
					               e.style = "font-weight: bold; color:#f40925;";
					          
					       }
					}
										
                 }]
}
var supportinquiryForm = new Ext.FormPanel({
       
		id:'supportinquiryForm',	
        frame: true,
		url:'save-cust.php',
		layout: 'column',
        bodyStyle: 'padding:5px',
		autoHeight: true,
        width: 400,
		//height:700,
			
			defaults: {
            border: false
           },	
		   
            items: [nameAndCompany,work]
    });
	

var supportinquiryWindow = new Ext.Window({
		title: 'View Customer Support Information',
		width:800,		
		//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:13,
			id:'siSavebtn',	
			handler: function () {	
										 
								supportinquiryForm.getForm().submit({
									  			
										  waitMsg: 'Saving...',
										  //params:{cust_id:Ext.getCmp('cust_id').getValue()},	
										  	success: function () {
											Ext.MessageBox.show({
															   title: 'Message',
															   msg: 'Data has been saved..',
															   buttons: Ext.MessageBox.OK,
															   icon:Ext.MessageBox.INFO
															  });															 
															 customerstore.reload();
															  if(formMode=='edit'){
																location.href="loginhome.php";
															 }
													
											},
											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',
			tabIndex:14,
			id:'siResetbtn',	
			handler: function () {
			supportinquiryForm.getForm().reset();
			//customerstore.removeAll();
			}
        },
	 	   {
            text: 'Close',
			iconCls: 'icon-close',
			id:'siClosebtn',	
			tabIndex:15,
			handler: function () {
				supportinquiryWindow.close();
				window.location = 'loginhome.php';
			
			}
        }]
	});	

	var varWidth =  (screen.width - supportinquiryWindow.width)/2;
	supportinquiryWindow.setPosition(varWidth,((screen.height/4)-110)); 
	supportinquiryWindow.show();
	
	/*supportinquiryWindow.on('hide',function(){
		customerstore.load();
	});*/
	 	
if(formMode=='edit')
{

	 supportinquiryForm.getForm().findField('cust_id').setValue('<?php echo $cust_id; ?>');

	 supportinquiryForm.getForm().findField('customer_orgname').setValue('<?php echo $cust_id; ?>');
	 supportinquiryForm.getForm().findField('customer_orgname').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('mobno').setValue('<?php print $mobno; ?>');
     supportinquiryForm.getForm().findField('phoneNo').setValue('<?php print $phoneNo; ?>');		

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

     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('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('pending_reason').setValue('<?php print $pending_reason; ?>');
	 supportinquiryForm.getForm().findField('pending_work').setValue('<?php print $pending_work; ?>');
	
}
});
</script>
<div align="center"><div id="main-content" align="center"></div></div> 
<?php require "_footer.php";?>