示例#1
0
 /**
  * @return an array of columns e.g. (type, title, args)
  */
 function getTickerColumns()
 {
     $columns = array();
     $columns[] = array('type' => 'number', 'title' => ct("Free delay"));
     $columns[] = array('type' => 'number', 'title' => ct("Premium delay"));
     return $columns;
 }
示例#2
0
function ct($n, $m)
{
    $ct = c::get($n, $m);
    if (!is_null($ct)) {
        return $ct;
    }
    if ($n === $m) {
        $ct = 0.0;
    } elseif ($n === 1 && $m === 0) {
        $ct = 2.0;
    } elseif ($m === 0) {
        $ct = (1 + ct($n - 1, 0)) * 2;
    } else {
        for ($i = $m + 1; $i != $n; ++$i) {
            $ct0 = c::get($n, $i);
            if (!is_null($ct0)) {
                break;
            }
        }
        for ($i -= 1; $i != $m; --$i) {
            $ct1 = 1 + $ct0 / 2 + ct($n, 0) / 2;
            c::set($n, $i, $ct1);
            $ct0 = $ct1;
        }
        $ct = 1 + ct($n, $m + 1) / 2 + ct($n, 0) / 2;
    }
    c::set($n, $m, $ct);
    return $ct;
}
 /**
  * @return an array of columns e.g. (type, title, args)
  */
 function getTickerColumns()
 {
     $columns = array();
     $columns[] = array('type' => 'number', 'title' => ct("1 min"), 'min' => 0, 'max' => 5);
     $columns[] = array('type' => 'number', 'title' => ct("5 min"), 'min' => 0, 'max' => 5);
     $columns[] = array('type' => 'number', 'title' => ct("15 min"), 'min' => 0, 'max' => 5);
     return $columns;
 }
示例#4
0
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'date', 'title' => ct("Date"));
     $report_type = $this->report_type;
     $report_table = $this->report_table;
     $report_ref_table = $this->report_ref_table;
     $report_reference = $this->report_reference;
     $key_prefix = $this->key_prefix;
     $key = $this->key;
     $actual_value_key = $this->actual_value_key;
     $q = db()->prepare("SELECT * FROM performance_reports WHERE report_type=? ORDER BY id DESC LIMIT 30");
     $q->execute(array($report_type));
     $reports = $q->fetchAll();
     if (!$reports) {
         return render_text($graph, "No report {$report_type} found.");
     }
     // construct an array of (date => )
     $data = array();
     $keys = array();
     $last_updated = false;
     foreach ($reports as $report) {
         // get all queries
         $q = db()->prepare("SELECT * FROM {$report_table} AS r " . ($report_ref_table ? "JOIN {$report_ref_table} AS q ON r.{$report_reference}=q.id " : "") . "WHERE report_id=?");
         $q->execute(array($report['id']));
         $date = date('Y-m-d H:i:s', strtotime($report['created_at']));
         $row = array();
         while ($query = $q->fetch()) {
             if (!isset($keys[$query[$key]])) {
                 $keys[$query[$key]] = count($keys);
                 $columns[] = array('type' => 'number', 'title' => $query[$key]);
             }
             if ($actual_value_key === null) {
                 if ($query[$key_prefix . '_count'] == 0) {
                     // prevent division by 0
                     $row[$keys[$query[$key]]] = graph_number_format(0);
                 } else {
                     $row[$keys[$query[$key]]] = graph_number_format($query[$key_prefix . '_time'] / $query[$key_prefix . '_count']);
                 }
             } else {
                 $row[$keys[$query[$key]]] = graph_number_format($query[$actual_value_key]);
             }
         }
         $data[$date] = $row;
         $last_updated = max($last_updated, strtotime($report['created_at']));
     }
     // fill in any missing rows, e.g. queries that may not have featured in certain reports
     foreach ($data as $date => $row) {
         foreach ($keys as $id) {
             if (!isset($row[$id])) {
                 $data[$date][$id] = 0;
             }
         }
     }
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated);
 }
示例#5
0
 /**
  * @return an array of columns e.g. (type, title, args)
  */
 function getTickerColumns()
 {
     $args = array(':pair' => get_currency_abbr($this->currency1) . "/" . get_currency_abbr($this->currency2));
     $columns = array();
     if ($this->onlyhasLastTrade()) {
         // hack fix because TheMoneyConverter and Coinbase only have last_trade
         $columns[] = array('type' => 'number', 'title' => ct(":pair"), 'args' => $args);
     } else {
         $columns[] = array('type' => 'number', 'title' => ct(":pair Bid"), 'args' => $args);
         $columns[] = array('type' => 'number', 'title' => ct(":pair Ask"), 'args' => $args);
     }
     return $columns;
 }
示例#6
0
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'string', 'title' => ct("Key"));
     $columns[] = array('type' => 'string', 'title' => ct("Title"), 'heading' => true);
     $columns[] = array('type' => 'string align-right', 'title' => ct("Total"));
     $columns[] = array('type' => 'string align-right', 'title' => ct("Last week"));
     $columns[] = array('type' => 'string align-right', 'title' => ct("Last day"));
     $columns[] = array('type' => 'string align-right', 'title' => ct("Last hour"));
     $last_updated = time();
     $summary = array('user_properties' => array('title' => ct('Users'), 'extra' => array('is_disabled=1' => ct('Disabled'))), 'addresses' => array('title' => ct('Addresses')), 'jobs' => array('title' => ct('Jobs'), 'extra' => array('is_executed=0' => ct('Pending'))), 'outstanding_premiums' => array('title' => ct('Premiums'), 'extra' => array('is_paid=1' => ct('Paid'))), 'uncaught_exceptions' => array('title' => ct('Uncaught exceptions')), 'ticker' => array('title' => ct('Ticker instances')));
     $result = array();
     foreach ($summary as $key => $data) {
         $row = array();
         $row[0] = $data['title'];
         if (isset($data['extra'])) {
             foreach ($data['extra'] as $extra_key => $extra_title) {
                 $row[0] .= " ({$extra_title})";
             }
         }
         $parts = array('1', 'created_at >= date_sub(now(), interval 7 day)', 'created_at >= date_sub(now(), interval 1 day)', 'created_at >= date_sub(now(), interval 1 hour)');
         foreach ($parts as $query) {
             $q = db()->prepare("SELECT COUNT(*) AS c FROM {$key} WHERE {$query}");
             $q->execute();
             $c = $q->fetch();
             $row[] = number_format($c['c']);
             if (isset($data['extra'])) {
                 foreach ($data['extra'] as $extra_key => $extra_title) {
                     $q = db()->prepare("SELECT COUNT(*) AS c FROM {$key} WHERE {$query} AND {$extra_key}");
                     $q->execute();
                     $c = $q->fetch();
                     $row[count($row) - 1] .= " (" . number_format($c['c']) . ")";
                 }
             }
         }
         $result[$key] = $row;
     }
     $row = array(ct("Unused premium addresses"));
     $q = db()->prepare("SELECT currency, COUNT(*) AS c FROM premium_addresses WHERE is_used=0 GROUP BY currency");
     $q->execute();
     while ($c = $q->fetch()) {
         $row[] = number_format($c['c']) . " (" . get_currency_abbr($c['currency']) . ")";
     }
     $result['unused_premium_addresses'] = $row;
     return array('key' => $key_column, 'columns' => $columns, 'data' => $result, 'last_updated' => $last_updated);
 }
示例#7
0
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => get_exchange_name($this->exchange));
     $columns = array();
     $columns[] = array('type' => 'string', 'title' => ct("Price"), 'heading' => true);
     $columns[] = array('type' => 'string', 'title' => ct("Value"));
     $data = array();
     $q = db()->prepare("SELECT * FROM ticker_recent WHERE exchange=:exchange AND currency1=:currency1 AND currency2=:currency2");
     $q->execute(array('exchange' => $this->exchange, 'currency1' => $this->currency1, 'currency2' => $this->currency2));
     if ($ticker = $q->fetch()) {
         $last_updated = $ticker['created_at'];
         $data[] = array('Bid', currency_format($this->currency1, $ticker['bid'], 4));
         $data[] = array('Ask', currency_format($this->currency1, $ticker['ask'], 4));
     } else {
         throw new GraphException(t("No recent rates found for :exchange :pair", $this->getTitleArgs()));
     }
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated, 'no_header' => true);
 }
示例#8
0
 /**
  * We need to transpose the returned data, both data and columns.
  */
 public function getData($days)
 {
     $original = parent::getData($days);
     $columns = array();
     $columns[] = array('type' => 'string', 'title' => ct("Total :currency"), 'args' => array(':currency' => get_currency_abbr($this->currency)), 'heading' => true);
     $data = array();
     $total = 0;
     foreach ($original['data'] as $key => $row) {
         foreach ($row as $i => $value) {
             $data[] = array($original['columns'][$i]['title'], currency_format($this->currency, $value, 4));
             $total += $value;
         }
     }
     // 'Total BTC' column
     $columns[] = array('type' => 'string', 'title' => currency_format($this->currency, $total, 4));
     // save for later
     $this->total = $total;
     return array('key' => $original['key'], 'columns' => $columns, 'data' => $data, 'last_updated' => $original['last_updated']);
 }
function print_report()
{
    $OUTPUT = clean_html(financialStatements::incomestmnt($_POST));
    switch ($_POST["key"]) {
        case ct("Print"):
            require "../tmpl-print.php";
            break;
        case ct("Save"):
            db_conn("core");
            $sql = "INSERT INTO save_income_stmnt (output, gendate, div) VALUES ('" . base64_encode($OUTPUT) . "', current_date, '" . USER_DIV . "')";
            $svincRslt = db_exec($sql) or errDie("Unable to save the balance sheet to Cubit.");
            return "<li class='err'>Income statement has been successfully saved to Cubit.</li>\n\t\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n\t\t\t\t<tr><th>Quick Links</th></tr>\n\t\t\t\t<tr class=datacell><td align=center><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td></tr>\n\t\t\t\t<tr class=datacell><td align=center><a href='index-reports.php'>Financials</a></td></tr>\n\t\t\t\t<tr class=datacell><td align=center><a href='index-reports-stmnt.php'>Current Year Financial Statements</a></td></tr>\n\t\t\t\t<tr class=datacell><td align=center><a href='../main.php'>Main Menu</td></tr>\n\t\t\t</table>";
            break;
        case ct("Export to Spreadsheet"):
            require_lib("xls");
            StreamXLS("income_statement", $OUTPUT);
            break;
    }
}
示例#10
0
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => ct("Currency"));
     $columns = array();
     // get data
     // TODO could probably cache this
     $q = db()->prepare("SELECT SUM(balance) AS balance, exchange, MAX(created_at) AS created_at FROM balances WHERE user_id=? AND is_recent=1 AND currency=? GROUP BY exchange");
     $q->execute(array($this->getUser(), $this->currency));
     $balances = $q->fetchAll();
     // need to also get address balances
     $summary_balances = get_all_summary_instances($this->getUser());
     // get additional balances
     $data = array();
     if (isset($summary_balances['blockchain' . $this->currency]) && $summary_balances['blockchain' . $this->currency]['balance'] != 0) {
         $balances[] = array("balance" => $summary_balances['blockchain' . $this->currency]['balance'], "exchange" => "blockchain", "created_at" => $summary_balances['blockchain' . $this->currency]['created_at']);
     }
     if (isset($summary_balances['offsets' . $this->currency]) && $summary_balances['offsets' . $this->currency]['balance'] != 0) {
         $balances[] = array("balance" => $summary_balances['offsets' . $this->currency]['balance'], "exchange" => "offsets", "created_at" => $summary_balances['offsets' . $this->currency]['created_at']);
     }
     // sort by balance
     usort($balances, array($this, 'sort_by_balance_desc'));
     $last_updated = find_latest_created_at($balances);
     // apply demo_scale and calculate total summary
     $data = array();
     $total = 0;
     foreach ($balances as $b) {
         if ($b['balance'] != 0) {
             $columns[] = array('type' => 'number', 'title' => get_exchange_name($b['exchange']));
             $data[] = demo_scale($b['balance']);
             $total += demo_scale($b['balance']);
         }
     }
     // return a more helpful message if there is no data
     if (!$data) {
         throw new NoDataGraphException_AddAccountsAddresses();
     }
     // sort data by balance
     $data = array(get_currency_abbr($this->currency) => $data);
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated);
 }
