/**
  * After Save
  *
  * @param newRecord new
  * @param success success
  * @return success
  */
 protected boolean afterSave(boolean newRecord, boolean success) {
   if (is_ValueChanged("DueAmt")) {
     log.fine("afterSave");
     getParent();
     m_parent.validatePaySchedule();
     m_parent.save();
   }
   return success;
 } //	afterSave
Exemplo n.º 2
0
 /**
  * Parent Constructor
  *
  * @param parent parent
  * @param invoice invoice
  * @param tLine tax line
  */
 public MTaxDeclarationLine(MTaxDeclaration parent, MInvoice invoice, MInvoiceTax tLine) {
   this(parent.getCtx(), 0, parent.get_TrxName());
   setClientOrg(invoice);
   setC_TaxDeclaration_ID(parent.getC_TaxDeclaration_ID());
   setIsManual(false);
   //
   setC_Invoice_ID(invoice.getC_Invoice_ID());
   setC_BPartner_ID(invoice.getC_BPartner_ID());
   setC_Currency_ID(invoice.getC_Currency_ID());
   setDateAcct(invoice.getDateAcct());
   //
   setC_Tax_ID(tLine.getC_Tax_ID());
   setTaxBaseAmt(tLine.getTaxBaseAmt());
   setTaxAmt(tLine.getTaxAmt());
 } //	MTaxDeclarationLine
  /**
   * Before Save
   *
   * @param newRecord new
   * @return true
   */
  @Override
  protected boolean beforeSave(boolean newRecord) {
    MPayment payment = new MPayment(getCtx(), getC_Payment_ID(), get_TrxName());
    if ((newRecord || is_ValueChanged("C_Invoice_ID"))
        && (payment.getC_Charge_ID() != 0
            || payment.getC_Invoice_ID() != 0
            || payment.getC_Order_ID() != 0)) {
      throw new AdempiereException("@PaymentIsAllocated@");
    }

    BigDecimal check =
        getAmount().add(getDiscountAmt()).add(getWriteOffAmt()).add(getOverUnderAmt());
    if (check.compareTo(getInvoiceAmt()) != 0) {
      throw new AdempiereException(
          "@InvoiceAmt@(" + getInvoiceAmt() + ") <> @Totals@(" + check + ")");
    }

    //	Org
    if (newRecord || is_ValueChanged("C_Invoice_ID")) {
      getInvoice();
      if (m_invoice != null) setAD_Org_ID(m_invoice.getAD_Org_ID());
    }

    return true;
  } //	beforeSave
  /**
   * Parent Constructor
   *
   * @param invoice invoice
   * @param paySchedule payment schedule
   */
  public MInvoicePaySchedule(MInvoice invoice, MPaySchedule paySchedule) {
    super(invoice.getCtx(), 0, invoice.get_TrxName());
    m_parent = invoice;
    setClientOrg(invoice);
    setC_Invoice_ID(invoice.getC_Invoice_ID());
    setC_PaySchedule_ID(paySchedule.getC_PaySchedule_ID());

    //	Amounts
    int scale = MCurrency.getStdPrecision(getCtx(), invoice.getC_Currency_ID());
    BigDecimal due = invoice.getGrandTotal();
    if (due.compareTo(Env.ZERO) == 0) {
      setDueAmt(Env.ZERO);
      setDiscountAmt(Env.ZERO);
      setIsValid(false);
    } else {
      due =
          due.multiply(paySchedule.getPercentage())
              .divide(HUNDRED, scale, BigDecimal.ROUND_HALF_UP);
      setDueAmt(due);
      BigDecimal discount =
          due.multiply(paySchedule.getDiscount()).divide(HUNDRED, scale, BigDecimal.ROUND_HALF_UP);
      setDiscountAmt(discount);
      setIsValid(true);
    }

    //	Dates
    Timestamp dueDate = TimeUtil.addDays(invoice.getDateInvoiced(), paySchedule.getNetDays());
    setDueDate(dueDate);
    Timestamp discountDate =
        TimeUtil.addDays(invoice.getDateInvoiced(), paySchedule.getDiscountDays());
    setDiscountDate(discountDate);
  } //	MInvoicePaySchedule
Exemplo n.º 5
0
 /**
  * Parent Constructor
  *
  * @param parent parent
  * @param invoice invoice
  * @param iLine invoice line
  */
 public MTaxDeclarationLine(MTaxDeclaration parent, MInvoice invoice, MInvoiceLine iLine) {
   this(parent.getCtx(), 0, parent.get_TrxName());
   setClientOrg(invoice);
   setC_TaxDeclaration_ID(parent.getC_TaxDeclaration_ID());
   setIsManual(false);
   //
   setC_Invoice_ID(invoice.getC_Invoice_ID());
   setC_BPartner_ID(invoice.getC_BPartner_ID());
   setC_Currency_ID(invoice.getC_Currency_ID());
   setDateAcct(invoice.getDateAcct());
   //
   setC_InvoiceLine_ID(iLine.getC_InvoiceLine_ID());
   setC_Tax_ID(iLine.getC_Tax_ID());
   if (invoice.isTaxIncluded()) {
     setTaxBaseAmt(iLine.getLineNetAmt());
     setTaxAmt(iLine.getTaxAmt());
   } else {
     setTaxBaseAmt(iLine.getLineNetAmt());
     setTaxAmt(iLine.getTaxAmt());
   }
 } //	MTaxDeclarationLine
 /**
  * Get BPartner of Invoice
  *
  * @return bp
  */
 public int getC_BPartner_ID() {
   if (m_invoice == null) getInvoice();
   if (m_invoice == null) return 0;
   return m_invoice.getC_BPartner_ID();
 } //	getC_BPartner_ID