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 //--------------------------------------------------------------------------------------
14 function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $workcentre,
21 $details = get_work_order($woid);
23 if (strlen($details[0]) == 0)
25 echo _("The order number sent is not valid.");
30 if (work_order_is_closed($woid))
32 display_error("UNEXPECTED : Issuing items for a closed Work Order");
37 // insert the actual issue
38 $sql = "INSERT INTO ".TB_PREF."wo_issues (workorder_id, reference, issue_date, loc_code, workcentre_id)
39 VALUES (".db_escape($woid).", ".db_escape($ref).", '" .
40 date2sql($date_) . "', ".db_escape($location).", ".db_escape($workcentre).")";
41 db_query($sql,"The work order issue could not be added");
43 $number = db_insert_id();
45 foreach ($items as $item)
49 $item->quantity = -$item->quantity;
51 // insert a -ve stock move for each item
52 add_stock_move(ST_MANUISSUE, $item->stock_id, $number,
53 $location, $date_, $memo_, -$item->quantity, 0);
55 $sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued)
56 VALUES (".db_escape($number).", ".db_escape($item->stock_id).", "
57 .db_escape($item->quantity).")";
58 db_query($sql,"A work order issue item could not be added");
62 add_comments(ST_MANUISSUE, $number, $date_, $memo_);
64 $Refs->save(ST_MANUISSUE, $number, $ref);
65 add_audit_trail(ST_MANUISSUE, $number, $date_);
70 //--------------------------------------------------------------------------------------
72 function get_work_order_issues($woid)
74 $sql = "SELECT * FROM ".TB_PREF."wo_issues WHERE workorder_id=".db_escape($woid)
75 ." ORDER BY issue_no";
76 return db_query($sql, "The work order issues could not be retrieved");
79 function get_additional_issues($woid)
81 $sql = "SELECT ".TB_PREF."wo_issues.*, ".TB_PREF."wo_issue_items.*
82 FROM ".TB_PREF."wo_issues, ".TB_PREF."wo_issue_items
83 WHERE ".TB_PREF."wo_issues.issue_no=".TB_PREF."wo_issue_items.issue_id
84 AND ".TB_PREF."wo_issues.workorder_id=".db_escape($woid)
85 ." ORDER BY ".TB_PREF."wo_issue_items.id";
86 return db_query($sql, "The work order issues could not be retrieved");
88 //--------------------------------------------------------------------------------------
90 function get_work_order_issue($issue_no)
92 $sql = "SELECT DISTINCT ".TB_PREF."wo_issues.*, ".TB_PREF."workorders.stock_id,
93 ".TB_PREF."stock_master.description, ".TB_PREF."locations.location_name, "
94 .TB_PREF."workcentres.name AS WorkCentreName
95 FROM ".TB_PREF."wo_issues, ".TB_PREF."workorders, ".TB_PREF."stock_master, "
96 .TB_PREF."locations, ".TB_PREF."workcentres
97 WHERE issue_no=".db_escape($issue_no)."
98 AND ".TB_PREF."workorders.id = ".TB_PREF."wo_issues.workorder_id
99 AND ".TB_PREF."locations.loc_code = ".TB_PREF."wo_issues.loc_code
100 AND ".TB_PREF."workcentres.id = ".TB_PREF."wo_issues.workcentre_id
101 AND ".TB_PREF."stock_master.stock_id = ".TB_PREF."workorders.stock_id";
102 $result = db_query($sql, "A work order issue could not be retrieved");
104 return db_fetch($result);
107 //--------------------------------------------------------------------------------------
109 function get_work_order_issue_details($issue_no)
111 $sql = "SELECT ".TB_PREF."wo_issue_items.*,"
112 .TB_PREF."stock_master.description, ".TB_PREF."stock_master.units
113 FROM ".TB_PREF."wo_issue_items, ".TB_PREF."stock_master
114 WHERE issue_id=".db_escape($issue_no)."
115 AND ".TB_PREF."stock_master.stock_id=".TB_PREF."wo_issue_items.stock_id
116 ORDER BY ".TB_PREF."wo_issue_items.id";
117 return db_query($sql, "The work order issue items could not be retrieved");
120 //--------------------------------------------------------------------------------------
122 function exists_work_order_issue($issue_no)
124 $sql = "SELECT issue_no FROM ".TB_PREF."wo_issues WHERE issue_no=".db_escape($issue_no);
125 $result = db_query($sql, "Cannot retreive a wo issue");
127 return (db_num_rows($result) > 0);
130 //--------------------------------------------------------------------------------------
132 function void_work_order_issue($type_no)
136 // void the actual issue items and their quantities
137 $sql = "UPDATE ".TB_PREF."wo_issue_items Set qty_issued = 0 WHERE issue_id="
138 .db_escape($type_no);
139 db_query($sql,"A work order issue item could not be voided");
141 // void all related stock moves
142 void_stock_move(ST_MANUISSUE, $type_no);
144 // void any related gl trans
145 void_gl_trans(ST_MANUISSUE, $type_no, true);
147 commit_transaction();
151 //--------------------------------------------------------------------------------------