Added dimension edition on purchase invoice entry.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 20 Feb 2015 09:34:29 +0000 (10:34 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 28 Feb 2015 17:04:10 +0000 (18:04 +0100)
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/invoice_items_db.inc
purchasing/includes/po_class.inc
purchasing/includes/purchasing_db.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/includes/ui/po_ui.inc
sql/alter2.4.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index dd172395ef803e21ff414aaa1807d79634bb987b..707704cf2abf21780b80cf9b8754b896ae4d9ca4 100644 (file)
@@ -126,7 +126,8 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan
        //$company_currency = get_company_currency();
        $trans_no = $supp_trans->trans_no;
        $trans_type = $supp_trans->trans_type;
-       /*Start an sql transaction */
+       $supplier = get_supplier($supp_trans->supplier_id);
+
        begin_transaction();
        hook_db_prewrite($supp_trans, $trans_type);
        $tax_total = 0;
@@ -138,8 +139,6 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan
        } else
                $allocs = get_po_prepayments($supp_trans);
 
-       $supplier = get_supplier($supp_trans->supplier_id);
-
        add_new_exchange_rate($supplier['curr_code'], $supp_trans->tran_date, $supp_trans->ex_rate);
 
     foreach ($taxes as $n => $taxitem)
@@ -234,8 +233,8 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan
                $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, "", 0, $memo_);
 
-               add_supp_invoice_gl_item($trans_type, $invoice_id, $entered_gl_code->gl_code,
-                       $entered_gl_code->amount, $memo_);
+               add_supp_invoice_gl_item($trans_type, $invoice_id, $entered_gl_code->gl_code, $entered_gl_code->amount, $memo_,
+                       $entered_gl_code->gl_dim, $entered_gl_code->gl_dim2);
 
                // store tax details if the gl account is a tax account
                if ($trans_type == ST_SUPPCREDIT)
@@ -270,8 +269,10 @@ function add_supp_invoice(&$supp_trans) // do not receive as ref because we chan
 
                $stock_gl_code = get_stock_gl_code($entered_grn->item_code);
 
-               $dim = $supplier['dimension_id'] ? $supplier['dimension_id'] : $stock_gl_code['dimension_id'];
-               $dim2 = $supplier['dimension2_id'] ? $supplier['dimension2_id'] : $stock_gl_code['dimension2_id'];
+               $dim = !empty($supp_trans->dimension) ? $supp_trans->dimension :
+                       ($supplier['dimension_id'] ? $supplier['dimension_id'] : $stock_gl_code['dimension_id']);
+               $dim2 = !empty($supp_trans->dimension2) ? $supp_trans->dimension2 :
+                       ($supplier['dimension2_id'] ? $supplier['dimension2_id'] : $stock_gl_code['dimension2_id']);
        if ($trans_type == ST_SUPPCREDIT)
                {
                        $iv_act = (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : 
@@ -490,7 +491,7 @@ function read_supp_invoice($trans_no, $trans_type, &$supp_trans)
                else
                {
                        $supp_trans->add_gl_codes_to_trans($details_row["gl_code"], get_gl_account_name($details_row["gl_code"]), 0, 0,
-                                       $details_row["FullUnitPrice"], $details_row["memo_"]);
+                                       $details_row["FullUnitPrice"], $details_row["memo_"], $details_row["dimension_id"], $details_row["dimension2_id"]);
                }
             }
                        $supp_trans->tax_overrides = get_tax_overrides($trans_type, $trans_no);
index 00fdbae8390b0e7524f0b10d6c28f59c37d26264..770f5b43dface13dff8faf1575bfc159900bc519 100644 (file)
 //-------------------------------------------------------------------------------------------------------------
 
 function add_supp_invoice_item($supp_trans_type, $supp_trans_no, $stock_id, $description,
-       $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_,
-       $err_msg="")
+       $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_, $dim_id=0, $dim2_id=0)
 {
        $sql = "INSERT INTO ".TB_PREF."supp_invoice_items (supp_trans_type, supp_trans_no, stock_id, description, gl_code, unit_price, unit_tax, quantity,
-               grn_item_id, po_detail_item_id, memo_) ";
+               grn_item_id, po_detail_item_id, memo_, dimension_id, dimension2_id) ";
        $sql .= "VALUES (".db_escape($supp_trans_type).", ".db_escape($supp_trans_no).", "
                .db_escape($stock_id).
        ", ".db_escape($description).", ".db_escape($gl_code).", ".db_escape($unit_price)
