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