📄 calloutcashjournal.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.*;
/**
* Cash Book Journal Callouts
*
* @author Jorg Janke
* @version $Id: CalloutCashJournal.java,v 1.7 2005/11/06 01:17:27 jjanke Exp $
*/
public class CalloutCashJournal extends CalloutEngine
{
/**
*
Cash Book Changed.
*
Update Beginning Balance
*
@return -
*/
public String cashBook (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
if (value == null)
return "";
int C_CashBook_ID = ((Integer)value).intValue();
MCashBook cb = MCashBook.get(ctx, C_CashBook_ID);
String sql = "SELECT * FROM C_CashBook "
+ "WHERE C_CashBook_ID = ?";
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_CashBook_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
cb = new MCashBook(ctx, rs,null);
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
mTab.setValue("BeginningBalance", cb.getCurrentBalance());
return "";
} //cashBook
/**
* Cash Journal Line Invoice.
* when Invoice selected
* - set C_Currency, DiscountAnt, Amount, WriteOffAmt
*/
public String invoice (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
if (isCalloutActive()) // assuming it is resetting value
return "";
setCalloutActive(true);
Integer C_Invoice_ID = (Integer)value;
if (C_Invoice_ID == null || C_Invoice_ID.intValue() == 0)
{
mTab.setValue("C_Currency_ID", null);
setCalloutActive(false);
return "";
}
// Date
Timestamp ts = Env.getContextAsDate(ctx, WindowNo, "DateAcct"); // from C_Cash
if (ts == null)
ts = new Timestamp(System.currentTimeMillis());
//
String sql = "SELECT C_BPartner_ID, C_Currency_ID," // 1..2
+ "invoiceOpen(C_Invoice_ID, 0), IsSOTrx, " // 3..4
+ "paymentTermDiscount(invoiceOpen(C_Invoice_ID, 0),C_Currency_ID,C_PaymentTerm_ID,DateInvoiced,?) "
+ "FROM C_Invoice WHERE C_Invoice_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setTimestamp(1, ts);
pstmt.setInt(2, C_Invoice_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
mTab.setValue("C_Currency_ID", new Integer(rs.getInt(2)));
BigDecimal PayAmt = rs.getBigDecimal(3);
BigDecimal DiscountAmt = rs.getBigDecimal(5);
boolean isSOTrx = "Y".equals(rs.getString(4));
if (!isSOTrx)
{
PayAmt = PayAmt.negate();
DiscountAmt = DiscountAmt.negate();
}
//
mTab.setValue("Amount", PayAmt.subtract(DiscountAmt));
mTab.setValue("DiscountAmt", DiscountAmt);
mTab.setValue("WriteOffAmt", Env.ZERO);
Env.setContext(ctx, WindowNo, "InvTotalAmt", PayAmt.toString());
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, "invoice", e);
setCalloutActive(false);
return e.getLocalizedMessage();
}
setCalloutActive(false);
return "";
} // CashJournal_Invoice
/**
* Cash Journal Line Invoice Amounts.
* when DiscountAnt, Amount, WriteOffAmt change
* making sure that add up to InvTotalAmt (created by CashJournal_Invoice)
*/
public String amounts (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
// Needs to be Invoice
if (isCalloutActive() || !"I".equals(mTab.getValue("CashType")))
return "";
// Check, if InvTotalAmt exists
String total = Env.getContext(ctx, WindowNo, "InvTotalAmt");
if (total == null || total.length() == 0)
return "";
BigDecimal InvTotalAmt = new BigDecimal(total);
setCalloutActive(true);
BigDecimal PayAmt = (BigDecimal)mTab.getValue("Amount");
BigDecimal DiscountAmt = (BigDecimal)mTab.getValue("DiscountAmt");
BigDecimal WriteOffAmt = (BigDecimal)mTab.getValue("WriteOffAmt");
String colName = mField.getColumnName();
log.fine(colName + " - Invoice=" + InvTotalAmt
+ " - Amount=" + PayAmt + ", Discount=" + DiscountAmt + ", WriteOff=" + WriteOffAmt);
// Amount - calculate write off
if (colName.equals("Amount"))
{
WriteOffAmt = InvTotalAmt.subtract(PayAmt).subtract(DiscountAmt);
mTab.setValue("WriteOffAmt", WriteOffAmt);
}
else // calculate PayAmt
{
PayAmt = InvTotalAmt.subtract(DiscountAmt).subtract(WriteOffAmt);
mTab.setValue("Amount", PayAmt);
}
setCalloutActive(false);
return "";
} // amounts
} // CalloutCashJournal
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -