Ejemplo n.º 1
0
        /// <summary>
        /// Load Document Details
        /// </summary>
        /// <returns>error message or null</returns>
        public override String LoadDocumentDetails()
        {
            SetC_Currency_ID(NO_CURRENCY);
            X_M_Production prod = (X_M_Production)GetPO();

            SetDateDoc(prod.GetMovementDate());
            SetDateAcct(prod.GetMovementDate());
            //	Contained Objects
            _lines = LoadLines(prod);
            log.Fine("Lines=" + _lines.Length);
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Is used to do a reverse entry of "Production Record" into the system
        /// </summary>
        /// <returns>message successfuly created or not</returns>
        protected override string DoIt()
        {
            if (M_Production_ID > 0)
            {
                //Copy Production Header
                X_M_Production production = new X_M_Production(GetCtx(), M_Production_ID, Get_Trx());

                //check production is Reversed or not, if Reversed then not to do anything
                if (production.IsReversed())
                {
                    return(Msg.GetMsg(GetCtx(), "AlreadyReversed"));
                }

                //Get data from Production Plan
                dsProductionPlan = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_LOCATOR_ID , 
                                       M_PRODUCT_ID , M_PRODUCTIONPLAN_ID ,  M_PRODUCTION_ID  ,  PROCESSED  , PRODUCTIONQTY  M_WAREHOUSE_ID FROM M_ProductionPlan 
                                       WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx());

                //get data from production Line
                dsProductionLine = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_ATTRIBUTESETINSTANCE_ID , M_LOCATOR_ID , 
                                       M_PRODUCT_ID ,  M_PRODUCTIONLINE_ID, M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID  , PROCESSED  , MOVEMENTQTY , 
                                       C_UOM_ID , PLANNEDQTY , M_WAREHOUSE_ID FROM M_ProductionLine 
                                       WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx());

                // Create New record of Production Header with Reverse Entry
                X_M_Production productionTo = new X_M_Production(production.GetCtx(), 0, production.Get_Trx());
                try
                {
                    productionTo.Set_TrxName(production.Get_Trx());
                    PO.CopyValues(production, productionTo, production.GetAD_Client_ID(), production.GetAD_Org_ID());
                    productionTo.SetName("{->" + productionTo.GetName() + ")");
                    if (production.Get_ColumnIndex("DocumentNo") > 0)
                    {
                        productionTo.Set_Value("DocumentNo", ("{->" + productionTo.Get_Value("DocumentNo") + ")"));
                    }
                    productionTo.SetMovementDate(production.GetMovementDate()); //SI_0662 : not to create reverse record in current date, it should be created with the same date.
                    productionTo.SetProcessed(false);
                    if (!productionTo.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }
                    else
                    {
                        #region create new record of Production Plan
                        if (dsProductionPlan != null && dsProductionPlan.Tables.Count > 0 && dsProductionPlan.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < dsProductionPlan.Tables[0].Rows.Count; i++)
                            {
                                //Original Line
                                fromProdPlan = new X_M_ProductionPlan(GetCtx(), Util.GetValueOfInt(dsProductionPlan.Tables[0].Rows[i]["M_PRODUCTIONPLAN_ID"]), Get_Trx());

                                // Create New record of Production Plan with Reverse Entry
                                toProdPlan = new X_M_ProductionPlan(production.GetCtx(), 0, production.Get_Trx());
                                try
                                {
                                    toProdPlan.Set_TrxName(production.Get_Trx());
                                    PO.CopyValues(fromProdPlan, toProdPlan, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID());
                                    toProdPlan.SetProductionQty(Decimal.Negate(toProdPlan.GetProductionQty()));
                                    toProdPlan.SetM_Production_ID(productionTo.GetM_Production_ID());
                                    toProdPlan.SetProcessed(false);
                                    if (!toProdPlan.Save(production.Get_Trx()))
                                    {
                                        production.Get_Trx().Rollback();
                                        ValueNamePair pp = VLogger.RetrieveError();
                                        _log.Log(Level.SEVERE, "Could Not create Production Plan reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                                        throw new Exception("Could not create Production Plan reverse entry");
                                    }
                                    else
                                    {
                                        #region check record exist on production line
                                        if (dsProductionLine != null && dsProductionLine.Tables.Count > 0 && dsProductionLine.Tables[0].Rows.Count > 0)
                                        {
                                            //check record exist on production line against production plan
                                            drProductionLine = dsProductionLine.Tables[0].Select("M_ProductionPlan_ID  = " + fromProdPlan.GetM_ProductionPlan_ID());
                                            if (drProductionLine.Length > 0)
                                            {
                                                for (int j = 0; j < drProductionLine.Length; j++)
                                                {
                                                    //Original Line
                                                    fromProdline = new X_M_ProductionLine(GetCtx(), Util.GetValueOfInt(drProductionLine[j]["M_PRODUCTIONLINE_ID"]), Get_Trx());

                                                    // Create New record of Production line with Reverse Entry
                                                    toProdline = new X_M_ProductionLine(production.GetCtx(), 0, production.Get_Trx());
                                                    try
                                                    {
                                                        toProdline.Set_TrxName(production.Get_Trx());
                                                        PO.CopyValues(fromProdline, toProdline, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID());
                                                        toProdline.SetMovementQty(Decimal.Negate(toProdline.GetMovementQty()));
                                                        toProdline.SetPlannedQty(Decimal.Negate(toProdline.GetPlannedQty()));
                                                        toProdline.SetM_Production_ID(productionTo.GetM_Production_ID());
                                                        toProdline.SetM_ProductionPlan_ID(toProdPlan.GetM_ProductionPlan_ID());
                                                        toProdline.SetReversalDoc_ID(fromProdline.GetM_ProductionLine_ID()); //maintain refernce of Orignal record on reversed record
                                                        toProdline.SetProcessed(false);
                                                        if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx()))
                                                        {
                                                            production.Get_Trx().Rollback();
                                                            ValueNamePair pp = VLogger.RetrieveError();
                                                            if (!string.IsNullOrEmpty(pp.GetName()))
                                                            {
                                                                throw new Exception("Could not create Production line reverse entry, " + pp.GetName());
                                                            }
                                                            else
                                                            {
                                                                throw new Exception("Could not create Production line reverse entry");
                                                            }
                                                        }
                                                        if (!toProdline.Save(production.Get_Trx()))
                                                        {
                                                            production.Get_Trx().Rollback();
                                                            ValueNamePair pp = VLogger.RetrieveError();
                                                            _log.Log(Level.SEVERE, "Could Not create Production Line reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                                                            throw new Exception("Could not create Production line reverse entry");
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        _log.Info("Error Occured during Production Reverse " + ex.ToString());
                                                        if (dsProductionLine != null)
                                                        {
                                                            dsProductionLine.Dispose();
                                                        }
                                                        if (dsProductionPlan != null)
                                                        {
                                                            dsProductionPlan.Dispose();
                                                        }
                                                        return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _log.Info("Error Occured during Production Reverse " + ex.ToString());
                                    if (dsProductionLine != null)
                                    {
                                        dsProductionLine.Dispose();
                                    }
                                    if (dsProductionPlan != null)
                                    {
                                        dsProductionPlan.Dispose();
                                    }
                                    return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                                }
                            }
                        }
                        #endregion

                        result = productionTo.GetName();
                    }

                    //set Reversed as True
                    productionTo.SetIsReversed(true);
                    if (!productionTo.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }

                    //Set reversed as true, Reverse Refernce on Orignal Document
                    production.SetIsReversed(true);
                    production.SetM_Ref_Production(productionTo.GetM_Production_ID());
                    if (!production.Save(production.Get_Trx()))
                    {
                        production.Get_Trx().Rollback();
                        ValueNamePair pp = VLogger.RetrieveError();
                        _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName());
                        throw new Exception("Could not create Production reverse entry");
                    }
                }
                catch (Exception ex)
                {
                    _log.Info("Error Occured during Production Reverse " + ex.ToString());
                    if (dsProductionLine != null)
                    {
                        dsProductionLine.Dispose();
                    }
                    if (dsProductionPlan != null)
                    {
                        dsProductionPlan.Dispose();
                    }
                    return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result));
                }
            }
            return(Msg.GetMsg(GetCtx(), "DocumentReversedSuccessfully" + result));
        }