function submit(&$db, &$ChangeDate)
{
    //initialize no input errors
    $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_Date($_POST['FromDate'])) {
        $InputError = 1;
        prnMsg(_('Invalid From Date'), 'error');
    }
    if (!Is_Date($_POST['ToDate'])) {
        $InputError = 1;
        prnMsg(_('Invalid To Date'), 'error');
    }
    // Use FormatDateForSQL to put the entered dates into right format for sql
    // Use ConvertSQLDate to put sql formatted dates into right format for functions such as
    // DateDiff and DateAdd
    $FormatFromDate = FormatDateForSQL($_POST['FromDate']);
    $FormatToDate = FormatDateForSQL($_POST['ToDate']);
    $ConvertFromDate = ConvertSQLDate($FormatFromDate);
    $ConvertToDate = ConvertSQLDate($FormatToDate);
    $DateGreater = Date1GreaterThanDate2($_POST['ToDate'], $_POST['FromDate']);
    $DateDiff = DateDiff($ConvertToDate, $ConvertFromDate, 'd');
    // Date1 minus Date2
    if ($DateDiff < 1) {
        $InputError = 1;
        prnMsg(_('To Date Must Be Greater Than From Date'), 'error');
    }
    if ($InputError == 1) {
        ShowInputForm($db, $ChangeDate);
        return;
    }
    $sql = "DROP TABLE IF EXISTS mrpcalendar";
    $result = DB_query($sql);
    $sql = "CREATE TABLE mrpcalendar (\n\t\t\t\tcalendardate date NOT NULL,\n\t\t\t\tdaynumber int(6) NOT NULL,\n\t\t\t\tmanufacturingflag smallint(6) NOT NULL default '1',\n\t\t\t\tINDEX (daynumber),\n\t\t\t\tPRIMARY KEY (calendardate)) DEFAULT CHARSET=utf8";
    $ErrMsg = _('The SQL to create passbom failed with the message');
    $result = DB_query($sql, $ErrMsg);
    $i = 0;
    /* $DaysTextArray used so can get text of day based on the value get from DayOfWeekFromSQLDate of
    	 the calendar date. See if that text is in the ExcludeDays array note no gettext here hard coded english days from $_POST*/
    $DaysTextArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    $ExcludeDays = array($_POST['Sunday'], $_POST['Monday'], $_POST['Tuesday'], $_POST['Wednesday'], $_POST['Thursday'], $_POST['Friday'], $_POST['Saturday']);
    $CalDate = $ConvertFromDate;
    for ($i = 0; $i <= $DateDiff; $i++) {
        $DateAdd = FormatDateForSQL(DateAdd($CalDate, 'd', $i));
        // If the check box for the calendar date's day of week was clicked, set the manufacturing flag to 0
        $DayOfWeek = DayOfWeekFromSQLDate($DateAdd);
        $ManuFlag = 1;
        foreach ($ExcludeDays as $exday) {
            if ($exday == $DaysTextArray[$DayOfWeek]) {
                $ManuFlag = 0;
            }
        }
        $sql = "INSERT INTO mrpcalendar (\n\t\t\t\t\tcalendardate,\n\t\t\t\t\tdaynumber,\n\t\t\t\t\tmanufacturingflag)\n\t\t\t\t VALUES ('" . $DateAdd . "',\n\t\t\t\t\t\t'1',\n\t\t\t\t\t\t'" . $ManuFlag . "')";
        $result = DB_query($sql, $ErrMsg);
    }
    // Update daynumber. Set it so non-manufacturing days will have the same daynumber as a valid
    // manufacturing day that precedes it. That way can read the table by the non-manufacturing day,
    // subtract the leadtime from the daynumber, and find the valid manufacturing day with that daynumber.
    $DayNumber = 1;
    $sql = "SELECT * FROM mrpcalendar\n\t\t\tORDER BY calendardate";
    $result = DB_query($sql, $ErrMsg);
    while ($myrow = DB_fetch_array($result)) {
        if ($myrow['manufacturingflag'] == "1") {
            $DayNumber++;
        }
        $CalDate = $myrow['calendardate'];
        $sql = "UPDATE mrpcalendar SET daynumber = '" . $DayNumber . "'\n\t\t\t\t\tWHERE calendardate = '" . $CalDate . "'";
        $resultupdate = DB_query($sql, $ErrMsg);
    }
    prnMsg(_('The MRP Calendar has been created'), 'success');
    ShowInputForm($db, $ChangeDate);
}
        }
        echo '<tr>
				<td>' . ConvertSQLDate($myrow['trandate']) . '</td>
				<td>' . $myrow['stockid'] . '</td>
				<td>' . $myrow['description'] . '</td>
				<td class="number">' . $myrow['quantity'] . '</td>
				<td class="number">' . number_format($myrow['value'], $_SESSION['Currencies'][$_SESSION['CompanyRecord']['currencydefault']]['DecimalPlaces']) . '</td>
			</tr>';
        $SubTotalQuantity += $myrow['quantity'];
        $SubTotalValue += $myrow['value'];
    }
}
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><td colspan="2"></td>';
echo '<td>' . _('Total For') . ' ' . $DayNames[DayOfWeekFromSQLDate(DateAdd($LastDate, 'd', -1))] . ' ' . DateAdd(ConvertSQLDate($LastDate), 'd', 0) . '</td>';
echo '<td class="number">' . $SubTotalQuantity . '</td>';
echo '<td class="number">' . number_format($SubTotalValue, $_SESSION['Currencies'][$_SESSION['CompanyRecord']['currencydefault']]['DecimalPlaces']) . '</td></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><td colspan="2"></td>';
echo '<td><b>' . 'Total' . '</b></td>';
echo '<td class="number"><b>' . $TotalQuantity . '</b></td>';
echo '<td class="number"><b>' . number_format($TotalValue, $_SESSION['Currencies'][$_SESSION['CompanyRecord']['currencydefault']]['DecimalPlaces']) . '</b></td></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '</table>';
echo '</td>';
echo '<td width="33%" style="text-align: left;vertical-align: top;">';
echo '<table width="100%" class="selection">';
$sql = "SELECT stockmoves.stockid,\n\t\t\t\tstockmaster.description,\n\t\t\t\tsum(-qty*price) AS value\n\t\t\tFROM stockmoves\n\t\t\tLEFT JOIN stockmaster\n\t\t\tON stockmaster.stockid=stockmoves.stockid\n\t\t\tLEFT JOIN stockcategory\n\t\t\tON stockmaster.categoryid=stockcategory.categoryid\n\t\t\tWHERE stockcategory.stocktype='X'\n\t\t\t\tAND stockmoves.trandate='" . FormatDateForSQL($_POST['ReportDate']) . "'\n\t\t\tGROUP BY stockmoves.stockid";
$result = DB_query($sql, $db);
    if ($debug == 1) {
        prnMsg(_('The SQL that returned no rows was') . '<br />' . $sql, 'error');
    }
    include 'includes/footer.inc';
    exit;
}
include 'includes/PDFStarter.php';
/*PDFStarter.php has all the variables for page size and width set up depending on the users default preferences for paper size */
$pdf->addInfo('Title', _('Dispatches After') . $_POST['DaysAcceptable'] . ' ' . _('Day(s) from Requested Delivery Date'));
$pdf->addInfo('Subject', _('Delivery Dates from') . ' ' . $_POST['FromDate'] . ' ' . _('to') . ' ' . $_POST['ToDate']);
$line_height = 12;
$PageNumber = 1;
$TotalDiffs = 0;
include 'includes/PDFDIFOTPageHeader.inc';
while ($myrow = DB_fetch_array($Result)) {
    if (DayOfWeekFromSQLDate($myrow['actualdispatchdate']) == 1) {
        $DaysDiff = $myrow['daydiff'] - 2;
    } else {
        $DaysDiff = $myrow['daydiff'];
    }
    if ($DaysDiff > $_POST['DaysAcceptable']) {
        $LeftOvers = $pdf->addTextWrap($Left_Margin, $YPos, 40, $FontSize, $myrow['orderno'], 'left');
        $LeftOvers = $pdf->addTextWrap($Left_Margin + 40, $YPos, 200, $FontSize, $myrow['stkcode'] . ' - ' . $myrow['description'], 'left');
        $LeftOvers = $pdf->addTextWrap($Left_Margin + 240, $YPos, 50, $FontSize, locale_number_format($myrow['quantity'], $myrow['decimalplaces']), 'right');
        $LeftOvers = $pdf->addTextWrap($Left_Margin + 295, $YPos, 50, $FontSize, $myrow['debtorno'], 'left');
        $LeftOvers = $pdf->addTextWrap($Left_Margin + 345, $YPos, 50, $FontSize, $myrow['branchcode'], 'left');
        $LeftOvers = $pdf->addTextWrap($Left_Margin + 395, $YPos, 50, $FontSize, ConvertSQLDate($myrow['actualdispatchdate']), 'left');
        $LeftOvers = $pdf->addTextWrap($Left_Margin + 445, $YPos, 20, $FontSize, $DaysDiff, 'left');
        $YPos -= $line_height;
        $TotalDiffs++;
        if ($YPos - 2 * $line_height < $Bottom_Margin) {
        $DaySalesArray[DayOfMonthFromSQLDate($DaySalesRow['trandate'])]['Sales'] = $DaySalesRow['salesvalue'];
    } else {
        $DaySalesArray[DayOfMonthFromSQLDate($DaySalesRow['trandate'])]['Sales'] = 0;
    }
    if ($DaySalesRow['salesvalue'] > 0) {
        $DaySalesArray[DayOfMonthFromSQLDate($DaySalesRow['trandate'])]['GPPercent'] = ($DaySalesRow['salesvalue'] - $DaySalesRow['cost']) / $DaySalesRow['salesvalue'];
    } else {
        $DaySalesArray[DayOfMonthFromSQLDate($DaySalesRow['trandate'])]['GPPercent'] = 0;
    }
    $BilledDays++;
    $CumulativeTotalSales += $DaySalesRow['salesvalue'];
    $CumulativeTotalCost += $DaySalesRow['cost'];
}
//end of while loop
echo '<tr>';
$ColumnCounter = DayOfWeekFromSQLDate($StartDateSQL);
for ($i = 0; $i < $ColumnCounter; $i++) {
    echo '<td></td>';
}
$DayNumber = 1;
/*Set up day number headings*/
for ($i = $ColumnCounter; $i <= 6; $i++) {
    echo '<th>' . $DayNumber . '</th>';
    $DayNumber++;
}
echo '</tr><tr>';
for ($i = 0; $i < $ColumnCounter; $i++) {
    echo '<td></td>';
}
$LastDayOfMonth = DayOfMonthFromSQLDate($EndDateSQL);
for ($i = 1; $i <= $LastDayOfMonth; $i++) {
Exemple #5
0
function submit(&$db, &$ChangeDate)
{
    //####SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT_SUBMIT####
    //initialize no input errors
    $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_date($_POST['FromDate'])) {
        $InputError = 1;
        prnMsg(_('Invalid From Date'), 'error');
    }
    if (!is_date($_POST['ToDate'])) {
        $InputError = 1;
        prnMsg(_('Invalid To Date'), 'error');
    }
    if ($inputerror != 1) {
        $formatdate = FormatDateForSQL($_POST['FromDate']);
        echo "</br>Format Date: {$formatdate}</br>";
        $convertdate = ConvertSQLDate($formatdate);
        echo "</br>Convert Date: {$convertdate}</br>";
        $dayofweek = DayOfWeekFromSQLDate($formatdate);
        echo "</br>Day of week: {$dayofweek}</br>";
        //$dateadd = DateAdd($_POST['FromDate'],"d",-3);
        $dateadd = DateAdd($convertdate, "d", -8);
        echo "</br>Date Add: {$dateadd}</br>";
        $dategreater = Date1GreaterThanDate2($_POST['ToDate'], $_POST['FromDate']);
        echo "</br>Date Greater: {$dategreater}</br>";
        $datediff = DateDiff($_POST['ToDate'], $_POST['FromDate'], "d");
        // Date1 minus Date2
        echo "</br>Date Difference: {$datediff}</br>";
        $sql = 'DROP TABLE IF EXISTS mrpcalendar';
        $result = DB_query($sql, $db);
        $sql = 'CREATE TABLE mrpcalendar (
					calendardate date NOT NULL,
					daynumber int(6) NOT NULL,
					manufacturingflag smallint(6) NOT NULL default "1",
					INDEX (daynumber),
					PRIMARY KEY (calendardate))';
        $ErrMsg = _('The SQL to to create passbom failed with the message');
        $result = DB_query($sql, $db, $ErrMsg);
        $i = 0;
        // $daystext used so can get text of day based on the value get from DayOfWeekFromSQLDate of
        // the calendar date. See if that text is in the ExcludeDays array
        $daysText = array(_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'));
        $ExcludeDays = array($_POST['Sunday'], $_POST['Monday'], $_POST['Tuesday'], $_POST['Wednesday'], $_POST['Thursday'], $_POST['Friday'], $_POST['Saturday']);
        $caldate = $_POST['FromDate'];
        for ($i = 0; $i <= $datediff; $i++) {
            $dateadd = FormatDateForSQL(DateAdd($caldate, "d", $i));
            // If the check box for the calendar date's day of week was clicked, set the manufacturing flag to 0
            $dayofweek = DayOfWeekFromSQLDate($dateadd);
            $manuflag = 1;
            foreach ($ExcludeDays as $exday) {
                if ($exday == $daysText[$dayofweek]) {
                    $manuflag = 0;
                }
            }
            // echo "</br>Date: $dateadd Day: $dayofweek";
            $sql = "INSERT INTO mrpcalendar (\n\t\t\t\t\t\tcalendardate,\n\t\t\t\t\t\tdaynumber,\n\t\t\t\t\t\tmanufacturingflag)\n\t\t\t\t\t VALUES ('{$dateadd}',\n\t\t\t\t\t\t\t'1',\n\t\t\t\t\t\t\t'{$manuflag}')";
            $result = DB_query($sql, $db, $ErrMsg);
        }
        // Update daynumber. Set it so non-manufacturing days will have the same daynumber as a valid
        // manufacturing day that precedes it. That way can read the table by the non-manufacturing day,
        // subtract the leadtime from the daynumber, and find the valid manufacturing day with that daynumber.
        $daynumber = 1;
        $sql = 'SELECT * FROM mrpcalendar ORDER BY calendardate';
        $result = DB_query($sql, $db, $ErrMsg);
        while ($myrow = DB_fetch_array($result)) {
            if ($myrow['manufacturingflag'] == "1") {
                $daynumber++;
            }
            $caldate = $myrow['calendardate'];
            $sql = "UPDATE mrpcalendar SET daynumber = '{$daynumber}'\n\t\t\t\t\t\tWHERE calendardate = '{$caldate}'";
            $resultupdate = DB_query($sql, $db, $ErrMsg);
        }
        echo '</br>' . _('Number of days') . ':' . $i . '</br>';
        prnMsg(_("The MRP Calendar has been created"), 'success');
        display($db, $ChangeDate);
    }
    // End of if inputerror != 1
}