Cost of Call Announcement is Wrong

Cost of call is 0.0.13 per minute
but ASTPP announces 0.0.1 per minute
see link below for pastebin log
play-balance-log

I am just guessing here, but maybe the decimal point is off in settings?

Decimal Points is set to 4 in Global Settings.
Is it rounding down 1.3 to 1 ??? Is there a setting I am missing?

Have you tried the ASTPP logs?

2023-12-19 15:32:42.147228 97.37% [DEBUG] switch_cpp.cpp:1465 [ASTPP] [Play Amount First Part] Query :0
2023-12-19 15:32:42.147228 97.37% [DEBUG] switch_cpp.cpp:1465 [ASTPP] [Play Amount Second Part] Query :01

From these lines it looks like a decimal is off somewhere.

Another thought, did you allow the call to go through and actually see what the charge would be?

I don’t know why you say the decimal is off. The cost of the call is .013 dollars, and astpp is announcing .01 without the 3 at the end so everything is correct except that the last digit (3) is cut when the cost is played.

I believe the actual rate is charged correctly but the announcement must also be correct, or my customers will complain all the time that the announced rate does not match the charged rate.

Because it is seems to be truncating the cost. Two decimal places versus three.

Yes. It’s cutting off the 3rd decimal but my settings are 4 decimals in global settings so unless there is another setting somewhere, this is a bug.

I do believe there is a coded setting somewhere. For my use, I put in 2 decimals, but yet the system is sending email notifications with five decimal places.

Looking at the docs:

Decimal Points: Set decimal points to use throughout the system (Default value: 4)

https://inextrix.atlassian.net/wiki/spaces/ASTPP/pages/6002491/Settings

Perhaps it is a bug.

Maybe @smrdoshi can give us some hint on that.

Yes I just checked the code and decimal 2 is hardcoded due to some reason. Here is the code ASTPP/freeswitch/scripts/astpp/lib/astpp.callingcard.functions.lua at V6.0 · iNextrix/ASTPP (github.com)

You can possibly change it as per your need and use that for now.
If you make it dynamic based on system configuration then would love to get the PR.

1 Like

Then shouldn’t it be part of the system settings?

Ideally, it should be the value used in global settings for decimal points. Since the database field already exists, it should be a minor code change in lua but I am just starting to learn it. Maybe I can make the change in a month or so but no promises. At first glance, I could not find the line in astpp.callingcard.functions.lua that sets the playcost decimals to 2 digits. Maybe someone else can take a look and at least identify the exact line number?

Looking at the code he linked, I can see a function to play the amount appears to start about line 287.

– Play amount audio file
function play_amount(amount)
amount_array = explode(“.”,amount)
amount_first_part = amount_array[1]
if (amount_array[2] == ‘0’ or amount_array[2] == nil) then
amount_array[2] = ‘00’
end

1 Like

I am guessing here without examining the code more, on line 294 is probably where it is hard coded

amount_second_part = string.sub(amount_array[2],0,2)

OK. I need help with this. Can anyone take a shot at the code? It’s currently hardcoded to 2 decimal places and someone else must have already modified it. Since all rates are announced in dollars, we must play at least 3 decimals to announce rates like 1.3 cents (= 0.013 dollars). I can’t be the only one who has a problem with this.

Best thing to do is to play with it.

amount_array[2] should be the size of the array it will create to hold that number of digits.
Not sure what the 0 is for.
I would guess the final 2 is for number of digits.

Try making both of those to 3.

This works. Cost of call is hardcoded to 3 decimals.

– Play amount audio file
function play_amount(amount)
amount_array = explode(“.”, amount)
amount_first_part = amount_array[1]

if (amount_array[2] == '0' or amount_array[2] == nil) then
    amount_array[2] = '000'
elseif #amount_array[2] == 1 then
    amount_array[2] = amount_array[2] .. '00'
elseif #amount_array[2] == 2 then
    amount_array[2] = amount_array[2] .. '0'
end

amount_second_part = string.sub(amount_array[2], 1, 3)

Logger.debug("[Play Amount First Part] Query :" .. amount_first_part)
Logger.debug("[Play Amount Second Part] Query :" .. amount_second_part)

session:execute("say", "en number pronounced " ..  amount_first_part)
session:streamFile("astpp-point.wav")

for i = 1, #amount_second_part do
    session:execute("say", "en number pronounced " ..  string.sub(amount_second_part, i, i))
end

end

Does it function when there are two digits?

Yes. Zeros are appended to make it 3 digits.

I guess what I mean is will it play for example, “zero five zero cents” for two digits, or will it play “zero five cents”?

Sorry, but I don’t understand. What is the amount you want to announce?
5 cents = 0.05 dollars so it should play 0 point 0, 5, 0 dollars but I haven’t tested every conceivable rate. The rate is announced in dollars, not cents and always with 3 decimals.