Removed obsolete stock_move.person_id field and related handling.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 6 Apr 2015 09:48:15 +0000 (11:48 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 7 Apr 2015 19:45:57 +0000 (21:45 +0200)
includes/db/inventory_db.inc
manufacturing/includes/db/work_orders_quick_db.inc
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sql/alter2.4.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index 48aa125d37b56918c0abe2ce8af964a1b6b957c5..9c9d2b2e3e68756b225184a06d9f74950c42bf5f 100644 (file)
@@ -354,18 +354,18 @@ function handle_negative_inventory($stock_id, $quantity, $standard_cost, $date_)
 
 // $date_ - display / non-sql date
 // $std_cost - in HOME currency
-// $price - in $person_id's currency
+// $price - in transaction currency
 
 function add_stock_move($type, $stock_id, $trans_no, $location,
-    $date_, $reference, $quantity, $std_cost, $person_id=0, $price=0)
+    $date_, $reference, $quantity, $std_cost, $price=0)
 {
        $date = date2sql($date_);
 
        $sql = "INSERT INTO ".TB_PREF."stock_moves (stock_id, trans_no, type, loc_code,
-               tran_date, person_id, reference, qty, standard_cost, price) VALUES ("
+               tran_date, reference, qty, standard_cost, price) VALUES ("
                .db_escape($stock_id).", ".db_escape($trans_no).", "
                .db_escape($type).", ".db_escape($location).", '$date', "
-               .db_escape($person_id).", ".db_escape($reference).", "
+               .db_escape($reference).", "
                .db_escape($quantity).", ".db_escape($std_cost)."," .db_escape($price).")";
 
        db_query($sql, "The stock movement record cannot be inserted");
@@ -403,7 +403,11 @@ function get_stock_moves($type, $type_no)
 
 function void_stock_move($type, $type_no)
 {
-    $sql = "SELECT * from ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
+    $sql = "SELECT move.*, supplier.supplier_id from ".TB_PREF."stock_moves move
+                               LEFT JOIN ".TB_PREF."supp_trans credit ON credit.trans_no=move.trans_no AND credit.type=move.type
+                               LEFT JOIN ".TB_PREF."grn_batch grn ON grn.id=move.trans_no AND 25=move.type
+                               LEFT JOIN ".TB_PREF."suppliers supplier ON IFNULL(grn.supplier_id, credit.supplier_id)=supplier.supplier_id
+     WHERE move.type=".db_escape($type)." AND move.trans_no=".db_escape($type_no);
 
     $result = db_query($sql, "Could not void stock moves");
     while ($row = db_fetch($result))
@@ -419,7 +423,7 @@ function void_stock_move($type, $type_no)
                        else
                                $unit_cost = $row["standard_cost"];
 
-                       update_average_material_cost($row["person_id"], $row["stock_id"],
+                       update_average_material_cost($row["supplier_id"], $row["stock_id"],
                                $unit_cost, -$row["qty"], sql2date($row["tran_date"]));
                }
     }
index 7474802477abaf6e8b022f38f3eaacb0921a0c2a..89d8fa47f9454a6034a2cb02a2b187b57262d62c 100644 (file)
@@ -68,7 +68,7 @@ function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type,
                // insert a -ve stock move for each item
                $UnitCost = get_standard_cost($bom_item["component"]);
                add_stock_move(ST_WORKORDER, $bom_item["component"], $woid,
-                       $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, $UnitCost, 0, $UnitCost);
+                       $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, $UnitCost, $UnitCost);
        }
        
        // -------------------------------------------------------------------------
index 58320e7cb8b078b2506918d1300ba642c918ef2a..7604568f8947b4754bd852d20e99514167a102c1 100644 (file)
@@ -152,8 +152,7 @@ function add_grn(&$po)
                        $po->line_items[$line_no]->grn_item_id = $grn_item;
                        /* Update location stock records - NB  a po cannot be entered for a service/kit parts done automatically */
                        add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
-                               $order_line->receive_qty, $order_line->standard_cost,
-                       $po->supplier_id, $order_line->taxfree_charge_price($po));
+                               $order_line->receive_qty, $order_line->standard_cost, $order_line->taxfree_charge_price($po));
 
                } /*quantity received is != 0 */
        } /*end of order_line loop */
