 // 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.Fluxo.Grid');


/**
 * Factory de filtros
 */
function createFilters(){
 return new Ext.ux.grid.GridFilters({
        encode: false,
        local: true,
        filters: [ {
            type: 'string',
            dataIndex: 'cedente'
        },{
            type: 'string',
            dataIndex: 'sacado'
        }, {
            type: 'string',
            dataIndex: 'descricao'
        },{
            type: 'string',
            dataIndex: 'recibo'
        }, {
            type: 'numeric',
            dataIndex: 'valor'
        },{
            type: 'numeric',
            dataIndex: 'valor_pago'
        }, {
            type: 'date',
            dataIndex: 'dt_vencimento'
        },{
            type: 'date',
            dataIndex: 'dt_pagamento'
        }
        ]
    });
}
//Cria a classe base a ser estendida
Financeiro.Fluxo.Grid.Pay = Ext.extend(Ext.grid.EditorGridPanel,{
	
	/**
	 * Inicializa o componente
	 * 
	 */
	initComponent : function(){
		var filters = createFilters();
		var config = {
			title: 'Contas a Pagar',	
			store: this.store = new Ext.data.JsonStore({
		    	proxy: new Ext.data.HttpProxy({ 
		    		url: App.sysURL + 'fluxo_action/listSaida/',
		    		method: 'POST'
		    	}),
			    root: 'results',
			    idProperty: 'id',  
			    totalProperty: 'total',
			    fields: ['id',{name:'dt_vencimento', type: 'date', dateFormat: 'Y-m-d'},{name: 'dt_pagamento', type: 'date', dateFormat: 'Y-m-d'},'cedente','descricao','valor','valor_pago','recibo','parcela_id']
			}),
			columns:[
				{id: 'cedente',header:'Cedente',dataIndex:'cedente',width:200, filterable: true, sortable: true},
				{id: 'descricao',header:'Descri&ccedil;&atilde;o',dataIndex:'descricao',width:150},
				{id: 'recibo',header:'NF / Recibo',dataIndex:'recibo',width:80,editor: new Ext.form.TextField()},
                                {id: 'vencimento',header:'Data Vencimento',dataIndex:'dt_vencimento',width:80, editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor',header:'Valor (R$)',dataIndex:'valor',width:50,editor: new Ext.form.NumberField(), align:'right'},
				{id: 'pagamento',header:'Data Pagamento',dataIndex:'dt_pagamento',width:80,editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor_pago',header:'Valor Pago (R$)',dataIndex:'valor_pago',width:50,editor: new Ext.form.NumberField(), align:'right'}
			],	
			tbar:[
			      {
			    	  text: '<b>Salvar</b>',
			    	  iconCls: 'ui-save-icon',
			    	  handler: this.saveChanges,
			    	  scope: this
			      },			      
			      /*{
			    	  text: 'Adicionar',
			    	  iconCls: 'ui-add-icon',
			    	  handler: this.openForm,
			    	  scope: this
			      },
			      {
			    	  text: 'Remover',
			    	  iconCls: 'ui-delete-icon',
			          handler: this.removeRecord,
		        	  scope: this		
			      },*/'->'
			],
                        bbar: {
                            xtype: 'paging',
                            store: this.store,       
                            displayInfo: true,
                            plugins: [filters],
                            pageSize: App.pageSize,
                            prependButtons: true
        		},
                        plugins: [filters],
			autoExpandRow: 'item_id',			
                        view: new Ext.ux.grid.BufferView({
                                forceFit: true,
                                scrollDelay: false
                        })

			
		};		
		
		//Aplica as configura��es ao objeto
		Ext.apply(this,config);
		
		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Fluxo.Grid.Pay.superclass.initComponent.apply(this);
		
		this.on('show',function(){
			this.store.load();
		},this);
		
	},
	
	/**
	 * Remove um registro de entrada
	 */
	removeRecord : function(){
		var sm = this.getSelectionModel(); 
		
		if (sm.selection){
			record = sm.selection.record;
			
			if (record.get('parcela_id') == ''){
				//Solicita a confirma��o da exclus�o do registro
				Ext.MessageBox.confirm('Confirma&ccedil;&atilde;o', 'Deseja realmente excluir este registro?',
					function(btn){	
						if (btn == 'yes'){
							Ext.Ajax.request({
							   url: App.sysURL + 'fluxo_action/deleteSaida/',
							   success: function(){
									this.store.load();
							   },
							   failure: this.failureDelete,
							   params: {id: record.get('id')},
							   scope: this
							});
						}
					},this
				);
			}else{
				Ext.Msg.show({
					   title: 'Erro',
					   msg: 'N&atilde;o &eacute; poss&iacute;vel excluir este registro, pois o mesmo <br> est&aacute; vinculado a uma parcela de um pedido!',
					   buttons: Ext.MessageBox.OK,
					   icon: Ext.MessageBox.ERROR
					});   			
			}
		}else{
			Ext.Msg.show({
			   title: 'Erro',
			   msg: 'Nenhum registro foi selecionado!',
			   buttons: Ext.MessageBox.OK,
			   icon: Ext.MessageBox.ERROR
			});   			
		}				
		
		
	},
	
	/**
	 * Salva as altera��es feitas nos registros de entradas
	 */
	saveChanges : function(button){
		//Recupera os registros modificados
		var changed = this.store.getModifiedRecords();
		var recordsToSave = new Array();

               this.loaderTarget = button;
               Ext.ux.Loader.start({sender: button, waitingText: 'Salvando...'});

		
		//Percorre a lista de registros modificados pegando seus dados
		for (i = 0; i < changed.length; i++){
			recordsToSave[i]= changed[i].data;				
		}
		
		//Codifica os registros modificados em uma string para envio ao backend
		var encoded = Ext.encode(recordsToSave);
		
		//Chama m�todo remoto para salvamento dos dados
		Ext.Ajax.request({
		   url: App.sysURL + 'fluxo_action/saveSaida/',
		   method: 'POST',
		   success: this.successSave,
		   failure: {},
		   params: {params: encoded},
		   scope: this			
		});				
	},
	
	/**
	 * Fun��o executada caso os registros alterados tenham sido salvos com �xito
	 */
	successSave : function(){
		this.store.commitChanges();
                //Comita as mudan�as no datastore
		this.store.load();

                Ext.ux.Msg.flash({
                    type: 'success',
                    msg: 'Registros atualizados com &ecirc;xito!'
                })
                Ext.ux.Loader.stop(this.loaderTarget);
                delete(this.loaderTarget);
	},
	
	/**
	 * Abre o formul�rio de cria��o de registro de entrada 
	 */
	openForm : function(){
		//Verifica se o formul�rio existe
		if (!this.window){
			//Caso n�o exista, cria o formul�rio
			this.createWindow();
		}
		
		//Exibe o formul�rio de cadastro
		this.window.show();
	},
	
	/**
	 * Cria a janela 
	 */
	createWindow : function(){
		this.window = new Ext.Window({
			title: 'Fluxo de Caixa - Sa&iacute;da',
			iconCls: 'app-financial-16',
			width: 300,
			autoHeight: true,
			closeAction: 'hide',
			defaultButton: 0,
			items:[
				this.form = new Ext.form.FormPanel({
					baseCls: 'x-plain',
					labelAlign:'top',
					bodyStyle: 'padding:8px',
					items:[
						{
							xtype: 'textfield',
							fieldLabel: 'Cedente',
							allowBlank: false,
							name: 'cedente',
							anchor: '98%'
						},
						{
							xtype: 'textfield',
							fieldLabel: 'Descri&ccedil;&atilde;o',
							allowBlank: false,
							name: 'descricao',
							anchor: '98%'
						},
						{
							xtype: 'container',
							layout: 'column',
							defaults:{columnWidth: .5},
							bodyStyle: 'padding-left:8px;',
							items:[
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
											{
												xtype: 'datefield',
												fieldLabel: 'Vencimento',
												allowBlank: false,
												name: 'dt_vencimento',
												anchor: '98%'
											}
							    	   ]
							       },
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
												{
													xtype: 'datefield',
													fieldLabel: 'Pagamento',
													name: 'dt_pagamento',
													anchor: '98%'
												}							    	          
							    	   ]
							       }							       
							]
						},
						{
							xtype: 'container',
							layout: 'column',
							defaults:{columnWidth: .5},
							bodyStyle: 'padding-left:8px;',
							items:[
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
												{
													xtype: 'numberfield',
													fieldLabel: 'Valor (R$)',
													allowBlank: false,
													name: 'valor',
													anchor: '98%'
												}
							    	   ]
							       },
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
												{
													xtype: 'numberfield',
													fieldLabel: 'Valor pago (R$)',
													name: 'valor_pago',
													anchor: '98%'
												}
							    	   ]
							       }							       
							]
						},						
						{
							xtype: 'textfield',
							fieldLabel: 'NF/Recibo',
							name: 'recibo',
							anchor: '98%'
						}						
					]
				})
			],
			buttons:[
				{
					text:'<b>Salvar</b>',
					id: this.id + '-save-btn',
					scope: this,
					handler: this.insertRecord
					
				},
				{
					text: 'Cancelar',
					scope: this,
					handler: function(){
						this.form.form.reset();
						this.window.hide();
					}
				}
			]
		});

		this.window.on('show',function(win){
			win.center();
		},this);
		
	},
	
	insertRecord : function(){
		if (this.form.form.isValid()){
			this.params = this.form.form.getValues(); 
			
			this.form.disable();
			
			Ext.Ajax.request({
			   url: App.sysURL + 'fluxo_action/insertSaida/',
			   success: this.successInsert,
			   failure: this.failureInsert,
			   params: this.params,
			   scope: this			
			});
		}else{
			Ext.Msg.show({
				   title: 'Erro',
				   msg: 'Os campos destacados s&atilde;o obrigat&oacute;rios!',
				   buttons: Ext.MessageBox.OK,
				   icon: Ext.MessageBox.INFO,
				   width:300,
				   scope: this
				});    						
			
		}
		
	},
	
	/**
	 * Confirma a inser��o do registro
	 * 
	 */
	successInsert : function(){
		Ext.Msg.show({
		   title: 'Confirma&ccedil;&atilde;o',
		   msg: 'O registro foi inserido com &ecirc;xito!',
		   buttons: Ext.MessageBox.OK,
		   icon: Ext.MessageBox.INFO,
		   width:300,
		   fn: function(){
				this.form.form.reset();
				this.form.enable();
				this.window.hide();
				this.store.load();		   		
		   },
		   scope: this
		});    						
	}
	
	
	
});

