Esempio n. 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();
        }
Esempio n. 2
0
        protected virtual void Tax_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            Tax  tax           = (Tax)e.Row;
            bool AlreadyWarned = false;
            bool isDeductible  = ((Tax)e.Row).DeductibleVAT == true;

            sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, null);
            sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, null);
            sender.RaiseExceptionHandling <Tax.taxCalcLevel2Exclude>(e.Row, tax.TaxCalcLevel2Exclude, null);
            sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, null);
            sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, null);
            sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, null);
            sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, null);
            sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, null);

            CheckAndFixTaxRates(e);

            if (AlreadyWarned == false && tax.TaxType != CSTaxType.VAT && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ExemptTax == true && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.StatisticalTax == true && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }


            if (AlreadyWarned == false && tax.PendingTax == true && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType != CSTaxType.VAT && tax.PendingTax == true)
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.PendingTax == true)
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.ExemptTax == true)
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.StatisticalTax == true)
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.PendingTax == true && tax.StatisticalTax == true)
            {
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.PendingTax == true && tax.ExemptTax == true)
            {
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.StatisticalTax == true && tax.ExemptTax == true)
            {
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxCalcLevel == "0" && tax.TaxCalcLevel2Exclude == true)
            {
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcLevel2Exclude>(e.Row, tax.TaxCalcLevel2Exclude, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType == CSTaxType.Use && tax.TaxCalcLevel2Exclude == false)
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.TheseTwoOptionsShouldBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcLevel2Exclude>(e.Row, tax.TaxCalcLevel2Exclude, new PXSetPropertyException(Messages.TheseTwoOptionsShouldBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType == CSTaxType.Use && tax.TaxCalcLevel == "0")
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType == CSTaxType.Withholding && tax.TaxCalcLevel != "0")
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.TaxCalcLevel == "0")
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false)
            {
                if (((Tax)e.Row).TaxType != CSTaxType.VAT)
                {
                    sender.SetValue <Tax.purchTaxAcctID>(e.Row, null);
                    sender.SetValue <Tax.purchTaxSubID>(e.Row, null);
                    sender.SetValue <Tax.reverseTax>(e.Row, false);
                    sender.SetValue <Tax.pendingTax>(e.Row, false);
                    sender.SetValue <Tax.exemptTax>(e.Row, false);
                    sender.SetValue <Tax.statisticalTax>(e.Row, false);
                    sender.SetValue <Tax.deductibleVAT>(e.Row, false);
                }

                if (((Tax)e.Row).PendingTax != true)
                {
                    sender.SetValue <Tax.pendingSalesTaxAcctID>(e.Row, null);
                    sender.SetValue <Tax.pendingSalesTaxSubID>(e.Row, null);
                    sender.SetValue <Tax.pendingPurchTaxAcctID>(e.Row, null);
                    sender.SetValue <Tax.pendingPurchTaxSubID>(e.Row, null);
                }

                if (((Tax)e.Row).TaxType != CSTaxType.Use && !isDeductible)
                {
                    sender.SetValue <Tax.expenseAccountID>(e.Row, null);
                    sender.SetValue <Tax.expenseSubID>(e.Row, null);
                }
            }

            if (sender.ObjectsEqual <Tax.taxVendorID>(e.Row, e.OldRow) == false)
            {
                foreach (TaxRev rev in TaxRevisions.Select())
                {
                    if (((Tax)e.Row).TaxVendorID == null)
                    {
                        if (rev.TaxType == TaxType.Sales)
                        {
                            rev.TaxBucketID = -2;
                        }
                        else
                        {
                            rev.TaxBucketID = -1;
                        }
                    }
                    else
                    {
                        rev.TaxBucketID = null;
                        TaxRevisions.Cache.RaiseExceptionHandling <TaxRev.taxBucketID>(rev, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty));
                    }

                    if (TaxRevisions.Cache.GetStatus(rev) == PXEntryStatus.Notchanged)
                    {
                        TaxRevisions.Cache.SetStatus(rev, PXEntryStatus.Updated);
                    }
                }
                PopulateBucketList(e.Row);
            }
            if (!sender.ObjectsEqual <Tax.outDate>(e.Row, e.OldRow))
            {
                PXSelectBase <TaxRev> TaxRevFiltered = new PXSelect <TaxRev, Where <TaxRev.taxID, Equal <Current <Tax.taxID> >, And <TaxRev.startDate, Greater <Required <Tax.outDate> > > > >(this);
                if (tax.OutDate.HasValue && TaxRevFiltered.Select(tax.OutDate).Count > 0)
                {
                    Tax.Cache.RaiseExceptionHandling <Tax.outDate>(tax, tax.OutDate, new PXException(Messages.TaxOutDateTooEarly));
                }
                else
                {
                    sender.SetValue <Tax.outdated>(e.Row, tax.OutDate.HasValue);
                    DateTime newEndDate = tax.OutDate.HasValue ? tax.OutDate.Value : new DateTime(2079, 6, 6);
                    foreach (TaxRev rev in TaxRevisions.Select())
                    {
                        TaxRev revcopy = (TaxRev)TaxRevisions.Cache.CreateCopy(rev);
                        revcopy.EndDate = newEndDate;
                        TaxRevisions.Cache.Update(revcopy);
                    }
                }
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        private void PrepareRevisions()
        {
            Tax taxrow = (Tax)Tax.Current;

            if (Tax.Current == null)
            {
                return;
            }

            if (taxrow.OutDate != null && !(bool)taxrow.Outdated)
            {
                {
                    TaxRev rev = new TaxRev();
                    rev.StartDate = taxrow.OutDate;
                    rev.TaxType   = "S";
                    TaxRevisions.Insert(rev);
                }

                if (taxrow.TaxType == "V")
                {
                    TaxRev rev = new TaxRev();
                    rev.StartDate = taxrow.OutDate;
                    rev.TaxType   = "P";
                    TaxRevisions.Insert(rev);
                }

                taxrow.Outdated = true;
                Tax.Update(taxrow);
            }

            DateTime?lastSalesDate = null;
            DateTime?lastPurchDate = null;

            //Assumes that taxRevisions are sorted in the descending order (latest first);
            foreach (TaxRev iRev in this.TaxRevisions.Select())
            {
                if (iRev.TaxType == "S" && lastSalesDate == null ||
                    iRev.TaxType == "P" && lastPurchDate == null)
                {
                    if (taxrow.OutDate.HasValue)
                    {
                        iRev.EndDate = taxrow.OutDate.Value;
                    }
                    else
                    {
                        TaxRevisions.Cache.SetDefaultExt <TaxRev.endDate>(iRev);
                    }
                    TaxRevisions.Update(iRev);
                }

                if (((Tax)Tax.Current).OutDate != null)
                {
                    if (((DateTime)((Tax)Tax.Current).OutDate).CompareTo(iRev.StartDate) <= 0)
                    {
                        iRev.Outdated = true;
                        TaxRevisions.Update(iRev);
                    }
                }

                if (iRev.TaxType == "S")
                {
                    if (lastSalesDate != null && iRev.EndDate != lastSalesDate)
                    {
                        iRev.EndDate = lastSalesDate;
                        TaxRevisions.Update(iRev);
                    }
                    lastSalesDate = ((DateTime)iRev.StartDate).AddDays(-1);
                }
                else if (iRev.TaxType == "P")
                {
                    if (lastPurchDate != null && iRev.EndDate != lastPurchDate)
                    {
                        iRev.EndDate = lastPurchDate;
                        TaxRevisions.Update(iRev);
                    }
                    lastPurchDate = ((DateTime)iRev.StartDate).AddDays(-1);
                }
            }
        }