-       .", ".db_escape($unit_tax).", ".db_escape($quantity).",
-               ".db_escape($grn_item_id).", ".db_escape($po_detail_item_id).", ".db_escape($memo_).")";
+       .", ".db_escape($unit_tax).", ".db_escape($quantity).", ".db_escape($grn_item_id)
+       .", ".db_escape($po_detail_item_id).", ".db_escape($memo_)
+       .", ".db_escape($dim_id).", ".db_escape($dim2_id).")";
 
-       if ($err_msg == "")
-               $err_msg = "Cannot insert a supplier transaction detail record";
-
-       db_query($sql, $err_msg);
+       db_query($sql, "Cannot insert a supplier transaction detail record");
 
        return db_insert_id();
 }
 
 //-------------------------------------------------------------------------------------------------------------
 
-function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $err_msg="")
+function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $dim_id=0, $dim2_id=0)
 {
        return add_supp_invoice_item($supp_trans_type, $supp_trans_no,  "", "", $gl_code, $amount,
-               0, 0, /*$grn_item_id*/0, /*$po_detail_item_id*/0, $memo_, $err_msg);
+               0, 0, /*$grn_item_id*/-1, /*$po_detail_item_id*/0, $memo_, 0, $dim_id, $dim2_id);
 }
 
 
-//----------------------------------------------------------------------------------------
-
 function get_supp_invoice_items($supp_trans_type, $supp_trans_no)
 {
-       $sql = "SELECT *, unit_price AS FullUnitPrice FROM "
-               .TB_PREF."supp_invoice_items inv LEFT JOIN ".TB_PREF."grn_items grn ON grn.id =inv.grn_item_id
+       $sql = "SELECT inv.*, grn.*, unit_price AS FullUnitPrice, 
+               stock.parallel_qe, 
+               stock.units,
+               tax_type.exempt,
+               tax_type.name as tax_type_name
+               FROM "
+                       .TB_PREF."supp_invoice_items inv LEFT JOIN ".TB_PREF."grn_items grn ON grn.id =inv.grn_item_id
+                               LEFT JOIN ".TB_PREF."stock_master stock ON stock.stock_id=inv.stock_id
+                               LEFT JOIN ".TB_PREF."item_tax_types tax_type ON stock.tax_type_id=tax_type.id
                WHERE supp_trans_type = ".db_escape($supp_trans_type)."
-               AND supp_trans_no = ".db_escape($supp_trans_no)
-               ." ORDER BY inv.id";
+                       AND supp_trans_no = ".db_escape($supp_trans_no)
+                       ." ORDER BY inv.id";
        return db_query($sql, "Cannot retreive supplier transaction detail records");
 }
 
