Added journal entries edition, removed reverse transaction je option.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 8 May 2009 10:23:52 +0000 (10:23 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 8 May 2009 10:23:52 +0000 (10:23 +0000)
gl/includes/db/gl_db_trans.inc
gl/includes/ui/gl_journal_ui.inc

index eb9cf02f385f02135ed680e0f57faa5850437393..b077e5d58268ad6b22b710048404283689c3c164 100644 (file)
@@ -307,15 +307,29 @@ function get_tax_summary($from, $to)
 //display_error($sql);
     return db_query($sql,"Cannot retrieve tax summary");
 }
+
 //--------------------------------------------------------------------------------
-function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null)
+// Write/update journal entries.
+//
+function write_journal_entries(&$cart)
 {
-       begin_transaction();
+       $date_ = $cart->tran_date;
+       $ref   = $cart->reference;
+       $memo_ = $cart->memo_;
+       $new = $cart->order_id == 0;
+       $trans_type = $cart->trans_type;
+       $trans_id = $new ? get_next_trans_no($trans_type) : $cart->order_id;
 
-       $trans_type = systypes::journal_entry();
-       $trans_id = get_next_trans_no($trans_type);
+       begin_transaction();
+       
+       if($new) {
+               $cart->order_id = $trans_id;
+       } else {
+               void_journal_trans($trans_type, $trans_id, true);
+               delete_comments($trans_type, $trans_id);
+       }
 
-       foreach ($items as $journal_item)
+       foreach ($cart->gl_items as $journal_item)
        {
                // post to first found bank account using given gl acount code.
                $is_bank_to = is_bank_account($journal_item->code_id);
@@ -326,8 +340,7 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null)
        if ($is_bank_to)
        {
                add_bank_trans($trans_type, $trans_id, $is_bank_to, $ref,
-                       $date_, $journal_item->amount,
-                       0, "", get_company_currency(),
+                       $date_, $journal_item->amount,  0, "", get_company_currency(),
                        "Cannot insert a destination bank transaction");
        }
                // store tax details if the gl account is a tax account
@@ -335,45 +348,14 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null)
                        $trans_type, $trans_id, -$journal_item->amount, 1, $date_, $memo_);
        }
        
-       add_comments($trans_type, $trans_id, $date_, $memo_);
+       if ($new) {
+               add_comments($trans_type, $trans_id, $date_, $memo_);
+               references::save($trans_type, $trans_id, $ref);
+       } else
+               update_comments($trans_type, $trans_id, null, $memo_);
 
-       references::save($trans_type, $trans_id, $ref);
        add_audit_trail($trans_type, $trans_id, $date_);
 
-       if ($reverse)
-       {
-
-       //$reversingDate = date(user_date_display(),
-       //      Mktime(0,0,0,get_month($date_)+1,1,get_year($date_)));
-       $reversingDate = begin_month(add_months($date_, 1));
-
-       $trans_id_reverse = get_next_trans_no($trans_type);
-
-       foreach ($items as $journal_item)
-       {
-                       $is_bank_to = is_bank_account($journal_item->code_id);
-
-               add_gl_trans($trans_type, $trans_id_reverse, $reversingDate,
-                       $journal_item->code_id, $journal_item->dimension_id, $journal_item->dimension2_id,
-                       $journal_item->reference, -$journal_item->amount);
-               if ($is_bank_to)
-               {
-                       add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref,
-                               $reversingDate, $journal_item->amount,
-                               0, "", get_company_currency(),
-                               "Cannot insert a destination bank transaction");
-               }
-                       // store tax details if the gl account is a tax account
-                       add_gl_tax_details($journal_item->code_id, 
-                               $trans_type, $trans_id, $journal_item->amount, 1, $reversingDate, $memo_);
-       }
-
-       add_comments($trans_type, $trans_id_reverse, $reversingDate, $memo_);
-
-       references::save($trans_type, $trans_id_reverse, $ref);
-               add_audit_trail($trans_type, $trans_id_reverse, $reversingDate);
-       }
-
        commit_transaction();
 
        return $trans_id;
@@ -410,9 +392,9 @@ function void_journal_trans($type, $type_no)
 {
        begin_transaction();
 
-       void_gl_trans($type, $type_no, true);
-       void_bank_trans($type, $type_no,true);
-       void_trans_tax_details($type, $type_no);
+       void_bank_trans($type, $type_no, true);
+//     void_gl_trans($type, $type_no, true);    // this is done above
+//     void_trans_tax_details($type, $type_no); // ditto
 
        commit_transaction();
 }
index 5a27c53cd2f15721e70ca4837be20820f1233c6f..85c7bcf12cdf69c91a8ec954de7260732784838d 100644 (file)
@@ -19,23 +19,24 @@ function display_order_header(&$Order)
        global $table_style2, $Ajax;
 
        $qes = has_quick_entries(QE_JOURNAL);
-
+       $new = $Order->order_id==0;
        start_outer_table("$table_style2 width=90%");
        table_section(1);
 
        start_row();
-    date_cells(_("Date:"), 'date_', '', true);
-       ref_cells(_("Reference:"), 'ref', '', references::get_next(0));
-       end_row();
+    date_cells(_("Date:"), 'date_', '', $new);
 
        if ($qes)
                table_section(2, "20%");
        else    
                table_section(2, "50%");
 
-       start_row();
-       check_cells(_("Reverse Transaction:"), 'Reverse', null);
+       if ($new)
+               ref_cells(_("Reference:"), 'ref', '');
+       else
+               label_cells(_("Reference:"), $Order->reference);
        end_row();
+
        if ($qes !== false)
        {
                table_section(3, "50%");