Exemple #1
0
		protected virtual void Tax_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
		{
			TaxDetail taxSum = e.Row as TaxDetail;
			TaxDetail taxSumOld = e.OldRow as TaxDetail;

			if (e.ExternalCall && IsTaxRowAmountUpdated(sender, e))
			{
				PXCache parentCache = ParentCache(sender.Graph);

				if (parentCache.Current != null)
				{
					decimal discrepancy = CalculateTaxDiscrepancy(parentCache, parentCache.Current);
					decimal discrepancyBase;
					PXDBCurrencyAttribute.CuryConvBase(ParentCache(sender.Graph), ParentRow(sender.Graph), discrepancy, out discrepancyBase);
					ParentSetValue(sender.Graph, _CuryTaxRoundDiff, discrepancy);
					ParentSetValue(sender.Graph, _TaxRoundDiff, discrepancyBase);
				}
			}

			if ((_TaxCalc != TaxCalc.NoCalc && e.ExternalCall || _TaxCalc == TaxCalc.ManualCalc))
			{
				if (e.OldRow != null && e.Row != null)
				{
					if (taxSumOld.TaxID != taxSum.TaxID)
					{
						VerifyTaxID(sender, e.Row, e.ExternalCall);
					}
					if (IsTaxRowAmountUpdated(sender, e))
					{
						CalcTotals(sender.Graph.Caches[_ChildType], null, false);
					}
				}
			}
		}
Exemple #2
0
        protected override TaxDetail CalculateTaxSum(PXCache sender, object taxrow, object row)
        {
            if (isManualVAT(sender))
            {
                PXCache sumcache = sender.Graph.Caches[_TaxSumType];
                string  taxzone  = GetTaxZone(sender, null);
                TaxZone zone     = PXSelect <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <TaxZone.taxZoneID> > > > .SelectWindowed(sender.Graph, 0, 1, taxzone);

                TaxDetail taxdet = (TaxDetail)((PXResult)taxrow)[0];
                TaxDetail taxSum = null;
                if (zone.TaxID == taxdet.TaxID)
                {
                    taxSum = DefaultSimplifiedVAT(sender, row, zone, taxdet);
                }
                return(taxSum);
            }

            return(base.CalculateTaxSum(sender, taxrow, row));
        }
Exemple #3
0
		protected decimal CalculateTaxDiscrepancy(PXCache sender, object row)
		{
			decimal discrepancy = 0m;
			SelectTaxes(sender, row, PXTaxCheck.RecalcTotals).
				FindAll(taxrow =>
				{
					Tax tax = (Tax)((PXResult)taxrow)[1];
					return tax.TaxCalcLevel == CSTaxCalcLevel.Inclusive;
				}).
				ForEach(taxrow =>
				{
					TaxDetail taxdet = (TaxDetail)((PXResult)taxrow)[0];
					TaxDetail taxSum = CalculateTaxSum(sender, taxrow, row);
					if (taxSum != null)
					{
						PXCache sumcache = sender.Graph.Caches[_TaxSumType];
						discrepancy += (decimal)sumcache.GetValue(taxdet, _CuryTaxAmt) + taxdet.CuryExpenseAmt.Value - (decimal)sumcache.GetValue(taxSum, _CuryTaxAmt) - taxSum.CuryExpenseAmt.Value;
					}
				});
			return discrepancy;
		}
Exemple #4
0
		protected virtual void Tax_CuryTaxableAmt_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
		{
			TaxDetail taxdetOrig = e.Row as TaxDetail;
			if (taxdetOrig == null) return;

			decimal newValue = (decimal)(sender.GetValue(e.Row, _CuryTaxableAmt) ?? 0m);
			decimal oldValue = (decimal)(e.OldValue ?? 0m);

			if (_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.TaxID))
				{
					TaxDetail taxdet = (TaxDetail)((PXResult)taxrow)[0];
					Tax tax = PXResult.Unwrap<Tax>(taxrow);
					TaxRev taxrev = PXResult.Unwrap<TaxRev>(taxrow);

					CalculateTaxSumTaxAmt(sender, taxdet, tax, taxrev);
				}
			}
		}
Exemple #5
0
        protected override void DefaultTaxes(PXCache sender, object row, bool DefaultExisting)
        {
            if (isManualVAT(sender))
            {
                string  taxzone = GetTaxZone(sender, null);
                TaxZone zone    = PXSelect <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <TaxZone.taxZoneID> > > > .SelectWindowed(sender.Graph, 0, 1, taxzone);

                //it is possible to brake this by overriding ManualTaxes - consider changing
                if (!ManualTaxes(sender, row).Any(det => det.TaxID == zone.TaxID))
                {
                    TaxDetail newdet = (TaxDetail)Activator.CreateInstance(_TaxSumType);
                    newdet = DefaultSimplifiedVAT(sender, row, zone, newdet);
                    if (newdet != null)
                    {
                        PXCache sumCache = sender.Graph.Caches[_TaxSumType];
                        Insert(sumCache, newdet);
                    }
                }
                return;
            }

            base.DefaultTaxes(sender, row, DefaultExisting);
        }
