0
function get_patient_balance($pid) {
  if ($GLOBALS['oer_config']['ws_accounting']['enabled'] === 2) {
    $brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
      "pid = ? AND billed = 1 AND activity = 1", array($pid) );
    $srow = sqlQuery("SELECT SUM(fee) AS amount FROM drug_sales WHERE " .
      "pid = ?", array($pid) );
    $drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
      "SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
      "pid = ?", array($pid) );
     return sprintf('%01.2f', $brow['amount'] + $srow['amount']
      - $drow['payments'] - $drow['adjustments']);
  }

以上是我正在使用的功能。在此函数中,$brow 从帐单表中创建一个数组。在这个数组中有负数。我希望能够从 SUM(fee) AS 金额中排除这些数字,以便我只加总正数。

4

1 回答 1

1

我希望能够从 SUM(fee) AS 金额中排除这些数字,以便我只加总正数。

所以,您只想添加所有费用> 0,对吗?如果我做对了,我认为这会奏效:

$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND billed = 1 AND activity = 1 and fee > 0", array($pid) );
于 2012-11-23T03:11:53.257 回答