template::data::transform::currency (private)

 template::data::transform::currency element_ref

Defined in packages/acs-templating/tcl/currency-procs.tcl

Transform the previously-validated submitted form data into a six-element currency list

Parameters:
element_ref - Reference variable to the form element

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.
Source code:

    upvar $element_ref element
    set element_id $element(id)

    set format [ns_queryget $element_id.format]
    for { set i [llength $format] } { $i < 5 } { incr i } {
        lappend format ""
    }

    # a currency is a 6 element list supporting, for example, the following forms: "$2.03" "Rs 50.42" "12.52L" "Y5,13c"

    set have_values 0

    for { set i 0 } { $i <= 4 } { incr i } {
        set key "$element_id.$i"
        if { [ns_queryexists $key] } {
            set value [ns_queryget $key]

            # let's put a leading zero if the whole part is empty
            if { $i == 1 } {
                if {$value eq ""} {
                    set value 0
                } else {
                    set have_values 1
                }
            }

            # and let's fill in the zeros at the end up to the precision
            if { $i == 3 } {
                if { $value ne "" } {
                    set have_values 1
                }
                set fractional_part_format [lindex $format 3]
                for { set j [string length $value] } { $j < $fractional_part_format } { incr j } {
                    append $value 0
                }
            }

            lappend the_amount $value

        } else {
            lappend the_amount ""
        }
    }

    lappend the_amount [ns_queryget $element_id.format]

    ns_log debug "template::data::transform::currency: the_amount: $the_amount length: [llength $the_amount]"

    if { $have_values } {
        return [list $the_amount]
    } else {
        return [list]
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ]
Show another procedure: