Changed Report Workorder Listing to include an option for listing GL rows.
[fa-stable.git] / reporting / rep402.php
1 <?php
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 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       Work Order Listing
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
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");
27
28 //----------------------------------------------------------------------------------------------------
29
30 print_work_order_listing();
31
32 function getTransactions($items, $open_only, $location)
33 {
34         $sql = "SELECT
35                 workorder.id,
36                 workorder.wo_ref,
37                 workorder.type,
38                 location.location_name,
39                 item.description,
40                 workorder.units_reqd,
41                 workorder.units_issued,
42                 workorder.date_,
43                 workorder.required_by,
44                 workorder.closed,
45                 workorder.stock_id
46                 FROM ".TB_PREF."workorders as workorder,"
47                         .TB_PREF."stock_master as item,"
48                         .TB_PREF."locations as location
49                 WHERE workorder.stock_id=item.stock_id 
50                         AND workorder.loc_code=location.loc_code";
51
52         if ($open_only != 0)
53                 $sql .= " AND workorder.closed=0";
54
55         if ($location != '')
56                 $sql .= " AND workorder.loc_code=".db_escape($location);
57
58         if ($items != '')
59                 $sql .= " AND workorder.stock_id=".db_escape($items);
60         
61         $sql .=" ORDER BY workorder.id";        
62
63     return db_query($sql,"No transactions were returned");
64
65 }
66
67 function print_gl_rows(&$rep, $result, $title)
68 {
69         global $systypes_array;
70
71         $dec = user_price_dec();
72
73     if (db_num_rows($result))
74     {
75                 $rep->Line($rep->row - 2);
76                 $rep->NewLine();
77                 $rep->Font('italic');
78                 $rep->TextCol(3, 11, $title);
79                 $rep->Font();
80                 $rep->Line($rep->row - 2);
81                 while($myrow = db_fetch($result)) {
82                         $rep->NewLine();
83                         $rep->TextCol(0, 2, $systypes_array[$myrow['type']] . ' ' . $myrow['type_no'], -2);
84                         $rep->TextCol(2, 3, sql2date($myrow["tran_date"]), -2);
85                         $rep->TextCol(3, 4, $myrow['account'], -2);
86                         $rep->TextCol(4, 5, $myrow['account_name'], -2);
87                         if ($myrow['amount'] > 0.0)
88                                 $rep->AmountCol(5, 6, $myrow['amount'], $dec);
89                         else    
90                                 $rep->AmountCol(6, 7, $myrow['amount'] * -1, $dec, -1);
91                         $rep->TextCol(8, 11, $myrow['memo_']);
92                 }
93         }
94 }
95
96 //----------------------------------------------------------------------------------------------------
97
98 function print_work_order_listing()
99 {
100     global $path_to_root, $wo_types_array;
101
102     $item = $_POST['PARAM_0'];
103     $location = $_POST['PARAM_1'];
104     $open_only = $_POST['PARAM_2'];
105     $show_gl = $_POST['PARAM_3'];
106         $comments = $_POST['PARAM_4'];
107         $orientation = $_POST['PARAM_5'];
108         $destination = $_POST['PARAM_6'];
109         if ($destination)
110                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
111         else
112                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
113
114         $orientation = ($orientation ? 'L' : 'P');
115
116         if ($item == '')
117                 $items = _('All');
118         else
119         {
120                 $row = get_item($item);
121                 $items = $row['description']; 
122         }
123
124         if ($location == '')
125                 $loc = _('All');
126         else
127                 $loc = get_location_name($location);
128
129         $open = $open_only == 1 ? _('Yes') : _('No');
130         $show = $show_gl == 1 ? _('Yes') : _('No');
131         
132         $cols = array(0, 100, 120, 165, 210, 275, 315, 375, 385, 440, 495, 555);
133
134         $headers = array(_('Type'), '#', ('Reference'), _('Location'), _('Item'), _('Required'), _('Manufactured'), ' ', _('Date'), _('Required By'), _('Closed'));
135
136         if ($show_gl)
137         {
138                 $cols2 = $cols;
139                 $headers2 = array(_("Transaction"), ' ', _("Date"), _("Account Code"),' ' . _("Account Name"), _("Debit"), _("Credit"), ' ', _("Memo"));
140         }       
141         else
142         {
143                 $cols2 = null;
144                 $headers2 = null;
145         }       
146
147         $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'left', 'left', 'left', 'left');
148
149     $params =   array(  0 => $comments,
150                                     1 => array('text' => _('Items'), 'from' => $items, 'to' => ''),
151                                     2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''),
152                                     3 => array('text' => _('Open Only'), 'from' => $open, 'to' => ''),
153                                     4 => array('text' => _('Show GL Rows'), 'from' => $show, 'to' => ''),
154                                     );
155
156     $rep = new FrontReport(_('Work Order Listing'), "WorkOrderListing", user_pagesize(), 9, $orientation);
157         if ($orientation == 'L')
158         recalculate_cols($cols);
159
160     $rep->Font();
161     if ($show_gl)
162         $rep->Info($params, $cols2, $headers2, $aligns, $cols, $headers);
163     else        
164         $rep->Info($params, $cols, $headers, $aligns);
165     $rep->NewPage();
166
167         $res = getTransactions($item, $open_only, $location);
168         while ($trans=db_fetch($res))
169         {
170                 $rep->TextCol(0, 1, $wo_types_array[$trans['type']]);
171                 $rep->TextCol(1, 2, $trans['id'], -1);
172                 $rep->TextCol(2, 3, $trans['wo_ref'], -1);
173                 $rep->TextCol(3, 4, $trans['location_name'], -1);
174                 $rep->TextCol(4, 5, $trans['description'], -1);
175                 $dec = get_qty_dec($trans['stock_id']);
176                 $rep->AmountCol(5, 6, $trans['units_reqd'], $dec);
177                 $rep->AmountCol(6, 7, $trans['units_issued'], $dec);
178                 $rep->TextCol(7, 8, '', -1);
179                 $rep->TextCol(8, 9, sql2date($trans['date_']), -1);
180                 $rep->TextCol(9, 10, sql2date($trans['required_by']), -1);
181                 $rep->TextCol(10, 11, $trans['closed'] ? ' ' : _('No'), -1);
182                 if ($show_gl)
183                 {
184                         $rep->NewLine();
185                         $productions = get_gl_wo_productions($trans['id'], true);
186                         print_gl_rows($rep, $productions, _("Finished Product Requirements"));
187
188                         $issues = get_gl_wo_issue_trans($trans['id'], -1, true);
189                         print_gl_rows($rep, $issues, _("Additional Material Issues"));
190
191                     $costs = get_gl_wo_cost_trans($trans['id'], -1, true);
192                         print_gl_rows($rep, $costs, _("Additional Costs"));
193
194                         $wo = get_gl_trans(ST_WORKORDER, $trans['id']);
195                         print_gl_rows($rep, $wo, _("Finished Product Receival"));
196                         $rep->Line($rep->row - 2);
197                         $rep->NewLine();
198                 }
199                 $rep->NewLine();
200         }
201         $rep->Line($rep->row);
202     $rep->End();
203 }
204