Switch to new access levels system
[fa-stable.git] / reporting / rep409.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 = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
13         'SA_MANUFTRANSVIEW' : 'SA_MANUFBULKREP';
14 // ----------------------------------------------------------------
15 // $ Revision:  2.0 $
16 // Creator:     Janusz Dobrowolski
17 // date_:       2008-01-14
18 // Title:       Print Workorders
19 // draft version!
20 // ----------------------------------------------------------------
21 $path_to_root="..";
22
23 include_once($path_to_root . "/includes/session.inc");
24 include_once($path_to_root . "/includes/date_functions.inc");
25 include_once($path_to_root . "/includes/data_checks.inc");
26 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
27
28 //----------------------------------------------------------------------------------------------------
29
30 print_workorders();
31
32 //----------------------------------------------------------------------------------------------------
33
34 function print_workorders()
35 {
36         global $path_to_root;
37
38         include_once($path_to_root . "/reporting/includes/pdf_report.inc");
39
40         $from = $_POST['PARAM_0'];
41         $to = $_POST['PARAM_1'];
42         $email = $_POST['PARAM_2'];
43         $comments = $_POST['PARAM_3'];
44
45         if ($from == null)
46                 $from = 0;
47         if ($to == null)
48                 $to = 0;
49         $dec = user_price_dec();
50
51         $fno = explode("-", $from);
52         $tno = explode("-", $to);
53
54         $cols = array(4, 60, 190, 255, 320, 385, 450, 515);
55
56         // $headers in doctext.inc
57         $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
58
59         $params = array('comments' => $comments);
60
61         $cur = get_company_Pref('curr_default');
62
63         if ($email == 0)
64         {
65                 $rep = new FrontReport(_('WORK ORDER'), "WorkOrderBulk", user_pagesize());
66                 $rep->currency = $cur;
67                 $rep->Font();
68                 $rep->Info($params, $cols, null, $aligns);
69         }
70
71         for ($i = $fno[0]; $i <= $tno[0]; $i++)
72         {
73                 $myrow = get_work_order($i);
74                 if ($myrow === false)
75                         continue;
76                 $date_ = sql2date($myrow["date_"]);                     
77                 if ($email == 1)
78                 {
79                         $rep = new FrontReport("", "", user_pagesize());
80                         $rep->currency = $cur;
81                         $rep->Font();
82                                 $rep->title = _('WORK ORDER');
83                                 $rep->filename = "WorkOrder" . $myrow['reference'] . ".pdf";
84                         $rep->Info($params, $cols, null, $aligns);
85                 }
86                 else
87                         $rep->title = _('WORK ORDER');
88                 $rep->Header2($myrow, null, null, '', 26);
89
90                 $result = get_wo_requirements($i);
91                 $rep->TextCol(0, 5,_("Work Order Requirements"), -2);
92                 $rep->NewLine(2);
93                 $has_marked = false;
94                 while ($myrow2=db_fetch($result))
95                 {
96                         $qoh = 0;
97                         $show_qoh = true;
98                         // if it's a non-stock item (eg. service) don't show qoh
99                         if (!has_stock_holding($myrow2["mb_flag"]))
100                                 $show_qoh = false;
101
102                         if ($show_qoh)
103                                 $qoh = get_qoh_on_date($myrow2["stock_id"], $myrow2["loc_code"], $date_);
104
105                         if ($show_qoh && ($myrow2["units_req"] * $myrow["units_issued"] > $qoh) &&
106                                 !sys_prefs::allow_negative_stock())
107                         {
108                                 // oops, we don't have enough of one of the component items
109                                 $has_marked = true;
110                         }
111                         else
112                                 $has_marked = false;
113                         if ($has_marked)
114                                 $str = $myrow2['stock_id']." ***";
115                         else
116                                 $str = $myrow2['stock_id'];
117                         $rep->TextCol(0, 1,     $str, -2);
118                         $rep->TextCol(1, 2, $myrow2['description'], -2);
119
120                         $rep->TextCol(2, 3,     $myrow2['location_name'], -2);
121                         $rep->TextCol(3, 4,     $myrow2['WorkCentreDescription'], -2);
122                         $dec = get_qty_dec($myrow2["stock_id"]);
123
124                         $rep->AmountCol(4, 5,   $myrow2['units_req'], $dec, -2);
125                         $rep->AmountCol(5, 6,   $myrow2['units_req'] * $myrow['units_issued'], $dec, -2);
126                         $rep->AmountCol(6, 7,   $myrow2['units_issued'], $dec, -2);
127                         $rep->NewLine(1);
128                         if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
129                                 $rep->Header2($myrow, null, null,'',26);
130                 }
131                 $rep->NewLine(1);
132                 $rep->TextCol(0, 5," *** = "._("Insufficient stock"), -2);
133
134                 $comments = get_comments(26, $i);
135                 if ($comments && db_num_rows($comments))
136                 {
137                         $rep->NewLine();
138                         while ($comment=db_fetch($comments))
139                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
140                 }
141         }
142         if ($email == 0)
143                 $rep->End();
144 }
145
146 ?>