Ejemplo n.º 1
0
        public override object Evaluate(PXCache cache, object item, Dictionary <Type, object> pars)
        {
            decimal?curyAmount   = (decimal?)pars[typeof(CuryAmount)];
            long?   curyInfoID   = (long?)pars[typeof(CuryInfoID)];
            long?   toCuryInfoID = (long?)pars[typeof(ToCuryInfoID)];

            CurrencyInfo orig_info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(cache.Graph, curyInfoID);

            CurrencyInfo info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(cache.Graph, toCuryInfoID);

            if (curyAmount == null || info == null || orig_info == null)
            {
                return(0m);
            }

            if (string.Equals(info.CuryID, orig_info.CuryID))
            {
                return(curyAmount);
            }

            decimal val;
            decimal curyval;

            PXCurrencyAttribute.CuryConvBase(cache, orig_info, (decimal)curyAmount, out val);
            PXCurrencyAttribute.CuryConvCury(cache, info, val, out curyval);
            return(curyval);
        }
Ejemplo n.º 2
0
        protected virtual void _(Events.RowUpdated <CurrencyInfo> e)
        {
            if (e.Row == null)
            {
                return;
            }

            foreach (ARTran tran in Base.Transactions.Select())
            {
                decimal newTranAmt = 0;
                if (e.Row.CuryRate != null)
                {
                    PXCurrencyAttribute.CuryConvBase(e.Cache, e.Row, tran.CuryTranAmt.GetValueOrDefault(), out newTranAmt);
                }
                var newTran = Base.Transactions.Cache.CreateCopy(tran) as ARTran;
                newTran.TranAmt = newTranAmt;

                decimal oldTranAmt = 0;
                if (e.OldRow.CuryRate != null)
                {
                    PXCurrencyAttribute.CuryConvBase(e.Cache, e.OldRow, tran.CuryTranAmt.GetValueOrDefault(), out oldTranAmt);
                }
                var oldTran = Base.Transactions.Cache.CreateCopy(tran) as ARTran;
                oldTran.TranAmt = oldTranAmt;

                SyncBudgets(newTran, oldTran);
            }
        }
Ejemplo n.º 3
0
        protected virtual void SetPOAdjustAdjdAmt(POAdjust row)
        {
            if (row == null)
            {
                return;
            }

            var order = POOrder.PK.Find(Base, row.AdjdOrderType, row.AdjdOrderNbr);

            if (order != null)
            {
                if (order.CuryID == Base.Document.Current.CuryID)
                {
                    POAdjustments.Cache.SetValueExt <POAdjust.curyAdjdAmt>(row, row.CuryAdjgAmt);
                }
                else
                {
                    PXCurrencyAttribute.CuryConvBase <POAdjust.adjgCuryInfoID>(POAdjustments.Cache, row, row.CuryAdjgAmt ?? 0, out decimal baseCuryAmt);
                    PXCurrencyAttribute.CuryConvCury(Base.Caches <POOrder>(), order, baseCuryAmt, out decimal orderCuryAmt);
                    POAdjustments.Cache.SetValueExt <POAdjust.curyAdjdAmt>(row, orderCuryAmt);
                }
            }

            POAdjustments.Cache.SetValueExt <POAdjust.adjdAmt>(row, row.AdjgAmt);
        }
Ejemplo n.º 4
0
        protected virtual void _(Events.FieldVerifying <POAdjust, POAdjust.curyAdjgAmt> eventArgs)
        {
            if (eventArgs.Row == null || eventArgs.Row.IsRequest == true)
            {
                return;
            }

            var order = POOrder.PK.Find(Base, eventArgs.Row.AdjdOrderType, eventArgs.Row.AdjdOrderNbr);

            if (order != null)
            {
                bool    exceed;
                decimal newValue = (decimal?)eventArgs.NewValue ?? 0;

                if (order.CuryID == Base.Document.Current.CuryID)
                {
                    exceed = order.CuryPrepaidTotal + newValue > order.CuryUnbilledOrderTotal;
                }
                else
                {
                    PXCurrencyAttribute.CuryConvBase <POAdjust.adjgCuryInfoID>(POAdjustments.Cache, eventArgs.Row, newValue, out decimal baseCuryValue);
                    exceed = order.PrepaidTotal + baseCuryValue > order.UnbilledOrderTotal;
                }

                if (exceed)
                {
                    throw new PXSetPropertyException(Messages.PrepaidTotalGreaterUnbilledOrderTotal, order.OrderNbr);
                }
            }
        }
Ejemplo n.º 5
0
        public override void Verify(PXCache cache, object item, List <object> pars, ref bool?result, ref object value)
        {
            decimal?curyAmount   = (decimal?)Calculate <CuryAmount>(cache, item);
            long?   curyInfoID   = (long?)Calculate <CuryInfoID>(cache, item);
            long?   toCuryInfoID = (long?)Calculate <ToCuryInfoID>(cache, item);

            CurrencyInfo orig_info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(cache.Graph, curyInfoID);

            CurrencyInfo info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(cache.Graph, toCuryInfoID);

            decimal val;
            decimal curyval;

            if (curyAmount == null || info == null || orig_info == null)
            {
                value = 0m;
                return;
            }

            if (string.Equals(info.CuryID, orig_info.CuryID))
            {
                value = curyAmount;
            }
            else
            {
                PXCurrencyAttribute.CuryConvBase(cache, orig_info, (decimal)curyAmount, out val);
                PXCurrencyAttribute.CuryConvCury(cache, info, val, out curyval);
                value = curyval;
            }
        }
        public static Decimal ConventCury(PXGraph graph, string curyRateTypeID, string curyID, decimal curyCost, string destinationCuryID)
        {
            if (curyID == destinationCuryID)
            {
                return(curyCost);
            }

            Decimal baseCost   = curyCost;
            string  BaseCuryID = new PXSetup <Company>(graph).Current.BaseCuryID;

            if (curyID != BaseCuryID)
            {
                PXCurrencyAttribute.CuryConvBase(graph.Caches[typeof(CurrencyInfo)], GetCurrencyInfo(graph, curyRateTypeID, curyID), curyCost, out baseCost, true);
            }
            Decimal cost = baseCost;

            if (destinationCuryID != BaseCuryID)
            {
                PXCurrencyAttribute.CuryConvCury(graph.Caches[typeof(CurrencyInfo)], GetCurrencyInfo(graph, curyRateTypeID, destinationCuryID), baseCost, out cost, true);
            }
            return(cost);
        }
