I am not so good in math. I would be very thankful if anyone solves my problem. Thanks in advance.

I am writing a small business software. I would like to explain the problem with a simple example.

Lets assume we are running a small kiosk and we sell gift hampers. 1 gift hamper contains 8 items: 4 cookies, 2 chocolates, 2 cakes. Now lets say a customer orders 10 gift hampers.

Now the user of my software would enter 80 items:

80 items (10 gift hampers)
-- 40 cookies
-- 20 chocolates
-- 20 cakes

My software keeps track of all the items stock. Lets assume the availablity of the items is the following:
-- 30 cookies are currently available
-- 20 chocolates are currently available
-- 13 cakes are currently available

When the user enters 80 I need to show the user 48 as available. 48 because:
-- Only 30 cookies are available, which means 7 gift hampers are available, for 7 gift hampers we need 28 cookies which is the max. which can be delivered.
-- Chocolates are available, so there is nothing we have to calculate.
-- Only 13 cakes are available, which means 6 gift hampers are available, for 6 gift hampers we need 12 cakes which is the max which can be delivered.

Since the minimum gift hampers deliverable from above is 6, which means only 6 gift hampers can be delivered which is 48 items because a set or a hamper contains 8 items.

Can anyone guide me how to calculate 48?

Thanks in advance,