示例#11
0
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => ct("Currency"));
     $columns = array();
     // get all balances
     $balances = get_all_summary_instances($this->getUser());
     $last_updated = find_latest_created_at($balances, "total");
     // and convert them using the most recent rates
     $rates = get_all_recent_rates();
     // create data
     // TODO refactor this into generic any-currency balances
     $data = array();
     if (isset($balances['totalbtc']) && $balances['totalbtc']['balance'] != 0) {
         $columns[] = array('type' => 'number', 'title' => get_currency_abbr('btc'));
         $data[] = graph_number_format(demo_scale($balances['totalbtc']['balance']));
     }
     foreach (get_all_currencies() as $cur) {
         // if the key is a currency, use the same currency colour across all graphs (#293)
         $color = array_search($cur, get_all_currencies());
         if ($cur == 'btc') {
             continue;
         }
         if (!is_fiat_currency($cur) && isset($balances['total' . $cur]) && $balances['total' . $cur]['balance'] != 0 && isset($rates['btc' . $cur])) {
             $columns[] = array('type' => 'number', 'title' => get_currency_abbr($cur), 'color' => $color);
             $data[] = graph_number_format(demo_scale($balances['total' . $cur]['balance'] * $rates['btc' . $cur]['bid']));
         }
         if (is_fiat_currency($cur) && isset($balances['total' . $cur]) && $balances['total' . $cur]['balance'] != 0 && isset($rates[$cur . 'btc']) && $rates[$cur . 'btc']['ask']) {
             $columns[] = array('type' => 'number', 'title' => get_currency_abbr($cur), 'color' => $color);
             $data[] = graph_number_format(demo_scale($balances['total' . $cur]['balance'] / $rates[$cur . 'btc']['ask']));
         }
     }
     // display a helpful message if there's no data
     if (!$data) {
         throw new NoDataGraphException_AddAccountsAddresses();
     }
     // sort data by balance
     arsort($data);
     $data = array(get_currency_abbr('btc') => $data);
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated);
 }
示例#12
0
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => ct("Currency"));
     $columns = array();
     $columns[] = array('type' => 'string', 'title' => ct("Currency"), 'heading' => true);
     $columns[] = array('type' => 'string', 'title' => ct("Total"));
     // a table of each currency
     // get all balances
     $balances = get_all_summary_instances($this->getUser());
     $summaries = get_all_summary_currencies($this->getUser());
     $currencies = get_all_currencies();
     $last_updated = find_latest_created_at($balances, "total");
     // create data
     $data = array();
     foreach ($currencies as $c) {
         if (isset($summaries[$c])) {
             $balance = isset($balances['total' . $c]) ? $balances['total' . $c]['balance'] : 0;
             $data[] = array("<span title=\"" . htmlspecialchars(get_currency_name($c)) . "\">" . get_currency_abbr($c) . "</span>", currency_format($c, demo_scale($balance), 4));
         }
     }
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated, 'add_more_currencies' => true, 'no_header' => true);
 }
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => ct("Currency"));
     $columns = array();
     $columns[] = array('type' => 'string', 'title' => ct("Exchange"), 'heading' => true);
     $columns[] = array('type' => 'string', 'title' => ct("Converted fiat"));
     // a table of each crypto2xxx value
     // get all balances
     $currencies = get_crypto_conversion_summary_types($this->getUser());
     $last_updated = false;
     // create data
     $data = array();
     foreach ($currencies as $key => $c) {
         $q = db()->prepare("SELECT * FROM summary_instances WHERE user_id=? AND summary_type=? AND is_recent=1");
         $q->execute(array($this->getUser(), "crypto2" . $key));
         if ($balance = $q->fetch()) {
             $data[] = array($c['short_title'], currency_format($c['currency'], demo_scale($balance['balance']), 4));
             $last_updated = max($last_updated, strtotime($balance['created_at']));
         }
     }
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated, 'add_more_currencies' => true, 'no_header' => true);
 }
示例#14
0
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'string', 'title' => ct("Key"));
     $columns[] = array('type' => 'string', 'title' => ct("Exchange"), 'heading' => true);
     $columns[] = array('type' => 'string', 'title' => ct("Price"));
     $columns[] = array('type' => 'string', 'title' => ct("Volume"));
     $q = db()->prepare("SELECT * FROM ticker_recent WHERE currency1=? AND currency2=? ORDER BY volume DESC");
     $q->execute(array($this->currency1, $this->currency2));
     $tickers = $q->fetchAll();
     $q = db()->prepare("SELECT * FROM average_market_count WHERE currency1=? AND currency2=?");
     $q->execute(array($this->currency1, $this->currency2));
     $market_count = $q->fetch();
     $average = false;
     foreach ($tickers as $ticker) {
         if ($ticker['exchange'] == 'average') {
             $average = $ticker;
         }
     }
     if (!$average) {
         throw new RenderGraphException(t("Could not find any average data"));
     }
     $volume_currency = $average['currency2'];
     // generate the table of data
     $data = array();
     foreach ($tickers as $ticker) {
         if ($ticker['exchange'] == "average") {
             continue;
         }
         if ($ticker['volume'] == 0) {
             continue;
         }
         $id = $ticker['exchange'] . "_" . $ticker['currency1'] . $ticker['currency2'] . "_daily";
         $data[$ticker['exchange']] = array("<a href=\"" . htmlspecialchars(url_for('historical', array('id' => $id, 'days' => 180))) . "\">" . get_exchange_name($ticker['exchange']) . "</a>", $this->average_currency_format_html($ticker['last_trade'], $ticker['last_trade']), currency_format($volume_currency, $ticker['volume'], 0) . " (" . ($average['volume'] == 0 ? "-" : number_format($ticker['volume'] * 100 / $average['volume']) . "%") . ")");
     }
     $last_updated = $average['created_at'];
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated, 'h1' => get_currency_abbr($average['currency1']) . "/" . get_currency_abbr($average['currency2']) . ": " . currency_format($average['currency1'], $average['last_trade']), 'h2' => "(" . number_format($average['volume']) . " " . get_currency_abbr($volume_currency) . " total volume)");
 }