Ejemplo n.º 7
0
        public virtual IEnumerable glaccountlist()
        {
            foreach (PXResult <GLHistoryByPeriod, RevaluedGLHistory, Account, Branch, FinPeriod, GLHistoryLastRevaluation> res in
                     PXSelectJoin <GLHistoryByPeriod,
                                   InnerJoin <RevaluedGLHistory,
                                              On <RevaluedGLHistory.ledgerID, Equal <GLHistoryByPeriod.ledgerID>,
                                                  And <RevaluedGLHistory.branchID, Equal <GLHistoryByPeriod.branchID>,
                                                       And <RevaluedGLHistory.accountID, Equal <GLHistoryByPeriod.accountID>,
                                                            And <RevaluedGLHistory.subID, Equal <GLHistoryByPeriod.subID>,
                                                                 And <RevaluedGLHistory.finPeriodID, Equal <GLHistoryByPeriod.lastActivityPeriod> > > > > >,
                                              InnerJoin <Account,
                                                         On <Account.accountID, Equal <GLHistoryByPeriod.accountID> >,
                                                         InnerJoin <Branch,
                                                                    On <Branch.branchID, Equal <GLHistoryByPeriod.branchID>,
                                                                        And <Branch.ledgerID, Equal <GLHistoryByPeriod.ledgerID> > >,
                                                                    InnerJoin <FinPeriod,
                                                                               On <GLHistoryByPeriod.finPeriodID, Equal <FinPeriod.finPeriodID>,
                                                                                   And <Branch.organizationID, Equal <FinPeriod.organizationID> > >,
                                                                               LeftJoin <GLHistoryLastRevaluation,
                                                                                         On <GLHistoryByPeriod.ledgerID, Equal <GLHistoryLastRevaluation.ledgerID>,
                                                                                             And <GLHistoryByPeriod.branchID, Equal <GLHistoryLastRevaluation.branchID>,
                                                                                                  And <GLHistoryByPeriod.accountID, Equal <GLHistoryLastRevaluation.accountID>,
                                                                                                       And <GLHistoryByPeriod.subID, Equal <GLHistoryLastRevaluation.subID> > > > > > > > > >,
                                   Where <Account.curyID, Equal <Current <RevalueFilter.curyID> >,
                                          And <FinPeriod.masterFinPeriodID, Equal <Current <RevalueFilter.finPeriodID> >,
                                               And <Where <RevaluedGLHistory.curyFinYtdBalance, NotEqual <decimal0>,
                                                           Or <RevaluedGLHistory.finYtdBalance, NotEqual <decimal0> > > > > > >
                     .Select(this))
            {
                GLHistoryByPeriod        histbyper             = res;
                GLHistoryLastRevaluation lastRevaluationPeriod = res;
                RevaluedGLHistory        hist = PXCache <RevaluedGLHistory> .CreateCopy(res);

                RevaluedGLHistory existing;

                if ((existing = GLAccountList.Locate(hist)) != null)
                {
                    yield return(existing);

                    continue;
                }
                else
                {
                    GLAccountList.Cache.SetStatus(hist, PXEntryStatus.Held);
                }

                if (string.IsNullOrEmpty(hist.CuryRateTypeID = ((Account)res).RevalCuryRateTypeId))
                {
                    hist.CuryRateTypeID = cmsetup.Current.GLRateTypeReval;
                }

                if (string.IsNullOrEmpty(hist.CuryRateTypeID))
                {
                    GLAccountList.Cache.RaiseExceptionHandling <RevaluedGLHistory.curyRateTypeID>(hist, null, new PXSetPropertyException(Messages.RateTypeNotFound));
                }
                else
                {
                    CurrencyRate curyrate = PXSelect <CurrencyRate,
                                                      Where <CurrencyRate.fromCuryID, Equal <Current <RevalueFilter.curyID> >,
                                                             And <CurrencyRate.toCuryID, Equal <Current <Company.baseCuryID> >,
                                                                  And <CurrencyRate.curyRateType, Equal <Required <Account.revalCuryRateTypeId> >,
                                                                       And <CurrencyRate.curyEffDate, LessEqual <Current <RevalueFilter.curyEffDate> > > > > >,
                                                      OrderBy <Desc <CurrencyRate.curyEffDate> > > .Select(this, hist.CuryRateTypeID);

                    if (curyrate == null || curyrate.CuryMultDiv == null)
                    {
                        hist.CuryMultDiv    = "M";
                        hist.CuryRate       = 1m;
                        hist.RateReciprocal = 1m;
                        hist.CuryEffDate    = Filter.Current.CuryEffDate;
                        GLAccountList.Cache.RaiseExceptionHandling <RevaluedGLHistory.curyRate>(hist, 1m, new PXSetPropertyException(Messages.RateNotFound, PXErrorLevel.RowWarning));
                    }
                    else
                    {
                        hist.CuryRate       = curyrate.CuryRate;
                        hist.RateReciprocal = curyrate.RateReciprocal;
                        hist.CuryEffDate    = curyrate.CuryEffDate;
                        hist.CuryMultDiv    = curyrate.CuryMultDiv;
                    }

                    CurrencyInfo info = new CurrencyInfo();
                    info.BaseCuryID  = company.Current.BaseCuryID;
                    info.CuryID      = hist.CuryID;
                    info.CuryMultDiv = hist.CuryMultDiv;
                    info.CuryRate    = hist.CuryRate;

                    decimal baseval;
                    PXCurrencyAttribute.CuryConvBase(currencyinfo.Cache, info, (decimal)hist.CuryFinYtdBalance, out baseval);
                    hist.FinYtdRevalued          = baseval;
                    hist.FinPtdRevalued          = hist.FinYtdRevalued - hist.FinYtdBalance;
                    hist.LastRevaluedFinPeriodID = lastRevaluationPeriod?.LastActivityPeriod;
                }

                yield return(hist);
            }
        }
