[0000095] Inbalance double entry on Documents
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 4 Dec 2008 13:04:29 +0000 (13:04 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 4 Dec 2008 13:04:29 +0000 (13:04 +0000)
CHANGELOG.txt
gl/includes/db/gl_db_trans.inc
manufacturing/view/wo_production_view.php
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/supp_payment_db.inc
sales/includes/db/payment_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_invoice_db.inc

index 880de99b60e08310f80eb7ba4df4550048fe1975..37a23099e9e131bdcd2834affb3e6efc816dbce4 100644 (file)
@@ -19,6 +19,15 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+04-Dec-2008 Joe Hunt
+# [0000095] Inbalance double entry on Documents
+$ /gl/includes/db/gl_db_trans.inc
+  /purchasing/includes/db/invoice_db.inc
+  /purchasing/includes/db/supp_payment_db.inc
+  /sales/includes/db/payment_db.inc
+  /sales/includes/db/sales_credit_db.inc
+  /sales/includes/db/sales_invoice_db.inc
+  
 29-Nov-2008 Joe Hunt
 # [0000094] Report does not show items that have 0 qty but have demand qty
 $ /reporting/rep302.php
index 969706789b52e308441c0b15a81db6e018c35537..fe547a8954957706cad7c195aac1e7b44101bf82 100644 (file)
@@ -21,7 +21,7 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension
                        $amount_in_home_currency = round($amount * $rate,  user_price_dec());
        }               
        else
-               $amount_in_home_currency = $amount;
+               $amount_in_home_currency = round($amount, user_price_dec());
        if ($dimension == null || $dimension < 0)
                $dimension = 0;
        if ($dimension2 == null || $dimension2 < 0)
@@ -52,7 +52,8 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension
        if ($err_msg == "")
                $err_msg = "The GL transaction could not be inserted";
 
-       return db_query($sql, $err_msg);
+       db_query($sql, $err_msg);
+       return $amount_in_home_currency;
 }
 
 //--------------------------------------------------------------------------------
@@ -68,7 +69,7 @@ function add_gl_trans_std_cost($type, $trans_id, $date_, $account, $dimension, $
                return add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
                        $amount, null, $person_type_id, $person_id, $err_msg);
        else
-               return null;
+               return 0;
 }
 
 //--------------------------------------------------------------------------------
index 64e287e73ba174fc1e7be82e14ec154524e4984e..1558f67cbcddedad032ee1830058161febda810d 100644 (file)
@@ -5,7 +5,10 @@ $path_to_root="../..";
 
 include_once($path_to_root . "/includes/session.inc");
 
-page(_("View Work Order Production"), true);
+$js = "";
+if ($use_popup_windows)
+       $js .= get_js_open_window(900, 500);
+page(_("View Work Order Production"), true, false, "", $js);
 
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/includes/manufacturing.inc");
index ae19c7e31b7dd3343e0c6647dc5455929fc1cd53..b19897da6b2ffd0c1007250f5b4df81488c6ec7f 100644 (file)
@@ -143,10 +143,6 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
 
     /* Now the control account */
     $supplier_accounts = get_supplier_accounts($supp_trans->supplier_id);
-    add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier_accounts["payable_account"], 0, 0,
-               -($invoice_items_total +  $tax_total + $supp_trans->ov_discount),
-               $supp_trans->supplier_id,
-               "The general ledger transaction for the control total could not be added");
 
     /*Loop through the GL Entries and create a debit posting for each of the accounts entered */
 
@@ -159,7 +155,7 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
     between the std cost and the currency cost charged as converted at the ex rate of of the invoice is written off
     to the purchase price variance account applicable to the item being invoiced.
     */
