3 //--------------------------------------------------------------------------------------
5 function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $additional_costs, $memo_)
9 // if unassembling, reverse the stock movements
10 if ($type == wo_types::unassemble())
11 $units_reqd = -$units_reqd;
13 $date = date2sql($date_);
14 if (!isset($additional_costs) || ($additional_costs == ""))
15 $additional_costs = 0;
17 $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, units_issued, stock_id,
18 type, additional_costs, date_, released_date, required_by, released, closed)
19 VALUES ('$wo_ref', '$loc_code', $units_reqd, $units_reqd, '$stock_id',
20 $type, $additional_costs, '$date', '$date', '$date', 1, 1)";
21 db_query($sql, "could not add work order");
23 $woid = db_insert_id();
25 //--------------------------------------------------------------------------
27 // create Work Order Requirements based on the bom
28 $result = get_bom($stock_id);
30 while ($bom_item = db_fetch($result))
33 $unit_quantity = $bom_item["quantity"];
34 $item_quantity = $bom_item["quantity"] * $units_reqd;
37 $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, units_issued, loc_code)
38 VALUES ($woid, " . "'" . $bom_item["component"] . "'" . ",
39 ". $bom_item["workcentre_added"] . ",
40 $unit_quantity, $item_quantity, '" . $bom_item["loc_code"] . "')";
42 db_query($sql, "The work order requirements could not be added");
44 // insert a -ve stock move for each item
45 add_stock_move(systypes::work_order(), $bom_item["component"], $woid,
46 $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, 0);
50 // -------------------------------------------------------------------------
52 // insert a +ve stock move for the item being manufactured
53 add_stock_move(systypes::work_order(), $stock_id, $woid, $loc_code, $date_,
54 $wo_ref, $units_reqd, 0);
56 // -------------------------------------------------------------------------
58 work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $additional_costs);
60 // -------------------------------------------------------------------------
62 add_comments(systypes::work_order(), $woid, $date_, $memo_);
64 add_forms_for_sys_type(systypes::work_order(), $woid, $type);
66 references::save_last($wo_ref, systypes::work_order());
72 //--------------------------------------------------------------------------------------
74 function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $additional_costs)
76 $result = get_bom($stock_id);
78 // credit all the components
80 while ($bom_item = db_fetch($result))
83 $bom_accounts = get_stock_gl_code($bom_item["component"]);
85 $bom_cost = $bom_item["standard_cost"] * $bom_item["quantity"] * $units_reqd;
87 add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $bom_accounts["inventory_account"], 0, 0,
89 alert("bokade bom- cost ".-$bom_cost);
91 $total_cost += $bom_cost;
93 // credit additional costs
94 $item_accounts = get_stock_gl_code($stock_id);
95 add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["assembly_account"],
96 $item_accounts["dimension_id"], $item_accounts["dimension2_id"], null, -$additional_costs);
97 alert("bokade additional cost ".-$additional_costs.", acc = ".$item_accounts["assembly_account"]);
99 // debit total components + additional
100 $total_cost += $additional_costs;
101 add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["inventory_account"],
102 0, 0, null, $total_cost);
103 alert("bokade total- cost ".$total_cost);
106 //--------------------------------------------------------------------------------------