@@ -259,7 +258,7 @@ function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
        db_query($sql);
 
     add_stock_move(ST_SUPPCREDIT, $entered_grn->item_code, $transno, $myrow['loc_code'], $date, "",
-               $entered_grn->this_quantity_inv, $mcost, $supplier, $entered_grn->chg_price);
+               $entered_grn->this_quantity_inv, $mcost, $entered_grn->chg_price);
 }
 
 function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false,
index ab5cd43903192748fdc5dbc1fe57779bf1fcdb3f..543df442ce77c51ae1081256879220205e2bb129 100644 (file)
@@ -675,7 +675,7 @@ function remove_not_invoice_item($id)
         $price = get_tax_free_price_for_item($myrow['item_code'], $myrow['unit_price'], $supp['tax_group_id'], $supp['tax_included']);        
 
     add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
-        -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], $price);
+        -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $price);
         
     $clearing_act = get_company_pref('grn_clearing_act');
     if ($clearing_act) {    // otherwise GRN clearing account is not used
index 25fe3fc280ba95b28230cf35a2f87639ebadb3c8..b23b96001b0113f564294dcfb620b4dd909cbefc 100644 (file)
@@ -193,7 +193,7 @@ function add_credit_movements_item(&$credit_note, &$credit_line,
            add_stock_move(ST_CUSTCREDIT,  $credit_line->stock_id,
                    key($credit_note->trans_no), $credit_note->Location,
                        $credit_note->document_date, $reference, $credit_line->qty_dispatched,
-               $curr_std_cost, 0, $price);
+               $curr_std_cost, $price);
        }
 }
 
