Ejemplo n.º 1
0
  /**
   * If invoice amount is greater then 0 then It will be payment. If invoice amount is less then 0
   * the It will be a refund. If invoice amount is 0 then payment will inactive
   *
   * @param amount
   * @param invoice
   * @param remark
   * @param type
   * @param user
   * @return
   */
  public static synchronized Payment processSingleTSalesPayment(
      BigDecimal amount,
      TicketingSalesAcDoc 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);

      TicketingSalesAcDoc doc = new TicketingSalesAcDoc();
      doc.setReference(invoice.getReference());
      doc.setStatus(Enums.AcDocStatus.ACTIVE);
      doc.setDocIssueDate(new java.util.Date());
      doc.setPnr(invoice.getPnr());
      doc.setCreatedOn(new java.util.Date());
      doc.setCreatedBy(user);
      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;
      }
      // invoice.addRelatedDocument(doc);
      payment.addTSalesDocument(doc);

      return payment;
    }
  }