3 function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
7 $details = get_work_order($woid);
9 if (strlen($details[0]) == 0)
11 echo _("The order number sent is not valid.");
15 if (work_order_is_closed($woid))
17 display_error("UNEXPECTED : Producing Items for a closed Work Order");
22 $date = date2sql($date_);
24 $sql = "INSERT INTO ".TB_PREF."wo_manufacture (workorder_id, reference, quantity, date_)
25 VALUES ($woid, '$ref', $quantity, '$date')";
27 db_query($sql,"A work order manufacture could not be added");
31 // insert a +ve stock move for the item being manufactured
32 // negative means "unproduce" or unassemble
33 add_stock_move(29, $details["stock_id"], $id,
34 $details["loc_code"], $date_, $memo_, $quantity, 0);
36 // update wo quantity and close wo if requested
37 work_order_update_finished_quantity($woid, $quantity, $close_wo);
40 add_comments(29, $id, $date_, $memo_);
42 add_forms_for_sys_type(29, $id, $quantity, $details["loc_code"]);
44 references::save_last($ref, 29);
49 //--------------------------------------------------------------------------------------------
51 function get_work_order_produce($id)
53 $sql = "SELECT ".TB_PREF."wo_manufacture.*,".TB_PREF."workorders.stock_id, ".TB_PREF."stock_master.description AS StockDescription
54 FROM ".TB_PREF."wo_manufacture, ".TB_PREF."workorders, ".TB_PREF."stock_master
55 WHERE ".TB_PREF."wo_manufacture.workorder_id=".TB_PREF."workorders.id
56 AND ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id
57 AND ".TB_PREF."wo_manufacture.id=$id";
58 $result = db_query($sql, "The work order production could not be retrieved");
60 return db_fetch($result);
63 //--------------------------------------------------------------------------------------
65 function get_work_order_productions($woid)
67 $sql = "SELECT * FROM ".TB_PREF."wo_manufacture WHERE workorder_id=$woid ORDER BY id";
68 return db_query($sql, "The work order issues could not be retrieved");
71 //--------------------------------------------------------------------------------------
73 function exists_work_order_produce($id)
75 $sql = "SELECT id FROM ".TB_PREF."wo_manufacture WHERE id=$id";
76 $result = db_query($sql, "Cannot retreive a wo production");
78 return (db_num_rows($result) > 0);
81 //--------------------------------------------------------------------------------------------
83 function void_work_order_produce($type_no)
87 $row = get_work_order_produce($type_no);
89 // deduct the quantity of this production from the parent work order
90 work_order_update_finished_quantity($row["workorder_id"], -$row["quantity"]);
92 // clear the production record
93 $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=$type_no";
94 db_query($sql, "Cannot void a wo production");
96 // void all related stock moves
97 void_stock_move(29, $type_no);
99 // void any related gl trans
100 void_gl_trans(29, $type_no, true);
102 commit_transaction();