-
+       $total = 0;
     foreach ($supp_trans->gl_codes as $entered_gl_code)
     {
 
@@ -170,7 +166,7 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                        $entered_gl_code->amount = -$entered_gl_code->amount;
 
                $memo_ = $entered_gl_code->memo_;
-               add_gl_trans_supplier($trans_type, $invoice_id, $date_, $entered_gl_code->gl_code,
+               $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $entered_gl_code->gl_code,
                        $entered_gl_code->gl_dim, $entered_gl_code->gl_dim2, $entered_gl_code->amount, $supp_trans->supplier_id);
 
                add_supp_invoice_gl_item($trans_type, $invoice_id, $entered_gl_code->gl_code,
@@ -189,7 +185,7 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                $line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree;
                $stock_gl_code = get_stock_gl_code($entered_grn->item_code);
 
-               add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
+               $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
                        $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
                        $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
        // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
@@ -255,12 +251,15 @@ function add_supp_invoice($supp_trans) // do not receive as ref because we chang
                        add_supp_invoice_tax_item($trans_type, $invoice_id, $taxitem['tax_type_id'],
                                $taxitem['rate'], 0, $taxitem['Value']);
 
-               add_gl_trans_supplier($trans_type, $invoice_id, $date_,
+               $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_,
                        $taxitem['purchasing_gl_code'], 0, 0, $taxitem['Value'],
                        $supp_trans->supplier_id,
                        "A general ledger transaction for the tax amount could not be added");
        }
     }
+       add_gl_trans($trans_type, $invoice_id, $date_, $supplier_accounts["payable_account"], 0, 0, "",
+               -$total, null, payment_person_types::supplier(), $supp_trans->supplier_id, 
+               "The general ledger transaction for the control total could not be added");
        add_comments($trans_type, $invoice_id, $date_, $supp_trans->Comments);
 
        references::save_last($supp_trans->reference, $trans_type);
index 5e5b400d952746786509494d52649ab3546fbe4b..ce85db523f6c3cdd9187d188e385e223ef6d05f5 100644 (file)
@@ -15,8 +15,8 @@ function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
        }
        else
        {
-               $supp_amount = $amount / $rate;
-               $supp_discount = $discount / $rate;
+               $supp_amount = round($amount / $rate, user_price_dec());
+               $supp_discount = round($discount / $rate, user_price_dec());
        }
        
 
@@ -31,22 +31,22 @@ function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
 
     $supplier_accounts = get_supplier_accounts($supplier_id);
 
-       add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0,
-               $supp_amount + $supp_discount, $supplier_id, "", $rate);
-
+       $total = 0;
        // Now credit discount received account with discounts
        if ($supp_discount != 0)
        {
-               add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
+               $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $supplier_accounts["payment_discount_account"], 0, 0,
                        -$supp_discount, $supplier_id, "", $rate);
        }
 
        if ($supp_amount != 0)
        {
-               add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
+               $total += add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
                        -$supp_amount, $supplier_id, "", $rate);
        }
 
+       add_gl_trans($trans_type, $payment_id, $date_, $supplier_accounts["payable_account"], 0, 0, "",
+               -$total, null, payment_person_types::supplier(), $supplier_id);
    /*now enter the bank_trans entry */
        add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
                $date_, $payment_type, -($amount), payment_person_types::supplier(),
index 14d358b8ff18624f05521a7d4c3c5f679611316a..1d7dfa0651df59ff85dcc690db1e27830fea507c 100644 (file)
@@ -18,9 +18,9 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
          void_gl_trans(12, $trans_no, true);
          void_cust_allocations(12, $trans_no, $date_);
        }
-
+       $total = 0;
        /* Bank account entry first */
-       add_gl_trans_customer(12, $payment_no, $date_,
+       $total += add_gl_trans_customer(12, $payment_no, $date_,
                $bank_account, 0, 0, $amount,  $customer_id,
                "Cannot insert a GL transaction for the bank account debit", $rate);
 
@@ -36,20 +36,20 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
                $discount_account = $company_record["default_prompt_payment_act"];
        }
 