示例#15
0
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'date', 'title' => ct("Date"));
     $columns = $this->getTickerColumns();
     // TODO extra_days_necessary
     $extra_days = 10;
     $sources = $this->getTickerSources($days, $extra_days);
     $args = $this->getTickerArgs();
     $data = array();
     $last_updated = false;
     foreach ($sources as $source) {
         $q = db()->prepare($source['query']);
         $q->execute($args);
         while ($ticker = $q->fetch()) {
             $data_key = date($this->isDaily() ? 'Y-m-d' : 'Y-m-d H:i:s', strtotime($ticker[$source['key']]));
             $data[$data_key] = $this->getTickerData($ticker);
             $last_updated = max($last_updated, strtotime($ticker['created_at']));
         }
     }
     // sort by key, but we only want values
     uksort($data, 'cmp_time_reverse');
     return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated);
 }
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'date', 'title' => ct("Date"));
     // $columns = $this->getTickerColumns();
     // TODO extra_days_necessary
     $extra_days = 10;
     $sources = $this->getCompositionSources($days, $extra_days);
     $args = $this->getCompositionArgs();
     $data = array();
     $last_updated = false;
     $exchanges_found = array();
     $maximum_balances = array();
     // only used to check for non-zero accounts
     $data_temp = array();
     $hide_missing_data = !require_get("debug_show_missing_data", false);
     $latest = array();
     foreach ($sources as $source) {
         $q = db()->prepare($source['query']);
         $q->execute($args);
         while ($ticker = $q->fetch()) {
             $key = date('Y-m-d', strtotime($ticker[$source['key']]));
             if (!isset($data_temp[$key])) {
                 $data_temp[$key] = array();
             }
             if (!isset($data_temp[$key][$ticker['exchange']])) {
                 $data_temp[$key][$ticker['exchange']] = 0;
             }
             $data_temp[$key][$ticker['exchange']] += $ticker[$source['balance_key']];
             $last_updated = max($last_updated, strtotime($ticker['created_at']));
             $exchanges_found[$ticker['exchange']] = $ticker['exchange'];
             if (!isset($maximum_balances[$ticker['exchange']])) {
                 $maximum_balances[$ticker['exchange']] = 0;
             }
             $maximum_balances[$ticker['exchange']] = max($ticker[$source['balance_key']], $maximum_balances[$ticker['exchange']]);
             if (!isset($latest[$ticker['exchange']])) {
                 $latest[$ticker['exchange']] = 0;
             }
             $latest[$ticker['exchange']] = max($latest[$ticker['exchange']], strtotime($ticker[$source['key']]));
         }
     }
     // get rid of any exchange summaries that had zero data
     foreach ($maximum_balances as $key => $balance) {
         if ($balance == 0) {
             foreach ($data_temp as $dt_key => $values) {
                 unset($data_temp[$dt_key][$key]);
             }
             unset($exchanges_found[$key]);
         }
     }
     // sort by date so we can get previous dates if necessary for missing data
     ksort($data_temp);
     $data = array();
     // add headings after we know how many exchanges we've found
     $first_heading = array('title' => t("Date"));
     $headings = array($first_heading);
     $i = 0;
     // sort them so they're always in the same order
     ksort($exchanges_found);
     foreach ($exchanges_found as $key => $ignored) {
         $headings[$key] = array('title' => $this->getHeadingTitle($key, $args));
     }
     // $data[0] = $headings;
     // add '0' for exchanges that we've found at one point, but don't have a data point
     // but reset to '0' for exchanges that are no longer present (i.e. from graph_data_balances archives)
     // this fixes a bug where old securities data is still displayed as present in long historical graphs
     $previous_row = array();
     foreach ($data_temp as $date => $values) {
         $row = array();
         foreach ($exchanges_found as $key => $ignored) {
             if (!$hide_missing_data || strtotime($date) <= $latest[$key]) {
                 if (!isset($values[$key])) {
                     $row[$key] = graph_number_format(isset($previous_row[$key]) ? $previous_row[$key] : 0);
                 } else {
                     $row[$key] = graph_number_format(demo_scale($values[$key]));
                 }
             } else {
                 $row[$key] = graph_number_format(0);
             }
         }
         if (count($row) > 0) {
             // don't add empty rows
             $data[$date] = $row;
             $previous_row = $row;
         }
     }
     // sort each row by the biggest value in the most recent data
     // so e.g. BTC comes first, LTC comes second, regardless of order of summary_instances, balances etc
     $keys = array_keys($data);
     // we can only sort if we actually have data
     if (count($keys) == 0) {
         // bail early
         throw new NoDataGraphException_AddCurrencies();
     }
     $last_row = $data[$keys[count($keys) - 1]];
     arsort($last_row);
     $data_temp = array();
     foreach ($data as $row => $columns) {
         $temp = array();
         foreach ($last_row as $key => $ignored) {
             $temp[$key] = $columns[$key];
         }
         $data_temp[$row] = $temp;
     }
     $data = $data_temp;
     // convert columns and data into numeric indices
     $result_columns = array();
     $result_column_map = array();
     foreach ($columns as $key => $column) {
         $result_columns[] = array('type' => 'number', 'title' => $this->getHeadingTitle($key, $args));
         // if the key is a currency, use the same currency colour across all graphs
         if (in_array(strtolower($key), get_all_currencies())) {
             $result_columns[count($result_columns) - 1]['color'] = array_search(strtolower($key), get_all_currencies());
         }
         $result_column_map[$key] = count($result_columns) - 1;
     }
     $result_data = array();
     foreach ($data as $date => $row) {
         $new_row = array();
         foreach ($row as $key => $value) {
             $new_row[$result_column_map[$key]] = $value;
         }
         $result_data[$date] = $new_row;
     }
     // find the last row, and calculate its total for later
     $last_row = array();
     $last_row_total = 0;
     foreach ($result_data as $date => $row) {
         $last_row = $row;
     }
     foreach ($row as $value) {
         $last_row_total += $value;
     }
     // sort the last row, and then use this new order to resort all
     // of the columns and data
     arsort($last_row);
     $sorted_columns = array();
     $sorted_data = array();
     foreach ($last_row as $i => $ignored) {
         $sorted_columns[] = $result_columns[$i];
     }
     foreach ($result_data as $date => $rows) {
         $sorted_row = array();
         foreach ($last_row as $i => $ignored) {
             $sorted_row[] = $rows[$i];
         }
         $sorted_rows[$date] = $sorted_row;
     }
     return array('key' => $key_column, 'columns' => $sorted_columns, 'data' => $sorted_rows, 'last_updated' => $last_updated, 'last_row_total' => $last_row_total);
 }
function print_report()
{
    $OUTPUT = clean_html(financialStatements::trialbal($_POST));
    switch ($_POST["key"]) {
        case ct("Print"):
            require "../tmpl-print.php";
            break;
        case ct("Save"):
            db_conn("core");
            $sql = "INSERT INTO save_trial_bal (output, gendate, div) VALUES ('" . base64_encode($OUTPUT) . "', current_date, '" . USER_DIV . "')";
            $svincRslt = db_exec($sql) or errDie("Unable to save the trial balance to Cubit.");
            return "\n\t\t\t\t<li>Trial Balance has been successfully saved to Cubit.</li>\n\t\t\t\t<table " . TMPL_tblDflts . " width='25%'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>Quick Links</th>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t<td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t<td align='center'><a href='index-reports.php'>Financials</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t<td align='center'><a href='index-reports-stmnt.php'>Current Year Financial Statements</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr class='datacell'>\n\t\t\t\t\t\t<td align='center'><a href='../main.php'>Main Menu</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>";
            break;
        case ct("Export to Spreadsheet"):
            require_lib("xls");
            StreamXLS("trial_balance", $OUTPUT);
            break;
    }
}
示例#18
0
<?php

echo ct("Hello");
echo urlencode("World");
echo t("Cat");
echo u("Ignored");
echo ht("Ignored");
echo plural("book", 5);
示例#19
0
 public function getTitle()
 {
     return ct("Equivalent :currency");
 }
示例#20
0
function api_v1_graphs($graph)
{
    $start_time = microtime(true);
    $result = array();
    /**
     * Graph rendering goes like this:
     * 0. check graph rendering permissions
     * 1. get raw graph data (from a {@link GraphRenderer} through {@link construct_graph_renderer()})
     * 2. apply deltas as necessary
     * 3. add technicals as necessary
     * 4. strip dates outside of the requested ?days parameter (e.g. from extra_days)
     * 5. construct heading and links
     * 6. construct subheading and revise last_updated
     * 7. return data
     * that is, deltas and technicals are done on the server-side; not the client-side.
     */
    $renderer = construct_graph_renderer($graph['graph_type'], $graph['arg0'], $graph['arg0_resolved']);
    // 0. check graph rendering permissions
    if ($renderer->requiresUser()) {
        if (!isset($graph['user_id']) || !$graph['user_id']) {
            throw new GraphException("No user specified for authenticated graph");
        }
        if (!isset($graph['user_hash']) || !$graph['user_hash']) {
            throw new GraphException("No user hash specified for authenticated graph");
        }
        $user = get_user($graph['user_id']);
        if (!$user) {
            throw new GraphException("No such user found");
        }
        if (!has_expected_user_graph_hash($graph['user_hash'], $user)) {
            throw new GraphException("Mismatched user hash for user " . $graph['user_id'] . " with graph type " . $graph['graph_type']);
        }
        if ($renderer->requiresAdmin()) {
            if (!$user['is_admin']) {
                throw new GraphException("Graph requires administrator privileges");
            }
        }
        $renderer->setUser($user['id']);
    }
    if ($renderer->usesDays()) {
        // 0.5 limit 'days' parameter as necessary
        $get_permitted_days = get_permitted_days();
        $has_valid_days = false;
        foreach ($get_permitted_days as $key => $days) {
            if ($days['days'] == $graph['days']) {
                $has_valid_days = true;
            }
        }
        if (!$has_valid_days) {
            throw new GraphException("Invalid days '" . $graph['days'] . "' for graph that requires days");
        }
    }
    // 1. get raw graph data
    try {
        $data = $renderer->getData($graph['days']);
        $original_count = count($data['data']);
        $result['type'] = $renderer->getChartType();
        // 2. apply deltas as necessary
        $data['data'] = calculate_graph_deltas($graph, $data['data'], false);
        // if there is no data, bail out early
        if (count($data['data']) == 0) {
            $result['type'] = 'nodata';
        } else {
            if ($renderer->canHaveTechnicals()) {
                // 3. add technicals as necessary
                // (only if there is at least one point of data, otherwise calculate_technicals() will throw an error)
                $technicals = calculate_technicals($graph, $data['data'], $data['columns'], false);
                $data['columns'] = $technicals['headings'];
                $data['data'] = $technicals['data'];
            }
        }
        // 4. discard early data
        if ($renderer->usesDays()) {
            $data['data'] = discard_early_data($data['data'], $graph['days']);
            $after_discard_count = count($data['data']);
        }
        $result['columns'] = $data['columns'];
        $result['key'] = $data['key'];
        $result['data'] = $data['data'];
        // clean up columns
        foreach ($result['columns'] as $key => $value) {
            $result['columns'][$key]['technical'] = isset($result['columns'][$key]['technical']) && $result['columns'][$key]['technical'] ? true : false;
            if ($result['columns'][$key]['technical']) {
                if (!isset($result['columns'][$key]['type'])) {
                    $result['columns'][$key]['type'] = 'number';
                }
            }
        }
    } catch (NoDataGraphException_AddAccountsAddresses $e) {
        $result['type'] = 'nodata';
        $result['text'] = ct("Either you have not specified any accounts or addresses, or these addresses and accounts have not yet been updated by :site_name.");
        $result['args'] = array(':site_name' => get_site_config('site_name'));
        $result['data'] = array();
        $data['last_updated'] = false;
        $data['add_accounts_addresses'] = true;
    } catch (NoDataGraphException_AddCurrencies $e) {
        $result['type'] = 'nodata';
        $result['text'] = ct("Either you have not enabled this currency, or your summaries for this currency have not yet been updated by :site_name.");
        $result['args'] = array(':site_name' => get_site_config('site_name'));
        $result['data'] = array();
        $data['last_updated'] = false;
        $data['add_more_currencies'] = true;
    }
    // 5. construct heading and links
    $result['heading'] = array('label' => $renderer->getTitle(), 'args' => $renderer->getTitleArgs(), 'url' => $renderer->getURL(), 'title' => $renderer->getLabel());
    if (isset($data['h1'])) {
        $result['h1'] = $data['h1'];
    }
    if (isset($data['h2'])) {
        $result['h2'] = $data['h2'];
    }
    if (isset($data['no_header'])) {
        $result['noHeader'] = $data['no_header'];
    }
    // 6. construct subheading and revise last_updated\
    if ($result['type'] != 'nodata' && $renderer->hasSubheading()) {
        $suffix = "";
        if ($graph['delta'] == 'percent') {
            $suffix .= '%';
        }
        if ($renderer->getCustomSubheading() !== false) {
            $result['subheading'] = number_format_html($renderer->getCustomSubheading(), 4, $suffix);
        } else {
            if ($result['type'] == 'piechart') {
                // sum up the first row and use that as a total
                if (count($data['data']) != 1) {
                    throw new GraphException("Expected one row of data for a piechart, got " . count($data['data']));
                }
                $sum = 0;
                foreach ($data['data'] as $ignored => $row) {
                    foreach ($row as $value) {
                        $sum += $value;
                    }
                }
                $result['subheading'] = number_format_html($sum, 4, $suffix);
            } else {
                $result['subheading'] = format_subheading_values_objects($graph, $data['data'], $data['columns']);
            }
        }
    }
    $result['lastUpdated'] = recent_format_html($data['last_updated']);
    $result['timestamp'] = iso_date();
    $result['classes'] = $renderer->getClasses();
    $result['graph_type'] = $graph['graph_type'];
    if (is_localhost()) {
        $result['_debug'] = $graph;
        if (isset($after_discard_count)) {
            $result['_debug']['data_discarded'] = $original_count - $after_discard_count;
        } else {
            $result['_debug']['data_not_discarded'] = true;
        }
    }
    // make sure that all 'number'-typed data is numeric
    foreach ($result['data'] as $i => $row) {
        foreach ($row as $key => $value) {
            $column = $result['columns'][$key];
            if ($column['type'] == 'number' || $column['type'] == 'percent') {
                $result['data'][$i][$key] = (double) $value;
                if (is_localhost()) {
                    $result['_debug']['number_formatted'] = true;
                }
            }
        }
    }
    // make sure that all data rows are numeric arrays and not objects
    // i.e. reindex everything to be numeric arrays, so they aren't output as JSON objects
    foreach ($result['data'] as $i => $row) {
        $new_row = array_values($row);
        foreach ($row as $key => $value) {
            $new_row[$key] = $value;
        }
        $result['data'][$i] = $new_row;
    }
    // format any extra text from the result
    if (isset($data['add_more_currencies'])) {
        $result['extra'] = array('classes' => 'add_accounts', 'href' => url_for('wizard_currencies'), 'label' => ct("Add more currencies"), 'args' => array());
    }
    if (isset($data['add_accounts_addresses'])) {
        $result['extra'] = array('classes' => 'add_accounts', 'href' => url_for('wizard_accounts'), 'label' => ct("Add accounts and addresses"), 'args' => array());
    }
    // 7. calculate if the graph data may be out of date
    if ($renderer->requiresUser() && $renderer->getUser()) {
        $user = get_user($renderer->getUser());
        if ($user && $renderer->usesSummaries() && (!$user['has_added_account'] || !$user['is_first_report_sent'] || strtotime($user['last_account_change']) > strtotime($user['last_sum_job']))) {
            $result['outofdate'] = true;
        }
    }
    $end_time = microtime(true);
    $time_diff = ($end_time - $start_time) * 1000;
    $result['time'] = (double) number_format_autoprecision($time_diff, 1, '.', '');
    $result['hash'] = $graph['hash'];
    // 7. return data
    return $result;
}
示例#21
0
function cw($input)
{
    return ct()->write($input);
}
 function getData($days)
 {
     $original = parent::getData($days);
     $original['columns'][0]['title'] = ct("MH/s");
     return $original;
 }
