/** * Perform process. * @return Message * @throws Exception */ //@Override protected override String DoIt() { if (0 == p_M_WorkOrderTransaction_ID) { throw new Exception("@FillMandatory@ @M_WorkOrderTransaction_ID@"); } ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction woTxn = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(GetCtx(), p_M_WorkOrderTransaction_ID, Get_TrxName()); ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(GetCtx(), woTxn.GetVAMFG_M_WorkOrder_ID(), Get_TrxName()); VAdvantage.Model.MBOM bom = new VAdvantage.Model.MBOM(GetCtx(), wo.GetM_BOM_ID(), Get_TrxName()); MBOMProduct[] BOMproducts = MBOMProduct.GetOfBOM(bom); for (int i = 0; i < BOMproducts.Length; i++) { string prodensity = "SELECT nvl(GOM01_DENSITY,0) FROM VAMFG_M_WorkOrder WHERE VAMFG_M_WorkOrder_ID =" + woTxn.GetVAMFG_M_WorkOrder_ID(); decimal DenQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(prodensity)); if (DenQty == 0) { DenQty = 1; } MBOMProduct BOMproduct = BOMproducts[i]; decimal qtyReqd = (p_Qty * BOMproduct.GetBOMQty()) * DenQty; //string qry = "SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = " + // " (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(woTxn.GetVAMFG_DateTrx(), true) + " AND M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + // " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID() + ") AND M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + // " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID() + ") AND AD_Org_ID = " + woTxn.GetAD_Org_ID() + " AND M_Product_ID = " + BOMproduct.GetM_ProductBOM_ID() + // " AND M_Locator_ID = " + woTxn.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + BOMproduct.GetM_AttributeSetInstance_ID(); //decimal CurrentQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(qry)); //if (CurrentQty < qtyReqd) //{ // ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx()); // return "Insufficient qty in warehouse for : " + product.GetName(); //} VAdvantage.Model.MStorage st = VAdvantage.Model.MStorage.Get(Env.GetCtx(), woTxn.GetM_Locator_ID(), BOMproduct.GetM_ProductBOM_ID(), BOMproduct.GetM_AttributeSetInstance_ID(), Get_TrxName()); if (st == null) { ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx()); return("Insufficient qty in warehouse for : " + product.GetName()); } decimal CurrentQty = st.GetQtyOnHand(); if (CurrentQty < qtyReqd) { ViennaAdvantage.Model.MProduct product = new ViennaAdvantage.Model.MProduct(GetCtx(), BOMproduct.GetM_ProductBOM_ID(), Get_Trx()); return("Insufficient qty in warehouse for : " + product.GetName()); } } if (p_Qty == 0) { //MVAMFGMWorkOrder wo = new MVAMFGMWorkOrder(GetCtx(), woTxn.GetVAMFG_M_WorkOrder_ID(), Get_TrxName()); // p_Qty = wo.GetVAMFG_QtyEntered().subtract(wo.GetVAMFG_QtyAssembled()); string prdOrdQry = "SELECT SUM(wkt.VAMFG_QtyEntered) AS ProdOrder FROM VAMFG_M_WrkOdrTransaction wkt WHERE wkt.VAMFG_WorkOrderTxnType ='CI' AND wkt.M_Product_ID = " + woTxn.GetM_Product_ID() + " AND wkt.VAMFG_M_Workorder_ID = " + woTxn.GetVAMFG_M_WorkOrder_ID() + " AND wkt.DocStatus ='CO'"; Decimal ProdOrdQty = VAdvantage.Utility.Util.GetValueOfDecimal(DB.ExecuteScalar(prdOrdQry, null, Get_TrxName())); p_Qty = Decimal.Subtract(wo.GetVAMFG_QtyEntered(), (ProdOrdQty)); //p_Qty = Decimal.Subtract(wo.GetVAMFG_QtyEntered(), (wo.GetVAMFG_QtyAssembled())); //log.Info ("@Quantity@ = " + wo.GetVAMFG_QtyEntered().subtract(wo.GetVAMFG_QtyAssembled().add(wo.GetVAMFG_QtyScrapped()))); log.Info("@Quantity@ = " + Decimal.Subtract(wo.GetVAMFG_QtyEntered(), Decimal.Add(wo.GetVAMFG_QtyAssembled(), (wo.GetVAMFG_QtyScrapped())))); } //woTxn.SetVAMFG_QtyEntered(p_Qty.setScale(MUOM.GetPrecision(GetCtx(), woTxn.GetC_UOM_ID()), Decimal.ROUND_HALF_UP)); woTxn.SetVAMFG_QtyEntered(Decimal.Round((p_Qty), VAdvantage.Model.MUOM.GetPrecision(woTxn.GetCtx(), woTxn.GetC_UOM_ID()), MidpointRounding.AwayFromZero)); // Added by Bharat on 20/12/2016 to Set Density and Liter values for production execution Process of Gulf Oil. Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("GOM01_", out mInfo)) { woTxn.SetGOM01_Density(wo.GetGOM01_Density()); Decimal qtyKg = Decimal.Multiply(wo.GetGOM01_Density(), woTxn.GetVAMFG_QtyEntered()); woTxn.SetGOM01_Quantity(Decimal.Round((qtyKg), MUOM.GetPrecision(woTxn.GetCtx(), woTxn.GetC_UOM_ID()), MidpointRounding.AwayFromZero)); } woTxn.Save(); ViennaAdvantage.Process.MWorkOrderTxnUtil prodTxnLines = new ViennaAdvantage.Process.MWorkOrderTxnUtil(true); // Done by Bharat on 24 Jan 2018 to delete lines as when process runs multiple times it creates duplicate lines. int no = DB.ExecuteQuery("DELETE FROM VAMFG_M_WrkOdrTrnsctionLine WHERE VAMFG_M_WrkOdrTransaction_ID = " + p_M_WorkOrderTransaction_ID, null, Get_TrxName()); ViennaAdvantage.Model.MVAMFGMWrkOdrTrnsctionLine[] wotlines = prodTxnLines.GenerateComponentTxnLine(GetCtx(), p_M_WorkOrderTransaction_ID, p_Qty, X_VAMFG_M_WorkOrderComponent.VAMFG_SUPPLYTYPE_Push, Get_TrxName()); if (wotlines != null && wotlines.Length > 0) { return("Generated " + wotlines.Length + " line(s) for component(s): " + VLogger.RetrieveInfo().GetName()); } else { return("Generated 0 lines for components."); } }
/** * Creates a Work Order Transaction header for a given Work Order * Transactions handled : Resource Usage (RU), Component Return (CR), Component Issue (CI) * @param ctx * @param VAMFG_M_WorkOrder_ID Work Order * @param TxnType Work Order Transaction Type * @param parent_M_WorkOrderTransaction_ID Parent Work Order Transaction * @param M_Locator_ID Work Order Transaction Locator * @param Qty Work Order Transaction Quantity * @param trx * @return MVAMFGMWrkOdrTransaction */ public ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction createWOTxn(Ctx ctx, int VAMFG_M_WorkOrder_ID, String TxnType, int parent_M_WorkOrderTransaction_ID, int M_Locator_ID, Decimal Qty, Trx trx) { int _countGOM01 = Convert.ToInt32(DB.ExecuteScalar("SELECT COUNT(AD_ModuleInfo_ID) FROM AD_ModuleInfo WHERE Prefix like 'GOM01_'")); if (!(TxnType.Equals(X_VAMFG_M_WrkOdrTransaction.VAMFG_WORKORDERTXNTYPE_ResourceUsage) || TxnType.Equals(X_VAMFG_M_WrkOdrTransaction.VAMFG_WORKORDERTXNTYPE_1_ComponentIssueToWorkOrder) || TxnType.Equals(X_VAMFG_M_WrkOdrTransaction.VAMFG_WORKORDERTXNTYPE_ComponentReturnFromWorkOrder))) { log.Severe("Not correct transaction type to generate WO Transaction"); return(null); } //Check the validity of the Work Order ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(ctx, VAMFG_M_WorkOrder_ID, trx); if (wo == null || !wo.GetDocStatus().Equals(X_VAMFG_M_WorkOrder.DOCSTATUS_InProgress)) { log.Severe("Work Order number not valid for transactions."); return(null); } // Checking if Quantity can be derived from associated WorkOrder if (parent_M_WorkOrderTransaction_ID == 0) { if (Qty == null || Qty == 0) { log.Info("Deriving Quantity from Work Order"); Qty = wo.GetVAMFG_QtyEntered(); } } //Deriving Qty from parent WO Move Txn if (Qty.CompareTo(Decimal.Zero) <= 0) { ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction parentWOT = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(ctx, parent_M_WorkOrderTransaction_ID, trx); Qty = parentWOT.GetVAMFG_QtyEntered(); } //Creating new WorkOrder Transaction ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction wot = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(ctx, 0, trx); wot.SetRequiredColumns(VAMFG_M_WorkOrder_ID, M_Locator_ID, X_VAMFG_M_WrkOdrTransaction.VAMFG_WOTXNSOURCE_Generated, TxnType); if (parent_M_WorkOrderTransaction_ID > 0) { wot.SetParentWorkOrderTxn_ID(parent_M_WorkOrderTransaction_ID); ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction parentWOT = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(ctx, parent_M_WorkOrderTransaction_ID, trx); wot.SetC_DocType_ID(parentWOT.GetC_DocType_ID()); // set the client & org derived from parent work order transaction wot.SetClientOrg(parentWOT); if (_countGOM01 > 0) { wot.SetGOM01_Density(parentWOT.GetGOM01_Density()); wot.SetGOM01_Quantity(parentWOT.GetGOM01_Quantity()); wot.SetGOM01_ActualQuantity(parentWOT.GetGOM01_ActualQuantity()); wot.SetGOM01_ActualDensity(parentWOT.GetGOM01_ActualDensity()); wot.SetGOM01_ActualLiter(parentWOT.GetGOM01_ActualLiter()); } } else { // derive the doctype from the WorkOrderClass MVAMFGMWorkOrderClass woclass = new MVAMFGMWorkOrderClass(ctx, wo.GetVAMFG_M_WorkOrderClass_ID(), trx); wot.SetC_DocType_ID(woclass.GetWOT_DocType_ID()); // since there is no parent work order transaction // set the client & org derived from the associated work order wot.SetClientOrg(wo); } //wot.SetVAMFG_QtyEntered(Qty.setScale(MUOM.getPrecision(ctx, wot.getC_UOM_ID()), Decimal.ROUND_HALF_UP)); wot.SetVAMFG_QtyEntered(Decimal.Round((Qty), VAdvantage.Model.MUOM.GetPrecision(ctx, wot.GetC_UOM_ID()), MidpointRounding.AwayFromZero)); if (save) { if (!wot.Save(trx)) { log.Severe("Could not save WO Txn."); return(null); } } return(wot); }