<?php require "_header.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: #A6CAF0;
	padding: 10px;
	margin-bottom: 10px;
	margin-right: 20px;
	display: block;
}
label.myBold
{
   font-weight: bold;
   color:#666667;
   font-size: 12px;
}
label.myBoldrad
{
   font-weight: bold;
   color:#F00;
   font-size: 12px;
}


    </style>
<?php 
$support_id= Escape($_REQUEST["ID"]);
if ($support_id !="" && isset($support_id)) { 
		$mode="edit";	
		$limit=1;
		$start=0;
		$condition=" and support_id = '$support_id' ";
		$order_field="";
		$order_type="";
		    			
		$objCustomerSupportMgmt = new CustomerSupportMgmt();
		
		$out =  $objCustomerSupportMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
		if (dbRows($out)){
			$row=dbArray($out);
			extract($row);			
		}    	   
}
else{
	$mode="add";
	$support_id=0;
}
?>
<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
<?php require "includeGridFilters.php";?> 
<script type="text/javascript" language="javascript"> 

var formMode = '<?php echo $mode;?>';
var support_id = '<?php  echo $support_id; ?>';

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

var labelArray;
	
	labelArray = [
		['Customer Name :<span class="comp">*</span>'],
		['Support Date :<span class="comp">*</span>'],
		['Support Time :<span class="comp">*</span>'],
		['Distance(K.m):<span class="comp">*</span>'],
		['Support Close:<span class="comp">*</span>'],
		['Next Support Date:<span class="comp">*</span>'],
		['Next Support Time:<span class="comp">*</span>'],
		['Charges(Rs.):<span class="comp">*</span>']
	];
	
	Ext.QuickTips.init();
	
