예제 #1
0
        /// <summary>
        /// Generates a child tax lines for missing zones.
        /// </summary>
        /// <param name="templateLinesByLineNumber">The template lines by line number.</param>
        /// <param name="zonesInSystem">The zones in system.</param>
        /// <param name="detailLinesByTemplateLineNumber">The detail lines by template line number.</param>
        /// <returns>
        /// The generated child tax lines for missing zones.
        /// </returns>
        private List <TaxReportLine> GenerateChildTaxLinesForMissingZones(Dictionary <int, TaxReportLine> templateLinesByLineNumber,
                                                                          Dictionary <string, TaxZone> zonesInSystem,
                                                                          ILookup <int, TaxReportLine> detailLinesByTemplateLineNumber)
        {
            Dictionary <int, List <string> > missingZonesByTemplateLineNumber =
                templateLinesByLineNumber.ToDictionary(templatePair => templatePair.Key,
                                                       templatePair => zonesInSystem.Select(zone => zone.Value.TaxZoneID)
                                                       .Except(detailLinesByTemplateLineNumber[templatePair.Key].Select(line => line.TaxZoneID))
                                                       .ToList());

            List <TaxReportLine> addedLines = new List <TaxReportLine>(capacity: 8);

            foreach (KeyValuePair <int, List <string> > templateNumberWithMissingZones in missingZonesByTemplateLineNumber)
            {
                TaxReportLine template = templateLinesByLineNumber[templateNumberWithMissingZones.Key];

                foreach (string missingZoneId in templateNumberWithMissingZones.Value)
                {
                    TaxReportLine child    = taxReportGraph.CreateChildLine(template, zonesInSystem[missingZoneId]);
                    TaxReportLine inserted = taxReportGraph.ReportLine.Cache.Insert(child) as TaxReportLine;

                    addedLines.Add(inserted);
                }
            }

            return(addedLines);
        }
예제 #2
0
        protected virtual void TaxReportLine_SortOrder_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            VendorMaster  taxVendor    = TaxVendor.Current;
            TaxReportLine reportLine   = (TaxReportLine)e.Row;
            int?          newSortOrder = e.NewValue as int?;

            if (reportLine == null || reportLine.TempLineNbr != null || taxVendor == null || taxVendor.ShowNoTemp == true ||
                reportLine.SortOrder == newSortOrder)
            {
                return;
            }

            if (newSortOrder == null || newSortOrder <= 0)
            {
                string errorMsg = newSortOrder == null
                                        ? Common.Messages.MustHaveValue
                                        : Common.Messages.ShouldBePositive;

                throw new PXSetPropertyException(errorMsg, nameof(TaxReportLine.SortOrder));
            }

            bool alreadyExists = ReportLine.Select()
                                 .RowCast <TaxReportLine>()
                                 .Any(line => line.SortOrder.Value == newSortOrder);

            if (alreadyExists)
            {
                throw new PXSetPropertyException(Messages.SortOrderNumbersMustBeUnique);
            }
        }
예제 #3
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);
                }
            }
예제 #4
0
        protected virtual void TaxReportLine_SortOrder_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            TaxReportLine reportLine = (TaxReportLine)e.Row;

            if (reportLine == null || reportLine.TempLineNbr != null || Equals(reportLine.SortOrder, e.OldValue))
            {
                return;
            }

            if (reportLine.TempLine == true)
            {
                var childTaxLines =
                    PXSelect <TaxReportLine,
                              Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                     And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > >
                    .Select(this, reportLine.VendorID, reportLine.LineNbr);

                foreach (TaxReportLine childLine in childTaxLines)
                {
                    childLine.SortOrder = reportLine.SortOrder;
                    ReportLine.Cache.SmartSetStatus(childLine, PXEntryStatus.Updated);
                }
            }

            ReportLine.View.RequestRefresh();
        }
