public virtual IEnumerable Generate(PXAdapter adapter)
        {
            var gafPeriod = GAFPeriodView.Current;

            Branch branch = BranchMaint.FindBranchByID(this, gafPeriod.BranchID);

            var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this, branch.ParentBranchID, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID);

            if (taxPeriod == null)
            {
                return(adapter.Get());
            }

            var chekingResult = _gafValidator.CheckGAFGenerationRequirements(gafPeriod.BranchID, taxPeriod);

            if (!chekingResult.IsSuccess)
            {
                throw new PXException(chekingResult.GetGeneralMessage());
            }

            if (chekingResult.HasWarning)
            {
                if (GAFPeriodView.Ask(chekingResult.GetGeneralMessage(), MessageButtons.OKCancel) != WebDialogResult.OK)
                {
                    return(adapter.Get());
                }
            }

            PXLongOperation.StartOperation(this, () => GenerateProc(gafPeriod));

            return(adapter.Get());
        }
        protected virtual void GAFPeriod_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            var gafPeriod = (GAFPeriod)e.Row;

            if (gafPeriod == null)
            {
                return;
            }

            if (gafPeriod.TaxPeriodID != null)
            {
                Branch branch = BranchMaint.FindBranchByID(this, gafPeriod.BranchID);

                var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this, branch.ParentBranchID, gafPeriod.TaxAgencyID,
                                                                gafPeriod.TaxPeriodID);

                if (taxPeriod == null)
                {
                    return;
                }

                gafPeriod.StartDate = taxPeriod.StartDate;
                gafPeriod.EndDateUI = taxPeriod.EndDateUI;
            }
            else
            {
                gafPeriod.StartDate = null;
                gafPeriod.EndDateUI = null;
            }
        }
        public static void UpdateTaxHistorySums(PXGraph graph, RoundingManager rmanager, string taxPeriodId, int?revisionId, int?branchID, Func <TaxReportLine, bool> ShowTaxReportLine = null)
        {
            if (!rmanager.IsRequireRounding)
            {
                return;
            }

            PXCache cache = graph.Caches[typeof(TaxHistory)];

            using (new PXReadBranchRestrictedScope(branchID))
            {
                PXResultset <TaxHistory> lines = GetTaxHistoryLines(graph, rmanager.CurrentVendor.BAccountID, taxPeriodId, revisionId);

                if (lines.Count == 0)
                {
                    return;
                }

                Branch branch = BranchMaint.FindBranchByID(graph, branchID);

                TaxPeriod period = TaxYearMaint.GetTaxPeriodByKey(graph, branch.ParentBranchID, rmanager.CurrentVendor.BAccountID,
                                                                  taxPeriodId);

                Company company = PXSelect <Company> .Select(graph);

                PXResult <Currency, CurrencyRateByDate> curyWithRateSet = GetCurrencyAndRateByDate(graph, rmanager.CurrentVendor, company, period);
                Currency           currency   = curyWithRateSet;
                CurrencyRateByDate rateByDate = currency.CuryID != company.BaseCuryID ? curyWithRateSet : null;

                TaxBucketsCalculation taxBucketsAggregatesCalc =
                    new TaxBucketsCalculation(TaxReportLineType.TaxAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine);

                TaxBucketsCalculation taxableBucketsAggregatesCalc =
                    new TaxBucketsCalculation(TaxReportLineType.TaxableAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine);

                taxBucketsAggregatesCalc.CalculateTaxBuckets(lines);
                taxableBucketsAggregatesCalc.CalculateTaxBuckets(lines);
            }

            cache.Persist(PXDBOperation.Insert);
            cache.Persisted(isAborted: false);
        }