Topic: Edit Journal -> orphaned attachments.

FA 2.4.1 - If you create a journal entry, attach a document, and then later edit the journal entry (e.g. journal enquiry - edit), the old journal number is voided, and a new journal number created.  However, the attachment data is NOT updated, so the document is orphaned, and the journal no longer is associated to the document, so doesn't list it for viewing.

The FIX:  (in gl/gl_journal.php)
Line 298:
if (isset($_POST['Process']))
{
        $cart = &$_SESSION['journal_items'];
        $new = $cart->order_id == 0;
                /***************
                * Start of fix for orphaned attachments
                ***************/
        $old_trans_type = $cart->trans_type;
        $old_trans_no = $cart->order_id;
                /***************/

new line 342:
        unset($_SESSION['journal_items']);
                /*********************************************
                * original code does not update attachments.
                * The old trans no is zero'd/marked voided and a new trans created
                * This leads to an orphaned transaction. 
                *
                * Update attachment info
                ***********************************************/
        if( isset( $old_trans_no ) )
        {
                $sql = "UPDATE " . TB_PREF . "attachments SET `trans_no` = '" . $trans_no . "' WHERE trans_no = '" . $old_trans_no . "' and type_no = '" . $old_trans_type . "'";
                db_query( $sql, "Couldn't update attachments" );
        }
                /***************/

I have not checked the other functions (i.e. bank payments/deposits, etc) but expect they are similar.  I did see void_transaction function then calls different void_XXX_trans functions so didn't chase down the rabbit hole.  If they all call the db HOOKs calls this could be made into a module but I didn't chase that neither.

Re: Edit Journal -> orphaned attachments.

I will check this asap.

Joe

Re: Edit Journal -> orphaned attachments.

This has now been fixed, but not in file /gl/gl_journal.php. It was better to fix it in /gl/includes/db/gl_journal.inc in function write_journal_transaction.

You can download the fixed file here and replace it /gl/includes/db/gl_journal.inc.

Thank you for pointing this our. There were no errors in the bank payment/deposit routines.

Joe

Re: Edit Journal -> orphaned attachments.

@joe you mean to say function write_journal_entries (instead of write_journal_transaction)

Re: Edit Journal -> orphaned attachments.

Yes, of course you are right. Sorry for the typo. Thanks for the correction.

Joe