Exemplo n.º 1
0
        protected bool isManualVAT(PXCache sender)
        {
            string  taxzone = GetTaxZone(sender, null);
            TaxZone zone    = PXSelect <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <TaxZone.taxZoneID> > > > .SelectWindowed(sender.Graph, 0, 1, taxzone);

            return(zone != null && zone.IsManualVATZone == true && PXAccess.FeatureInstalled <FeaturesSet.manualVATEntryMode>());
        }
Exemplo n.º 2
0
		public static decimal CalcResidualAmt(PXCache cache, object row, string aTaxZoneID, string aTaxCategoryID, DateTime aDocDate,
			string TaxCalcMode, decimal ControlTotalAmt, decimal LinesTotal, decimal TaxTotal)
		{
			decimal taxableAmount = 0.0m;
			TaxZone zone = PXSelect<TaxZone, Where<TaxZone.taxZoneID, Equal<Required<TaxZone.taxZoneID>>>>.SelectWindowed(cache.Graph, 0, 1, aTaxZoneID);
			if (PXAccess.FeatureInstalled<FeaturesSet.manualVATEntryMode>() && zone != null && zone.IsManualVATZone == true)
			{
				taxableAmount = ControlTotalAmt - LinesTotal - TaxTotal;
			}
			else
			{
				switch (TaxCalcMode)
				{
					case TaxCalculationMode.Gross:
						taxableAmount = TaxAttribute.CalcTaxableFromTotalAmount(cache, row, aTaxZoneID,
							aTaxCategoryID, aDocDate, ControlTotalAmt - LinesTotal, false, GLTaxAttribute.TaxCalcLevelEnforcing.EnforceInclusive);
						break;
					case TaxCalculationMode.Net:
						taxableAmount = TaxAttribute.CalcTaxableFromTotalAmount(cache, row, aTaxZoneID,
							aTaxCategoryID, aDocDate, ControlTotalAmt - LinesTotal - TaxTotal, false, GLTaxAttribute.TaxCalcLevelEnforcing.EnforceCalcOnItemAmount);
						break;
					case TaxCalculationMode.TaxSetting:
						//disabled for now
						//taxableAmount = TaxAttribute.CalcTaxableFromTotalAmount(cache, row, aTaxZoneID,
						//	aTaxCategoryID, aDocDate, ControlTotalAmt - LinesTotal, false, GLTaxAttribute.TaxCalcLevelEnforcing.None);
						break;
				}
			}
			return taxableAmount;
		}
Exemplo n.º 3
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);
        }
        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());
        }
Exemplo n.º 5
0
        protected virtual void TaxPlugin_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            TaxPlugin row = e.Row as TaxPlugin;

            if (row == null)
            {
                return;
            }

            TaxZone shipVia = PXSelect <TaxZone, Where <TaxZone.taxZoneID, Equal <Current <TaxPlugin.taxPluginID> > > > .SelectWindowed(this, 0, 1);

            if (shipVia != null)
            {
                throw new PXException(Messages.TaxZoneFK);
            }
        }
Exemplo n.º 6
0
        protected override void ZoneUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            if (PXAccess.FeatureInstalled <FeaturesSet.manualVATEntryMode>())
            {
                TaxZone newTaxZone = PXSelect <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <TaxZone.taxZoneID> > > > .Select(sender.Graph, (string)sender.GetValue(e.Row, _TaxZoneID));

                if (newTaxZone != null && newTaxZone.IsManualVATZone == true)
                {
                    ReDefaultTaxes(sender, null, null);
                    _ParentRow = e.Row;
                    CalcTaxes(sender, null);
                    _ParentRow = null;
                    return;
                }
            }
            base.ZoneUpdated(sender, e);
        }
