diff --git a/migration/i1.0a-release/oracle/201301222018_TICKET-1001770.sql b/migration/i1.0a-release/oracle/201301222018_TICKET-1001770.sql new file mode 100644 index 0000000000..07b4596bbd --- /dev/null +++ b/migration/i1.0a-release/oracle/201301222018_TICKET-1001770.sql @@ -0,0 +1,17 @@ +-- Jan 22, 2013 3:46:04 PM SGT +-- Ticket 1001770: RMA improvements +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.inoutline',Updated=TO_DATE('2013-01-22 15:46:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=10829 +; + +-- Jan 22, 2013 3:46:23 PM SGT +-- Ticket 1001770: RMA improvements +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.product',Updated=TO_DATE('2013-01-22 15:46:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=208397 +; + +-- Jan 22, 2013 3:46:31 PM SGT +-- Ticket 1001770: RMA improvements +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.charge',Updated=TO_DATE('2013-01-22 15:46:31','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=52002 +; + +SELECT register_migration_script('201301222018_TICKET-1001770.sql') FROM dual +; \ No newline at end of file diff --git a/migration/i1.0a-release/postgresql/201301222018_TICKET-1001770.sql b/migration/i1.0a-release/postgresql/201301222018_TICKET-1001770.sql new file mode 100644 index 0000000000..22e3f37a9c --- /dev/null +++ b/migration/i1.0a-release/postgresql/201301222018_TICKET-1001770.sql @@ -0,0 +1,17 @@ +-- Jan 22, 2013 3:46:04 PM SGT +-- Ticket 1001770: RMA improvements +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.inoutline',Updated=TO_TIMESTAMP('2013-01-22 15:46:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=10829 +; + +-- Jan 22, 2013 3:46:23 PM SGT +-- Ticket 1001770: RMA improvements +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.product',Updated=TO_TIMESTAMP('2013-01-22 15:46:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=208397 +; + +-- Jan 22, 2013 3:46:31 PM SGT +-- Ticket 1001770: RMA improvements +UPDATE AD_Column SET Callout='org.adempiere.model.CalloutRMA.charge',Updated=TO_TIMESTAMP('2013-01-22 15:46:31','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=52002 +; + +SELECT register_migration_script('201301222018_TICKET-1001770.sql') FROM dual +; \ No newline at end of file diff --git a/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java b/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java index 3bd6e895d8..504ab6e170 100644 --- a/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java +++ b/org.adempiere.base.callout/src/org/adempiere/model/CalloutRMA.java @@ -13,48 +13,232 @@ * For the text or an alternative of this public license, you may reach us * * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ + *****************************************************************************/ package org.adempiere.model; +import java.math.BigDecimal; import java.util.Properties; import org.compiere.model.CalloutEngine; import org.compiere.model.GridField; import org.compiere.model.GridTab; +import org.compiere.model.I_C_InvoiceLine; +import org.compiere.model.MCharge; +import org.compiere.model.MInOutLine; +import org.compiere.model.MInvoice; +import org.compiere.model.MInvoiceLine; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MProductPricing; +import org.compiere.model.MRMA; +import org.compiere.model.MRMALine; +import org.compiere.model.Query; +import org.compiere.model.Tax; import org.compiere.util.DB; +import org.compiere.util.Env; /** - * - * @author Ashley G Ramdass + * + * @author Ashley G Ramdass */ -public class CalloutRMA extends CalloutEngine -{ +public class CalloutRMA extends CalloutEngine { - /** - * docType - set document properties based on document type. - * @param ctx - * @param WindowNo - * @param mTab - * @param mField - * @param value - * @return error message or "" - */ - public String docType (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) - { - Integer C_DocType_ID = (Integer)value; - if (C_DocType_ID == null || C_DocType_ID.intValue() == 0) - return ""; - - String sql = "SELECT d.IsSoTrx " - + "FROM C_DocType d WHERE C_DocType_ID=?"; - - String docSOTrx = DB.getSQLValueString(null, sql, C_DocType_ID); - - boolean isSOTrx = "Y".equals(docSOTrx); - - mTab.setValue("IsSOTrx", isSOTrx); - - return ""; - } + /** + * docType - set document properties based on document type. + * + * @param ctx + * @param WindowNo + * @param mTab + * @param mField + * @param value + * @return error message or "" + */ + public String docType(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + Integer C_DocType_ID = (Integer) value; + if (C_DocType_ID == null || C_DocType_ID.intValue() == 0) + return ""; + + String sql = "SELECT d.IsSoTrx FROM C_DocType d WHERE C_DocType_ID=?"; + String docSOTrx = DB.getSQLValueString(null, sql, C_DocType_ID); + boolean isSOTrx = "Y".equals(docSOTrx); + mTab.setValue(MRMA.COLUMNNAME_IsSOTrx, isSOTrx); + + return ""; + } + + public String inoutline(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + Integer M_InOutLine_ID = (Integer) value; + if (M_InOutLine_ID == null || M_InOutLine_ID.intValue() == 0) + return ""; + + MInOutLine iol = new MInOutLine(ctx, M_InOutLine_ID, null); + + int invoiceLine_ID = new Query(ctx, I_C_InvoiceLine.Table_Name, + "M_InOutLine_ID=?", null).setParameters(M_InOutLine_ID) + .firstId(); + if (invoiceLine_ID <= 0) + invoiceLine_ID = 0; + + if (invoiceLine_ID != 0) + { + MInvoiceLine invoiceLine = new MInvoiceLine(ctx, invoiceLine_ID, null); + if (invoiceLine.getM_Product_ID() != 0) + mTab.setValue(MRMALine.COLUMNNAME_M_Product_ID, invoiceLine.getM_Product_ID()); + if (invoiceLine.getC_Charge_ID() != 0) + mTab.setValue(MRMALine.COLUMNNAME_C_Charge_ID, invoiceLine.getC_Charge_ID()); + mTab.setValue(MRMALine.COLUMNNAME_Qty, invoiceLine.getQtyEntered()); + mTab.setValue(MRMALine.COLUMNNAME_Amt, invoiceLine.getPriceEntered()); + mTab.setValue(MRMALine.COLUMNNAME_C_Tax_ID, invoiceLine.getC_Tax_ID()); + + BigDecimal lineNetAmt = invoiceLine.getQtyEntered().multiply(invoiceLine.getPriceEntered()); + int precision = invoiceLine.getPrecision(); + if (lineNetAmt.scale() > precision) + lineNetAmt = lineNetAmt.setScale(precision, BigDecimal.ROUND_HALF_UP); + mTab.setValue(MRMALine.COLUMNNAME_LineNetAmt, lineNetAmt); + } + else if (iol.getC_OrderLine_ID() != 0) + { + MOrderLine orderLine = new MOrderLine(ctx, iol.getC_OrderLine_ID(), null); + if (orderLine.getM_Product_ID() != 0) + mTab.setValue(MRMALine.COLUMNNAME_M_Product_ID, orderLine.getM_Product_ID()); + if (orderLine.getC_Charge_ID() != 0) + mTab.setValue(MRMALine.COLUMNNAME_C_Charge_ID, orderLine.getC_Charge_ID()); + mTab.setValue(MRMALine.COLUMNNAME_Qty, orderLine.getQtyEntered()); + mTab.setValue(MRMALine.COLUMNNAME_Amt, orderLine.getPriceEntered()); + mTab.setValue(MRMALine.COLUMNNAME_C_Tax_ID, orderLine.getC_Tax_ID()); + + BigDecimal lineNetAmt = orderLine.getQtyEntered().multiply(orderLine.getPriceEntered()); + int precision = orderLine.getPrecision(); + if (lineNetAmt.scale() > precision) + lineNetAmt = lineNetAmt.setScale(precision, BigDecimal.ROUND_HALF_UP); + mTab.setValue(MRMALine.COLUMNNAME_LineNetAmt, lineNetAmt); + } + + return ""; + } + + public String product(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + if (isCalloutActive() || value == null) + return ""; + + Integer M_Product_ID = (Integer) value; + if (M_Product_ID == null || M_Product_ID.intValue() == 0) + return ""; + + Integer M_RMA_ID = (Integer) mTab.getValue(MRMALine.COLUMNNAME_M_RMA_ID); + if (M_RMA_ID == null || M_RMA_ID.intValue() == 0) + return ""; + + Integer AD_Org_ID = (Integer) mTab.getValue(MRMALine.COLUMNNAME_AD_Org_ID); + if (AD_Org_ID == null || AD_Org_ID.intValue() == 0) + return ""; + + MRMA rma = new MRMA(ctx, M_RMA_ID, null); + MProductPricing pp = new MProductPricing(M_Product_ID, rma.getC_BPartner_ID(), Env.ONE, rma.isSOTrx()); + int taxId = 0; + int precision = 0; + + MInvoice invoice = rma.getOriginalInvoice(); + if (invoice != null) + { + pp.setM_PriceList_ID(invoice.getM_PriceList_ID()); + pp.setPriceDate(invoice.getDateInvoiced()); + + precision = invoice.getPrecision(); + taxId = Tax.get(ctx, M_Product_ID, 0, + invoice.getDateInvoiced(), invoice.getDateInvoiced(), + AD_Org_ID, rma.getShipment().getM_Warehouse_ID(), + invoice.getC_BPartner_Location_ID(), // should be bill to + invoice.getC_BPartner_Location_ID(), rma.isSOTrx()); + } + else + { + MOrder order = rma.getOriginalOrder(); + if (order != null) + { + pp.setM_PriceList_ID(order.getM_PriceList_ID()); + pp.setPriceDate(order.getDateOrdered()); + + precision = order.getPrecision(); + taxId = Tax.get(ctx, M_Product_ID, 0, + order.getDateOrdered(), order.getDateOrdered(), + AD_Org_ID, order.getM_Warehouse_ID(), + order.getC_BPartner_Location_ID(), // should be bill to + order.getC_BPartner_Location_ID(), rma.isSOTrx()); + } + else + return "No Invoice/Order found the Shipment/Receipt associated"; + } + + pp.calculatePrice(); + + mTab.setValue(MRMALine.COLUMNNAME_Qty, Env.ONE); + mTab.setValue(MRMALine.COLUMNNAME_Amt, pp.getPriceStd()); + if (taxId != 0) + mTab.setValue(MRMALine.COLUMNNAME_C_Tax_ID, taxId); + + BigDecimal lineNetAmt = Env.ONE.multiply(pp.getPriceStd()); + if (lineNetAmt.scale() > precision) + lineNetAmt = lineNetAmt.setScale(precision, BigDecimal.ROUND_HALF_UP); + mTab.setValue(MRMALine.COLUMNNAME_LineNetAmt, lineNetAmt); + + return ""; + } + + public String charge(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + if (isCalloutActive() || value == null) + return ""; + + Integer C_Charge_ID = (Integer) value; + if (C_Charge_ID == null || C_Charge_ID.intValue() == 0) + return ""; + + Integer M_RMA_ID = (Integer) mTab.getValue(MRMALine.COLUMNNAME_M_RMA_ID); + if (M_RMA_ID == null || M_RMA_ID.intValue() == 0) + return ""; + + Integer AD_Org_ID = (Integer) mTab.getValue(MRMALine.COLUMNNAME_AD_Org_ID); + if (AD_Org_ID == null || AD_Org_ID.intValue() == 0) + return ""; + + MCharge charge = MCharge.get(ctx, C_Charge_ID); + + // Retrieve tax Exempt + String sql = "SELECT C_Tax_ID FROM C_Tax WHERE AD_Client_ID=? AND IsActive='Y' " + + "AND IsTaxExempt='Y' AND ValidFrom < SYSDATE ORDER BY IsDefault DESC"; + // Set tax for charge as exempt + int taxId = DB.getSQLValueEx(null, sql, Env.getAD_Client_ID(ctx)); + + mTab.setValue(MRMALine.COLUMNNAME_Qty, Env.ONE); + mTab.setValue(MRMALine.COLUMNNAME_Amt, charge.getChargeAmt()); + if (taxId != 0) + mTab.setValue(MRMALine.COLUMNNAME_C_Tax_ID, taxId); + + MRMA rma = new MRMA(ctx, M_RMA_ID, null); + int precision = 0; + + MInvoice invoice = rma.getOriginalInvoice(); + if (invoice != null) + precision = invoice.getPrecision(); + else + { + MOrder order = rma.getOriginalOrder(); + if (order != null) + precision = order.getPrecision(); + else + return "No Invoice/Order found the Shipment/Receipt associated"; + } + + BigDecimal lineNetAmt = Env.ONE.multiply(charge.getChargeAmt()); + if (lineNetAmt.scale() > precision) + lineNetAmt = lineNetAmt.setScale(precision, BigDecimal.ROUND_HALF_UP); + mTab.setValue(MRMALine.COLUMNNAME_LineNetAmt, lineNetAmt); + + return ""; + } } diff --git a/org.adempiere.base/src/org/compiere/model/MRMALine.java b/org.adempiere.base/src/org/compiere/model/MRMALine.java index 02c2a1723a..44f899630c 100644 --- a/org.adempiere.base/src/org/compiere/model/MRMALine.java +++ b/org.adempiere.base/src/org/compiere/model/MRMALine.java @@ -121,6 +121,18 @@ public class MRMALine extends X_M_RMALine MCharge charge = MCharge.get(this.getCtx(), getC_Charge_ID()); unitAmount = charge.getChargeAmt(); + MInvoice invoice = getParent().getOriginalInvoice(); + if (invoice != null) + precision = invoice.getPrecision(); + else + { + MOrder order = getParent().getOriginalOrder(); + if (order != null) + precision = order.getPrecision(); + else + throw new IllegalStateException("No Invoice/Order found the Shipment/Receipt associated"); + } + // Retrieve tax Exempt String sql = "SELECT C_Tax_ID FROM C_Tax WHERE AD_Client_ID=? AND IsActive='Y' " + "AND IsTaxExempt='Y' AND ValidFrom < SYSDATE ORDER BY IsDefault DESC"; diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java index 0540e07339..822fe5a07a 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromRMA.java @@ -47,7 +47,12 @@ public abstract class CreateFromRMA extends CreateFrom { public boolean dynInit() throws Exception { log.config(""); - setTitle("Customer RMA - Create Lines From"); + + boolean isSOTrx = true; + String value = Env.getContext(Env.getCtx(), getGridTab().getWindowNo(), MRMA.COLUMNNAME_IsSOTrx); + if (value != null && value.equalsIgnoreCase("N")) + isSOTrx = false; + setTitle(isSOTrx ? "Customer" : "Vendor" + " RMA - Create Lines From"); return true; }