Changed Report Statements to accept selector Outstanding Only
[fa-stable.git] / gl / includes / db / gl_db_bank_trans.inc
index ad369861053d2dc6c47c4f2b62d2cadfe7db7ee7..3face339851f19604b27ac28079165c0ae7c3de5 100644 (file)
@@ -83,6 +83,33 @@ function get_bank_trans($type, $trans_no=null, $person_type_id=null, $person_id=
 
 //----------------------------------------------------------------------------------------
 
+function get_bank_trans_for_bank_account($bank_account, $from, $to)
+{
+       $from = date2sql($from);
+       $to = date2sql($to);
+       $sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
+               WHERE ".TB_PREF."bank_trans.bank_act = ".db_escape($bank_account) . "
+               AND trans_date >= '$from'
+               AND trans_date <= '$to'
+               ORDER BY trans_date,".TB_PREF."bank_trans.id";
+
+       return db_query($sql,"The transactions for '" . $bank_account . "' could not be retrieved");
+}
+
+//----------------------------------------------------------------------------------------
+
+function get_balance_before_for_bank_account($bank_account, $from)
+{
+       $from = date2sql($from);
+       $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act="
+               .db_escape($bank_account) . "
+               AND trans_date < '$from'";
+       $before_qty = db_query($sql, "The starting balance on hand could not be calculated");
+       $bfw_row = db_fetch_row($before_qty);
+       return $bfw_row[0];
+}
+//----------------------------------------------------------------------------------------
+
 function get_gl_trans_value($account, $type, $trans_no)
 {
        $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans WHERE account="
@@ -125,4 +152,38 @@ function void_bank_trans($type, $type_no, $nested=false)
 
 //----------------------------------------------------------------------------------
 
+//----------------------------------------------------------------------------------------
+
+function clear_bank_trans($type, $type_no, $nested=false)
+{
+       global $Refs;
+       
+       if (!$nested)
+               begin_transaction();
+
+       $sql = "DELETE FROM ".TB_PREF."bank_trans 
+               WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
+
+       $result = db_query($sql, "could not clear bank transactions for type=$type and trans_no=$type_no");
+
+       clear_gl_trans($type, $type_no, true);
+
+       // in case it's a customer trans - probably better to check first
+       void_cust_allocations($type, $type_no);
+       clear_customer_trans($type, $type_no);
+
+       // in case it's a supplier trans - probably better to check first
+       void_supp_allocations($type, $type_no);
+       clear_supp_trans($type, $type_no);
+
+       clear_trans_tax_details($type, $type_no);
+
+       //Delete the reference
+       $Refs->delete($type, $type_no); 
+       
+       if (!$nested)
+               commit_transaction();
+}
+
+
 ?>
\ No newline at end of file