Esempio n. 1
0
  public static PaymentsModel emptyInstance() {

    PaymentsModel p = new PaymentsModel();

    p.m_iPayments = new Integer(0);
    p.m_dPaymentsTotal = new Double(0.0);
    p.m_lpayments = new ArrayList<PaymentsLine>();

    p.m_iSales = null;
    p.m_dSalesBase = null;
    p.m_dSalesTaxes = null;
    p.m_lsales = new ArrayList<SalesLine>();

    return p;
  }
Esempio n. 2
0
  public static PaymentsModel loadInstance(AppView app) throws BasicException {

    PaymentsModel p = new PaymentsModel();

    // Propiedades globales
    p.m_sHost = app.getProperties().getHost();
    p.m_iSeq = app.getActiveCashSequence();
    p.m_dDateStart = app.getActiveCashDateStart();
    p.m_dDateEnd = null;

    // Pagos
    Object[] valtickets =
        (Object[])
            new StaticSentence(
                    app.getSession(),
                    "SELECT COUNT(*), SUM(PAYMENTS.TOTAL) "
                        + "FROM PAYMENTS, RECEIPTS "
                        + "WHERE PAYMENTS.RECEIPT = RECEIPTS.ID AND RECEIPTS.MONEY = ?",
                    SerializerWriteString.INSTANCE,
                    new SerializerReadBasic(new Datas[] {Datas.INT, Datas.DOUBLE}))
                .find(app.getActiveCashIndex());

    if (valtickets == null) {
      p.m_iPayments = new Integer(0);
      p.m_dPaymentsTotal = new Double(0.0);
    } else {
      p.m_iPayments = (Integer) valtickets[0];
      p.m_dPaymentsTotal = (Double) valtickets[1];
    }

    List l =
        new StaticSentence(
                app.getSession(),
                "SELECT PAYMENTS.PAYMENT, SUM(PAYMENTS.TOTAL) "
                    + "FROM PAYMENTS, RECEIPTS "
                    + "WHERE PAYMENTS.RECEIPT = RECEIPTS.ID AND RECEIPTS.MONEY = ? "
                    + "GROUP BY PAYMENTS.PAYMENT",
                SerializerWriteString.INSTANCE,
                new SerializerReadClass(
                    PaymentsModel.PaymentsLine
                        .class)) // new SerializerReadBasic(new Datas[] {Datas.STRING,
                                 // Datas.DOUBLE}))
            .list(app.getActiveCashIndex());

    if (l == null) {
      p.m_lpayments = new ArrayList();
    } else {
      p.m_lpayments = l;
    }

    // Sales
    Object[] recsales =
        (Object[])
            new StaticSentence(
                    app.getSession(),
                    "SELECT COUNT(DISTINCT RECEIPTS.ID), SUM(TICKETLINES.UNITS * TICKETLINES.PRICE) "
                        + "FROM RECEIPTS, TICKETLINES WHERE RECEIPTS.ID = TICKETLINES.TICKET AND RECEIPTS.MONEY = ?",
                    SerializerWriteString.INSTANCE,
                    new SerializerReadBasic(new Datas[] {Datas.INT, Datas.DOUBLE}))
                .find(app.getActiveCashIndex());
    if (recsales == null) {
      p.m_iSales = null;
      p.m_dSalesBase = null;
    } else {
      p.m_iSales = (Integer) recsales[0];
      p.m_dSalesBase = (Double) recsales[1];
    }

    // Taxes
    Object[] rectaxes =
        (Object[])
            new StaticSentence(
                    app.getSession(),
                    "SELECT SUM(TAXLINES.AMOUNT) "
                        + "FROM RECEIPTS, TAXLINES WHERE RECEIPTS.ID = TAXLINES.RECEIPT AND RECEIPTS.MONEY = ?",
                    SerializerWriteString.INSTANCE,
                    new SerializerReadBasic(new Datas[] {Datas.DOUBLE}))
                .find(app.getActiveCashIndex());
    if (rectaxes == null) {
      p.m_dSalesTaxes = null;
    } else {
      p.m_dSalesTaxes = (Double) rectaxes[0];
    }

    List<SalesLine> asales =
        new StaticSentence(
                app.getSession(),
                "SELECT TAXCATEGORIES.NAME, SUM(TAXLINES.AMOUNT) "
                    + "FROM RECEIPTS, TAXLINES, TAXES, TAXCATEGORIES WHERE RECEIPTS.ID = TAXLINES.RECEIPT AND TAXLINES.TAXID = TAXES.ID AND TAXES.CATEGORY = TAXCATEGORIES.ID "
                    + "AND RECEIPTS.MONEY = ?"
                    + "GROUP BY TAXCATEGORIES.NAME",
                SerializerWriteString.INSTANCE,
                new SerializerReadClass(PaymentsModel.SalesLine.class))
            .list(app.getActiveCashIndex());
    if (asales == null) {
      p.m_lsales = new ArrayList<SalesLine>();
    } else {
      p.m_lsales = asales;
    }

    return p;
  }