Example #1
0
		private void defaultCuryRate(PXCache cache, bool ForceDefault)
		{
			CurrencyRate rate = getCuryRate(cache);
			if (rate != null)
			{
				DateTime? UserCuryEffDate = CuryEffDate;

				CuryEffDate = rate.CuryEffDate;
				CuryRate = Math.Round((decimal)rate.CuryRate, 8);
				CuryMultDiv = rate.CuryMultDiv;
				RecipRate = Math.Round((decimal)rate.RateReciprocal, 8);

				if (rate.CuryEffDate < UserCuryEffDate)
				{
					CurrencyRateType ratetype = (CurrencyRateType)PXSelectorAttribute.Select<CurrencyInfo.curyRateTypeID>(cache, this);
					if (ratetype != null && ratetype.RateEffDays > 0 && ((TimeSpan)(UserCuryEffDate - rate.CuryEffDate)).Days > ratetype.RateEffDays)
					{
						throw new PXRateIsNotDefinedForThisDateException(rate.CuryRateType, rate.FromCuryID, rate.ToCuryID, (DateTime)UserCuryEffDate);
					}
				}
			}
			else if (ForceDefault)
			{
				if (object.Equals(this._CuryID, this._BaseCuryID))
				{
					bool dirty = cache.IsDirty;
					CurrencyInfo dflt = new CurrencyInfo();
					cache.SetDefaultExt<CurrencyInfo.curyRate>(dflt);
					cache.SetDefaultExt<CurrencyInfo.curyMultDiv>(dflt);
					cache.SetDefaultExt<CurrencyInfo.recipRate>(dflt);
					CuryRate = Math.Round((decimal)dflt.CuryRate, 8);
					CuryMultDiv = dflt.CuryMultDiv;
					RecipRate = Math.Round((decimal)dflt.RecipRate, 8);
					cache.IsDirty = dirty;
				}
				else if (this._CuryRateTypeID == null || this._CuryEffDate == null)
				{
					this.CuryRate = null;
					this.RecipRate = null;
					this.CuryMultDiv = "M"; 
				}
				else
				{
					this.CuryRate = null;
					this.RecipRate = null;
					this.CuryMultDiv = "M";
					throw new PXSetPropertyException(Messages.RateNotFound, PXErrorLevel.Warning);
				}
			}
		}
Example #2
0
            public void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null && !String.IsNullOrEmpty(info.ModuleCode))
                {
                    CMSetup CMSetup = null;
                    if (PXAccess.FeatureInstalled <FeaturesSet.multicurrency>())
                    {
                        CMSetup = info.getCMSetup(sender);
                    }

                    if (CMSetup != null)
                    {
                        string rateType;
                        switch (info.ModuleCode)
                        {
                        case BatchModule.PM:
                            rateType = CMSetup.PMRateTypeDflt;
                            break;

                        case BatchModule.CA:
                            rateType = CMSetup.CARateTypeDflt;
                            break;

                        case BatchModule.AP:
                            rateType = CMSetup.APRateTypeDflt;
                            break;

                        case BatchModule.AR:
                            rateType = CMSetup.ARRateTypeDflt;
                            break;

                        case BatchModule.GL:
                            rateType = CMSetup.GLRateTypeDflt;
                            break;

                        default:
                            rateType = null;
                            break;
                        }
                        if (!string.IsNullOrEmpty(rateType))
                        {
                            e.NewValue = rateType;
                        }
                    }
                }
            }
Example #3
0
            public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null)
                {
                    try
                    {
                        info.defaultCuryRate(sender);
                    }
                    catch (PXSetPropertyException ex)
                    {
                        sender.RaiseExceptionHandling(_FieldName, e.Row, sender.GetValue(e.Row, _FieldOrdinal), ex);
                    }
                }
            }
Example #4
0
            public void RowSelected(PXCache sender, PXRowSelectedEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null)
                {
                    bool disabled = info.IsReadOnly == true || (info.CuryID == info.BaseCuryID);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.curyMultDiv>(sender, info, !disabled);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.sampleCuryRate>(sender, info, !disabled);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.sampleRecipRate>(sender, info, !disabled);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.curyRateTypeID>(sender, info, !disabled);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.curyEffDate>(sender, info, !disabled);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.baseCuryID>(sender, info, false);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.displayCuryID>(sender, info, false);
                    PXUIFieldAttribute.SetEnabled <CurrencyInfo.curyID>(sender, info, true);
                }
            }
Example #5
0
            public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null)
                {
                    //reset effective date to document date first
                    info.SetDefaultEffDate(sender);
                    try
                    {
                        info.defaultCuryRate(sender);
                    }
                    catch (PXSetPropertyException ex)
                    {
                        sender.RaiseExceptionHandling(_FieldName, e.Row, sender.GetValue(e.Row, _FieldOrdinal), ex);
                    }
                    info.CuryPrecision = null;
                }
            }
Example #6
0
            public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null && e.ExternalCall)
                {
                    decimal rate = Math.Round((decimal)info.SampleRecipRate, 8);
                    if (rate == 0)
                    {
                        rate = 1;
                    }
                    info.CuryRate    = rate;
                    info.RecipRate   = Math.Round((decimal)(1 / rate), 8);
                    info.CuryMultDiv = "D";
                    if (info.CheckRateVariance(sender))
                    {
                        PXUIFieldAttribute.SetWarning(sender, e.Row, "SampleRecipRate", Messages.RateVarianceExceeded);
                    }
                }
            }
Example #7
0
            public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info == null || !e.ExternalCall)
                {
                    return;
                }

                decimal rate = Math.Round((decimal)info.SampleCuryRate, 8);

                bool hasCurrencyRateDefaulted = false;

                if (rate == 0)
                {
                    try
                    {
                        info.defaultCuryRate(sender);
                        hasCurrencyRateDefaulted = true;
                    }
                    catch (PXSetPropertyException)
                    {
                        rate = 1;
                    }
                }

                if (!hasCurrencyRateDefaulted)
                {
                    info.CuryRate    = rate;
                    info.RecipRate   = Math.Round(1m / rate, 8);
                    info.CuryMultDiv = CuryMultDivType.Mult;
                }

                if (info.CheckRateVariance(sender))
                {
                    PXUIFieldAttribute.SetWarning <CurrencyInfo.sampleCuryRate>(
                        sender,
                        e.Row,
                        Messages.RateVarianceExceeded);
                }
            }
Example #8
0
            public void FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null && !String.IsNullOrEmpty(info.ModuleCode))
                {
                    CMSetup CMSetup = info.getCMSetup(sender);
                    //if (CMSetup != null && CMSetup.MCActivated == true)
                    //{
                    //    if (info.ModuleCode == "AP" && CMSetup.APRateTypeOverride != true ||
                    //        info.ModuleCode == "AR" && CMSetup.ARRateTypeOverride != true)
                    //    {
                    //        object newValue;
                    //        sender.RaiseFieldDefaulting<CurrencyInfo.curyRateTypeID>(e.Row, out newValue);
                    //        if (!object.Equals(newValue, e.NewValue))
                    //        {
                    //            throw new PXSetPropertyException(Messages.RateTypeCannotBeChanged, "CuryRateTypeID");
                    //        }
                    //    }
                    //}
                }
            }
Example #9
0
            public void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null && !String.IsNullOrEmpty(info.ModuleCode))
                {
                    CMSetup CMSetup = info.getCMSetup(sender);
                    if (CMSetup != null && CMSetup.MCActivated == true)
                    {
                        string rateType;
                        switch (info.ModuleCode)
                        {
                        case "CA":
                            rateType = CMSetup.CARateTypeDflt;
                            break;

                        case "AP":
                            rateType = CMSetup.APRateTypeDflt;
                            break;

                        case "AR":
                            rateType = CMSetup.ARRateTypeDflt;
                            break;

                        case "GL":
                            rateType = CMSetup.GLRateTypeDflt;
                            break;

                        default:
                            rateType = null;
                            break;
                        }
                        if (!string.IsNullOrEmpty(rateType))
                        {
                            e.NewValue = rateType;
                        }
                    }
                }
            }
Example #10
0
            public void RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
            {
                CurrencyInfo info = e.Row as CurrencyInfo;

                if (info != null)
                {
                    CurrencyInfo old = e.OldRow as CurrencyInfo;
                    if (old != null && (String.IsNullOrEmpty(info.CuryID) || String.IsNullOrEmpty(info.BaseCuryID)))
                    {
                        info.BaseCuryID = old.BaseCuryID;
                        info.CuryID     = old.CuryID;
                    }
                    if (currencyInfoDirty == false &&
                        info.CuryID == old.CuryID &&
                        info.CuryRateTypeID == old.CuryRateTypeID &&
                        info.CuryEffDate == old.CuryEffDate &&
                        info.CuryMultDiv == old.CuryMultDiv &&
                        info.CuryRate == old.CuryRate)
                    {
                        sender.IsDirty    = false;
                        currencyInfoDirty = null;
                    }
                }
            }
        public void Revalue(RevalueFilter filter, List <RevaluedGLHistory> list)
        {
            JournalEntry je        = PXGraph.CreateInstance <JournalEntry>();
            PostGraph    pg        = PXGraph.CreateInstance <PostGraph>();
            PXCache      basecache = je.Caches[typeof(AcctHist)];

            je.Views.Caches.Add(typeof(AcctHist));

            string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID;

            if (string.IsNullOrEmpty(extRefNbrNumbering) == false)
            {
                RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering);
                helper.Subscribe(je);
            }

            DocumentList <Batch> created = new DocumentList <Batch>(je);

            Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID);

            bool hasErrors = false;

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (RevaluedGLHistory hist in list)
                {
                    PXProcessing <RevaluedGLHistory> .SetCurrentItem(hist);

                    if (hist.FinPtdRevalued == 0m)
                    {
                        PXProcessing <RevaluedGLHistory> .SetProcessed();

                        continue;
                    }

                    string FinPeriod =
                        FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(hist.BranchID), filter.FinPeriodID)
                        .Result
                        .FinPeriodID;

                    ProcessingResult result = CheckFinPeriod(FinPeriod, hist.BranchID);
                    if (!result.IsSuccess)
                    {
                        hasErrors = true;
                        continue;
                    }

                    if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted)
                    {
                        je.Save.Press();

                        if (created.Find(je.BatchModule.Current) == null)
                        {
                            created.Add(je.BatchModule.Current);
                        }
                    }

                    Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch();
                    if (cmbatch.BatchNbr == null)
                    {
                        je.Clear();

                        CurrencyInfo info = new CurrencyInfo();
                        info.CuryID      = hist.CuryID;
                        info.CuryEffDate = hist.CuryEffDate;
                        info.BaseCalc    = false;
                        info             = je.currencyinfo.Insert(info) ?? info;

                        cmbatch             = new Batch();
                        cmbatch.BranchID    = hist.BranchID;
                        cmbatch.Module      = "CM";
                        cmbatch.Status      = "U";
                        cmbatch.AutoReverse = false;
                        cmbatch.Released    = true;
                        cmbatch.Hold        = false;
                        cmbatch.DateEntered = filter.CuryEffDate;
                        FinPeriodIDAttribute.SetPeriodsByMaster <Batch.finPeriodID>(je.BatchModule.Cache, cmbatch, filter.FinPeriodID);

                        cmbatch.CuryID      = hist.CuryID;
                        cmbatch.CuryInfoID  = info.CuryInfoID;
                        cmbatch.DebitTotal  = 0m;
                        cmbatch.CreditTotal = 0m;
                        cmbatch.Description = filter.Description;
                        je.BatchModule.Insert(cmbatch);

                        CurrencyInfo b_info = je.currencyinfo.Select();
                        if (b_info != null)
                        {
                            b_info.CuryID         = hist.CuryID;
                            b_info.CuryEffDate    = hist.CuryEffDate;
                            b_info.CuryRateTypeID = hist.CuryRateTypeID;
                            b_info.CuryRate       = hist.CuryRate;
                            b_info.RecipRate      = hist.RateReciprocal;
                            b_info.CuryMultDiv    = hist.CuryMultDiv;
                            je.currencyinfo.Update(b_info);
                        }
                    }
                    else
                    {
                        if (!je.BatchModule.Cache.ObjectsEqual(je.BatchModule.Current, cmbatch))
                        {
                            je.Clear();
                        }

                        je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module);
                    }

                    {
                        GLTran tran = new GLTran();
                        tran.SummPost      = false;
                        tran.AccountID     = hist.AccountID;
                        tran.SubID         = hist.SubID;
                        tran.CuryDebitAmt  = 0m;
                        tran.CuryCreditAmt = 0m;

                        if (hist.AccountType == AccountType.Asset || hist.AccountType == AccountType.Expense)
                        {
                            tran.DebitAmt  = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued;
                            tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m;
                        }
                        else
                        {
                            tran.DebitAmt  = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m;
                            tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued;
                        }

                        tran.TranType  = "REV";
                        tran.TranClass = hist.AccountType;
                        tran.RefNbr    = string.Empty;
                        tran.TranDesc  = filter.Description;
                        FinPeriodIDAttribute.SetPeriodsByMaster <GLTran.finPeriodID>(je.GLTranModuleBatNbr.Cache, tran, filter.FinPeriodID);
                        tran.TranDate    = filter.CuryEffDate;
                        tran.CuryInfoID  = null;
                        tran.Released    = true;
                        tran.ReferenceID = null;
                        tran.ProjectID   = PM.ProjectDefaultAttribute.NonProject();

                        je.GLTranModuleBatNbr.Insert(tran);
                    }

                    foreach (GLTran tran in je.GLTranModuleBatNbr.SearchAll <Asc <GLTran.tranClass> >(new object[] { "G" }))
                    {
                        je.GLTranModuleBatNbr.Delete(tran);
                    }

                    {
                        GLTran tran = new GLTran();
                        tran.SummPost      = true;
                        tran.ZeroPost      = false;
                        tran.CuryDebitAmt  = 0m;
                        tran.CuryCreditAmt = 0m;

                        if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal)
                        {
                            tran.AccountID = currency.RevalGainAcctID;
                            tran.SubID     = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalGainSubID>(je, hist.BranchID, currency);
                            tran.DebitAmt  = 0m;
                            tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal);
                        }
                        else
                        {
                            tran.AccountID = currency.RevalLossAcctID;
                            tran.SubID     = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalLossSubID>(je, hist.BranchID, currency);
                            tran.DebitAmt  = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal);
                            tran.CreditAmt = 0m;
                        }

                        tran.TranType    = "REV";
                        tran.TranClass   = GLTran.tranClass.UnrealizedAndRevaluationGOL;
                        tran.RefNbr      = string.Empty;
                        tran.TranDesc    = filter.Description;
                        tran.Released    = true;
                        tran.ReferenceID = null;

                        je.GLTranModuleBatNbr.Insert(tran);
                    }

                    {
                        AcctHist accthist = new AcctHist();
                        accthist.BranchID    = hist.BranchID;
                        accthist.LedgerID    = hist.LedgerID;
                        accthist.AccountID   = hist.AccountID;
                        accthist.SubID       = hist.SubID;
                        accthist.FinPeriodID = filter.FinPeriodID;
                        accthist.CuryID      = hist.CuryID;
                        accthist.BalanceType = "A";

                        accthist = (AcctHist)basecache.Insert(accthist);
                        accthist.FinPtdRevalued += hist.FinPtdRevalued;
                    }

                    PXProcessing <RevaluedGLHistory> .SetProcessed();
                }

                if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted)
                {
                    je.Save.Press();

                    if (created.Find(je.BatchModule.Current) == null)
                    {
                        created.Add(je.BatchModule.Current);
                    }
                }

                ts.Complete();
            }

            CMSetup cmsetup = PXSelect <CMSetup> .Select(je);

            for (int i = 0; i < created.Count; i++)
            {
                if (cmsetup.AutoPostOption == true)
                {
                    pg.Clear();
                    pg.PostBatchProc(created[i]);
                }
            }

            if (hasErrors)
            {
                //Clean current to prevent set exception to the last item
                PXProcessing <RevaluedGLHistory> .SetCurrentItem(null);

                throw new PXException(ErrorMessages.SeveralItemsFailed);
            }

            if (created.Count > 0)
            {
                je.BatchModule.Current = created[created.Count - 1];
                throw new PXRedirectRequiredException(je, "Preview");
            }

            decimal val = 0m;

            foreach (RevaluedGLHistory res in GLAccountList.Cache.Updated)
            {
                if ((bool)res.Selected)
                {
                    decimal sign = AccountRules.IsDEALAccount(res.AccountType) ? 1.0m : -1.0m;
                    val += sign * (decimal)res.FinPtdRevalued;
                }
            }

            if (val == 0)
            {
                throw new PXOperationCompletedWithWarningException(Messages.NoRevaluationEntryWasMade);
            }
        }
