📄 minvoicepayschedule.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Invoice Payment Schedule Model
*
* @author Jorg Janke
* @version $Id: MInvoicePaySchedule.java,v 1.12 2005/09/28 01:34:03 jjanke Exp $
*/
public class MInvoicePaySchedule extends X_C_InvoicePaySchedule
{
/**
* Get Payment Schedule of the invoice
* @param C_Invoice_ID invoice id (direct)
* @param C_InvoicePaySchedule_ID id (indirect)
* @return array of schedule
*/
public static MInvoicePaySchedule[] getInvoicePaySchedule(Properties ctx,
int C_Invoice_ID, int C_InvoicePaySchedule_ID, String trxName)
{
String sql = "SELECT * FROM C_InvoicePaySchedule ips ";
if (C_Invoice_ID != 0)
sql += "WHERE C_Invoice_ID=? ";
else
sql += "WHERE EXISTS (SELECT * FROM C_InvoicePaySchedule x"
+ " WHERE x.C_InvoicePaySchedule_ID=? AND ips.C_Invoice_ID=x.C_Invoice_ID) ";
sql += "ORDER BY DueDate";
//
ArrayList<MInvoicePaySchedule> list = new ArrayList<MInvoicePaySchedule>();
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, trxName);
if (C_Invoice_ID != 0)
pstmt.setInt(1, C_Invoice_ID);
else
pstmt.setInt(1, C_InvoicePaySchedule_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
list.add (new MInvoicePaySchedule(ctx, rs, trxName));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "getInvoicePaySchedule", e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MInvoicePaySchedule[] retValue = new MInvoicePaySchedule[list.size()];
list.toArray(retValue);
return retValue;
} // getSchedule
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MInvoicePaySchedule.class);
/** 100 */
private final static BigDecimal HUNDRED = new BigDecimal(100);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param C_InvoicePaySchedule_ID id
*/
public MInvoicePaySchedule (Properties ctx, int C_InvoicePaySchedule_ID, String trxName)
{
super(ctx, C_InvoicePaySchedule_ID, trxName);
if (C_InvoicePaySchedule_ID == 0)
{
// setC_Invoice_ID (0);
// setDiscountAmt (Env.ZERO);
// setDiscountDate (new Timestamp(System.currentTimeMillis()));
// setDueAmt (Env.ZERO);
// setDueDate (new Timestamp(System.currentTimeMillis()));
setIsValid (false);
}
} // MInvoicePaySchedule
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MInvoicePaySchedule (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MInvoicePaySchedule
/**
* 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
/** Parent */
private MInvoice m_parent = null;
/**
* @return Returns the parent.
*/
public MInvoice getParent ()
{
if (m_parent == null)
m_parent = new MInvoice (getCtx(), getC_Invoice_ID(), get_TrxName());
return m_parent;
} // getParent
/**
* @param parent The parent to set.
*/
public void setParent (MInvoice parent)
{
m_parent = parent;
} // setParent
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MInvoicePaySchedule[");
sb.append(get_ID()).append("-Due=" + getDueDate() + "/" + getDueAmt())
.append(";Discount=").append(getDiscountDate() + "/" + getDiscountAmt())
.append("]");
return sb.toString();
} // toString
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
if (is_ValueChanged("DueAmt"))
{
log.fine("beforeSave");
setIsValid(false);
}
return true;
} // beforeSave
/**
* 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
} // MInvoicePaySchedule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -