Пример #1
0
            private void ProcessTaxRecord(TaxHistory record, TaxReportLine taxLine, decimal?roundedTaxAmount)
            {
                PXCache taxHistoryCache = graph.Caches[typeof(TaxHistory)];

                decimal?filedAmount = record.ReportFiledAmt;
                int     lineNbr     = record.LineNbr.Value;
                int     branchID    = record.BranchID.Value;

                if (filedAmount != roundedTaxAmount)
                {
                    TaxHistory taxHistory = CreateDeltaHistory(record, roundedTaxAmount);
                    taxHistoryCache.Insert(taxHistory);
                }

                if (!linesWithRelatedAggregatesTable.ContainsKey(lineNbr))
                {
                    return;
                }

                List <int> relatedAggregateLineNumbers = linesWithRelatedAggregatesTable[lineNbr];

                foreach (int aggrLineNumber in relatedAggregateLineNumbers)
                {
                    decimal amount = (roundedTaxAmount ?? 0m) * (taxLine.LineMult ?? 0m);
                    AddTaxAmountToAggregateLine(branchID, aggrLineNumber, amount);
                }
            }
        protected virtual void TaxTran_RevisionID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            if (Document.Current.BranchID == null)
            {
                e.NewValue = null;
            }
            else
            {
                Organization organization = OrganizationMaint.FindOrganizationByID(this, PXAccess.GetParentOrganizationID(Document.Current.BranchID));
                int?[]       branchID     = organization.FileTaxesByBranches == true ? new[] { Document.Current.BranchID } : null;

                using (new PXReadBranchRestrictedScope(organization.OrganizationID.SingleToArray(), branchID, requireAccessForAllSpecified: true))
                {
                    TaxHistory max =
                        PXSelect <TaxHistory,
                                  Where <TaxHistory.vendorID, Equal <Current <TaxAdjustment.vendorID> >,
                                         And <TaxHistory.taxPeriodID, Equal <Current <TaxAdjustment.taxPeriod> > > >,
                                  OrderBy <
                                      Desc <TaxHistory.revisionID> > >
                        .Select(this);

                    e.NewValue = max != null ? max.RevisionID : 1;
                }
            }
        }
        protected virtual void TaxTran_RevisionID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            TaxHistory max = PXSelect <TaxHistory, Where
                                       <TaxHistory.vendorID, Equal <Current <TaxAdjustment.vendorID> >,
                                        And <TaxHistory.taxPeriodID, Equal <Current <TaxAdjustment.taxPeriod> > > >,
                                       OrderBy <Desc <TaxHistory.revisionID> > >
                             .Select(this);

            e.NewValue = max != null ? max.RevisionID : 1;
        }
Пример #4
0
            public void CalculateTaxBuckets(PXResultset <TaxHistory> taxLines)
            {
                if (aggregatesTable == null || linesWithRelatedAggregatesTable == null)
                {
                    return;
                }

                netHistoryByBranchID.Clear();
                roundedNetAmtByBranchID.Clear();

                foreach (PXResult <TaxHistory, TaxReportLine> rec in taxLines)
                {
                    TaxReportLine line   = rec;
                    TaxHistory    record = rec;

                    if (line.LineType != taxType || record.BranchID == null)
                    {
                        continue;
                    }

                    int branchID = record.BranchID.Value;
                    int lineNbr  = record.LineNbr.Value;

                    if (aggregatesTable.ContainsKey(lineNbr))
                    {
                        if (!netHistoryByBranchID.ContainsKey(branchID))
                        {
                            netHistoryByBranchID[branchID] = new TaxLinesWithHistoryPerBranch();
                        }

                        netHistoryByBranchID[branchID][lineNbr] = rec;
                    }
                    else
                    {
                        decimal?roundedAmount = roundingManager.Round(record.ReportFiledAmt);
                        ProcessTaxRecord(record, line, roundedAmount);
                    }
                }

                foreach (KeyValuePair <int, TaxLinesWithRoundAmountsPerBranch> branchIdWithLinesAndNetAmountsTable in roundedNetAmtByBranchID)
                {
                    TaxLinesWithHistoryPerBranch      branchTaxLinesAndHistory         = netHistoryByBranchID[branchIdWithLinesAndNetAmountsTable.Key];
                    TaxLinesWithRoundAmountsPerBranch branchTaxLinesWithRoundedAmounts = branchIdWithLinesAndNetAmountsTable.Value;
                    var aggregateLinesInBranch = aggregatesTable.Keys.Where(aggrLineNumber => branchTaxLinesAndHistory.ContainsTaxLine(aggrLineNumber));

                    foreach (int aggregateLineNumber in aggregateLinesInBranch)
                    {
                        TaxHistory    aggrLineRecord = branchTaxLinesAndHistory[aggregateLineNumber];
                        TaxReportLine aggrLine       = branchTaxLinesAndHistory[aggregateLineNumber];
                        decimal?      roundedAmount  = branchTaxLinesWithRoundedAmounts[aggregateLineNumber];

                        ProcessTaxRecord(aggrLineRecord, aggrLine, roundedAmount);
                    }
                }
            }