-//----------------------------------------------------------------------------------------
-
 function void_supp_invoice_items($type, $type_no)
 {
        $sql = "UPDATE ".TB_PREF."supp_invoice_items SET quantity=0, unit_price=0
index 0464c42b6fe73fdaa627f257be9d408f0e1a330f..47129816ac1b7501303319d38426d5b708d76b6b 100644 (file)
@@ -37,6 +37,8 @@ class purch_order
        var $terms;
        var $ex_rate;
        var $cash_account;
+       var $dimension,
+               $dimension2;
 
        var $reference;
        var $tax_overrides = array();           // array of taxes manually inserted during sales invoice entry (direct invoice)
index 2a2c2399399bae73c1549bd4bed7303f8f2bcd8b..149b42d9d6f70b1399cab3c82f578e434c5fcd92 100644 (file)
@@ -184,6 +184,8 @@ function add_direct_supp_trans($cart)
        $inv->supplier_id = $cart->supplier_id;
        $inv->tran_date = $cart->orig_order_date;
        $inv->due_date = $cart->due_date;
+       $inv->dimension = $cart->dimension;
+       $inv->dimension2 = $cart->dimension2;
        $inv->reference = $ref;
        $inv->supp_reference = $cart->supp_ref;
        $inv->tax_included = $cart->tax_included;
index cfa661699dd9a62f8b245a445fefe0fc526326be..99fe1934f7fcf65a183362c7e97fc4be72a53963 100644 (file)
@@ -48,6 +48,9 @@ class supp_trans
        var $currency;
        var $tax_overrides = array();           // array of taxes manually inserted during sales invoice entry
 
+       var $dimension,
+               $dimension2;
+
        function supp_trans($trans_type, $trans_no=0)
        {
                $this->trans_type = $trans_type;
index d16e8d1392b684402fe0a80d79da9d36bc99c36d..5846af6e6b5c37c3cd3eb4231c76cda8bc908a2a 100644 (file)
@@ -20,6 +20,8 @@ function copy_from_trans(&$supp_trans)
        $_POST['reference'] = $supp_trans->reference;
        $_POST['supplier_id'] = $supp_trans->supplier_id;
        $_POST['tax_algorithm'] = $supp_trans->tax_algorithm;
+    $_POST['dimension'] = $supp_trans->dimension;
+    $_POST['dimension2'] = $supp_trans->dimension2;
 
        $_POST['_ex_rate'] = $supp_trans->ex_rate;
        if (isset($supp_trans->tax_overrides))
@@ -38,6 +40,8 @@ function copy_to_trans(&$supp_trans)
        $supp_trans->reference = $_POST['reference'];
        if (isset($_POST['tax_algorithm']))
            $supp_trans->tax_algorithm = $_POST['tax_algorithm'];
+       $supp_trans->dimension = @$_POST['dimension'];
+       $supp_trans->dimension2 =  @$_POST['dimension2'];
 
        $supp_trans->ex_rate = input_num('_ex_rate', null);
 
@@ -124,6 +128,12 @@ function invoice_header(&$supp_trans)
        }
                text_row(_("Supplier's Ref.:"), 'supp_reference', $_POST['supp_reference'], 20, 60);
 
+       if (get_company_pref('use_dimension'))
+               dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1);
+
+       if (get_company_pref('use_dimension') == 2)
+               dimensions_list_row(_('Dimension 2').':', 'dimension2', null, true, _('Default'), false, 2);
+
        table_section(2, "33%");
 
        date_row(_("Date") . ":", 'tran_date', '', true, 0, 0, 0, "", true);
index ed696468740f8aa4a517b3ca262ea1bebaf953ea..811bcb880148779fca35c22074693190d1212d9e 100644 (file)
@@ -30,6 +30,8 @@ function copy_from_cart()
        $_POST['prep_amount'] = price_format($cart->prep_amount);
        $_POST['_ex_rate'] = $cart->ex_rate;
        $_POST['cash_account'] = $cart->cash_account;
+    $_POST['dimension'] = $cart->dimension;
+    $_POST['dimension2'] = $cart->dimension2;
     foreach($cart->tax_overrides as $id => $value)
            $_POST['mantax'][$id] = price_format($value);
 }
@@ -50,6 +52,8 @@ function copy_to_cart()
        $cart->Comments = $_POST['Comments'];   
        $cart->Location = $_POST['StkLocation'];
        $cart->delivery_address = $_POST['delivery_address'];
+       $cart->dimension = @$_POST['dimension'];
+       $cart->dimension2 =  @$_POST['dimension2'];
        if (isset($_POST['tax_algorithm']))
            $cart->tax_algorithm = $_POST['tax_algorithm'];
        $cart->prep_amount = input_num('prep_amount', 0);
@@ -151,7 +155,6 @@ function display_po_header(&$order)
                        $_POST['OrderDate']);
        }
 
-
     if ($editable)
     {
        ref_row(_("Reference:"), 'ref');
@@ -168,6 +171,11 @@ function display_po_header(&$order)
                date_row(_("Due Date:"), 'due_date', '', false, 0, 0, 0, null, true);
 
        text_row(_("Supplier's Reference:"), 'supp_ref', null, 16, 15);
+
+       if (get_company_pref('use_dimension'))
+               dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1);
+       if (get_company_pref('use_dimension') == 2)
+               dimensions_list_row(_('Dimension 2').':', 'dimension2', null, true, _('Default'), false, 2);
        locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true); 
 
        table_section(3);
index b250e04af3783cc251be31cb7dff72af6c0b9861..92d77970a504e58b3877e6cf12481fd79441bca8 100644 (file)
@@ -142,3 +142,12 @@ ALTER TABLE `0_workcentres` ENGINE=InnoDB;
 
 ALTER TABLE `0_gl_trans` CHANGE `type_no` `type_no` int(11) NOT NULL default '0';
 ALTER TABLE `0_loc_stock` CHANGE `reorder_level` `reorder_level` double NOT NULL default '0';
