Fixed bank transaction dition problem (bank transaction balance check should be perfo...
[fa-stable.git] / gl / includes / db / gl_db_banking.inc
index 41879225587e638e572495105daed95d58509019..4a88583a24a73138d080699f128edbbfa5f934ae 100644 (file)
@@ -306,10 +306,11 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
                'person_type_id', 'person_id', 'person_detail_id', 'ref', 'memo_', 'use_transaction'),
                $args);
        hook_db_prewrite($args, $trans_type);
-
+       $aid = 0;
        if ($trans_no) {
-               void_transaction($trans_type, $trans_no, Today(), _("Document reentered."));
+               $old_trans = $trans_no;
                $Refs->restore_last($trans_type, $trans_no);
+               $aid = has_attachment($trans_type, $trans_no);
        }
 
        $currency = get_bank_account_currency($from_account);
@@ -351,7 +352,12 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
        if ($do_exchange_variance)
                $trans_no1 = get_next_trans_no(ST_JOURNAL);
     }
-
+       if ($aid != 0)
+       {
+               $row = get_attachment($aid);
+               update_attachment($aid, $row['type_no'], $trans_no, $row['description'],
+                       $row['filename'], $row['unique_name'], $row['filesize'], $row['filetype']);
+       }
        // do the source account postings
 
     add_bank_trans($trans_type, $trans_no, $from_account, $ref,
@@ -416,6 +422,11 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
        $Refs->save($trans_type, $trans_no, $ref);
        add_audit_trail($trans_type, $trans_no, $date_);
 
+       // old transaction can be voided only after new transaction is entered,
+       //  otherwise the operation could fail for cash accounts due to temporary negative balance
+       if (@$old_trans) 
+                       void_transaction($trans_type, $old_trans, Today(), _("Document reentered."));
+
        $args->trans_no = $trans_no;
        hook_db_postwrite($args, $trans_type);
        if ($use_transaction)