📄 mpayselectioncheck.java
字号:
bp[BP_VALUE] = "";
bp[BP_NAME] = rs.getString(2);
if (bp[BP_NAME] == null)
bp[BP_NAME] = "";
bp[BP_CONTACT] = rs.getString(3);
if (bp[BP_CONTACT] == null)
bp[BP_CONTACT] = "";
bp[BP_ADDR1] = rs.getString(4);
if (bp[BP_ADDR1] == null)
bp[BP_ADDR1] = "";
bp[BP_ADDR2] = rs.getString(5);
if (bp[BP_ADDR2] == null)
bp[BP_ADDR2] = "";
bp[BP_CITY] = rs.getString(6);
if (bp[BP_CITY] == null)
bp[BP_CITY] = "";
bp[BP_REGION] = rs.getString(7);
if (bp[BP_REGION] == null)
bp[BP_REGION] = "";
bp[BP_POSTAL] = rs.getString(8);
if (bp[BP_POSTAL] == null)
bp[BP_POSTAL] = "";
bp[BP_COUNTRY] = rs.getString(9);
if (bp[BP_COUNTRY] == null)
bp[BP_COUNTRY] = "";
bp[BP_REFNO] = rs.getString(10);
if (bp[BP_REFNO] == null)
bp[BP_REFNO] = "";
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, "getBPartnerInfo", e);
}
return bp;
} // getBPartnerInfo
/**************************************************************************
* Confirm Print.
* Create Payments the first time
* @param checks checks
* @return last Document number or 0 if nothing printed
*/
public static int confirmPrint (MPaySelectionCheck[] checks, MPaymentBatch batch)
{
int lastDocumentNo = 0;
for (int i = 0; i < checks.length; i++)
{
MPaySelectionCheck check = checks[i];
MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), null);
// Existing Payment
if (check.getC_Payment_ID() != 0)
{
// Update check number
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
{
payment.setCheckNo(check.getDocumentNo());
if (!payment.save())
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
}
}
else // New Payment
{
payment = new MPayment(check.getCtx(), 0, null);
payment.setAD_Org_ID(check.getAD_Org_ID());
//
if (check.getPaymentRule().equals(PAYMENTRULE_Check))
payment.setBankCheck (check.getParent().getC_BankAccount_ID(), false, check.getDocumentNo());
else if (check.getPaymentRule().equals(PAYMENTRULE_CreditCard))
payment.setTenderType(MPayment.TENDERTYPE_CreditCard);
else if (check.getPaymentRule().equals(PAYMENTRULE_DirectDeposit)
|| check.getPaymentRule().equals(PAYMENTRULE_DirectDeposit))
payment.setBankACH(check.getParent().getC_BankAccount_ID(), false);
else
{
s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
continue;
}
payment.setTrxType(MPayment.TRXTYPE_CreditPayment);
payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
payment.setDiscountAmt(check.getDiscountAmt());
payment.setDateTrx(check.getParent().getPayDate());
payment.setC_BPartner_ID(check.getC_BPartner_ID());
// Link to Batch
if (batch != null)
{
if (batch.getC_PaymentBatch_ID() == 0)
batch.save(); // new
payment.setC_PaymentBatch_ID(batch.getC_PaymentBatch_ID());
}
// Link to Invoice
MPaySelectionLine[] psls = check.getPaySelectionLines(false);
s_log.fine("confirmPrint - " + check + " (#SelectionLines=" + psls.length + ")");
if (check.getQty() == 1 && psls != null && psls.length == 1)
{
MPaySelectionLine psl = psls[0];
s_log.fine("Map to Invoice " + psl);
//
payment.setC_Invoice_ID (psl.getC_Invoice_ID());
payment.setDiscountAmt (psl.getDiscountAmt());
payment.setWriteOffAmt(psl.getDifferenceAmt());
BigDecimal overUnder = psl.getOpenAmt().subtract(psl.getPayAmt())
.subtract(psl.getDiscountAmt()).subtract(psl.getDifferenceAmt());
payment.setOverUnderAmt(overUnder);
}
else
payment.setDiscountAmt(Env.ZERO);
payment.setWriteOffAmt(Env.ZERO);
if (!payment.save())
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
//
int C_Payment_ID = payment.get_ID();
if (C_Payment_ID < 1)
s_log.log(Level.SEVERE, "Payment not created=" + check);
else
{
check.setC_Payment_ID (C_Payment_ID);
check.save(); // Payment process needs it
// Should start WF
payment.processIt(DocAction.ACTION_Complete);
if (!payment.save())
s_log.log(Level.SEVERE, "Payment not saved: " + payment);
}
} // new Payment
// Get Check Document No
try
{
int no = Integer.parseInt(check.getDocumentNo());
if (lastDocumentNo < no)
lastDocumentNo = no;
}
catch (NumberFormatException ex)
{
s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
}
check.setIsPrinted(true);
check.setProcessed(true);
if (!check.save ())
s_log.log(Level.SEVERE, "Check not saved: " + check);
} // all checks
s_log.fine("Last Document No = " + lastDocumentNo);
return lastDocumentNo;
} // confirmPrint
/** Logger */
static private CLogger s_log = CLogger.getCLogger (MPaySelectionCheck.class);
/** BPartner Info Index for Value */
private static final int BP_VALUE = 0;
/** BPartner Info Index for Name */
private static final int BP_NAME = 1;
/** BPartner Info Index for Contact Name */
private static final int BP_CONTACT = 2;
/** BPartner Info Index for Address 1 */
private static final int BP_ADDR1 = 3;
/** BPartner Info Index for Address 2 */
private static final int BP_ADDR2 = 4;
/** BPartner Info Index for City */
private static final int BP_CITY = 5;
/** BPartner Info Index for Region */
private static final int BP_REGION = 6;
/** BPartner Info Index for Postal Code */
private static final int BP_POSTAL = 7;
/** BPartner Info Index for Country */
private static final int BP_COUNTRY = 8;
/** BPartner Info Index for Reference No */
private static final int BP_REFNO = 9;
/**************************************************************************
* Constructor
* @param ctx context
* @param C_PaySelectionCheck_ID C_PaySelectionCheck_ID
*/
public MPaySelectionCheck (Properties ctx, int C_PaySelectionCheck_ID, String trxName)
{
super(ctx, C_PaySelectionCheck_ID, trxName);
if (C_PaySelectionCheck_ID == 0)
{
// setC_PaySelection_ID (0);
// setC_BPartner_ID (0);
// setPaymentRule (null);
setPayAmt (Env.ZERO);
setDiscountAmt(Env.ZERO);
setIsPrinted (false);
setIsReceipt (false);
setQty (0);
}
} // MPaySelectionCheck
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MPaySelectionCheck(Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MPaySelectionCheck
/**
* Create from Line
* @param line payment selection
*/
public MPaySelectionCheck (MPaySelectionLine line, String PaymentRule)
{
this (line.getCtx(), 0, line.get_TrxName());
setClientOrg(line);
setC_PaySelection_ID (line.getC_PaySelection_ID());
setC_BPartner_ID (line.getInvoice().getC_BPartner_ID());
setPaymentRule (PaymentRule);
//
setIsReceipt(line.isSOTrx());
setPayAmt (line.getPayAmt());
setDiscountAmt(line.getDiscountAmt());
setQty (1);
} // MPaySelectionCheck
/**
* Create from Pay Selection
* @param ps payment selection
*/
public MPaySelectionCheck (MPaySelection ps, String PaymentRule)
{
this (ps.getCtx(), 0, ps.get_TrxName());
setClientOrg(ps);
setC_PaySelection_ID (ps.getC_PaySelection_ID());
setPaymentRule (PaymentRule);
} // MPaySelectionCheck
/** Parent */
private MPaySelection m_parent = null;
/** Payment Selection lines of this check */
private MPaySelectionLine[] m_lines = null;
/**
* Add Payment Selection Line
* @param line line
*/
public void addLine (MPaySelectionLine line)
{
if (getC_BPartner_ID() != line.getInvoice().getC_BPartner_ID())
throw new IllegalArgumentException("Line for fifferent BPartner");
//
if (isReceipt() == line.isSOTrx())
{
setPayAmt (getPayAmt().add(line.getPayAmt()));
setDiscountAmt(getDiscountAmt().add(line.getDiscountAmt()));
}
else
{
setPayAmt (getPayAmt().subtract(line.getPayAmt()));
setDiscountAmt(getDiscountAmt().subtract(line.getDiscountAmt()));
}
setQty (getQty()+1);
} // addLine
/**
* Get Parent
* @return parent
*/
public MPaySelection getParent()
{
if (m_parent == null)
m_parent = new MPaySelection (getCtx(), getC_PaySelection_ID(), get_TrxName());
return m_parent;
} // getParent
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MPaymentCheck[");
sb.append(get_ID()).append("-").append(getDocumentNo())
.append("-").append(getPayAmt())
.append(",PaymetRule=").append(getPaymentRule())
.append(",Qty=").append(getQty())
.append("]");
return sb.toString();
} // toString
/**
* Get Payment Selection Lines of this check
* @param requery requery
* @return array of peyment selection lines
*/
public MPaySelectionLine[] getPaySelectionLines (boolean requery)
{
if (m_lines != null && !requery)
return m_lines;
ArrayList<MPaySelectionLine> list = new ArrayList<MPaySelectionLine>();
String sql = "SELECT * FROM C_PaySelectionLine WHERE C_PaySelectionCheck_ID=? ORDER BY Line";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getC_PaySelectionCheck_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MPaySelectionLine(getCtx(), rs, get_TrxName()));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
//
m_lines = new MPaySelectionLine[list.size ()];
list.toArray (m_lines);
return m_lines;
} // getPaySelectionLines
} // MPaySelectionCheck
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -