function load_report_data($report)
 {
     global $db, $Seq;
     $period = $report->period;
     $this->max_num_levels = sizeof($report['FieldListings']) - 1;
     // maximum number of indents
     $sql = "select account_id, beginning_balance + debit_amount - credit_amount as balance \n\t\tfrom " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " where period = " . $period . " order by account_id";
     $result = $db->Execute($sql);
     $balance = array();
     while (!$result->EOF) {
         if (in_array($this->coa_info[$result->fields['account_id']]['account_type'], array(20, 22, 24, 40, 42, 44))) {
             $balance[$result->fields['account_id']] = -$result->fields['balance'];
         } else {
             $balance[$result->fields['account_id']] = $result->fields['balance'];
         }
         $result->MoveNext();
     }
     $this->fill_bal_sheet($balance);
     // build the output data
     $this->bal_sheet_data = array();
     $net_income = new income_statement();
     $net_income->load_report_data($report, $period);
     // retrieve and add net income value
     $net_income_entry = array('id' => '0', 'description' => RW_FIN_NET_INCOME, 'heading_only' => '0', 'primary_acct_id' => RW_SUB_ACT_BAL_SHT_IS_ACCT, 'account_type' => 44, 'total' => $net_income->ytd_net_income);
     if (isset($this->coa_info[RW_SUB_ACT_BAL_SHT_IS_ACCT])) {
         $this->coa_info[RW_SUB_ACT_BAL_SHT_IS_ACCT]['child'][] = $net_income_entry;
         $this->coa_info[RW_SUB_ACT_BAL_SHT_IS_ACCT]['total'] += $net_income->ytd_net_income;
     } else {
         $this->coa_info['0'] = $net_income_entry;
     }
     $this->build_data_fields($this->coa_info, $level = 1);
     return $this->bal_sheet_data;
 }
 function load_report_data($report)
 {
     $period = $report->period;
     // build assets
     $this->bal_tot_2 = 0;
     $this->bal_tot_3 = 0;
     $this->bal_sheet_data = array();
     $this->bal_sheet_data[] = array('d', RW_FIN_PROP_EQUIP, '', '', '');
     $the_list = array(8, 10, 12);
     $negate_array = array(false, false, false);
     $this->add_bal_sheet_data($the_list, $negate_array, $period);
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_PROP_EQUIP, '', '', ProcessData($this->bal_tot_2, $report->fieldlist[2]->processing));
     $this->bal_sheet_data[] = array('d', '', '', '', '');
     // blank line
     $this->bal_sheet_data[] = array('d', RW_FIN_CURRENT_ASSETS, '', '', '');
     $the_list = array(0, 2, 4, 6);
     $negate_array = array(false, false, false, false);
     $this->bal_tot_2 = 0;
     $this->add_bal_sheet_data($the_list, $negate_array, $period);
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_CURRENT_ASSETS, '', '', ProcessData($this->bal_tot_2, $report->fieldlist[2]->processing));
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_ASSETS, '', '', ProcessData($this->bal_tot_3, $report->fieldlist[3]->processing));
     $this->bal_sheet_data[] = array('d', '', '', '', '');
     // blank line
     // build liabilities
     $this->bal_sheet_data[] = array('d', RW_FIN_CUR_LIABILITIES, '', '', '');
     $this->bal_tot_2 = 0;
     $this->bal_tot_3 = 0;
     $the_list = array(20, 22);
     $negate_array = array(true, true);
     $this->add_bal_sheet_data($the_list, $negate_array, $period);
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_CUR_LIABILITIES, '', '', ProcessData($this->bal_tot_2, $report->fieldlist[2]->processing));
     $this->bal_sheet_data[] = array('d', '', '', '', '');
     // blank line
     $this->bal_sheet_data[] = array('d', RW_FIN_LONG_TERM_LIABILITIES, '', '', '');
     $this->bal_tot_2 = 0;
     $the_list = array(24);
     $negate_array = array(true);
     $this->add_bal_sheet_data($the_list, $negate_array, $period);
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_LT_LIABILITIES, '', '', ProcessData($this->bal_tot_2, $report->fieldlist[2]->processing));
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_LIABILITIES, '', '', ProcessData($this->bal_tot_3, $report->fieldlist[3]->processing));
     $this->bal_sheet_data[] = array('d', '', '', '', '');
     // blank line
     // build capital
     $this->bal_sheet_data[] = array('d', RW_FIN_CAPITAL, '', '', '');
     $this->bal_tot_2 = 0;
     $the_list = array(40, 42, 44);
     $negate_array = array(true, true, true);
     $this->add_bal_sheet_data($the_list, $negate_array, $period);
     $net_income = new income_statement();
     $net_income->load_report_data($report, $period);
     // retrieve and add net income value
     $this->bal_tot_2 += $net_income->ytd_net_income;
     $this->bal_tot_3 += $net_income->ytd_net_income;
     $this->bal_sheet_data[] = array('d', RW_FIN_NET_INCOME, ProcessData($net_income->ytd_net_income, $report->fieldlist[2]->processing), '', '');
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_CAPITAL, '', '', ProcessData($this->bal_tot_2, $report->fieldlist[2]->processing));
     $this->bal_sheet_data[] = array('d', RW_FIN_TOTAL_LIABILITIES_CAPITAL, '', '', ProcessData($this->bal_tot_3, $report->fieldlist[3]->processing));
     return $this->bal_sheet_data;
 }