Redundant check for negative stock removed.
[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         $orientation = $_POST['PARAM_4'];
40
41
42         if (!$from || !$to) return;
43
44         $orientation = ($orientation ? 'L' : 'P');
45         $fno = explode("-", $from);
46         $tno = explode("-", $to);
47         $from = min($fno[0], $tno[0]);
48         $to = max($fno[0], $tno[0]);
49
50         $cols = array(4, 60, 190, 255, 320, 385, 450, 515);
51
52         // $headers in doctext.inc
53         $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
54
55         $params = array('comments' => $comments);
56
57         $cur = get_company_Pref('curr_default');
58
59         if ($email == 0)
60                 $rep = new FrontReport(_('WORK ORDER'), "WorkOrderBulk", user_pagesize(), 9, $orientation);
61         if ($orientation == 'L')
62         recalculate_cols($cols);
63
64         for ($i = $from; $i <= $to; $i++)
65         {
66                 $myrow = get_work_order($i);
67                 if ($myrow === false)
68                         continue;
69                 $date_ = sql2date($myrow["date_"]);
70                 if ($email == 1)
71                 {
72                         $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
73                         $rep->title = _('WORK ORDER');
74                         $rep->filename = "WorkOrder" . $myrow['wo_ref'] . ".pdf";
75                 }
76                 $rep->SetHeaderType('Header2');
77                 $rep->currency = $cur;
78                 $rep->Font();
79                 $rep->Info($params, $cols, null, $aligns);
80
81                 $contact = array('email' =>$myrow['email'],'lang' => $dflt_lang, // ???
82                         'name' => $myrow['contact'], 'name2' => '', 'contact');
83
84                 $rep->SetCommonData($myrow, null, null, '', 26, $contact);
85                 $rep->NewPage();
86
87                 $result = get_wo_requirements($i);
88                 $rep->TextCol(0, 5,_("Work Order Requirements"), -2);
89                 $rep->NewLine(2);
90                 $has_marked = false;
91                 while ($myrow2=db_fetch($result))
92                 {
93                         $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
94                         $rep->TextCol(1, 2, $myrow2['description'], -2);
95
96                         $rep->TextCol(2, 3,     $myrow2['location_name'], -2);
97                         $rep->TextCol(3, 4,     $myrow2['WorkCentreDescription'], -2);
98                         $dec = get_qty_dec($myrow2["stock_id"]);
99
100                         $rep->AmountCol(4, 5,   $myrow2['units_req'], $dec, -2);
101                         $rep->AmountCol(5, 6,   $myrow2['units_req'] * $myrow['units_issued'], $dec, -2);
102                         $rep->AmountCol(6, 7,   $myrow2['units_issued'], $dec, -2);
103                         $rep->NewLine(1);
104                         if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
105                                 $rep->NewPage();
106                 }
107                 $memo = get_comments_string(ST_WORKORDER, $i);
108                 if ($memo != "")
109                 {
110                         $rep->NewLine();
111                         $rep->TextColLines(1, 5, $memo, -2);
112                 }
113
114                 if ($email == 1)
115                 {
116                         $myrow['DebtorName'] = $myrow['contact'];
117                         $myrow['reference'] = $myrow['wo_ref'];
118                         $rep->End($email);
119                 }
120         }
121         if ($email == 0)
122                 $rep->End();
123 }
124
125 ?>