Esempio n. 1
0
function submit(&$db, &$StockID, &$DemandID)
{
    // In this section if hit submit button. Do edit checks. If all checks pass, see if record already
    // exists for StockID/Duedate/MRPDemandtype combo; that means do an Update, otherwise, do INSERT.
    //initialise no input errors assumed initially before we test
    // echo "</br>Submit - DemandID = $DemandID</br>";
    $FormatedDuedate = FormatDateForSQL($_POST['Duedate']);
    $InputError = 0;
    /* actions to take once the user has clicked the submit button
    	ie the page has called itself with some user input */
    //first off validate inputs sensible
    if (!is_numeric($_POST['Quantity'])) {
        $InputError = 1;
        prnMsg(_('Quantity must be numeric'), 'error');
    }
    if ($_POST['Quantity'] <= 0) {
        $InputError = 1;
        prnMsg(_('Quantity must be greater than 0'), 'error');
    }
    if (!is_Date($_POST['Duedate'])) {
        $InputError = 1;
        prnMsg(_('Invalid due date'), 'error');
    }
    $sql = "SELECT * FROM mrpdemandtypes\n\t\tWHERE mrpdemandtype='" . $_POST['MRPDemandtype'] . "'";
    $result = DB_query($sql, $db);
    if (DB_num_rows($result) == 0) {
        $InputError = 1;
        prnMsg(_('Invalid demand type'), 'error');
    }
    // Check if valid part number - Had done a Select Count(*), but that returned a 1 in DB_num_rows
    // even if there was no record.
    $sql = "SELECT * FROM stockmaster\n\t\tWHERE stockid='{$StockID}'";
    $result = DB_query($sql, $db);
    if (DB_num_rows($result) == 0) {
        $InputError = 1;
        prnMsg($StockID . ' ' . _('is not a valid item code'), 'error');
        unset($_POST['StockID']);
        unset($StockID);
    }
    // Check if part number/demand type/due date combination already exists
    $sql = "SELECT * FROM mrpdemands\n\t          WHERE stockid='{$StockID}'\n\t\t  AND mrpdemandtype='" . $_POST['MRPDemandtype'] . "'" . " AND duedate='{$FormatedDuedate}'\n\t\t   AND demandid <> '{$DemandID}'";
    $result = DB_query($sql, $db);
    if (DB_num_rows($result) > 0) {
        $InputError = 1;
        prnMsg(_('Record alread exists for part number/demand type/date'), 'error');
    }
    if ($InputError != 1) {
        $sql = "SELECT count(*) FROM mrpdemands\n\t\t\t       WHERE demandid='{$DemandID}'";
        $result = DB_query($sql, $db);
        $myrow = DB_fetch_row($result);
        if ($myrow[0] > 0) {
            //If $myrow[0] > 0, it means this is an edit, so do an update
            $sql = "UPDATE mrpdemands SET quantity = '" . $_POST['Quantity'] . "',\n\t\t\t\t\t\t\tmrpdemandtype = '" . trim(strtoupper($_POST['MRPDemandtype'])) . "',\n\t\t\t\t\t\t\tduedate = '" . $FormatedDuedate . "'\n\t\t\t\t\tWHERE demandid = '" . $DemandID . "'";
            $msg = _("The MRP demand record has been updated for {$StockID}");
        } else {
            // If $myrow[0] from SELECT count(*) is zero, this is an entry of a new record
            $sql = "INSERT INTO mrpdemands (stockid,\n\t\t\t\t\t\t\tmrpdemandtype,\n\t\t\t\t\t\t\tquantity,\n\t\t\t\t\t\t\tduedate)\n\t\t\t\t\t\tVALUES ('" . $StockID . "',\n\t\t\t\t\t\t\t'" . trim(strtoupper($_POST['MRPDemandtype'])) . "',\n\t\t\t\t\t\t\t'" . $_POST['Quantity'] . "',\n\t\t\t\t\t\t\t'" . $FormatedDuedate . "')";
            $msg = _('A new MRP demand record has been added to the database for') . ' ' . $StockID;
        }
        $result = DB_query($sql, $db, _('The update/addition of the MRP demand record failed because'));
        prnMsg($msg, 'success');
        unset($_POST['MRPDemandtype']);
        unset($_POST['Quantity']);
        unset($_POST['StockID']);
        unset($_POST['Duedate']);
        unset($StockID);
        unset($DemandID);
    }
    // End of else where DB_num_rows showed there was a valid stockmaster record
    display($db, $StockID, $DemandID);
}
     }
 }
 /*end while loop */
 // Print summary information for last part
 $YPos -= $line_height;
 $pdf->addTextWrap(40, $YPos, 130, $FontSize, $holddescription, '', 0, $fill);
 $pdf->addTextWrap(170, $YPos, 50, $FontSize, _('Unit Cost: '), 'center', 0, $fill);
 $pdf->addTextWrap(220, $YPos, 40, $FontSize, number_format($holdcost, 2), 'right', 0, $fill);
 $pdf->addTextWrap(260, $YPos, 50, $FontSize, number_format($totalpartqty, $holddecimalplaces), 'right', 0, $fill);
 $pdf->addTextWrap(310, $YPos, 60, $FontSize, number_format($totalpartcost, 2), 'right', 0, $fill);
 $pdf->addTextWrap(370, $YPos, 30, $FontSize, _('M/B: '), 'right', 0, $fill);
 $pdf->addTextWrap(400, $YPos, 15, $FontSize, $holdmbflag, 'right', 0, $fill);
 // Get and print supplier info for part
 list($lastdate, $lastsupplier, $preferredsupplier) = GetPartInfo($db, $holdpart);
 $displaydate = $lastdate;
 if (!is_Date($lastdate)) {
     $displaydate = " ";
 }
 $YPos -= $line_height;
 $pdf->addTextWrap(50, $YPos, 80, $FontSize, _('Last Purchase Date: '), 'left', 0, $fill);
 $pdf->addTextWrap(130, $YPos, 60, $FontSize, $displaydate, 'left', 0, $fill);
 $pdf->addTextWrap(190, $YPos, 60, $FontSize, _('Supplier: '), 'left', 0, $fill);
 $pdf->addTextWrap(250, $YPos, 60, $FontSize, $lastsupplier, 'left', 0, $fill);
 $pdf->addTextWrap(310, $YPos, 120, $FontSize, _('Preferred Supplier: '), 'left', 0, $fill);
 $pdf->addTextWrap(430, $YPos, 60, $FontSize, $preferredsupplier, 'left', 0, $fill);
 $FontSize = 8;
 $YPos -= 2 * $line_height;
 if ($YPos < $Bottom_Margin + $line_height) {
     PrintHeader($pdf, $YPos, $PageNumber, $Page_Height, $Top_Margin, $Left_Margin, $Page_Width, $Right_Margin, $_POST['Consolidation'], $reportdate);
     // include('includes/MRPPlannedPurchaseOrdersPageHeader.inc');
 }
