//	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());
        }
Exemple #2
0
 /// <summary>
 ///  Parent Constructor.
 /// </summary>
 /// <param name="workorderoperation"></param>
 /// <param name="workorder"></param>
 public MVAMFGMWorkOrderComponent(MVAMFGMWorkOrderOperation workorderoperation, MVAMFGMWorkOrder workorder)
     : this(workorderoperation.GetCtx(), 0, workorderoperation.Get_TrxName())
 {
     if (workorderoperation.Get_ID() == 0)
     {
         throw new Exception("Header not saved");
     }
     SetVAMFG_M_WorkOrderOperation_ID(workorderoperation.GetVAMFG_M_WorkOrderOperation_ID()); //	parent
     SetWorkOrder(workorder);
 }                                                                                            //	MWorkOrderComponent
Exemple #3
0
        }       //	getOfWorkOrder

        /// <summary>
        ///  Get Components of a Work Order Operation
        /// </summary>
        /// <param name="workorderoperation"></param>
        /// <param name="whereClause"></param>
        /// <param name="orderClause"></param>
        /// <returns></returns>
        public static MVAMFGMWorkOrderComponent[] GetOfWorkOrderOperation(MVAMFGMWorkOrderOperation workorderoperation, String whereClause, String orderClause)
        {
            StringBuilder sqlstmt = new StringBuilder("SELECT * FROM VAMFG_M_WorkOrderComponent WHERE VAMFG_M_WorkOrderOperation_ID=@param1 ");

            if (whereClause != null)
            {
                sqlstmt.Append("AND ").Append(whereClause);
            }
            if (orderClause != null)
            {
                sqlstmt.Append(" ORDER BY ").Append(orderClause);
            }
            String sql = sqlstmt.ToString();
            //ArrayList<MWorkOrderComponent> list = new ArrayList<MWorkOrderComponent>();
            List <MVAMFGMWorkOrderComponent> list = new List <MVAMFGMWorkOrderComponent>();

            SqlParameter[] param = null;
            IDataReader    idr   = null;
            DataTable      dt    = new DataTable();

            //PreparedStatement pstmt = DB.prepareStatement (sql, workorderoperation.get_Trx());
            //ResultSet rs = null;
            try
            {
                param    = new SqlParameter[1];
                param[0] = new SqlParameter("@param1", workorderoperation.GetVAMFG_M_WorkOrderOperation_ID());
                idr      = DB.ExecuteReader(sql, param, workorderoperation.Get_TrxName());
                dt.Load(idr);
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list.Add(new MVAMFGMWorkOrderComponent(workorderoperation.GetCtx(), dt.Rows[i], workorderoperation.Get_TrxName()));
                }
            }
            catch
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                log.Log(Level.SEVERE, sql);
                return(null);
            }

            MVAMFGMWorkOrderComponent[] retValue = new MVAMFGMWorkOrderComponent[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }       //	getOfWorkOrderOperation
        /// <summary>
        /// Generates Resource Transaction Lines against WO Txn between &
        /// including specified operation VAMFG_SeqNo; skips the optional operations unless
        /// they are either the starting operation sequence or ending operation sequence
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_WorkOrderTransaction_ID"></param>
        /// <param name="Qty"></param>
        /// <param name="OperationFrom"></param>
        /// <param name="OperationTo"></param>
        /// <param name="trx"></param>
        /// <param name="automatic"></param>
        /// <returns></returns>
        public MVAMFGMWrkOdrRscTxnLine[] GenerateResourceTxnLine(Ctx ctx, int M_WorkOrderTransaction_ID, Decimal?Qty,
                                                                 Decimal?OperationFrom, Decimal?OperationTo, Trx trx, bool automatic)
        {
            if (0 >= M_WorkOrderTransaction_ID)
            {
                log.Severe("No Work Order Transaction ID specified");
                return(null);
            }

            if (OperationFrom.Value.CompareTo(OperationTo) > 0)
            {
                log.Severe("Operation Numbers not correct.");
                return(null);
            }

            if (Qty != null && Qty.Value.CompareTo(Decimal.Zero) <= 0)
            {
                log.Severe("Number of product assemblies must be positive");
                return(null);
            }

            ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction wot = new ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction(ctx, M_WorkOrderTransaction_ID, trx);
            if (wot != null && !(wot.GetVAMFG_WorkOrderTxnType().Equals(X_VAMFG_M_WrkOdrTransaction.VAMFG_WORKORDERTXNTYPE_ResourceUsage) &&
                                 (wot.GetDocStatus().Equals(X_VAMFG_M_WrkOdrTransaction.DOCSTATUS_Drafted) || wot.GetDocStatus().Equals(X_VAMFG_M_WrkOdrTransaction.DOCSTATUS_InProgress))))
            {
                log.Severe("Work Order transaction type not correct.");
                return(null);
            }

            //ArrayList<MVAMFGMWrkOdrRscTxnLine> wortLines = new ArrayList<MVAMFGMWrkOdrRscTxnLine>();
            // List<MVAMFGMWrkOdrRscTxnLine> wortLines=new List<MVAMFGMWrkOdrRscTxnLine>();
            System.Collections.ArrayList wortLines = new System.Collections.ArrayList();

            ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(ctx, wot.GetVAMFG_M_WorkOrder_ID(), trx);
            int resTxnLineSeqNo = DB.GetSQLValue(trx, "SELECT Max(VAMFG_SeqNo) FROM MVAMFGMWrkOdrRscTxnLine WHERE VAMFG_M_WrkOdrTransaction_ID =" + M_WorkOrderTransaction_ID);

            StringBuilder wc = new StringBuilder();

            if (OperationFrom.Value.CompareTo(Decimal.Zero) > 0)
            {
                wc.Append(" VAMFG_SeqNo >= ").Append(OperationFrom);
                if (OperationTo.Value.CompareTo(Decimal.Zero) > 0)
                {
                    wc.Append(" AND VAMFG_SeqNo <= ").Append(OperationTo);
                }
            }
            else if (OperationTo.Value.CompareTo(Decimal.Zero) > 0)
            {
                wc.Append(" VAMFG_SeqNo <= ").Append(OperationTo);
            }

            //	Don't consider the optional operations, but include the "From" and "To" operations even if they are optional
            wc.Append(" AND (VAMFG_IsOptional <> 'Y' ");
            if (OperationFrom.Value.CompareTo(Decimal.Zero) > 0)
            {
                wc.Append(" OR VAMFG_SeqNo = ").Append(OperationFrom);
            }
            if (OperationTo.Value.CompareTo(Decimal.Zero) > 0)
            {
                wc.Append(" OR VAMFG_SeqNo = ").Append(OperationTo);
            }
            wc.Append(" )");

            ViennaAdvantage.CMFG.Model.MVAMFGMWorkOrder worder = new CMFG.Model.MVAMFGMWorkOrder(ctx, wo.GetVAMFG_M_WorkOrder_ID(), trx);
            String whereClause = (wc.Length > 0 ? wc.ToString() : null);

            MVAMFGMWorkOrderOperation[] woos = MVAMFGMWorkOrderOperation.GetOfWorkOrder(worder, whereClause, "VAMFG_SeqNo");

            StringBuilder response = new StringBuilder();

            foreach (MVAMFGMWorkOrderOperation woo in woos)
            {
                MVAMFGMWorkOrderResource[] wors = MVAMFGMWorkOrderResource.GetofWorkOrderOperation(woo, null, null);
                foreach (MVAMFGMWorkOrderResource wor in wors)
                {
                    String chargeType = wor.GetVAMFG_ChargeType();
                    if (!((chargeType.Equals(X_VAMFG_M_WorkOrderResource.VAMFG_CHARGETYPE_Automatic) && automatic) ||
                          (chargeType.Equals(X_VAMFG_M_WorkOrderResource.VAMFG_CHARGETYPE_Manual) && !automatic)))
                    {
                        continue;
                    }
                    //calculated values
                    Decimal resAmt = Decimal.Zero;      //Resource amount to be charged
                    //if product assembly quantity, Qty, is null then derive based on how many have already been charged
                    //if estimated amt as indicated by WorkOrder Resource is already, then don't charge any more
                    if (Qty == null)
                    {
                        Decimal resCharged = wor.GetVAMFG_QtySpent();
                        Decimal resReq     = Decimal.Multiply(wo.GetVAMFG_QtyEntered(), (wor.GetVAMFG_QtyRequired()));
                        resAmt = Decimal.Subtract(resReq, (resCharged));
                        if (resAmt.CompareTo(Decimal.Zero) <= 0)
                        {
                            log.Warning("Estimated Resource usage has been already charged.");
                            continue;
                        }
                    }
                    else
                    {
                        resAmt = Decimal.Multiply(Qty.Value, (wor.GetVAMFG_QtyRequired()));
                    }

                    MVAMFGMWrkOdrRscTxnLine wortl = new MVAMFGMWrkOdrRscTxnLine(ctx, 0, trx);
                    //wortl.SetVAMFG_QtyEntered(resAmt.setScale(MUOM.getPrecision(ctx, wor.getC_UOM_ID()), Decimal.ROUND_HALF_UP));
                    wortl.SetVAMFG_QtyEntered(Decimal.Round((resAmt), VAdvantage.Model.MUOM.GetPrecision(ctx, wor.GetC_UOM_ID()), MidpointRounding.AwayFromZero));
                    // set fields from parent Work Order Transaction
                    wortl.SetVAMFG_M_WrkOdrTransaction_ID(M_WorkOrderTransaction_ID);
                    wortl.SetClientOrg(wot);

                    // set fields from Work Order Resource
                    wortl.Setresourceinfo(wor);

                    //increase the VAMFG_SeqNo for each WOResourceTxnLine
                    resTxnLineSeqNo += 10;
                    wortl.SetVAMFG_SeqNo(resTxnLineSeqNo);

                    wortl.SetIsActive(true);

                    //Add to the return ArrayList
                    wortLines.Add(wortl);

                    ViennaAdvantage.Model.MProduct product = ViennaAdvantage.Model.MProduct.Get(ctx, wortl.GetM_Product_ID());
                    response.Append(product.GetName() + ": ").Append(wortl.GetVAMFG_QtyEntered());
                    if (!wortl.Save())
                    {
                        log.Severe("Could not save resource transaction line.");
                    }
                }
            }

            if (save)
            {
                try
                {
                    if (!VAdvantage.Model.PO.SaveAll(trx, wortLines))
                    {
                        log.Severe("Could not save resource transaction line.");
                        return(null);
                    }
                }
                catch { }
            }
            log.SaveInfo("Info", response.ToString());
            // return (MVAMFGMWrkOdrRscTxnLine[])wortLines.ToArray();
            MVAMFGMWrkOdrRscTxnLine[] newObject = null;

            try
            {
                newObject = (MVAMFGMWrkOdrRscTxnLine[])wortLines.ToArray(typeof(MVAMFGMWrkOdrRscTxnLine));
                return(newObject);
            }
            catch { }
            return((MVAMFGMWrkOdrRscTxnLine[])wortLines.ToArray());
        }
