// API to add component transaction lines in M_WorkOrderTransactionLine. Called from MWarehouseTask for WMS integration. /** * Api to add component transaction lines. * @param ctx * @param VAMFG_M_WorkOrder_ID Work Order * @param M_WorkOrderComponent_ID Work Order Component * @param Qty Number of components to be issued * @param M_Locator_ID Supply Locator for the component * @param trx * @return int M_WorkOrderTransactionLine_ID */ public int AddComponentTxnLine(Ctx ctx, int M_WorkOrderComponent_ID, Decimal Qty, int M_Locator_ID, Trx trx) { ViennaAdvantage.Model.MVAMFGMWorkOrderComponent woc = new ViennaAdvantage.Model.MVAMFGMWorkOrderComponent(ctx, M_WorkOrderComponent_ID, trx); MVAMFGMWorkOrderOperation woo = new MVAMFGMWorkOrderOperation(ctx, woc.GetVAMFG_M_WorkOrderOperation_ID(), trx); ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction wot = RetrieveWOTxn(ctx, woo.GetVAMFG_M_WorkOrder_ID(), X_VAMFG_M_WrkOdrTransaction.VAMFG_WORKORDERTXNTYPE_1_ComponentIssueToWorkOrder, trx); if (wot == null) { log.Severe("Cannot create or retrieve WO Txn."); return(0); } ViennaAdvantage.Model.MVAMFGMWrkOdrTrnsctionLine wotLine = new ViennaAdvantage.Model.MVAMFGMWrkOdrTrnsctionLine(ctx, 0, trx); wotLine.SetRequiredColumns(wot.GetVAMFG_M_WrkOdrTransaction_ID(), woc.GetM_Product_ID(), woc.GetM_AttributeSetInstance_ID(), woc.GetC_UOM_ID(), Qty, woc.GetVAMFG_M_WorkOrderOperation_ID(), woc.GetBasisType()); wotLine.SetC_BPartner_ID(wot.GetC_BPartner_ID()); wotLine.SetC_BPartner_Location_ID(wot.GetC_BPartner_Location_ID()); wotLine.SetM_Locator_ID(M_Locator_ID); if (save) { if (!wotLine.Save(trx)) { log.Severe("Could not save component transaction line."); return(0); } } return(wotLine.GetVAMFG_M_WrkOdrTrnsctionLine_ID()); }
} // setWorkOrder /// <summary> /// Called before Save for Pre-Save Operation /// Set Line number if missing ///Check for duplicate component under one operation. /// </summary> /// <param name="newRecord"></param> /// <returns></returns> protected override Boolean BeforeSave(bool newRecord) { // Get Line No if (GetVAMFG_Line() == 0) { String sql = "SELECT COALESCE(MAX(VAMFG_Line),0)+10 FROM VAMFG_M_WorkOrderComponent WHERE VAMFG_M_WorkOrderOperation_ID=" + GetVAMFG_M_WorkOrderOperation_ID(); int ii = DB.GetSQLValue(Get_TrxName(), sql); SetVAMFG_Line(ii); } if (newRecord) { String sql = "SELECT * from VAMFG_M_WorkOrderComponent WHERE M_Product_ID=@param1 and VAMFG_M_WorkOrderOperation_ID = @param2"; SqlParameter[] param = null; IDataReader idr = null; DataTable dt = new DataTable(); //PreparedStatement pstmt = DB.prepareStatement(sql, null); //ResultSet rs = null; bool success = true; try { param = new SqlParameter[2]; param[0] = new SqlParameter("@param1", GetM_Product_ID()); param[1] = new SqlParameter("@param2", GetVAMFG_M_WorkOrderOperation_ID()); idr = DB.ExecuteReader(sql, param, null); if (idr.Read()) { // Show error log.SaveError("Error", Msg.GetMsg(GetCtx(), "DuplicateComponent")); success = false; } if (idr != null) { idr.Close(); idr = null; } } catch { if (idr != null) { idr.Close(); idr = null; } log.Log(Level.SEVERE, sql); } if (!success) { return(false); } } if ((GetVAMFG_QtyRequired().CompareTo(Env.ZERO)) < 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@QtyRequired@ < 0")); return(false); } if (GetVAMFG_Line() < 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@Line@ < 0")); return(false); } // get current cost from product cost on new record and when product changed // currency conversion also required if order has different currency with base currency if (newRecord || (Is_ValueChanged("M_Product_ID"))) { if (GetM_Product_ID() > 0) { decimal currentcostprice = MCost.GetproductCosts(GetAD_Client_ID(), GetAD_Org_ID(), GetM_Product_ID(), VAdvantage.Utility.Util.GetValueOfInt(GetM_AttributeSetInstance_ID()), Get_TrxName()); MVAMFGMWorkOrderOperation woo = new MVAMFGMWorkOrderOperation(GetCtx(), GetVAMFG_M_WorkOrderOperation_ID(), Get_TrxName()); MVAMFGMWorkOrder wor = new MVAMFGMWorkOrder(GetCtx(), woo.GetVAMFG_M_WorkOrder_ID(), Get_TrxName()); if (wor.GetVAMFG_Description() != null && wor.GetVAMFG_Description().Contains("(->")) { // not to set cuurent cost price on reversal because its already filed during creation of line } else { SetCurrentCostPrice(currentcostprice); } } } if (Is_ValueChanged("VAMFG_QtyRequired")) { //BigDecimal qtyRequired = getQtyRequired().setScale(MUOM.getPrecision(getCtx(), getC_UOM_ID()), BigDecimal.ROUND_HALF_UP); Decimal qtyRequired = Decimal.Round((GetVAMFG_QtyRequired()), VAdvantage.Model.MUOM.GetPrecision(GetCtx(), GetC_UOM_ID())); if (qtyRequired.CompareTo(GetVAMFG_QtyRequired()) != 0) { log.Fine("Corrected QtyRequired Scale UOM=" + GetC_UOM_ID() + "; QtyRequired=" + GetVAMFG_QtyRequired() + "->" + qtyRequired); SetVAMFG_QtyRequired(qtyRequired); } } return(true); } // beforeSave