I need some help to create the following document:
This document is intended to support a small retail business.
Workflow description:
I send products in different shipments to different customers.
To bill them I want to be able to see how much of each product I have shipped and also how much has already been billed.
Then I want to track different payments that cancel the amount owed by each customer.
Example

May 5th: I send Mark 2 units of product A (worth $1 per unit)and 6 units of product B (worth $2 each)

May 10th: I send Mark 3 units of product A (worth $1 per unit)and 5 units of product B (worth $2 each)

May 30th: I bill Mark for 4 units of A and 4 of B

June 1st: Mark pays me $10

June 10th: I send Mark 3 units of product A (worth $1 per unit)and 5 units of product B (worth $2 each)

First Problem: I want to bill Mark for the remainder of the shipments so i need to add all the Units Sent and subtract the Units that have already been Billed
The answer is:
A = 2+34+3=4 unit remaining to be billed
B = 6+54+5=12 units remaining to be billed
I bill him for 4 unit of A and 12 units of B 
Second Problem: i want to know how much money mark owes me for billed products. I have to add all the bills sent and subtract payments made.
The answer is:
Bills sent:
First Bill 4x$1 + 4x$2 = 8
Payment = 10
Second Bill 4x$1 + 12x$2 = 28
He still owes me $26