Ejemplo n.º 1
0
        public static UnitCostPair CalculateCuryUnitCost <unitCostField, inventoryIDField, uomField>(PXCache cache, object row, bool raiseUnitCostDefaulting, decimal?unitCost)
            where unitCostField : IBqlField
            where inventoryIDField : IBqlField
            where uomField : IBqlField
        {
            decimal curyUnitCost = 0m;

            if (raiseUnitCostDefaulting == true)
            {
                object unitCostObj;
                cache.RaiseFieldDefaulting <unitCostField>(row, out unitCostObj);
                unitCost = (decimal?)unitCostObj;
            }

            if (unitCost != null && unitCost != 0m)
            {
                decimal valueConvertedToBase = INUnitAttribute.ConvertToBase <inventoryIDField, uomField>(cache, row, unitCost.Value, INPrecision.NOROUND);

                IPXCurrencyHelper currencyHelper = cache.Graph.FindImplementation <IPXCurrencyHelper>();

                if (currencyHelper != null)
                {
                    currencyHelper.CuryConvCury(unitCost.Value, out valueConvertedToBase);
                }
                else
                {
                    CM.PXDBCurrencyAttribute.CuryConvCury(cache, row, valueConvertedToBase, out valueConvertedToBase, true);
                }

                curyUnitCost = Math.Round(valueConvertedToBase, CommonSetupDecPl.PrcCst, MidpointRounding.AwayFromZero);
            }

            return(new UnitCostPair(curyUnitCost, unitCost));
        }
Ejemplo n.º 2
0
        protected virtual void CROpportunityProducts_CuryUnitCost_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            CROpportunityProducts    crOpportunityProductsRow    = (CROpportunityProducts)e.Row;
            FSxCROpportunityProducts fsxCROpportunityProductsRow = cache.GetExtension <FSxCROpportunityProducts>(crOpportunityProductsRow);

            if (string.IsNullOrEmpty(crOpportunityProductsRow.UOM) == false && crOpportunityProductsRow.InventoryID != null && crOpportunityProductsRow.POCreate == true)
            {
                object unitcost;
                cache.RaiseFieldDefaulting <CROpportunityProducts.unitCost>(e.Row, out unitcost);

                if (unitcost != null && (decimal)unitcost != 0m)
                {
                    decimal newval = INUnitAttribute.ConvertToBase <CROpportunityProducts.inventoryID, CROpportunityProducts.uOM>(cache, crOpportunityProductsRow, (decimal)unitcost, INPrecision.NOROUND);

                    IPXCurrencyHelper currencyHelper = Base.FindImplementation <IPXCurrencyHelper>();

                    if (currencyHelper != null)
                    {
                        currencyHelper.CuryConvCury((decimal)unitcost, out newval);
                    }
                    else
                    {
                        CM.PXDBCurrencyAttribute.CuryConvCury(cache, crOpportunityProductsRow, newval, out newval, true);
                    }

                    e.NewValue = Math.Round(newval, CommonSetupDecPl.PrcCst, MidpointRounding.AwayFromZero);
                    e.Cancel   = true;
                }
            }
        }
Ejemplo n.º 3
0
        public virtual void UpdateCostAndPrice(List <DocLineExt> docLines)
        {
            if (docLines.Count == 0)
            {
                return;
            }

            FSServiceOrder fsServiceOrderRow = docLines[0].fsServiceOrder;
            FSSrvOrdType   fsSrvOrdTypeRow   = docLines[0].fsSrvOrdType;
            FSPostDoc      fsPostDocRow      = docLines[0].fsPostDoc;
            FSAppointment  fsAppointmentRow  = docLines[0].fsAppointment;

            if (fsSrvOrdTypeRow.BillingType != ID.SrvOrdType_BillingType.COST_AS_COST)
            {
                return;
            }

            PMTran  pmTranRow;
            INTran  inTranRow, inTranRowUpd;
            decimal curyUnitCost = 0m;
            List <PXResult <INTran> > inTranRowsList = null;

            DocLineExt docLineExtRow = docLines.Where(x => x.fsPostDoc.INDocLineRef != null).FirstOrDefault();

            if (docLineExtRow != null &&
                docLineExtRow.fsPostDoc != null &&
                docLineExtRow.fsPostDoc.INDocLineRef != null)
            {
                inTranRow = (INTran)docLineExtRow.fsPostDoc.INDocLineRef;

                inTranRowsList = PXSelect <INTran,
                                           Where <
                                               INTran.docType, Equal <Required <INTran.docType> >,
                                               And <
                                                   INTran.refNbr, Equal <Required <INTran.refNbr> > > > >
                                 .Select(new PXGraph(), inTranRow.DocType, inTranRow.RefNbr)
                                 .ToList();
            }

            if (inTranRowsList.Count() > 0)
            {
                foreach (DocLineExt docLineExt in docLines)
                {
                    pmTranRow = (PMTran)docLineExt.fsPostDoc.DocLineRef;
                    inTranRow = (INTran)docLineExt.fsPostDoc.INDocLineRef;

                    if (pmTranRow != null && inTranRow != null)
                    {
                        inTranRowUpd = inTranRowsList.RowCast <INTran>()
                                       .Where(x => x.DocType == inTranRow.DocType && x.RefNbr == inTranRow.RefNbr && x.LineNbr == inTranRow.LineNbr)
                                       .FirstOrDefault();

                        if (inTranRowUpd != null)
                        {
                            IPXCurrencyHelper currencyHelper = Base.FindImplementation <IPXCurrencyHelper>();

                            curyUnitCost = INUnitAttribute.ConvertToBase <PMTran.inventoryID, PMTran.uOM>(Base.Transactions.Cache, pmTranRow, (decimal)inTranRowUpd.UnitCost, INPrecision.NOROUND);

                            if (currencyHelper != null)
                            {
                                currencyHelper.CuryConvCury((decimal)(inTranRowUpd.UnitCost), out curyUnitCost);
                            }
                            else
                            {
                                CM.PXDBCurrencyAttribute.CuryConvCury(Base.Transactions.Cache, Base.BaseCuryInfo.Current, curyUnitCost, out curyUnitCost, true);
                            }

                            pmTranRow.TranCuryUnitRate = Math.Round(curyUnitCost, CommonSetupDecPl.PrcCst, MidpointRounding.AwayFromZero);
                            Base.Transactions.Update(pmTranRow);
                        }
                    }
                }
            }
        }