Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3943782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:49:21+00:00 2026-05-20T00:49:21+00:00

I’m having problems correctly calculating tax and discounts per item, mainly because I’m not

  • 0

I’m having problems correctly calculating tax and discounts per item, mainly because I’m not certain what the order should be. I can do this on a calculator without any problems but writing the SQL is a different story. The total column was done by a friend and works as expected. Based on his total column, I’ve added the taxtotal column which seems to give the correct result. I am still having an issue with the discounts though.

There are 2 discount columns. One is an initial discount that can be set in the inventory and a second discount that can be applied by the clerk. The columns for the discounts are op.discount and p.discount. There is no separate table for discounts and are just columns within the two joins.

I’d like to make sure that my taxtotal column is correct as well so if someone sees an issue or a better way of writing it, I’d be appreciative of any suggestions.

SELECT
    p.tax_state as tax_state,
    p.tax_fed as tax_fed,
    p.price AS price,
    op.quantity AS quantity,
    op.discount AS discount,
    (p.tax_state + p.tax_fed) AS tax,
    ( ( p.tax_state + p.tax_fed ) / 100 ) * ( p.price * op.quantity - ( p.price * op.quantity * op.discount + p.discount /100 ) ) AS taxtotal,
    (p.price * (1 + ((p.tax_state + p.tax_fed) / 100)) * (1.0 - op.discount) * op.quantity) AS total
FROM pos_order o
JOIN pos_item_order op ON op.order_id = o.order_id
JOIN inv_item p ON p.item_id = op.item_id
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:49:21+00:00Added an answer on May 20, 2026 at 12:49 am

    if you can create function do this

    
    SELECT
        p.tax_state as tax_state,
        p.tax_fed as tax_fed,
        p.price AS price,
        op.quantity AS quantity,
        op.discount AS discount,
        (p.tax_state + p.tax_fed) AS tax,
        taxtotal(p.tax_state , p.tax_fed, p.price ,op.quantity, op.discount ) AS taxtotal
        valueTotal(p.tax_state , p.tax_fed, p.price ,op.quantity, op.discount ) AS total
    FROM pos_item_order op 
    JOIN inv_item p ON p.item_id = op.item_id
    
    
    

    create this function

    
    DROP FUNCTION IF EXISTS `taxtotal`;
    CREATE DEFINER=`root`@`localhost` FUNCTION `taxtotal`(`tax_state` double,`tax_fed` double,`price` double,`quantity` INT,`discount` double) RETURNS double
    BEGIN
        RETURN ( ( `tax_state` + `tax_fed`) / 100 ) * ( `price` * `quantity` - ( `price` * `quantity` * `discount`/100 ) );
    END
    ;;
    DELIMITER ;
    DROP FUNCTION IF EXISTS `valueTotal`;
    CREATE DEFINER=`root`@`localhost` FUNCTION `valueTotal`(`tax_state` double,`tax_fed` double,`price` double,`quantity` INT,`discount` double) RETURNS double
    BEGIN
        RETURN (p.price * (1 + ((p.tax_state + p.tax_fed) / 100)) * (1.0 - op.discount) * op.quantity);
    END
    ;;
    DELIMITER ;
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.