<?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 = [
		['Order No :<span class="comp">*</span>'],
		['EStore Name :<span class="comp">*</span>'],
		['Contact :<span class="comp">*</span>'],
		['Billing Address :<span class="comp">*</span>'],
		['Shipping Address :<span class="comp">*</span>'],

		['Product Name:<span class="comp">*</span>'],
		['Qty:<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 allowanceTypestore = new Ext.data.ArrayStore({
           fields: ['allowancetype'],
	       data: [['MFS110 L1'],['MFS100V54'],['MIS100V2']]
});

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 distance = {columnWidth: 1,
    layout: 'form',
	labelWidth: 130,
    items: [{
					xtype: 'textfield',
					name: 'address',
				
						width:300
					,labelSeparator:''
					,fieldLabel :labelArray[3] 
					,allowBlank:false
					,id: 'address'
					
				 },
				 {
					xtype: 'textfield',
					name: 'address1',
				
						width:300
					,labelSeparator:''
					,fieldLabel :labelArray[4] 
					,allowBlank:false
					,id: 'address1'
					
				 },
			     {
					xtype: 'textfield',
					name: 'estore_phoneno',
					width:300
					,labelSeparator:''
					,fieldLabel :labelArray[2] 
					,id: 'estore_phoneno'
					,readOnly:true
					
				 },
				  {
					xtype: 'textfield',
					name: 'product_name',
					width:300
					,labelSeparator:''
					,fieldLabel :labelArray[4] 
					,id: 'product_name'
					,readOnly:true
					
				 },
				  {
					xtype: 'textfield',
					name: 'quantity',
					width:300
					,labelSeparator:''
					,fieldLabel :labelArray[5] 
					,id: 'quantity'
					,readOnly:true
					
				 },
				  {
					xtype: 'textfield',
					name: 'courier_no',
					width:300
					,labelSeparator:''
					,fieldLabel :'Docket No<span class="comp">*</span>' 
					,id: 'courier_no'
					,readOnly:false
					,allowBlank:false

					
				 },
				 {
					xtype: 'datefield',
					name: 'invoice_date',
					tabIndex:10,
					labelSeparator:'',	
					fieldLabel :'Invoice Date<span class="comp">*</span>' 
					,width:130
					,value:new Date()
					,allowBlank:false
					,id: 'invoice_date'
					,vtype: 'daterange'
					 
				  },
				  {
							xtype: 'textfield',
							name: 'invoice_no',
							id:'invoice_no',	
							labelSeparator:'',	
							fieldLabel :'Invoice No' ,
							width:130,
							tabIndex:11,
							readOnly:true,
							allowBlank:false,
							minLength:1,
							maxLength:50
							
							
				},
				 {
					xtype: 'textfield',
					name: 'customer_id'
					,id: 'customer_id'
					
					,hidden:true
				 },
				  {
					xtype: 'textfield',
					name: 'support_id'
					,id: 'support_id'
					,value:support_id
					,hidden:true
				 }]
}





 
var nameAndCompany = { columnWidth: 1,
    layout: 'form',
	labelWidth: 130,
    bodyStyle:'padding-top:1px',
    items: [
		   {
					xtype: 'textfield',
					name: 'order_no',
					labelSeparator:'',	
					fieldLabel :labelArray[0] 
					,width:120				
					,allowBlank:false
					,id: 'order_no'
					
			},
			{
				xtype: 'textfield',
				name: 'estore_name',
				labelSeparator:'',	
				fieldLabel :labelArray[1] 
				,width:300
				,allowBlank:false
				,id: 'estore_name'
				
				 
			  }]
}


