Bug. Edit Journal -> orphaned attachments.
authorJoe <joe.hunt.consulting@gmail.com>
Fri, 15 Mar 2024 11:18:14 +0000 (12:18 +0100)
committerJoe <joe.hunt.consulting@gmail.com>
Fri, 15 Mar 2024 11:18:45 +0000 (12:18 +0100)
gl/includes/db/gl_journal.inc

index 7de137a1f5c6bbe88cb15022067cc0c0195a4fab..88a8553da80448729b6be1e8a37e16f28c6e3596 100644 (file)
@@ -103,6 +103,7 @@ 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);
@@ -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();