Пример #5
0
            private TaxHistory CreateDeltaHistory(TaxHistory original, decimal?roundedAmount)
            {
                TaxHistory delta = new TaxHistory
                {
                    BranchID       = original.BranchID,
                    VendorID       = original.VendorID,
                    CuryID         = original.CuryID,
                    TaxID          = string.Empty,
                    TaxPeriodID    = original.TaxPeriodID,
                    LineNbr        = original.LineNbr,
                    RevisionID     = original.RevisionID,
                    ReportFiledAmt = roundedAmount - original.ReportFiledAmt,
                };

                if (rateByDate == null)
                {
                    delta.FiledAmt = delta.ReportFiledAmt;
                }
                else
                {
                    if (rateByDate.CuryRate == null)
                    {
                        throw new PXException(CM.Messages.RateNotFound);
                    }

                    delta.FiledAmt = RecalcCurrency(currency, rateByDate, delta.ReportFiledAmt.GetValueOrDefault());
                }

                if (delta.ReportFiledAmt > 0)
                {
                    delta.AccountID = currency.RoundingLossAcctID;
                    delta.SubID     = GainLossSubAccountMaskAttribute.GetSubID <Currency.roundingLossSubID>(graph, delta.BranchID, currency);
                }
                else
                {
                    delta.AccountID = currency.RoundingGainAcctID;
                    delta.SubID     = GainLossSubAccountMaskAttribute.GetSubID <Currency.roundingGainSubID>(graph, delta.BranchID, currency);
                }

                if (delta.AccountID == null || delta.SubID == null)
                {
                    throw new PXException(Messages.CannotPrepareReportDefineRoundingAccounts);
                }

                return(delta);
            }
Пример #6
0
        private static decimal?SumComponentLinesAmounts(List <int> componentLinesNumbers,
                                                        Dictionary <int, PXResult <TaxReportLine, TaxHistory> > recordsByLineNumberTable)
        {
            decimal?sum = 0m;

            foreach (int line in componentLinesNumbers.Where(l => recordsByLineNumberTable.ContainsKey(l)))
            {
                PXResult <TaxReportLine, TaxHistory> currline = recordsByLineNumberTable[line];
                TaxReportLine taxLine    = (TaxReportLine)currline;
                TaxHistory    taxHistory = (TaxHistory)currline;

                if (taxHistory.ReportUnfiledAmt != null)
                {
                    sum += taxLine.LineMult * taxHistory.ReportUnfiledAmt;
                }
            }

            return(sum);
        }
Пример #7
0
        protected virtual void TaxTran_RevisionID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            if (Document.Current.BranchID == null)
            {
                e.NewValue = null;
            }
            else
            {
                using (new PXReadBranchRestrictedScope(PXAccess.GetMasterBranchID(Document.Current.BranchID).First()))
                {
                    TaxHistory max = PXSelect <TaxHistory,
                                               Where <TaxHistory.vendorID, Equal <Current <TaxAdjustment.vendorID> >,
                                                      And <TaxHistory.taxPeriodID, Equal <Current <TaxAdjustment.taxPeriod> > > >,
                                               OrderBy <Desc <TaxHistory.revisionID> > >
                                     .Select(this);

                    e.NewValue = max != null ? max.RevisionID : 1;
                }
            }
        }
Пример #8
0
        public static PXResultset <TaxReportLine, TaxHistory> GetPreviewReport(PXGraph graph, Vendor vendor,
                                                                               PXResultset <TaxReportLine, TaxHistory> records,
                                                                               Func <TaxReportLine, bool> ShowTaxReportLine = null)
        {
            if (records.Count == 0)
            {
                return(records);
            }

            const bool      calcWithZones    = true;
            int             vendorbAccountID = vendor.BAccountID.Value;
            RoundingManager rmanager         = new RoundingManager(vendor);

            Dictionary <int, List <int> > taxAggregatesDict = TaxReportMaint.AnalyseBuckets(graph,
                                                                                            vendorbAccountID,
                                                                                            TaxReportLineType.TaxAmount,
                                                                                            calcWithZones,
                                                                                            ShowTaxReportLine) ?? new Dictionary <int, List <int> >();

            Dictionary <int, List <int> > taxableAggregatesDict = TaxReportMaint.AnalyseBuckets(graph,
                                                                                                vendorbAccountID,
                                                                                                TaxReportLineType.TaxableAmount,
                                                                                                calcWithZones,
                                                                                                ShowTaxReportLine) ?? new Dictionary <int, List <int> >();

            var recordsByLineNumberTable = new Dictionary <int, PXResult <TaxReportLine, TaxHistory> >();

            foreach (PXResult <TaxReportLine, TaxHistory> record in records)
            {
                TaxReportLine taxLine    = record;
                TaxHistory    taxHistory = record;

                taxHistory.ReportUnfiledAmt = rmanager.Round(taxHistory.ReportUnfiledAmt);
                recordsByLineNumberTable[taxLine.LineNbr.Value] = record;
            }

            CalculateReportUnfiledAmtForAggregatedTaxLines(taxAggregatesDict, recordsByLineNumberTable);
            CalculateReportUnfiledAmtForAggregatedTaxLines(taxableAggregatesDict, recordsByLineNumberTable);
            return(records);
        }
Пример #9
0
        private static void CalculateReportUnfiledAmtForAggregatedTaxLines(Dictionary <int, List <int> > aggregatesTable,
                                                                           Dictionary <int, PXResult <TaxReportLine, TaxHistory> > recordsByLineNumberTable)
        {
            if (aggregatesTable == null)
            {
                return;
            }

            foreach (KeyValuePair <int, List <int> > aggregateWithLines in aggregatesTable)
            {
                int        aggregateLineNumber   = aggregateWithLines.Key;
                List <int> componentLinesNumbers = aggregateWithLines.Value;

                if (!recordsByLineNumberTable.ContainsKey(aggregateLineNumber))
                {
                    continue;
                }

                TaxHistory aggrTaxHistory = recordsByLineNumberTable[aggregateLineNumber];
                aggrTaxHistory.ReportUnfiledAmt = SumComponentLinesAmounts(componentLinesNumbers, recordsByLineNumberTable);
            }
        }