Example #1
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();
        }
Example #2
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);
                }
            }
        }