use of org.compiere.minigrid.IDColumn in project lar_361 by comitsrl.
the class Info method mouseClicked.
/**
************************************************************************
* Mouse Clicked
* @param e event
*/
public void mouseClicked(MouseEvent e) {
// Double click with selected row => exit/zoom
if (e.getClickCount() > 1 && p_table.getSelectedRow() != -1) {
if (p_multiSelection && isDoubleClickTogglesSelection()) {
if (m_keyColumnIndex >= 0) {
Object data = p_table.getValueAt(p_table.getSelectedRow(), m_keyColumnIndex);
if (data instanceof IDColumn) {
IDColumn id = (IDColumn) data;
id.setSelected(!id.isSelected());
p_table.setValueAt(data, p_table.getSelectedRow(), m_keyColumnIndex);
}
}
} else
dispose(true);
} else // Right Click => start Calculator
if (SwingUtilities.isRightMouseButton(e)) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
use of org.compiere.minigrid.IDColumn in project lar_361 by comitsrl.
the class SubCurrentLine method updateTable.
/**
* Update Table
* @param order order
*/
public void updateTable(PosOrderModel order) {
int C_Order_ID = 0;
if (order != null)
C_Order_ID = order.getC_Order_ID();
if (C_Order_ID == 0) {
p_posPanel.f_curLine.m_table.loadTable(new PO[0]);
p_posPanel.f_order.setSums(null);
}
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(m_sql, null);
pstmt.setInt(1, C_Order_ID);
rs = pstmt.executeQuery();
m_table.loadTable(rs);
} catch (Exception e) {
log.log(Level.SEVERE, m_sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
for (int i = 0; i < m_table.getRowCount(); i++) {
IDColumn key = (IDColumn) m_table.getModel().getValueAt(i, 0);
if (key != null && orderLineId > 0 && key.getRecord_ID() == orderLineId) {
m_table.getSelectionModel().setSelectionInterval(i, i);
break;
}
}
enableButtons();
p_posPanel.f_order.setSums(order);
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class WListbox method tableValueChange.
/* (non-Javadoc)
* @see org.adempiere.webui.event.TableValueChangeListener#tableValueChange
* (org.adempiere.webui.event.TableValueChangeEvent)
*/
public void tableValueChange(TableValueChangeEvent event) {
// column of table field which caused the event
int col = event.getColumn();
// row of table field which caused the event
int row = event.getRow();
boolean newBoolean;
IDColumn idColumn;
// then set the IDColumn's select field
if (col >= 0 && row >= 0) {
if (this.getValueAt(row, col) instanceof IDColumn && event.getNewValue() instanceof Boolean) {
newBoolean = ((Boolean) event.getNewValue()).booleanValue();
idColumn = (IDColumn) this.getValueAt(row, col);
idColumn.setSelected(newBoolean);
this.setValueAt(idColumn, row, col);
} else // othewise just set the value in the model to the new value
{
this.setValueAt(event.getNewValue(), row, col);
}
}
return;
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class Allocation method getInvoiceData.
public Vector<Vector<Object>> getInvoiceData(boolean isMultiCurrency, Object date, IMiniTable invoiceTable) {
/********************************
* Load unpaid Invoices
* 1-TrxDate, 2-Value, (3-Currency, 4-InvAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-ConvDisc, 8-WriteOff, 9-Applied
*
SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID,c.ISO_Code,
i.GrandTotal*i.MultiplierAP "GrandTotal",
currencyConvert(i.GrandTotal*i.MultiplierAP,i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) "GrandTotal $",
invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID) "Open",
currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.MultiplierAP "Open $",
invoiceDiscount(i.C_Invoice_ID,SysDate,C_InvoicePaySchedule_ID) "Discount",
currencyConvert(invoiceDiscount(i.C_Invoice_ID,SysDate,C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.Multiplier*i.MultiplierAP "Discount $",
i.MultiplierAP, i.Multiplier
FROM C_Invoice_v i INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID)
WHERE -- i.IsPaid='N' AND i.Processed='Y' AND i.C_BPartner_ID=1000001
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuffer sql = new StringBuffer(// 1..3
"SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID," + // 4..5 Orig Currency
"c.ISO_Code,i.GrandTotal*i.MultiplierAP, " + // 6 #1 Converted, #2 Date
"currencyConvert(i.GrandTotal*i.MultiplierAP,i.C_Currency_ID,?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID), " + // 7 #3, #4 Converted Open
"currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),i.C_Currency_ID,?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.MultiplierAP, " + // 8 AllowedDiscount
"currencyConvert(invoiceDiscount" + // #5, #6
"(i.C_Invoice_ID,?,C_InvoicePaySchedule_ID),i.C_Currency_ID,?,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.Multiplier*i.MultiplierAP," + // 9..11
"i.MultiplierAP, i.IsSoTrx, i.AD_Org_ID " + // corrected for CM/Split
"FROM C_Invoice_v i" + " INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID) " + "WHERE i.IsPaid='N' AND i.Processed='Y'" + // #7
" AND i.C_BPartner_ID=?");
if (!isMultiCurrency)
// #8
sql.append(" AND i.C_Currency_ID=?");
if (m_AD_Org_ID != 0)
sql.append(" AND i.AD_Org_ID=" + m_AD_Org_ID);
if (apar != null && !apar.equals(APAR_A)) {
sql.append(" AND i.IsSoTrx='" + (apar.equals(APAR_R) ? "Y" : "N") + "'");
}
sql.append(" ORDER BY i.DateInvoiced, i.DocumentNo");
log.fine("InvSQL=" + sql.toString());
// role security
sql = new StringBuffer(MRole.getDefault(Env.getCtx(), false).addAccessSQL(sql.toString(), "i", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO));
try {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_C_Currency_ID);
pstmt.setTimestamp(2, (Timestamp) date);
pstmt.setInt(3, m_C_Currency_ID);
pstmt.setTimestamp(4, (Timestamp) date);
pstmt.setTimestamp(5, (Timestamp) date);
pstmt.setInt(6, m_C_Currency_ID);
pstmt.setInt(7, m_C_BPartner_ID);
if (!isMultiCurrency)
pstmt.setInt(8, m_C_Currency_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Vector<Object> line = new Vector<Object>();
// 0-C_Invoice_ID
line.add(new IDColumn(rs.getInt(3)));
// 1-TrxDate
line.add(rs.getTimestamp(1));
if (// Ar/Ap
rs.getString(10).equals("Y"))
line.add("AR");
else
line.add("AP");
// 11 AD_Org_ID
int orgID = rs.getInt(11);
if (orgID == 0)
line.add("*");
else
line.add((new MOrg(Env.getCtx(), orgID, null).getName()));
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
// 2-Value
line.add(pp);
if (isMultiCurrency) {
// 3-Currency
line.add(rs.getString(4));
// 4-Orig Amount
line.add(rs.getBigDecimal(5));
}
// 3/5-ConvAmt
line.add(rs.getBigDecimal(6));
BigDecimal open = rs.getBigDecimal(7);
if (// no conversion rate
open == null)
open = Env.ZERO;
// 4/6-ConvOpen
line.add(open);
BigDecimal discount = rs.getBigDecimal(8);
if (// no conversion rate
discount == null)
discount = Env.ZERO;
// 5/7-ConvAllowedDisc
line.add(discount);
// 6/8-WriteOff
line.add(Env.ZERO);
// 7/9-Applied
line.add(Env.ZERO);
// 8/10-OverUnder
line.add(open);
// Add when open <> 0 (i.e. not if no conversion rate)
if (Env.ZERO.compareTo(open) != 0)
data.add(line);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
}
return data;
}
use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.
the class Allocation method saveData.
/**************************************************************************
* Save Data
*/
public String saveData(int m_WindowNo, Object date, IMiniTable payment, IMiniTable invoice, String trxName) {
if (m_noInvoices + m_noPayments == 0)
return "";
// fixed fields
int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
int AD_Org_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Org_ID");
int C_BPartner_ID = m_C_BPartner_ID;
int C_Order_ID = 0;
int C_CashLine_ID = 0;
Timestamp DateTrx = (Timestamp) date;
// the allocation currency
int C_Currency_ID = m_C_Currency_ID;
//
if (AD_Org_ID == 0) {
//ADialog.error(m_WindowNo, this, "Org0NotAllowed", null);
throw new AdempiereException("@Org0NotAllowed@");
}
//
log.config("Client=" + AD_Client_ID + ", Org=" + AD_Org_ID + ", BPartner=" + C_BPartner_ID + ", Date=" + DateTrx);
// Payment - Loop and add them to paymentList/amountList
int pRows = payment.getRowCount();
ArrayList<Integer> paymentList = new ArrayList<Integer>(pRows);
ArrayList<BigDecimal> amountList = new ArrayList<BigDecimal>(pRows);
BigDecimal paymentAppliedAmt = Env.ZERO;
paymentList = payment.getSelectedKeys();
// Sum up the payment and applied amounts.
for (int i = 0; i < pRows; i++) {
if (payment.isRowChecked(i)) {
// Applied Payment
BigDecimal PaymentAmt = (BigDecimal) payment.getValueAt(i, i_payment);
amountList.add(PaymentAmt);
//
paymentAppliedAmt = paymentAppliedAmt.add(PaymentAmt);
//
log.fine("C_Payment_ID=" + payment.getRowKey(i) + " - PaymentAmt=" + // + " * " + Multiplier + " = " + PaymentAmtAbs);
PaymentAmt);
}
}
log.config("Number of Payments=" + paymentList.size() + " - Total=" + paymentAppliedAmt);
// Invoices - Loop and generate allocations
int iRows = invoice.getRowCount();
// Create Allocation
MAllocationHdr alloc = new // manual
MAllocationHdr(// manual
Env.getCtx(), // manual
true, DateTrx, C_Currency_ID, Env.getContext(Env.getCtx(), "#AD_User_Name"), trxName);
alloc.setAD_Org_ID(AD_Org_ID);
// Set Description
if (!Util.isEmpty(m_description))
alloc.setDescription(m_description);
alloc.saveEx();
// For all invoices
BigDecimal unmatchedApplied = Env.ZERO;
for (int i = 0; i < iRows; i++) {
// Invoice line is selected
if (invoice.isRowChecked(i)) {
// Invoice variables
int C_Invoice_ID = ((IDColumn) invoice.getValueAt(i, invoice.getKeyColumnIndex())).getRecord_ID();
BigDecimal AppliedAmt = (BigDecimal) invoice.getValueAt(i, i_applied);
// semi-fixed fields (reset after first invoice)
BigDecimal DiscountAmt = (BigDecimal) invoice.getValueAt(i, i_discount);
BigDecimal WriteOffAmt = (BigDecimal) invoice.getValueAt(i, i_writeOff);
// OverUnderAmt needs to be in Allocation Currency
BigDecimal OverUnderAmt = ((BigDecimal) invoice.getValueAt(i, i_open)).subtract(AppliedAmt).subtract(DiscountAmt).subtract(WriteOffAmt);
// + " -> " + AppliedAbs);
log.config("Invoice #" + i + " - AppliedAmt=" + AppliedAmt);
for (int j = 0; j < paymentList.size() && AppliedAmt.signum() != 0; j++) {
int C_Payment_ID = ((Integer) paymentList.get(j)).intValue();
BigDecimal PaymentAmt = (BigDecimal) amountList.get(j);
if (// only match same sign (otherwise appliedAmt increases)
PaymentAmt.signum() == AppliedAmt.signum()) {
// and not zero (appliedAmt was checked earlier)
log.config(".. with payment #" + j + ", Amt=" + PaymentAmt);
BigDecimal amount = AppliedAmt;
if (// if there's more open on the invoice
amount.abs().compareTo(PaymentAmt.abs()) > 0)
// than left in the payment
amount = PaymentAmt;
// Allocation Line
MAllocationLine aLine = new MAllocationLine(alloc, amount, DiscountAmt, WriteOffAmt, OverUnderAmt);
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
aLine.saveEx();
// Apply Discounts and WriteOff only first time
DiscountAmt = Env.ZERO;
WriteOffAmt = Env.ZERO;
// subtract amount from Payment/Invoice
AppliedAmt = AppliedAmt.subtract(amount);
PaymentAmt = PaymentAmt.subtract(amount);
log.fine("Allocation Amount=" + amount + " - Remaining Applied=" + AppliedAmt + ", Payment=" + PaymentAmt);
// update
amountList.set(j, PaymentAmt);
}
// for all applied amounts
}
if (AppliedAmt.signum() == 0 && DiscountAmt.signum() == 0 && WriteOffAmt.signum() == 0)
continue;
else {
// remainder will need to match against other invoices
int C_Payment_ID = 0;
// Allocation Line
MAllocationLine aLine = new MAllocationLine(alloc, AppliedAmt, DiscountAmt, WriteOffAmt, OverUnderAmt);
aLine.setDocInfo(C_BPartner_ID, C_Order_ID, C_Invoice_ID);
aLine.setPaymentInfo(C_Payment_ID, C_CashLine_ID);
aLine.saveEx();
log.fine("Allocation Amount=" + AppliedAmt);
unmatchedApplied = unmatchedApplied.add(AppliedAmt);
}
}
// invoice selected
}
// check for unapplied payment amounts (eg from payment reversals)
for (int i = 0; i < paymentList.size(); i++) {
BigDecimal payAmt = (BigDecimal) amountList.get(i);
if (payAmt.signum() == 0)
continue;
int C_Payment_ID = ((Integer) paymentList.get(i)).intValue();
log.fine("Payment=" + C_Payment_ID + ", Amount=" + payAmt);
// Allocation Line
MAllocationLine aLine = new MAllocationLine(alloc, payAmt, Env.ZERO, Env.ZERO, Env.ZERO);
aLine.setDocInfo(C_BPartner_ID, 0, 0);
aLine.setPaymentInfo(C_Payment_ID, 0);
aLine.saveEx();
unmatchedApplied = unmatchedApplied.subtract(payAmt);
}
// check for charge amount
if (m_C_Charge_ID > 0 && unmatchedApplied.compareTo(Env.ZERO) != 0) {
BigDecimal chargeAmt = totalDiff;
// Allocation Line
MAllocationLine aLine = new MAllocationLine(alloc, chargeAmt.negate(), Env.ZERO, Env.ZERO, Env.ZERO);
aLine.set_CustomColumn("C_Charge_ID", m_C_Charge_ID);
aLine.setC_BPartner_ID(m_C_BPartner_ID);
aLine.saveEx(trxName);
unmatchedApplied = unmatchedApplied.add(chargeAmt);
}
if (unmatchedApplied.signum() != 0)
log.log(Level.SEVERE, "Allocation not balanced -- out by " + unmatchedApplied);
// Should start WF
if (alloc.get_ID() != 0) {
if (//@Trifon
!alloc.processIt(DocAction.ACTION_Complete))
//@Trifon
throw new AdempiereException("@ProcessFailed@: " + alloc.getProcessMsg());
alloc.saveEx();
}
// Test/Set IsPaid for Invoice - requires that allocation is posted
for (int i = 0; i < iRows; i++) {
// Invoice line is selected
if (invoice.isRowChecked(i)) {
// Invoice variables
int C_Invoice_ID = ((IDColumn) invoice.getValueAt(i, invoice.getKeyColumnIndex())).getRecord_ID();
String sql = "SELECT invoiceOpen(C_Invoice_ID, 0) " + "FROM C_Invoice WHERE C_Invoice_ID=?";
BigDecimal open = DB.getSQLValueBD(trxName, sql, C_Invoice_ID);
if (open != null && open.signum() == 0) {
sql = "UPDATE C_Invoice SET IsPaid='Y' " + "WHERE C_Invoice_ID=" + C_Invoice_ID;
int no = DB.executeUpdate(sql, trxName);
log.config("Invoice #" + i + " is paid - updated=" + no);
} else
log.config("Invoice #" + i + " is not paid - " + open);
}
}
// Test/Set Payment is fully allocated
for (int i = 0; i < paymentList.size(); i++) {
int C_Payment_ID = ((Integer) paymentList.get(i)).intValue();
MPayment pay = new MPayment(Env.getCtx(), C_Payment_ID, trxName);
if (pay.testAllocation())
pay.saveEx();
log.config("Payment #" + i + (pay.isAllocated() ? " not" : " is") + " fully allocated");
}
paymentList.clear();
amountList.clear();
return alloc.getDocumentNo();
}
Aggregations