<?php

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."CRM/class/class.Language-Pack.php");
include_once (PATH_TO_ROOT."CRM/_CRM_config.php");

$LangPack = new LanguagePack($db, $aLanguage);
$ajax = CRM_RPATH."_forms/filter/_ajax/ajax.filter.php";
$gridName = "FilterPanel".$suffix;
?>

new Ext.form.FormPanel({
	id:'<?php echo $gridName;?>',
	bodyStyle:'padding: 20px',
	region: 'north',
	defaults:{
    	style: 'margin-right: 15px',
    	style: 'margin-bottom: 5px'
	},
	height: <?php if($finance){?> 265 <?php }elseif($deliveryContract) { ?> 220 <?php }else{ ?> 380 <?php }?>,
	collapsible: true,
	items:[{
    	xtype: 'container',
    	layout: 'column',
    	defaults:{
    		style: 'margin-right: 20px; margin-bottom: 15px'
    	},
    	items:[{
			xtype: 'button',
			id: 'today_<?php echo $suffix;?>',
        	name: 'today',
        	width: 80,
        	pressed: true,
        	enableToggle: true,
        	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "today_button_text","Danes");?>',
        	handler: function(){
        		Ext.getCmp('time_from_<?php echo $suffix;?>').setValue(new Date());
        		Ext.getCmp('time_to_<?php echo $suffix;?>').setValue(new Date());
        	},
        	listeners: {
        		click: function(comp){
        			if(comp.pressed == true){
        				if(Ext.getCmp('yesterday_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('yesterday_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_month_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_month_<?php echo $suffix;?>').toggle();	
        				} 
        			}
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
		},{
			xtype: 'button',
			id: 'yesterday_<?php echo $suffix;?>',
        	name: 'yesterday',
        	width: 80,
        	enableToggle: true,
        	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "yesterday_button_text","Včeraj");?>',
        	handler: function(){
        		<?php
        			$now = new DateTime();
					$now->modify("-1 day");
        		?>
        		Ext.getCmp('time_from_<?php echo $suffix;?>').setValue('<?php echo $now->format("d.m.Y");?>');
        		Ext.getCmp('time_to_<?php echo $suffix;?>').setValue('<?php echo $now->format("d.m.Y");?>');
        	},
        	listeners: {
        		click: function(comp){
        			if(comp.pressed == true){
        				if(Ext.getCmp('today_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('today_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_month_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_month_<?php echo $suffix;?>').toggle();	
        				} 
        			}
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
		},{
			xtype: 'button',
			id: 'this_week_<?php echo $suffix;?>',
        	name: 'this_week',
        	width: 80,
        	enableToggle: true,
        	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "this_week_button_text","Ta teden");?>',
        	handler: function(){
        		var now = new Date();
				var day = now.getDay(),
				diff = now.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
				var start = new Date(now.setDate(diff));
				var end = new Date(now.setDate(diff+6));        
				<?php 
        			$d = new DateTime(); 
        			$weekday = $d->format('w'); 
        			$diff = ($weekday == 0 ? 6 : $weekday -1);
					$d->modify("-$diff day");   
        		?>		
        		
        		Ext.getCmp('time_from_<?php echo $suffix;?>').setValue('<?php echo $d->format("d.m.Y");?>');
        		Ext.getCmp('time_to_<?php echo $suffix;?>').setValue('<?php $d->modify('+6 day'); echo $d->format("d.m.Y");?>');
        	},
        	listeners: {
        		click: function(comp){
        			if(comp.pressed == true){
        				if(Ext.getCmp('yesterday_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('yesterday_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('today_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('today_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_month_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_month_<?php echo $suffix;?>').toggle();	
        				} 
        			}
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
		},{
			xtype: 'button',
			id: 'last_week_<?php echo $suffix;?>',
        	name: 'last_week',
        	width: 80,
        	enableToggle: true,
        	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "last_week_button_text","Prejšnji teden");?>',
        	handler: function(){      		
        		<?php 
        			$d = new DateTime(); 
        			$weekday = $d->format('w'); 
        			$diff = 7 + ($weekday == 0 ? 6 : $weekday -1); 
        			$d->modify("-$diff day");  
        		?>
        		Ext.getCmp('time_from_<?php echo $suffix;?>').setValue('<?php echo $d->format("d.m.Y");?>');
        		Ext.getCmp('time_to_<?php echo $suffix;?>').setValue('<?php $d->modify("+6 day"); echo $d->format("d.m.Y");?>');
        	},
        	listeners: {
        		click: function(comp){
        			if(comp.pressed == true){
        				if(Ext.getCmp('yesterday_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('yesterday_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('today_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('today_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_month_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_month_<?php echo $suffix;?>').toggle();	
        				} 
        			}
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
		},{
			xtype: 'button',
			id: 'this_month_<?php echo $suffix;?>',
        	name: 'this_month',
        	width: 80,
        	enableToggle: true,
        	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "this_month_button_text","Ta mesec");?>',
        	handler: function(){
        		var date = new Date();
				var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
				var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);    		
        		
        		Ext.getCmp('time_from_<?php echo $suffix;?>').setValue(firstDay);
        		Ext.getCmp('time_to_<?php echo $suffix;?>').setValue(lastDay);
        	},
        	listeners: {
        		click: function(comp){
        			if(comp.pressed == true){
        				if(Ext.getCmp('yesterday_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('yesterday_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('today_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('today_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_month_<?php echo $suffix;?>').toggle();	
        				} 
        			}
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
		},{
			xtype: 'button',
			id: 'last_month_<?php echo $suffix;?>',
        	name: 'last_month',
        	width: 80,
        	enableToggle: true,
        	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "last_month_button_text","Prejšnji mesec");?>',
        	handler: function(){
        		var date = new Date();
				var firstDay = new Date(date.getFullYear(), date.getMonth()-1, 1);
				var lastDay = new Date(date.getFullYear(), date.getMonth(), 0);    		
        		
        		Ext.getCmp('time_from_<?php echo $suffix;?>').setValue(firstDay);
        		Ext.getCmp('time_to_<?php echo $suffix;?>').setValue(lastDay);
        	},
        	listeners: {
        		click: function(comp){
        			if(comp.pressed == true){
        				if(Ext.getCmp('yesterday_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('yesterday_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('last_week_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('last_week_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('this_month_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('this_month_<?php echo $suffix;?>').toggle();	
        				}
        				if(Ext.getCmp('today_<?php echo $suffix;?>').pressed == true){
        					Ext.getCmp('today_<?php echo $suffix;?>').toggle();	
        				}
        			}
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
		}]
	}
	 <?php if(!$finance && !$deliveryContract){?> 
	 	,{
		xtype: 'checkbox',
		id: 'all_checkboxes_<?php echo $suffix;?>',
    	name: 'all_checkboxes',
    	enableToggle: true,
    	fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "all_checkboxes_checkbox_text","Vse izbrano");?>',
    	style: 'margin-bottom: 15px',
    	listeners:{
    		check: function(comp, a){
    			Ext.each(Ext.getCmp('status_checkgroup_<?php echo $suffix;?>').items.items,function(c){
					Ext.getCmp(c.id).setValue(a);
				})
				Ext.each(Ext.getCmp('store_checkgroup_<?php echo $suffix;?>').items.items,function(c){
					Ext.getCmp(c.id).setValue(a);
				})
				if(Ext.getCmp('export_button_o'))
	    			Ext.getCmp('export_button_o').disable();
	    		else if(Ext.getCmp('export_button_d'))
	    			(Ext.getCmp('export_button_d')).disable();
    		}
    	}
	}<?php }?>,{
		xtype: 'container',
		layout: 'column',
		labelWidth: 140,
    	items: [{
    		xtpye: 'container',
    		layout:'form',
    		border: false,
    		items:[{
    			xtype: 'datefield',
    			id: 'time_from_<?php echo $suffix;?>',
    			format: 'd.m.Y',
	        	name: 'time_from',
	        	value: '<?php $d = new DateTime(); 
        			$weekday = $d->format('w'); 
        			$diff = ($weekday == 0 ? 6 : $weekday -1);
					$d->modify("-$diff day");   
					if($deliveryContract) echo $d->format("d.m.Y"); else echo date("d.m.Y");?>',
	        	fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "time_from_textbox","Čas od (od 0:00)");?>',
	        	listeners: {
	        		change: function(){
	        			if(Ext.getCmp('export_button_o'))
			    			Ext.getCmp('export_button_o').disable();
			    		else if(Ext.getCmp('export_button_d'))
			    			(Ext.getCmp('export_button_d')).disable();
	        		}
	        	}
    		}]
    	},{
    		xtype:'container',
    		layout: 'form',
    		style: 'margin-left: 40px',
    		items:[{		
    			xtype: 'datefield',
    			id: 'time_to_<?php echo $suffix;?>',
    			format: 'd.m.Y',
	        	name: 'time_to',
	        	value: '<?php $d = new DateTime(); 
        			$weekday = $d->format('w'); 
        			$diff = ($weekday == 0 ? 6 : $weekday -1);
					$d->modify("-$diff day");    if($deliveryContract) {$d->modify('+6 day'); echo $d->format("d.m.Y");} else echo date("d.m.Y");?>',
	        	fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "time_to_textbox","Čas do (od 24:00)");?>',
	        	listeners: {
	        		change: function(){
	        			if(Ext.getCmp('export_button_o'))
			    			Ext.getCmp('export_button_o').disable();
			    		else if(Ext.getCmp('export_button_d'))
			    			(Ext.getCmp('export_button_d')).disable();
	        		}
	        	}
    		}]
    	}
    	<?php if($orders) { ?>
    	,{
  			xtype: 'container',
  			items: [{
  				xtype: 'radiogroup',
	    		cls: 'x-check-group-alt',
	    		items: [{
	    	        name: 'DeliveryOrOrderDate',
	    	        id:'DeliveryOrOrderDate1_<?php echo $suffix;?>',
	    	        boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "DeliveryOrOrderDate1_radio","Datum naročila");?>',
	    	        checked: true,
	    	        style: { marginLeft: '15px' }
	    		},{
					name: 'DeliveryOrOrderDate',
	    	        id:'DeliveryOrOrderDate2_<?php echo $suffix;?>',
	    	        boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "DeliveryOrOrderDate2_radio","Datum spremembe");?>',
	    	        style: { marginLeft: '10px' }
	    		},{
	    		    name: 'DeliveryOrOrderDate',
	    		    id: 'DeliveryOrOrderDate3_<?php echo $suffix;?>',
	    		    boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "DeliveryOrOrderDate3_radio","Datum dejanske dostave");?>',
                    style: { marginLeft: '10px' }
	    		}]
  			}]
    	}
    	<?php } ?>
    	]	
	}
	<?php if(!$finance && !$deliveryContract){?>
		,{
		xtype: 'checkboxgroup',
		fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "state_label","Status");?>',
		id: 'status_checkgroup_<?php echo $suffix;?>',
		columns: 3,
		width: 800,
    	items: [{
    		name:'check_all',
    		id: 'check_all_<?php echo $suffix;?>',
    		boxLabel:'-',
    		listeners:{
				check: function(comp, a){
					Ext.each(Ext.getCmp('status_checkgroup_<?php echo $suffix;?>').items.items,function(c){
						Ext.getCmp(c.id).setValue(a);
					})
					if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
				}
	    	}
    	},{
        	name: 'ordered',
        	id: 'ordered_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "ordered_checkbox_text","Naročeno");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'delivered',
        	id: 'delivered_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "deleviered_checkbox_text","Dostavljeno");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'date_changed',
        	id: 'date_changed_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "date_changed_checkbox_text","Sprememba datuma");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'storno_team',
        	id: 'storno_team_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "storno_team_checkbox_text","Storno ekipa");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'storno_delivery',
        	id: 'storno_delivery_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "storno_delivery_checkbox_text","Storno dostava");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'product_return',
        	id: 'product_return_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "product_return_checkbox_text","Vračilo izdelek");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'credit_denial',
        	id: 'credit_denial_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "credit_denial_checkbox_text","Zavrnitev kredita");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'reclamation',
        	id: 'reclamation_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "reclamation_checkbox_text","Reklamacija");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	}]
	}<?php }?>
	<?php if(!$deliveryContract){ ?>,{
		xtype: 'checkboxgroup',
		fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "storage_label","Shramba");?>',
		id: 'store_checkgroup_<?php echo $suffix;?>',
		width: 400,
		style: 'margin-bottom: 10px',
    	items: [{
    		name:'check_all_storage',
    		id: 'check_all_storage_<?php echo $suffix;?>',
    		boxLabel:'-',
    		listeners:{
				check: function(comp,a){
					Ext.each(Ext.getCmp('store_checkgroup_<?php echo $suffix;?>').items.items,function(c){
						Ext.getCmp(c.id).setValue(a);
					})
					if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
				}
	    	}
    	},{
        	name: 'own_delivery',
        	id: 'own_delivery_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "own_delivery_checkbox_text","Osebna dostava");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	},{
        	name: 'central_delivery',
        	id: 'central_delivery_<?php echo $suffix;?>',
        	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "central_delivery_checkbox_text","Centralna dostava");?>',
        	listeners: {
        		check: function(){
        			if(Ext.getCmp('export_button_o'))
		    			Ext.getCmp('export_button_o').disable();
		    		else if(Ext.getCmp('export_button_d'))
		    			(Ext.getCmp('export_button_d')).disable();
        		}
        	}
    	}]	
	}
	<?php }?>
	<?php if(!$deliveryContract) {?>,
	new Ext.form.ComboBox({
	    fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "teams_label","Ekipe");?>', 
	    mode: 'remote',
	    triggerAction: 'all',
	    width: 200,
	    hiddenName: 'teams',
	    name: 'teams',
	    id: 'teams_<?php echo $suffix;?>',
	    lazyRender: true,
	    store: new Ext.data.JsonStore({
            url : '<?php echo $ajax; ?>',
            autoLoad: true,
            root : 'rows',
            baseParams: {
                action: 'getTeam'
            },
            fields:[
                     { name:"id", type: 'int' },
                     { name:"team", type: 'string' }
            ]
        }),
        listeners: {
    		change: function(){
    			if(Ext.getCmp('export_button_o'))
	    			Ext.getCmp('export_button_o').disable();
	    		else if(Ext.getCmp('export_button_d'))
	    			(Ext.getCmp('export_button_d')).disable();
    		}
    	},
	    valueField: 'id',
	    displayField: 'team' 
   }),
   new Ext.form.ComboBox({
	    fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "assistant_label","Assistant");?>', 
	    mode: 'local',
	    triggerAction: 'all',
	    width: 200,
	    hiddenName: 'assistant',
	    name: 'assistant',
	    id: 'assistant_<?php echo $suffix;?>',
	    lazyRender: true,
	    store: new Ext.data.ArrayStore({
		    fields:['id', 'value'],
		    data:[
		        <?php 
		            $assistents = array();
                    if(isset($_SESSION['CRM_login'])){
                        $sql = "SELECT *
                            FROM ".DB_WARPIT_WEBCATI_BASE."._Interviewer
                            WHERE id IN
                            (
                                SELECT id 
                                FROM ".DB_WARPIT_WEBCATI_BASE."._group_link
                                WHERE id_group =
                                (
                                    SELECT id_group 
                                    FROM ".DB_WARPIT_WEBCATI_BASE."._group_link
                                    WHERE id = '".$_SESSION['UserInfo']['id']."'
                                 )
                            )";
                    }else{
                        $sql = "SELECT * FROM ".DB_WARPIT_WEBCATI_BASE."._Interviewer";
                    }
                  //  echo $sql;
                    $res = $db->SQLexecute($sql);
                    
                    while($row = $db->fetchAssoc($res)){
                        array_push($assistents, "['".$row['id']."', '".$row['Firstname']." ".$row['Surname']." (".$row['username'].")']");
                    }
                    echo implode(", ", $assistents);
		        ?>
		    ]
		}),
		listeners: {
    		change: function(){
    			if(Ext.getCmp('export_button_o'))
	    			Ext.getCmp('export_button_o').disable();
	    		else if(Ext.getCmp('export_button_d'))
	    			(Ext.getCmp('export_button_d')).disable();
    		}
    	},
	    valueField: 'id',
	    displayField: 'value' 
   }),
    {
    	xtype: 'container',
    	layout:'column',
    	labelWidth: 140,
    	items:[{
    		xtype: 'container',
    		layout:'form',
    		border: false,
    		items:[{
	    		xtype: 'textfield',		
		    	fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "ppid_textbox_text","PPID");?>',
				id: 'ppid_<?php echo $suffix;?>',
				width: 60,
		    	name: 'ppid',
		    	listeners: {
		    		change: function(){
		    			if(Ext.getCmp('export_button_o'))
			    			Ext.getCmp('export_button_o').disable();
			    		else if(Ext.getCmp('export_button_d'))
			    			(Ext.getCmp('export_button_d')).disable();
		    		}
		    	}
	    	}]
    	},{
    		xtype: 'container',
    		layout:'form',
    		border: false,
    		items:[{
				xtype:'checkbox',
				name: 'disablePagging',
				id: 'disablePagging_<?php echo $suffix;?>',
				boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "disable_pagging_checkbox","Disable pagging");?>'
    		}]
    	}]
		
	}<?php } else{?>
	,{
		xtype: 'textfield',
		id: 'firstname_<?php echo $suffix;?>',
    	name: 'firstname',
    	fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "firstname_textbox_text","Ime");?>',
    	listeners: {
    		change: function(){
    			if(Ext.getCmp('export_button_o'))
	    			Ext.getCmp('export_button_o').disable();
	    		else if(Ext.getCmp('export_button_d'))
	    			(Ext.getCmp('export_button_d')).disable();
    		}
    	}
	},{
		xtype: 'textfield',
		id: 'surname_<?php echo $suffix;?>',
    	name: 'surname',
    	fieldLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "surname_textbox_text","Priimek");?>',
    	listeners: {
    		change: function(){
    			if(Ext.getCmp('export_button_o'))
	    			Ext.getCmp('export_button_o').disable();
	    		else if(Ext.getCmp('export_button_d'))
	    			(Ext.getCmp('export_button_d')).disable();
    		}
    	}
	},{
		xtype: 'checkbox',
		id: 'dateChecked_<?php echo $suffix;?>',
    	name: 'dateChecked',
    	boxLabel: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "dateChecked_checkbox_text","Datum checked");?>'
	}
	 <?php } ?>,{
		xtype: 'button',
		id: 'search_<?php echo $suffix;?>',
    	name: 'search',
    	width: 80,
    	text: '<?php echo $LangPack->GetLabel("filter_delivery_grid", "search_button_text","Išči");?>',
    	handler: function(){
    		if(Ext.getCmp('mainTabPanel').getActiveTab().id == 'DeliveryTab'){
				Ext.getCmp('DeliveryGrid').getStore().proxy.setApi({read : '<?php echo $ajax;?>' });
			} else if(Ext.getCmp('mainTabPanel').getActiveTab().id == 'OrdersTab'){
				Ext.getCmp('Orders').getStore().proxy.setApi({read : '<?php echo $ajax;?>' });
			}
    		if(Ext.getCmp('mainTabPanel').getActiveTab().id == 'DeliveryTab'){
    			if(Ext.getCmp('disablePagging_<?php echo $suffix;?>').getValue()){
	    			Ext.getCmp('DeliveryGrid').bottomToolbar.hide();
	    			Ext.getCmp('DeliveryGrid').doLayout();	
    			}else{
    				Ext.getCmp('DeliveryGrid').bottomToolbar.show();
	    			Ext.getCmp('DeliveryGrid').doLayout();	
    			}
    			Ext.getCmp('DeliveryGrid').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje...");?>');
    			Ext.getCmp('DeliveryGrid').getStore().load({
    				url: '<?php echo $ajax;?>',  
    				params: { 
    					action: 'dataFilter',
    					form: 'delivery',
    					disable_pagging: Ext.getCmp('disablePagging_<?php echo $suffix;?>').getValue(),
    					all_checked: Ext.getCmp('all_checkboxes_<?php echo $suffix; ?>').getValue(),
    					time_from: Ext.getCmp('time_from_<?php echo $suffix; ?>').getRawValue(),
    					time_to: Ext.getCmp('time_to_<?php echo $suffix; ?>').getRawValue(),
    					all_states: Ext.getCmp('check_all_<?php echo $suffix; ?>').getValue(),
    					state_ordered: Ext.getCmp('ordered_<?php echo $suffix; ?>').getValue(),
    					state_delivered: Ext.getCmp('delivered_<?php echo $suffix; ?>').getValue(),
    					state_date_changed: Ext.getCmp('date_changed_<?php echo $suffix; ?>').getValue(),
    					state_storno_team: Ext.getCmp('storno_team_<?php echo $suffix; ?>').getValue(),
    					state_storno_delivery: Ext.getCmp('storno_delivery_<?php echo $suffix; ?>').getValue(),
    					state_product_return: Ext.getCmp('product_return_<?php echo $suffix; ?>').getValue(),
    					state_credit_denial: Ext.getCmp('credit_denial_<?php echo $suffix; ?>').getValue(),
    					state_reclamation: Ext.getCmp('reclamation_<?php echo $suffix; ?>').getValue(),
    					all_storage: Ext.getCmp('check_all_storage_<?php echo $suffix; ?>').getValue(),
    					storage_own_delivery: Ext.getCmp('own_delivery_<?php echo $suffix; ?>').getValue(),
    					storage_central_delivery: Ext.getCmp('central_delivery_<?php echo $suffix; ?>').getValue(),
    					teams: Ext.getCmp('teams_<?php echo $suffix; ?>').getValue(),
    					assistant: Ext.getCmp('assistant_<?php echo $suffix; ?>').getValue(),
    					ppid: Ext.getCmp('ppid_<?php echo $suffix; ?>').getValue() 
					},
					callback: function(resp, opt, success){
						if(success){
							Ext.getCmp('DeliveryGrid').getEl().unmask();
						}
					}
				});
    		} else if(Ext.getCmp('mainTabPanel').getActiveTab().id == 'OrdersTab') {
    			if(Ext.getCmp('disablePagging_<?php echo $suffix;?>').getValue()){
	    			Ext.getCmp('Orders').bottomToolbar.hide();
    				Ext.getCmp('Orders').doLayout();
    				Ext.getCmp('Orders').getStore()
    			}else{
    				Ext.getCmp('Orders').bottomToolbar.show();
    				Ext.getCmp('Orders').doLayout();
    			}
    			Ext.getCmp('Orders').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje...");?>');
    			Ext.getCmp('Orders').getStore().load({
    				url: '<?php echo $ajax;?>',  
    				params: { 
    					action: 'dataFilter',
    					form: 'orders',
    					order_date: Ext.getCmp('DeliveryOrOrderDate2_<?php echo $suffix;?>').getValue(),
    					order_date2: Ext.getCmp('DeliveryOrOrderDate3_<?php echo $suffix;?>').getValue(),
    					disable_pagging: Ext.getCmp('disablePagging_<?php echo $suffix;?>').getValue(),
    					all_checked: Ext.getCmp('all_checkboxes_<?php echo $suffix; ?>').getValue(),
    					time_from: Ext.getCmp('time_from_<?php echo $suffix; ?>').getRawValue(),
    					time_to: Ext.getCmp('time_to_<?php echo $suffix; ?>').getRawValue(),
    					all_states: Ext.getCmp('check_all_<?php echo $suffix; ?>').getValue(),
    					state_ordered: Ext.getCmp('ordered_<?php echo $suffix; ?>').getValue(),
    					state_delivered: Ext.getCmp('delivered_<?php echo $suffix; ?>').getValue(),
    					state_date_changed: Ext.getCmp('date_changed_<?php echo $suffix; ?>').getValue(),
    					state_storno_team: Ext.getCmp('storno_team_<?php echo $suffix; ?>').getValue(),
    					state_storno_delivery: Ext.getCmp('storno_delivery_<?php echo $suffix; ?>').getValue(),
    					state_product_return: Ext.getCmp('product_return_<?php echo $suffix; ?>').getValue(),
    					state_credit_denial: Ext.getCmp('credit_denial_<?php echo $suffix; ?>').getValue(),
    					state_reclamation: Ext.getCmp('reclamation_<?php echo $suffix; ?>').getValue(),
    					all_storage: Ext.getCmp('check_all_storage_<?php echo $suffix; ?>').getValue(),
    					storage_own_delivery: Ext.getCmp('own_delivery_<?php echo $suffix; ?>').getValue(),
    					storage_central_delivery: Ext.getCmp('central_delivery_<?php echo $suffix; ?>').getValue(),
    					teams: Ext.getCmp('teams_<?php echo $suffix; ?>').getValue(),
    					assistant: Ext.getCmp('assistant_<?php echo $suffix; ?>').getValue(),
    					ppid: Ext.getCmp('ppid_<?php echo $suffix; ?>').getValue() 
					},
					callback: function(resp, opt, success){
						if(success){
							Ext.getCmp('Orders').getEl().unmask();
						}
					}
				});
    		}else if(Ext.getCmp('mainTabPanel').getActiveTab().id == 'FinanceTab') {
    			Ext.getCmp('Finance').getStore().setBaseParam('ime', '');
				Ext.getCmp('Finance').getStore().setBaseParam('priimek', '');
				Ext.getCmp('Finance').getStore().setBaseParam('dorder_date_to', '');
				Ext.getCmp('Finance').getStore().setBaseParam('dorder_date_from', '');
				Ext.getCmp('Finance').getStore().setBaseParam('email', '');
				Ext.getCmp('Finance').getStore().setBaseParam('kraj', '');
				Ext.getCmp('Finance').getStore().setBaseParam('naslov', '');
				Ext.getCmp('Finance').getStore().setBaseParam('order_article_amount', '');
				Ext.getCmp('Finance').getStore().setBaseParam('order_article_price', '');
				Ext.getCmp('Finance').getStore().setBaseParam('order_article_code', '');
				Ext.getCmp('Finance').getStore().setBaseParam('order_type', '');
				Ext.getCmp('Finance').getStore().setBaseParam('order_status', '');
				Ext.getCmp('Finance').getStore().setBaseParam('postna_st', '');
				Ext.getCmp('Finance').getStore().setBaseParam('tel1', '');
				Ext.getCmp('Finance').getStore().setBaseParam('tel2', '');
				Ext.getCmp('Finance').getStore().setBaseParam('tp_city', '');
				Ext.getCmp('Finance').getStore().setBaseParam('tp_date', '');
				Ext.getCmp('Finance').getStore().setBaseParam('tp_time', '');
				
    			Ext.getCmp('Finance').getStore().load({
    				url: '<?php echo $ajax;?>',  
    				params: { 
    					action: 'get',
    					time_from_finance: Ext.getCmp('time_from_<?php echo $suffix; ?>').getRawValue(),
    					time_to_finance: Ext.getCmp('time_to_<?php echo $suffix; ?>').getRawValue(),
    					state_delivered: true,
    					all_storage: Ext.getCmp('check_all_storage_<?php echo $suffix; ?>').getValue(),
    					storage_own_delivery: Ext.getCmp('own_delivery_<?php echo $suffix; ?>').getValue(),
    					storage_central_delivery: Ext.getCmp('central_delivery_<?php echo $suffix; ?>').getValue(),
    					teams: Ext.getCmp('teams_<?php echo $suffix; ?>').getValue(),
    					assistant: Ext.getCmp('assistant_<?php echo $suffix; ?>').getValue(),
    					ppid: Ext.getCmp('ppid_<?php echo $suffix; ?>').getValue() 
					}
				});
    		}else if(Ext.getCmp('mainTabPanel').getActiveTab().id == 'deliveryContractTab') {
    			Ext.getCmp('deliveryContract').getStore().load({
    				url: '<?php echo $ajaxDeliveryContract;?>',  
    				params: { 
    					action: 'get',
    					time_from: Ext.getCmp('time_from_<?php echo $suffix; ?>').getRawValue(),
    					time_to: Ext.getCmp('time_to_<?php echo $suffix; ?>').getRawValue(),
    					firstname: Ext.getCmp('firstname_<?php echo $suffix;?>').getValue(),
    					dateCheck: Ext.getCmp('dateChecked_<?php echo $suffix;?>').getValue(),
    					showLate: Ext.getCmp('showLateButton').pressed,
    					surname: Ext.getCmp('surname_<?php echo $suffix;?>').getValue()
					}
				});
    		}
    	},
    	listeners: {
    		click: function(){
    			if(Ext.getCmp('export_button_o'))
	    			Ext.getCmp('export_button_o').enable();
	    		else if(Ext.getCmp('export_button_d'))
	    			(Ext.getCmp('export_button_d')).enable();
    		}
    	}
	}]
})

