im_burn_rate_blurb

one of the documented procedures in this installation of the ACS
Usage:
im_burn_rate_blurb {-db "" }
What it does:
Counts the number of employees with payroll information and returns "The company has $num_employees employees and a monthly payroll of $payroll"
Defined in: /web/philip/tcl/intranet-defs.tcl

Source code:

arg_parser_for_im_burn_rate_blurb $args

    set release_db 0
    if { [empty_string_p $db] } {
	set release_db 1
	set db [ns_db gethandle subquery]
    }

    # We use "exists" instead of a join because there can be more
    # than one mapping between a user and a group, one for each role,
    #
    set selection [ns_db 1row $db "select count(u.user_id) as num_employees, 
ltrim(to_char(sum(salary),'999G999G999G999')) as payroll,
sum(decode(salary,NULL,1,0)) as num_missing
from im_monthly_salaries salaries, users u
where exists (select 1
              from user_group_map ugm
              where ugm.user_id = u.user_id
              and ugm.group_id = [im_employee_group_id $db])
and u.user_id = salaries.user_id (+)"]

    set_variables_after_query

    if { $release_db } {
	ns_db releasehandle $db
    }

    if { $num_employees == 0 } {
	return ""
    }
    set html "The company has $num_employees [util_decode $num_employees 1 employee employees]"
    if { ![empty_string_p $payroll] } {
        append html " and a monthly payroll of \$$payroll"
    }
    if { $num_missing > 0 } {
	append html " ($num_missing missing info)"
    }
    append html "."
    return $html


philg@mit.edu