From: <te...@us...> - 2014-09-07 15:55:55
|
Revision: 6866 http://sourceforge.net/p/web-erp/reponame/6866 Author: tehonu Date: 2014-09-07 15:55:49 +0000 (Sun, 07 Sep 2014) Log Message: ----------- new script listing all items in running WO that can be produced with available stock in location. Prints also single item production slip with basic BOM, components and image information. Modified Paths: -------------- trunk/includes/MainMenuLinksArray.php trunk/sql/mysql/upgrade4.11-4.12.sql Added Paths: ----------- trunk/PrintWOItemSlip.php trunk/WOCanBeProducedNow.php Added: trunk/PrintWOItemSlip.php =================================================================== --- trunk/PrintWOItemSlip.php (rev 0) +++ trunk/PrintWOItemSlip.php 2014-09-07 15:55:49 UTC (rev 6866) @@ -0,0 +1,214 @@ +<?php + +include('includes/session.inc'); + +if (isset($_GET['WO'])) { + $WO = filter_number_format($_GET['WO']); +} elseif (isset($_POST['WO'])){ + $WO = filter_number_format($_POST['WO']); +} else { + $WO = ''; +} + +if (isset($_GET['StockId'])) { + $StockId = $_GET['StockId']; +} elseif (isset($_POST['StockId'])) { + $StockId = $_POST['StockId']; +} + +if (isset($_GET['Location'])) { + $Location = $_GET['Location']; +} elseif (isset($_POST['Location'])) { + $Location = $_POST['Location']; +} + + +if (isset($WO) AND isset($StockId) AND $WO!=''){ + + $sql = "SELECT woitems.qtyreqd, + woitems.qtyrecd, + stockmaster.description, + stockmaster.decimalplaces, + stockmaster.units + FROM woitems, stockmaster + WHERE stockmaster.stockid = woitems.stockid + AND woitems.wo = '" . $WO . "' + AND woitems.stockid = '" . $StockId . "' "; + + $ErrMsg = _('The SQL to find the details of the item to produce failed'); + $resultItems = DB_query($sql,$db,$ErrMsg); + + if (DB_num_rows($resultItems) != 0){ + include('includes/PDFStarter.php'); + + $pdf->addInfo('Title',_('WO Production Slip')); + $pdf->addInfo('Subject',_('WO Production Slip')); + + while ($myItem = DB_fetch_array($resultItems)) { + // print the info of the parent product + $FontSize=10; + $PageNumber=1; + $line_height=12; + $Xpos = $Left_Margin+1; + $fill = FALSE; + + $QtyPending = $myItem['qtyreqd'] - $myItem['qtyrecd']; + + PrintHeader($pdf,$YPos,$PageNumber,$Page_Height,$Top_Margin,$Left_Margin, + $Page_Width,$Right_Margin,$WO,$StockId,$myItem['description'],$QtyPending,$myItem['units'],$myItem['decimalplaces'],$ReportDate); + + $PartCounter = 0; + + $sqlBOM = "SELECT bom.parent, + bom.component, + bom.quantity AS bomqty, + stockmaster.decimalplaces, + stockmaster.units, + stockmaster.description, + stockmaster.shrinkfactor, + locstock.quantity AS qoh + FROM bom, stockmaster, locstock + WHERE bom.component = stockmaster.stockid + AND bom.component = locstock.stockid + AND locstock.loccode = '". $Location ."' + AND bom.parent = '" . $StockId . "' + AND bom.effectiveafter < '" . Date('Y-m-d') . "' + AND (bom.effectiveto > '" . Date('Y-m-d') . "' + OR bom.effectiveto='0000-00-00')"; + + $ErrMsg = _('The bill of material could not be retrieved because'); + $BOMResult = DB_query ($sqlBOM,$db,$ErrMsg); + while ($myComponent = DB_fetch_array($BOMResult)) { + + $ComponentNeeded = $myComponent['bomqty'] * $QtyPending; + $PrevisionShrinkage = $ComponentNeeded * ($myComponent['shrinkfactor'] / 100); + + $Xpos = $Left_Margin+1; + + $pdf->addTextWrap($Xpos,$YPos,150,$FontSize, $myComponent['component'], 'left'); + $pdf->addTextWrap(150,$YPos,50,$FontSize,locale_number_format($myComponent['bomqty'],$myComponent['decimalplaces']), 'right'); + $pdf->addTextWrap(200,$YPos,30,$FontSize,$myComponent['units'], 'left'); + $pdf->addTextWrap(230,$YPos,50,$FontSize,locale_number_format($ComponentNeeded,$myComponent['decimalplaces']), 'right'); + $pdf->addTextWrap(280,$YPos,30,$FontSize,$myComponent['units'], 'left'); + $pdf->addTextWrap(310,$YPos,50,$FontSize,locale_number_format($PrevisionShrinkage,$myComponent['decimalplaces']), 'right'); + $pdf->addTextWrap(360,$YPos,30,$FontSize,$myComponent['units'], 'left'); + + $YPos -= $line_height; + + if ($YPos < $Bottom_Margin + $line_height){ + PrintHeader($pdf,$YPos,$PageNumber,$Page_Height,$Top_Margin,$Left_Margin,$Page_Width, + $Right_Margin,$WO,$Stockid,$myItem['description'],$QtyPending,$myItem['units'],$myItem['decimalplaces'],$ReportDate); + } + } + } + + // Production Notes + $pdf->addTextWrap($Xpos,$YPos-50,100,$FontSize,_('Incidences / Production Notes :'), 'left'); + $YPos -=(8*$line_height); + + //add components prepared by + $pdf->addTextWrap(40,$YPos-50,100,$FontSize,_('Components Prepared By :'), 'left'); + $pdf->addTextWrap(40,$YPos-70,100,$FontSize,_('Name'), 'left'); + $pdf->addTextWrap(80,$YPos-70,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(40,$YPos-90,100,$FontSize,_('Date'), 'left'); + $pdf->addTextWrap(80,$YPos-90,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(40,$YPos-110,100,$FontSize,_('Hour'), 'left'); + $pdf->addTextWrap(80,$YPos-110,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(40,$YPos-150,100,$FontSize,_('Signature'), 'left'); + $pdf->addTextWrap(80,$YPos-150,200,$FontSize,':__________________','left',0,$fill); + + //add Produced by + $pdf->addTextWrap(200,$YPos-50,100,$FontSize,_('Item Produced By :'), 'left'); + $pdf->addTextWrap(200,$YPos-70,100,$FontSize,_('Name'), 'left'); + $pdf->addTextWrap(240,$YPos-70,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(200,$YPos-90,100,$FontSize,_('Date'), 'left'); + $pdf->addTextWrap(240,$YPos-90,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(200,$YPos-110,100,$FontSize,_('Hour'), 'left'); + $pdf->addTextWrap(240,$YPos-110,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(200,$YPos-150,100,$FontSize,_('Signature'), 'left'); + $pdf->addTextWrap(240,$YPos-150,200,$FontSize,':__________________','left',0,$fill); + + //add Quality Control by + $pdf->addTextWrap(400,$YPos-50,100,$FontSize,_('Quality Control By :'), 'left'); + $pdf->addTextWrap(400,$YPos-70,100,$FontSize,_('Name'), 'left'); + $pdf->addTextWrap(440,$YPos-70,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(400,$YPos-90,100,$FontSize,_('Date'), 'left'); + $pdf->addTextWrap(440,$YPos-90,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(400,$YPos-110,100,$FontSize,_('Hour'), 'left'); + $pdf->addTextWrap(440,$YPos-110,200,$FontSize,':__________________','left',0,$fill); + $pdf->addTextWrap(400,$YPos-150,100,$FontSize,_('Signature'), 'left'); + $pdf->addTextWrap(440,$YPos-150,200,$FontSize,':__________________','left',0,$fill); + + if ($YPos < $Bottom_Margin + $line_height){ + PrintHeader($pdf,$YPos,$PageNumber,$Page_Height,$Top_Margin,$Left_Margin,$Page_Width, + $Right_Margin,$WO,$Stockid,$myItem['description'],$QtyPending,$myItem['units'],$myItem['decimalplaces'],$ReportDate); + } + + $pdf->OutputD('WO-' . $WO . '-' . $StockId . '-' . Date('Y-m-d') . '.pdf'); + $pdf->__destruct(); + }else{ + $Title = _('WO Item production Slip'); + include('includes/header.inc'); + prnMsg(_('There were no items with ready to produce'),'info'); + prnMsg($sql); + echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>'; + include('includes/footer.inc'); + exit; + + } +} + + +function PrintHeader(&$pdf,&$YPos,&$PageNumber,$Page_Height,$Top_Margin,$Left_Margin, + $Page_Width,$Right_Margin,$WO,$StockId,$Description,$Qty,$UOM,$DecimalPlaces, $ReportDate) { + + /*PDF page header for MRP Planned Work Orders report */ + if ($PageNumber>1){ + $pdf->newPage(); + } + $line_height=12; + $FontSize=10; + $YPos= $Page_Height-$Top_Margin; + + $pdf->addTextWrap($Left_Margin,$YPos,300,$FontSize,$_SESSION['CompanyRecord']['coyname']); + $pdf->addTextWrap(190,$YPos,100,$FontSize,$ReportDate); + $pdf->addTextWrap($Page_Width-$Right_Margin-150,$YPos,160,$FontSize,_('Printed') . ': ' . + Date($_SESSION['DefaultDateFormat']) . ' ' . _('Page') . ' ' . $PageNumber,'left'); + $YPos -=$line_height; + + $pdf->addTextWrap($Left_Margin,$YPos,150,$FontSize,_('Work Order Item Production Slip')); + $YPos -=(2*$line_height); + + $pdf->addTextWrap($Left_Margin,$YPos,150,$FontSize,_('WO'). ': ' . $WO); + $YPos -= $line_height; + + $pdf->addTextWrap($Left_Margin,$YPos,500,$FontSize,_('Item Code'). ': ' . $StockId . ' --> ' . $Description); + $YPos -= $line_height; + + $pdf->addTextWrap($Left_Margin,$YPos,150,$FontSize,_('Quantity'). ': ' . locale_number_format($Qty,$DecimalPlaces) . ' ' . $UOM); + $YPos -=(2*$line_height); + + if(file_exists($_SESSION['part_pics_dir'] . '/' .$StockId.'.jpg') ) { + $pdf->Image($_SESSION['part_pics_dir'] . '/'.$StockId.'.jpg',135,$Page_Height-$Top_Margin-$YPos+10,200,200); + $YPos -=(16*$line_height); + }/*end checked file exist*/ + + + /*set up the headings */ + $Xpos = $Left_Margin+1; + + $pdf->addTextWrap($Xpos,$YPos,150,$FontSize,_('Component Code'), 'left'); + $pdf->addTextWrap(150,$YPos,50,$FontSize,_('Qty BOM'), 'right'); + $pdf->addTextWrap(200,$YPos,30,$FontSize,_(''), 'left'); + $pdf->addTextWrap(230,$YPos,50,$FontSize,_('Qty Needed'), 'right'); + $pdf->addTextWrap(280,$YPos,30,$FontSize,_(''), 'left'); + $pdf->addTextWrap(310,$YPos,50,$FontSize,_('Shrinkage'), 'right'); + $pdf->addTextWrap(360,$YPos,30,$FontSize,_(''), 'left'); + + $FontSize=10; + $YPos -= $line_height; + + $PageNumber++; +} + +?> Added: trunk/WOCanBeProducedNow.php =================================================================== --- trunk/WOCanBeProducedNow.php (rev 0) +++ trunk/WOCanBeProducedNow.php 2014-09-07 15:55:49 UTC (rev 6866) @@ -0,0 +1,250 @@ +<?php + +include('includes/session.inc'); +$Title = _('WO items can be produced with available stock'); +include('includes/header.inc'); + +if (isset($_POST['submit'])) { + submit($db, $RootPath, $_POST['Location']); +} else { + display($db); +} + +//####_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT#### +function submit(&$db, $RootPath, $Location) { + + $WhereLocation = " AND workorders.loccode >= '". $Location ."' "; + + $sql = "SELECT woitems.wo, + woitems.stockid, + woitems.qtyreqd, + woitems.qtyrecd, + stockmaster.decimalplaces, + stockmaster.units + FROM workorders, woitems, stockmaster + WHERE workorders.wo = woitems.wo + AND stockmaster.stockid = woitems.stockid + AND workorders.closed = 0 + AND woitems.qtyreqd > woitems.qtyrecd ". + $WhereLocation . + "ORDER BY woitems.wo, woitems.stockid" + ; + + $ErrMsg = _('The SQL to find the WO items to produce '); + $resultItems = DB_query($sql,$db,$ErrMsg); + if (DB_num_rows($resultItems) != 0){ + + echo '<p class="page_title_text" align="center"><strong>' . "Items in WO to be produced now in " . $Location . " with available stock" . '</strong></p>'; + echo '<div>'; + echo '<table class="selection">'; + $TableHeader = ' + <tr> + <th>' . _('WO') . '</th> + <th>' . _('Stock ID') . '</th> + <th>' . _('Requested') . '</th> + <th>' . _('Received') . '</th> + <th>' . _('Pending') . '</th> + <th>' . _('UOM') . '</th> + <th>' . _('Component') . '</th> + <th>' . _('QOH') . '</th> + <th>' . _('Needed') . '</th> + <th>' . _('Shrinkage') . '</th> + <th>' . _('UOM') . '</th> + <th>' . _('') . '</th> + <th>' . _('Result') . '</th> + </tr>'; + + while ($myItem = DB_fetch_array($resultItems)) { + echo $TableHeader; + + $QtyPending = $myItem['qtyreqd'] - $myItem['qtyrecd']; + $QtyCanBeProduced = $QtyPending; + + $WOLink = '<a href="' . $RootPath . '/WorkOrderEntry.php?WO=' . $myItem['wo'] . '">' . $myItem['wo'] . '</a>'; + $CodeLink = '<a href="' . $RootPath . '/SelectProduct.php?StockID=' . $myItem['stockid'] . '">' . $myItem['stockid'] . '</a>'; + + printf('<td class="number">%s</td> + <td>%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + </tr>', + $WOLink, + $CodeLink, + locale_number_format($myItem['qtyreqd'],$myItem['decimalplaces']), + locale_number_format($myItem['qtyrecd'],$myItem['decimalplaces']), + locale_number_format($QtyPending,$myItem['decimalplaces']), + $myItem['units'], + '', + '', + '', + '', + '', + '', + '' + ); + + // Get the BOM for this item + $sqlBOM = "SELECT bom.parent, + bom.component, + bom.quantity AS bomqty, + stockmaster.decimalplaces, + stockmaster.units, + stockmaster.shrinkfactor, + locstock.quantity AS qoh + FROM bom, stockmaster, locstock + WHERE bom.component = stockmaster.stockid + AND bom.component = locstock.stockid + AND locstock.loccode = '". $Location ."' + AND bom.parent = '" . $myItem['stockid'] . "' + AND bom.effectiveafter < '" . Date('Y-m-d') . "' + AND (bom.effectiveto > '" . Date('Y-m-d') . "' + OR bom.effectiveto='0000-00-00')"; + + $ErrMsg = _('The bill of material could not be retrieved because'); + $BOMResult = DB_query ($sqlBOM,$db,$ErrMsg); + $ItemCanBeproduced = TRUE; + + while ($myComponent = DB_fetch_array($BOMResult)) { + + $ComponentNeeded = $myComponent['bomqty'] * $QtyPending; + $PrevisionShrinkage = $ComponentNeeded * ($myComponent['shrinkfactor'] / 100); + + if ($myComponent['qoh'] >= $ComponentNeeded){ + $Available = "OK"; + }else{ + $Available = ""; + $ItemCanBeproduced = FALSE; + } + + $ComponentLink = '<a href="' . $RootPath . '/SelectProduct.php?StockID=' . $myComponent['component'] . '">' . $myComponent['component'] . '</a>'; + + printf('<td class="number">%s</td> + <td>%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + </tr>', + '', + '', + '', + '', + '', + '', + $ComponentLink, + locale_number_format($myComponent['qoh'],$myComponent['decimalplaces']), + locale_number_format($ComponentNeeded,$myComponent['decimalplaces']), + locale_number_format($PrevisionShrinkage,$myComponent['decimalplaces']), + $myComponent['units'], + $Available, + '' + ); + } + if ($ItemCanBeproduced){ + $Action = 'Produce ' . locale_number_format($QtyPending,0) . ' x ' . $myItem['stockid'] . ' for WO ' . locale_number_format($myItem['wo'],0); + $ComponentLink = '<a href="' . $RootPath . '/PrintWOItemSlip.php?StockId=' . $myItem['stockid'] . '&WO='. $myItem['wo'] . '&Location=' . $Location . '">' . $Action . '</a>'; + }else{ + $ComponentLink = ""; + } + printf('<td class="number">%s</td> + <td>%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td class="number">%s</td> + <td>%s</td> + <td>%s</td> + <td>%s</td> + </tr>', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + $ComponentLink + ); + } + echo '</table> + </div>'; + + }else{ + prnMsg('No items waiting to be produced in ' . $Location); + } + +} // End of function submit() + + +function display(&$db) //####DISPLAY_DISPLAY_DISPLAY_DISPLAY_DISPLAY_DISPLAY_##### +{ +// Display form fields. This function is called the first time +// the page is called. + + echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post"> + <div> + <br/> + <br/>'; + echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + + echo '<p class="page_title_text" align="center"><strong>' . "List of items in WO ready to be produced in: " . '</strong></p>'; + + echo '<table>'; + + echo '<tr> + <td>' . _('For Factory Location') . ':</td> + <td><select name="Location">'; + + $sql = "SELECT loccode, + locationname + FROM locations"; + + $LocnResult=DB_query($sql,$db); + + while ($myrow=DB_fetch_array($LocnResult)){ + echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; + } + echo '</select></td> + </tr>'; + + + echo '<tr><td> </td></tr> + <tr><td> </td></tr> + <tr> + <td> </td> + <td><input type="submit" name="submit" value="' . _('Search Items To Produce') . '" /></td> + </tr> + </table> + <br />'; + echo '</div> + </form>'; + +} // End of function display() + +include('includes/footer.inc'); +?> \ No newline at end of file Modified: trunk/includes/MainMenuLinksArray.php =================================================================== --- trunk/includes/MainMenuLinksArray.php 2014-09-06 03:14:43 UTC (rev 6865) +++ trunk/includes/MainMenuLinksArray.php 2014-09-07 15:55:49 UTC (rev 6866) @@ -294,6 +294,7 @@ _('List Components Required'), _('List Materials Not Used Anywhere'), _('Indented Where Used Listing'), + _('WO Items ready to produce'), _('MRP'), _('MRP Shortages'), _('MRP Suggested Purchase Orders'), @@ -308,6 +309,7 @@ '/BOMExtendedQty.php', '/MaterialsNotUsed.php', '/BOMIndentedReverse.php', + '/WOCanBeProducedNow.php', '/MRPReport.php', '/MRPShortages.php', '/MRPPlannedPurchaseOrders.php', Modified: trunk/sql/mysql/upgrade4.11-4.12.sql =================================================================== --- trunk/sql/mysql/upgrade4.11-4.12.sql 2014-09-06 03:14:43 UTC (rev 6865) +++ trunk/sql/mysql/upgrade4.11-4.12.sql 2014-09-07 15:55:49 UTC (rev 6866) @@ -77,6 +77,10 @@ ALTER TABLE `mrpparameters` ADD `userldemands` VARCHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'use RL requirements or not' AFTER `usemrpdemands`; +INSERT INTO `scripts` ( `script` , `pagesecurity` , `description` ) VALUES ('WOCanBeProducedNow.php', '4', 'List of WO items that can be produced with available stock in location'); +INSERT INTO `scripts` ( `script` , `pagesecurity` , `description` ) VALUES ('PrintWOItemSlip.php', '4', 'PDF WO Item production Slip '); + + UPDATE config SET confvalue='4.12' WHERE confname='VersionNumber'; |