/* $Revision: 1.5 $ */
// MRPPlannedWorkOrders.php - Report of manufactured parts that MRP has determined should have
// work orders created for them
$PageSecurity = 2;
include 'includes/session.inc';
if (isset($_POST['PrintPDF'])) {
    include 'includes/PDFStarter.php';
    $FontSize = 9;
    $pdf->addinfo('Title', _('MRP Panned Work Orders Report'));
    $pdf->addinfo('Subject', _('MRP Planned Work Orders'));
    $PageNumber = 1;
    $line_height = 12;
    $Xpos = $Left_Margin + 1;
    $wheredate = " ";
    $reportdate = " ";
    if (is_Date($_POST['cutoffdate'])) {
        $formatdate = FormatDateForSQL($_POST['cutoffdate']);
        $wheredate = ' AND duedate <= "' . $formatdate . '" ';
        $reportdate = _(' Through  ') . Format_Date($_POST['cutoffdate']);
    }
    if ($_POST['Consolidation'] == 'None') {
        $sql = 'SELECT mrpplannedorders.*,
					   stockmaster.stockid,
					   stockmaster.description,
					   stockmaster.mbflag,
					   stockmaster.decimalplaces,
					   stockmaster.actualcost,
                      (stockmaster.materialcost + stockmaster.labourcost + 
	                   stockmaster.overheadcost ) as computedcost
				FROM mrpplannedorders, stockmaster
				WHERE mrpplannedorders.part = stockmaster.stockid ' . "{$wheredate}" . ' AND stockmaster.mbflag = "M"