示例#23
0
 public function getTitle()
 {
     return ct("Total :currency");
 }
 /**
  * Used by balance sheet to calculate profit/loss
  *
  * @param bool $ytdate whether we should calculate a month only or year to date
  * @param int $month_to last month end mond
  * @param string $prevyear yrdb for last year balance
  * @return float
  */
 static function balsheet_GetProfitLoss($ytdate, $month_to = false, $prevyear = false)
 {
     global $PRDMON;
     if ($month_to === false) {
         $month_to = $PRDMON[12];
     }
     if ($ytdate === false) {
         $TPF = "_actual";
     } else {
         $TPF = "";
     }
     if ($prevyear == false) {
         $SCHEMA = "core";
     } else {
         $SCHEMA = "{$prevyear}";
     }
     db_conn("core");
     $sql = "SELECT * FROM accounts\n\t\t\t\tWHERE (acctype='I' OR acctype='E') AND accnum='000' AND div='" . USER_DIV . "'";
     $accRslt = db_exec($sql) or errDie(ct("Unable to retrieve the sales/cost of sales accounts from Cubit."));
     $sales_total = 0;
     $cost_of_sales_total = 0;
     $other_income_total = 0;
     $expenses_total = 0;
     while ($accData = pg_fetch_array($accRslt)) {
         // Retrieve the amounts from the trial_bal
         $sql = "SELECT debit, credit FROM \"{$SCHEMA}\".trial_bal{$TPF}\n\t\t\t\t\tWHERE topacc='{$accData['topacc']}' AND accnum='000'\n\t\t\t\t\t\tAND div='" . USER_DIV . "' AND month='{$month_to}'";
         $tbRslt = db_exec($sql) or errDie(ct("Unable to retrieve the sales/cost of sales amounts from Cubit."));
         $tbData = pg_fetch_array($tbRslt);
         if ($accData["acctype"] == "I" && $accData["toptype"] == "" || $accData["toptype"] == "other_income") {
             $other_income_total += $tbData["credit"] - $tbData["debit"];
             $sql = "SELECT debit, credit FROM \"{$SCHEMA}\".trial_bal{$TPF}\n\t\t\t\t\t\tWHERE topacc='{$accData['topacc']}' AND accnum!='000' AND month='{$month_to}'";
             $stbRslt = db_exec($sql) or errDie(ct("Unable to retrieve sub account information from Cubit."));
             while ($stbData = pg_fetch_array($stbRslt)) {
                 $other_income_total += $stbData["credit"] - $stbData["debit"];
             }
         } elseif ($accData["toptype"] == "cost_of_sales") {
             $cost_of_sales_total += $tbData["debit"] - $tbData["credit"];
             $sql = "SELECT debit, credit FROM \"{$SCHEMA}\".trial_bal{$TPF}\n\t\t\t\t\t\tWHERE topacc='{$accData['topacc']}' AND accnum!='000' AND month='{$month_to}'";
             $stbRslt = db_exec($sql) or errDie(ct("Unable to retrieve sub account information from Cubit."));
             while ($stbData = pg_fetch_array($stbRslt)) {
                 $cost_of_sales_total += $stbData["debit"] - $stbData["credit"];
             }
         } else {
             if ($accData["toptype"] == "sales") {
                 $sales_total += $tbData["credit"] - $tbData["debit"];
                 $sql = "SELECT debit, credit FROM \"{$SCHEMA}\".trial_bal{$TPF}\n\t\t\t\t\t\tWHERE topacc='{$accData['topacc']}' AND accnum!='000' AND month='{$month_to}'";
                 $stbRslt = db_exec($sql) or errDie(ct("Unable to retrieve sub account information from Cubit."));
                 while ($stbData = pg_fetch_array($stbRslt)) {
                     $sales_total += $stbData["credit"] - $stbData["debit"];
                 }
             } else {
                 if ($accData["acctype"] == "E" && $accData["toptype"] == "" || $accData["toptype"] == "expenses") {
                     $expenses_total += $tbData["debit"] - $tbData["credit"];
                     $sql = "SELECT debit, credit FROM \"{$SCHEMA}\".trial_bal{$TPF}\n\t\t\t\t\t\tWHERE topacc='{$accData['topacc']}' AND accnum!='000'\n\t\t\t\t\t\t\tAND month='{$month_to}'";
                     $stbRslt = db_exec($sql) or errDie(ct("Unable to retrieve sub account information from Cubit."));
                     while ($stbData = pg_fetch_array($stbRslt)) {
                         $expenses_total += $stbData["debit"] - $stbData["credit"];
                     }
                 }
             }
         }
     }
     // Retrieve tax
     db_conn("core");
     $sql = "SELECT debit, credit FROM \"{$SCHEMA}\".trial_bal{$TPF}\n\t\t\t\tWHERE topacc='2800' AND accnum='000' AND month='{$month_to}'";
     $taxRslt = db_exec($sql) or errDie(ct("Unable to retrieve normal tax from Cubit."));
     $tax_ar = pg_fetch_array($taxRslt, 0);
     $tax = $tax_ar["debit"] - $tax_ar["credit"];
     $plt = sprint($sales_total - $cost_of_sales_total + $other_income_total - $expenses_total - $tax);
     return $plt;
 }