Ejemplo n.º 8
0
        public virtual IEnumerable araccountlist()
        {
            foreach (PXResult <ARHistoryByPeriod, RevaluedARHistory, Account, Customer> res in PXSelectJoin <ARHistoryByPeriod,
                                                                                                             InnerJoin <RevaluedARHistory,
                                                                                                                        On <RevaluedARHistory.customerID, Equal <ARHistoryByPeriod.customerID>,
                                                                                                                            And <RevaluedARHistory.branchID, Equal <ARHistoryByPeriod.branchID>,
                                                                                                                                 And <RevaluedARHistory.accountID, Equal <ARHistoryByPeriod.accountID>,
                                                                                                                                      And <RevaluedARHistory.subID, Equal <ARHistoryByPeriod.subID>,
                                                                                                                                           And <RevaluedARHistory.curyID, Equal <ARHistoryByPeriod.curyID>,
                                                                                                                                                And <RevaluedARHistory.finPeriodID, Equal <ARHistoryByPeriod.lastActivityPeriod> > > > > > >,
                                                                                                                        LeftJoin <Account, On <Account.accountID, Equal <ARHistoryByPeriod.accountID>, And <Account.curyID, IsNotNull> >,
                                                                                                                                  InnerJoin <Customer, On <Customer.bAccountID, Equal <ARHistoryByPeriod.customerID> > > > >,
                                                                                                             Where <ARHistoryByPeriod.curyID, Equal <Current <RevalueFilter.curyID> >,
                                                                                                                    And <ARHistoryByPeriod.finPeriodID, Equal <Current <RevalueFilter.finPeriodID> >,
                                                                                                                         And <Account.accountID, IsNull,
                                                                                                                              And <RevaluedARHistory.curyFinYtdBalance, NotEqual <decimal0> >
                                                                                                                              > > > > .Select(this))
            {
                ARHistoryByPeriod histbyper = res;
                RevaluedARHistory hist      = PXCache <RevaluedARHistory> .CreateCopy(res);

                RevaluedARHistory existing;
                Customer          cust = res;

                if ((existing = ARAccountList.Locate(hist)) != null)
                {
                    yield return(existing);

                    continue;
                }
                else
                {
                    ARAccountList.Cache.SetStatus(hist, PXEntryStatus.Held);
                }

                hist.CustomerClassID = cust.CustomerClassID;
                hist.CuryRateTypeID  = cmsetup.Current.ARRateTypeReval ?? cust.CuryRateTypeID;

                if (string.IsNullOrEmpty(hist.CuryRateTypeID))
                {
                    ARAccountList.Cache.RaiseExceptionHandling <RevaluedGLHistory.curyRateTypeID>(hist, null, new PXSetPropertyException(Messages.RateTypeNotFound));
                }
                else
                {
                    CurrencyRateByDate curyrate = PXSelect <CurrencyRateByDate,
                                                            Where <CurrencyRateByDate.fromCuryID, Equal <Current <RevalueFilter.curyID> >,
                                                                   And <CurrencyRateByDate.toCuryID, Equal <Current <Company.baseCuryID> >,
                                                                        And <CurrencyRateByDate.curyRateType, Equal <Required <Customer.curyRateTypeID> >,
                                                                             And2 <Where <CurrencyRateByDate.curyEffDate, LessEqual <Current <RevalueFilter.curyEffDate> >, Or <CurrencyRateByDate.curyEffDate, IsNull> >, And <Where <CurrencyRateByDate.nextEffDate, Greater <Current <RevalueFilter.curyEffDate> >, Or <CurrencyRateByDate.nextEffDate, IsNull> > > > > > > >
                                                  .Select(this, hist.CuryRateTypeID);

                    if (curyrate == null || curyrate.CuryMultDiv == null)
                    {
                        hist.CuryMultDiv = "M";
                        hist.CuryRate    = 1m;
                        ARAccountList.Cache.RaiseExceptionHandling <RevaluedARHistory.curyRate>(hist, 1m, new PXSetPropertyException(Messages.RateNotFound, PXErrorLevel.RowWarning));
                    }
                    else
                    {
                        hist.CuryRate    = curyrate.CuryRate;
                        hist.CuryMultDiv = curyrate.CuryMultDiv;
                    }

                    CurrencyInfo info = new CurrencyInfo();
                    info.BaseCuryID  = company.Current.BaseCuryID;
                    info.CuryID      = hist.CuryID;
                    info.CuryMultDiv = hist.CuryMultDiv;
                    info.CuryRate    = hist.CuryRate;

                    //hist.CuryFinYtdBalance -= hist.CuryFinYtdDeposits;
                    //hist.FinYtdBalance -= hist.FinYtdDeposits;

                    decimal baseval;
                    PXCurrencyAttribute.CuryConvBase(currencyinfo.Cache, info, (decimal)hist.CuryFinYtdBalance, out baseval);
                    hist.FinYtdRevalued  = baseval;
                    hist.FinPrevRevalued = string.Equals(histbyper.FinPeriodID, histbyper.LastActivityPeriod) ? hist.FinPtdRevalued : 0m;
                    hist.FinPtdRevalued  = hist.FinYtdRevalued - hist.FinPrevRevalued - hist.FinYtdBalance;
                }
                yield return(hist);
            }
        }
        protected virtual decimal ConvertAmt(string from, string to, string rateType, DateTime effectiveDate, decimal amount)
        {
            if (from == to)
            {
                return(amount);
            }

            decimal result = amount;

            PXCache curyCache = CarrierRatesDummyCuryInfo.Cache;

            using (var rs = new ReadOnlyScope(curyCache))
            {
                if (from == Base.Accessinfo.BaseCuryID)
                {
                    CurrencyInfo ci = new CurrencyInfo();
                    ci.CuryRateTypeID = rateType;
                    ci.CuryID         = to;
                    ci = (CurrencyInfo)curyCache.Insert(ci);
                    ci.SetCuryEffDate(curyCache, effectiveDate);
                    curyCache.Update(ci);
                    PXCurrencyAttribute.CuryConvCury(curyCache, ci, amount, out result);
                    curyCache.Delete(ci);
                }
                else if (to == Base.Accessinfo.BaseCuryID)
                {
                    CurrencyInfo ci = new CurrencyInfo();
                    ci.CuryRateTypeID = rateType;
                    ci.CuryID         = from;
                    ci = (CurrencyInfo)curyCache.Insert(ci);
                    ci.SetCuryEffDate(curyCache, effectiveDate);
                    curyCache.Update(ci);
                    PXCurrencyAttribute.CuryConvBase(curyCache, ci, amount, out result);
                    curyCache.Delete(ci);
                }
                else
                {
                    CurrencyInfo ciFrom = new CurrencyInfo();
                    ciFrom.CuryRateTypeID = rateType;
                    ciFrom.CuryID         = from;
                    ciFrom = (CurrencyInfo)curyCache.Insert(ciFrom);
                    ciFrom.SetCuryEffDate(curyCache, effectiveDate);
                    curyCache.Update(ciFrom);
                    decimal inBase;
                    PXCurrencyAttribute.CuryConvBase(curyCache, ciFrom, amount, out inBase, true);

                    CurrencyInfo ciTo = new CurrencyInfo();
                    ciTo.CuryRateTypeID = rateType;
                    ciTo.CuryID         = to;
                    ciTo = (CurrencyInfo)curyCache.Insert(ciTo);
                    ciTo.SetCuryEffDate(curyCache, effectiveDate);
                    curyCache.Update(ciFrom);
                    PXCurrencyAttribute.CuryConvCury(curyCache, ciTo, inBase, out result, true);

                    curyCache.Delete(ciFrom);
                    curyCache.Delete(ciTo);
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        public virtual IEnumerable apaccountlist()
        {
            foreach (PXResult <APHistoryByPeriod, RevaluedAPHistory, Vendor, APHistoryLastRevaluation> res in
                     PXSelectJoin <APHistoryByPeriod,
                                   InnerJoin <RevaluedAPHistory,
                                              On <RevaluedAPHistory.vendorID, Equal <APHistoryByPeriod.vendorID>,
                                                  And <RevaluedAPHistory.branchID, Equal <APHistoryByPeriod.branchID>,
                                                       And <RevaluedAPHistory.accountID, Equal <APHistoryByPeriod.accountID>,
                                                            And <RevaluedAPHistory.subID, Equal <APHistoryByPeriod.subID>,
                                                                 And <RevaluedAPHistory.curyID, Equal <APHistoryByPeriod.curyID>,
                                                                      And <RevaluedAPHistory.finPeriodID, Equal <APHistoryByPeriod.lastActivityPeriod> > > > > > >,
                                              InnerJoin <Vendor,
                                                         On <Vendor.bAccountID, Equal <APHistoryByPeriod.vendorID> >,
                                                         LeftJoin <APHistoryLastRevaluation,
                                                                   On <APHistoryByPeriod.vendorID, Equal <APHistoryLastRevaluation.vendorID>,
                                                                       And <APHistoryByPeriod.branchID, Equal <APHistoryLastRevaluation.branchID>,
                                                                            And <APHistoryByPeriod.accountID, Equal <APHistoryLastRevaluation.accountID>,
                                                                                 And <APHistoryByPeriod.subID, Equal <APHistoryLastRevaluation.subID>,
                                                                                      And <APHistoryByPeriod.curyID, Equal <APHistoryLastRevaluation.curyID> > > > > > > > >,
                                   Where <APHistoryByPeriod.curyID, Equal <Current <RevalueFilter.curyID> >,
                                          And <APHistoryByPeriod.finPeriodID, Equal <Current <RevalueFilter.finPeriodID> >,
                                               And <Where <RevaluedAPHistory.curyFinYtdBalance, NotEqual <decimal0>,
                                                           Or <RevaluedAPHistory.finPtdRevalued, NotEqual <decimal0>,
                                                               Or <RevaluedAPHistory.curyFinYtdDeposits, NotEqual <decimal0> > > > > > > >
                     .Select(this))
            {
                APHistoryByPeriod        histbyper             = res;
                APHistoryLastRevaluation lastRevaluationPeriod = res;
                RevaluedAPHistory        hist = PXCache <RevaluedAPHistory> .CreateCopy(res);

                RevaluedAPHistory existing;
                Vendor            vendor = res;

                if ((existing = APAccountList.Locate(hist)) != null)
                {
                    yield return(existing);

                    continue;
                }
                else
                {
                    APAccountList.Cache.SetStatus(hist, PXEntryStatus.Held);
                }

                hist.VendorClassID  = vendor.VendorClassID;
                hist.CuryRateTypeID = cmsetup.Current.APRateTypeReval ?? ((Vendor)res).CuryRateTypeID;

                if (string.IsNullOrEmpty(hist.CuryRateTypeID))
                {
                    APAccountList.Cache.RaiseExceptionHandling <RevaluedGLHistory.curyRateTypeID>(hist, null, new PXSetPropertyException(Messages.RateTypeNotFound));
                }
                else
                {
                    CurrencyRate curyrate = PXSelect <CurrencyRate,
                                                      Where <CurrencyRate.fromCuryID, Equal <Current <RevalueFilter.curyID> >,
                                                             And <CurrencyRate.toCuryID, Equal <Current <Company.baseCuryID> >,
                                                                  And <CurrencyRate.curyRateType, Equal <Required <Vendor.curyRateTypeID> >,
                                                                       And <CurrencyRate.curyEffDate, LessEqual <Current <RevalueFilter.curyEffDate> > > > > >,
                                                      OrderBy <Desc <CurrencyRate.curyEffDate> > > .Select(this, hist.CuryRateTypeID);

                    if (curyrate == null || curyrate.CuryMultDiv == null)
                    {
                        hist.CuryMultDiv    = "M";
                        hist.CuryRate       = 1m;
                        hist.RateReciprocal = 1m;
                        hist.CuryEffDate    = Filter.Current.CuryEffDate;
                        APAccountList.Cache.RaiseExceptionHandling <RevaluedAPHistory.curyRate>(hist, 1m, new PXSetPropertyException(Messages.RateNotFound, PXErrorLevel.RowWarning));
                    }
                    else
                    {
                        hist.CuryRate       = curyrate.CuryRate;
                        hist.RateReciprocal = curyrate.RateReciprocal;
                        hist.CuryEffDate    = curyrate.CuryEffDate;
                        hist.CuryMultDiv    = curyrate.CuryMultDiv;
                    }

                    CurrencyInfo info = new CurrencyInfo();
                    info.BaseCuryID  = company.Current.BaseCuryID;
                    info.CuryID      = hist.CuryID;
                    info.CuryMultDiv = hist.CuryMultDiv;
                    info.CuryRate    = hist.CuryRate;
                    info.RecipRate   = hist.RateReciprocal;

                    hist.CuryFinYtdBalance -= hist.CuryFinYtdDeposits;
                    hist.FinYtdBalance     -= hist.FinYtdDeposits;

                    decimal baseval;
                    PXCurrencyAttribute.CuryConvBase(currencyinfo.Cache, info, (decimal)hist.CuryFinYtdBalance, out baseval);
                    hist.FinYtdRevalued          = baseval;
                    hist.FinPrevRevalued         = string.Equals(histbyper.FinPeriodID, histbyper.LastActivityPeriod) ? hist.FinPtdRevalued : 0m;
                    hist.FinPtdRevalued          = hist.FinYtdRevalued - hist.FinPrevRevalued - hist.FinYtdBalance;
                    hist.LastRevaluedFinPeriodID = lastRevaluationPeriod?.LastActivityPeriod;
                }
                yield return(hist);
            }
        }
Ejemplo n.º 11
0
        public static ItemCost Fetch(PXGraph graph, int?vendorID, int?vendorLocationID, DateTime?docDate, string curyID, int?inventoryID, int?subItemID, int?siteID, string uom, bool onlyVendor)
        {
            InventoryItem     item        = null;
            INItemCost        cost        = null;
            Vendor            vendor      = null;
            POVendorInventory vendorPrice = null;

            foreach (PXResult <InventoryItem, INItemCost, Vendor, POVendorInventory> r in
                     PXSelectJoin <InventoryItem,
                                   LeftJoin <INItemCost, On <INItemCost.inventoryID, Equal <InventoryItem.inventoryID> >,
                                             LeftJoin <Vendor,
                                                       On <Vendor.bAccountID, Equal <Required <Vendor.bAccountID> > >,
                                                       LeftJoin <POVendorInventory,
                                                                 On <POVendorInventory.inventoryID, Equal <InventoryItem.inventoryID>,
                                                                     And <POVendorInventory.active, Equal <boolTrue>,
                                                                          And <POVendorInventory.vendorID, Equal <Vendor.bAccountID>,
                                                                               And2 <Where <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> >,
                                                                                            Or <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID>,
                                                                                                Or <POVendorInventory.subItemID, IsNull,
                                                                                                    Or <Where <Required <POVendorInventory.subItemID>, IsNull,
                                                                                                               And <POVendorInventory.subItemID, Equal <True> > > > > > >,

                                                                                     And2 <Where <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> >,
                                                                                                  Or <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit> > >,
                                                                                           And <Where <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> >,
                                                                                                       Or <POVendorInventory.vendorLocationID, IsNull> > > > > > > > > > >,
                                   Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > >,
                                   OrderBy <
                                       Asc <Switch <Case <Where <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit> >, boolTrue>, boolFalse>,
                                            Asc <Switch <Case <Where <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID> >, boolTrue>, boolFalse>,
                                                 Asc <Switch <Case <Where <POVendorInventory.vendorLocationID, IsNull>, boolTrue>, boolFalse>,
                                                      Asc <InventoryItem.inventoryCD> > > > > >
                     .Select(graph, vendorID, subItemID, subItemID, uom, vendorLocationID, inventoryID))
            {
                item        = r;
                cost        = r;
                vendor      = r;
                vendorPrice = r;
                if (vendorPrice != null)
                {
                    break;
                }
            }
            if (vendorPrice != null && vendorPrice.VendorID != null)
            {
                Decimal?price =
                    (docDate != null && docDate >= vendorPrice.EffDate && vendorPrice.EffPrice > 0)
                                        ? vendorPrice.EffPrice
                                        : vendorPrice.LastPrice;
                string purchaseUnit = vendorPrice.PurchaseUnit ?? item.PurchaseUnit;

                if (price == 0)
                {
                    price = null;
                }

                if (price != null)
                {
                    Company company = new PXSetup <Company>(graph).Current;
                    if (vendorPrice.CuryID == company.BaseCuryID || vendorPrice.CuryID == null)
                    {
                        return(new ItemCost(item, purchaseUnit, price.Value));
                    }
                    try
                    {
                        Decimal basePrice;
                        PXCurrencyAttribute.CuryConvBase(graph.Caches[typeof(CurrencyInfo)], GetCurrencyInfo(graph, vendor.CuryRateTypeID, vendorPrice.CuryID), price.Value, out basePrice, true);
                        return(new ItemCost(item, purchaseUnit, vendorPrice.CuryID, price.Value, basePrice));
                    }
                    catch
                    {
                        return(new ItemCost(item, purchaseUnit, 0));
                    }
                }
            }

            return
                (FetchHistoryLastCost(graph, vendorID, vendorLocationID, inventoryID, subItemID) ??
                 (onlyVendor ? null : FetchLastCost(graph, item, docDate)) ??
                 (onlyVendor ? null : FetchSiteLastCost(graph, item, cost, siteID)) ??
                 new ItemCost(item, 0));
        }
Ejemplo n.º 12
0
        public virtual List <PMTask> CreateProjectTrans()
        {
            var autoAllocateTasks = new List <PMTask>();

            if (Base.BatchModule.Current != null && Base.BatchModule.Current.Module != BatchModule.GL)
            {
                PXResultset <GLTran> trans = new PXSelect <GLTran,
                                                           Where <GLTran.module, Equal <Current <Batch.module> >,
                                                                  And <GLTran.batchNbr, Equal <Current <Batch.batchNbr> >,
                                                                       And <GLTran.pMTranID, IsNull,
                                                                            And <GLTran.isNonPM, NotEqual <True> > > > > >(Base).Select();

                if (trans.Count > 0)
                {
                    ProjectBalance pb = CreateProjectBalance();
                    var            tasksToAutoAllocate = new Dictionary <string, PMTask>();
                    var            sourceForAllocation = new List <PMTran>();

                    var doc = new PMRegister();
                    doc.Module      = Base.BatchModule.Current.Module;
                    doc.Date        = Base.BatchModule.Current.DateEntered;
                    doc.Description = Base.BatchModule.Current.Description;
                    doc.Released    = true;
                    doc.Status      = PMRegister.status.Released;
                    bool docInserted = false;                     //to prevent creating empty batch
                    JournalEntryTranRef entryRefGraph = PXGraph.CreateInstance <JournalEntryTranRef>();

                    foreach (GLTran tran in trans)
                    {
                        var acc = (Account)PXSelect <Account,
                                                     Where <Account.accountID, Equal <Required <GLTran.accountID> >,
                                                            And <Account.accountGroupID, IsNotNull> > > .Select(Base, tran.AccountID);

                        if (acc == null)
                        {
                            continue;
                        }

                        var ag = (PMAccountGroup)PXSelect <PMAccountGroup,
                                                           Where <PMAccountGroup.groupID, Equal <Required <Account.accountGroupID> >,
                                                                  And <PMAccountGroup.type, NotEqual <PMAccountType.offBalance> > > > .Select(Base, acc.AccountGroupID);

                        if (ag == null)
                        {
                            continue;
                        }

                        var project = (PMProject)PXSelect <PMProject,
                                                           Where <PMProject.contractID, Equal <Required <GLTran.projectID> >,
                                                                  And <PMProject.nonProject, Equal <False> > > > .Select(Base, tran.ProjectID);

                        if (project == null)
                        {
                            continue;
                        }

                        var task = (PMTask)PXSelect <PMTask,
                                                     Where <PMTask.projectID, Equal <Required <GLTran.projectID> >,
                                                            And <PMTask.taskID, Equal <Required <GLTran.taskID> > > > > .Select(Base, tran.ProjectID, tran.TaskID);

                        if (task == null)
                        {
                            continue;
                        }

                        APTran apTran = null;
                        if (Base.BatchModule.Current.Module == BatchModule.AP)
                        {
                            apTran = (APTran)PXSelect <APTran,
                                                       Where <APTran.refNbr, Equal <Required <GLTran.refNbr> >,
                                                              And <APTran.lineNbr, Equal <Required <GLTran.tranLineNbr> >,
                                                                   And <APTran.tranType, Equal <Required <GLTran.tranType> > > > > > .Select(Base, tran.RefNbr, tran.TranLineNbr, tran.TranType);
                        }

                        ARTran arTran = null;
                        if (Base.BatchModule.Current.Module == BatchModule.AR)
                        {
                            arTran = (ARTran)PXSelect <ARTran,
                                                       Where <ARTran.refNbr, Equal <Required <GLTran.refNbr> >,
                                                              And <ARTran.lineNbr, Equal <Required <GLTran.tranLineNbr> >,
                                                                   And <ARTran.tranType, Equal <Required <GLTran.tranType> > > > > > .Select(Base, tran.RefNbr, tran.TranLineNbr, tran.TranType);
                        }

                        if (!docInserted)
                        {
                            doc         = ProjectDocs.Insert(doc);
                            docInserted = true;
                        }

                        doc.OrigDocType = entryRefGraph.GetDocType(apTran, arTran, tran);
                        doc.OrigNoteID  = entryRefGraph.GetNoteID(apTran, arTran, tran);

                        PMTran pmt = (PMTran)ProjectTrans.Cache.Insert();

                        pmt.BranchID       = tran.BranchID;
                        pmt.AccountGroupID = acc.AccountGroupID;
                        pmt.AccountID      = tran.AccountID;
                        pmt.SubID          = tran.SubID;
                        entryRefGraph.AssignCustomerVendorEmployee(tran, pmt);                         //CustomerLocation is lost.
                        //pmt.BatchNbr = tran.BatchNbr;
                        pmt.Date         = tran.TranDate;
                        pmt.TranDate     = tran.TranDate;
                        pmt.Description  = tran.TranDesc;
                        pmt.FinPeriodID  = tran.FinPeriodID;
                        pmt.TranPeriodID = tran.TranPeriodID;
                        pmt.InventoryID  = tran.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID;
                        pmt.OrigLineNbr  = tran.LineNbr;
                        pmt.OrigModule   = tran.Module;
                        pmt.OrigRefNbr   = tran.RefNbr;
                        pmt.OrigTranType = tran.TranType;
                        pmt.ProjectID    = tran.ProjectID;
                        pmt.TaskID       = tran.TaskID;
                        pmt.CostCodeID   = tran.CostCodeID;
                        if (arTran != null)
                        {
                            pmt.Billable                  = false;
                            pmt.ExcludedFromBilling       = true;
                            pmt.ExcludedFromBillingReason = arTran.TranType == ARDocType.CreditMemo ?
                                                            PXMessages.LocalizeFormatNoPrefix(Messages.ExcludedFromBillingAsCreditMemoResult, arTran.RefNbr) :
                                                            PXMessages.LocalizeFormatNoPrefix(Messages.ExcludedFromBillingAsARInvoiceResult, arTran.RefNbr);
                        }
                        else
                        {
                            pmt.Billable = tran.NonBillable != true;
                        }
                        pmt.Released = true;

                        if (apTran != null && apTran.Date != null)
                        {
                            pmt.Date = apTran.Date;
                        }

                        pmt.UseBillableQty = true;
                        pmt.UOM            = tran.UOM;

                        pmt.Amount = tran.DebitAmt - tran.CreditAmt;

                        CurrencyInfo projectCuryInfo = null;
                        if (PXAccess.FeatureInstalled <FeaturesSet.projectMultiCurrency>())
                        {
                            pmt.TranCuryID     = Base.BatchModule.Current.CuryID;
                            pmt.ProjectCuryID  = project.CuryID;
                            pmt.BaseCuryInfoID = tran.CuryInfoID;
                            pmt.TranCuryAmount = tran.CuryDebitAmt - tran.CuryCreditAmt;

                            if (project.CuryID == Base.ledger.Current.BaseCuryID)
                            {
                                pmt.ProjectCuryInfoID = tran.CuryInfoID;
                                pmt.ProjectCuryAmount = pmt.Amount;
                            }
                            else if (project.CuryID == Base.BatchModule.Current.CuryID)
                            {
                                projectCuryInfo                = new CurrencyInfo();
                                projectCuryInfo.ModuleCode     = GL.BatchModule.PM;
                                projectCuryInfo.BaseCuryID     = project.CuryID;
                                projectCuryInfo.CuryID         = project.CuryID;
                                projectCuryInfo.CuryRateTypeID = project.RateTypeID ?? Base.CMSetup.Current.PMRateTypeDflt;
                                projectCuryInfo.CuryEffDate    = tran.TranDate;
                                projectCuryInfo.CuryRate       = 1;
                                projectCuryInfo.RecipRate      = 1;
                                projectCuryInfo                = Base.currencyinfo.Insert(projectCuryInfo);
                                pmt.ProjectCuryInfoID          = projectCuryInfo.CuryInfoID;
                                pmt.ProjectCuryAmount          = pmt.TranCuryAmount;
                            }
                            else
                            {
                                CM.Extensions.IPXCurrencyService currencyService = ServiceLocator.Current.GetInstance <Func <PXGraph, CM.Extensions.IPXCurrencyService> >()(Base);

                                projectCuryInfo                = new CurrencyInfo();
                                projectCuryInfo.ModuleCode     = GL.BatchModule.PM;
                                projectCuryInfo.BaseCuryID     = project.CuryID;
                                projectCuryInfo.CuryID         = Base.BatchModule.Current.CuryID;
                                projectCuryInfo.CuryRateTypeID = project.RateTypeID ?? currencyService.DefaultRateTypeID(BatchModule.PM);
                                projectCuryInfo.CuryEffDate    = tran.TranDate;

                                var rate = currencyService.GetRate(projectCuryInfo.CuryID, projectCuryInfo.BaseCuryID, projectCuryInfo.CuryRateTypeID, projectCuryInfo.CuryEffDate);
                                if (rate == null)
                                {
                                    throw new PXException(PM.Messages.FxTranToProjectNotFound, projectCuryInfo.CuryID, projectCuryInfo.BaseCuryID, projectCuryInfo.CuryRateTypeID, tran.TranDate);
                                }

                                projectCuryInfo       = Base.currencyinfo.Insert(projectCuryInfo);
                                pmt.ProjectCuryInfoID = projectCuryInfo.CuryInfoID;
                                decimal val;
                                PXCurrencyAttribute.CuryConvBase(Base.BatchModule.Cache, projectCuryInfo, pmt.TranCuryAmount.GetValueOrDefault(), out val);
                                pmt.ProjectCuryAmount = val;
                            }
                        }
                        else
                        {
                            pmt.TranCuryAmount    = pmt.Amount;
                            pmt.ProjectCuryAmount = pmt.Amount;
                            pmt.TranCuryID        = Base.ledger.Current.BaseCuryID;
                            pmt.ProjectCuryID     = Base.ledger.Current.BaseCuryID;

                            if (Base.BatchModule.Current.CuryID != Base.ledger.Current.BaseCuryID)
                            {
                                CurrencyInfo baseCuryInfo = new CurrencyInfo();
                                baseCuryInfo.ModuleCode     = GL.BatchModule.PM;
                                baseCuryInfo.BaseCuryID     = Base.ledger.Current.BaseCuryID;
                                baseCuryInfo.CuryID         = Base.ledger.Current.BaseCuryID;
                                baseCuryInfo.CuryRateTypeID = null;
                                baseCuryInfo.CuryEffDate    = tran.TranDate;
                                baseCuryInfo.CuryRate       = 1;
                                baseCuryInfo.RecipRate      = 1;
                                baseCuryInfo          = Base.currencyinfo.Insert(baseCuryInfo);
                                pmt.ProjectCuryInfoID = baseCuryInfo.CuryInfoID;
                                pmt.BaseCuryInfoID    = baseCuryInfo.CuryInfoID;
                            }
                            else
                            {
                                pmt.ProjectCuryInfoID = tran.CuryInfoID;
                                pmt.BaseCuryInfoID    = tran.CuryInfoID;
                            }
                        }

                        pmt.Qty = tran.Qty;                        //pmt.Amount >= 0 ? tran.Qty : (tran.Qty * -1);
                        int sign = 1;
                        if (acc.Type == AccountType.Income || acc.Type == AccountType.Liability)
                        {
                            sign = -1;
                        }

                        if (ProjectBalance.IsFlipRequired(acc.Type, ag.Type))
                        {
                            pmt.ProjectCuryAmount = -pmt.ProjectCuryAmount;
                            pmt.TranCuryAmount    = -pmt.TranCuryAmount;
                            pmt.Amount            = -pmt.Amount;
                            pmt.Qty = -pmt.Qty;
                        }
                        pmt.BillableQty = pmt.Qty;


                        Base.GLTranModuleBatNbr.SetValueExt <GLTran.pMTranID>(tran, pmt.TranID);

                        if (apTran != null && apTran.NoteID != null)
                        {
                            PXNoteAttribute.CopyNoteAndFiles(Base.Caches[typeof(AP.APTran)], apTran, ProjectTrans.Cache, pmt);
                        }
                        else if (arTran != null && arTran.NoteID != null)
                        {
                            PXNoteAttribute.CopyNoteAndFiles(Base.Caches[typeof(AR.ARTran)], arTran, ProjectTrans.Cache, pmt);
                        }

                        ProjectBalance.Result balance = pb.Calculate(project, pmt, ag, acc.Type, sign, 1);

                        if (balance.Status != null)
                        {
                            PMBudgetAccum ps = new PMBudgetAccum();
                            ps.ProjectID      = balance.Status.ProjectID;
                            ps.ProjectTaskID  = balance.Status.ProjectTaskID;
                            ps.AccountGroupID = balance.Status.AccountGroupID;
                            ps.InventoryID    = balance.Status.InventoryID;
                            ps.CostCodeID     = balance.Status.CostCodeID;
                            ps.UOM            = balance.Status.UOM;
                            ps.IsProduction   = balance.Status.IsProduction;
                            ps.Type           = balance.Status.Type;
                            ps.Description    = balance.Status.Description;
                            ps.CuryInfoID     = balance.Status.CuryInfoID;

                            ps                   = ProjectBudget.Insert(ps);
                            ps.ActualQty        += balance.Status.ActualQty.GetValueOrDefault();
                            ps.CuryActualAmount += balance.Status.CuryActualAmount.GetValueOrDefault();
                            ps.ActualAmount     += balance.Status.ActualAmount.GetValueOrDefault();

                            if (arTran != null && arTran.LineNbr != null && ag.Type == GL.AccountType.Income)
                            {
                                ps.CuryInvoicedAmount -= balance.Status.CuryActualAmount.GetValueOrDefault();
                                ps.InvoicedAmount     -= balance.Status.ActualAmount.GetValueOrDefault();
                            }
                        }

                        if (balance.ForecastHistory != null)
                        {
                            PMForecastHistoryAccum forecast = new PMForecastHistoryAccum();
                            forecast.ProjectID      = balance.ForecastHistory.ProjectID;
                            forecast.ProjectTaskID  = balance.ForecastHistory.ProjectTaskID;
                            forecast.AccountGroupID = balance.ForecastHistory.AccountGroupID;
                            forecast.InventoryID    = balance.ForecastHistory.InventoryID;
                            forecast.CostCodeID     = balance.ForecastHistory.CostCodeID;
                            forecast.PeriodID       = balance.ForecastHistory.PeriodID;

                            forecast = ForecastHistory.Insert(forecast);

                            forecast.ActualQty        += balance.ForecastHistory.ActualQty.GetValueOrDefault();
                            forecast.CuryActualAmount += balance.ForecastHistory.CuryActualAmount.GetValueOrDefault();
                            forecast.ActualAmount     += balance.ForecastHistory.ActualAmount.GetValueOrDefault();
                        }

                        if (balance.TaskTotal != null)
                        {
                            PMTaskTotal ta = new PMTaskTotal();
                            ta.ProjectID = balance.TaskTotal.ProjectID;
                            ta.TaskID    = balance.TaskTotal.TaskID;

                            ta                = ProjectTaskTotals.Insert(ta);
                            ta.CuryAsset     += balance.TaskTotal.CuryAsset.GetValueOrDefault();
                            ta.Asset         += balance.TaskTotal.Asset.GetValueOrDefault();
                            ta.CuryLiability += balance.TaskTotal.CuryLiability.GetValueOrDefault();
                            ta.Liability     += balance.TaskTotal.Liability.GetValueOrDefault();
                            ta.CuryIncome    += balance.TaskTotal.CuryIncome.GetValueOrDefault();
                            ta.Income        += balance.TaskTotal.Income.GetValueOrDefault();
                            ta.CuryExpense   += balance.TaskTotal.CuryExpense.GetValueOrDefault();
                            ta.Expense       += balance.TaskTotal.Expense.GetValueOrDefault();
                        }

                        RegisterReleaseProcess.AddToUnbilledSummary(Base, pmt);

                        sourceForAllocation.Add(pmt);
                        if (pmt.Allocated != true && pmt.ExcludedFromAllocation != true && project.AutoAllocate == true)
                        {
                            if (!tasksToAutoAllocate.ContainsKey(string.Format("{0}.{1}", task.ProjectID, task.TaskID)))
                            {
                                tasksToAutoAllocate.Add(string.Format("{0}.{1}", task.ProjectID, task.TaskID), task);
                            }
                        }

                        entryRefGraph.AssignAdditionalFields(tran, pmt);
                    }
                    autoAllocateTasks.AddRange(tasksToAutoAllocate.Values);
                }
            }
            return(autoAllocateTasks);
        }