-       if (($discount + $amount) != 0) {
-               /* Now Credit Debtors account with receipts + discounts */
-               add_gl_trans_customer(12, $payment_no, $date_,
-                       $debtors_account, 0, 0, -($discount + $amount), $customer_id,
-                       "Cannot insert a GL transaction for the debtors account credit", $rate);
-       }
-
        if ($discount != 0)     {
                /* Now Debit discount account with discounts allowed*/
-               add_gl_trans_customer(12, $payment_no, $date_,
+               $total += add_gl_trans_customer(12, $payment_no, $date_,
                        $discount_account, 0, 0, $discount, $customer_id,
                        "Cannot insert a GL transaction for the payment discount debit", $rate);
        }
 
+       if (($discount + $amount) != 0) {
+               /* Now Credit Debtors account with receipts + discounts */
+               add_gl_trans(12, $payment_no, $date_, $debtors_account, 0, 0, "",
+                       -$total, null, payment_person_types::customer(), $customer_id, 
+                       "Cannot insert a GL transaction for the debtors account credit");
+       }
+
        /*now enter the bank_trans entry */
        add_bank_trans(12, $payment_no, $bank_account, $ref,
                $date_, $receipt_type, $amount, payment_person_types::customer(), $customer_id,
index 2f56e9012d03548015ab02a7fffdb17aa5da7351..d196ee062ae7a8cc096d361ec62a8087100c14fc 100644 (file)
@@ -97,7 +97,7 @@ function write_credit_note($credit_note, $write_off_acc)
                }
        }
 
-
+       $total = 0;
        foreach ($credit_note->line_items as $credit_line) {
 
                if ($credit_invoice && $credit_line->qty_dispatched!=$credit_line->qty_old ) {
@@ -119,23 +119,13 @@ function write_credit_note($credit_note, $write_off_acc)
                add_credit_movements_item($credit_note, $credit_line,
                        $credit_type, $line_taxfree_price+$line_tax, $credit_invoice);
 
-               add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
+               $total += add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,
                    $credit_date, $credit_type, $write_off_acc, $branch_data);
        } /*end of credit_line loop */
 
-       /*Post credit note transaction to GL credit debtors,
-       debit freight re-charged and debit sales */
-
-       if (($credit_note_total + $credit_note->freight_cost) != 0) {
-
-               add_gl_trans_customer(11, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0,
-                       -($credit_note_total + $credit_note->freight_cost + $items_added_tax + $freight_added_tax),
-                       $credit_note->customer_id,
-                       "The total debtor GL posting for the credit note could not be inserted");
-       }
 
        if ($credit_note->freight_cost !=0) {
-               add_gl_trans_customer(11, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
+               $total += add_gl_trans_customer(11, $credit_no, $credit_date, $company_data["freight_act"], 0, 0,
                        $credit_note->get_tax_free_shipping(), $credit_note->customer_id,
                        "The freight GL posting for this credit note could not be inserted");
        }
@@ -146,11 +136,20 @@ function write_credit_note($credit_note, $write_off_acc)
                        add_customer_trans_tax_detail_item(11, $credit_no, $taxitem['tax_type_id'],
                                $taxitem['rate'], $credit_note->tax_included, $taxitem['Value']);
 
-                       add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
+                       $total += add_gl_trans_customer(11, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
                                $taxitem['Value'], $credit_note->customer_id,
                                "A tax GL posting for this credit note could not be inserted");
                }
        }
+       /*Post credit note transaction to GL credit debtors,
+       debit freight re-charged and debit sales */
+
+       if (($credit_note_total + $credit_note->freight_cost) != 0) {
+
+               add_gl_trans(11, $credit_no, $credit_date, $branch_data["receivables_account"], 0, 0, "",
+                       -$total, null, payment_person_types::customer(), $credit_note->customer_id, 
+                       "The total debtor GL posting for the credit note could not be inserted");
+       }
        add_comments(11, $credit_no, $credit_date, $credit_note->Comments);
 
        if ($trans_no == 0) {
@@ -210,12 +209,13 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
        $dim = ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_codes["dimension_id"]);
        $dim2 = ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_codes["dimension2_id"]);
 
+       $total = 0;
        /* insert gl_trans to credit stock and debit cost of sales at standard cost*/
        $standard_cost = get_standard_cost($order_line->stock_id);
        if ($standard_cost != 0) {
                /*first the cost of sales entry*/
 
-               add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
+               $total += add_gl_trans_std_cost(11, $credit_no, $date_, $stock_gl_codes["cogs_account"],
                        $dim, $dim2, "", -($standard_cost * $order_line->qty_dispatched),
                        payment_person_types::customer(), $order->customer_id,
                        "The cost of sales GL posting could not be inserted");
@@ -228,7 +228,7 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
                        $stock_entry_account = $stock_gl_code["inventory_account"];
                }
 
-               add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
+               $total += add_gl_trans_std_cost(11, $credit_no, $date_, $stock_entry_account, 0, 0,
                        "", ($standard_cost * $order_line->qty_dispatched),
                        payment_person_types::customer(), $order->customer_id,
                        "The stock side (or write off) of the cost of sales GL posting could not be inserted");
