+ if ($dimension != 0)
+ $sql .= " AND dimension_id = ".($dimension<0?0:db_escape($dimension));
+ if ($dimension2 != 0)
+ $sql .= " AND dimension2_id = ".($dimension2<0?0:db_escape($dimension2));
+ $result = db_query($sql,"No budget accounts were returned");
+
+ $row = db_fetch_row($result);
+ return $row[0];
+}
+//-------------------------------------------------------------------------------------
+
+function exists_gl_budget($date_, $account, $dimension, $dimension2)
+{
+ $sql = "SELECT account FROM ".TB_PREF."budget_trans WHERE account=".db_escape($account)
+ ." AND tran_date='$date_' AND
+ dimension_id=".db_escape($dimension)." AND dimension2_id=".db_escape($dimension2);
+ $result = db_query($sql, "Cannot retreive a gl transaction");
+
+ return (db_num_rows($result) > 0);
+}
+
+function add_update_gl_budget_trans($date_, $account, $dimension, $dimension2, $amount)
+{
+ $date = date2sql($date_);
+
+ if (exists_gl_budget($date, $account, $dimension, $dimension2))
+ $sql = "UPDATE ".TB_PREF."budget_trans SET amount=".db_escape($amount)
+ ." WHERE account=".db_escape($account)
+ ." AND dimension_id=".db_escape($dimension)
+ ." AND dimension2_id=".db_escape($dimension2)
+ ." AND tran_date='$date'";
+ else
+ $sql = "INSERT INTO ".TB_PREF."budget_trans (tran_date,
+ account, dimension_id, dimension2_id, amount, memo_) VALUES ('$date',
+ ".db_escape($account).", ".db_escape($dimension).", "
+ .db_escape($dimension2).", ".db_escape($amount).", '')";
+
+ db_query($sql, "The GL budget transaction could not be saved");
+}
+
+function delete_gl_budget_trans($date_, $account, $dimension, $dimension2)
+{
+ $date = date2sql($date_);
+
+ $sql = "DELETE FROM ".TB_PREF."budget_trans WHERE account=".db_escape($account)
+ ." AND dimension_id=".db_escape($dimension)
+ ." AND dimension2_id=".db_escape($dimension2)
+ ." AND tran_date='$date'";
+ db_query($sql, "The GL budget transaction could not be deleted");
+}
+
+function get_only_budget_trans_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0)
+{
+
+ $from = date2sql($from_date);
+ $to = date2sql($to_date);
+
+ $sql = "SELECT SUM(amount) FROM ".TB_PREF."budget_trans
+ WHERE account=".db_escape($account)
+ ." AND tran_date >= '$from' AND tran_date <= '$to'
+ AND dimension_id = ".db_escape($dimension)
+ ." AND dimension2_id = ".db_escape($dimension2);