////

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 product = inquiryForm.getForm().findField('product_name').getValue();	
			if(product == 'Combo (IRIS Scanner and Finger Print) Pack' || product == 'Combo (IRIS Scanner and Finger Print) 1 Pack' || product == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| product == 'COMBO_MFS110_IRIS100V2 1 Pack')
			{
			var qty = inquiryForm.getForm().findField('quantity').getValue()*2;		
			}
			else
			{
			var qty = inquiryForm.getForm().findField('quantity').getValue();		
			}
			
			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)) {								
			
			for(i=1;i<=qty;i++) {
			
			var CreditAccount='CreditAccount' + i;
			
			var CreditAmount='CreditAmount' + i;
			
			var CreditDelete='CreditDelete' + i;
			
			var CreditAccountHiddenId='CreditAccountHiddenId' + i;
		    
		//	Creditaccountid[i+2] = "" ;			
			
		/*	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
					
				});
				 
				if(product == 'IRIS Scanner MIS100V2 1pc' || product == 'IRIS Scanner MIS 100V2 1 pcs')
				{
				 Ext.getCmp(CreditAccount).setValue('MIS100V2');
				}
				else if(product == 'Finger Print Scanner MFS100V54 1pc' || product == 'FingerPrint Scanner MFS100V54 1pc')
				{
				Ext.getCmp(CreditAccount).setValue('MFS100V54');	
				}
				else if(product == 'MFS110 L1 1 pcs')
				{
				Ext.getCmp(CreditAccount).setValue('MFS110 L1');	
				}
				 
			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: '50'}
						
				});
		
				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;
		
		var product = inquiryForm.getForm().findField('product_name').getValue();	
		if(product == 'Combo (IRIS Scanner and Finger Print) Pack' || product == 'Combo (IRIS Scanner and Finger Print) 1 Pack'|| product == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| product == 'COMBO_MFS110_IRIS100V2 1 Pack')
		{
		var qty = inquiryForm.getForm().findField('quantity').getValue()*2;		
		}
		else
		{
		var qty = inquiryForm.getForm().findField('quantity').getValue();		
		}
	for(t=0;t<cntElement;t++) {			 			 	
		
		cnt 	= Ext.getCmp(parentId).items.get(t);	
		cntValue  = Ext.getCmp(cnt.id).getValue();									
		if(qty == cntElement)
		{
			Ext.MessageBox.show({
							  title: 'Error',
							  msg: 'Maximum Order Limit Over !',
							  buttons: Ext.MessageBox.OK,
							  icon:Ext.MessageBox.ERROR
		                     });
			return false;
		}
		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: false,
		height:450,
		//layout: 'accordion',
        width: 800,	
			defaults: {
            border: false
           },	
            items: [{
				//xtype: 'fieldset',
				bodyStyle: 'padding:10px',
               //title: 'Add Suport',
                layout: 'column',	
                items: [nameAndCompany,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: false,
                    layout: 'column',
                    items: [{  
								xtype: 'label',
								text:"Product",
								name: 'per',	
								cls: 'x-form-item myBold',
								style: 'padding:0px 110px',										
								id:'per'
							 },{  
								xtype: 'label',
								text:"Serial No",
								name: 'per',	
								cls: 'x-form-item myBold',
								style: 'padding:0px 23px 10px',	
								allowBlank:false,	
								id:'serial_no'
							 },btn,CreditAccountfieldSet,
							 {  
								xtype: 'label',
								text:"Total",
								name: 'total',	
								cls: 'x-form-item myBoldrad',
								style: 'padding:0px 118px',											
								id:'Total',
								hidden:true
							 },{  
								xtype: 'textfield',									
								id:'txtTotalCredit',
								hidden:true,
								name: 'txtTotalCredit',
								width		: 100,	
								height		: 25,
								style: 'padding:0px 3px '
							 }]
		
				}]
    });

inquiryForm.getForm().findField('order_no').on('blur',function (){
		var varorder_no=inquiryForm.getForm().findField('order_no').getValue();	
		if(varorder_no!="")
		{
		
   			inquiryForm.getForm().load({
				params:{order_no:varorder_no},
				url:'data/get-customer-detail.php',
				waitMsg:'Loading',
				failure: function() {
			  		Ext.MessageBox.show({
						title: 'Error',
						msg: 'Invoice Already Printed.',
						buttons: Ext.MessageBox.OK,
						icon:Ext.MessageBox.ERROR
				    });
					

			
					}
				 
				});
				
				
		account();		
	} 
		inquiryForm.getForm().findField('courier_no').focus(true,100);
   	});
	
var inquiryWindow = new Ext.Window({
		title: 'CSC Order',
		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;							
						}						
					}					
				}				
			
					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
															  });
															  Ext.MessageBox.confirm('Confirmation',' Do U Want To Print Invoice..?',printrecipt1);
															
															  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();
				get_InvoiceNo();
			}
			}
        },
	 	           {
            text: 'Close',
			iconCls: 'icon-close',
			handler: function () {
			if(formMode=='edit'){
				location.href="view-product-inquiry.php";
			}else
			{
				inquiryWindow.close();
			 }	
			}
        }
	 ]

	});
	
		function get_InvoiceNo(){
	Ext.Ajax.request({
		loadMask: true,
		sync : true,
		url: 'data/getinvoiceNo.php',
		
		success: function(resp){
			var value=Ext.decode(resp.responseText).count;
			
			if(value==','){
				
			 Ext.MessageBox.show({
					title: 'Error',
					msg: 'Ro.No Not Found.',
					buttons: Ext.MessageBox.OK,
					icon:Ext.MessageBox.ERROR
				});
			} 
			else{
				var arr_data = new Array();
				arr_data =  value.split(",");
				Ext.getCmp('invoice_no').setValue(arr_data[0]);
				
			}					
		}				
	});	}	
	
	
	function printrecipt1(btn){
		if(btn=='yes')
		{			  
		
		   var product = inquiryForm.getForm().findField('product_name').getValue();	
		if(product == 'Combo (IRIS Scanner and Finger Print) Pack' || product == 'Combo (IRIS Scanner and Finger Print) 1 Pack' || product == 'COMBO (IRISScanner and FingerPrint) 1 pcs'|| product == 'COMBO_MFS110_IRIS100V2 1 Pack')
		{
		   window.location='csc-invoice.php?ID=' + Ext.getCmp('customer_id').getValue();
		}
		else		
		{
			window.location='csc-invoice-print.php?ID=' + Ext.getCmp('customer_id').getValue();
		}
		 
		 /*if(formMode=="edit"){
			location.href = 'view-feesreceipt.php';
		}*/
		  
		}
		else
		{
			resetform();
			/*lastreceivedfees_store.reload();
			grid1.reconfigure(lastreceivedfees_store,receivedfees_colModel);*/
		
		if(formMode=="edit"){
			location.href = 'view-feesreceipt.php';
		}	
			
		}
		
		
		
		}
	var varWidth =  (screen.width - inquiryWindow.width)/2;
	inquiryWindow.setPosition(varWidth,((screen.height/4)-110));
	
	inquiryWindow.show();
		inquiryForm.getForm().findField('order_no').focus(true,100);
	
 if(i==0){	
		account();
  }	
	get_InvoiceNo();
	if(formMode=='edit'){
	<?php
	
	$support_work 			= replaceSpecial($support_work);
	$support_pending 		= replaceSpecial($support_pending);
	
	?>
		inquiryForm.getForm().findField('order_no').setValue('<?php print $order_no; ?>');
		inquiryForm.getForm().findField('estore_name').setValue('<?php print $estore_name; ?>');
		inquiryForm.getForm().findField('address').setValue('<?php print $address; ?>');
		inquiryForm.getForm().findField('address1').setValue('<?php print $address1; ?>');


		inquiryForm.getForm().findField('estore_phoneno').setValue('<?php print $estore_phoneno; ?>');
		inquiryForm.getForm().findField('product_name').setValue('<?php print $product_name; ?>');
		inquiryForm.getForm().findField('quantity').setValue('<?php print $quantity; ?>');
		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; ?>');	
			}
		}});
		
	
	
		

	
     	
		
		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";?>