Example #12
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);
            }
        }
        public static void Revalue(RevalueFilter filter, List <RevaluedGLHistory> list)
        {
            JournalEntry je        = PXGraph.CreateInstance <JournalEntry>();
            PostGraph    pg        = PXGraph.CreateInstance <PostGraph>();
            PXCache      cache     = je.Caches[typeof(CuryAcctHist)];
            PXCache      basecache = je.Caches[typeof(AcctHist)];

            je.Views.Caches.Add(typeof(CuryAcctHist));
            je.Views.Caches.Add(typeof(AcctHist));

            string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID;

            if (string.IsNullOrEmpty(extRefNbrNumbering) == false)
            {
                RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering);
                je.RowPersisting.AddHandler <GLTran>(helper.OnRowPersisting);
            }

            DocumentList <Batch> created = new DocumentList <Batch>(je);

            Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (RevaluedGLHistory hist in list)
                {
                    if (hist.FinPtdRevalued == 0m)
                    {
                        continue;
                    }

                    if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted)
                    {
                        je.Save.Press();

                        if (created.Find(je.BatchModule.Current) == null)
                        {
                            created.Add(je.BatchModule.Current);
                        }
                    }

                    Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch();
                    if (cmbatch.BatchNbr == null)
                    {
                        je.Clear();

                        CurrencyInfo info = new CurrencyInfo();
                        info.CuryID      = hist.CuryID;
                        info.CuryEffDate = filter.CuryEffDate;
                        info             = je.currencyinfo.Insert(info) ?? info;

                        cmbatch              = new Batch();
                        cmbatch.BranchID     = hist.BranchID;
                        cmbatch.Module       = "CM";
                        cmbatch.Status       = "U";
                        cmbatch.AutoReverse  = false;
                        cmbatch.Released     = true;
                        cmbatch.Hold         = false;
                        cmbatch.DateEntered  = filter.CuryEffDate;
                        cmbatch.FinPeriodID  = filter.FinPeriodID;
                        cmbatch.TranPeriodID = filter.FinPeriodID;
                        cmbatch.CuryID       = hist.CuryID;
                        cmbatch.CuryInfoID   = info.CuryInfoID;
                        cmbatch.DebitTotal   = 0m;
                        cmbatch.CreditTotal  = 0m;
                        cmbatch.Description  = filter.Description;
                        je.BatchModule.Insert(cmbatch);

                        CurrencyInfo b_info = je.currencyinfo.Select();
                        if (b_info != null)
                        {
                            b_info.CuryID      = hist.CuryID;
                            b_info.CuryEffDate = filter.CuryEffDate;
                            b_info.CuryRate    = 1m;
                            b_info.CuryMultDiv = "M";
                            je.currencyinfo.Update(b_info);
                        }
                    }
                    else
                    {
                        je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module);
                    }

                    {
                        GLTran tran = new GLTran();
                        tran.SummPost      = false;
                        tran.AccountID     = hist.AccountID;
                        tran.SubID         = hist.SubID;
                        tran.CuryDebitAmt  = 0m;
                        tran.CuryCreditAmt = 0m;

                        if (hist.AccountType == AccountType.Asset || hist.AccountType == AccountType.Expense)
                        {
                            tran.DebitAmt  = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued;
                            tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m;
                        }
                        else
                        {
                            tran.DebitAmt  = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m;
                            tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued;
                        }

                        tran.TranType     = "REV";
                        tran.TranClass    = hist.AccountType;
                        tran.RefNbr       = string.Empty;
                        tran.TranDesc     = string.Empty;
                        tran.TranPeriodID = filter.FinPeriodID;
                        tran.FinPeriodID  = filter.FinPeriodID;
                        tran.TranDate     = filter.CuryEffDate;
                        tran.CuryInfoID   = null;
                        tran.Released     = true;
                        tran.ReferenceID  = null;

                        je.GLTranModuleBatNbr.Insert(tran);
                    }

                    foreach (GLTran tran in je.GLTranModuleBatNbr.SearchAll <Asc <GLTran.tranClass> >(new object[] { "G" }))
                    {
                        je.GLTranModuleBatNbr.Delete(tran);
                    }

                    {
                        GLTran tran = new GLTran();
                        tran.SummPost      = true;
                        tran.CuryDebitAmt  = 0m;
                        tran.CuryCreditAmt = 0m;

                        if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal)
                        {
                            tran.AccountID = currency.RevalGainAcctID;
                            tran.SubID     = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalGainSubID>(je, hist.BranchID, currency);
                            tran.DebitAmt  = 0m;
                            tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal);
                        }
                        else
                        {
                            tran.AccountID = currency.RevalLossAcctID;
                            tran.SubID     = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalLossSubID>(je, hist.BranchID, currency);
                            tran.DebitAmt  = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal);
                            tran.CreditAmt = 0m;
                        }

                        tran.TranType    = "REV";
                        tran.TranClass   = "G";
                        tran.RefNbr      = string.Empty;
                        tran.TranDesc    = string.Empty;
                        tran.Released    = true;
                        tran.ReferenceID = null;

                        je.GLTranModuleBatNbr.Insert(tran);
                    }

                    {
                        AcctHist accthist = new AcctHist();
                        accthist.BranchID    = hist.BranchID;
                        accthist.LedgerID    = hist.LedgerID;
                        accthist.AccountID   = hist.AccountID;
                        accthist.SubID       = hist.SubID;
                        accthist.FinPeriodID = filter.FinPeriodID;
                        accthist.CuryID      = hist.CuryID;
                        accthist.BalanceType = "A";

                        accthist = (AcctHist)basecache.Insert(accthist);
                        accthist.FinPtdRevalued += hist.FinPtdRevalued;
                    }

                    {
                        CuryAcctHist accthist = new CuryAcctHist();
                        accthist.BranchID    = hist.BranchID;
                        accthist.LedgerID    = hist.LedgerID;
                        accthist.AccountID   = hist.AccountID;
                        accthist.SubID       = hist.SubID;
                        accthist.FinPeriodID = filter.FinPeriodID;
                        accthist.CuryID      = hist.CuryID;
                        accthist.BalanceType = "A";
                        accthist.BaseCuryID  = je.currencyinfo.Current.BaseCuryID;

                        accthist = (CuryAcctHist)cache.Insert(accthist);
                    }
                }

                if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted)
                {
                    je.Save.Press();

                    if (created.Find(je.BatchModule.Current) == null)
                    {
                        created.Add(je.BatchModule.Current);
                    }
                }

                ts.Complete();
            }

            CMSetup cmsetup = PXSelect <CMSetup> .Select(je);

            for (int i = 0; i < created.Count; i++)
            {
                if (cmsetup.AutoPostOption == true)
                {
                    pg.Clear();
                    pg.PostBatchProc(created[i]);
                }
            }

            if (created.Count > 0)
            {
                je.BatchModule.Current = created[created.Count - 1];
                throw new PXRedirectRequiredException(je, "Preview");
            }
        }
