Esempio n. 1
0
 public static void CheckReportSettingsEditable(PXGraph graph, int?vendorID)
 {
     if (TaxYearMaint.PrepearedTaxPeriodForVendorExists(graph, vendorID))
     {
         throw new PXException(Messages.TheTaxReportSettingsCannotBeModified);
     }
 }
        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;
            }
        }
Esempio n. 4
0
        public static void CheckReportSettingsEditableAndSetWarningTo <TVendorIDField>(PXGraph graph, PXCache cache, object row, int?vendorID)
            where TVendorIDField : IBqlField
        {
            if (TaxYearMaint.PrepearedTaxPeriodForVendorExists(graph, vendorID))
            {
                var bAccIDfieldState = (PXFieldState)cache.GetStateExt <TVendorIDField>(row);

                cache.RaiseExceptionHandling <TVendorIDField>(row, bAccIDfieldState.Value,
                                                              new PXSetPropertyException(Messages.TheTaxReportSettingsCannotBeModified, PXErrorLevel.Warning));
            }
        }
Esempio n. 5
0
        public static void UpdateTaxHistorySums(PXGraph graph, RoundingManager rmanager, string taxPeriodId, int?revisionId, int?organizationID, int?branchID, Func <TaxReportLine, bool> ShowTaxReportLine = null)
        {
            if (!rmanager.IsRequireRounding)
            {
                return;
            }

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

            using (new PXReadBranchRestrictedScope(organizationID.SingleToArray(), branchID.SingleToArrayOrNull(), requireAccessForAllSpecified: true))
            {
                PXResultset <TaxHistory> lines = GetTaxHistoryLines(graph, rmanager.CurrentVendor.BAccountID, taxPeriodId, revisionId);

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

                if (organizationID == null)
                {
                    Branch branch = PXSelect <Branch, Where <Branch.branchID, Equal <Required <Branch.branchID> > > > .SelectSingleBound(graph, null, branchID);

                    organizationID = branch?.OrganizationID;
                }

                TaxPeriod period = TaxYearMaint.GetTaxPeriodByKey(graph, organizationID, 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);
        }
        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);
        }
        private void ValidateDocDate(PXCache cache, TaxAdjustment doc)
        {
            if (doc.DocDate == null || doc.TaxPeriod == null || doc.BranchID == null)
            {
                return;
            }

            var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this,
                                                            PXAccess.GetParentOrganizationID(doc.BranchID),
                                                            doc.VendorID,
                                                            doc.TaxPeriod);

            if (taxPeriod == null)
            {
                return;
            }

            string errorMessage = null;

            if (vendor.Current.TaxReportFinPeriod == true)
            {
                var finPeriod = FinPeriodRepository.GetByID(doc.FinPeriodID, PXAccess.GetParentOrganizationID(doc.BranchID));

                if (finPeriod.FinDate >= taxPeriod.EndDate)
                {
                    errorMessage = Messages.SelectedDateBelongsToTheTaxPeriodThatIsGreaterThanTheSpecifiedOne;
                }
            }
            else if (doc.DocDate >= taxPeriod.EndDate)
            {
                errorMessage = Messages.SelectedDateBelongsToTheTaxPeriodThatIsGreaterThanTheSpecifiedOne;
            }

            var ex = errorMessage != null
                                ? new PXSetPropertyException(errorMessage, PXErrorLevel.Warning)
                                : null;

            cache.RaiseExceptionHandling <TaxAdjustment.docDate>(doc, doc.DocDate, ex);
        }
Esempio n. 8
0
        private void SetDocDateByPeriods(PXCache cache, TaxAdjustment document)
        {
            if (document.TaxPeriod == null || document.BranchID == null)
            {
                return;
            }

            int masterbranchID = PXAccess.GetMasterBranchID(document.BranchID).First();

            var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this,
                                                            masterbranchID,
                                                            document.VendorID,
                                                            document.TaxPeriod);

            if (taxPeriod == null)
            {
                return;
            }

            DateTime?docDate;

            if (vendor.Current.TaxReportFinPeriod == true)
            {
                var finPeriod = FinPeriodIDAttribute.FindMaxFinPeriodWithEndDataBelongToInterval(this, taxPeriod.StartDate,
                                                                                                 taxPeriod.EndDate);

                docDate = finPeriod != null
                                        ? finPeriod.FinDate
                                        : Accessinfo.BusinessDate;
            }
            else
            {
                docDate = taxPeriod.EndDateUI;
            }

            cache.SetValueExt <TaxAdjustment.docDate>(document, docDate);
        }
Esempio n. 9
0
 public TaxPeriod GetTaxPeriodByKey(int?branchID, int?taxAgencyID, string taxPeriodID)
 {
     return(TaxYearMaint.GetTaxPeriodByKey(_graph, branchID, taxAgencyID, taxPeriodID));
 }
Esempio n. 10
0
        protected virtual void baseTaxPeriodFilterRowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            VATPeriodFilter filter = (VATPeriodFilter)e.Row;

            if (filter == null)
            {
                return;
            }

            if (!sender.ObjectsEqual <VATPeriodFilter.organizationID, VATPeriodFilter.branchID>(e.Row, e.OldRow))
            {
                List <PXView> views = this.Views.Select(view => view.Value).ToList();
                foreach (var view in views)
                {
                    view.Clear();
                }
            }

            if (!sender.ObjectsEqual <VATPeriodFilter.organizationID>(e.Row, e.OldRow) ||
                !sender.ObjectsEqual <VATPeriodFilter.branchID>(e.Row, e.OldRow) ||
                !sender.ObjectsEqual <VATPeriodFilter.vendorID>(e.Row, e.OldRow))
            {
                if (filter.OrganizationID != null && filter.VendorID != null)
                {
                    PX.Objects.TX.TaxPeriod taxper = TaxYearMaint.FindPreparedPeriod(this, filter.OrganizationID, filter.VendorID);

                    if (taxper != null)
                    {
                        filter.TaxPeriodID = taxper.TaxPeriodID;
                    }
                    else
                    {
                        taxper             = TaxYearMaint.FindLastClosedPeriod(this, filter.OrganizationID, filter.VendorID);
                        filter.TaxPeriodID = taxper != null ? taxper.TaxPeriodID : null;
                    }
                }
                else
                {
                    filter.TaxPeriodID = null;
                }
            }

            Organization organization = OrganizationMaint.FindOrganizationByID(this, filter.OrganizationID);

            if (!sender.ObjectsEqual <VATPeriodFilter.organizationID>(e.Row, e.OldRow) ||
                !sender.ObjectsEqual <VATPeriodFilter.branchID>(e.Row, e.OldRow) ||
                !sender.ObjectsEqual <VATPeriodFilter.vendorID>(e.Row, e.OldRow) ||
                !sender.ObjectsEqual <VATPeriodFilter.taxPeriodID>(e.Row, e.OldRow) ||
                filter.RevisionId == null)
            {
                if (filter.OrganizationID != null &&
                    (filter.BranchID != null && organization.FileTaxesByBranches == true || organization.FileTaxesByBranches != true) &&
                    filter.VendorID != null && filter.TaxPeriodID != null)
                {
                    filter.RevisionId = ReportTaxProcess.CurrentRevisionId(this, filter.OrganizationID, filter.BranchID, filter.VendorID, filter.TaxPeriodID);
                }
                else
                {
                    filter.RevisionId = null;
                }
            }
        }