From: <tim...@us...> - 2010-07-12 18:38:59
|
Revision: 3611 http://web-erp.svn.sourceforge.net/web-erp/?rev=3611&view=rev Author: tim_schofield Date: 2010-07-12 18:38:48 +0000 (Mon, 12 Jul 2010) Log Message: ----------- Layout changes, sql quoting corrections Modified Paths: -------------- trunk/MRP.php trunk/doc/Change.log.html Modified: trunk/MRP.php =================================================================== --- trunk/MRP.php 2010-07-12 18:38:26 UTC (rev 3610) +++ trunk/MRP.php 2010-07-12 18:38:48 UTC (rev 3611) @@ -5,13 +5,13 @@ $PageSecurity=9; include('includes/session.inc'); -$title = _('MRP'); +$title = _('Run MRP Calculation'); include('includes/header.inc'); if (isset($_POST['submit'])) { - if (!$_POST['Leeway'] || !is_numeric($_POST['Leeway'])) { - $_POST['Leeway'] = 0; + if (!$_POST['Leeway'] || !is_numeric($_POST['Leeway'])) { + $_POST['Leeway'] = 0; } // MRP - Create levels table based on bom @@ -58,7 +58,7 @@ $sql = "INSERT INTO tempbom (parent, component, sortpart, level) SELECT bom.parent AS parent, bom.component AS component, CONCAT(bom.parent,'%',bom.component) AS sortpart, - '$lctr' as level + '". $lctr. "' as level FROM bom LEFT JOIN bom as bom2 ON bom.parent = bom2.component WHERE bom2.component IS NULL"; $result = DB_query($sql,$db); @@ -74,7 +74,7 @@ $sql = "INSERT INTO tempbom (parent, component, sortpart, level) SELECT bom.parent AS parent, bom.component AS component, CONCAT(passbom.sortpart,'%',bom.component) AS sortpart, - $lctr as level + '" .$lctr . "' as level FROM bom,passbom WHERE bom.parent = passbom.part"; $result = DB_query($sql,$db); @@ -96,8 +96,8 @@ $sql = 'SELECT COUNT(*) FROM bom - INNER JOIN passbom ON bom.parent = passbom.part - GROUP BY bom.parent'; + INNER JOIN passbom ON bom.parent = passbom.part + GROUP BY bom.parent'; $result = DB_query($sql,$db); $myrow = DB_fetch_row($result); @@ -126,7 +126,7 @@ foreach ($parts as $part) { $ctr++; $newlevel = $level - $ctr; - $sql = "INSERT INTO bomlevels (part, level) VALUES('$part','$newlevel')"; + $sql = "INSERT INTO bomlevels (part, level) VALUES('" . $part . "','" . $newlevel . "')"; $result2 = DB_query($sql,$db); } // End of foreach } //end of while loop @@ -158,9 +158,9 @@ FROM bomlevels INNER JOIN stockmaster ON bomlevels.part = stockmaster.stockid GROUP BY bomlevels.part, - pansize, - shrinkfactor, - stockmaster.eoq'; + pansize, + shrinkfactor, + stockmaster.eoq'; $result = DB_query($sql,$db); $sql = 'ALTER TABLE levels ADD INDEX part(part)'; $result = DB_query($sql,$db); @@ -249,7 +249,7 @@ salesorderdetails.orderno, "1", stkcode - FROM salesorders, salesorderdetails + FROM salesorders, salesorderdetails WHERE salesorders.orderno = salesorderdetails.orderno AND (quantity - qtyinvoiced) > 0 AND salesorderdetails.completed = 0 @@ -303,7 +303,7 @@ $result = DB_query($sql,$db); prnMsg(_('Loading requirements based on mrpdemands'),'info'); flush(); - } + } $sql = 'INSERT INTO mrprequirements (part, daterequired, @@ -366,30 +366,30 @@ purchorderdetails.deliverydate, 0 FROM purchorderdetails, - purchorders + purchorders WHERE purchorderdetails.orderno = purchorders.orderno - AND purchorders.status != "Cancelled" - AND(quantityord - quantityrecd) > 0'; + AND purchorders.status != "Cancelled" + AND(quantityord - quantityrecd) > 0'; $result = DB_query($sql,$db); prnMsg(_('Loading supplies from inventory on hand'),'info'); flush(); // Set date for inventory already onhand to 0000-00-00 so it is first in sort if ($_POST['location'][0] == 'All') { - $whereloc = ' '; + $whereloc = ' '; } elseif (sizeof($_POST['location']) == 1) { - $whereloc = " AND loccode ='" . $_POST['location'][0] . "' "; + $whereloc = " AND loccode ='" . $_POST['location'][0] . "' "; } else { - $whereloc = " AND loccode IN("; - $commactr = 0; - foreach ($_POST['location'] as $key => $value) { - $whereloc .= "'" . $value . "'"; - $commactr++; - if ($commactr < sizeof($_POST['location'])) { - $whereloc .= ","; - } // End of if - } // End of foreach - $whereloc .= ')'; + $whereloc = " AND loccode IN("; + $commactr = 0; + foreach ($_POST['location'] as $key => $value) { + $whereloc .= "'" . $value . "'"; + $commactr++; + if ($commactr < sizeof($_POST['location'])) { + $whereloc .= ","; + } // End of if + } // End of foreach + $whereloc .= ')'; } $sql = 'INSERT INTO mrpsupplies (id, @@ -474,7 +474,7 @@ // part, that serves as a gross requirement for a lower level part, so will read down through // the Bill of Materials to generate those requirements in function LevelNetting(). for ($level = $maxlevel; $level >= $minlevel; $level--) { - $sql = 'SELECT * FROM levels WHERE level = ' . "$level " . ' LIMIT 50000'; //should cover most eventualities!! + $sql = 'SELECT * FROM levels WHERE level = "' . $level .'" LIMIT 50000'; //should cover most eventualities!! prnMsg('</br>------ ' . _('Processing level') .' ' . $level . ' ------','info'); flush(); @@ -500,6 +500,7 @@ // Create entry for location field from $_POST['location'], which is an array // since multiple locations can be selected $commactr = 0; + $locparm=''; foreach ($_POST['location'] as $key => $value) { $locparm .= $value ; $commactr++; @@ -521,17 +522,19 @@ '" . $_POST['eoqflag'] . "', '" . $_POST['usemrpdemands'] . "', '" . $_POST['Leeway'] . "')"; - $result = DB_query($sql,$db); + $result = DB_query($sql,$db); } else { // End of if submit isset - // Display form if submit has not been hit + // Display form if submit has not been hit + echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/inventory.png" title="' . + _('Inventory') . '" alt="">' . ' ' . $title . ''; - // Display parameters from last run - $sql = 'SELECT * FROM mrpparameters'; - $result = DB_query($sql,$db,'','',false,false); - if (DB_error_no($db)==0){ + // Display parameters from last run + $sql = 'SELECT * FROM mrpparameters'; + $result = DB_query($sql,$db,'','',false,false); + if (DB_error_no($db)==0){ - $myrow = DB_fetch_array($result); + $myrow = DB_fetch_array($result); $leeway = $myrow['leeway']; $usemrpdemands = _('No'); @@ -550,47 +553,51 @@ if ($myrow['shrinkageflag'] == 'y') { $useshrinkage = _('Yes'); } - - echo '<table><tr><td>     </td>'; + echo '<table cellpadding=5><tr><td valign=top>'; + echo '<table class=selection>'; + echo '<tr><th colspan=3><font color=blue size=3>'._('Last Run Details').'</font></th></tr>'; + echo '<tr>'; echo '<td>' . _('Last Run Time') . ':  </td><td>' . $myrow['runtime'] . '</td></tr>'; - echo '<td></td><td>' . _('Location') . ':  </td><td>' . $myrow['location'] . '</td></tr>'; - echo '<td></td><td>' . _('Days Leeway') . ':  </td><td>' . $leeway . '</td></tr>'; - echo '<td></td><td>' . _('Use MRP Demands') . ':  </td><td>' . $usemrpdemands . '</td></tr>'; - echo '<td></td><td>' . _('Use EOQ') . ':  </td><td>' . $useeoq . '</td></tr>'; - echo '<td></td><td>' . _('Use Pan Size') . ':  </td><td>' . $usepansize . '</td></tr>'; - echo '<td></td><td>' . _('Use Shrinkage') . ':  </td><td>' . $useshrinkage . '</td></tr>'; - echo '</table>'; + echo '<td>' . _('Location') . ':  </td><td>' . $myrow['location'] . '</td></tr>'; + echo '<td>' . _('Days Leeway') . ':  </td><td>' . $leeway . '</td></tr>'; + echo '<td>' . _('Use MRP Demands') . ':  </td><td>' . $usemrpdemands . '</td></tr>'; + echo '<td>' . _('Use EOQ') . ':  </td><td>' . $useeoq . '</td></tr>'; + echo '<td>' . _('Use Pan Size') . ':  </td><td>' . $usepansize . '</td></tr>'; + echo '<td>' . _('Use Shrinkage') . ':  </td><td>' . $useshrinkage . '</td></tr>'; + echo '</table></td>'; } - echo "<p><form method='post' action='" . $_SERVER['PHP_SELF'] . '?' . SID . "'>"; - echo '<table>'; + echo "<p><form method='post' action='" . $_SERVER['PHP_SELF'] . '?' . SID . "'>"; + echo '<td><table class=selection>'; // Generate selections for Location + echo '<tr><th colspan=3><font color=blue size=3>'._('This Run Details').'</font></th></tr>'; echo '<tr> <td>' . _('Location') . '</td> <td><select name="location[]" multiple> <option value="All" selected>' . _('All') . '</option>'; - $sql = 'SELECT loccode - FROM locations'; + $sql = 'SELECT loccode, + locationname + FROM locations'; $result = DB_query($sql,$db); while ($myrow = DB_fetch_array($result)) { echo '<option value="'; - echo $myrow['loccode'] . '">' . $myrow['loccode'] . '</option>'; + echo $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>'; } //end while loop echo '</select></td></tr>'; if (!isset($leeway)){ $leeway =0; } - echo '<tr><td>' . _('Days Leeway') . ':</td><td><input type="text" name="Leeway" size="4" value=' . $leeway . '>'; - echo '<tr><td>' ._('Use MRP Demands?') . ':</td>'; - echo '<td><input type="checkbox" name="usemrpdemands" value="y" checked></td></tr>'; - echo '<tr><td>' ._('Use EOQ?') . ':</td>'; - echo '<td><input type="checkbox" name="eoqflag" value="y" checked></td></tr>'; - echo '<tr><td>' ._('Use Pan Size?') . ':</td>'; - echo '<td><input type="checkbox" name="pansizeflag" value="y" checked></td></tr>'; - echo '<tr><td>' ._('Use Shrinkage?') . ':</td>'; - echo '<td><input type="checkbox" name="shrinkageflag" value="y" checked></td></tr>'; - echo '</table><div class="centre"></br></br><input type="submit" name="submit" value="' . _('Run MRP') . '"></div>'; - echo '</form>'; + echo '<tr><td>' . _('Days Leeway') . ':</td><td><input type="text" name="Leeway" class=number size="4" value=' . $leeway . '>'; + echo '<tr><td>' ._('Use MRP Demands?') . ':</td>'; + echo '<td><input type="checkbox" name="usemrpdemands" value="y" checked></td></tr>'; + echo '<tr><td>' ._('Use EOQ?') . ':</td>'; + echo '<td><input type="checkbox" name="eoqflag" value="y" checked></td></tr>'; + echo '<tr><td>' ._('Use Pan Size?') . ':</td>'; + echo '<td><input type="checkbox" name="pansizeflag" value="y" checked></td></tr>'; + echo '<tr><td>' ._('Use Shrinkage?') . ':</td>'; + echo '<td><input type="checkbox" name="shrinkageflag" value="y" checked></td></tr>'; + echo '</table></td></tr></table><div class="centre"></br></br><input type="submit" name="submit" value="' . _('Run MRP') . '"></div>'; + echo '</form>'; } // End of Main program logic ------------------------------------------------------- @@ -599,16 +606,16 @@ // Create an array of mrprequirements and an array of mrpsupplies, then read through // them seeing if all requirements are covered by supplies. Create a planned order // for any unmet requirements. Change dates if necessary for the supplies. - //echo '</br>Part is ' . "$part" . '</br>'; + //echo '</br>Part is ' . "$part" . '</br>'; - // Get decimal places from stockmaster for rounding of shrinkage factor - $sql = "SELECT decimalplaces FROM stockmaster WHERE stockid = '" . $part . "'"; + // Get decimal places from stockmaster for rounding of shrinkage factor + $sql = "SELECT decimalplaces FROM stockmaster WHERE stockid = '" . $part . "'"; $result = DB_query($sql,$db); $myrow=DB_fetch_row($result); $decimalplaces = $myrow[0]; - // Load mrprequirements into $requirements array - $sql = "SELECT * FROM mrprequirements WHERE part = '" . "$part" . "' ORDER BY daterequired"; + // Load mrprequirements into $requirements array + $sql = "SELECT * FROM mrprequirements WHERE part = '" .$part. "' ORDER BY daterequired"; $result = DB_query($sql,$db); $requirements = array(); $i = 0; @@ -617,8 +624,8 @@ $i++; } //end of while loop - // Load mrpsupplies into $supplies array - $sql = "SELECT * FROM mrpsupplies WHERE part = '" . "$part" . "' ORDER BY duedate"; + // Load mrpsupplies into $supplies array + $sql = "SELECT * FROM mrpsupplies WHERE part = '" .$part. "' ORDER BY duedate"; $result = DB_query($sql,$db); $supplies = array(); $i = 0; @@ -627,96 +634,96 @@ $i++; } //end of while loop - // Go through all requirements and check if have supplies to cover them - $requirementcount = count($requirements); - $supplycount = count($supplies); - $reqi = 0; //Index for requirements - $supi = 0; // index for supplies - $totalrequirement = 0; - $totalsupply = 0; + // Go through all requirements and check if have supplies to cover them + $requirementcount = count($requirements); + $supplycount = count($supplies); + $reqi = 0; //Index for requirements + $supi = 0; // index for supplies + $totalrequirement = 0; + $totalsupply = 0; - if ($requirementcount > 0 && $supplycount > 0) { - $totalrequirement += $requirements[$reqi]['quantity']; - $totalsupply += $supplies[$supi]['supplyquantity']; - while ($totalrequirement > 0 && $totalsupply > 0) { - $supplies[$supi]['updateflag'] = 1; - // ******** Put leeway calculation in here ******** - $duedate = ConvertSQLDate($supplies[$supi]['duedate']); - $reqdate = ConvertSQLDate($requirements[$reqi]['daterequired']); - $datediff = DateDiff($duedate,$reqdate,'d'); + if ($requirementcount > 0 && $supplycount > 0) { + $totalrequirement += $requirements[$reqi]['quantity']; + $totalsupply += $supplies[$supi]['supplyquantity']; + while ($totalrequirement > 0 && $totalsupply > 0) { + $supplies[$supi]['updateflag'] = 1; + // ******** Put leeway calculation in here ******** + $duedate = ConvertSQLDate($supplies[$supi]['duedate']); + $reqdate = ConvertSQLDate($requirements[$reqi]['daterequired']); + $datediff = DateDiff($duedate,$reqdate,'d'); //if ($supplies[$supi]['duedate'] > $requirements[$reqi]['daterequired']) { if ($datediff > abs($_POST['Leeway'])) { - $sql = "UPDATE mrpsupplies SET mrpdate = '" . $requirements[$reqi]['daterequired'] . - "' WHERE id = '" . $supplies[$supi]['id'] . "' AND duedate = mrpdate"; - $result = DB_query($sql,$db); + $sql = "UPDATE mrpsupplies SET mrpdate = '" . $requirements[$reqi]['daterequired'] . + "' WHERE id = '" . $supplies[$supi]['id'] . "' AND duedate = mrpdate"; + $result = DB_query($sql,$db); } - if ($totalrequirement > $totalsupply) { - $totalrequirement -= $totalsupply; - $requirements[$reqi]['quantity'] -= $totalsupply; - $totalsupply = 0; - $supplies[$supi]['supplyquantity'] = 0; - $supi++; - if ($supplycount > $supi) { - $totalsupply += $supplies[$supi]['supplyquantity']; - } - } else { - $totalsupply -= $totalrequirement; - $supplies[$supi]['supplyquantity'] -= $totalrequirement; - $totalrequirement = 0; - $requirements[$reqi]['quantity'] = 0; - $reqi++; - if ($requirementcount > $reqi) { - $totalrequirement += $requirements[$reqi]['quantity']; - } - } // End of if $totalrequirement > $totalsupply - } // End of while - } // End of if + if ($totalrequirement > $totalsupply) { + $totalrequirement -= $totalsupply; + $requirements[$reqi]['quantity'] -= $totalsupply; + $totalsupply = 0; + $supplies[$supi]['supplyquantity'] = 0; + $supi++; + if ($supplycount > $supi) { + $totalsupply += $supplies[$supi]['supplyquantity']; + } + } else { + $totalsupply -= $totalrequirement; + $supplies[$supi]['supplyquantity'] -= $totalrequirement; + $totalrequirement = 0; + $requirements[$reqi]['quantity'] = 0; + $reqi++; + if ($requirementcount > $reqi) { + $totalrequirement += $requirements[$reqi]['quantity']; + } + } // End of if $totalrequirement > $totalsupply + } // End of while + } // End of if - // When get to this part of code, have gone through all requirements, If there is any - // unmet requirements, create an mrpplannedorder to cover it. Also call the - // CreateLowerLevelRequirement() function to create gross requirements for lower level parts. + // When get to this part of code, have gone through all requirements, If there is any + // unmet requirements, create an mrpplannedorder to cover it. Also call the + // CreateLowerLevelRequirement() function to create gross requirements for lower level parts. - // There is an excess quantity if the eoq is higher than the actual required amount. - // If there is a subsuquent requirement, the excess quantity is subtracted from that - // quantity. For instance, if the first requirement was for 2 and the eoq was 5, there - // would be an excess of 3; if there was another requirement for 3 or less, the excess - // would cover it, so no planned order would have to be created for the second requirement. - $excessqty = 0; - foreach ($requirements as $key => $row) { - $daterequired[$key] = $row['daterequired']; - } - if (count($requirements)) { - array_multisort($daterequired, SORT_ASC, $requirements); - } - foreach($requirements as $requirement) { - // First, inflate requirement if there is a shrinkage factor - // Should the quantity be rounded? - if ($_POST['shrinkageflag'] == 'y' and $shrinkfactor > 0) { - $requirement['quantity'] = ($requirement['quantity'] * 100) / (100 - $shrinkfactor); - $requirement['quantity'] = round($requirement['quantity'],$decimalplaces); - } - if ($excessqty >= $requirement['quantity']) { - $plannedqty = 0; - $excessqty -= $requirement['quantity']; - } else { - $plannedqty = $requirement['quantity'] - $excessqty; - $excessqty = 0; - } - if ($plannedqty > 0) { - if ($_POST['eoqflag'] == 'y' and $eoq > $plannedqty) { - $excessqty = $eoq - $plannedqty; - $plannedqty = $eoq; - } - // Pansize calculation here - // if $plannedqty not evenly divisible by $pansize, calculate as $plannedqty - // divided by $pansize and rounded up to the next highest integer and then - // multiplied by the pansize. For instance, with a planned qty of 17 with a pansize - // of 5, divide 17 by 5 to get 3 with a remainder of 2, which is rounded up to 4 - // and then multiplied by 5 - the pansize - to get 20 - if ($_POST['pansizeflag'] == 'y' and $pansize != 0 and $plannedqty % $pansize != 0) { - $plannedqty = ceil($plannedqty / $pansize) * $pansize; - } + // There is an excess quantity if the eoq is higher than the actual required amount. + // If there is a subsuquent requirement, the excess quantity is subtracted from that + // quantity. For instance, if the first requirement was for 2 and the eoq was 5, there + // would be an excess of 3; if there was another requirement for 3 or less, the excess + // would cover it, so no planned order would have to be created for the second requirement. + $excessqty = 0; + foreach ($requirements as $key => $row) { + $daterequired[$key] = $row['daterequired']; + } + if (count($requirements)) { + array_multisort($daterequired, SORT_ASC, $requirements); + } + foreach($requirements as $requirement) { + // First, inflate requirement if there is a shrinkage factor + // Should the quantity be rounded? + if ($_POST['shrinkageflag'] == 'y' and $shrinkfactor > 0) { + $requirement['quantity'] = ($requirement['quantity'] * 100) / (100 - $shrinkfactor); + $requirement['quantity'] = round($requirement['quantity'],$decimalplaces); + } + if ($excessqty >= $requirement['quantity']) { + $plannedqty = 0; + $excessqty -= $requirement['quantity']; + } else { + $plannedqty = $requirement['quantity'] - $excessqty; + $excessqty = 0; + } + if ($plannedqty > 0) { + if ($_POST['eoqflag'] == 'y' and $eoq > $plannedqty) { + $excessqty = $eoq - $plannedqty; + $plannedqty = $eoq; + } + // Pansize calculation here + // if $plannedqty not evenly divisible by $pansize, calculate as $plannedqty + // divided by $pansize and rounded up to the next highest integer and then + // multiplied by the pansize. For instance, with a planned qty of 17 with a pansize + // of 5, divide 17 by 5 to get 3 with a remainder of 2, which is rounded up to 4 + // and then multiplied by 5 - the pansize - to get 20 + if ($_POST['pansizeflag'] == 'y' and $pansize != 0 and $plannedqty % $pansize != 0) { + $plannedqty = ceil($plannedqty / $pansize) * $pansize; + } $sql = "INSERT INTO mrpplannedorders (id, part, duedate, @@ -736,29 +743,29 @@ $result = DB_query($sql,$db); // If part has lower level components, create requirements for them $sql = "SELECT COUNT(*) FROM bom - WHERE parent ='" . $requirement['part'] . "' - GROUP BY parent"; - $result = DB_query($sql,$db); - $myrow = DB_fetch_row($result); - if ($myrow[0] > 0) { - CreateLowerLevelRequirement($db,$requirement['part'],$requirement['daterequired'], - $plannedqty,$requirement['mrpdemandtype'],$requirement['orderno'], - $requirement['whererequired']); + WHERE parent ='" . $requirement['part'] . "' + GROUP BY parent"; + $result = DB_query($sql,$db); + $myrow = DB_fetch_row($result); + if ($myrow[0] > 0) { + CreateLowerLevelRequirement($db,$requirement['part'],$requirement['daterequired'], + $plannedqty,$requirement['mrpdemandtype'],$requirement['orderno'], + $requirement['whererequired']); } - } // End of if $plannedqty > 0 - } // End of foreach $requirements + } // End of if $plannedqty > 0 + } // End of foreach $requirements // If there are any supplies not used and updateflag is zero, those supplies are not - // necessary, so change date + // necessary, so change date - foreach($supplies as $supply) { - if ($supply['supplyquantity'] > 0 && $supply['updateflag'] == 0) { + foreach($supplies as $supply) { + if ($supply['supplyquantity'] > 0 && $supply['updateflag'] == 0) { $id = $supply['id']; - $sql = "UPDATE mrpsupplies SET mrpdate ='2050-12-31' WHERE id = '$id' - AND ordertype <> 'QOH'"; - $result = DB_query($sql,$db); - } - } + $sql = "UPDATE mrpsupplies SET mrpdate ='2050-12-31' WHERE id = '".$id."' + AND ordertype <> 'QOH'"; + $result = DB_query($sql,$db); + } + } } // End of LevelNetting ------------------------------------------------------- @@ -770,51 +777,51 @@ $toporderno, $whererequired) { // Creates an mrprequirement based on the net requirement from the part above it in the bom - $sql = "SELECT bom.component, - bom.quantity, - levels.leadtime, - levels.eoq - FROM bom - LEFT JOIN levels - ON bom.component = levels.part - WHERE bom.parent = '$toppart' + $sql = "SELECT bom.component, + bom.quantity, + levels.leadtime, + levels.eoq + FROM bom + LEFT JOIN levels + ON bom.component = levels.part + WHERE bom.parent = '".$toppart."' AND effectiveafter <= now() AND effectiveto >= now()"; $resultbom = DB_query($sql,$db); while ($myrow=DB_fetch_array($resultbom)) { - // Calculate required date by subtracting leadtime from top part's required date - $leadtime = $myrow['leadtime']; + // Calculate required date by subtracting leadtime from top part's required date + $leadtime = $myrow['leadtime']; - // Following sql finds daynumber for the top part's required date, subtracts leadtime, and finds - // a valid manufacturing date for the daynumber. There is only one valid manufacturing date - // for each daynumber, but there could be several non-manufacturing dates for the - // same daynumber. MRPCalendar.php maintains the manufacturing calendar. - $calendarsql = "SELECT COUNT(*),cal2.calendardate - FROM mrpcalendar - LEFT JOIN mrpcalendar as cal2 - ON (mrpcalendar.daynumber - $leadtime) = cal2.daynumber - WHERE mrpcalendar.calendardate = '$topdate' - AND cal2.manufacturingflag='1' - GROUP BY cal2.calendardate"; - $resultdate = DB_query($calendarsql,$db); - $myrowdate=DB_fetch_array($resultdate); - $newdate = $myrowdate[1]; - // If can't find date based on manufacturing calendar, use $topdate - if ($myrowdate[0] == 0){ - // Convert $topdate from mysql format to system date format, use that to subtract leadtime - // from it using DateAdd, convert that date back to mysql format - $convertdate = ConvertSQLDate($topdate); - $dateadd = DateAdd($convertdate,"d",($leadtime * -1)); - $newdate = FormatDateForSQL($dateadd); - } + // Following sql finds daynumber for the top part's required date, subtracts leadtime, and finds + // a valid manufacturing date for the daynumber. There is only one valid manufacturing date + // for each daynumber, but there could be several non-manufacturing dates for the + // same daynumber. MRPCalendar.php maintains the manufacturing calendar. + $calendarsql = "SELECT COUNT(*),cal2.calendardate + FROM mrpcalendar + LEFT JOIN mrpcalendar as cal2 + ON (mrpcalendar.daynumber - '".$leadtime."') = cal2.daynumber + WHERE mrpcalendar.calendardate = '".$topdate."' + AND cal2.manufacturingflag='1' + GROUP BY cal2.calendardate"; + $resultdate = DB_query($calendarsql,$db); + $myrowdate=DB_fetch_array($resultdate); + $newdate = $myrowdate[1]; + // If can't find date based on manufacturing calendar, use $topdate + if ($myrowdate[0] == 0){ + // Convert $topdate from mysql format to system date format, use that to subtract leadtime + // from it using DateAdd, convert that date back to mysql format + $convertdate = ConvertSQLDate($topdate); + $dateadd = DateAdd($convertdate,"d",($leadtime * -1)); + $newdate = FormatDateForSQL($dateadd); + } - $component = $myrow['component']; - $extendedquantity = $myrow['quantity'] * $topquantity; + $component = $myrow['component']; + $extendedquantity = $myrow['quantity'] * $topquantity; // Commented out the following lines 8/15/09 because the eoq should be considered in the // LevelNetting() function where $excessqty is calculated -// if ($myrow['eoq'] > $extendedquantity) { -// $extendedquantity = $myrow['eoq']; -// } +// if ($myrow['eoq'] > $extendedquantity) { +// $extendedquantity = $myrow['eoq']; +// } $sql = "INSERT INTO mrprequirements (part, daterequired, @@ -823,13 +830,13 @@ orderno, directdemand, whererequired) - VALUES ('$component', - '$newdate', - '$extendedquantity', - '$topmrpdemandtype', - '$toporderno', + VALUES ('".$component."', + '".$newdate."', + '".$extendedquantity."', + '".$topmrpdemandtype."', + '".$toporderno."', '0', - '$whererequired')"; + '".$whererequired."')"; $result = DB_query($sql,$db); } //end of while loop Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-07-12 18:38:26 UTC (rev 3610) +++ trunk/doc/Change.log.html 2010-07-12 18:38:48 UTC (rev 3611) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>12/07/10 Tim: MRP.php - Layout changes, sql quoting corrections</p> <p>12/07/10 Tim: Locations.php - Bug Fixes, Layout changes, sql quoting corrections</p> <p>12/07/10 Tim: PDFGrn.php - Correct conversion factor bug</p> <p>11/07/10 Tim: InventoryValuation.php - Layout changes</p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |