2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
16 $details = get_work_order($woid);
18 if (strlen($details[0]) == 0)
20 echo _("The order number sent is not valid.");
24 if (work_order_is_closed($woid))
26 display_error("UNEXPECTED : Producing Items for a closed Work Order");
31 $date = date2sql($date_);
33 $sql = "INSERT INTO ".TB_PREF."wo_manufacture (workorder_id, reference, quantity, date_)
34 VALUES (".db_escape($woid).", ".db_escape($ref).", ".db_escape($quantity)
37 db_query($sql,"A work order manufacture could not be added");
41 // -------------------------------------------------------------------------
43 work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, true);
45 // -------------------------------------------------------------------------
46 // insert a +ve stock move for the item being manufactured
47 // negative means "unproduce" or unassemble
48 add_stock_move(29, $details["stock_id"], $id,
49 $details["loc_code"], $date_, $memo_, $quantity, 0);
50 // update wo quantity and close wo if requested
51 work_order_update_finished_quantity($woid, $quantity, $close_wo);
55 add_comments(29, $id, $date_, $memo_);
57 references::save_last($ref, 29);
62 //--------------------------------------------------------------------------------------------
64 function get_work_order_produce($id)
66 $sql = "SELECT ".TB_PREF."wo_manufacture.*,".TB_PREF."workorders.stock_id, "
67 .TB_PREF."stock_master.description AS StockDescription
68 FROM ".TB_PREF."wo_manufacture, ".TB_PREF."workorders, ".TB_PREF."stock_master
69 WHERE ".TB_PREF."wo_manufacture.workorder_id=".TB_PREF."workorders.id
70 AND ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id
71 AND ".TB_PREF."wo_manufacture.id=".db_escape($id);
72 $result = db_query($sql, "The work order production could not be retrieved");
74 return db_fetch($result);
77 //--------------------------------------------------------------------------------------
79 function get_work_order_productions($woid)
81 $sql = "SELECT * FROM ".TB_PREF."wo_manufacture WHERE workorder_id="
82 .db_escape($woid)." ORDER BY id";
83 return db_query($sql, "The work order issues could not be retrieved");
86 //--------------------------------------------------------------------------------------
88 function exists_work_order_produce($id)
90 $sql = "SELECT id FROM ".TB_PREF."wo_manufacture WHERE id=".db_escape($id);
91 $result = db_query($sql, "Cannot retreive a wo production");
93 return (db_num_rows($result) > 0);
96 //--------------------------------------------------------------------------------------------
98 function void_work_order_produce($type_no)
102 $row = get_work_order_produce($type_no);
104 // deduct the quantity of this production from the parent work order
105 work_order_update_finished_quantity($row["workorder_id"], -$row["quantity"]);
107 // clear the production record
108 $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".db_escape($type_no);
109 db_query($sql, "Cannot void a wo production");
111 // void all related stock moves
112 void_stock_move(29, $type_no);
114 // void any related gl trans
115 void_gl_trans(29, $type_no, true);
117 commit_transaction();