Exemplo n.º 1
0
  public static MOrder createOrder(
      Properties ctx,
      int bPartnerId,
      boolean isSotrx,
      int priceListId,
      String orderType,
      int warehouseId,
      String paymentRule,
      String trxName)
      throws OperationException {
    int terminalId = POSTerminalManager.getTerminalId(ctx);
    if (terminalId == 0) {
      throw new OperationException("NO POS Terminal!!!");
    }

    MOrder order = new MOrder(ctx, 0, trxName);
    MBPartner bPartner = new MBPartner(ctx, bPartnerId, trxName);

    if (bPartner.getPrimaryC_BPartner_Location_ID() == 0)
      throw new BPartnerNoLocationException("Business partner has no location");
    order.setAD_Org_ID(Env.getAD_Org_ID(ctx));
    // order.setC_POS_ID(terminalId);  TODO - Trifon; order.setU_POSTerminal_ID(terminalId);
    order.setBPartner(bPartner);
    order.setC_BPartner_ID(bPartner.get_ID());
    order.setC_BPartner_Location_ID(bPartner.getPrimaryC_BPartner_Location_ID());
    order.setIsSOTrx(isSotrx);

    order.setM_PriceList_ID(priceListId);

    MPriceList priceList = new MPriceList(ctx, priceListId, null);
    order.setC_Currency_ID(priceList.getC_Currency_ID());
    order.setDocAction(DocumentEngine.ACTION_Complete);
    order.setSalesRep_ID(Env.getAD_User_ID(ctx));

    if (orderType.equalsIgnoreCase(UDIOrderTypes.CREDIT_ORDER_NO_SHIPMENT.getOrderType())) {
      /**
       * because for credit orders, compiere generates shipment automatically, so we want a credit
       * order with standard doc type
       */
      order.setC_DocTypeTarget_ID(
          getDocTypeFromOrderType(ctx, UDIOrderTypes.POS_ORDER.getOrderType(), isSotrx));
      order.setOrderType(UDIOrderTypes.CREDIT_ORDER.getOrderType());
    } else {
      order.setC_DocTypeTarget_ID(getDocTypeFromOrderType(ctx, orderType, isSotrx));
      order.setOrderType(orderType);
    }

    order.setM_Warehouse_ID(warehouseId);
    order.setIsDiscountPrinted(true);
    if (paymentRule != null) order.setPaymentRule(paymentRule);

    order.setDateOrdered(new Timestamp(System.currentTimeMillis()));
    order.setInvoiceRule(MOrder.INVOICERULE_Immediate);

    PoManager.save(order);

    return order;
  }
Exemplo n.º 2
0
  public Vector<Vector<Object>> getParentData(MBPartner bpartner) {
    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    Vector<Object> line = new Vector<Object>();

    List<MBPartner> students =
        new Query(
                ctx,
                MBPartner.Table_Name,
                "C_BPartner_ID <> ? AND C_BPartner_ID IN (Select C_BPartner_ID from AD_User where BPartner_Parent_ID=?)",
                null) // missing contact clauses
            .setParameters(bpartner.get_ID(), bpartner.get_ID())
            .list();

    for (MBPartner student : students) {

      studentList.put(student.getValue(), student);
      findPaymentSchedule(student);

      line.add(student.getValue());
      line.add(student.getName());
      line.add("0000"); // replace by SecureCode
      line.add("0000"); // replace by Enrollment
      line.add("0000"); // replace by Transport Code

      String whereClause =
          "AD_User_ID IN (Select AD_User_ID from AD_User where BPartner_Parent_ID=? AND C_BPartner_ID=? AND ISPAYMENTRESPONSIBLE=? )";
      MUser contact =
          new Query(ctx, MUser.Table_Name, whereClause, null)
              .setParameters(bpartner.get_ID(), student.get_ID(), true)
              .first();

      line.add(contact != null ? true : false);

      data.add(line);
      line = new Vector<Object>();
    }

    return data;
  }
Exemplo n.º 3
0
  /**
   * ************************************************************************ Set BPartner
   *
   * @param C_BPartner_ID id
   */
  public void setC_BPartner_ID(int C_BPartner_ID) {
    log.debug("PosSubCustomer.setC_BPartner_ID=" + C_BPartner_ID);
    if (C_BPartner_ID == 0) m_bpartner = null;
    else {
      m_bpartner = new MBPartner(p_ctx, C_BPartner_ID, null);
      if (m_bpartner.get_ID() == 0) m_bpartner = null;
    }

    //	Set Info
    if (m_bpartner != null) {
      f_name.setText(m_bpartner.getName());
    } else {
      f_name.setText(null);
    }
    //	Sets Currency
    m_M_PriceList_Version_ID = 0;
    getM_PriceList_Version_ID();
    // fillCombos();
    if (p_posPanel.m_order != null && m_bpartner != null)
      p_posPanel.m_order.setBPartner(
          m_bpartner); // added by ConSerTi to update the client in the request
  } //	setC_BPartner_ID
