Wednesday, November 4, 2009

Printing Check Amount With Decimal Part


Yesterday was not really a good day for me. because a simple fix on the check amount dragged my entire day till 10pm. But it kinda helped me to explore lot of stuff.

Let me come straight to the actual problem.

Currently we are showing the checkamount padded with asterisk(*) like *******1200 (I will use this value for by below examples). Here is how I pad the asterisk
<?xdofx:lpad(PaymentAmount/Value,12,'*')?>

Since there is no decimal part in this value the bank some times considers the last 2 digits from the right as the decimal part. In this case they consider 00 as decimal part and paid only 12 dollar. To avoid this confusion we decided to print the decimal part also so that the amount will look like ****1200.00

Now here the problem starts. I initially thought of using to_char/to_number like
<?xdofx:lpad(to_char(PaymentAmount/Value,'999,999,99.99'),12,'*')?>
and format the value with 2 decimal part. But for some reason this did not work. I still get the amount as *******1200. Even I tried
<?xdofx:lpad(format-number:format-number:PaymentAmount/Value;'999G999D99',12,'*')?>
but no luck.

Then something sparked in mind to search about any existing configuration/setup for this decimal part just like the units and subunits. So started googling, checking payment user guide, installation guide, digging the check document gendration code, etc... but no luck on this even after spending 4hrs on this.

I wonder whether we have such configuration/setup to define the number of decimal part. Because in europe they use comma(,) instead of dot(.) as the decimal seperator. Where do we do this setup in the application? Is there any profile option to do this? its still a blindspot for me?

Finally I decided to getback on resolving this issue programatically. So started trying all possible ways to do this and no luck. Even lot of forums have questions about this and there is no good solution suggested.

Around 9pm I decided not to think smarter and tried to do with some if and else conditions and came up with the below logic,

xdoxslt:set_variable($_XDOCTX, 'ln_dot', xdoxslt:replace(PaymentAmount/Value,'.',''))
<?choose:?>
<?when:xdoxslt:get_variable($_XDOCTX,'ln_dot')= xdoxslt :to_number(PaymentAmount/Value)?>
<?xdofx:lpad(PaymentAmount/Value||'.00'||PaymentAmount/Currency/Code,15,'*')?>
<?end when?>
<?otherwise:?>
<?choose:?>
<?when:xdoxslt:get_variable($_XDOCTX,'ln_dot') div 100 = xdoxslt :to_number(PaymentAmount/Value)?>
<?xdofx:lpad(PaymentAmount/Value||PaymentAmount/Currency/Code,15,'*')?>
<?end when?>
<?otherwise:?>
<?xdofx:lpad(PaymentAmount/Value||'0'||PaymentAmount/Currency/Code,15,'*')?>
<?end otherwise?>
<?end choose?>
<?end otherwise?>
<?end choose?>


Above logic when statement handles the below data conditions,
1. Amount without decimals like 1200
2. Anount with one decimal value like 1200.9
3. Amoutn with 2 decimal value like 1200.98

How I handle contion 2 and 3? its simple math :) I am divding the replaced value with 100 to check whether I had 2 decimal digits in the original amount. So that I can concatenate one zero at the end.

I know this sounds like a crazy school kid logic :) but it helped me :D I know you readers will have great logic to handling this. If so please do share it in the comment section.

But even still I think there should be a setup for managing this decimal part, if not oracle should consider about having atleast in there future application release 12.X.X


2 comments:

Arun said...

Laskshman..Do you know if there is a simpler function that can leverage format-number and the concatentation of currency code and the *.  I know the above works, but I'd like a simpler native version, if possible.

Lakshmanan AK said...

I did not come across any. Will post here if I find anything.

Post a Comment