Exemple #5
0
        /// <summary>
        /// Constructor called from BOM Drop
        /// </summary>
        /// <param name="workorder"></param>
        /// <param name="workorderoperation"></param>
        /// <param name="product"></param>
        /// <param name="QtyRequired"></param>
        /// <param name="SupplyType"></param>
        /// <param name="locator"></param>
        public MVAMFGMWorkOrderComponent(ViennaAdvantage.Model.MVAMFGMWorkOrder workorder, MVAMFGMWorkOrderOperation workorderoperation, ViennaAdvantage.Model.MProduct product, Decimal QtyRequired,
                                         String SupplyType, int M_AttributeSetInstance_ID, VAdvantage.Model.MLocator locator)
            : this(workorderoperation.GetCtx(), 0, workorderoperation.Get_TrxName())
        {
            if (workorderoperation.Get_ID() == 0)
            {
                throw new Exception("Header not saved");
            }
            SetVAMFG_M_WorkOrderOperation_ID(workorderoperation.GetVAMFG_M_WorkOrderOperation_ID());    //	parent
            SetM_Product_ID(product.GetM_Product_ID());
            SetC_UOM_ID(product.GetC_UOM_ID());
            SetVAMFG_QtyRequired(QtyRequired);
            SetVAMFG_SupplyType(SupplyType);
            // Changes done b y Vivek Kumar assigned by Mukesh on 16/11/2017
            // Changes done to save AttributesetInstance at Work Order component
            SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
            if (locator != null)
            {
                SetM_Locator_ID(locator.GetM_Locator_ID());
            }

            SetWorkOrder(workorder);
        }
Exemple #6
0
        }                                                                                            //	MWorkOrderComponent

        /// <summary>
        /// constructor called from BOM Explode
        /// assumes MLocator as null (not specified)
        /// </summary>
        /// <param name="workorder"></param>
        /// <param name="workorderoperation"></param>
        /// <param name="product"></param>
        /// <param name="QtyRequired"></param>
        /// <param name="SupplyType"></param>
        public MVAMFGMWorkOrderComponent(MVAMFGMWorkOrder workorder, MVAMFGMWorkOrderOperation workorderoperation, ViennaAdvantage.Model.MProduct product, Decimal QtyRequired,
                                         String SupplyType, int M_AttributeSetInstance_ID)
            : this(workorder, workorderoperation, product, QtyRequired, SupplyType, M_AttributeSetInstance_ID, null)
        {
        }
Exemple #7
0
        }       //	setM_Product_ID

        /**
         * @param headerInfo the headerInfo to set
         */
        public void SetHeaderInfo(MVAMFGMWorkOrderOperation headerInfo)
        {
            this.headerInfo = headerInfo;
        }
Exemple #8
0
        }       //	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