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,
19 $details = get_work_order($woid);
21 if (strlen($details[0]) == 0)
23 echo _("The order number sent is not valid.");
28 if (work_order_is_closed($woid))
30 display_error("UNEXPECTED : Issuing items for a closed Work Order");
35 // insert the actual issue
36 $sql = "INSERT INTO ".TB_PREF."wo_issues (workorder_id, reference, issue_date, loc_code, workcentre_id)
37 VALUES ($woid, ".db_escape($ref).", '" .
38 date2sql($date_) . "', ".db_escape($location).", $workcentre)";
39 db_query($sql,"The work order issue could not be added");
41 $number = db_insert_id();
43 foreach ($items as $item)
47 $item->quantity = -$item->quantity;
49 // insert a -ve stock move for each item
50 add_stock_move(28, $item->stock_id, $number,
51 $location, $date_, $memo_, -$item->quantity, 0);
53 $sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued)
54 VALUES ('$number', '$item->stock_id', $item->quantity)";
55 db_query($sql,"A work order issue item could not be added");
59 add_comments(28, $number, $date_, $memo_);
61 references::save_last($ref, 28);
66 //--------------------------------------------------------------------------------------
68 function get_work_order_issues($woid)
70 $sql = "SELECT * FROM ".TB_PREF."wo_issues WHERE workorder_id=$woid ORDER BY issue_no";
71 return db_query($sql, "The work order issues could not be retrieved");
74 function get_additional_issues($woid)
76 $sql = "SELECT ".TB_PREF."wo_issues.*, ".TB_PREF."wo_issue_items.*
77 FROM ".TB_PREF."wo_issues, ".TB_PREF."wo_issue_items
78 WHERE ".TB_PREF."wo_issues.issue_no=".TB_PREF."wo_issue_items.issue_id
79 AND ".TB_PREF."wo_issues.workorder_id=$woid ORDER BY ".TB_PREF."wo_issue_items.id";
80 return db_query($sql, "The work order issues could not be retrieved");
82 //--------------------------------------------------------------------------------------
84 function get_work_order_issue($issue_no)
86 $sql = "SELECT DISTINCT ".TB_PREF."wo_issues.*, ".TB_PREF."workorders.stock_id,
87 ".TB_PREF."stock_master.description, ".TB_PREF."locations.location_name, ".TB_PREF."workcentres.name AS WorkCentreName
88 FROM ".TB_PREF."wo_issues, ".TB_PREF."workorders, ".TB_PREF."stock_master, ".TB_PREF."locations, ".TB_PREF."workcentres
89 WHERE issue_no='$issue_no'
90 AND ".TB_PREF."workorders.id = ".TB_PREF."wo_issues.workorder_id
91 AND ".TB_PREF."locations.loc_code = ".TB_PREF."wo_issues.loc_code
92 AND ".TB_PREF."workcentres.id = ".TB_PREF."wo_issues.workcentre_id
93 AND ".TB_PREF."stock_master.stock_id = ".TB_PREF."workorders.stock_id";
94 $result = db_query($sql, "A work order issue could not be retrieved");
96 return db_fetch($result);
99 //--------------------------------------------------------------------------------------
101 function get_work_order_issue_details($issue_no)
103 $sql = "SELECT ".TB_PREF."wo_issue_items.*,".TB_PREF."stock_master.description, ".TB_PREF."stock_master.units
104 FROM ".TB_PREF."wo_issue_items, ".TB_PREF."stock_master
105 WHERE issue_id=$issue_no
106 AND ".TB_PREF."stock_master.stock_id=".TB_PREF."wo_issue_items.stock_id
107 ORDER BY ".TB_PREF."wo_issue_items.id";
108 return db_query($sql, "The work order issue items could not be retrieved");
111 //--------------------------------------------------------------------------------------
113 function exists_work_order_issue($issue_no)
115 $sql = "SELECT issue_no FROM ".TB_PREF."wo_issues WHERE issue_no=$issue_no";
116 $result = db_query($sql, "Cannot retreive a wo issue");
118 return (db_num_rows($result) > 0);
121 //--------------------------------------------------------------------------------------
123 function void_work_order_issue($type_no)
127 // void the actual issue items and their quantities
128 $sql = "UPDATE ".TB_PREF."wo_issue_items Set qty_issued = 0 WHERE issue_id=$type_no";
129 db_query($sql,"A work order issue item could not be voided");
131 // void all related stock moves
132 void_stock_move(28, $type_no);
134 // void any related gl trans
135 void_gl_trans(28, $type_no, true);
137 commit_transaction();
141 //--------------------------------------------------------------------------------------