Small adjustments
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 11 Jun 2009 00:09:05 +0000 (00:09 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 11 Jun 2009 00:09:05 +0000 (00:09 +0000)
manufacturing/includes/db/work_order_produce_items_db.inc
manufacturing/includes/db/work_orders_db.inc
manufacturing/includes/db/work_orders_quick_db.inc
manufacturing/work_order_costs.php
manufacturing/work_order_entry.php

index c9131df8ba586d790c3fc6a4d187238e14a5d73c..ef5640c3448f8c83b0341b73bef10588f3b31558 100644 (file)
@@ -37,19 +37,19 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
 
        $id = db_insert_id();
 
+       // -------------------------------------------------------------------------
+
+       work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, true);
+
+       // -------------------------------------------------------------------------
        // insert a +ve stock move for the item being manufactured
        // negative means "unproduce" or unassemble
        add_stock_move(29, $details["stock_id"], $id,
                $details["loc_code"], $date_, $memo_, $quantity, 0);
-
        // update wo quantity and close wo if requested
        work_order_update_finished_quantity($woid, $quantity, $close_wo);
 
-       // -------------------------------------------------------------------------
 
-       work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, true);
-
-       // -------------------------------------------------------------------------
        if ($memo_)
                add_comments(29, $id, $date_, $memo_);
 
index 09a402c85d0b949a05803a3a35ba07cda77f4fb7..1c4fe7e282ab70a4f822f3f35aa9bdbd854943e3 100644 (file)
@@ -79,11 +79,11 @@ function add_issue_cost($stock_id, $qty, $date_, $costs)
        $myrow = db_fetch($result);
        $material_cost =  $myrow['material_cost'];
        $qoh = get_qoh_on_date($stock_id, null, $date_);
-       if ($qoh <= 0)
+       if ($qoh + $qty  <= 0)
                $material_cost = 0;
        else
-               $material_cost = ($qoh * $material_cost + $qty * $costs) /      $qoh;
-       $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
+               $material_cost = ($qty * $costs) /      ($qoh + $qty);
+       $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=material_cost+$material_cost
                WHERE stock_id='$stock_id'";
        db_query($sql,"The cost details for the inventory item could not be updated");
 }
index b1f9a6c7a19c65b42ce75e1a48ef85e6f2e637cd..52b5081968b9b9eb1545730d0284a9ef085c9685 100644 (file)
@@ -125,7 +125,8 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced
                                null, -$issue_cost);
                        $issue_total += $issue_cost;
                }
-               add_issue_cost($stock_id, $units_reqd, $date_, $issue_total);
+               if ($issue_total != 0)
+                       add_issue_cost($stock_id, $units_reqd, $date_, $issue_total);
                $result = get_gl_wo_cost_trans($woid, WO_LABOUR);
                $lcost = 0;
                while ($row = db_fetch($result))
index a4ebdf2e6f5c0a97670cc4f5935527e68ca2570a..0d68a3f9db4e9413aac25c93f6a3b04bb999532b 100644 (file)
@@ -103,6 +103,7 @@ function can_process()
 
 if (isset($_POST['process']) && can_process() == true)
 {
+       begin_transaction();
        add_gl_trans_std_cost(systypes::work_order(), $_POST['selected_id'], $_POST['date_'], $_POST['cr_acc'],
                0, 0, $wo_cost_types[$_POST['PaymentType']], -input_num('costs'), payment_person_types::WorkOrder(), $_POST['PaymentType']);
        $is_bank_to = is_bank_account($_POST['cr_acc']);
@@ -116,7 +117,7 @@ if (isset($_POST['process']) && can_process() == true)
        add_gl_trans_std_cost(systypes::work_order(), $_POST['selected_id'], $_POST['date_'], $_POST['db_acc'],
                $_POST['dim1'], $_POST['dim2'], $wo_cost_types[$_POST['PaymentType']], input_num('costs'), payment_person_types::WorkOrder(), 
                        $_POST['PaymentType']);
-       
+       commit_transaction();   
 
        meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['selected_id']);
 }
index 18abddb5762fc20a75d89411960d3aaa4e10c2bf..7977a59db19c09485aba6aaa99b2d6800eb4cd74 100644 (file)
@@ -380,7 +380,7 @@ else
        wo_types_list_row(_("Type:"), 'type', null);
 }
 
-if ($_POST['released'] == true)
+if (get_post('released'))
 {
        hidden('stock_id', $_POST['stock_id']);
        hidden('StockLocation', $_POST['StockLocation']);
@@ -433,7 +433,7 @@ else
        
 }
 
-if ($_POST['released'])
+if (get_post('released'))
        label_row(_("Released On:"),$_POST['released_date']);
 
 textarea_row(_("Memo:"), 'memo_', null, 40, 5);
@@ -445,7 +445,7 @@ if (isset($selected_id))
        echo "<table align=center><tr>";
 
        submit_cells('UPDATE_ITEM', _("Update"), '', _('Save changes to work order'), true);
-       if (isset($_POST['released']))
+       if (get_post('released'))
        {
                submit_cells('close', _("Close This Work Order"),'','',true);
        }