 // vim: sw=4:ts=4:nu:nospell:fdc=4
 /*global Ext, EQP */
 /**
 * Classe que define o painel de lista de pedido
 *
 * @author Ot�vio Augusto
 * @copyright (c) 2009, by Ot�vio Augusto
 * @company Net On - Solu��es Tecnol�gicas
 * @date 10 de Setembro 2009
 *
 */

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

//Cria a classe base a ser estendida
Financeiro.Relatorio.Report.GastoSetor = Ext.extend(Ext.Panel,{
	
	/**
	 * Inicializa o componente
	 * 
	 */
	initComponent : function(){
		this.store = new Ext.data.JsonStore({
                    proxy: new Ext.data.HttpProxy({
                            url: App.sysURL + 'report_action/listBySetor/',
                            method: 'POST'
                    }),
		    root: 'results',
		    idProperty: 'id',
		    totalProperty: 'total',
		    fields: ['setor',{name: 'gasto', type: 'float'}],
                    listeners:{
                        'load' : function(){
                            Ext.ux.Loader.stop(this.loaderTarget);
                            delete(this.loaerTarget);
                        },
                        scope: this
                    }

		});
			    
	
		var config = {
                    title: 'Gastos por Setor',
                    iconCls: 'app-setor-16',
                    items:[
                        {
                            xtype: 'columnchart',
                            store: this.store,
                            yField: 'gasto',
                            url: App.uiURL + 'lib/ext/resources/charts.swf',
                            xField: 'setor',
                            xAxis: new Ext.chart.CategoryAxis({
                                title: 'Setor'
                            }),
                            yAxis: new Ext.chart.NumericAxis({
                                title: 'Gasto (R$)',
                                labelRenderer : Ext.util.Format.numberRenderer('0.0')
                            }),
                            extraStyle: {
                               xAxis: {
                                    //labelRotation: -90
                                }
                            },
                            tipRenderer : function(chart, record){
                                return "R$ " + Ext.util.Format.number(record.data.gasto, '0.000,00/i') + ' gastos com o setor ' + record.data.setor;
                            }

                        }
                        
                    ]
		};		
		
		//Aplica as configura��es ao objeto
		Ext.apply(this,config);
		
		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Relatorio.Report.GastoSetor.superclass.initComponent.apply(this);
		
		this.on('show',function(){
			//this.store.load();
		},this);
		
	},

        /**
         * Gera o relatório textual
         */
        generateTextualReport : function(){
            if (Ext.getCmp('dt-start').isValid() & Ext.getCmp('dt-end').isValid()){
                window.open(App.sysURL + 'report_action/listBySetor/' + Ext.getCmp('dt-start').getRawValue().replace('/', '-').replace('/', '-') + '/' + Ext.getCmp('dt-end').getRawValue().replace('/','-').replace('/', '-'),'blank');
            }else{
                Ext.ux.Msg.flash({
                   msg: 'O per&iacute;odo n&atilde;o foi informado!',
                   type: 'warning'
                });
            }
            
        }

});

//Registra o novo componente
Ext.reg('relatorio-report-gasto-setor',Financeiro.Relatorio.Report.GastoSetor);


