Exemplo n.º 1
0
  public BigDecimal calculateTotalDueAmountOther(List<OtherSalesAcDoc> invoices) {

    BigDecimal total = new BigDecimal("0.00");
    for (OtherSalesAcDoc inv : invoices) {
      total = total.add(inv.calculateDueAmount());
    }

    return total;
  }
Exemplo n.º 2
0
  public static synchronized Payment processSingleOSalesPayment(
      BigDecimal amount,
      OtherSalesAcDoc invoice,
      String remark,
      Enums.PaymentType type,
      User user) {
    if (amount.compareTo(invoice.calculateDueAmount().abs()) > 0) {
      return null;
    } else {
      Payment payment = new Payment();
      payment.setRemark(remark);
      payment.setPaymentType(type);
      payment.setCreatedOn(new java.util.Date());
      payment.setCreatedBy(user);

      OtherSalesAcDoc doc = new OtherSalesAcDoc();
      doc.setReference(invoice.getReference());
      doc.setStatus(Enums.AcDocStatus.ACTIVE);
      doc.setDocIssueDate(new java.util.Date());
      doc.setCreatedBy(user);
      doc.setCreatedOn(new java.util.Date());
      doc.setAgent(invoice.getAgent());
      doc.setCustomer(invoice.getCustomer());
      doc.setParent(invoice);
      doc.setPayment(payment);

      if (invoice.calculateDueAmount().compareTo(new BigDecimal("0.00")) == 1) {
        // Make payment
        doc.setType(Enums.AcDocType.PAYMENT);
        doc.setDocumentedAmount(amount.negate()); // Payment saves as negative
      } else if (invoice.calculateDueAmount().compareTo(new BigDecimal("0.00")) == -1) {
        // Make refund
        doc.setType(Enums.AcDocType.REFUND);
        doc.setDocumentedAmount(amount);
      } else {
        // Do nothing
        return null;
      }

      payment.addOtherDocument(doc);
      return payment;
    }
  }