 // vim: sw=4:ts=4:nu:nospell:fdc=4
 /*global Ext, EQP */
 /**
 * Componente de �rea de administra��o de grupos
 *
 * @author Ot�vio Augusto
 * @copyright (c) 2009, by Ot�vio Augusto
 * @company Net On - Solu��es Tecnol�gicas
 * @date 7 de Setembro 2009
 *
 */

//Define o namespace
Ext.ns('Financeiro');

Financeiro.Relatorio = Ext.extend(App.Module,{
	
	title: 'Relat&oacute;rios',
	id: 'financeiro-relatorio',
	bodyBorder: false,
	layout: 'fit',
	iconCls: 'app-report-16',
	moduleAction: 'fluxo_action/',
	
	/**
	 * Inicializa o componente
	 */
	initComponent: function(){		
		//Chama o initComponent da super classe
		Financeiro.Relatorio.superclass.initComponent.apply(this, arguments);
	},//end of initComponent
		
	/**
	 * Cria o DataGrid de visualiza��o de Grupos
	 */
	createGrid : function(){
				
		//Cria o DataStore,
		this.store = new Ext.data.JsonStore({
                    proxy: new Ext.data.HttpProxy({
                            url: App.sysURL + this.moduleAction + 'findAll/',
                            method: 'POST'
                    }),
		    root: 'results',
		    idProperty: 'id',  
		    totalProperty: 'total',
		    fields: ['descricao','id']
		});
		
		var panel = {
			xtype: 'tabpanel',
			id: this.id + '-grid',
			activeTab: 0,
                        tbar:[
                          {
                            xtype: 'tbtext',
                            text: 'De:'
                          },
                          {
                              xtype: 'datefield',
                              id: 'dt-start',
                              allowBlank: false
                          },
                          '',
                          {
                            xtype: 'tbtext',
                            text: 'At&eacute;:'
                          },
                          {
                              xtype: 'datefield',
                              id: 'dt-end',
                              allowBlank: false
                          },'','',
                          '-',
                          {
                              xtype: 'button',
                              text: '<b>Gerar Gráfico</b>',
                              iconCls: 'app-report-16',
                              scope: this,
                              handler: function(button){
                                   Ext.getCmp(this.id + '-grid').getActiveTab().loaderTarget = button;
                                   Ext.ux.Loader.start({sender: button, waitingText: 'Gerando gr&aacute;fico...'});

                                  Ext.getCmp(this.id + '-grid').getActiveTab().store.load({
                                      params:{
                                          start: Ext.getCmp('dt-start').getValue(),
                                          end: Ext.getCmp('dt-end').getValue()
                                      }
                                  })
                              }
                          },'-',
                          {
                              text: 'Gerar relat&oacute;rio (em texto)',
                              iconCls: 'app-pdf',
                              handler: function(){
                                  Ext.getCmp(this.id + '-grid').getActiveTab().generateTextualReport();
                              },
                              scope: this
                          }
                        ],
                        layoutConfig:{
                              deferredRender:false,
                              layoutOnCardChange: true
                        },
			items:[
			       {
			    	   xtype: 'relatorio-report-gasto-setor'
			       },
			       {
			    	   xtype: 'relatorio-report-gasto-centro-custo'
			       },
			       {
			    	   xtype: 'relatorio-report-gasto-item'
			       }


			]
		};
		
		//Retorna o DataGrid criado
		return panel;
	},	
	
	/**
	 * Cria a janela e o formul�rio de edi��o de registro
	 */
	createForm : function(){
            this.window = new Ext.Window({});
	}
});

//Registra o novo componente
Ext.reg('financeiro-relatorio',Financeiro.Relatorio);
