<?php 
	require "_header.php";
	require "data/combo_employee.php";
?>
<!-- start custom CSS/JS -->
<script type="text/javascript">

var labelArray;
labelArray = [
	['Section :<span class="comp">*</span>'],
	['Year :<span class="comp">*</span>'],
	['Month :<span class="comp">*</span>'],
	['Employee :<span class="comp">*</span>']		
];

Ext.onReady(function(){
    Ext.QuickTips.init();
	
	var sectionliststore = new Ext.data.ArrayStore({
		fields: ['section_id', 'section_name'],
		data: Ext.employee.section
	});
	
	var yearstore1 = new Ext.data.ArrayStore({
		fields: ['year_name'],
		data: Ext.employee.year
  	});


	var yearstore2 = new Ext.data.ArrayStore({
		fields: ['year_name'],
		data: Ext.employee.year
	});
	
	Ext.namespace('Ext.month');
   	Ext.month.list = [
		[1, 'January'],[2, 'February'],[3, 'March'],[4, 'April'],[5, 'May'],[6, 'June'],
		[7, 'July'],[8, 'August'],[9, 'September'],[10, 'October'],[11, 'November'],[12, 'December']];
	
	
   var monthliststore1 = new Ext.data.SimpleStore({
    fields: [{name:'monthid',type:'int'}, 'monthname'],
    data : Ext.month.list
   });
    var monthliststore2 = new Ext.data.SimpleStore({
    fields: [{name:'monthid',type:'int'}, 'monthname'],
    data : Ext.month.list
   });
   
 
	var employeestore = new Ext.data.ArrayStore({
		fields: ['section_id','employee_id', 'employee_salaryno','employee_name','employee_basicsalary','employee_payscale'],
        data: Ext.employee.salinfo 
	});    
   
	
	var formyearlymonthwise = new Ext.FormPanel({
        labelWidth: 85,
        url: 'report-form-yearly-gross-salary-monthwise-result.php',
		method:'post',
        frame:true,
		standardSubmit:true,
       
        bodyStyle:'padding:6px 6px 0',
        
		defaultType: 'textfield',
               items :[
					    {
							xtype: 'combo',
							labelSeparator:'',	
							fieldLabel :labelArray[0] ,
							name: 'sectionid',
							id:'section',
							hidden:true,
							hiddenName: 'sectionid',
							store: sectionliststore,
							displayField:'section_name',
							tabIndex:1,
							valueField: 'section_id',
							width: 180,
							typeAhead: true,
							selectOnFocus:true,
							forceSelection:true,							
							mode: 'local',
							triggerAction: 'all',
							emptyText:'Please select section...',
							editable:false,
							allowBlank:true,
							listeners:{select:{fn:function(combo, value){
								formyearlymonthwise.getForm().findField('sectionname').setValue(combo.getRawValue());	
								/*employeestore.load({params:{
									datarequired:'employeerecords',		
									sectionid:formyearlymonthwise.getForm().findField('section').getValue()
								}});*/								
								Ext.getCmp('employee').clearValue();
								Ext.getCmp('employee').store.filter('section_id', combo.getValue());
								
							}}}
                       },
					    {
						   
						xtype       : 'container',
						autoEl      : {},
						border      : false,
						layout      : 'column',
						anchor      : '100%',
						defaultType : 'field',
						items       : [{
										xtype  : 'container',
										layout : 'form',
										columnWidth : .26,
										anchor      : '-50',
										items  : [{ xtype: 'radio',
													  hideLabel: true,
													  name: 'radiotype',
													  checked:true,
													  inputValue: '1',												  
													  labelSeparator:'',	
													  boxLabel :labelArray[3],
													  handler:function(){
														  if(this.checked) {
														
														  }													  	
						 								 }	}
						 						 ,{
													 
											      xtype: 'radio',
												  hideLabel: true,
											      name: 'radiotype',
											      inputValue: '2',
											      boxLabel: 'All',
												   handler:function(){
													if(this.checked) {
													formyearlymonthwise.getForm().findField('employee').disable();	
													 formyearlymonthwise.getForm().findField('employee').reset();	
													  }	
													  else
													  {
													  	Ext.getCmp('employee').enable();	
														Ext.getCmp('employee').clearValue();
														Ext.getCmp('employee').store.filter('section_id', Ext.getCmp('section').getValue());
													  }										  	
												  }	
												  
											    }]
									     },
									    {
										xtype       : 'container',
										layout      : 'form',
										columnWidth : .7,
										labelWidth: 1,
										items       : [{
				        xtype: 'combo',
						name:'employeeid',
						id:'employee',
						hiddenName:'ID',
						store:employeestore,
						displayField: 'employee_name',
						valueField: 'employee_id',
						editable:true,
						mode: 'local',
						allowBlank:false, 
						triggerAction: 'all',
						emptyText: 'Please Select Employee ...',
						width:180
					}]
									   }]
						   
						  											  
						},
					    {
						xtype       : 'container',
						autoEl      : {},
						border      : false,
						layout      : 'column',
						anchor      : '100%',
						defaultType : 'field',
						items       : [{
										xtype  : 'container',
										layout : 'form',
										columnWidth : .56,
										anchor      : '-50',
										items  : [{
													xtype: 'combo',
													labelSeparator:'',	
							fieldLabel :labelArray[1],
													name: 'Yearfrom',
													id:'Yearfrom',
													store: yearstore1,
													displayField:'year_name',
													valueField: 'year_name',
													width: 87,
													tabIndex:2,
													typeAhead: true,
													selectOnFocus:true,
													forceSelection:true,
													triggerAction: 'all',
													emptyText:'From',
													editable:true,
													allowBlank:false,
													mode:'local',
													listeners:{select:{fn:function(combo, value) 
																{
																	formyearlymonthwise.getForm().findField('Yearto').reset();
																	formyearlymonthwise.getForm().findField('month_namefrom').enable();
																	formyearlymonthwise.getForm().findField('month_nameto').enable();  
																	var name=Ext.getCmp('Yearfrom').getValue('year_name');
																	
																	var i= yearstore2.find('year_name',name);
																		  var record =yearstore2.getAt(i+1);
																		  year=(record.data.year_name);
																		  formyearlymonthwise.getForm().findField('Yearto').setValue(year);
																	}
																  },
																blur:{fn:function(combo, value) 
																{
																	if(Ext.getCmp('Yearfrom').getValue('year_name')!="")
																	{
																	formyearlymonthwise.getForm().findField('Yearto').reset();
																	formyearlymonthwise.getForm().findField('Yearto').setValue("");
																	//formyearlymonthwise.getForm().findField('month_namefrom').enable();
																	formyearlymonthwise.getForm().findField('month_nameto').enable();  
																	var name=Ext.getCmp('Yearfrom').getValue('year_name');
																	
																	var i= yearstore2.find('year_name',name);
																		  var record =yearstore2.getAt(i+1);
																		  year=(record.data.year_name);
																		  formyearlymonthwise.getForm().findField('Yearto').setValue(year);
																	}
																	}
																  }
													}
                      							  },{
													xtype: 'combo',
													name: 'month_namefrom',
													id:'month_namefrom',
													labelSeparator:'',	
													fieldLabel :labelArray[2] ,
													forceSelection:true,
													hiddenName:	'month_idfrom',			
													displayField:'monthname',
													valueField:'monthid',
													typeAhead: true,
													tabIndex:3,
													labelWidth: 70,
													disabled:true,
													width:87,
													emptyText:'From',
													allowBlank:false,
													triggerAction:'all',
													mode: 'local',
													editable:true,
													store: monthliststore1,
													listeners:{select:{fn:function(combo, value) 
													{
													formyearlymonthwise.getForm().findField('month_nameto').reset(); 
													var name=Ext.getCmp('month_namefrom').getValue();
												 	var i= monthliststore1.find('monthid',name);
													//formyearlymonthwise.getForm().findField('monthnamefrom').setValue(combo.getRawValue());
													 if(i!=0)
													 {
													  var record = monthliststore1.getAt(i-1);
												      month=record.data.monthname;
													  formyearlymonthwise.getForm().findField('month_nameto').setValue(month);  
													   
													  
													   var j= formyearlymonthwise.getForm().findField('Yearfrom').getValue();
													   formyearlymonthwise.getForm().findField('Yearto').setValue(parseInt(j)+1);
													  
													  
													  
													 }
													 else
													 {
														
														 formyearlymonthwise.getForm().findField('month_nameto').setValue('December'); 
														var lastyaer= formyearlymonthwise.getForm().findField('Yearto').getValue();
														 formyearlymonthwise.getForm().findField('Yearto').setValue(lastyaer-1);
													
														 }
												
												
												}
													  },
												blur:{fn:function(combo, value) 
													{
													if(Ext.getCmp('month_namefrom').getValue()!="")
													{
													formyearlymonthwise.getForm().findField('month_nameto').reset(); 
													var name=Ext.getCmp('month_namefrom').getValue();
												 	var i= monthliststore2.find('monthid',name);
													//formyearlymonthwise.getForm().findField('monthnamefrom').setValue(combo.getRawValue());
													 if(i!=0)
													 {
													  var record = monthliststore2.getAt(i-1);
												      month=record.data.monthname;
													  formyearlymonthwise.getForm().findField('month_nameto').setValue(month);  
													   
													  
													   var j= formyearlymonthwise.getForm().findField('Yearfrom').getValue();
													   
													   formyearlymonthwise.getForm().findField('Yearto').setValue(parseInt(j)+1);
													   
													  
													  
													  
													 }
													 else
													 {
														
														 formyearlymonthwise.getForm().findField('month_nameto').setValue('December'); 	
														 var lastyaer= formyearlymonthwise.getForm().findField('Yearto').getValue();
														 formyearlymonthwise.getForm().findField('Yearto').setValue(lastyaer);
													
														 }
													}
												
												
												}
													  }
													}
													
												}]
									     },
									   {
										xtype       : 'container',
										layout      : 'form',
										columnWidth : .44,
										labelWidth: 1,
										items       : [{
														xtype: 'combo',
														name: 'Yearto',
														id:'Yearto',
														store: yearstore2,
														displayField:'year_name',
														valueField: 'year_name',
														width: 87,
														typeAhead: true,
														selectOnFocus:true,
														forceSelection:true,
														//disabled:true,
														emptyText:'To',
														editable:false,
														allowBlank:false,
														mode:'local'
                        							},{
													xtype: 'combo',
													name: 'month_nameto',
													id:'month_nameto',
													forceSelection:true,
													hiddenName:	'month_idto',			
													displayField:'monthname',
													valueField:'monthid',
													selectOnFocus:true,
													forceSelection:true,
													typeAhead: true,
													emptyText:'To',
													width:87,
													allowBlank:false,
													mode: 'local',
													disabled:true,
													//triggerAction:'all',
													editable:false,
													store: monthliststore2,
													listeners:{select:{fn:function(combo, value) 
													{
														}
														 }
													}
													
												}]
									   }]
		             },
						{
						xtype: 'textfield',
						name: 'sectionname',
						id:'sectionname',
						hidden:true
		    		}
					]	
    });
    
	var monthwiseWindow = new Ext.Window({
        title: 'Yearly Gross Salary Monthwise',
		width:360,		
		height:220,		
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'close',
		
		collapsible:true,
		items: formyearlymonthwise,
		buttonAlign: 'center',
	    buttons: [
						{
							text:'View Report',
							tabIndex:4,
							handler: function()
							{		
								var Yearfrom=formyearlymonthwise.getForm().findField('Yearfrom').getValue();
								var Yearto=formyearlymonthwise.getForm().findField('Yearto').getValue();
								var month_idfrom=formyearlymonthwise.getForm().findField('month_idfrom').getValue();
								var ID=formyearlymonthwise.getForm().findField('ID').getValue();
			
							var redirect = 'report-form-yearly-gross-salary-monthwise-result.php?Yearfrom='+Yearfrom + '&Yearto='+Yearto + '&month_idfrom='+month_idfrom + '&ID='+ID  ; 
							window.location = redirect;
							}
						},
						{
						text: 'Reset', 
						handler: function () {   
												 formyearlymonthwise.getForm().reset();
    								 			formyearlymonthwise.getForm().findField('section').focus(true,500);
									 }
						},
						{
					text: 'Close',
						handler: function () {   
						monthwiseWindow.close();
											 }
					   }
					]

	});
	var varWidth =  (screen.width - monthwiseWindow.width)/2;
	monthwiseWindow.setPosition(varWidth,((screen.height/4)-110));
	monthwiseWindow.show();
	SetSectionValue('add',sectionliststore,'section','section'); 		  
	sectionliststore.on({'load': {
	fn: function(store, options)
		{  
			  if(sectionliststore.getCount()==1)
			  {
			    
			     Ext.getCmp('section').setValue(sectionliststore.getAt(0).data.section_id,true);
			
		         Ext.getCmp('employee').focus(true,500); 
			  }
			  else
			  {
			  Ext.getCmp('section').focus(true,500); 
			  }
	   	
	  	}
    } 
	}); 
			//formyearlymonthwise.getForm().findField('section').focus(true,500);

	
});

</script>
<!-- end custom CSS/JS -->
<div id="main-content" align="center"></div>
<?php require "_footer.php";?>