Getting the rate of a Tax Code

Hi,

I'm using the .NET SDK and I cannot find anywhere the actual rate of a taxCode, is this property available at all?

Thanks,

Ignacio

  • I solved my problem

    It seems that the .net does not support this, I had to use the COM API

    Horrible code but it works, so far there is no other way

    This is the code, if anybody need to use it


    using Interop.PeachwServer;

    private Dictionary<string, double> ImportTaxes()
    {
    var taxCodes = new Dictionary<string, double>();
    Interop.PeachwServer.Login login = new Interop.PeachwServer.Login();
    Interop.PeachwServer.Application app;
    app = (Interop.PeachwServer.Application)login.GetApplication("Peachtree Software", "9E5643PCU118X6C");

    var file = System.IO.Path.GetTempFileName();
    var exporter = (Export)app.CreateExporter(PeachwIEObj.peachwIEObjSalesTaxCodes);
    exporter.AddToExportFieldList((short)PeachwIEObjSalesTaxCodesField.peachwIEObjSalesTaxCodesField_SalesTaxCodeId);
    exporter.AddToExportFieldList((short)PeachwIEObjSalesTaxCodesField.peachwIEObjSalesTaxCodesField_TaxRate);
    exporter.SetFilename(file);
    exporter.SetFileType(PeachwIEFileType.peachwIEFileTypeCSV);
    try
    {
    exporter.Export();
    }
    catch (Exception ee)
    {
    Logger.Log(ee);
    }

    using (var reader = new StreamReader(file))
    {
    string line;
    while ((line = reader.ReadLine()) != null)
    {
    var parts = line.Split(new char[] { ',' });
    if (parts.Length == 2)
    if (!taxCodes.ContainsKey(parts[0]))
    taxCodes.Add(parts[0], Convert.ToDouble(parts[1]));
    }
    }
    return taxCodes;
    }
  • If possible, I share my result and that it is working for me.

    public IEnumerable<Taxes> Get()
    {
    BindingFlags bf = BindingFlags.Instance | BindingFlags.NonPublic;

    List<Taxes> taxes = new List<Taxes>();
    Company company = Connection.company;

    SalesTaxCodeList salesTaxs = company.Factories.SalesTaxCodeFactory.List();
    salesTaxs.Load();

    foreach (SalesTaxCode salesTax in salesTaxs)
    {
    Taxes tax = new Taxes();
    decimal taxPerAgency = 0;

    SalesTaxAgencyCollection salesTaxsAgencies = salesTax.SalesTaxAgencies;
    foreach (SalesTaxAgency salesTaxagency in salesTaxsAgencies)
    {
    Type t = salesTaxagency.GetType();
    var salesDomainTax = (Sage.Peachtree.Domain.Entities.SalesTaxAgency)t.GetProperty("MyDomainEntity", bf).GetValue(salesTaxagency);
    Sage.Peachtree.Domain.Entities.FixedRateSalesTaxRateCalculation rateCalculation = (Sage.Peachtree.Domain.Entities.FixedRateSalesTaxRateCalculation)salesDomainTax.RateCalculation;
    taxPerAgency = taxPerAgency + rateCalculation.Rate;
    }

    tax.ID = salesTax.ID.ToString();
    tax.Description = salesTax.Description.ToString();
    tax.Key = salesTax.Key.Guid.ToString();
    tax.Rate = taxPerAgency;

    taxes.Add(tax);
    }

    return taxes;
    }