예제 #5
0
        protected virtual void TaxReportLine_NetTax_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            TaxReportLine line = (TaxReportLine)e.Row;

            if (e.NewValue != null && (bool)e.NewValue && line.LineType == "A")
            {
                throw new PXSetPropertyException(Messages.NetTaxMustBeTax, PXErrorLevel.RowError);
            }
        }
        public virtual IEnumerable UpdateTaxZoneLines(PXAdapter adapter)
        {
            var vendor = TaxVendor.Current;

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

            var templateLines = PXSelect <TaxReportLine,
                                          Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                                 And <TaxReportLine.tempLine, Equal <True> > > > .Select(this, vendor.BAccountID).RowCast <TaxReportLine>();

            if (templateLines.Any() == false)
            {
                throw new PXException(Messages.NoLinesByTaxZone);
            }

            bool addedSome = false;

            var zoneLines = PXSelect <TaxReportLine,
                                      Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                             And <TaxReportLine.tempLineNbr, IsNotNull> > > .Select(this, vendor.BAccountID).RowCast <TaxReportLine>();

            var zones = PXSelect <TaxZone> .Select(this).RowCast <TaxZone>();

            var missingZones = templateLines.ToDictionary(
                template => template,
                template => zones
                .Select(zone => zone.TaxZoneID)
                .Except(zoneLines
                        .Where(line => line.TempLineNbr == template.LineNbr)
                        .Select(line => line.TaxZoneID)
                        .Distinct())
                .ToList <string>());

            foreach (var kvp in missingZones)
            {
                TaxReportLine template = kvp.Key;
                foreach (var zoneId in kvp.Value)
                {
                    TaxZone taxZone = zones.Single(zone => zone.TaxZoneID == zoneId);
                    var     child   = CreateChildLine(template, taxZone);
                    ReportLine.Cache.Insert(child);

                    addedSome = true;
                }
            }

            if (addedSome == false)
            {
                throw new PXException(Messages.NoNewZonesLoaded);
            }

            return(adapter.Get());
        }
예제 #7
0
        protected virtual void TaxReportLine_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            TaxReportLine line = e.Row as TaxReportLine;

            if (line == null)
            {
                return;
            }
            PXUIFieldAttribute.SetEnabled <TaxReportLine.reportLineNbr>(sender, line, line.HideReportLine != true);
        }
예제 #8
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);
                    }
                }
            }
예제 #9
0
        private void DeleteChildTaxLinesForMainTaxLine(TaxReportLine mainLine)
        {
            var childTaxLines =
                PXSelect <TaxReportLine,
                          Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                 And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > >
                .Select(this, mainLine.VendorID, mainLine.LineNbr);

            foreach (TaxReportLine child in childTaxLines)
            {
                ReportLine.Cache.Delete(child);
            }
        }
예제 #10
0
        protected virtual void TaxReportLine_HideReportLine_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            TaxReportLine line = e.Row as TaxReportLine;

            if (line == null)
            {
                return;
            }
            if (line.HideReportLine == true)
            {
                sender.SetValueExt <TaxReportLine.reportLineNbr>(line, null);
            }
        }