Exemplo n.º 7
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));
        }
        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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public static void Process(TaxImportProcess graph, TXImportState item)
        {
            TaxBuilder.Result result = TaxBuilderEngine.Execute(graph, item.StateCode);

            List <Tax> taxes;
            List <KeyValuePair <Tax, List <TaxRev> > > revisions;
            List <TaxZone>        zones;
            List <TaxZoneDet>     zoneDetails;
            List <TaxCategoryDet> categoryDetails;
            List <TaxZoneZip>     zoneZips;

            Translate(graph, item, result, out taxes, out revisions, out zones, out zoneDetails, out categoryDetails, out zoneZips);

            //Save to TX module:

            foreach (TaxZone zone in zones)
            {
                TaxZone existing = PXSelect <TaxZone, Where <TaxZone.taxZoneID, Equal <Required <TaxZone.taxZoneID> > > > .Select(graph, zone.TaxZoneID);

                if (existing == null)
                {
                    graph.TaxZones.Insert(zone);
                }

                PXSelectBase <TaxZoneZip> selectZips = new PXSelect <TaxZoneZip, Where <TaxZoneZip.taxZoneID, Equal <Required <TaxZoneZip.taxZoneID> > > >(graph);
                foreach (TaxZoneZip z in selectZips.Select(zone.TaxZoneID))
                {
                    graph.TaxZoneZip.Delete(z);
                }
            }

            foreach (TaxZoneZip zip in zoneZips)
            {
                graph.TaxZoneZip.Insert(zip);
            }

            foreach (Tax tax in taxes)
            {
                Tax existing = PXSelect <Tax, Where <Tax.taxID, Equal <Required <Tax.taxID> > > > .Select(graph, tax.TaxID);

                if (existing == null)
                {
                    graph.Taxes.Insert(tax);
                }
            }

            foreach (KeyValuePair <Tax, List <TaxRev> > kv in revisions)
            {
                PXResultset <TaxRev> existingRevisions = PXSelect <TaxRev, Where <TaxRev.taxID, Equal <Required <TaxRev.taxID> > > > .Select(graph, kv.Key.TaxID);


                if (existingRevisions.Count == 0)
                {
                    foreach (TaxRev revision in kv.Value)
                    {
                        graph.Revisions.Insert(revision);
                    }
                }
                else
                {
                    foreach (TaxRev revision in kv.Value)
                    {
                        bool skip = false;
                        foreach (TaxRev existing in existingRevisions)
                        {
                            if (graph.Revisions.Cache.ObjectsEqual <TaxRev.startDate, TaxRev.endDate, TaxRev.taxRate>(revision, existing))
                            {
                                skip = true;
                                break;
                            }
                        }

                        if (!skip)
                        {
                            graph.Revisions.Insert(revision);
                        }
                    }
                }
            }

            foreach (TaxCategoryDet category in categoryDetails)
            {
                TaxCategoryDet existing = PXSelect <TaxCategoryDet, Where <TaxCategoryDet.taxID, Equal <Required <TaxCategoryDet.taxID> >,
                                                                           And <TaxCategoryDet.taxCategoryID, Equal <Required <TaxCategoryDet.taxCategoryID> > > > > .Select(graph, category.TaxID, category.TaxCategoryID);

                if (existing == null)
                {
                    graph.TaxCategoryDetails.Insert(category);
                }
            }

            foreach (TaxZoneDet zd in zoneDetails)
            {
                TaxZoneDet existing = PXSelect <TaxZoneDet, Where <TaxZoneDet.taxID, Equal <Required <TaxZoneDet.taxID> >,
                                                                   And <TaxZoneDet.taxZoneID, Equal <Required <TaxZoneDet.taxZoneID> > > > > .Select(graph, zd.TaxID, zd.TaxZoneID);

                if (existing == null)
                {
                    graph.TaxZoneDetails.Insert(zd);
                }
            }

            graph.Actions.PressSave();
        }
Exemplo n.º 11
0
        private static void Translate(TaxImportProcess graph, TXImportState item, TaxBuilder.Result result, out List <Tax> taxes,
                                      out List <KeyValuePair <Tax, List <TaxRev> > > revisions, out List <TaxZone> zones, out List <TaxZoneDet> zoneDetails, out List <TaxCategoryDet> categoryDetails, out List <TaxZoneZip> zoneZips)
        {
            taxes           = new List <Tax>(result.Taxes.Count);
            revisions       = new List <KeyValuePair <Tax, List <TaxRev> > >(result.Taxes.Count);
            zones           = new List <TaxZone>(result.Zones.Count);
            zoneDetails     = new List <TaxZoneDet>(result.ZoneDetails.Count);
            categoryDetails = new List <TaxCategoryDet>(result.Taxes.Count * 2);
            zoneZips        = new List <TaxZoneZip>(result.ZoneZips.Count);

            TXImportSettings settings = PXSetup <TXImportSettings> .Select(graph);

            if (string.IsNullOrEmpty(settings.TaxableCategoryID))
            {
                throw new PXException(Messages.TaxableCategoryIDIsNotSet);
            }

            foreach (ZoneRecord zr in result.Zones)
            {
                TaxZone taxZone = new TaxZone();
                taxZone.TaxZoneID = zr.ZoneID;
                taxZone.Descr     = zr.Description;

                if (zr.CombinedRate > 0)
                {
                    taxZone.DfltTaxCategoryID = settings.TaxableCategoryID;
                }

                taxZone.IsImported = true;
                zones.Add(taxZone);
            }

            foreach (TaxRecord tr in result.Taxes)
            {
                Tax tax = new Tax();
                tax.TaxID          = tr.TaxID;
                tax.TaxType        = CSTaxType.Sales;
                tax.Descr          = tr.Description;
                tax.IsImported     = true;
                tax.SalesTaxAcctID = item.AccountID;
                tax.SalesTaxSubID  = item.SubID;
                tax.TaxCalcType    = CSTaxCalcType.Doc;
                tax.TaxCalcLevel   = CSTaxCalcLevel.CalcOnItemAmt;
                taxes.Add(tax);

                revisions.Add(new KeyValuePair <Tax, List <TaxRev> >(tax, GetRevisions(tr)));
                categoryDetails.AddRange(GetCategories(graph, settings, tr));
            }

            foreach (ZoneDetailRecord zd in result.ZoneDetails)
            {
                TaxZoneDet zoneDetail = new TaxZoneDet();
                zoneDetail.TaxID      = zd.TaxID;
                zoneDetail.TaxZoneID  = zd.ZoneID;
                zoneDetail.IsImported = true;
                zoneDetails.Add(zoneDetail);
            }

            foreach (IList <ZoneZipPlusRecord> zr in result.ZoneZipPlus.Values)
            {
                foreach (ZoneZipPlusRecord zzp in zr)
                {
                    TaxZoneZip tzzp = new TaxZoneZip();
                    tzzp.TaxZoneID = zzp.ZoneID;
                    tzzp.ZipCode   = zzp.ZipCode;
                    tzzp.ZipMin    = zzp.ZipMin;
                    tzzp.ZipMax    = zzp.ZipMax;

                    zoneZips.Add(tzzp);
                }
            }
        }