Example #14
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);
            }
        }
        public static void Revalue(RevalueFilter filter, List <RevaluedARHistory> list)
        {
            JournalEntry je        = PXGraph.CreateInstance <JournalEntry>();
            PostGraph    pg        = PXGraph.CreateInstance <PostGraph>();
            PXCache      cache     = je.Caches[typeof(CuryARHist)];
            PXCache      basecache = je.Caches[typeof(ARHist)];

            je.Views.Caches.Add(typeof(CuryARHist));
            je.Views.Caches.Add(typeof(ARHist));

            string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID;

            if (string.IsNullOrEmpty(extRefNbrNumbering) == false)
            {
                RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering);
                helper.Subscribe(je);
            }

            DocumentList <Batch> created = new DocumentList <Batch>(je);

            Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (RevaluedARHistory hist in list)
                {
                    if (hist.FinPtdRevalued == 0m)
                    {
                        continue;
                    }

                    if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted)
                    {
                        je.Save.Press();

                        if (created.Find(je.BatchModule.Current) == null)
                        {
                            created.Add(je.BatchModule.Current);
                        }
                    }

                    Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch();
                    if (cmbatch.BatchNbr == null)
                    {
                        je.Clear();

                        CurrencyInfo info = new CurrencyInfo();
                        info.CuryID      = hist.CuryID;
                        info.CuryEffDate = hist.CuryEffDate;
                        info.BaseCalc    = false;
                        info             = je.currencyinfo.Insert(info) ?? info;

                        cmbatch              = new Batch();
                        cmbatch.BranchID     = hist.BranchID;
                        cmbatch.Module       = "CM";
                        cmbatch.Status       = "U";
                        cmbatch.AutoReverse  = true;
                        cmbatch.Released     = true;
                        cmbatch.Hold         = false;
                        cmbatch.DateEntered  = filter.CuryEffDate;
                        cmbatch.FinPeriodID  = filter.FinPeriodID;
                        cmbatch.TranPeriodID = filter.FinPeriodID;
                        cmbatch.CuryID       = hist.CuryID;
                        cmbatch.CuryInfoID   = info.CuryInfoID;
                        cmbatch.DebitTotal   = 0m;
                        cmbatch.CreditTotal  = 0m;
                        cmbatch.Description  = filter.Description;
                        je.BatchModule.Insert(cmbatch);

                        CurrencyInfo b_info = je.currencyinfo.Select();
                        if (b_info != null)
                        {
                            b_info.CuryID         = hist.CuryID;
                            b_info.CuryEffDate    = hist.CuryEffDate;
                            b_info.CuryRateTypeID = hist.CuryRateTypeID;
                            b_info.CuryRate       = hist.CuryRate;
                            b_info.RecipRate      = hist.RateReciprocal;
                            b_info.CuryMultDiv    = hist.CuryMultDiv;
                            je.currencyinfo.Update(b_info);
                        }
                    }
                    else
                    {
                        if (!je.BatchModule.Cache.ObjectsEqual(je.BatchModule.Current, cmbatch))
                        {
                            je.Clear();
                        }

                        je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module);
                    }

                    {
                        GLTran tran = new GLTran();
                        tran.SummPost      = false;
                        tran.AccountID     = currency.ARProvAcctID ?? hist.AccountID;
                        tran.SubID         = currency.ARProvSubID ?? hist.SubID;
                        tran.CuryDebitAmt  = 0m;
                        tran.CuryCreditAmt = 0m;

                        tran.DebitAmt  = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued;
                        tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m;

                        tran.TranType     = "REV";
                        tran.TranClass    = AccountType.Asset;
                        tran.RefNbr       = string.Empty;
                        tran.TranDesc     = filter.Description;
                        tran.TranPeriodID = filter.FinPeriodID;
                        tran.FinPeriodID  = filter.FinPeriodID;
                        tran.TranDate     = filter.CuryEffDate;
                        tran.CuryInfoID   = null;
                        tran.Released     = true;
                        tran.ReferenceID  = hist.CustomerID;

                        je.GLTranModuleBatNbr.Insert(tran);
                    }

                    CustomerClass custclass = PXSelectReadonly <CustomerClass, Where <CustomerClass.customerClassID, Equal <Required <CustomerClass.customerClassID> > > > .Select(je, hist.CustomerClassID);

                    if (custclass == null)
                    {
                        custclass = new CustomerClass();
                    }

                    if (custclass.UnrealizedGainAcctID == null)
                    {
                        custclass.UnrealizedGainSubID = null;
                    }

                    if (custclass.UnrealizedLossAcctID == null)
                    {
                        custclass.UnrealizedLossSubID = null;
                    }

                    {
                        GLTran tran = new GLTran();
                        tran.SummPost      = true;
                        tran.ZeroPost      = false;
                        tran.CuryDebitAmt  = 0m;
                        tran.CuryCreditAmt = 0m;

                        if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal)
                        {
                            tran.AccountID = custclass.UnrealizedGainAcctID ?? currency.UnrealizedGainAcctID;
                            tran.SubID     = custclass.UnrealizedGainSubID ?? GainLossSubAccountMaskAttribute.GetSubID <Currency.unrealizedGainSubID>(je, hist.BranchID, currency);
                            tran.DebitAmt  = 0m;
                            tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal);
                        }
                        else
                        {
                            tran.AccountID = custclass.UnrealizedLossAcctID ?? currency.UnrealizedLossAcctID;
                            tran.SubID     = custclass.UnrealizedLossSubID ?? GainLossSubAccountMaskAttribute.GetSubID <Currency.unrealizedLossSubID>(je, hist.BranchID, currency);
                            tran.DebitAmt  = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal);
                            tran.CreditAmt = 0m;
                        }

                        tran.TranType    = "REV";
                        tran.TranClass   = GLTran.tranClass.UnrealizedAndRevaluationGOL;
                        tran.RefNbr      = string.Empty;
                        tran.TranDesc    = filter.Description;
                        tran.Released    = true;
                        tran.ReferenceID = null;

                        je.GLTranModuleBatNbr.Insert(tran);
                    }

                    {
                        CuryARHist arhist = new CuryARHist();
                        arhist.BranchID    = hist.BranchID;
                        arhist.AccountID   = hist.AccountID;
                        arhist.SubID       = hist.SubID;
                        arhist.FinPeriodID = filter.FinPeriodID;
                        arhist.CustomerID  = hist.CustomerID;
                        arhist.CuryID      = hist.CuryID;

                        arhist = (CuryARHist)cache.Insert(arhist);
                        arhist.FinPtdRevalued += hist.FinPtdRevalued;
                    }

                    {
                        ARHist arhist = new ARHist();
                        arhist.BranchID    = hist.BranchID;
                        arhist.AccountID   = hist.AccountID;
                        arhist.SubID       = hist.SubID;
                        arhist.FinPeriodID = filter.FinPeriodID;
                        arhist.CustomerID  = hist.CustomerID;

                        arhist = (ARHist)basecache.Insert(arhist);
                        arhist.FinPtdRevalued += hist.FinPtdRevalued;
                    }
                }

                if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted)
                {
                    je.Save.Press();

                    if (created.Find(je.BatchModule.Current) == null)
                    {
                        created.Add(je.BatchModule.Current);
                    }
                }

                ts.Complete();
            }

            CMSetup cmsetup = PXSelect <CMSetup> .Select(je);

            for (int i = 0; i < created.Count; i++)
            {
                if (cmsetup.AutoPostOption == true)
                {
                    pg.Clear();
                    pg.PostBatchProc(created[i]);
                }
            }

            if (created.Count > 0)
            {
                je.BatchModule.Current = created[created.Count - 1];
                throw new PXRedirectRequiredException(je, "Preview");
            }
        }
        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);
            }
        }
Example #17
0
 public static bool IsSameCury(long?CuryInfoIDA, long?CuryInfoIDB, CurrencyInfo curyInfoA, CurrencyInfo curyInfoB)
 {
     return(CuryInfoIDA == CuryInfoIDB || curyInfoA != null && curyInfoB != null && curyInfoA.CuryID == curyInfoB.CuryID);
 }