예제 #11
0
        protected virtual void TaxBucketLine_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            var bucketLine = (TaxBucketLine)e.Row;

            var reportLine = new TaxReportLine()
            {
                VendorID = bucketLine.VendorID,
                LineNbr  = bucketLine.LineNbr
            };

            reportLine = (TaxReportLine)ReportLineView.Cache.Locate(reportLine);

            if (reportLine?.TempLineNbr == null)            //it is parent line
            {
                CheckUnique(cache, bucketLine);
            }
        }
        protected override void OnRowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            TaxReportLine insertedLine = e.Row as TaxReportLine;
            VendorMaster  vendorMaster = taxReportGraph.TaxVendor.Current;

            if (vendorMaster == null || insertedLine == null || insertedLine.SortOrder != null)
            {
                return;
            }

            List <TaxReportLine> taxLines = Select().RowCast <TaxReportLine>()
                                            .Where(line => line.SortOrder.HasValue)
                                            .ToList();

            insertedLine.SortOrder = taxLines.Count > 0
                                ? taxLines.Max(line => line.SortOrder) + 1
                                : insertedLine.LineNbr;
        }
        private void MoveRowByArrow(bool moveUp)
        {
            TaxReportLine currentLine = Current;

            if (!AllowDragDrop || currentLine == null)
            {
                return;
            }

            var lines = Select().RowCast <TaxReportLine>()
                        .Where(line => !Cache.ObjectsEqual(line, currentLine));

            TaxReportLine nextLine;

            if (moveUp)
            {
                nextLine = lines.Where(line => line.SortOrder < currentLine.SortOrder)
                           .OrderByDescending(line => line.SortOrder)
                           .FirstOrDefault();
            }
            else
            {
                nextLine = lines.Where(line => line.SortOrder > currentLine.SortOrder)
                           .OrderBy(line => line.SortOrder)
                           .FirstOrDefault();
            }

            if (nextLine == null)
            {
                return;
            }

            int?tempVar = nextLine.SortOrder;

            nextLine.SortOrder    = currentLine.SortOrder;
            currentLine.SortOrder = tempVar;

            Cache.SmartSetStatus(currentLine, PXEntryStatus.Updated);
            Cache.SmartSetStatus(nextLine, PXEntryStatus.Updated);

            RenumberDetailTaxLines(new TaxReportLine[] { }, new[] { currentLine, nextLine });
            Cache.IsDirty = true;
        }
예제 #14
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);
        }
        private TaxReportLine CreateChildLine(TaxReportLine template, TaxZone zone)
        {
            TaxReportLine child = PXCache <TaxReportLine> .CreateCopy(template);

            child.TempLineNbr   = child.LineNbr;
            child.TaxZoneID     = zone.TaxZoneID;
            child.LineNbr       = null;
            child.TempLine      = false;
            child.ReportLineNbr = null;

            if (string.IsNullOrEmpty(child.Descr) == false)
            {
                int fid;
                if ((fid = child.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase)) >= 0)
                {
                    child.Descr = child.Descr.Remove(fid, TAG_TAXZONE.Length).Insert(fid, child.TaxZoneID);
                }
            }

            return(child);
        }
예제 #16
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);
        }
예제 #17
0
        private void UpdateZones(PXCache sender, TaxReportLine oldRow, TaxReportLine newRow)
        {
            if (oldRow != null && (newRow == null || newRow.TempLine == false))
            {
                if (!string.IsNullOrEmpty(newRow?.Descr))
                {
                    int fid = newRow.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase);

                    if (fid >= 0)
                    {
                        newRow.Descr = newRow.Descr.Remove(fid, TAG_TAXZONE.Length).TrimEnd(' ');
                    }
                }

                DeleteChildTaxLinesForMainTaxLine(oldRow);
            }

            if (newRow?.TempLine == true && newRow.TempLine != oldRow?.TempLine)
            {
                newRow.TaxZoneID = null;

                if (string.IsNullOrEmpty(newRow.Descr) || newRow.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase) < 0)
                {
                    newRow.Descr += ' ' + TAG_TAXZONE;
                }

                foreach (TaxZone zone in PXSelect <TaxZone> .Select(this))
                {
                    TaxReportLine child = CreateChildLine(newRow, zone);
                    sender.Insert(child);
                }
            }

            if (newRow?.TempLine == true && oldRow?.TempLine == true)
            {
                UpdateTaxLineOnFieldUpdatedWhenDetailByTaxZoneNotChanged(sender, oldRow, newRow);
            }
        }
예제 #18
0
        private void UpdateNet(object row)
        {
            bool          refreshNeeded = false;
            TaxReportLine currow        = row as TaxReportLine;

            if (currow.NetTax.Value && currow.TempLineNbr == null)
            {
                foreach (TaxReportLine reportrow in PXSelect <TaxReportLine, Where <TaxReportLine.vendorID, Equal <Required <VendorMaster.bAccountID> > > > .Select(this, currow.VendorID))
                {
                    if (reportrow.NetTax.Value && reportrow.LineNbr != currow.LineNbr && reportrow.TempLineNbr != currow.LineNbr)
                    {
                        reportrow.NetTax = false;
                        ReportLine.Cache.Update(reportrow);
                        refreshNeeded = true;
                    }
                }
            }

            if (refreshNeeded)
            {
                ReportLine.View.RequestRefresh();
            }
        }
예제 #19
0
        private void UpdateZones(PXCache sender, object OldRow, object NewRow)
        {
            if (OldRow != null && (NewRow == null || (bool)((TaxReportLine)NewRow).TempLine == false))
            {
                foreach (TaxReportLine child in PXSelect <TaxReportLine, Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >, And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > > .Select(this, ((TaxReportLine)OldRow).VendorID, ((TaxReportLine)OldRow).LineNbr))
                {
                    sender.Delete(child);
                }
            }

            if (NewRow != null && (bool)((TaxReportLine)NewRow).TempLine == true && (OldRow == null || ((TaxReportLine)NewRow).TempLine != ((TaxReportLine)OldRow).TempLine))
            {
                ((TaxReportLine)NewRow).TaxZoneID = null;

                if (string.IsNullOrEmpty(((TaxReportLine)NewRow).Descr) || ((TaxReportLine)NewRow).Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase) < 0)
                {
                    ((TaxReportLine)NewRow).Descr += ' ' + TAG_TAXZONE;
                }

                foreach (TaxZone zone in PXSelect <TaxZone> .Select(this))
                {
                    TaxReportLine child = PXCache <TaxReportLine> .CreateCopy((TaxReportLine)NewRow);

                    child.TempLineNbr = child.LineNbr;
                    child.TaxZoneID   = zone.TaxZoneID;

                    if (string.IsNullOrEmpty(child.Descr) == false)
                    {
                        int fid;
                        if ((fid = child.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase)) >= 0)
                        {
                            child.Descr = child.Descr.Remove(fid, TAG_TAXZONE.Length).Insert(fid, child.TaxZoneID);
                        }
                    }

                    child.LineNbr  = null;
                    child.TempLine = false;
                    sender.Insert(child);
                }
            }

            if (NewRow != null && OldRow != null && ((TaxReportLine)NewRow).TempLine == ((TaxReportLine)OldRow).TempLine == true)
            {
                foreach (TaxReportLine child in PXSelect <TaxReportLine, Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >, And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > > .Select(this, ((TaxReportLine)OldRow).VendorID, ((TaxReportLine)OldRow).LineNbr))
                {
                    child.Descr = ((TaxReportLine)NewRow).Descr;

                    if (string.IsNullOrEmpty(child.Descr) == false)
                    {
                        int fid;
                        if ((fid = child.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase)) >= 0)
                        {
                            child.Descr = child.Descr.Remove(fid, TAG_TAXZONE.Length).Insert(fid, child.TaxZoneID);
                        }
                    }

                    child.NetTax   = ((TaxReportLine)NewRow).NetTax;
                    child.LineType = ((TaxReportLine)NewRow).LineType;
                    child.LineMult = ((TaxReportLine)NewRow).LineMult;
                    sender.Update(child);
                }
            }
        }