index 434401326d021da64121b45903f08150e81d6dde..51b709c12b5f10abb47bdbe008162b2c930b2d40 100644 (file)
@@ -96,7 +96,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
                if ($delivery_line->qty_dispatched != 0) {
                        add_stock_move(ST_CUSTDELIVERY, $delivery_line->stock_id, $delivery_no,
                                $delivery->Location, $delivery->document_date, $delivery->reference,
-                               -$delivery_line->qty_dispatched, $delivery_line->standard_cost, 0,
+                               -$delivery_line->qty_dispatched, $delivery_line->standard_cost,
                                 $line_price*(1-$delivery_line->discount_percent));
 
                        $stock_gl_code = get_stock_gl_code($delivery_line->stock_id);
index 55fc2ab63e49e06e73ff34bfc4f9c66c98c5c9dd..727e91c3a39e83c979ff677fb058f5382d156edc 100644 (file)
@@ -236,4 +236,6 @@ UPDATE `0_stock_moves` SET
        price = price*(1-discount_percent);
 ALTER TABLE `0_stock_moves` DROP COLUMN `discount_percent`;
 
+ALTER TABLE `0_stock_moves` DROP COLUMN `person_id`;
+
 DROP TABLE IF EXISTS `0_movement_types`;
index 75c9fe04a921510d6793234dadf844a465ec5dc5..62a93c3f28511175e350e3465af4fec3c4a0506e 100644 (file)
@@ -1812,7 +1812,6 @@ CREATE TABLE `0_stock_moves` (
   `type` smallint(6) NOT NULL DEFAULT '0',
   `loc_code` char(5) NOT NULL DEFAULT '',
   `tran_date` date NOT NULL DEFAULT '0000-00-00',
-  `person_id` int(11) DEFAULT NULL,
   `price` double NOT NULL DEFAULT '0',
   `reference` char(40) NOT NULL DEFAULT '',
   `qty` double NOT NULL DEFAULT '1',
@@ -1827,42 +1826,42 @@ CREATE TABLE `0_stock_moves` (
 --
 
 INSERT INTO `0_stock_moves` VALUES
-('1', '1', '102', '25', 'DEF', '2009-06-21', '2', '10', '', '100', '10'),
-('2', '1', '103', '25', 'DEF', '2009-06-21', '2', '11', '', '100', '11'),
-('3', '1', '104', '25', 'DEF', '2009-06-21', '2', '12', '', '100', '12'),
-('4', '1', '102', '26', 'DEF', '2009-06-21', '0', '0', '1', '-10', '0'),
-('5', '1', '103', '26', 'DEF', '2009-06-21', '0', '0', '1', '-10', '0'),
-('6', '1', '104', '26', 'DEF', '2009-06-21', '0', '0', '1', '-10', '0'),
-('7', '1', '3400', '26', 'DEF', '2009-06-21', '0', '0', '1', '10', '0'),
-('8', '2', '102', '13', 'DEF', '2009-06-21', '0', '30.4', '1', '-2', '10'),
-('9', '3', '102', '13', 'DEF', '2009-06-21', '0', '50', 'auto', '-1', '10'),
-('10', '4', '102', '13', 'DEF', '2009-06-21', '0', '35.89', 'auto', '-1', '10'),
-('11', '3', '102', '26', 'DEF', '2009-06-21', '0', '0', '3', '-2', '0'),
-('12', '3', '103', '26', 'DEF', '2009-06-21', '0', '0', '3', '-2', '0'),
-('13', '3', '104', '26', 'DEF', '2009-06-21', '0', '0', '3', '-2', '0'),
-('14', '3', '3400', '26', 'DEF', '2009-06-21', '0', '0', '3', '2', '0'),
-('15', '4', '102', '26', 'DEF', '2009-06-21', '0', '0', '4', '-4', '0'),
-('16', '4', '103', '26', 'DEF', '2009-06-21', '0', '0', '4', '-4', '0'),
-('17', '4', '104', '26', 'DEF', '2009-06-21', '0', '0', '4', '-4', '0'),
-('18', '4', '3400', '26', 'DEF', '2009-06-21', '0', '0', '4', '4', '0'),
-('19', '2', '102', '26', 'DEF', '2009-06-21', '0', '0', '', '-2', '0'),
-('20', '2', '103', '26', 'DEF', '2009-06-21', '0', '0', '', '-2', '0'),
-('21', '2', '104', '26', 'DEF', '2009-06-21', '0', '0', '', '-2', '0'),
-('22', '1', '3400', '29', 'DEF', '2009-06-21', '0', '0', '', '2', '0'),
-('23', '5', '102', '26', 'DEF', '2009-06-21', '0', '0', '5', '-5', '0'),
-('24', '5', '103', '26', 'DEF', '2009-06-21', '0', '0', '5', '-5', '0'),
-('25', '5', '104', '26', 'DEF', '2009-06-21', '0', '0', '5', '-5', '0'),
-('26', '5', '3400', '26', 'DEF', '2009-06-21', '0', '0', '5', '5', '0'),
-('27', '6', '102', '26', 'DEF', '2009-06-21', '0', '0', '6', '5', '0'),
-('28', '6', '103', '26', 'DEF', '2009-06-21', '0', '0', '6', '5', '0'),
-('29', '6', '104', '26', 'DEF', '2009-06-21', '0', '0', '6', '5', '0'),
-('30', '6', '3400', '26', 'DEF', '2009-06-21', '0', '0', '6', '-5', '0'),
-('31', '7', '102', '26', 'DEF', '2009-06-21', '0', '0', '7', '2', '0'),
-('32', '7', '103', '26', 'DEF', '2009-06-21', '0', '0', '7', '2', '0'),
-('33', '7', '104', '26', 'DEF', '2009-06-21', '0', '0', '7', '2', '0'),
-('34', '7', '3400', '26', 'DEF', '2009-06-21', '0', '0', '7', '-2', '0'),
-('35', '5', '102', '13', 'DEF', '2009-06-21', '0', '50', 'auto', '-1', '10'),
-('36', '3', '102', '11', 'DEF', '2009-06-21', '0', '37.68', 'Return Ex Inv: 18', '1', '10');
+('1', '1', '102', '25', 'DEF', '2009-06-21',  '10', '', '100', '10'),
+('2', '1', '103', '25', 'DEF', '2009-06-21',  '11', '', '100', '11'),
+('3', '1', '104', '25', 'DEF', '2009-06-21',  '12', '', '100', '12'),
+('4', '1', '102', '26', 'DEF', '2009-06-21',  '0', '1', '-10', '0'),
+('5', '1', '103', '26', 'DEF', '2009-06-21',  '0', '1', '-10', '0'),
+('6', '1', '104', '26', 'DEF', '2009-06-21',  '0', '1', '-10', '0'),
+('7', '1', '3400', '26', 'DEF', '2009-06-21', '0', '1', '10', '0'),
+('8', '2', '102', '13', 'DEF', '2009-06-21',  '30.4', '1', '-2', '10'),
+('9', '3', '102', '13', 'DEF', '2009-06-21',  '50', 'auto', '-1', '10'),
+('10', '4', '102', '13', 'DEF', '2009-06-21', '35.89', 'auto', '-1', '10'),
+('11', '3', '102', '26', 'DEF', '2009-06-21', '0', '3', '-2', '0'),
+('12', '3', '103', '26', 'DEF', '2009-06-21', '0', '3', '-2', '0'),
+('13', '3', '104', '26', 'DEF', '2009-06-21', '0', '3', '-2', '0'),
+('14', '3', '3400', '26', 'DEF', '2009-06-21', '0', '3', '2', '0'),
+('15', '4', '102', '26', 'DEF', '2009-06-21', '0', '4', '-4', '0'),
+('16', '4', '103', '26', 'DEF', '2009-06-21', '0', '4', '-4', '0'),
+('17', '4', '104', '26', 'DEF', '2009-06-21', '0', '4', '-4', '0'),
+('18', '4', '3400', '26', 'DEF', '2009-06-21', '0', '4', '4', '0'),
+('19', '2', '102', '26', 'DEF', '2009-06-21', '0', '', '-2', '0'),
+('20', '2', '103', '26', 'DEF', '2009-06-21', '0', '', '-2', '0'),
+('21', '2', '104', '26', 'DEF', '2009-06-21', '0', '', '-2', '0'),
+('22', '1', '3400', '29', 'DEF', '2009-06-21', '0', '', '2', '0'),
+('23', '5', '102', '26', 'DEF', '2009-06-21', '0', '5', '-5', '0'),
+('24', '5', '103', '26', 'DEF', '2009-06-21', '0', '5', '-5', '0'),
+('25', '5', '104', '26', 'DEF', '2009-06-21', '0', '5', '-5', '0'),
+('26', '5', '3400', '26', 'DEF', '2009-06-21', '0', '5', '5', '0'),
+('27', '6', '102', '26', 'DEF', '2009-06-21', '0', '6', '5', '0'),
+('28', '6', '103', '26', 'DEF', '2009-06-21', '0', '6', '5', '0'),
+('29', '6', '104', '26', 'DEF', '2009-06-21', '0', '6', '5', '0'),
+('30', '6', '3400', '26', 'DEF', '2009-06-21', '0', '6', '-5', '0'),
+('31', '7', '102', '26', 'DEF', '2009-06-21', '0', '7', '2', '0'),
+('32', '7', '103', '26', 'DEF', '2009-06-21', '0', '7', '2', '0'),
+('33', '7', '104', '26', 'DEF', '2009-06-21', '0', '7', '2', '0'),
+('34', '7', '3400', '26', 'DEF', '2009-06-21', '0', '7', '-2', '0'),
+('35', '5', '102', '13', 'DEF', '2009-06-21', '50', 'auto', '-1', '10'),
+('36', '3', '102', '11', 'DEF', '2009-06-21', '37.68', 'Return Ex Inv: 18', '1', '10');
 
 ### Structure of table `0_supp_allocations` ###
 
index 1cd4bd33fda0c83fbe9b72ad05d5263e24db02cf..31947a52b602dc8590f82c5c3a7871001516334d 100644 (file)
@@ -1618,7 +1618,6 @@ CREATE TABLE `0_stock_moves` (
   `type` smallint(6) NOT NULL DEFAULT '0',
   `loc_code` char(5) NOT NULL DEFAULT '',
   `tran_date` date NOT NULL DEFAULT '0000-00-00',
-  `person_id` int(11) DEFAULT NULL,
   `price` double NOT NULL DEFAULT '0',
   `reference` char(40) NOT NULL DEFAULT '',
   `qty` double NOT NULL DEFAULT '1',