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 $page_security = 'SA_BOMREP';
13 // ----------------------------------------------------------------
17 // Title: Work Order Listing
18 // ----------------------------------------------------------------
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/includes/banking.inc");
25 include_once($path_to_root . "/gl/includes/gl_db.inc");
26 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
28 //----------------------------------------------------------------------------------------------------
30 print_work_order_listing();
32 function getTransactions($items, $open_only, $location)
38 location.location_name,
41 workorder.units_issued,
43 workorder.required_by,
46 FROM ".TB_PREF."workorders as workorder
47 LEFT JOIN ".TB_PREF."voided v ON v.id=workorder.id and v.type=".ST_WORKORDER.","
48 .TB_PREF."stock_master as item,"
49 .TB_PREF."locations as location
51 AND workorder.stock_id=item.stock_id
52 AND workorder.loc_code=location.loc_code";
55 $sql .= " AND workorder.closed=0";
58 $sql .= " AND workorder.loc_code=".db_escape($location);
61 $sql .= " AND workorder.stock_id=".db_escape($items);
63 $sql .=" ORDER BY workorder.id";
65 return db_query($sql,"No transactions were returned");
69 function print_gl_rows(&$rep, $result, $title)
71 global $systypes_array;
73 $dec = user_price_dec();
75 if (db_num_rows($result))
77 $rep->Line($rep->row -= 4);
80 $rep->TextCol(3, 11, $title);
82 $rep->Line($rep->row -= 4);
83 while($myrow = db_fetch($result)) {
85 $rep->TextCol(0, 2, $systypes_array[$myrow['type']] . ' ' . $myrow['type_no'], -2);
86 $rep->TextCol(2, 3, sql2date($myrow["tran_date"]), -2);
87 $rep->TextCol(3, 4, $myrow['account'], -2);
88 $rep->TextCol(4, 5, $myrow['account_name'], -2);
89 if ($myrow['amount'] > 0.0)
90 $rep->AmountCol(5, 6, $myrow['amount'], $dec);
92 $rep->AmountCol(6, 7, $myrow['amount'] * -1, $dec, -1);
93 $rep->TextCol(8, 11, $myrow['memo_']);
98 //----------------------------------------------------------------------------------------------------
100 function print_work_order_listing()
102 global $path_to_root, $wo_types_array;
104 $item = $_POST['PARAM_0'];
105 $location = $_POST['PARAM_1'];
106 $open_only = $_POST['PARAM_2'];
107 $show_gl = $_POST['PARAM_3'];
108 $comments = $_POST['PARAM_4'];
109 $orientation = $_POST['PARAM_5'];
110 $destination = $_POST['PARAM_6'];
112 include_once($path_to_root . "/reporting/includes/excel_report.inc");
114 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
116 $orientation = ($orientation ? 'L' : 'P');
122 $row = get_item($item);
123 $items = $row['description'];
129 $loc = get_location_name($location);
131 $open = $open_only == 1 ? _('Yes') : _('No');
132 $show = $show_gl == 1 ? _('Yes') : _('No');
134 $cols = array(0, 100, 120, 165, 210, 275, 315, 375, 385, 440, 495, 555);
136 $headers = array(_('Type'), '#', ('Reference'), _('Location'), _('Item'), _('Required'), _('Manufactured'), ' ', _('Date'), _('Required By'), _('Closed'));
141 $headers2 = array(_("Transaction"), ' ', _("Date"), _("Account Code"),' ' . _("Account Name"), _("Debit"), _("Credit"), ' ', _("Memo"));
149 $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'left', 'left', 'left', 'left');
151 $params = array( 0 => $comments,
152 1 => array('text' => _('Items'), 'from' => $items, 'to' => ''),
153 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''),
154 3 => array('text' => _('Open Only'), 'from' => $open, 'to' => ''),
155 4 => array('text' => _('Show GL Rows'), 'from' => $show, 'to' => ''),
158 $rep = new FrontReport(_('Work Order Listing'), "WorkOrderListing", user_pagesize(), 9, $orientation);
159 if ($orientation == 'L')
160 recalculate_cols($cols);
164 $rep->Info($params, $cols2, $headers2, $aligns, $cols, $headers);
166 $rep->Info($params, $cols, $headers, $aligns);
169 $res = getTransactions($item, $open_only, $location);
170 while ($trans=db_fetch($res))
172 $rep->TextCol(0, 1, $wo_types_array[$trans['type']]);
173 $rep->TextCol(1, 2, $trans['id'], -1);
174 $rep->TextCol(2, 3, $trans['wo_ref'], -1);
175 $rep->TextCol(3, 4, $trans['location_name'], -1);
176 $rep->TextCol(4, 5, $trans['description'], -1);
177 $dec = get_qty_dec($trans['stock_id']);
178 $rep->AmountCol(5, 6, $trans['units_reqd'], $dec);
179 $rep->AmountCol(6, 7, $trans['units_issued'], $dec);
180 $rep->TextCol(7, 8, '', -1);
181 $rep->TextCol(8, 9, sql2date($trans['date_']), -1);
182 $rep->TextCol(9, 10, sql2date($trans['required_by']), -1);
183 $rep->TextCol(10, 11, $trans['closed'] ? ' ' : _('No'), -1);
187 $productions = get_gl_wo_productions($trans['id'], true);
188 print_gl_rows($rep, $productions, _("Finished Product Requirements"));
190 $issues = get_gl_wo_issue_trans($trans['id'], -1, true);
191 print_gl_rows($rep, $issues, _("Additional Material Issues"));
193 $costs = get_gl_wo_cost_trans($trans['id'], -1, true);
194 print_gl_rows($rep, $costs, _("Additional Costs"));
196 $wo = get_gl_trans(ST_WORKORDER, $trans['id']);
197 print_gl_rows($rep, $wo, _("Finished Product Receival"));
198 $rep->Line($rep->row - 2);
203 $rep->Line($rep->row);