📄 vmatch.java
字号:
if (sameQty.isSelected())
m_sql.append(" AND ").append(m_qtyColumn).append("=").append(docQty);
// ** Load Table **
tableLoad (xMatchedToTable);
}
// Display To be Matched Qty
m_xMatched = new BigDecimal (qty);
xMatched.setValue(m_xMatched);
xMatchedTo.setValue(Env.ZERO);
difference.setValue(m_xMatched);
// Status Info
statusBar.setStatusLine(matchFrom.getSelectedItem().toString()
+ "# = " + xMatchedTable.getRowCount() + " - "
+ matchTo.getSelectedItem().toString()
+ "# = " + xMatchedToTable.getRowCount(),
xMatchedToTable.getRowCount() == 0);
statusBar.setStatusDB(0);
} // cmd_seachTo
/***************************************************************************
* Table Model Listener - calculate matchd Qty
* @param e event
*/
public void tableChanged (TableModelEvent e)
{
if (e.getColumn() != 0)
return;
log.config("Row=" + e.getFirstRow() + "-" + e.getLastRow() + ", Col=" + e.getColumn()
+ ", Type=" + e.getType());
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// Matched From
int matchedRow = xMatchedTable.getSelectedRow();
KeyNamePair Product = (KeyNamePair)xMatchedTable.getValueAt(matchedRow, 5);
// Matched To
double qty = 0.0;
int noRows = 0;
for (int row = 0; row < xMatchedToTable.getRowCount(); row++)
{
IDColumn id = (IDColumn)xMatchedToTable.getValueAt(row, 0);
if (id != null && id.isSelected())
{
KeyNamePair ProductCompare = (KeyNamePair)xMatchedToTable.getValueAt(row, 5);
if (Product.getKey() != ProductCompare.getKey())
{
id.setSelected(false);
}
else
{
if (matchMode.getSelectedIndex() == MODE_NOTMATCHED)
qty += ((Double)xMatchedToTable.getValueAt(row, I_QTY)).doubleValue(); // doc
qty -= ((Double)xMatchedToTable.getValueAt(row, I_MATCHED)).doubleValue(); // matched
noRows++;
}
}
}
// update qualtities
m_xMatchedTo = new BigDecimal(qty);
xMatchedTo.setValue(m_xMatchedTo);
difference.setValue(m_xMatched.subtract(m_xMatchedTo));
bProcess.setEnabled(noRows != 0);
setCursor(Cursor.getDefaultCursor());
// Status
statusBar.setStatusDB(noRows);
} // tableChanged
/**************************************************************************
* Initialise Table access - create SQL, dateColumn.
* <br>
* The driving table is "hdr", e.g. for hdr.C_BPartner_ID=..
* The line table is "lin", e.g. for lin.M_Product_ID=..
* You use the dateColumn/qtyColumn variable directly as it is table specific.
* <br>
* The sql is dependent on MatchMode:
* - If Matched - all (fully or partially) matched records are listed
* - If Not Matched - all not fully matched records are listed
* @param display (Invoice, Shipment, Order) see MATCH_*
* @param matchToType (Invoice, Shipment, Order) see MATCH_*
*/
private void tableInit (int display, int matchToType)
{
boolean matched = matchMode.getSelectedIndex() == MODE_MATCHED;
log.config("Display=" + m_matchOptions[display]
+ ", MatchTo=" + m_matchOptions[matchToType]
+ ", Matched=" + matched);
m_sql = new StringBuffer ();
if (display == MATCH_INVOICE)
{
m_dateColumn = "hdr.DateInvoiced";
m_qtyColumn = "lin.QtyInvoiced";
m_sql.append("SELECT hdr.C_Invoice_ID,hdr.DocumentNo, hdr.DateInvoiced, bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.C_InvoiceLine_ID, p.Name,lin.M_Product_ID,"
+ " lin.QtyInvoiced,SUM(NVL(mi.Qty,0)) "
+ "FROM C_Invoice hdr"
+ " INNER JOIN C_BPartner bp ON (hdr.C_BPartner_ID=bp.C_BPartner_ID)"
+ " INNER JOIN C_InvoiceLine lin ON (hdr.C_Invoice_ID=lin.C_Invoice_ID)"
+ " INNER JOIN M_Product p ON (lin.M_Product_ID=p.M_Product_ID)"
+ " INNER JOIN C_DocType dt ON (hdr.C_DocType_ID=dt.C_DocType_ID AND dt.DocBaseType IN ('API','APC'))"
+ " FULL JOIN M_MatchInv mi ON (lin.C_InvoiceLine_ID=mi.C_InvoiceLine_ID) "
+ "WHERE hdr.DocStatus IN ('CO','CL')");
m_groupBy = " GROUP BY hdr.C_Invoice_ID,hdr.DocumentNo,hdr.DateInvoiced,bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.C_InvoiceLine_ID,p.Name,lin.M_Product_ID,lin.QtyInvoiced "
+ "HAVING "
+ (matched ? "0" : "lin.QtyInvoiced")
+ "<>SUM(NVL(mi.Qty,0))";
}
else if (display == MATCH_ORDER)
{
m_dateColumn = "hdr.DateOrdered";
m_qtyColumn = "lin.QtyOrdered";
m_sql.append("SELECT hdr.C_Order_ID,hdr.DocumentNo, hdr.DateOrdered, bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.C_OrderLine_ID, p.Name,lin.M_Product_ID,"
+ " lin.QtyOrdered,SUM(COALESCE(mo.Qty,0)) "
+ "FROM C_Order hdr"
+ " INNER JOIN C_BPartner bp ON (hdr.C_BPartner_ID=bp.C_BPartner_ID)"
+ " INNER JOIN C_OrderLine lin ON (hdr.C_Order_ID=lin.C_Order_ID)"
+ " INNER JOIN M_Product p ON (lin.M_Product_ID=p.M_Product_ID)"
+ " INNER JOIN C_DocType dt ON (hdr.C_DocType_ID=dt.C_DocType_ID AND dt.DocBaseType='POO')"
+ " FULL JOIN M_MatchPO mo ON (lin.C_OrderLine_ID=mo.C_OrderLine_ID) "
+ "WHERE mo.")
.append(matchToType == MATCH_SHIPMENT ? "M_InOutLine_ID" : "C_InvoiceLine_ID")
.append(matched ? " IS NOT NULL" : " IS NULL"
+ " AND hdr.DocStatus IN ('CO','CL')");
m_groupBy = " GROUP BY hdr.C_Order_ID,hdr.DocumentNo,hdr.DateOrdered,bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.C_OrderLine_ID,p.Name,lin.M_Product_ID,lin.QtyOrdered "
+ "HAVING "
+ (matched ? "0" : "lin.QtyOrdered")
+ "<>SUM(COALESCE(mo.Qty,0))";
}
else // Shipment
{
m_dateColumn = "hdr.MovementDate";
m_qtyColumn = "lin.MovementQty";
m_sql.append("SELECT hdr.M_InOut_ID,hdr.DocumentNo, hdr.MovementDate, bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.M_InOutLine_ID, p.Name,lin.M_Product_ID,"
+ " lin.MovementQty,SUM(NVL(m.Qty,0)) "
+ "FROM M_InOut hdr"
+ " INNER JOIN C_BPartner bp ON (hdr.C_BPartner_ID=bp.C_BPartner_ID)"
+ " INNER JOIN M_InOutLine lin ON (hdr.M_InOut_ID=lin.M_InOut_ID)"
+ " INNER JOIN M_Product p ON (lin.M_Product_ID=p.M_Product_ID)"
+ " INNER JOIN C_DocType dt ON (hdr.C_DocType_ID = dt.C_DocType_ID AND dt.DocBaseType='MMR')"
+ " FULL JOIN ")
.append(matchToType == MATCH_ORDER ? "M_MatchPO" : "M_MatchInv")
.append(" m ON (lin.M_InOutLine_ID=m.M_InOutLine_ID) "
+ "WHERE hdr.DocStatus IN ('CO','CL')");
m_groupBy = " GROUP BY hdr.M_InOut_ID,hdr.DocumentNo,hdr.MovementDate,bp.Name,hdr.C_BPartner_ID,"
+ " lin.Line,lin.M_InOutLine_ID,p.Name,lin.M_Product_ID,lin.MovementQty "
+ "HAVING "
+ (matched ? "0" : "lin.MovementQty")
+ "<>SUM(NVL(m.Qty,0))";
}
// Log.trace(7, "VMatch.tableInit", m_sql + "\n" + m_groupBy);
} // tableInit
/**
* Fill the table using m_sql
* @param table table
*/
private void tableLoad (MiniTable table)
{
// log.finest(m_sql + " - " + m_groupBy);
String sql = MRole.getDefault().addAccessSQL(
m_sql.toString(), "hdr", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
+ m_groupBy;
log.finest(sql);
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(sql);
table.loadTable(rs);
stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
} // tableLoad
/**
* Create Matching Record
* @param invoice true if matching invoice false if matching PO
* @param M_InOutLine_ID shipment line
* @param Line_ID C_InvoiceLine_ID or C_OrderLine_ID
* @param qty quantity
* @return true if created
*/
private boolean createMatchRecord (boolean invoice, int M_InOutLine_ID, int Line_ID,
BigDecimal qty)
{
if (qty.compareTo(Env.ZERO) == 0)
return true;
log.fine("IsInvoice=" + invoice
+ ", M_InOutLine_ID=" + M_InOutLine_ID + ", Line_ID=" + Line_ID
+ ", Qty=" + qty);
//
boolean success = false;
MInOutLine sLine = new MInOutLine (Env.getCtx(), M_InOutLine_ID, null);
if (invoice) // Shipment - Invoice
{
// Update Invoice Line
MInvoiceLine iLine = new MInvoiceLine (Env.getCtx(), Line_ID, null);
iLine.setM_InOutLine_ID(M_InOutLine_ID);
if (sLine.getC_OrderLine_ID() != 0)
iLine.setC_OrderLine_ID(sLine.getC_OrderLine_ID());
iLine.save();
// Create Shipment - Invoice Link
if (iLine.getM_Product_ID() != 0)
{
MMatchInv match = new MMatchInv (iLine, null, qty);
match.setM_InOutLine_ID(M_InOutLine_ID);
if (match.save())
success = true;
else
log.log(Level.SEVERE, "Inv Match not created: " + match);
}
else
success = true;
// Create PO - Invoice Link = corrects PO
if (iLine.getC_OrderLine_ID() != 0 && iLine.getM_Product_ID() != 0)
{
MMatchPO matchPO = MMatchPO.create(iLine, sLine, null, qty);
matchPO.setC_InvoiceLine_ID(iLine);
matchPO.setM_InOutLine_ID(M_InOutLine_ID);
if (!matchPO.save())
log.log(Level.SEVERE, "PO(Inv) Match not created: " + matchPO);
}
}
else // Shipment - Order
{
// Update Shipment Line
sLine.setC_OrderLine_ID(Line_ID);
sLine.save();
// Update Order Line
MOrderLine oLine = new MOrderLine(Env.getCtx(), Line_ID, null);
if (oLine.get_ID() != 0) // other in MInOut.completeIt
{
oLine.setQtyReserved(oLine.getQtyReserved().subtract(qty));
if(!oLine.save())
log.severe("QtyReserved not updated - C_OrderLine_ID=" + Line_ID);
}
// Create PO - Shipment Link
if (sLine.getM_Product_ID() != 0)
{
MMatchPO match = new MMatchPO (sLine, null, qty);
if (!match.save())
log.log(Level.SEVERE, "PO Match not created: " + match);
else
{
success = true;
// Correct Ordered Qty for Stocked Products (see MOrder.reserveStock / MInOut.processIt)
if (sLine.getProduct() != null && sLine.getProduct().isStocked())
success = MStorage.add (Env.getCtx(), sLine.getM_Warehouse_ID(),
sLine.getM_Locator_ID(),
sLine.getM_Product_ID(),
sLine.getM_AttributeSetInstance_ID(), oLine.getM_AttributeSetInstance_ID(),
null, null, qty.negate(), null);
}
}
else
success = true;
}
return success;
} // createMatchRecord
} // VMatch
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -