a18089e6bfda88c2528a54bedb98ab89673baa5c
[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 //----------------------------------------------------------------------------------------------------
68
69 function print_work_order_listing()
70 {
71     global $path_to_root, $wo_types_array;
72
73     $item = $_POST['PARAM_0'];
74     $location = $_POST['PARAM_1'];
75     $open_only = $_POST['PARAM_2'];
76         $comments = $_POST['PARAM_3'];
77         $orientation = $_POST['PARAM_4'];
78         $destination = $_POST['PARAM_5'];
79         if ($destination)
80                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
81         else
82                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
83
84         $orientation = ($orientation ? 'L' : 'P');
85
86         if ($item == '')
87                 $items = _('All');
88         else
89         {
90                 $row = get_item($item);
91                 $items = $row['description']; 
92         }
93
94         if ($location == '')
95                 $loc = _('All');
96         else
97                 $loc = get_location_name($location);
98
99         $open = $open_only == 1 ? _('Yes') : _('No');
100         
101         $cols = array(0, 100, 120, 165, 210, 275, 315, 375, 385, 440, 495, 555);
102
103         $headers = array(_('Type'), '#', ('Reference'), _('Location'), _('Item'), _('Required'), _('Manufactured'), ' ', _('Date'), _('Required By'), _('Closed'));
104
105         $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'left', 'left', 'left', 'left');
106
107     $params =   array(  0 => $comments,
108                                     1 => array('text' => _('Items'), 'from' => $items, 'to' => ''),
109                                     2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''),
110                                     3 => array('text' => _('Open Only'), 'from' => $open, 'to' => ''));
111
112     $rep = new FrontReport(_('Work Order Listing'), "WorkOrderListing", user_pagesize(), 9, $orientation);
113         if ($orientation == 'L')
114         recalculate_cols($cols);
115
116     $rep->Font();
117     $rep->Info($params, $cols, $headers, $aligns);
118     $rep->NewPage();
119
120         $res = getTransactions($item, $open_only, $location);
121         while ($trans=db_fetch($res))
122         {
123                 $rep->TextCol(0, 1, $wo_types_array[$trans['type']]);
124                 $rep->TextCol(1, 2, $trans['id'], -1);
125                 $rep->TextCol(2, 3, $trans['wo_ref'], -1);
126                 $rep->TextCol(3, 4, $trans['location_name'], -1);
127                 $rep->TextCol(4, 5, $trans['description'], -1);
128                 $dec = get_qty_dec($trans['stock_id']);
129                 $rep->AmountCol(5, 6, $trans['units_reqd'], $dec);
130                 $rep->AmountCol(6, 7, $trans['units_issued'], $dec);
131                 $rep->TextCol(7, 8, '', -1);
132                 $rep->TextCol(8, 9, sql2date($trans['date_']), -1);
133                 $rep->TextCol(9, 10, sql2date($trans['required_by']), -1);
134                 $rep->TextCol(10, 11, $trans['closed'] ? ' ' : _('No'), -1);
135                 $rep->NewLine();
136         }
137         $rep->Line($rep->row);
138     $rep->End();
139 }
140