+
+# added dimensions in supplier documents
+ALTER TABLE `0_supp_invoice_items` ADD COLUMN `dimension_id` int(11) NOT NULL DEFAULT '0' AFTER `memo_`;
+ALTER TABLE `0_supp_invoice_items` ADD COLUMN `dimension2_id` int(11) NOT NULL DEFAULT '0' AFTER `dimension_id`;
+
+UPDATE `0_supp_invoice_items` si
+       LEFT JOIN `0_gl_trans` gl ON si.supp_trans_type=gl.`type` AND si.supp_trans_no=gl.type_no AND si.gl_code=gl.account
+       SET si.dimension_id=gl.dimension_id, si.dimension2_id=gl.dimension2_id
+WHERE si.grn_item_id=-1 AND (gl.dimension_id OR gl.dimension2_id)
index 7e23a8ed26df5728626bb1b6e0c9c9d0c7db1610..ae3aefdec8854340fa546f2b0714f4351b672fec 100644 (file)
@@ -1952,6 +1952,8 @@ CREATE TABLE IF NOT EXISTS `0_supp_invoice_items` (
   `unit_price` double NOT NULL default '0',
   `unit_tax` double NOT NULL default '0',
   `memo_` tinytext,
+  `dimension_id` int(11) NOT NULL DEFAULT '0',
+  `dimension2_id` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY  (`id`),
   KEY `Transaction` (`supp_trans_type`,`supp_trans_no`,`stock_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8  AUTO_INCREMENT=6 ;
@@ -1960,11 +1962,11 @@ CREATE TABLE IF NOT EXISTS `0_supp_invoice_items` (
 -- Dumping data for table `0_supp_invoice_items`
 --
 
-INSERT INTO `0_supp_invoice_items` VALUES(1, 7, 20, '0', 1, 1, '102', '17inch VGA Monitor', 100, 10, 0.5, '');
-INSERT INTO `0_supp_invoice_items` VALUES(2, 7, 20, '0', 2, 2, '103', '32MB VGA Card', 100, 11, 0.55, '');
-INSERT INTO `0_supp_invoice_items` VALUES(3, 7, 20, '0', 3, 3, '104', '52x CD Drive', 100, 12, 0.6, '');
-INSERT INTO `0_supp_invoice_items` VALUES(4, 8, 20, '2150', 0, 0, '', '', 0, 0.95, 0, 'Phone');
-INSERT INTO `0_supp_invoice_items` VALUES(5, 8, 20, '5780', 0, 0, '', '', 0, 19.05, 0, 'Phone');
+INSERT INTO `0_supp_invoice_items` VALUES(1, 7, 20, '0', 1, 1, '102', '17inch VGA Monitor', 100, 10, 0.5, '', 0, 0);
+INSERT INTO `0_supp_invoice_items` VALUES(2, 7, 20, '0', 2, 2, '103', '32MB VGA Card', 100, 11, 0.55, '', 0, 0);
+INSERT INTO `0_supp_invoice_items` VALUES(3, 7, 20, '0', 3, 3, '104', '52x CD Drive', 100, 12, 0.6, '', 0, 0);
+INSERT INTO `0_supp_invoice_items` VALUES(4, 8, 20, '2150', 0, 0, '', '', 0, 0.95, 0, 'Phone', 0, 0);
+INSERT INTO `0_supp_invoice_items` VALUES(5, 8, 20, '5780', 0, 0, '', '', 0, 19.05, 0, 'Phone', 0, 0);
 
 -- --------------------------------------------------------
 
index 3012d7576af16246ad684000573af6f232f15525..73d29c9e0329cbe0a97ae9be6712f13b0f38c142 100644 (file)
@@ -1721,6 +1721,8 @@ CREATE TABLE IF NOT EXISTS `0_supp_invoice_items` (
   `unit_price` double NOT NULL default '0',
   `unit_tax` double NOT NULL default '0',
   `memo_` tinytext,
+  `dimension_id` int(11) NOT NULL DEFAULT '0',
+  `dimension2_id` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY  (`id`),
   KEY `Transaction` (`supp_trans_type`,`supp_trans_no`,`stock_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;