示例#25
0
 public function getData($days)
 {
     $key_column = array('type' => 'string', 'title' => ct("Currency"));
     $columns = array();
     $last_updated = false;
     $columns[] = array('type' => 'string', 'title' => "", 'heading' => true);
     // a matrix table of each currency vs. each currency, and their current
     // last_trade and volume on each exchange the user is interested in
     $currencies = get_all_currencies();
     $summaries = get_all_summary_currencies($this->getUser());
     $conversion = get_all_conversion_currencies($this->getUser());
     $graph["last_updated"] = 0;
     $interested = array();
     foreach ($currencies as $c) {
         if (isset($summaries[$c])) {
             $interested[] = $c;
             $columns[] = array('type' => 'string', 'title' => get_currency_abbr($c));
         }
     }
     foreach ($interested as $c1) {
         $row = array(get_currency_abbr($c1));
         foreach ($interested as $c2) {
             // go through each exchange pair
             $cell = "";
             foreach (get_exchange_pairs() as $exchange => $pairs) {
                 foreach ($pairs as $pair) {
                     if ($c1 == $pair[0] && $c2 == $pair[1]) {
                         $q = db()->prepare("SELECT * FROM ticker_recent WHERE exchange=? AND currency1=? AND currency2=? LIMIT 1");
                         $q->execute(array($exchange, $c1, $c2));
                         if ($ticker = $q->fetch()) {
                             // TODO currency_format should be a graph option
                             $exchange_short = strlen($exchange) > 8 ? substr($exchange, 0, 7) . "..." : $exchange;
                             $cell .= "<li><span class=\"rate\">" . number_format_html($ticker['last_trade'], 4) . "</span> " . ($ticker['volume'] == 0 ? "" : "<span class=\"volume\">(" . number_format_html($ticker['volume'], 4) . ")</span>");
                             $cell .= " <span class=\"exchange\" title=\"" . htmlspecialchars(get_exchange_name($exchange)) . "\">[" . htmlspecialchars($exchange_short) . "]</span>";
                             $cell .= "</li>\n";
                             $last_updated = max($last_updated, strtotime($ticker['created_at']));
                         } else {
                             $cell .= "<li class=\"warning\">" . t("Could not find rate for :exchange: :pair", array(':exchange' => $exchange, ':pair' => $c1 . "/" . $c2)) . "</li>\n";
                         }
                     }
                 }
             }
             if ($cell) {
                 $cell = "<ul class=\"rate_matrix\">" . $cell . "</ul>";
             }
             $row[] = $cell;
         }
         $data[] = $row;
     }
     // now delete any empty rows or columns
     // columns
     $deleteRows = array();
     $deleteColumns = array();
     for ($i = 0; $i < count($data) - 1; $i++) {
         $empty = true;
         for ($j = 1; $j < count($data[$i]); $j++) {
             if ($data[$i][$j]) {
                 $empty = false;
                 break;
             }
         }
         if ($empty) {
             $deleteRows[] = $i;
         }
     }
     for ($i = 1; $i < count($data); $i++) {
         $empty = true;
         for ($j = 0; $j < count($data[$i]) - 1; $j++) {
             if ($data[$j][$i]) {
                 $empty = false;
                 break;
             }
         }
         if ($empty) {
             $deleteColumns[] = $i;
         }
     }
     $new_data = array();
     foreach ($data as $i => $row) {
         if (in_array($i, $deleteRows)) {
             continue;
         }
         $x = array();
         foreach ($data[$i] as $j => $cell) {
             if (in_array($j, $deleteColumns)) {
                 continue;
             }
             $x[] = $cell;
         }
         $new_data[] = $x;
     }
     foreach ($deleteColumns as $i) {
         unset($columns[$i]);
     }
     $columns = array_values($columns);
     return array('key' => $key_column, 'columns' => $columns, 'data' => $new_data, 'last_updated' => $last_updated, 'add_more_currencies' => true);
 }
示例#26
0
 public function getTitle()
 {
     return ct("All :currency balances");
 }
示例#27
0
文件: map.php 项目: beyondye/ENPHP
?>
</a>&gt;<?php 
echo '<a href="/map">' . $sMap . '</a>';
?>
</p>
                
                <b id="lt"><i><?php 
echo $sMap . ($nCurr > 1 ? '第' . $nCurr . '页' : '');
?>
</i></b>
                <div>
                    <?php 
if (!empty($aList)) {
    foreach ($aList as $n => $a) {
        if (isset($aTxt[$a['id']])) {
            echo '<i' . (empty($a['pic']) ? '' : ' class="p"') . '><em>' . date('Y-m-d', $a['ctime']) . '</em><a href="/' . $a['id'] . '">' . $a['title'] . '</a>' . (empty($a['pic']) ? '' : '<img src="' . $a['pic'] . '" alt="' . $a['title'] . '" />') . ct($aTxt[$a['id']]['txt'], 300) . '</i>';
        } else {
            echo '<a href="/' . $a['id'] . '">' . $a['title'] . '</a><em>' . date('Y-m-d', $a['ctime']) . '</em>';
        }
    }
} else {
    echo '抱歉,暂无相关资料……';
}
?>
                </div>
                <p id="pg"><?php 
echo $sPG;
?>
</p>
            </dd>
            <dt><div id="a1"><script>a(1)</script></div><script>d()</script><div id="a2"><script>a(2)</script></div>
 function getTitle()
 {
     $bits = explode("_", $this->summary_type, 2);
     $this->exchange = $bits[1];
     return ct("Converted :currency (:exchange)");
 }
 function getTitle()
 {
     return ct("Converted :currency");
 }