Exemple #6
0
        protected TaxDetail DefaultSimplifiedVAT(PXCache sender, object row, TaxZone zone, TaxDetail newdet)
        {
            PXCache cache             = sender.Graph.Caches[_TaxSumType];
            decimal?docCuryTaxAmt     = (decimal?)ParentGetValue(sender.Graph, _DocCuryTaxAmt) ?? 0m;
            decimal?docCuryOrigDocAmt = (decimal?)ParentGetValue(sender.Graph, _CuryOrigDocAmt) ?? 0m;

            if (docCuryTaxAmt == 0m)
            {
                return(null);
            }
            newdet.TaxID = zone.TaxID;
            if (docCuryOrigDocAmt - docCuryTaxAmt != 0)
            {
                newdet.TaxRate = (docCuryTaxAmt / (docCuryOrigDocAmt - docCuryTaxAmt)) * 100m;
            }
            else
            {
                newdet.TaxRate = 0m;
            }
            newdet.NonDeductibleTaxRate = 0m;
            cache.SetValue(newdet, _CuryTaxableAmt, Math.Abs(docCuryOrigDocAmt.Value) > Math.Abs(docCuryTaxAmt.Value) ? docCuryOrigDocAmt - docCuryTaxAmt : 0m);
            cache.SetValue(newdet, _CuryTaxAmt, docCuryTaxAmt);
            newdet.CuryExpenseAmt = 0m;
            return(newdet);
        }
Exemple #7
0
        public virtual decimal GetPerUnitTaxAmountForTaxableAdjustmentCalculation(Tax taxForTaxableAdustment, TaxDetail taxDetail, PXCache taxDetailCache,
                                                                                  object row, PXCache rowCache, string curyTaxAmtFieldName,
                                                                                  Func <List <object> > perUnitTaxSelector)
        {
            taxForTaxableAdustment.ThrowOnNull(nameof(taxForTaxableAdustment));
            taxDetail.ThrowOnNull(nameof(taxDetail));
            taxDetailCache.ThrowOnNull(nameof(taxDetailCache));
            row.ThrowOnNull(nameof(row));
            rowCache.ThrowOnNull(nameof(rowCache));
            curyTaxAmtFieldName.ThrowOnNullOrWhiteSpace(nameof(curyTaxAmtFieldName));
            perUnitTaxSelector.ThrowOnNull(nameof(perUnitTaxSelector));

            if (taxForTaxableAdustment.TaxType == CSTaxType.PerUnit)
            {
                return(0m);
            }

            Type          taxAmountField  = taxDetailCache.GetBqlField(curyTaxAmtFieldName);
            List <object> allPerUnitTaxes = perUnitTaxSelector?.Invoke();

            if (allPerUnitTaxes == null || allPerUnitTaxes.Count == 0)
            {
                return(0m);
            }

            var(perUnitInclusiveTaxes, perUnitLevel1Taxes) = GetNonExcludedPerUnitTaxesByCalculationLevel(allPerUnitTaxes);

            if (perUnitInclusiveTaxes.Count == 0 && perUnitLevel1Taxes.Count == 0)
            {
                return(0m);
            }

            switch (taxForTaxableAdustment.TaxCalcLevel)
            {
            case CSTaxCalcLevel.Inclusive when perUnitLevel1Taxes.Count > 0:
                PXTrace.WriteInformation(Messages.CombinationOfExclusivePerUnitTaxAndInclusveTaxIsForbiddenErrorMsg);
                throw new PXSetPropertyException(Messages.CombinationOfExclusivePerUnitTaxAndInclusveTaxIsForbiddenErrorMsg, PXErrorLevel.Error);

            case CSTaxCalcLevel.Inclusive:
                //The adjustment to taxable is amount of all per unit taxes. The level 1 per unit taxes are prohibited.
                return(SumTaxAmountsWithReverseAdjustment(taxDetailCache.Graph, perUnitInclusiveTaxes, taxAmountField));

            case CSTaxCalcLevel.CalcOnItemAmt:
                var allNonExcludedPerUnitTaxes = perUnitInclusiveTaxes.Concat(perUnitLevel1Taxes);
                return(SumTaxAmountsWithReverseAdjustment(taxDetailCache.Graph, allNonExcludedPerUnitTaxes, taxAmountField));

            case CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt:
                // For level 2 taxes:
                // Taxable = LineAmt - InclusiveTaxAmt (including per unit inclusive taxes) + Level 1 Taxes amount (including per unit level 1 taxes)
                // Therefore, we need to add only the previously subtracted amount of inclusive per unit taxes
                return(SumTaxAmountsWithReverseAdjustment(taxDetailCache.Graph, perUnitInclusiveTaxes, taxAmountField));

            default:
                return(0m);
            }
        }