package com.rjconsultores.ventaboletos.web.gui.controladores.relatorios;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Datebox;

import com.rjconsultores.ventaboletos.service.LogDespesasReceitasDivService;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderLogDespesaReceitaDiv;

@Controller("logReceitasDespesasDiversasController")
@Scope("prototype")
public class LogReceitasDespesasDiversasController extends MyGenericForwardComposer {

		private static final long serialVersionUID = 1L;

		@Autowired
		private DataSource dataSourceRead;
		@Autowired
		private LogDespesasReceitasDivService logDespesasReceitasDivService;
		
		private MyListbox logList;
		private Datebox datInicial;
		private Datebox datFinal;

		@Override
		public void doAfterCompose(Component comp) throws Exception {
			super.doAfterCompose(comp);
			logList.setItemRenderer(new RenderLogDespesaReceitaDiv());
			logList.setData(logDespesasReceitasDivService.obtenerTodos());
		}
		
		public void onClick$btnPesquisa(Event ev) throws InterruptedException {
			logList.setData(logDespesasReceitasDivService.obterPorPeriodo(datInicial.getValue(), datFinal.getValue()));
		}

		public MyListbox getLogList() {
			return logList;
		}

		public void setLogList(MyListbox logList) {
			this.logList = logList;
		}		
}
