From: Janusz Dobrowolski Date: Thu, 30 Dec 2010 11:41:49 +0000 (+0000) Subject: Added option for using GRN Clearing Account for non invoiced GRNs X-Git-Tag: 2.3-final~839 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=da996b57bbeeb3e83c37526b3ae687b291ca6045 Added option for using GRN Clearing Account for non invoiced GRNs --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 326d4f7a..5e518213 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,18 @@ Legend: ! -> Note $ -> Affected files +30-Dec-2010 Janusz Dobrowolski ++ Added option for using GRN Clearing Account for yet non invoiced GRNs. +$ /purchasing/includes/po_class.inc + /purchasing/includes/db/grn_db.inc + /purchasing/includes/db/invoice_db.inc + /sql/en_US-demo.sql + /sql/en_US-new.sql +! Added GRN clearing account setting +$ /admin/gl_setup.php +! Added set_company_pref() function +$ /admin/db/company_db.inc + 29-Dec-2010 Janusz Dobrowolski ! Hook files inclusion moved to session.inc $ /includes/hooks.inc diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 2b979f1a..7b66d030 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -89,12 +89,25 @@ function add_grn(&$po) $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_); + $clearing_act = get_company_pref('grn_clearing_act'); + if ($clearing_act) { // otherwise GRN clearing account is not used + $total = 0; + $supplier_accounts = get_supplier_accounts($po->supplier_id); + } foreach ($po->line_items as $line_no => $order_line) { - if ($order_line->receive_qty != 0 && $order_line->receive_qty != "" && isset($order_line->receive_qty)) { + $stock_gl_code = get_stock_gl_code($order_line->stock_id); + + if($clearing_act) { + $inv_act = (is_inventory_item($order_line->stock_id) ? $stock_gl_code["inventory_account"] : + ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"])); + $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $inv_act, + $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], + $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id); + } /*Update sales_order_details for the new quantity received and the standard cost used for postings to GL and recorded in the stock movements for FIFO/LIFO stocks valuations*/ //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008 if (is_inventory_item($order_line->stock_id)) @@ -126,6 +139,10 @@ function add_grn(&$po) } /*quantity received is != 0 */ } /*end of order_line loop */ + if ($clearing_act) { + $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $clearing_act, + 0, 0, -$total, $po->supplier_id); + } $Refs->save(ST_SUPPRECEIVE, $grn, $po->reference); add_audit_trail(ST_SUPPRECEIVE, $grn, $date_); diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 58e3aeb7..8b7afeea 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -189,6 +189,8 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b $trans_type, $invoice_id, $entered_gl_code->amount, $ex_rate, $date_, $supp_trans->supp_reference, $supp_trans->tax_included); } + + $clearing_act = get_company_pref('grn_clearing_act'); foreach ($supp_trans->grn_items as $line_no => $entered_grn) { @@ -200,14 +202,14 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b $line_taxfree = $entered_grn->taxfree_charge_price($supp_trans->tax_group_id); $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); - $iv_act = (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : - ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"])); + + $iv_act = $clearing_act ? $clearing_act : (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : + ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"])); + $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id); - /*$total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, - $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 if ($trans_type == ST_SUPPINVOICE) { diff --git a/purchasing/includes/po_class.inc b/purchasing/includes/po_class.inc index 2324d25d..b767e9ea 100644 --- a/purchasing/includes/po_class.inc +++ b/purchasing/includes/po_class.inc @@ -230,6 +230,12 @@ class po_line_details $this->standard_cost =0; $this->grn_item_id = $grn_item_id; } + + function taxfree_charge_price($po) + { + return get_tax_free_price_for_item($this->stock_id, $this->price, + $po->tax_group_id, $po->tax_included, $po->tax_group_array); + } } ?> diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 49057301..c822b4b1 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -2065,6 +2065,7 @@ INSERT INTO `0_sys_prefs` VALUES('default_assembly_act', 'glsetup.items', 'varch INSERT INTO `0_sys_prefs` VALUES('default_workorder_required', 'glsetup.manuf', 'int', 11, '20'); INSERT INTO `0_sys_prefs` VALUES('version_id', 'system', 'varchar', 11, '2.3rc'); INSERT INTO `0_sys_prefs` VALUES('auto_curr_reval', 'setup.company', 'smallint', 6, '1'); +INSERT INTO `0_sys_prefs` VALUES('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, '1550'); -- -------------------------------------------------------- diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 041bced2..e904c2ba 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -1824,6 +1824,7 @@ INSERT INTO `0_sys_prefs` VALUES('default_assembly_act', 'glsetup.items', 'varch INSERT INTO `0_sys_prefs` VALUES('default_workorder_required', 'glsetup.manuf', 'int', 11, '20'); INSERT INTO `0_sys_prefs` VALUES('version_id', 'system', 'varchar', 11, '2.3rc'); INSERT INTO `0_sys_prefs` VALUES('auto_curr_reval', 'setup.company', 'smallint', 6, '1'); +INSERT INTO `0_sys_prefs` VALUES('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, '1550'); -- --------------------------------------------------------