Logic for Billing
-
I am developing a billing software for a Water Company would someone out there help in the algorithm for calculating the amount to pay based on the logic below am using vb.net. The Company has set tarrifs which are Consumption Amount Per Consumption 0-10 12 10-20 33 20-40 44 40-100 56 over 100 64 if a client consumes less than 10 units he pays the minimum which is 120 if a client for Example consumes say 110 units the amount is calculated as follows 0 -10 ten units are used hence amount to pay will be 10*12 =120 100 units will remain 10 -20 ten units are again used hence the amount will be 10*33 =330 total amount will be 120 +330 = 450 90 units remain 20-40 twenty units are used hence amount will be 20 * 44 =880 total amount will be 120+330+880 =1330 70 units remain 40 -100 60 units will be used hence amount will be 60 * 56 =3360 total amount will be 120+330+880+3360=4690 10 units remain over 100 10 * 64 =640 total amount = 4690 +640 = 5330 briogene
-
I am developing a billing software for a Water Company would someone out there help in the algorithm for calculating the amount to pay based on the logic below am using vb.net. The Company has set tarrifs which are Consumption Amount Per Consumption 0-10 12 10-20 33 20-40 44 40-100 56 over 100 64 if a client consumes less than 10 units he pays the minimum which is 120 if a client for Example consumes say 110 units the amount is calculated as follows 0 -10 ten units are used hence amount to pay will be 10*12 =120 100 units will remain 10 -20 ten units are again used hence the amount will be 10*33 =330 total amount will be 120 +330 = 450 90 units remain 20-40 twenty units are used hence amount will be 20 * 44 =880 total amount will be 120+330+880 =1330 70 units remain 40 -100 60 units will be used hence amount will be 60 * 56 =3360 total amount will be 120+330+880+3360=4690 10 units remain over 100 10 * 64 =640 total amount = 4690 +640 = 5330 briogene
-
I am developing a billing software for a Water Company would someone out there help in the algorithm for calculating the amount to pay based on the logic below am using vb.net. The Company has set tarrifs which are Consumption Amount Per Consumption 0-10 12 10-20 33 20-40 44 40-100 56 over 100 64 if a client consumes less than 10 units he pays the minimum which is 120 if a client for Example consumes say 110 units the amount is calculated as follows 0 -10 ten units are used hence amount to pay will be 10*12 =120 100 units will remain 10 -20 ten units are again used hence the amount will be 10*33 =330 total amount will be 120 +330 = 450 90 units remain 20-40 twenty units are used hence amount will be 20 * 44 =880 total amount will be 120+330+880 =1330 70 units remain 40 -100 60 units will be used hence amount will be 60 * 56 =3360 total amount will be 120+330+880+3360=4690 10 units remain over 100 10 * 64 =640 total amount = 4690 +640 = 5330 briogene
Your algorithm looks suspicious to me. Please verify (just for peace of mind) that the more you use, the more expensive each successive unit is. I don't work with utilities, and perhaps this is completely correct. It is just counter to my free-market thinking, where, the more you buy, the cheaper each succeding unit is...
static int tarrifAmounts[] = {0, 10, 20, 40, 100, INT_MAX};
static int tarrifRates[] = {0, 12, 33, 44, 56, 64};int bill( int amount )
{
int ret = 0;
int tindx = 1;
while( amount > tarrifAmounts[tindx] )
{
ret += tarrifRates[tindx] * (tarrifAmounts[tindx]-tarrifAmounts[tindx-1]);
tindx++ ;
}
ret += tarrifRates[tindx] * (amount - tarrifAmounts[tindx-1]);
return ret;
}Convert it to VB, check whether it works, and send my payment to ... ;) David -- modified at 16:54 Monday 22nd October, 2007 OOPS: I just noticed that you said there is a minumum charge. Therefore, the actual billing amount will need to be: max(MINIMUM_CHARGE, bill(amountUsed)) Or just embed it into the bill algorithm. Whatever works for you.
-
You've clearly described the algorithm in this post. Now do your own homework.
-- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
Sometimes a person has a mental block, and just has to see someone else's solution before the clouds begin to clear. And then some of it is just experience. When he has been programming as long as I have, solving problems like this will probably be second nature to him. I've worked with programmers for years now, and I see folks struggle with these kinds of (seemingly simple) problems all the time. Then again, sometimes I struggle with (seemingly simple) problems, and a bit of insight from a coworker is greatly appreciated. David
-
I am developing a billing software for a Water Company would someone out there help in the algorithm for calculating the amount to pay based on the logic below am using vb.net. The Company has set tarrifs which are Consumption Amount Per Consumption 0-10 12 10-20 33 20-40 44 40-100 56 over 100 64 if a client consumes less than 10 units he pays the minimum which is 120 if a client for Example consumes say 110 units the amount is calculated as follows 0 -10 ten units are used hence amount to pay will be 10*12 =120 100 units will remain 10 -20 ten units are again used hence the amount will be 10*33 =330 total amount will be 120 +330 = 450 90 units remain 20-40 twenty units are used hence amount will be 20 * 44 =880 total amount will be 120+330+880 =1330 70 units remain 40 -100 60 units will be used hence amount will be 60 * 56 =3360 total amount will be 120+330+880+3360=4690 10 units remain over 100 10 * 64 =640 total amount = 4690 +640 = 5330 briogene
How handsome does this form need to look, you can do all the math in the push of a button while showing the total bill hours and the total price ONLY or you can break it down into the different levels and show the sub totals of each as you have explained. I would perform the over 100 math first then deal with everything under 100, in your case 10, 10, 20, 60. The code can be a tad long hand so others can figure it out later in your absence or transfer or move on to a different job, like the boss who may not be an old VB Head. The code can be written after your psuedo code using If Then statements or If Then Else. Do you already have a form made up, whats on it, I would make it as busy as possible, maybe 7 textboxes, 7 labels, 1 button for the math, but code out each box as in your psuedo code and the button will perform it all and show the TOTAL AMOUNT OWED based on the HOURS CONSUMED. I just built an excel spreadsheet with the minimum amount of numbers to go from say 23 thru 150, I only used like 7 numbers, like 28 + 36 = 64 or 25 + 32 + 40 = 97, by using these few numbers thru my upper limit I could combine them to get any total from 23 thru 150 inclusive, the maximum of additions would be 5 of my 7 such as 25 + 25 +......= 150. EDIT, SINCE I LIVE IN A FORIEGN COUNTRY, THE US DOLLAR TO YEN CHANGES DAILY AND WE HAVE CHARTS TO SHOW AT AN INSTANT WHAT YOU WILL GET FOR THE AMOUNT YOU ARE GOING TO EXCHANGE. I think what I am trying to say is that you should also create a table that will show every combonation from zero (0.01) hours usage thru a FINITE 'n' upper limit or infinite limit, excel will knock that out in seconds for the usage numbers over 100 since the rate does not change over 100. Are you going to link this all to a spreadsheet or to SQL database, put customer info on form1 and make it busier than I stated above, thats good too. As you say, you cant see the forest for the trees, this should be an easy one, just depends on how you want it to look and how long do you want the code, even the longest will print out on one sheet of paper. The more electric you use, the more those people pay, sound like VA disability math being used here.
-
Your algorithm looks suspicious to me. Please verify (just for peace of mind) that the more you use, the more expensive each successive unit is. I don't work with utilities, and perhaps this is completely correct. It is just counter to my free-market thinking, where, the more you buy, the cheaper each succeding unit is...
static int tarrifAmounts[] = {0, 10, 20, 40, 100, INT_MAX};
static int tarrifRates[] = {0, 12, 33, 44, 56, 64};int bill( int amount )
{
int ret = 0;
int tindx = 1;
while( amount > tarrifAmounts[tindx] )
{
ret += tarrifRates[tindx] * (tarrifAmounts[tindx]-tarrifAmounts[tindx-1]);
tindx++ ;
}
ret += tarrifRates[tindx] * (amount - tarrifAmounts[tindx-1]);
return ret;
}Convert it to VB, check whether it works, and send my payment to ... ;) David -- modified at 16:54 Monday 22nd October, 2007 OOPS: I just noticed that you said there is a minumum charge. Therefore, the actual billing amount will need to be: max(MINIMUM_CHARGE, bill(amountUsed)) Or just embed it into the bill algorithm. Whatever works for you.