//Registra o novo componente
Ext.reg('fluxo-grid-pay',Financeiro.Fluxo.Grid.Pay);

//Cria a classe base a ser estendida
Financeiro.Fluxo.Grid.Payed = Ext.extend(Ext.grid.GridPanel,{
	
	/**
	 * Inicializa o componente
	 * 
	 */
	initComponent : function(){
                var filters = createFilters();
                
		var config = {
			title: 'Contas Pagas',	
			store: this.store = new Ext.data.JsonStore({
		    	proxy: new Ext.data.HttpProxy({ 
		    		url: App.sysURL + 'fluxo_action/listSaida/',
		    		method: 'POST'
		    	}),
			    root: 'results',
			    idProperty: 'id',  
			    totalProperty: 'total',
			    fields: ['id',{name:'dt_vencimento', type: 'date', dateFormat: 'Y-m-d'},{name: 'dt_pagamento', type: 'date', dateFormat: 'Y-m-d'},'cedente','descricao','valor','valor_pago','recibo','parcela_id']
			}),
			columns:[
				{id: 'cedente',header:'Cedente',dataIndex:'cedente',width:200},
				{id: 'descricao',header:'Descri&ccedil;&atilde;o',dataIndex:'descricao',width:150},
				{id: 'recibo',header:'NF / Recibo',dataIndex:'recibo',width:80,editor: new Ext.form.TextField()},
				{id: 'vencimento',header:'Data Vencimento',dataIndex:'dt_vencimento',width:80, editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor',header:'Valor (R$)',dataIndex:'valor',width:50,editor: new Ext.form.NumberField(), align:'right'},
				{id: 'pagamento',header:'Data Pagamento',dataIndex:'dt_pagamento',width:80,editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor_pago',header:'Valor Pago (R$)',dataIndex:'valor_pago',width:50,editor: new Ext.form.NumberField(), align:'right'}
			],
                        bbar: {
                            xtype: 'paging',
                            store: this.store,
                            displayInfo: true,
                            plugins: [filters],
                            pageSize: App.pageSize,
                            prependButtons: true
        		},
                        plugins: [filters],
			autoExpandRow: 'item_id',	
			//plugins:[this.searchPlugin],
                        view: new Ext.ux.grid.BufferView({
                                forceFit: true,
                                scrollDelay: false
                        })
			
		};		
		
		//Aplica as configura��es ao objeto
		Ext.apply(this,config);
		
		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Fluxo.Grid.Pay.superclass.initComponent.apply(this);
		
		this.on('show',function(){
			this.store.load({params:{list:true}});
		},this);
		
	}
	
});

//Registra o novo componente
Ext.reg('fluxo-grid-payed',Financeiro.Fluxo.Grid.Payed);


//Cria a classe base a ser estendida
Financeiro.Fluxo.Grid.Receive = Ext.extend(Ext.grid.EditorGridPanel,{
	
	/**
	 * Inicializa o componente
	 * 
	 */
	initComponent : function(){
                var filters = createFilters();
                
		var config = {
			title: 'Contas a Receber',	
			store: this.store = new Ext.data.JsonStore({
		    	proxy: new Ext.data.HttpProxy({ 
		    		url: App.sysURL + 'fluxo_action/listEntrada/',
		    		method: 'POST'
		    	}),
			    root: 'results',
			    idProperty: 'id',  
			    totalProperty: 'total',
			    fields: ['id',{name:'dt_vencimento', type: 'date', dateFormat: 'Y-m-d'},{name: 'dt_pagamento', type: 'date', dateFormat: 'Y-m-d'},'sacado','descricao','valor','valor_pago','recibo']
			}),
			columns:[
				{id: 'sacado',header:'Sacado',dataIndex:'sacado',width:130},
				{id: 'descricao',header:'Descri&ccedil;&atilde;o',dataIndex:'descricao',width:90},
				{id: 'recibo',header:'NF / Recibo',dataIndex:'recibo',width:80,editor: new Ext.form.TextField()},
				{id: 'vencimento',header:'Data Vencimento',dataIndex:'dt_vencimento',width:80, editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor',header:'Valor (R$)',dataIndex:'valor',width:80,editor: new Ext.form.NumberField(), align: 'right'},
				{id: 'recebimento',header:'Data Rebimento',dataIndex:'dt_pagamento',width:80,editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor_recebido',header:'Valor Recebido (R$)',dataIndex:'valor_pago',width:80,editor: new Ext.form.NumberField(),align: 'right'}
			],
			tbar:[
			      {
			    	  text: '<b>Salvar</b>',
			    	  iconCls: 'ui-save-icon',
			    	  handler: this.saveChanges,
			    	  scope: this
			      },			      
			      {
			    	  text: 'Adicionar',
			    	  iconCls: 'ui-add-icon',
			    	  handler: this.openForm,
			    	  scope: this
			      },
			      {
			    	  text: 'Remover',
			    	  iconCls: 'ui-delete-icon',
			    	  handler: this.removeRecord,
		        	  scope: this		
			      }			      			      
			],
                        bbar: {
                            xtype: 'paging',
                            store: this.store,
                            displayInfo: true,
                            plugins: [filters],
                            pageSize: App.pageSize,
                            prependButtons: true
        		},
                        plugins: [filters],
			autoExpandRow: 'item_id',			
			view : new Ext.grid.GridView({
				forceFit: true
			})
			
		};		
		
		//Aplica as configura��es ao objeto
		Ext.apply(this,config);
		
		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Fluxo.Grid.Receive.superclass.initComponent.apply(this);
		
		this.on('show',function(){
			this.store.load();
		},this);
		
		
	},
	
	/**
	 * Remove um registro de entrada
	 */
	removeRecord : function(button){
		var sm = this.getSelectionModel(); 
		
		if (sm.selection){
			record = sm.selection.record;

			//Solicita a confirma��o da exclus�o do registro
			Ext.MessageBox.confirm('Confirma&ccedil;&atilde;o', 'Deseja realmente excluir este registro?',
				function(btn){
					if (btn == 'yes'){
                                               Ext.ux.Loader.start({sender: button, waitingText: 'Deletando...'});

						Ext.Ajax.request({
						   url: App.sysURL + 'fluxo_action/deleteEntrada/',
						   success: function(){
							this.store.load();
                                                        Ext.ux.Loader.stop(button);
                                                        Ext.ux.Msg.flash({
                                                            type: 'success',
                                                            msg: 'Registro exclu&iacute;do com &ecirc;xito!'
                                                        })
						   },
						   failure: this.failureDelete,
						   params: {id: record.get('id')},
						   scope: this
						});
					}
				},this
			);
		}else{
			Ext.ux.Msg.flash({
			   msg: 'Nenhum registro foi selecionado!',
                           type: 'warning'
			});   			
		}				
		
		
	},
	
	/**
	 * Salva as altera��es feitas nos registros de entradas
	 */
	saveChanges : function(button){
		//Recupera os registros modificados
		var changed = this.store.getModifiedRecords();
		var recordsToSave = new Array();
               this.loaderTarget = button;
               Ext.ux.Loader.start({sender: button, waitingText: 'Salvando...'});

		//Percorre a lista de registros modificados pegando seus dados
		for (i = 0; i < changed.length; i++){
			recordsToSave[i]= changed[i].data;				
		}
		
		//Codifica os registros modificados em uma string para envio ao backend
		var encoded = Ext.encode(recordsToSave);
		
		//Chama m�todo remoto para salvamento dos dados
		Ext.Ajax.request({
		   url: App.sysURL + 'fluxo_action/saveEntrada/',
		   method: 'POST',
		   success: this.successSave,
		   failure: {},
		   params: {params: encoded},
		   scope: this			
		});				
	},
	
	/**
	 * Fun��o executada caso os registros alterados tenham sido salvos com �xito
	 */
	successSave : function(){
		//Comita as mudan�as no datastore
		this.store.load();

                Ext.ux.Msg.flash({
                    type: 'success',
                    msg: 'Registros atualizados com &ecirc;xito!'
                });
                
                Ext.ux.Loader.stop(this.loaderTarget);
                delete(this.loaerTarget);
	},
	
	/**
	 * Abre o formul�rio de cria��o de registro de entrada 
	 */
	openForm : function(){
		//Verifica se o formul�rio existe
		if (!this.window){
			//Caso n�o exista, cria o formul�rio
			this.createWindow();
		}
		
		//Exibe o formul�rio de cadastro
		this.window.show();
	},
	
	/**
	 * Cria a janela 
	 */
	createWindow : function(){
		this.window = new Ext.Window({
			title: 'Fluxo de Caixa - Entrada',
			iconCls: 'app-financial-16',
			width: 300,
			autoHeight: true,
			closeAction: 'hide',
			defaultButton: 0,
			items:[
				this.form = new Ext.form.FormPanel({
					baseCls: 'x-plain',
					labelAlign:'top',
					bodyStyle: 'padding:8px',
					items:[
						{
							xtype: 'textfield',
							fieldLabel: 'Sacado',
							allowBlank: false,
							name: 'sacado',
							anchor: '98%'
						},
						{
							xtype: 'textfield',
							fieldLabel: 'Descri&ccedil;&atilde;o',
							allowBlank: false,
							name: 'descricao',
							anchor: '98%'
						},
						{
							xtype: 'container',
							layout: 'column',
							defaults:{columnWidth: .5},
							bodyStyle: 'padding-left:8px;',
							items:[
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
											{
												xtype: 'datefield',
												fieldLabel: 'Vencimento',
												allowBlank: false,
												name: 'dt_vencimento',
												anchor: '98%'
											}
							    	   ]
							       },
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
												{
													xtype: 'datefield',
													fieldLabel: 'Pagamento',
													name: 'dt_pagamento',
													anchor: '98%'
												}							    	          
							    	   ]
							       }							       
							]
						},
						{
							xtype: 'container',
							layout: 'column',
							defaults:{columnWidth: .5},
							bodyStyle: 'padding-left:8px;',
							items:[
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
												{
													xtype: 'numberfield',
													fieldLabel: 'Valor (R$)',
													allowBlank: false,
													name: 'valor',
													anchor: '98%'
												}
							    	   ]
							       },
							       {
							    	   xtype: 'container',
							    	   layout: 'form',
							    	   items:[
												{
													xtype: 'numberfield',
													fieldLabel: 'Valor pago (R$)',
													name: 'valor_pago',
													anchor: '98%'
												}
							    	   ]
							       }							       
							]
						},						
						{
							xtype: 'textfield',
							fieldLabel: 'NF/Recibo',
							name: 'recibo',
							anchor: '98%'
						}						
					]
				})
			],
			buttons:[
				{
					text:'<b>Salvar</b>',
					id: this.id + '-save-btn',
					scope: this,
					handler: this.insertRecord
					
				},
				{
					text: 'Cancelar',
					scope: this,
					handler: function(){
						this.form.form.reset();
						this.window.hide();
					}
				}
			]
		});

		this.window.on('show',function(win){
			win.center();
		},this);
		
	},
	
	insertRecord : function(button){
		if (this.form.form.isValid()){
			this.params = this.form.form.getValues(); 

                       this.loaderTarget = button;
                       Ext.ux.Loader.start({sender: button, waitingText: 'Salvando...'});

			//this.form.disable();
			
			Ext.Ajax.request({
			   url: App.sysURL + 'fluxo_action/insertEntrada/',
			   success: this.successInsert,
			   failure: this.failureInsert,
			   params: this.params,
			   scope: this			
			});
		}else{
			Ext.Msg.show({
				   title: 'Erro',
				   msg: 'Os campos destacados s&atilde;o obrigat&oacute;rios!',
				   buttons: Ext.MessageBox.OK,
				   icon: Ext.MessageBox.INFO,
				   width:300,
				   scope: this
				});    						
			
		}
		
	},
	
	/**
	 * Confirma a inser��o do registro
	 * 
	 */
	successInsert : function(){
                Ext.ux.Loader.stop(this.loaderTarget);
                delete(this.loaerTarget);

                this.form.form.reset();
                this.form.enable();
                this.window.hide();
                this.store.load();

                Ext.ux.Msg.flash({
                    msg: 'O registro foi inserido com &ecirc;xito!',
                    type: 'success'
                });

	}
	
	
	
});

