From d266769382e3bed5a87101346b461b8e261205eb Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Thu, 4 Dec 2008 13:04:29 +0000 Subject: [PATCH] [0000095] Inbalance double entry on Documents --- CHANGELOG.txt | 9 ++++++ gl/includes/db/gl_db_trans.inc | 7 ++-- manufacturing/view/wo_production_view.php | 5 ++- purchasing/includes/db/invoice_db.inc | 15 ++++----- purchasing/includes/db/supp_payment_db.inc | 14 ++++---- sales/includes/db/payment_db.inc | 20 ++++++------ sales/includes/db/sales_credit_db.inc | 37 +++++++++++----------- sales/includes/db/sales_invoice_db.inc | 22 ++++++------- 8 files changed, 71 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 880de99b..37a23099 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/gl/includes/db/gl_db_trans.inc b/gl/includes/db/gl_db_trans.inc index 96970678..fe547a89 100644 --- a/gl/includes/db/gl_db_trans.inc +++ b/gl/includes/db/gl_db_trans.inc @@ -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; } //-------------------------------------------------------------------------------- diff --git a/manufacturing/view/wo_production_view.php b/manufacturing/view/wo_production_view.php index 64e287e7..1558f67c 100644 --- a/manufacturing/view/wo_production_view.php +++ b/manufacturing/view/wo_production_view.php @@ -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"); diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index ae19c7e3..b19897da 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -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); diff --git a/purchasing/includes/db/supp_payment_db.inc b/purchasing/includes/db/supp_payment_db.inc index 5e5b400d..ce85db52 100644 --- a/purchasing/includes/db/supp_payment_db.inc +++ b/purchasing/includes/db/supp_payment_db.inc @@ -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(), diff --git a/sales/includes/db/payment_db.inc b/sales/includes/db/payment_db.inc index 14d358b8..1d7dfa06 100644 --- a/sales/includes/db/payment_db.inc +++ b/sales/includes/db/payment_db.inc @@ -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, diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 2f56e901..d196ee06 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -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 diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index c4303fc6..112dbe13 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -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) { -- 2.30.2