Ext.onReady(function() {
	 var i=0;
	   var total=0;
    var total_debit=0;
    var j =0;  
   
	var h =0 ; 
	var d =0;
	var f ="";
	var n ="";
    var CurrentTextboxId ="";
	var Creditcount=0;
	var Debitcount=0;
    var getcreditid =0;
    var getparentid=0;
    var CAccountHiddenId="";
    var DAccountHiddenId="";
	
	
var checkColumn = new Ext.grid.CheckColumn({
       header: 'Select',
	  dataIndex:'selected',
	  id: 'selected',
	  name: 'selected',
	  width: 55
    });
var supportclosestore = new Ext.data.ArrayStore({
           fields: ['supportclose'],
	       data: [['Yes'],['No']]
}); 


var allowanceTypestore = new Ext.data.ArrayStore({
           fields: ['allowancetype'],
	       data: [['Bus'],['Auto'],['Train'],['Petrol'],['Stay'],['Food']]
});

var serviceTypestore = new Ext.data.ArrayStore({
           fields: ['sevicetype_combo'],
	       data: [['Free'],['Chargable']]
});

function formatDate(value){
        return value ? value.dateFormat('d/M/Y') :'';
    }
	
		
store = new Ext.data.JsonStore({
       	autoDestroy: true,
        url:'data/getcustomersupportproduct.php',
        remoteSort: true,
        sortInfo: {
            field: 'product_id',
            direction: 'ASC'
        },        
        idProperty: 'product_id',
        root: 'data',
        totalProperty: 'total',
        fields: [{
            name: 'product_id',
			type: 'int'
        }, {
            name: 'product_name'
        },
		{name:'selected',type: 'bool'},
		{name:'purchasedate',type: 'date'},
		{name:'servicetype'}
		]
    });
	
	var servicetype_combo = new Ext.form.ComboBox({
	name: 'servicetype_combo',
	id:'servicetype_combo',
	allowBlank:false,
	fieldLabel: 'Subject',
	forceSelection:true,				
	displayField:'sevicetype_combo',
	valueField: 'sevicetype_combo',
	width: 50,
	emptyText:'Subject'
	,triggerAction:'all'
	,mode:'local'
	,store: serviceTypestore
	,editable:true

});
    
var createColModel = function (finish,start) {
        var columns = [
			checkColumn,
		{
            dataIndex: 'product_id',
			header: 'Product ID',
			hidden:true
			
        }, {
            dataIndex: 'product_name',
			header: 'Product Name',
			width: 320
        },{
			header: 'Purchase Date',
			dataIndex:'purchasedate',
			id:'purchasedate',
			name: 'purchasedate',
			renderer: formatDate,
			width: 95
		 },{ 
			id: 'servicetype',
			name: 'servicetype',
			header: "Service Type",
			width: 100,
			dataIndex:'servicetype',
			align: 'left',
			sortable: true,
			editor: servicetype_combo
        }
		 
		 ];
		return new Ext.grid.ColumnModel({
            columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    }
	
var grid = new Ext.grid.EditorGridPanel({
        store: store,
		colModel: createColModel(40), 
        loadMask: true,
		clicksToEdit: 1,
		frame: false,
		enableColLock:false,
		height:140,    
        width: 590,
        layout: 'fit',
		columnLines:true,
		plugins: checkColumn
    });

			
var from = { columnWidth: .38,
    layout: 'form',
	labelWidth: 130,
    items: [{
					xtype: 'timefield',
					name: 'support_timefrom',
					labelSeparator:'',	
					fieldLabel :labelArray[2] 
					,width:94
					,emptyText:'Start'
					,allowBlank:false
					,id: 'support_timefrom'
				 }]
}

var to = {columnWidth: .59,
    layout: 'form',
	labelWidth: 1,
    items: [{
					xtype: 'timefield',
					name: 'support_timeto'
					,width:94
					,emptyText:'End'
					,allowBlank:false
					,id: 'support_timeto'
				 }]
}

var distance = {columnWidth: 1,
    layout: 'form',
	labelWidth: 130,
    items: [{
					xtype: 'numberfield',
					name: 'distance',
					maxLength:4
					,width:95
					,labelSeparator:''
					,fieldLabel :labelArray[3] 
					,allowBlank:false
					,id: 'distance'
					,autoCreate: {tag: 'input', type: 'text',maxlength: '4'}
				 },
			     {
					xtype: 'numberfield',
					name: 'Charges',
					width:95
					,labelSeparator:''
					,fieldLabel :labelArray[7] 
					,id: 'Charges'
					,readOnly:true
					,autoCreate: {tag: 'input', type: 'text',maxlength: '4'}
				 },
				  {
					xtype: 'textfield',
					name: 'support_id'
					,id: 'support_id'
					,value:support_id
					,hidden:true
				 }]
}
var busAddress = { columnWidth: 1,
    layout: 'form',
	labelWidth: 130,
    items: [{   width:130,
				xtype: 'combo',
				name: 'supportclose',
				id:'supportclose',
				labelSeparator:'',	
				fieldLabel :labelArray[4],
				forceSelection:true,				
				displayField:'supportclose',
				valueField: 'supportclose',
				emptyText:'',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',
				store: supportclosestore,
   				listeners:{select:{fn:function(combo, value) 
                {
					if(combo.getValue()=='No')
					{
						Ext.getCmp('nextsupportdate').enable();
						Ext.getCmp('nextsupporttime').enable();
						Ext.getCmp('workcomment').enable();
					}
					else
					{
						Ext.getCmp('nextsupportdate').reset();
						Ext.getCmp('nextsupporttime').reset();
						Ext.getCmp('nextsupportdate').disable();
						Ext.getCmp('nextsupporttime').disable();
					}
				}	
				}}

				},{
				xtype: 'datefield',
				name: 'nextsupportdate',
				labelSeparator:'',	
				allowBlank:false,
				fieldLabel :labelArray[5] 
				,width:130
				,disabled:true
				,id: 'nextsupportdate'
				,vtype: 'daterange'
				 
			  },{
			  xtype: 'timefield',
				name: 'nextsupporttime',
				labelSeparator:'',	
				fieldLabel :labelArray[6] 
				,width:130
				,allowBlank:false
				,disabled:true
				,id: 'nextsupporttime'
				 
			  }]
}

var comment1 = {columnWidth: .5,
    layout: 'form',
	labelWidth: 60,
    items: [{
			  layout: 'form',					
			  items:[{	xtype: 'textarea',
						width:230,
						name: 'workcomment',
						fieldLabel:'Work',
						id:'workcomment'
					 }]				
		  }]
}

var comment2 = {columnWidth: .5,
    layout: 'form',
	labelWidth: 60,
    items: [{
			  layout: 'form',					
			  items:[{	xtype: 'textarea',
						width:230,
						name: 'pendingcomment',
						fieldLabel:'Pending',
						id:'pendingcomment'
					 }]				
		  }]
}
 
var nameAndCompany = { columnWidth: 1,
    layout: 'form',
	labelWidth: 130,
    bodyStyle:'padding-top:1px',
    items: [
		   {
				xtype: 'combo',
			   	name: 'customer_id',
			   	id:'customer_id',
				hiddenName: 'customer_idhedden',
				tabIndex:3,
				labelSeparator:'',	
				fieldLabel :labelArray[0] ,
				displayField:'customer_orgname',
				tabIndex:3,
				valueField: 'customer_id',
				width: 200,
				blankText: '',
				emptyText:'',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',			
				selectOnFocus: true,	
				store: customersore,
				forceSelection:true,
				editable:true,
				listeners:{select:{fn:function(combo, value) 
												{										      
													custid=combo.getValue('customer_id'); 
												    store.load({
														params: {customer_id:custid}
													});
												}
											  }
									   }
				
				
				
				
		  	},{
				xtype: 'datefield',
				name: 'support_date',
				labelSeparator:'',	
				fieldLabel :labelArray[1] 
				,width:200
				,allowBlank:false
				,id: 'support_date'
				,vtype: 'daterange'
				 
			  }]
}


////

var CreditAccountfieldSet = {
		id:'formParamsTableau',
		border     : false,
		height     : 150,	
		frame:false,
	    labelWidth:10,
        width:450,
        autoScroll:true,
        title: '',
	    items:[
			{        	
				layout:'column',				
        		id:'formParamsTableau_CreditAccountHiddenId',
        		layout: 'form',
				hidden:true,
	      		labelWidth  : 1,
				width:20,
        		columnWidth:.58
        	},
			{        	
				layout:'column',
				items:[{
        		id:'formParamsTableau_CreditAccount',
        		layout: 'form',
		   		labelWidth  : 50,
				width:20,
        		columnWidth:.58
        	},
			{
        		id:'formParamsTableau_CreditAmount',
				name:'creditamount',
        		layout: 'form',
				labelWidth  : 1,
				width:20,
        		columnWidth:.32
        	},{
        		id:'formParamsTableau_CreditDelete',
        		layout: 'form',
        		labelWidth  : 1,
				width:20,
		 		columnWidth:.10				 
        		}
        	]
        }]				
  }
var btn=new Ext.Button({
                           id:'btn',
						   style: 'padding:0px 33px',	
						   iconCls: 'icon-add',
						   handler: function () { 
						              account();
							}						                        
                         });
						 
function account()
{					
			var Add_CreditAccount=Ext.getCmp("formParamsTableau_CreditAccount");
			
			var Add_CreditAmount=Ext.getCmp("formParamsTableau_CreditAmount");
			
			var Add_CreditDelete=Ext.getCmp("formParamsTableau_CreditDelete");
			
			var Add_CreditAccountHiddenId=Ext.getCmp("formParamsTableau_CreditAccountHiddenId");	
			
			if(CheckItem(Add_CreditAmount.id) && CheckItem(Add_CreditAccount.id)) {								
			
			i++;						
			
			var CreditAccount='CreditAccount' + i;
			
			var CreditAmount='CreditAmount' + i;
			
			var CreditDelete='CreditDelete' + i;
			
			var CreditAccountHiddenId='CreditAccountHiddenId' + i;
		    
		//	Creditaccountid[i-1] = "" ;			
			
		/*	var txtcreditAccount =new Ext.form.TextField({
					width:190,
					height:20,
					allowBlank:false,
					id :CreditAccount,
					name:'CreditAccount'
				 });*/
				 
				 
				 
			 var txtcreditAccount = new Ext.form.ComboBox({
					id :CreditAccount,
					name:'CreditAccount',
					allowBlank:false,
					editable:true,
					forceSelection:true,				
					displayField:'allowancetype',
					valueField: 'allowancetype',
					width: 190,
					height:30
					,triggerAction:'all'
					,mode:'local'
					,store: allowanceTypestore
				
				});
				 
				 
			var AccountHiddenId =new Ext.form.TextField({
					width:190,
					height:40,
					allowBlank:false,
					id :CreditAccountHiddenId,
					hidden:true,
					name:'CreditAccountHiddenId'
					
					
				 });				 
				
				Add_CreditAccount.add(txtcreditAccount);
			    
				
			    var txtcreditAmount =new Ext.form.NumberField({			          
						allowBlank:false,
						width:100,
						height:22,
						id:CreditAmount,
						name:'CreditAmount',
						allowNegative: false,
						blankText  :'This field required only positive value',
						enableKeyEvents: true,
						autoCreate: {tag: 'input', type: 'text',  maxlength: '4'}
						
				});
		
				Add_CreditAmount.add(txtcreditAmount);	
		
				txtcreditAmount.on('keyup', function(){
		   
		    				    creditAmountValue  = this.getValue() ;	
								getcreditid = this.getId();								
								getparentid = Add_CreditAmount.id;
					    		 CreditTotal = getCreditTotal(getcreditid,getparentid);						   		
								 TotalAccount(CreditTotal,creditAmountValue);
		 		});
							
			Add_CreditDelete.add({
								xtype:'button',
								iconCls:'remove',
								id:CreditDelete,
								height:22,
								width:20,
								style:{margin:'0px 0px 0px 0px',padding:'0px 0px 4.5px 0px'},	
								handler: function () {																							           	 							       
								
												var Component1 = Ext.getCmp(CreditAccount);
												var Component2 = Ext.getCmp(CreditAmount);
												var Component3 = Ext.getCmp(CreditDelete);
												var Component4 = Ext.getCmp(CreditAccountHiddenId);																									
												var creditAccountId = Component1.id;
																								
												var delind = creditAccountId.replace("CreditAccount","");
												
				   								delind = parseInt(delind) - 1;
												
												if(delind != 0) {
													
													var MinusValue =Component2.getValue();
																
															if(MinusValue=="")
															{
															  var minusvaluecredit=0;
															  var TotalValue = Ext.getCmp('txtTotalCredit').getValue();
													          TotalValue = parseFloat(TotalValue) - parseFloat(minusvaluecredit)
													          Ext.getCmp('txtTotalCredit').setValue(TotalValue);
															}
															else
															{
																								
													var TotalValue = Ext.getCmp('txtTotalCredit').getValue();
													
													TotalValue = parseFloat(TotalValue) - parseFloat(MinusValue)
													Ext.getCmp('txtTotalCredit').setValue(TotalValue);
											        
												          }
																																					
													removefield_credit(Component4,Component1,Component2,Component3);																				
												}
										   }	
				
								});		 
			
			inquiryForm.doLayout();	
			}
			
			
  }	
function  CheckItem(parentId){
   
   	var cntElement = Ext.getCmp(parentId).items.length;
	
	if(cntElement==0)
		return true;
			
	for(t=0;t<cntElement;t++) {			 			 	
		
		cnt 	= Ext.getCmp(parentId).items.get(t);	
		cntValue  = Ext.getCmp(cnt.id).getValue();									
	  
		if(cntValue == "") {				
			
		Ext.MessageBox.show({
							  title: 'Error',
							  msg: 'Empty not allowed !',
							  buttons: Ext.MessageBox.OK,
							  icon:Ext.MessageBox.ERROR
		                     });
			return false;
		}		
	 }		
	 return true;
   }
   function TotalAccount(CreditTotal,creditAmountValue){
   
	   if(creditAmountValue > 0) {										  
			CreditTotal	= CreditTotal + parseFloat(creditAmountValue) ;	
			
	   }   
	  
	 Ext.getCmp('txtTotalCredit').setValue(CreditTotal);
	 
									
   }
   
   function getCreditTotal(Id,parentId)  
  {		   
	 var cntElement = Ext.getCmp(parentId).items.length;
	 
	 Creditcount 	=	cntElement;
	 
	 var cnt;
	 var amount=0;
	 var TotalAmount=0;
	 var t=0;
	 
	 for(t=0;t<cntElement;t++) {			 			 	
		
		cnt 	= Ext.getCmp(parentId).items.get(t);	
		amount  = Ext.getCmp(cnt.id).getValue();						
			
		if(cnt.id != Id) {						
			if(amount > 0) {			
				TotalAmount = TotalAmount + parseFloat(amount);				
			}						
		}
		
	 }		 	 			 
	 return TotalAmount;
   }
 function removefield_credit(comp1,comp2,comp3,comp4)
{
	var Add_CreditAccount=Ext.getCmp("formParamsTableau_CreditAccount");
	var Add_CreditAmount=Ext.getCmp("formParamsTableau_CreditAmount");
	var Add_CreditDelete=Ext.getCmp("formParamsTableau_CreditDelete");
	var Add_CreditAccountHiddenId=Ext.getCmp("formParamsTableau_CreditAccountHiddenId");

    Add_CreditAccountHiddenId.remove(comp1);
	Add_CreditAccount.remove(comp2);
	Add_CreditAmount.remove(comp3);
	Add_CreditDelete.remove(comp4);
	
	inquiryForm.doLayout();																									
												
}	

function resetvoucher(){
		
	 	
	Ext.getCmp("formParamsTableau_CreditAccount").removeAll();
	Ext.getCmp("formParamsTableau_CreditAmount").removeAll();
	Ext.getCmp("formParamsTableau_CreditDelete").removeAll();
	Ext.getCmp("formParamsTableau_CreditAccountHiddenId").removeAll();
	i=0;
	account();
	inquiryForm.getForm().reset();
	store.removeAll();
		
 } 
 var inquiryForm = new Ext.FormPanel({
        frame: true,
		url:'save-support.php',
        bodyStyle: 'padding:5px',
		autoHeight: true,
		//layout: 'accordion',
        width: 600,	
			defaults: {
            border: false
           },	
            items: [{
				//xtype: 'fieldset',
				bodyStyle: 'padding:10px',
               //title: 'Add Suport',
                layout: 'column',	
                items: [nameAndCompany,from,to,distance/*,{
				  	xtype: 'box',
					style:'margin:0px 20px 0px 0px',
					height		: 140,
					width		: 300,										       
					autoEl: { tag: 'div',
						html: '<img id="pic" src="images/contact.jpg" alt="photograph"width=300 height=128/>'
					}}*/]
            },{
                    xtype: 'fieldset',
					title: 'Product',
					autoHeight: true,
					collapsible: true,
					collapsed: true,
                    layout: 'column',
                    items: [grid]
		
				},{
					xtype: 'fieldset',
					title: 'Support Conformation',
					collapsible: true,
					collapsed: false,
					autoHeight: true,
                    layout: 'column',
                    items: [busAddress]
		
				},{
                    xtype: 'fieldset',
					title: 'Support Comment',
					autoHeight: true,
					collapsible: true,
					collapsed: false,
                    layout: 'column',
                    items: [comment1,comment2]
		
				},{
                    xtype: 'fieldset',
					title: 'Expenses',
					autoHeight: true,
					collapsible: true,
					collapsed: false,
                    layout: 'column',
                    items: [{  
								xtype: 'label',
								text:"Expenses",
								name: 'per',	
								cls: 'x-form-item myBold',
								style: 'padding:0px 110px',										
								id:'per'
							 },{  
								xtype: 'label',
								text:"Amount",
								name: 'per',	
								cls: 'x-form-item myBold',
								style: 'padding:0px 23px 10px',										
								id:'Amount'
							 },btn,CreditAccountfieldSet,
							 {  
								xtype: 'label',
								text:"Total",
								name: 'total',	
								cls: 'x-form-item myBoldrad',
								style: 'padding:0px 118px',											
								id:'Total'
							 },{  
								xtype: 'textfield',									
								id:'txtTotalCredit',
								name: 'txtTotalCredit',
								width		: 100,	
								height		: 25,
								style: 'padding:0px 3px '
							 }]
		
				}]
    });
	

var inquiryWindow = new Ext.Window({
		title: 'Customer Support',
		width:660,		
		height:700,
		modal:true,
		scrollable:true,
		autoHeight: true,
		shadow: false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: inquiryForm,
		buttonAlign: 'center',
	    buttons: [{
            text: 'Save',	
			iconCls: 'icon-save',		
			handler: function () {			  
			  var selectedproduct_ids = "";
				var produdct_id= "";
				var selectedproduct_servicetype = "";
				var purchasedate= "";
				cnt=0;
				len = grid.store.getCount();
				for(var i = 0; i < len; i++)
				{
					var record = grid.store.getAt(i);
					if(record.data.selected == true  )
					{
						if(record.data.servicetype!="")
						{
							produdct_id =record.data.product_id;	
							servicetype =record.data.servicetype	
							selectedproduct_ids = selectedproduct_ids + produdct_id + ",";
							selectedproduct_servicetype = selectedproduct_servicetype + servicetype + ",";						
						}
						else
						{
							cnt=1;
							i = len;							
						}						
					}					
				}				
				if(produdct_id=="")
				{
					Ext.MessageBox.show({
						title: 'Error',
					   	msg: 'Please select product',
					   	buttons: Ext.MessageBox.OK,
					   	icon:Ext.MessageBox.ERROR
					});
				}
				else if(cnt==1){
						Ext.MessageBox.show({
							title: 'Error',
							msg: 'Please select Service Type.',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.ERROR
						});	
				}
				else
				{
					selectedproduct_ids= selectedproduct_ids.substr(0,selectedproduct_ids.length - 1);
					selectedproduct_servicetype= selectedproduct_servicetype.substr(0,selectedproduct_servicetype.length - 1);
				   //code For Expenses
										var Add_CreditAmount=Ext.getCmp("formParamsTableau_CreditAmount");
										var Add_CreditAccountHiddenId=Ext.getCmp("formParamsTableau_CreditAccount");
										var arrayExpensesAmount=  new Array();
										var arrayExpensesName=  new Array();
																			
										var varParentID ="";
										var cntElement=0;

										varParentID =Add_CreditAccountHiddenId.id;
									    cntElement = Ext.getCmp(varParentID).items.length;
										for(t=0;t<cntElement;t++) {			 			 										
											cnt 	= Ext.getCmp(varParentID).items.get(t);	
											hiddendId  = Ext.getCmp(cnt.id).getValue();
											arrayExpensesName[t] =	hiddendId;	
										 }
										 
										 varParentID =Add_CreditAmount.id;
										 cntElement = Ext.getCmp(varParentID).items.length;
										 for(t=0;t<cntElement;t++) {			 			 										
											cnt 	= Ext.getCmp(varParentID).items.get(t);	
											amount  = Ext.getCmp(cnt.id).getValue();
											arrayExpensesAmount[t] =	amount;																		
										 }
										 
								inquiryForm.getForm().submit({
										  waitMsg: 'Saving...',
										   params  : {
														expensesname: Ext.util.JSON.encode(arrayExpensesName),
														expensesamount: Ext.util.JSON.encode(arrayExpensesAmount),
														product_ids:selectedproduct_ids,servicetype:selectedproduct_servicetype
													},		
											success: function () {
											Ext.MessageBox.show({
															   title: 'Message',
															   msg: 'Data has been saved..',
															   buttons: Ext.MessageBox.OK,
															   icon:Ext.MessageBox.INFO
															  });
															 resetvoucher();
															  if(formMode=='edit'){
																location.href="view-support.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',
			handler: function () {
			if(formMode!='edit'){
				resetvoucher();
			}
			}
        },
	 	           {
            text: 'Close',
			iconCls: 'icon-close',
			handler: function () {
			if(formMode=='edit'){
				location.href="view-product-inquiry.php";
			}else
			{
				inquiryWindow.close();
			 }	
			}
        }
	 ]

	});
	
	var varWidth =  (screen.width - inquiryWindow.width)/2;
	inquiryWindow.setPosition(varWidth,((screen.height/4)-110));
	
	inquiryWindow.show();
	
	
 if(i==0){	
		account();
  }	
	
	if(formMode=='edit'){
	<?php
	
	$support_work 			= replaceSpecial($support_work);
	$support_pending 		= replaceSpecial($support_pending);
	
	?>
		inquiryForm.getForm().findField('support_date').setValue('<?php print $support_date; ?>');
		inquiryForm.getForm().findField('support_timefrom').setValue('<?php print $support_stime; ?>');
		inquiryForm.getForm().findField('support_timeto').setValue('<?php print $support_etime; ?>');
		
		customersore.on({'load':{
			fn: function(store, options){
				inquiryForm.getForm().findField('customer_id').setRawValue('<?php print $customer_id; ?>');
				inquiryForm.getForm().findField('customer_id').setValue('<?php print $customer_id; ?>');	
			}
		}});
		
		inquiryForm.getForm().findField('distance').setValue('<?php print $support_distance; ?>');
		inquiryForm.getForm().findField('Charges').setValue('<?php print $support_charge; ?>');
		inquiryForm.getForm().findField('supportclose').setValue('<?php print $support_close; ?>');
		
		if('<?php print $support_close; ?>'=='No')
		{
						Ext.getCmp('nextsupportdate').enable();
						Ext.getCmp('nextsupporttime').enable();
						inquiryForm.getForm().findField('nextsupportdate').setValue('<?php print $nextsupport_date; ?>');
     					inquiryForm.getForm().findField('nextsupporttime').setValue('<?php print $nextsupport_time; ?>');
		}
		inquiryForm.getForm().findField('workcomment').setValue('<?php print $support_work; ?>');
     	inquiryForm.getForm().findField('pendingcomment').setValue('<?php print $support_pending; ?>');
		
		store.load({
						params: {support_id:'<?php print $support_id; ?>',editcustomer_id:'<?php print $customer_id; ?>'}
					});
		
	
	}
	
<?php
	if($mode=="edit"){
	$credit_index = 1;	
	$debit_index = 1;	
	$objSupportExpencsesMgmt=new SupportExpencsesMgmt();
	$where="And support_id = $support_id";
		
		$out_det =  $objSupportExpencsesMgmt->getAllRecords(0,0,$where,$order_field,$order_type) ;
	    while($row_det = dbArray($out_det)){
	   
		if($credit_index != 1)
		{ ?> account(); <?php } 
						  ?> 	
inquiryForm.getForm().findField('CreditAccount'+'<?php echo $credit_index ; ?>').setValue('<?php echo $row_det["expenses"]; ?>');
inquiryForm.getForm().findField('CreditAmount'+'<?php echo $credit_index ; ?>').setValue('<?php echo $row_det["cost"] ; ?>'); 
	
				  <?php
				  $finalTotal+=$row_det["cost"];
				  $credit_index++;        
			}?>
			Ext.getCmp('txtTotalCredit').setValue('<?php echo $finalTotal; ?>');
			<?php	 	   
	
	   }
	?>


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