function print_supp($errors = "")
{
    global $_POST;
    extract($_POST);
    if (!isset($fdate_day)) {
        $fdate_day = "01";
    }
    if (!isset($fdate_month)) {
        $fdate_month = date("m");
    }
    if (!isset($fdate_year)) {
        $fdate_year = date("Y");
    }
    if (!isset($tdate_day)) {
        $tdate_day = date("d");
    }
    if (!isset($tdate_month)) {
        $tdate_month = date("m");
    }
    if (!isset($tdate_year)) {
        $tdate_year = date("Y");
    }
    $fdate = "{$fdate_year}-{$fdate_month}-{$fdate_day}";
    $tdate = "{$tdate_year}-{$tdate_month}-{$tdate_day}";
    # Set up table to display in
    $printSupp = "\n\t\t\t\t\t<center>\n\t\t\t\t    <h3>Current Supplier Transactions</h3>\n\t\t\t\t\t<form method='POST' action='" . SELF . "'>\n\t\t\t\t\t\t<input type='hidden' name='key' value='printSupp'>\n\t\t\t\t\t\t<input type='hidden' name='search' value='true'>\n\t\t\t\t\t<table " . TMPL_tblDflts . ">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='5'>Date Range</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><b>From </b></td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t" . mkDateSelect("fdate", $fdate_year, $fdate_month, $fdate_day) . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td><b> To </b></td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t" . mkDateSelect("tdate", $tdate_year, $tdate_month, $tdate_day) . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td><input type='submit' value='View &raquo'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t\t</form>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='500'>";
    # connect to database
    db_connect();
    # Query server
    $i = 0;
    $sql = "SELECT * FROM suppliers WHERE div = '" . USER_DIV . "' ORDER BY supid ASC";
    $suppRslt = db_exec($sql) or errDie("Unable to retrieve Suppliers from database.");
    if (pg_numrows($suppRslt) < 1) {
        return "\n\t\t\t\t\t<li>There are no Suppliers in Cubit.</li>\n\t\t\t\t\t<table " . TMPL_tblDflts . " width='15%'>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>" . ct("Quick Links") . "</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td><a href='supp-view.php'>" . ct("View Suppliers") . "</a></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t\t</table>";
    }
    if (!isset($search)) {
        $search = "";
    }
    if ($search) {
        while ($supp = pg_fetch_array($suppRslt)) {
            # get department
            db_conn("exten");
            $sql = "SELECT * FROM departments WHERE deptid = '{$supp['deptid']}' AND div = '" . USER_DIV . "'";
            $deptRslt = db_exec($sql);
            if (pg_numrows($deptRslt) < 1) {
                $deptname = "<li class=err>" . ct("Department not Found.") . "";
            } else {
                $dept = pg_fetch_array($deptRslt);
                $deptname = $dept['deptname'];
            }
            if ($supp['location'] == 'int') {
                $cur = $supp['currency'];
                $bal = "fbalance";
            } else {
                $cur = CUR;
                $bal = "balance";
            }
            $printSupp .= "\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td colspan='10'>{$supp['supno']} - {$supp['supname']}  <b>{$cur} {$supp[$bal]}</b></td>\n\t\t\t\t\t\t</tr>";
            # connect to database
            db_connect();
            $stmnt = "";
            $totout = 0;
            # Query server
            $sql = "SELECT * FROM sup_stmnt WHERE supid = '{$supp['supid']}' AND edate >= '{$fdate}' AND edate <= '{$tdate}' AND div = '" . USER_DIV . "' ORDER BY edate ASC";
            $stRslt = db_exec($sql) or errDie("Unable to retrieve invoices statement from database.");
            if (pg_numrows($stRslt) < 1) {
                $stmnt .= "\n\t\t\t\t\t\t<tr  class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td colspan='10'>" . ct("No transactions found for the current date range.") . "</td>\n\t\t\t\t\t\t</tr>";
            } else {
                while ($st = pg_fetch_array($stRslt)) {
                    # Accounts details
                    if ($st['cacc'] > 0) {
                        $accRs = get("core", "*", "accounts", "accid", $st['cacc']);
                        if (pg_numrows($accRs) < 1) {
                            $acc['accname'] = "No Account.";
                            $acc['topacc'] = "000";
                            $acc['accnum'] = "000";
                        } else {
                            $acc = pg_fetch_array($accRs);
                        }
                    } else {
                        $acc['accname'] = "No Account.";
                        $acc['topacc'] = "000";
                        $acc['accnum'] = "000";
                    }
                    # format date
                    $st['edate'] = explode("-", $st['edate']);
                    $st['edate'] = $st['edate'][2] . "-" . $st['edate'][1] . "-" . $st['edate'][0];
                    $st['amount'] = sprint($st['amount']);
                    $stmnt .= "\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td align='center'>{$st['edate']}</td>\n\t\t\t\t\t\t\t\t\t<td>{$st['ref']}</td>\n\t\t\t\t\t\t\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t\t\t\t\t\t<td>{$st['descript']}</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>{$cur} {$st['amount']}</td>\n\t\t\t\t\t\t\t\t</tr>";
                    # keep track of da totals
                    $totout += $st['amount'];
                }
            }
            $printSupp .= $stmnt . "<tr><td><br><br></td></tr>";
        }
    }
    $printSupp .= "\n\t\t\t\t\t\t</table>\n\t\t\t\t\t\t<form method='POST' action='xls/supp-tran-rep-xls.php'>\n\t\t\t\t\t\t\t<input type='hidden' name='key' value='printSupp'>\n\t\t\t\t\t\t\t<input type='hidden' name='fdate_day' value='{$fdate_day}'>\n\t\t\t\t\t\t\t<input type='hidden' name='fdate_month' value='{$fdate_month}'>\n\t\t\t\t\t\t\t<input type='hidden' name='fdate_year' value='{$fdate_year}'>\n\t\t\t\t\t\t\t<input type='hidden' name='tdate_day' value='{$tdate_day}'>\n\t\t\t\t\t\t\t<input type='hidden' name='tdate_month' value='{$tdate_month}'>\n\t\t\t\t\t\t\t<input type='hidden' name='tdate_year' value='{$tdate_year}'>\n\t\t\t\t\t\t\t<center><input type='submit' value='Export to Spreadsheet'></center>\n\t\t\t\t\t\t<p>\n\t\t\t\t\t\t<table " . TMPL_tblDflts . " width='15%'>\n\t\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<th>" . ct("Quick Links") . "</th>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td><a href='supp-view.php'>" . ct("View Suppliers") . "</a></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</center>";
    return $printSupp;
}