Bug. Edit Journal -> orphaned attachments.
[fa-stable.git] / gl / includes / db / gl_journal.inc
index 56ec39c31ab5063209cae4d34d257117af7ff485..88a8553da80448729b6be1e8a37e16f28c6e3596 100644 (file)
@@ -103,9 +103,10 @@ function write_journal_entries(&$cart)
        $memo_ = $cart->memo_;
        $trans_type = $cart->trans_type;
        $new = $cart->order_id == 0;
+       $old_no = $cart->order_id;
 
        begin_transaction();
-
+       hook_db_prewrite($cart, ST_JOURNAL);
        if (!$new)
        {
                $msg = void_transaction($trans_type, $cart->order_id, Today(), _("Document reentered."));
@@ -117,6 +118,18 @@ function write_journal_entries(&$cart)
        }
 
        $trans_id = $cart->order_id = get_next_trans_no($trans_type);
+       if ($old_no)
+       {
+               $aid = 0;
+               $aid = has_attachment($trans_type, $old_no);
+               if ($aid != 0)
+               {
+                       $row = get_attachment($aid);
+                       update_attachment($aid, $row['type_no'], $trans_id, $row['description'],
+                               $row['filename'], $row['unique_name'], $row['filesize'], $row['filetype']);
+               }
+
+       }       
        $total = $cart->gl_items_total_debit();
 
        $cart->write_gl();
@@ -132,7 +145,7 @@ function write_journal_entries(&$cart)
        }
 
        add_audit_trail($trans_type, $trans_id, $date_);
-
+       hook_db_postwrite($cart, ST_JOURNAL);
        commit_transaction();
 
        return $trans_id;