Added memo/comments print in remittance and receipt. Optimized memo/prints in other...
[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 || !$to) return;
41
42         $fno = explode("-", $from);
43         $tno = explode("-", $to);
44         $from = min($fno[0], $tno[0]);
45         $to = max($fno[0], $tno[0]);
46
47         $cols = array(4, 60, 190, 255, 320, 385, 450, 515);
48
49         // $headers in doctext.inc
50         $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
51
52         $params = array('comments' => $comments);
53
54         $cur = get_company_Pref('curr_default');
55
56         if ($email == 0)
57         {
58                 $rep = new FrontReport(_('WORK ORDER'), "WorkOrderBulk", user_pagesize());
59                 $rep->SetHeaderType('Header2');
60                 $rep->currency = $cur;
61                 $rep->Font();
62                 $rep->Info($params, $cols, null, $aligns);
63         }
64
65         for ($i = $from; $i <= $to; $i++)
66         {
67                 $myrow = get_work_order($i);
68                 if ($myrow === false)
69                         continue;
70                 $date_ = sql2date($myrow["date_"]);
71                 if ($email == 1)
72                 {
73                         $rep = new FrontReport("", "", user_pagesize());
74                         $rep->SetHeaderType('Header2');
75                         $rep->currency = $cur;
76                         $rep->Font();
77                                 $rep->title = _('WORK ORDER');
78                                 $rep->filename = "WorkOrder" . $myrow['wo_ref'] . ".pdf";
79                         $rep->Info($params, $cols, null, $aligns);
80                 }
81                 else
82                         $rep->title = _('WORK ORDER');
83
84                 $contact[] = array('email' =>$myrow['email'],'lang' => $dflt_lang,
85                         'name' => $myrow['contact'], 'name2' => '', 'contact');
86
87                 $rep->SetCommonData($myrow, null, null, '', 26, $contact);
88                 $rep->NewPage();
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                                 !$SysPrefs->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->NewPage();
130                 }
131                 $rep->NewLine(1);
132                 $rep->TextCol(0, 5," *** = "._("Insufficient stock"), -2);
133
134                 $memo = get_comments_string(ST_WORKORDER, $i);
135                 if ($memo != "")
136                 {
137                         $rep->NewLine();
138                         $rep->TextColLines(1, 5, $memo, -2);
139                 }
140
141                 if ($email == 1)
142                 {
143                         $myrow['DebtorName'] = $myrow['contact'];
144                         $myrow['reference'] = $myrow['wo_ref'];
145                         $rep->End($email);
146                 }
147         }
148         if ($email == 0)
149                 $rep->End();
150 }
151
152 ?>