Calculate miscellaneous percentages

Asked

Viewed 102 times

-1

I have a sales system, where each user has an X percentage on their sale, at the moment I have 15 users, 10 of them with 5% profit on each sale, and the other 5 have 8% profit on each sale. So I have my administration page where I see how much I will have to pay them all if I add up all the percentages of gain, the problem is that I have to calculate sale by sale, that is, if the user has 5% profit and the other has 8%, I have to script do the following:

$Valor += $ValorDoProduto * ($GanhoDoUsuario / 100);

So, if I add up all users, I will have an X value that represents the amount I will pay if I add up all the winnings of each user. But I would like to make it simpler, so that I calculate all the sales, then returning me an X value, that X value is the sales without taking away the seller’s gain, so when I have the X value that is the sum of all the products sold I would add up all the percentages, and then subtract and have the same value that you would have using the calculus up there. Explaining better: I have a user table on MySQL, each user has a gain in percentage for each sale, there is the possibility to 'add' all percentages and then make a single calculation to determine how much I will have to pay commission to all of them?

1 answer

1

It is not possible. If you add up the values of all products you no longer know that part of the total profits corresponds to the gains of 5% or 8%.

At most you can add all the sales of the users of each subgroup (one subgroup being the set of users who receive 5% or 8% of a sale). In the end you apply the percentage to the sum of each subgroup to know how much you have to pay each seller. So you only have to do one calculation per subgroup (in your case 2) instead of one per user.

  • Got it, I thought I’d have like... thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.