Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/household_income_class.inc
<?php
//*Client Data System, Copyright (C) 2000, 2001, 2002, 2003 Tedd Kelleher.  This is free software, subject to the 
//*GNU GENERAL PUBLIC LICENSE, Version 2, June 1991 (in file named gpl.txt), which should accompany 
//*any distribution of this file.  Tedd Kelleher can be contacted at hide@address.com

class Household_income {
    var $client_income_detail;  //Contains details of the income in the format $var[[client_id]][[table_element_id]]
    var $total_household_income;


    function Household_income ( $client_id, $org_id='', $user_id=''  )  {
        
        if ( $org_id < 1 ) {
            $org_id = $_SESSION['org_idB'];
            //echo "Orgaaaaaaaaaa is is ".$org_id."<p>";
            //var_dump ( $_SESSION );
        }
        
        if ( $user_id < 1 ) {
            $user_id = $_SESSION['user_idB'];
        }
        
        //echo "OrgAA is is ".$org_id."<p>";
        
        //Find the related clients
        include_once ( $include_root.'client_profile_class.inc' );
        include_once ( $include_root.'relationships_class.inc' );
        include_once ( $include_root.'reports_class.inc' );
        include_once ( $include_root.'client_lookup_class.inc' );
        include_once ( $include_root.'encryption_class.inc' );
        include_once ( $include_root.'Questions_into_array_class.inc' );
        $rels = new Relationships ( $client_id );
        
        //$cur_cli_array = array ( $client_id => 'zz' ); 
        
        settype ( $rels->related_clients_profile_array, 'array' );
        
        //array_push ( $rels->related_clients_profile_array, $cur_cli_array ); 
        //var_dump ($rels->related_clients_profile_array);
        
        //Find the most recent income reports for each client
        foreach ( $rels->related_clients_profile_array AS $cur_client_id => $cur_client_array )
		{
            $sql = "
            SELECT client_rpt_id, report_type FROM client_rpt_profile 
            WHERE 
                client_id = ".$cur_client_id." 
                AND ( 
                    report_type LIKE 'client_income'
                    OR report_type LIKE 'client_income_exit_followup'
                )
                AND succeeded_by IS NULL
                ORDER BY client_rpt_id DESC
            "; 
            
            $income_reports_array = run_query_return_array ( $sql, 'Pulling latest income report' );
            
            include_once ( $include_root.'client_report_class.inc' );
            
            //$qs_income = new Questions_into_array ( 'client, $user_access_level, $org_id, $group_id, $display_or_edit, $rp_id = '' )
            
            //var_dump ( $income_reports_array );
            
            //Find the first accessible report...
            if ( is_array ( $income_reports_array ) )
			{
                foreach ( $income_reports_array AS $cur_income_report )
				{
                    //echo "Org is is ".$org_id."<p>";
                    $perms = report_permissions_client ( $cur_income_report['client_rpt_id'], $org_id, $user_id );
                    //echo "The idA is ".$cur_income_report['client_rpt_id']."<p>";
                    //echo "Report type is ".$cur_income_report['report_type']."<p>";
                    
                    //var_dump ( $perms ); 
                    
                    if ( $perms['read_rpt'] == 1 )
					{
                        //..and put the answers into an array
                        $qs_income = 
                            new Questions_into_array ( 
                                  $cur_income_report['report_type'], '40', $org_id, $_SESSION['group_idB'], 'display' 
                                  );
                        
                        //var_dump ( $qs_income->question_elements );
                        
                        $cli_rpt = new Client_report; 
                        
                        $cli_rpt->pull_existing_client_report_answers ( 
                             $cur_income_report['client_rpt_id'], $qs_income->questions, $qs_income->question_elements, 'no question id modifier' );
                        
                        //echo "<p>Report id is ".$cur_income_report['client_rpt_id']."<p>";
                        
                        $client_income_answers[$cur_client_id] = $cli_rpt->vetted_frm_ans[0]; 
                        //echo "Found accessible report<p>";
					    //break as we only want data from the first record and the (last report submitted)
                        break 1;
                    }
                }
            }
            //var_dump ( $client_income_answers);
        }
        
		
        if ( is_array ( $client_income_answers ) )
		{
            //Loop through the retrieved answers
            foreach ( $client_income_answers AS $clis_id => $cur_answers )
			{
                 //echo "client is ".$clis_id."<p>";
				 if ( is_array ( $cur_answers[151][1] ) ) {
                     foreach ( $cur_answers[151][1] AS $cur_q_id => $cur_val )
					 {
                        //echo "dol val ".$cur_val."<p>";
                        $this->total_household_income += $cur_val;
                        $this->client_income_detail[$clis_id][$cur_q_id] = $qs_income->question_elements[151]['y'][$cur_q_id];
                        $this->client_income_detail[$clis_id][$cur_q_id]['value'] = $cur_val;
                     }
                 }
                 
                 if ( is_array ( $cur_answers[163][18] ) ) {
                     foreach ( $cur_answers[163][18] AS $cur_q_id => $cur_val )
					 {
                        //echo "dol val ".$cur_val."<p>";
                        $this->total_household_income += $cur_val;
                        $this->client_income_detail[$clis_id][$cur_q_id] = $qs_income->question_elements[163]['y'][$cur_q_id];
                        $this->client_income_detail[$clis_id][$cur_q_id]['value'] = $cur_val;
                     }
                 }
				 
                 //$this->total_household_income = $this->total_household_income + $cur_answers[151][1][16] + $cur_answers['163_0'][18][34];      
            }
        }
        //echo "Income: ".$this->total_household_income;
        //echo pretty_var_dump ( $this->client_income_detail ); 
    
    }












    
}
?>
Return current item: Homeless Mangement Information System