protected virtual void TaxTotal_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            TaxTotal taxSum    = sender.GetExtension <TaxTotal>(e.Row);
            TaxTotal taxSumOld = sender.GetExtension <TaxTotal>(e.OldRow);

            if (e.ExternalCall && (!TaxTotals.Cache.ObjectsEqual <TaxTotal.curyTaxAmt>(taxSum, taxSumOld) || !TaxTotals.Cache.ObjectsEqual <TaxTotal.curyExpenseAmt>(taxSum, taxSumOld)))
            {
                PXCache parentCache = Documents.Cache;

                if (parentCache.Current != null)
                {
                    decimal discrepancy = CalculateTaxDiscrepancy(parentCache.Current);
                    decimal discrepancyBase;
                    PXDBCurrencyAttribute.CuryConvBase(parentCache, CurrentDocument, discrepancy, out discrepancyBase);
                    ParentSetValue <Document.curyTaxRoundDiff>(discrepancy);
                    ParentSetValue <Document.taxRoundDiff>(discrepancyBase);
                }
            }

            if ((CurrentDocument.TaxCalc != TaxCalc.NoCalc && e.ExternalCall || CurrentDocument.TaxCalc == TaxCalc.ManualCalc))
            {
                if (e.OldRow != null && e.Row != null)
                {
                    if (taxSumOld.RefTaxID != taxSum.RefTaxID)
                    {
                        VerifyTaxID(taxSum, e.ExternalCall);
                    }
                    if (!TaxTotals.Cache.ObjectsEqual <TaxTotal.curyTaxAmt>(taxSum, taxSumOld) || !TaxTotals.Cache.ObjectsEqual <TaxTotal.curyExpenseAmt>(taxSum, taxSumOld))
                    {
                        CalcTotals(null, false);
                    }
                }
            }
        }
        protected virtual void VerifyTaxID(TaxTotal row, bool externalCall)
        {
            bool nomatch = false;

            //TODO: move details to parameter

            foreach (Detail det in Details.Select())
            {
                ITaxDetail taxzonedet = MatchesCategory(det, (TaxItem)row);
                AddOneTax(det, taxzonedet);
            }
            object originalRow = TaxTotals.Cache.GetMain(row);

            _NoSumTotals      = (CurrentDocument.TaxCalc == TaxCalc.ManualCalc && row.TaxRate != 0m && externalCall == false);
            PXRowDeleting del = delegate(PXCache _sender, PXRowDeletingEventArgs _e) { nomatch |= ReferenceEquals(originalRow, _e.Row); };

            Base.RowDeleting.AddHandler(originalRow.GetType(), del);
            try
            {
                CalcTaxes(null);
            }
            finally
            {
                Base.RowDeleting.RemoveHandler(originalRow.GetType(), del);
            }
            _NoSumTotals = false;

            if (nomatch)
            {
                TaxTotals.Cache.RaiseExceptionHandling <TaxTotal.refTaxID>(row, row.RefTaxID,
                                                                           new PXSetPropertyException(Messages.NoLinesMatchTax, PXErrorLevel.RowError));
            }
            TaxTotals.Cache.Current = row;
        }
Exemple #3
0
        protected virtual void TaxTotal_CuryTaxableAmt_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            TaxTotal taxdetOrig = sender.GetExtension <TaxTotal>(e.Row);

            if (taxdetOrig == null)
            {
                return;
            }

            decimal newValue = (decimal)(sender.GetValue(e.Row, typeof(TaxTotal.curyTaxableAmt).Name) ?? 0m);
            decimal oldValue = (decimal)(e.OldValue ?? 0m);

            if (CurrentDocument.TaxCalc != TaxCalc.NoCalc && e.ExternalCall &&
                newValue != oldValue)
            {
                foreach (object taxrow in SelectTaxes <
                             Where <Tax.taxID, Equal <Required <Tax.taxID> > > >(sender.Graph, null, PXTaxCheck.RecalcTotals, taxdetOrig.RefTaxID))
                {
                    TaxTotal taxdet = sender.GetExtension <TaxTotal>(((PXResult)taxrow)[0]);
                    Tax      tax    = PXResult.Unwrap <Tax>(taxrow);
                    TaxRev   taxrev = PXResult.Unwrap <TaxRev>(taxrow);

                    CalculateTaxSumTaxAmt(taxdet, tax, taxrev);
                }
            }
        }
        protected virtual void TaxTotal_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            TaxTotal taxSum = sender.GetExtension <TaxTotal>(e.Row);

            if ((CurrentDocument.TaxCalc != TaxCalc.NoCalc && e.ExternalCall || CurrentDocument.TaxCalc == TaxCalc.ManualCalc))
            {
                VerifyTaxID(taxSum, e.ExternalCall);
            }
        }
        protected override IEnumerable <ITaxDetail> ManualTaxes(Detail row)
        {
            List <ITaxDetail> ret = new List <ITaxDetail>();

            foreach (PXResult res in SelectTaxes(row, PXTaxCheck.RecalcTotals))
            {
                TaxTotal item = TaxTotals.Cache.GetExtension <TaxTotal>(res[0]);
                ret.Add((TaxItem)item);
            }
            return(ret);
        }
 protected virtual void TaxTotal_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
 {
     if ((CurrentDocument.TaxCalc != TaxCalc.NoCalc && e.ExternalCall || CurrentDocument.TaxCalc == TaxCalc.ManualCalc))
     {
         TaxTotal row = sender.GetExtension <TaxTotal>(e.Row);
         foreach (Detail det in Details.Select())
         {
             DelOneTax(det, row.RefTaxID);
         }
         CalcTaxes(null);
     }
 }
        protected decimal CalculateTaxDiscrepancy(object row)
        {
            decimal discrepancy = 0m;

            SelectTaxes(row, PXTaxCheck.RecalcTotals).
            FindAll(taxrow =>
            {
                Tax tax = (Tax)((PXResult)taxrow)[1];
                return(tax.TaxCalcLevel == CSTaxCalcLevel.Inclusive);
            }).
            ForEach(taxrow =>
            {
                TaxDetail taxdet = Taxes.Cache.GetExtension <TaxDetail>(((PXResult)taxrow)[0]);
                TaxTotal taxSum  = CalculateTaxSum(taxrow, row);
                if (taxSum != null)
                {
                    PXCache sumcache = TaxTotals.Cache;
                    discrepancy     += taxdet.CuryTaxAmt.Value + taxdet.CuryExpenseAmt.Value - taxSum.CuryTaxAmt.Value - taxSum.CuryExpenseAmt.Value;
                }
            });
            return(discrepancy);
        }