//Registra o novo componente
Ext.reg('fluxo-grid-receive',Financeiro.Fluxo.Grid.Receive);


//Cria a classe base a ser estendida
Financeiro.Fluxo.Grid.Received = Ext.extend(Ext.grid.GridPanel,{
	
	/**
	 * Inicializa o componente
	 * 
	 */
	initComponent : function(){
                var filters = createFilters();
                
		var config = {
			title: 'Contas Recebidas',	
			store: this.store = new Ext.data.JsonStore({
		    	proxy: new Ext.data.HttpProxy({ 
		    		url: App.sysURL + 'fluxo_action/listEntrada/',
		    		method: 'POST',
		    		baseParams:{list:'received'}
		    	}),
			    root: 'results',
			    idProperty: 'id',  
			    totalProperty: 'total',
			    fields: ['id',{name:'dt_vencimento', type: 'date', dateFormat: 'Y-m-d'},{name: 'dt_pagamento', type: 'date', dateFormat: 'Y-m-d'},'sacado','descricao','valor','valor_pago','recibo']
			}),
			columns:[
				{id: 'sacado',header:'Sacado',dataIndex:'sacado',width:130},
				{id: 'descricao',header:'Descri&ccedil;&atilde;o',dataIndex:'descricao',width:90},
				{id: 'recibo',header:'NF / Recibo',dataIndex:'recibo',width:80,editor: new Ext.form.TextField()},
				{id: 'vencimento',header:'Data Vencimento',dataIndex:'dt_vencimento',width:80, editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor',header:'Valor (R$)',dataIndex:'valor',width:80,editor: new Ext.form.NumberField(), align: 'right'},
				{id: 'recebimento',header:'Data Rebimento',dataIndex:'dt_pagamento',width:80,editor: new Ext.form.DateField(),renderer: Ext.util.Format.dateRenderer('d/m/Y')},
				{id: 'valor_recebido',header:'Valor Recebido (R$)',dataIndex:'valor_pago',width:80,editor: new Ext.form.NumberField(),align: 'right'}
			],
                        bbar: {
                            xtype: 'paging',
                            store: this.store,
                            displayInfo: true,
                            plugins: [filters],
                            pageSize: App.pageSize,
                            prependButtons: true
        		},
                        plugins: [filters],
			autoExpandRow: 'item_id',			
                        view: new Ext.ux.grid.BufferView({
                                forceFit: true,
                                scrollDelay: false
                        })
			
		};		
		
		//Aplica as configura��es ao objeto
		Ext.apply(this,config);
		
		//Chama o m�todo de inicializa��o da superclasse
		Financeiro.Fluxo.Grid.Receive.superclass.initComponent.apply(this);
		
		this.on('show',function(){
			this.store.load({params:{list:true}});
		},this);
		
		
	}		
});

//Registra o novo componente
Ext.reg('fluxo-grid-received',Financeiro.Fluxo.Grid.Received);