@@ -253,19 +253,20 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
                        $sales_account = $branch_data['sales_account'];
                else
                        $sales_account = $stock_gl_codes['sales_account'];
-               add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $dim, $dim2,
+               $total += add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $dim, $dim2,
                        ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id,
                        "The credit note GL posting could not be inserted");
 
                if ($order_line->discount_percent != 0) {
 
-                       add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"],
+                       $total += add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"],
                                $dim, $dim2, -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent),
                                $order->customer_id,
                                "The credit note discount GL posting could not be inserted");
 
                } /*end of if discount !=0 */
        } /*if line_price!=0 */
+       return $total;
 }
 
 ?>
\ No newline at end of file
index c4303fc60561f2b14ae2b3bba9d1217c8a1d859f..112dbe13d955ed47b744763a8b911b7e3e5aa69d 100644 (file)
@@ -72,7 +72,7 @@ function write_sales_invoice(&$invoice)
                void_cust_allocations(10, $invoice_no); // ?
                void_customer_trans_tax_details(10, $invoice_no);
        }
-
+       $total = 0;
        foreach ($invoice->line_items as $invoice_line) {
 
                $line_taxfree_price = get_tax_free_price_for_item($invoice_line->stock_id,
@@ -106,13 +106,13 @@ function write_sales_invoice(&$invoice)
                                // else take the Item Dimension (if any)
                                $dim = ($customer['dimension_id'] != 0 ? $customer["dimension_id"] : $stock_gl_code["dimension_id"]);
                                $dim2 = ($customer['dimension2_id'] != 0 ? $customer["dimension2_id"] : $stock_gl_code["dimension2_id"]);
-                               add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
+                               $total += add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $dim, $dim2,
                                        (-$line_taxfree_price * $invoice_line->qty_dispatched),
                                        $invoice->customer_id, "The sales price GL posting could not be inserted");
 
                                if ($invoice_line->discount_percent != 0) {
 
-                                       add_gl_trans_customer(10, $invoice_no, $date_,
+                                       $total += add_gl_trans_customer(10, $invoice_no, $date_,
                                                $branch_data["sales_discount_account"], $dim, $dim2,
                                                ($line_taxfree_price * $invoice_line->qty_dispatched * $invoice_line->discount_percent),
                                                $invoice->customer_id, "The sales discount GL posting could not be inserted");
@@ -121,14 +121,8 @@ function write_sales_invoice(&$invoice)
                } /*quantity dispatched is more than 0 */
        } /*end of delivery_line loop */
 
-       /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
-       if (($items_total + $charge_shipping) != 0) {
-               add_gl_trans_customer(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0,
-                       ($items_total + $charge_shipping + $items_added_tax + $freight_added_tax),
-                       $invoice->customer_id, "The total debtor GL posting could not be inserted");
-       }
        if ($charge_shipping != 0) {
-               add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
+               $total += add_gl_trans_customer(10, $invoice_no, $date_, $company_data["freight_act"], 0, 0,
                        -$invoice->get_tax_free_shipping(), $invoice->customer_id,
                        "The freight GL posting could not be inserted");
        }
@@ -138,12 +132,18 @@ function write_sales_invoice(&$invoice)
                        add_customer_trans_tax_detail_item(10, $invoice_no, $taxitem['tax_type_id'],
                                $taxitem['rate'], $invoice->tax_included, $taxitem['Value']);
 
-                       add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
+                       $total += add_gl_trans_customer(10, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
                                (-$taxitem['Value']), $invoice->customer_id,
                                "A tax GL posting could not be inserted");
                }
        }
 
+       /*Post debtors transaction to GL debit debtors, credit freight re-charged and credit sales */
+       if (($items_total + $charge_shipping) != 0) {
+               add_gl_trans(10, $invoice_no, $date_, $branch_data["receivables_account"], 0, 0, "",
+                       -$total, null, payment_person_types::customer(), $invoice->customer_id, 
+                       "The total debtor GL posting could not be inserted");
+       }
        add_comments(10, $invoice_no, $date_, $invoice->Comments);
 
        if ($trans_no == 0) {