//Cria a classe base a ser estendida
Financeiro.Relatorio.Report.GastoCentroCusto = Ext.extend(Ext.Panel,{

	/**
	 * Inicializa o componente
	 *
	 */
	initComponent : function(){
		this.store = new Ext.data.JsonStore({
                    proxy: new Ext.data.HttpProxy({
                            url: App.sysURL + 'report_action/listByCentroCusto/',
                            method: 'POST'
                    }),
		    root: 'results',
		    idProperty: 'id',
		    totalProperty: 'total',
		    fields: ['c_custo',{name: 'gasto', type: 'float'}],
                    listeners:{
                        'load' : function(){
                            Ext.ux.Loader.stop(this.loaderTarget);
                            delete(this.loaerTarget);
                        },
                        scope: this
                    }
		});


		var config = {
                    title: 'Gastos por Centros de Custo',
                    iconCls: 'app-custo-16',
                    items:[
                        {
                            xtype: 'columnchart',
                            store: this.store,
                            yField: 'gasto',
                            url: App.uiURL + 'lib/ext/resources/charts.swf',
                            xField: 'c_custo',
                            xAxis: new Ext.chart.CategoryAxis({
                                title: 'Centro de Custo'
                            }),
                            yAxis: new Ext.chart.NumericAxis({
                                title: 'Gasto (R$)',
                                labelRenderer : Ext.util.Format.numberRenderer('0.0')
                            }),
                            extraStyle: {
                               xAxis: {
                                    //labelRotation: -90
                                }
                            },
                            tipRenderer : function(chart, record){
                                return "R$ " + Ext.util.Format.number(record.data.gasto, '0.000,00/i') + ' gastos em ' + record.data.c_custo;
                            }

                        }

                    ]
		};

		//Aplica as configura��es ao objeto
		Ext.apply(this,config);

		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Relatorio.Report.GastoCentroCusto.superclass.initComponent.apply(this);

		this.on('show',function(){
			//this.store.load();
		},this);

	},
        
        /**
         * Gera o relatório textual
         */
        generateTextualReport : function(){
            if (Ext.getCmp('dt-start').isValid() & Ext.getCmp('dt-end').isValid()){
                window.open(App.sysURL + 'report_action/listByCentroCusto/' + Ext.getCmp('dt-start').getRawValue().replace('/', '-').replace('/', '-') + '/' + Ext.getCmp('dt-end').getRawValue().replace('/','-').replace('/', '-'),'blank');
            }else{
                Ext.ux.Msg.flash({
                   msg: 'O per&iacute;odo n&atilde;o foi informado!',
                   type: 'warning'
                });
            }

        }

});

//Registra o novo componente
Ext.reg('relatorio-report-gasto-centro-custo',Financeiro.Relatorio.Report.GastoCentroCusto);


//Cria a classe base a ser estendida
Financeiro.Relatorio.Report.GastoItem = Ext.extend(Ext.Panel,{

	/**
	 * Inicializa o componente
	 *
	 */
	initComponent : function(){
		this.store = new Ext.data.JsonStore({
                    proxy: new Ext.data.HttpProxy({
                            url: App.sysURL + 'report_action/listByItem/',
                            method: 'POST'
                    }),
		    root: 'results',
		    idProperty: 'id',
		    totalProperty: 'total',
		    fields: ['item',{name: 'gasto', type: 'float'}, 'qtd'],
                    listeners:{
                        'load' : function(){
                            Ext.ux.Loader.stop(this.loaderTarget);
                            delete(this.loaerTarget);
                        },
                        scope: this
                    }

		});


		var config = {
                    title: 'Gastos por Produto / Serviço',
                    iconCls: 'app-item-16',
                    items:[
                        {
                            xtype: 'columnchart',
                            store: this.store,
                            yField: 'gasto',
                            url: App.uiURL + 'lib/ext/resources/charts.swf',
                            xField: 'item',
                            xAxis: new Ext.chart.CategoryAxis({
                                title: 'Produto / Serviço'
                            }),
                            yAxis: new Ext.chart.NumericAxis({
                                title: 'Gasto (R$)',
                                labelRenderer : Ext.util.Format.numberRenderer('0.0')
                            }),
                            extraStyle: {
                               xAxis: {
                                    labelRotation: -90
                                }
                            },
                            tipRenderer : function(chart, record){
                                return "R$ " + Ext.util.Format.number(record.data.gasto, '0.000,00/i') + ' gastos com ' + record.data.item + '\nTotal de: ' + record.data.qtd + ((parseInt(record.data.qtd) > 1) ? " items" : " item");
                            }

                        }

                    ]
		};

		//Aplica as configura��es ao objeto
		Ext.apply(this,config);

		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Relatorio.Report.GastoItem.superclass.initComponent.apply(this);

		this.on('show',function(){
			//this.store.load();
		},this);

	},

        /**
         * Gera o relatório textual
         */
        generateTextualReport : function(){
            if (Ext.getCmp('dt-start').isValid() & Ext.getCmp('dt-end').isValid()){
                window.open(App.sysURL + 'report_action/listByItem/' + Ext.getCmp('dt-start').getRawValue().replace('/', '-').replace('/', '-') + '/' + Ext.getCmp('dt-end').getRawValue().replace('/','-').replace('/', '-'),'blank');
            }else{
                Ext.ux.Msg.flash({
                   msg: 'O per&iacute;odo n&atilde;o foi informado!',
                   type: 'warning'
                });
            }

        }
});

//Registra o novo componente
Ext.reg('relatorio-report-gasto-item',Financeiro.Relatorio.Report.GastoItem);

