1<?php
2include ('includes/session.php');
3
4if (isset($_GET['WO'])) {
5	$WO = filter_number_format($_GET['WO']);
6} elseif (isset($_POST['WO'])) {
7	$WO = filter_number_format($_POST['WO']);
8} else {
9	$WO = '';
10}
11
12if (isset($_GET['StockId'])) {
13	$StockId = $_GET['StockId'];
14} elseif (isset($_POST['StockId'])) {
15	$StockId = $_POST['StockId'];
16}
17
18if (isset($_GET['Location'])) {
19	$Location = $_GET['Location'];
20} elseif (isset($_POST['Location'])) {
21	$Location = $_POST['Location'];
22}
23
24if (isset($WO) and isset($StockId) and $WO != '') {
25
26	$SQL = "SELECT woitems.qtyreqd,
27					woitems.qtyrecd,
28					stockmaster.description,
29					stockmaster.decimalplaces,
30					stockmaster.units
31			FROM woitems, stockmaster
32			WHERE stockmaster.stockid = woitems.stockid
33				AND woitems.wo = '" . $WO . "'
34				AND woitems.stockid = '" . $StockId . "' ";
35
36	$ErrMsg = _('The SQL to find the details of the item to produce failed');
37	$ResultItems = DB_query($SQL, $ErrMsg);
38
39	if (DB_num_rows($ResultItems) != 0) {
40		include ('includes/PDFStarter.php');
41
42		$pdf->addInfo('Title', _('WO Production Slip'));
43		$pdf->addInfo('Subject', _('WO Production Slip'));
44
45		while ($myItem = DB_fetch_array($ResultItems)) {
46			// print the info of the parent product
47			$FontSize = 10;
48			$PageNumber = 1;
49			$line_height = 12;
50			$Xpos = $Left_Margin + 1;
51			$fill = false;
52
53			$QtyPending = $myItem['qtyreqd'] - $myItem['qtyrecd'];
54
55			PrintHeader($pdf, $YPos, $PageNumber, $Page_Height, $Top_Margin, $Left_Margin, $Page_Width, $Right_Margin, $WO, $StockId, $myItem['description'], $QtyPending, $myItem['units'], $myItem['decimalplaces'], $ReportDate);
56
57			$PartCounter = 0;
58
59			$SQLBOM = "SELECT bom.parent,
60						bom.component,
61						bom.quantity AS bomqty,
62						stockmaster.decimalplaces,
63						stockmaster.units,
64						stockmaster.description,
65						stockmaster.shrinkfactor,
66						locstock.quantity AS qoh
67					FROM bom, stockmaster, locstock
68					WHERE bom.component = stockmaster.stockid
69						AND bom.component = locstock.stockid
70						AND locstock.loccode = '" . $Location . "'
71						AND bom.parent = '" . $StockId . "'
72                        AND bom.effectiveafter <= '" . date('Y-m-d') . "'
73                        AND bom.effectiveto > '" . date('Y-m-d') . "'";
74
75			$ErrMsg = _('The bill of material could not be retrieved because');
76			$BOMResult = DB_query($SQLBOM, $ErrMsg);
77			while ($myComponent = DB_fetch_array($BOMResult)) {
78
79				$ComponentNeeded = $myComponent['bomqty'] * $QtyPending;
80				$PrevisionShrinkage = $ComponentNeeded * ($myComponent['shrinkfactor'] / 100);
81
82				$Xpos = $Left_Margin + 1;
83
84				$pdf->addTextWrap($Xpos, $YPos, 150, $FontSize, $myComponent['component'], 'left');
85				$pdf->addTextWrap(150, $YPos, 50, $FontSize, locale_number_format($myComponent['bomqty'], 'Variable'), 'right');
86				$pdf->addTextWrap(200, $YPos, 30, $FontSize, $myComponent['units'], 'left');
87				$pdf->addTextWrap(230, $YPos, 50, $FontSize, locale_number_format($ComponentNeeded, $myComponent['decimalplaces']), 'right');
88				$pdf->addTextWrap(280, $YPos, 30, $FontSize, $myComponent['units'], 'left');
89				$pdf->addTextWrap(310, $YPos, 50, $FontSize, locale_number_format($PrevisionShrinkage, $myComponent['decimalplaces']), 'right');
90				$pdf->addTextWrap(360, $YPos, 30, $FontSize, $myComponent['units'], 'left');
91
92				$YPos-= $line_height;
93
94				if ($YPos < $Bottom_Margin + $line_height) {
95					PrintHeader($pdf, $YPos, $PageNumber, $Page_Height, $Top_Margin, $Left_Margin, $Page_Width, $Right_Margin, $WO, $Stockid, $myItem['description'], $QtyPending, $myItem['units'], $myItem['decimalplaces'], $ReportDate);
96				}
97			}
98		}
99
100		// Production Notes
101		$pdf->addTextWrap($Xpos, $YPos - 50, 200, $FontSize, _('Incidences / Production Notes') . ':', 'left');
102		$YPos-= (8 * $line_height);
103
104		PrintFooterSlip($pdf, _('Components Ready By'), _('Item Produced By'), _('Quality Control By'), $YPos, $FontSize, false);
105
106		if ($YPos < $Bottom_Margin + $line_height) {
107			PrintHeader($pdf, $YPos, $PageNumber, $Page_Height, $Top_Margin, $Left_Margin, $Page_Width, $Right_Margin, $WO, $Stockid, $myItem['description'], $QtyPending, $myItem['units'], $myItem['decimalplaces'], $ReportDate);
108		}
109
110		$pdf->OutputD('WO-' . $WO . '-' . $StockId . '-' . Date('Y-m-d') . '.pdf');
111		$pdf->__destruct();
112	} else {
113		$Title = _('WO Item production Slip');
114		include ('includes/header.php');
115		prnMsg(_('There were no items with ready to produce'), 'info');
116		prnMsg($SQL);
117		echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>';
118		include ('includes/footer.php');
119		exit;
120
121	}
122}
123
124function PrintHeader(&$pdf, &$YPos, &$PageNumber, $Page_Height, $Top_Margin, $Left_Margin, $Page_Width, $Right_Margin, $WO, $StockId, $Description, $Qty, $UOM, $DecimalPlaces, $ReportDate) {
125
126	if ($PageNumber > 1) {
127		$pdf->newPage();
128	}
129	$line_height = 12;
130	$FontSize = 10;
131	$YPos = $Page_Height - $Top_Margin;
132
133	$pdf->addTextWrap($Left_Margin, $YPos, 300, $FontSize, $_SESSION['CompanyRecord']['coyname']);
134	$pdf->addTextWrap(190, $YPos, 100, $FontSize, $ReportDate);
135	$pdf->addTextWrap($Page_Width - $Right_Margin - 150, $YPos, 160, $FontSize, _('Printed') . ': ' . Date($_SESSION['DefaultDateFormat']) . '   ' . _('Page') . ' ' . $PageNumber, 'left');
136	$YPos-= $line_height;
137
138	$pdf->addTextWrap($Left_Margin, $YPos, 150, $FontSize, _('Work Order Item Production Slip'));
139	$YPos-= (2 * $line_height);
140
141	$pdf->addTextWrap($Left_Margin, $YPos, 150, $FontSize, _('WO') . ': ' . $WO);
142	$YPos-= $line_height;
143
144	$pdf->addTextWrap($Left_Margin, $YPos, 500, $FontSize, _('Item Code') . ': ' . $StockId . ' --> ' . $Description);
145	$YPos-= $line_height;
146
147	$pdf->addTextWrap($Left_Margin, $YPos, 150, $FontSize, _('Quantity') . ': ' . locale_number_format($Qty, $DecimalPlaces) . ' ' . $UOM);
148	$YPos-= (2 * $line_height);
149
150	if (file_exists($_SESSION['part_pics_dir'] . '/' . $StockId . '.jpg')) {
151		$pdf->Image($_SESSION['part_pics_dir'] . '/' . $StockId . '.jpg', 135, $Page_Height - $Top_Margin - $YPos + 10, 200, 200);
152		$YPos-= (16 * $line_height);
153	} /*end checked file exist*/
154
155	/*set up the headings */
156	$Xpos = $Left_Margin + 1;
157
158	$pdf->addTextWrap($Xpos, $YPos, 150, $FontSize, _('Component Code'), 'left');
159	$pdf->addTextWrap(150, $YPos, 50, $FontSize, _('Qty BOM'), 'right');
160	$pdf->addTextWrap(200, $YPos, 30, $FontSize, '', 'left');
161	$pdf->addTextWrap(230, $YPos, 50, $FontSize, _('Qty Needed'), 'right');
162	$pdf->addTextWrap(280, $YPos, 30, $FontSize, '', 'left');
163	$pdf->addTextWrap(310, $YPos, 50, $FontSize, _('Shrinkage'), 'right');
164	$pdf->addTextWrap(360, $YPos, 30, $FontSize, '', 'left');
165
166	$FontSize = 10;
167	$YPos-= $line_height;
168
169	$PageNumber++;
170}
171
172function PrintFooterSlip($pdf, $Column1, $Column2, $Column3, $YPos, $FontSize, $fill) {
173	//add column 1
174	$pdf->addTextWrap(40, $YPos - 50, 100, $FontSize, $Column1 . ':', 'left');
175	$pdf->addTextWrap(40, $YPos - 70, 100, $FontSize, _('Name'), 'left');
176	$pdf->addTextWrap(80, $YPos - 70, 200, $FontSize, ':__________________', 'left', 0, $fill);
177	$pdf->addTextWrap(40, $YPos - 90, 100, $FontSize, _('Date'), 'left');
178	$pdf->addTextWrap(80, $YPos - 90, 200, $FontSize, ':__________________', 'left', 0, $fill);
179	$pdf->addTextWrap(40, $YPos - 110, 100, $FontSize, _('Hour'), 'left');
180	$pdf->addTextWrap(80, $YPos - 110, 200, $FontSize, ':__________________', 'left', 0, $fill);
181	$pdf->addTextWrap(40, $YPos - 150, 100, $FontSize, _('Signature'), 'left');
182	$pdf->addTextWrap(80, $YPos - 150, 200, $FontSize, ':__________________', 'left', 0, $fill);
183
184	//add column 2
185	$pdf->addTextWrap(220, $YPos - 50, 100, $FontSize, $Column2 . ':', 'left');
186	$pdf->addTextWrap(220, $YPos - 70, 100, $FontSize, _('Name'), 'left');
187	$pdf->addTextWrap(260, $YPos - 70, 200, $FontSize, ':__________________', 'left', 0, $fill);
188	$pdf->addTextWrap(220, $YPos - 90, 100, $FontSize, _('Date'), 'left');
189	$pdf->addTextWrap(260, $YPos - 90, 200, $FontSize, ':__________________', 'left', 0, $fill);
190	$pdf->addTextWrap(220, $YPos - 110, 100, $FontSize, _('Hour'), 'left');
191	$pdf->addTextWrap(260, $YPos - 110, 200, $FontSize, ':__________________', 'left', 0, $fill);
192	$pdf->addTextWrap(220, $YPos - 150, 100, $FontSize, _('Signature'), 'left');
193	$pdf->addTextWrap(260, $YPos - 150, 200, $FontSize, ':__________________', 'left', 0, $fill);
194
195	//add column 3
196	$pdf->addTextWrap(400, $YPos - 50, 100, $FontSize, $Column3 . ':', 'left');
197	$pdf->addTextWrap(400, $YPos - 70, 100, $FontSize, _('Name'), 'left');
198	$pdf->addTextWrap(440, $YPos - 70, 200, $FontSize, ':__________________', 'left', 0, $fill);
199	$pdf->addTextWrap(400, $YPos - 90, 100, $FontSize, _('Date'), 'left');
200	$pdf->addTextWrap(440, $YPos - 90, 200, $FontSize, ':__________________', 'left', 0, $fill);
201	$pdf->addTextWrap(400, $YPos - 110, 100, $FontSize, _('Hour'), 'left');
202	$pdf->addTextWrap(440, $YPos - 110, 200, $FontSize, ':__________________', 'left', 0, $fill);
203	$pdf->addTextWrap(400, $YPos - 150, 100, $FontSize, _('Signature'), 'left');
204	$pdf->addTextWrap(440, $YPos - 150, 200, $FontSize, ':__________________', 'left', 0, $fill);
205}
206
207?>
208