예제 #20
0
            private void calcOccurances(bool CalcWithZones)
            {
                if (!CalcWithZones)
                {
                    _vendorBucketLines.WhereAnd <Where <TaxReportLine.tempLineNbr, IsNull> >();
                }
                PXResultset <TaxBucketLine> BucketLineTaxAmt = _vendorBucketLines.Select(_bAccountID, _taxLineType);

                if (BucketLineTaxAmt == null)
                {
                    _bucketsDict = null;
                    return;
                }
                _bucketsDict = new Dictionary <int, List <int> >();
                foreach (PXResult <TaxBucketLine> bucketLineSet in BucketLineTaxAmt)
                {
                    TaxBucketLine bucketLine = (TaxBucketLine)bucketLineSet[typeof(TaxBucketLine)];
                    TaxReportLine reportLine = (TaxReportLine)bucketLineSet[typeof(TaxReportLine)];
                    if (bucketLine.BucketID != null && reportLine.LineNbr != null)
                    {
                        if (!_bucketsDict.ContainsKey((int)bucketLine.BucketID))
                        {
                            _bucketsDict[(int)bucketLine.BucketID] = new List <int>();
                        }
                        _bucketsDict[(int)bucketLine.BucketID].Add((int)bucketLine.LineNbr);
                    }
                }
                List <int> bucketsList = _bucketsDict.Keys.ToList <int>();

                for (int i = 0; i < bucketsList.Count; i++)
                {
                    for (int j = i + 1; j < bucketsList.Count; j++)
                    {
                        if (_bucketsDict[bucketsList[i]].Count == _bucketsDict[bucketsList[j]].Count &&
                            IsSubList(_bucketsDict[bucketsList[i]], _bucketsDict[bucketsList[j]]))
                        {
                            _bucketsDict.Remove(bucketsList[i]);
                            break;
                        }
                    }
                }
                _bucketLinesOccurence = new Dictionary <int, int>();
                _bucketsLinesPairs    = new Dictionary <int, Dictionary <int, int> >();
                foreach (KeyValuePair <int, List <int> > kvp in _bucketsDict)
                {
                    foreach (int lineNbr in kvp.Value)
                    {
                        if (!_bucketLinesOccurence.ContainsKey(lineNbr))
                        {
                            _bucketLinesOccurence[lineNbr] = 0;
                        }
                        _bucketLinesOccurence[lineNbr]++;
                    }
                    for (int i = 0; i < kvp.Value.Count - 1; i++)
                    {
                        for (int j = i + 1; j < kvp.Value.Count; j++)
                        {
                            int key;
                            int value;
                            if (kvp.Value[i] < kvp.Value[j])
                            {
                                key   = kvp.Value[i];
                                value = kvp.Value[j];
                            }
                            else
                            {
                                key   = kvp.Value[j];
                                value = kvp.Value[i];
                            }
                            if (!_bucketsLinesPairs.ContainsKey(key))
                            {
                                _bucketsLinesPairs[key] = new Dictionary <int, int>();
                            }
                            if (!_bucketsLinesPairs[key].ContainsKey(value))
                            {
                                _bucketsLinesPairs[key][value] = 0;
                            }
                            _bucketsLinesPairs[key][value]++;
                        }
                    }
                }
            }
