Package br.com.colegio.dao

Source Code of br.com.colegio.dao.BoletoDAO

package br.com.colegio.dao;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import br.com.colegio.dao.storage.BoletoData;
import br.com.colegio.dao.storage.Storage;
import br.com.colegio.vo.Boleto;

public class BoletoDAO
{
  public static Collection<Object> list()
  {
    try
    {
      return Storage.select(Boleto.class.getName(), null);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static Boleto get(Long cod)
  {
    try
    {
      Object res = Storage.get(Boleto.class.getName(), cod);

      if (res != null)
        return (Boleto)res;
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static Collection<Object> getByCodigo(String codigo)
  {
    try
    {
      String params = "String p1";
      String filter = " codigo == p1";

      Map<String, Object> parVal = new HashMap<String, Object>();
      parVal.put("p1", codigo);

      return Storage.select(Boleto.class.getName(), filter, params, parVal, null);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static Collection<Object> getByStatusAndData(Date di, Date df, String status, String order)
  {
    try
    {
      String params = "String p1, String p2, String p3";
      String filter = null;

      if (di != null && df != null)
        filter = "dataVencimento >= p1 && dataVencimento < p2";

      if (filter == null && status != null && !status.equals(""))
        filter = "statusBoleto == p3";
      else if (status != null && !status.equals(""))
        filter += " && statusBoleto == p3";

      Map<String, Object> parVal = new HashMap<String, Object>();
      parVal.put("p1", di);
      parVal.put("p2", df);
      parVal.put("p3", status);

      return Storage.select(Boleto.class.getName(), filter, params, parVal, order);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static Collection<Object> getByAluno(String codAluno)
  {
    try
    {
      String params = "String p1";
      String filter = "alunoBoleto == p1";

      Map<String, Object> parVal = new HashMap<String, Object>();
      parVal.put("p1", codAluno);

      return Storage.select(Boleto.class.getName(), filter, params, parVal, null);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static Collection<Object> get(String filter, String params, Map<String, Object> parVal)
  {
    try
    {
      return Storage.select(Boleto.class.getName(), filter, params, parVal, null);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static Collection<Object> getByStatus(Long codStatus)
  {
    try
    {
      String params = "String p1";
      String filter = " statusBoleto == p1";

      Map<String, Object> parVal = new HashMap<String, Object>();
      parVal.put("p1", codStatus);

      return Storage.select(Boleto.class.getName(), filter, params, parVal, null);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    return null;
  }

  public static String save(String codigo,
                String grupo,
                Date dataVencimento,
                Date dataEmissao,
                double valorTotal,
                double desconto,
                double multa,
                Date dataMulta,
                double jurosDia,
                String descricao,
                String descricaoCompleta,
                Date dataPagamento,
                double pagamentoValor,
                double pagamentoDesconto,
                double pagamentoMulta,
                double pagamentoTarifa,
                Date creditoData,
                String alunoBoleto,
                int codigoRetornoBoleto,
                int pagamentoCanalBoleto,
                String statusBoleto,
                String pagamentoTipo) throws Exception
  {
    Boleto b = BoletoData.getInstance().get(codigo);

    if (b == null)
    {
      b = new Boleto();
      b.setCodigo(codigo);
      b.setGrupo(grupo);
      b.setDataVencimento(dataVencimento);
      b.setDataEmissao(dataEmissao);
      b.setValorTotal(valorTotal);
      b.setDesconto(desconto);
      b.setMulta(multa);
      b.setDataMulta(dataMulta);
      b.setJurosDia(jurosDia);
      b.setDescricao(descricao);
      b.setDescricaoCompleta(descricaoCompleta);
      b.setDataPagamento(dataPagamento);
      b.setPagamentoValor(pagamentoValor);
      b.setPagamentoDesconto(pagamentoDesconto);
      b.setPagamentoMulta(pagamentoMulta);
      b.setPagamentoTarifa(pagamentoTarifa);
      b.setCreditoData(creditoData);
      b.setAlunoBoleto(alunoBoleto);
      b.setCodigoRetornoBoleto(codigoRetornoBoleto);
      b.setPagamentoCanalBoleto(pagamentoCanalBoleto);
      b.setStatusBoleto(statusBoleto);
      b.setPagamentoTipo(pagamentoTipo);

      BoletoData.getInstance().atualizaData((Boleto)Storage.save(b));

      return "INSERT : " + codigo;
    }
    //else if (!b.getStatusBoleto().getCodigo().equalsIgnoreCase("P")
    //    && !b.getStatusBoleto().getCodigo().equalsIgnoreCase("C"))
    else if(statusBoleto.equals("P"))
    {
      b.setCodigo(codigo);
      b.setGrupo(grupo);
      b.setDataVencimento(dataVencimento);
      b.setDataEmissao(dataEmissao);
      b.setValorTotal(valorTotal);
      b.setDesconto(desconto);
      b.setMulta(multa);
      b.setDataMulta(dataMulta);
      b.setJurosDia(jurosDia);
      b.setDescricao(descricao);
      b.setDescricaoCompleta(descricaoCompleta);
      b.setDataPagamento(dataPagamento);
      b.setPagamentoValor(pagamentoValor);
      b.setPagamentoDesconto(pagamentoDesconto);
      b.setPagamentoMulta(pagamentoMulta);
      b.setPagamentoTarifa(pagamentoTarifa);
      b.setCreditoData(creditoData);
      b.setAlunoBoleto(alunoBoleto);
      b.setCodigoRetornoBoleto(codigoRetornoBoleto);
      b.setPagamentoCanalBoleto(pagamentoCanalBoleto);
      b.setStatusBoleto(statusBoleto);
      b.setPagamentoTipo(pagamentoTipo);

      BoletoData.getInstance().atualizaData((Boleto)Storage.save(b));

      return "UPDATE : " + codigo;
    }

    return "- : " + codigo;
  }

  public static Boleto save(Boleto reg) throws Exception
  {
    return (Boleto)Storage.save(reg);
  }

  public static void delete(Long reg) throws Exception
  {
    Storage.delete(Boleto.class.getName(), reg);
  }
}
TOP

Related Classes of br.com.colegio.dao.BoletoDAO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.