Index: Doc_InOut.java =================================================================== --- Doc_InOut.java (revision 7272) +++ Doc_InOut.java (working copy) @@ -142,6 +142,7 @@ // Line pointers FactLine dr = null; FactLine cr = null; + FactLine cr_ppv = null; // *** Sales - Shipment if (getDocumentType().equals(DOCTYPE_MatShipment) && isSOTrx()) @@ -366,10 +367,60 @@ } // } + else + // Bayu Cahya, Sistematika + if (MAcctSchema.COSTINGMETHOD_StandardCosting.equals(costingMethod)) + { + int C_OrderLine_ID = line.getC_OrderLine_ID(); + if (C_OrderLine_ID > 0) + { + MOrderLine orderLine = new MOrderLine (getCtx(), C_OrderLine_ID, getTrxName()); + MOrder order = orderLine.getParent(); + // check currency for purchase order + // if does not equal with acc schema curr, convert first + if (orderLine.getC_Currency_ID() != as.getC_Currency_ID()) + { + C_Currency_ID = orderLine.getC_Currency_ID(); + Timestamp dateAcct = line.getDateAcct(); //Movement Date + BigDecimal rate = MConversionRate.getRate( + as.getC_Currency_ID(), C_Currency_ID, + dateAcct, order.getC_ConversionType_ID(), + orderLine.getAD_Client_ID(), orderLine.getAD_Org_ID()); + + if (rate == null) + { + p_Error = "Purchase Order not convertible - " + as.getName(); + return null; + } + + // Get standard cost and multiply + costs = line.getProductCosts(as, line.getAD_Org_ID(), false); + costs = costs.multiply(rate); + if (costs.scale() > as.getCostingPrecision()) + costs = costs.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP); + + } + else + { + costs = line.getProductCosts(as, line.getAD_Org_ID(), false); // current costs + + } + } + else + { + // raise + p_Error = "Resubmit - No Purchase Order link for " + product.getName(); + log.log(Level.WARNING, p_Error); + return null; + + } + + } // end for Standard Costing else { costs = line.getProductCosts(as, line.getAD_Org_ID(), false); // current costs - } + } + if (costs == null || costs.signum() == 0) { p_Error = "Resubmit - No Costs for " + product.getName(); @@ -412,9 +463,49 @@ /*cr = fact.createLine(line, getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), as.getC_Currency_ID(), null, costs);*/ - cr = fact.createLine(line, - getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), - C_Currency_ID, null, costs); + if (!MAcctSchema.COSTINGMETHOD_StandardCosting.equals(costingMethod)) + { + cr = fact.createLine(line, + getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), + C_Currency_ID, null, costs); + } + else + // Standard Costing + { + // Check Purchase Price + int C_OrderLine_ID = line.getC_OrderLine_ID(); + MOrderLine orderLine = new MOrderLine (getCtx(), C_OrderLine_ID, getTrxName()); + BigDecimal ttlPurchasePrice = + orderLine.getLineNetAmt().divide(orderLine.getQtyOrdered()) + .multiply(line.getQty()); + + // PPV + BigDecimal amtPPV = costs.subtract(ttlPurchasePrice); + + cr = fact.createLine(line, + getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), + C_Currency_ID, null, (amtPPV != Env.ZERO ? costs.subtract(amtPPV) : costs)); + + if (amtPPV.signum() != 0) + { + ProductCost productCost = new ProductCost(getCtx(), getM_Product_ID(), + line.getM_AttributeSetInstance_ID(), null); + cr_ppv = fact.createLine(line, + productCost.getAccount(ProductCost.ACCTTYPE_P_PPV, as), + C_Currency_ID, null, amtPPV); + + if (cr_ppv == null) + { + p_Error = "CR PPV not created: " + line; + log.log(Level.WARNING, p_Error); + return null; + } + cr_ppv.setM_Locator_ID(line.getM_Locator_ID()); + cr_ppv.setLocationFromBPartner(getC_BPartner_Location_ID(), true); // from Loc + cr_ppv.setLocationFromLocator(line.getM_Locator_ID(), false); // to Loc + cr_ppv.setQty(line.getQty().negate()); + } + } // if (cr == null) { @@ -426,6 +517,7 @@ cr.setLocationFromBPartner(getC_BPartner_Location_ID(), true); // from Loc cr.setLocationFromLocator(line.getM_Locator_ID(), false); // to Loc cr.setQty(line.getQty().negate()); + if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID !=0 && line.getReversalLine_ID() != 0) { // Set AmtAcctCr from Original Shipment/Receipt @@ -435,6 +527,12 @@ p_Error = "Original Receipt not posted yet"; return null; } + if (!cr_ppv.updateReverseLine (MInOut.Table_ID, + m_Reversal_ID, line.getReversalLine_ID(), Env.ONE)) + { + p_Error = "Original Receipt not posted yet"; + return null; + } } } } // Receipt