示例#1
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 override TaxDetail CalculateTaxSum(PXCache sender, object taxrow, object row)
            {
                TaxRev taxrev = PXResult.Unwrap <TaxRev>(taxrow);
                Tax    tax    = PXResult.Unwrap <Tax>(taxrow);
                bool   propagateCustomRate = false;
                var    origTaxRate         = taxrev.TaxRate;

                if (taxrev.TaxID != null && tax != null)
                {
                    SOTaxAmazonExt taxExt = tax.GetExtension <SOTaxAmazonExt>();
                    if (taxExt.UsrAMPropagateTaxAmt == true)
                    {
                        SOTaxTran soTax = PXResult <SOTaxTran> .Current;
                        if (soTax != null && taxrev.TaxID == soTax.TaxID && soTax.CuryTaxableAmt.GetValueOrDefault() > 0)
                        {
                            var taxRate = soTax.CuryTaxAmt / soTax.CuryTaxableAmt * 100;
                            if (taxRate != origTaxRate && taxRate > 0)
                            {
                                taxrev.TaxRate      = taxRate;
                                propagateCustomRate = true;
                            }
                        }
                    }
                }
                TaxDetail result = base.CalculateTaxSum(sender, taxrow, row);

                if (result != null && propagateCustomRate)
                {
                    result.TaxRate = origTaxRate;
                    taxrev.TaxRate = origTaxRate;
                }
                return(result);
            }
        protected override TaxDetail CalculateTaxSum(PXCache sender, object taxrow, object row)
        {
            TaxRev    taxrev = PXResult.Unwrap <TaxRev>(taxrow);
            Tax       tax    = PXResult.Unwrap <Tax>(taxrow);
            bool      propagateCustomRate = false;
            decimal?  origTaxRate         = taxrev.TaxRate;
            SOTaxTran soTax = PXResult <SOTaxTran> .Current;

            if (taxrev != null && taxrev.TaxID != null && tax != null)
            {
                KCTaxExt taxExt = tax.GetExtension <KCTaxExt>();
                if (taxExt.UsrKCPropagateTaxAmt == true)
                {
                    if (soTax != null && taxrev.TaxID == soTax.TaxID && soTax.CuryTaxableAmt.GetValueOrDefault() > 0)
                    {
                        decimal?taxRate = soTax.CuryTaxAmt / soTax.CuryTaxableAmt * 100;
                        if (taxRate != origTaxRate && taxRate > 0)
                        {
                            taxrev.TaxRate      = taxRate;
                            propagateCustomRate = true;
                        }
                    }
                }
            }

            bool compositeExists = false;

            foreach (var line in sender.Inserted)
            {
                ARTran tran = (ARTran)line;
                KCSOInvoiceEntryExt graphKCExt = sender.Graph.GetExtension <KCSOInvoiceEntryExt>();
                InventoryItem       product    = graphKCExt.KCInventoryItem.SelectSingle(tran.InventoryID);
                if (product == null)
                {
                    continue;
                }
                InventoryItemPCExt productPCExt = product.GetExtension <InventoryItemPCExt>();
                if (productPCExt == null)
                {
                    continue;
                }

                if (productPCExt.UsrKNCompositeType != null)
                {
                    compositeExists  = true;
                    tran.CuryTranAmt = 0;
                    tran.TranAmt     = 0;
                }
            }

            TaxDetail result = base.CalculateTaxSum(sender, taxrow, row);

            if ((compositeExists || result == null) && PXResult <SOOrder> .Current != null && soTax != null)
            {
                if (result != null)
                {
                    result = null;
                }
                bool?isFromCA = ((SOOrder)PXResult <SOOrder> .Current).GetExtension <KCSOOrderExt>().UsrKCSiteName?.EndsWith("FBA");
                if (isFromCA.GetValueOrDefault())
                {
                    decimal?taxableAmount = 0;
                    foreach (ARTran tran in sender.Inserted)
                    {
                        if (tran.LineType == KCConstants.LineTypeGI ||
                            tran.LineType == KCConstants.LineTypeGN)
                        {
                            taxableAmount += tran.TranAmt;
                        }
                    }
                    if (soTax.CuryTaxableAmt != soTax.TaxableAmt && soTax.CuryTaxableAmt == 0)
                    {
                        soTax.CuryTaxableAmt = soTax.TaxableAmt;
                    }
                    decimal?taxAmount = soTax.TaxAmt * taxableAmount / soTax.CuryTaxableAmt;

                    result = (TaxDetail)((PXResult)taxrow)[0];
                    PXCache pxcache2 = sender.Graph.Caches[this._TaxSumType];
                    pxcache2.SetValue(result, this._CuryOrigTaxableAmt, soTax.CuryTaxableAmt);
                    pxcache2.SetValue(result, this._CuryTaxableAmt, taxableAmount);
                    pxcache2.SetValue(result, this._CuryTaxAmt, taxAmount);
                }
            }

            if (propagateCustomRate && result != null)
            {
                result.TaxRate = origTaxRate;
            }
            return(result);
        }
            public Decimal CalcTaxableFromTotalAmount(PXCache cache, object row, string aTaxZoneID, string aTaxCategoryID, DateTime aDocDate, Decimal aCuryTotal)
            {
                Decimal           result  = Decimal.Zero;
                PXGraph           graph   = cache.Graph;
                List <TaxZoneDet> taxList = GetApplicableTaxList(graph, aTaxZoneID, aTaxCategoryID, aDocDate);
                Dictionary <string, PXResult <Tax, TaxRev> > taxRates = GetTaxRevisionList(graph, aDocDate);
                List <PXResult <Tax, TaxRev> > orderedTaxList         = new List <PXResult <Tax, TaxRev> >(taxList.Count);

                foreach (TaxZoneDet iDet in taxList)
                {
                    PXResult <Tax, TaxRev> line;
                    if (taxRates.TryGetValue(iDet.TaxID, out line))
                    {
                        int idx;
                        for (idx = orderedTaxList.Count;
                             (idx > 0) &&
                             String.Compare(((Tax)orderedTaxList[idx - 1]).TaxCalcLevel, ((Tax)line).TaxCalcLevel) > 0;
                             idx--)
                        {
                            ;
                        }
                        orderedTaxList.Insert(idx, new PXResult <Tax, TaxRev>(line, line));
                    }
                }
                Decimal rateInclusive = Decimal.Zero;
                Decimal rateLvl1      = Decimal.Zero;
                Decimal rateLvl2      = Decimal.Zero;

                foreach (PXResult <Tax, TaxRev> iRes in orderedTaxList)
                {
                    Tax     tax        = iRes;
                    TaxRev  taxRev     = iRes;
                    Decimal multiplier = tax.ReverseTax == true ? Decimal.MinusOne : Decimal.One;
                    switch (tax.TaxCalcLevel)
                    {
                    case CSTaxCalcLevel.Inclusive:
                        rateInclusive += multiplier * taxRev.TaxRate.Value;
                        break;

                    case CSTaxCalcLevel.CalcOnItemAmt:
                        rateLvl1 += multiplier * taxRev.TaxRate.Value;
                        break;

                    case CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt:
                        rateLvl2 += multiplier * taxRev.TaxRate.Value;
                        break;
                    }
                }

                decimal baseLvl2      = PXDBCurrencyAttribute.RoundCury(cache, row, aCuryTotal / (1 + rateLvl2 / 100));
                decimal baseLvl1      = PXDBCurrencyAttribute.RoundCury(cache, row, baseLvl2 / (1 + (rateLvl1 + rateInclusive) / 100));
                Decimal curyTaxTotal  = decimal.Zero;
                Decimal curyTax2Total = decimal.Zero;

                foreach (PXResult <Tax, TaxRev> iRes in orderedTaxList)
                {
                    Tax     tax        = iRes;
                    TaxRev  taxRev     = iRes;
                    Decimal multiplier = tax.ReverseTax == true ? Decimal.MinusOne : Decimal.One;
                    switch (tax.TaxCalcLevel)
                    {
                    case CSTaxCalcLevel.Inclusive:
                        break;

                    case CSTaxCalcLevel.CalcOnItemAmt:
                        curyTaxTotal += multiplier * PXDBCurrencyAttribute.RoundCury(cache, row, (baseLvl1 * taxRev.TaxRate / 100m) ?? 0m);
                        break;

                    case CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt:
                        curyTax2Total += multiplier * PXDBCurrencyAttribute.RoundCury(cache, row, (baseLvl2 * taxRev.TaxRate / 100m) ?? 0m);
                        break;
                    }
                }
                result = aCuryTotal - curyTaxTotal - curyTax2Total;
                return(result);
            }
示例#5
0
 /// <summary>
 /// Fill aggregated tax detail for per unit tax. Do nothing for retained tax.
 /// </summary>
 protected override TaxDetail FillAggregatedTaxDetailForPerUnitTax(PXCache rowCache, object row, Tax tax, TaxRev taxRevision,
                                                                   TaxDetail aggrTaxDetail, List <object> taxItems)
 {
     return(aggrTaxDetail);
 }
示例#6
0
 /// <summary>
 /// Fill tax details for line for per unit taxes. Do nothing for retained tax.
 /// </summary>
 protected override void TaxSetLineDefaultForPerUnitTaxes(PXCache rowCache, object row, Tax tax, TaxRev taxRevision, TaxDetail taxDetail)
 {
 }