Report fixed according to changed headers API in FrontReport class.
[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, $SysPrefs;
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->SetHeaderType('Header2');
67                 $rep->currency = $cur;
68                 $rep->Font();
69                 $rep->Info($params, $cols, null, $aligns);
70         }
71
72         for ($i = $fno[0]; $i <= $tno[0]; $i++)
73         {
74                 $myrow = get_work_order($i);
75                 if ($myrow === false)
76                         continue;
77                 $date_ = sql2date($myrow["date_"]);                     
78                 if ($email == 1)
79                 {
80                         $rep = new FrontReport("", "", user_pagesize());
81                         $rep->SetHeaderType('Header2');
82                         $rep->currency = $cur;
83                         $rep->Font();
84                                 $rep->title = _('WORK ORDER');
85                                 $rep->filename = "WorkOrder" . $myrow['reference'] . ".pdf";
86                         $rep->Info($params, $cols, null, $aligns);
87                 }
88                 else
89                         $rep->title = _('WORK ORDER');
90                 $rep->SetCommonData($myrow, null, null, '', 26);
91                 $rep->NewPage();
92
93                 $result = get_wo_requirements($i);
94                 $rep->TextCol(0, 5,_("Work Order Requirements"), -2);
95                 $rep->NewLine(2);
96                 $has_marked = false;
97                 while ($myrow2=db_fetch($result))
98                 {
99                         $qoh = 0;
100                         $show_qoh = true;
101                         // if it's a non-stock item (eg. service) don't show qoh
102                         if (!has_stock_holding($myrow2["mb_flag"]))
103                                 $show_qoh = false;
104
105                         if ($show_qoh)
106                                 $qoh = get_qoh_on_date($myrow2["stock_id"], $myrow2["loc_code"], $date_);
107
108                         if ($show_qoh && ($myrow2["units_req"] * $myrow["units_issued"] > $qoh) &&
109                                 !$SysPrefs->allow_negative_stock())
110                         {
111                                 // oops, we don't have enough of one of the component items
112                                 $has_marked = true;
113                         }
114                         else
115                                 $has_marked = false;
116                         if ($has_marked)
117                                 $str = $myrow2['stock_id']." ***";
118                         else
119                                 $str = $myrow2['stock_id'];
120                         $rep->TextCol(0, 1,     $str, -2);
121                         $rep->TextCol(1, 2, $myrow2['description'], -2);
122
123                         $rep->TextCol(2, 3,     $myrow2['location_name'], -2);
124                         $rep->TextCol(3, 4,     $myrow2['WorkCentreDescription'], -2);
125                         $dec = get_qty_dec($myrow2["stock_id"]);
126
127                         $rep->AmountCol(4, 5,   $myrow2['units_req'], $dec, -2);
128                         $rep->AmountCol(5, 6,   $myrow2['units_req'] * $myrow['units_issued'], $dec, -2);
129                         $rep->AmountCol(6, 7,   $myrow2['units_issued'], $dec, -2);
130                         $rep->NewLine(1);
131                         if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
132                                 $rep->NewPage();
133                 }
134                 $rep->NewLine(1);
135                 $rep->TextCol(0, 5," *** = "._("Insufficient stock"), -2);
136
137                 $comments = get_comments(ST_WORKORDER, $i);
138                 if ($comments && db_num_rows($comments))
139                 {
140                         $rep->NewLine();
141                         while ($comment=db_fetch($comments))
142                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
143                 }
144         }
145         if ($email == 0)
146                 $rep->End();
147 }
148
149 ?>