Exemplo n.º 4
0
  public boolean completePayments(int docType_ID, String documentNo, Timestamp trxDate) {
    boolean success = false;

    message_error = "No se pudo completar los pagos";

    try {

      success = validatePayments();

      // create header

      caPayment = new X_CA_Payment(ctx, 0, null);
      caPayment.setC_BPartner_ID(m_bpartner.get_ID());
      caPayment.setDocumentNo(documentNo);
      caPayment.setC_DocType_ID(docType_ID);
      caPayment.setDateTrx(trxDate);
      caPayment.saveEx();

      // save lines

      // buscar tabla de prioridades
      // List<X_CA_PaymentPreference> priorities = new Query(ctx, X_CA_PaymentPreference.Table_Name,
      // "", null)
      // .setOnlyActiveRecords(true).setOrderBy("SeqNo").list();

      for (int tableRow = 0; tableRow <= paymentTable.getRowCount() - 1; tableRow++) {

        String type = getComboValue(tableRow, 0);

        if (!"AN".equals(type) && !"ME".equals(type))
          throw new AdempiereException("Indicar tipo de pago (Anual/Mensual)");

        String paymentType = getComboValue(tableRow, 1);
        String card = getComboValue(tableRow, 2);
        java.lang.Number quote = (java.lang.Number) paymentTable.getValueAt(tableRow, 3);
        Boolean hasinteres = (Boolean) paymentTable.getValueAt(tableRow, 4);
        String account = getComboValue(tableRow, 5);
        String reference = (String) paymentTable.getValueAt(tableRow, 6);
        java.lang.Number amount = (java.lang.Number) paymentTable.getValueAt(tableRow, 7);

        for (int studentRow = 0; studentRow <= studentTable.getRowCount() - 1; studentRow++) {

          String value = (String) studentTable.getValueAt(studentRow, INDEX_VALUE);
          I_C_BPartner student = studentList.get(value);
          Boolean doPay = (Boolean) studentTable.getValueAt(studentRow, 5);

          if (doPay) {
            MTimeExpenseLine currentSchedule = null;

            for (MTimeExpenseLine schedule : paymentSchedules) {
              if (schedule.getC_BPartner_ID() == student.getC_BPartner_ID()) {
                currentSchedule = schedule;
              }
            }

            if (currentSchedule == null) throw new AdempiereException("No existe programa de Pago");

            // generar nuevo pago
            MPayment payment = new MPayment(ctx, 0, null);

            payment.set_ValueOfColumn("CA_Payment_ID", caPayment.get_ID());
            payment.setC_DocType_ID(1000008); // pago, que siempre no, que es cobro
            payment.setC_BankAccount_ID(Integer.parseInt(account));

            payment.set_ValueOfColumn("SalesRep_ID", Env.getContextAsInt(ctx, "#AD_User_ID"));

            payment.setTenderType(paymentType);

            if ("K".equals(paymentType)
                || "Q".equals(paymentType)) // cheque nacional - internacional
            {
              payment.setCheckNo(reference);
            } else if ("A".equals(paymentType)) // Depósito directo
            {
              payment.setAccountNo(reference);
            } else if ("C".equals(paymentType)) // Tarjeta de Crédito
            {
              payment.setCreditCardType(card);
              payment.setCreditCardNumber(reference);
              payment.set_ValueOfColumn("NumberOfShares", new BigDecimal(String.valueOf(quote)));
              payment.set_ValueOfColumn("HasInterests", hasinteres);
            }

            payment.setC_BPartner_ID(student.getC_BPartner_ID());

            payment.setPayAmt(new BigDecimal(String.valueOf(getAmount(currentSchedule, type))));
            payment.setC_Order_ID(currentSchedule.get_ID());
            payment.setC_Currency_ID(100); // USD

            if (payment.getPayAmt().compareTo(new BigDecimal("0")) > 0) {
              payment.saveEx();
              payment.processIt(DocAction.ACTION_Complete);
            }
          }
        }
      }

      success = true;
    } catch (Exception e) {
      success = false;
      e.printStackTrace();
      message_error = e.getMessage();
    }

    return success;
  }