예제 #21
0
        private void UpdateTaxLineOnFieldUpdatedWhenDetailByTaxZoneNotChanged(PXCache sender, TaxReportLine oldRow, TaxReportLine newRow)
        {
            var childTaxLines =
                PXSelect <TaxReportLine,
                          Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                 And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > >
                .Select(this, oldRow.VendorID, oldRow.LineNbr);

            foreach (TaxReportLine child in childTaxLines)
            {
                child.Descr = newRow.Descr;

                if (!string.IsNullOrEmpty(child.Descr))
                {
                    int fid = child.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase);

                    if (fid >= 0)
                    {
                        child.Descr = child.Descr.Remove(fid, TAG_TAXZONE.Length)
                                      .Insert(fid, child.TaxZoneID);
                    }
                }

                child.NetTax    = newRow.NetTax;
                child.LineType  = newRow.LineType;
                child.LineMult  = newRow.LineMult;
                child.SortOrder = newRow.SortOrder;
                sender.Update(child);
            }
        }
        protected override void PasteLines(TaxReportLine focus, IList <TaxReportLine> moved)
        {
            if (!Cache.AllowUpdate || focus?.SortOrder == null || moved.Count == 0)
            {
                return;
            }

            int insertPos    = focus.SortOrder.Value;
            int firstLinePos = moved.Min(line => line.SortOrder.Value);

            if (insertPos == firstLinePos)
            {
                return;
            }

            int firstTaxLinesSetDivisionPoint, secondTaxLinesSetDivisionPoint;

            if (insertPos > firstLinePos)               //Dragging down
            {
                firstTaxLinesSetDivisionPoint  = firstLinePos;
                secondTaxLinesSetDivisionPoint = insertPos;
            }
            else                                        //Dragging up
            {
                firstTaxLinesSetDivisionPoint = insertPos;

                //Sort order of the last of moved line. Is necessary to handle holes in selection during between lines list filling
                secondTaxLinesSetDivisionPoint = moved.Max(line => line.SortOrder.Value);
            }

            HashSet <int> movedLineNumbers = moved.Select(line => line.LineNbr.Value).ToHashSet();

            List <TaxReportLine> betweenLines = new List <TaxReportLine>();
            List <TaxReportLine> movedLines   = new List <TaxReportLine>(capacity: moved.Count);
            List <TaxReportLine> restLines    = new List <TaxReportLine>();

            foreach (TaxReportLine line in Select())
            {
                bool lineIsMoved = movedLineNumbers.Contains(line.LineNbr.Value);

                if (lineIsMoved)
                {
                    movedLines.Add(line);
                }
                else if (line.SortOrder >= firstTaxLinesSetDivisionPoint)
                {
                    if (Cache.InsertPositionMode)
                    {
                        if (line.SortOrder <= secondTaxLinesSetDivisionPoint)
                        {
                            betweenLines.Add(line);
                        }
                        else
                        {
                            restLines.Add(line);
                        }
                    }
                    else
                    {
                        if (line.SortOrder < secondTaxLinesSetDivisionPoint)
                        {
                            betweenLines.Add(line);
                        }
                        else
                        {
                            restLines.Add(line);
                        }
                    }
                }
            }

            ReEnumerateOnPasteLines(betweenLines, movedLines, restLines, firstLinePos, insertPos);

            View.Clear();               //clears stored cache so that grid lines are reordered.
        }
        private void UpdateZones(PXCache sender, object OldRow, object NewRow)
        {
            TaxReportLine oldRow = OldRow as TaxReportLine;
            TaxReportLine newRow = NewRow as TaxReportLine;

            if (oldRow != null && (newRow == null || newRow.TempLine == false))
            {
                if (string.IsNullOrEmpty(newRow?.Descr) == false)
                {
                    int fid;
                    if ((fid = newRow.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase)) >= 0)
                    {
                        newRow.Descr = newRow.Descr.Remove(fid, TAG_TAXZONE.Length).TrimEnd(' ');
                    }
                }

                foreach (TaxReportLine child in PXSelect <TaxReportLine,
                                                          Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                                                 And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > >
                         .Select(this, oldRow.VendorID, oldRow.LineNbr))
                {
                    sender.Delete(child);
                }
            }

            if (newRow?.TempLine == true && newRow.TempLine != oldRow?.TempLine)
            {
                newRow.TaxZoneID = null;

                if (string.IsNullOrEmpty(newRow.Descr) ||
                    (newRow.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase) < 0))
                {
                    newRow.Descr += ' ' + TAG_TAXZONE;
                }

                foreach (TaxZone zone in PXSelect <TaxZone> .Select(this))
                {
                    TaxReportLine child = CreateChildLine(newRow, zone);
                    sender.Insert(child);
                }
            }

            if (newRow?.TempLine == true && oldRow?.TempLine == true)
            {
                foreach (TaxReportLine child in PXSelect <TaxReportLine,
                                                          Where <TaxReportLine.vendorID, Equal <Required <TaxReportLine.vendorID> >,
                                                                 And <TaxReportLine.tempLineNbr, Equal <Required <TaxReportLine.tempLineNbr> > > > >
                         .Select(this, oldRow.VendorID, oldRow.LineNbr))
                {
                    child.Descr = newRow.Descr;

                    if (string.IsNullOrEmpty(child.Descr) == false)
                    {
                        int fid;
                        if ((fid = child.Descr.IndexOf(TAG_TAXZONE, StringComparison.OrdinalIgnoreCase)) >= 0)
                        {
                            child.Descr = child.Descr.Remove(fid, TAG_TAXZONE.Length).Insert(fid, child.TaxZoneID);
                        }
                    }

                    child.NetTax   = newRow.NetTax;
                    child.LineType = newRow.LineType;
                    child.LineMult = newRow.LineMult;
                    sender.Update(child);
                }
            }
        }