Seph Seph - 1 year ago 71
SQL Question

Best way to store sales tax information

When designing a stock management database system for sales and purchases what would be the best way to store the various taxes and other such amounts?

A few of the fields that could be saved are:

  • Unit price excluding tax

  • Unit price including tax

  • Tax per item

  • Total excluding tax (rounded to 2 decimals)

  • Total including tax (rounded to 2 decimals)

  • Total tax (rounded to 2 decimals)

  • Tax Percentage

  • Fk link to the Tax % (and not store the tax amount)

Currently the most reasonable solution so far is storing down (roughly) item, quantity, total excluding tax (rounded), and the total tax (rounded).

Is there a better way of storing these details for a generic system?

Given the system needs to be robust, what should be done if there were multiple tax values which might need to be separated (e.g. state and city)? In this case a separate table would be in order, but would it be considered excessive to just have a rowID and some taxID mapping to a totalTax column?

To clarify: Asking how to store the data about individual transactions and that side; not so much the details about the tax specific rates.

Answer Source

The problem with approach is if the tax changes, VAT (sales tax) in the UK has changed twice in the last 12 months.

When I worked in ECommerce websites we had a table Tax_Rate which held the different tax rates a shop would deal with eg.

  1. TaxFree - 0%
  2. Vat - 17.5%
  3. DiscountedVat - 15%
  4. etc...

and then your stock table fields may have

  • ItemId
  • UnitPrice
  • fk_TaxRate

your invoice_detail row table will be

  • fk_OrderId
  • fk_ItemId
  • PerItemPriceCharged (denormalized)
  • TaxRateCharged (denormalized)
  • QuantityOrdered

your invoice table will be

  • OrderId
  • fk_CustomerId

Where fk_denotes a foreign key. Note that OrderId will not be unique in your invoice row table.

EDITS: Head's all over the place today.

You need to denormalize the invoice row total and the tax rate total because you don't want future changes in an item price or tax rate to affect the historical invoices.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download