Exemple #1
0
function VerifyFwdDate($FwdDate, $i, $Errors)
{
    if (!Is_Date($FwdDate)) {
        $Errors[$i] = InvalidFwdDate;
    }
    return $Errors;
}
             $_SESSION['SuppTrans']->Taxes[$Tax->TaxCalculationOrder]->TaxOvAmount = $_SESSION['SuppTrans']->Taxes[$Tax->TaxCalculationOrder]->TaxRate * $_SESSION['SuppTrans']->OvAmount;
         }
     } else {
         /*Tax being entered manually accept the taxamount entered as is*/
         $_SESSION['SuppTrans']->Taxes[$Tax->TaxCalculationOrder]->TaxOvAmount = filter_number_format($_POST['TaxAmount' . $Tax->TaxCalculationOrder]);
     }
     $TaxTotal += $_SESSION['SuppTrans']->Taxes[$Tax->TaxCalculationOrder]->TaxOvAmount;
 }
 $InputError = False;
 if ($TaxTotal + $_SESSION['SuppTrans']->OvAmount <= 0) {
     $InputError = True;
     prnMsg(_('The credit note as entered cannot be processed because the total amount of the credit note is less than or equal to 0') . '. ' . _('Credit notes are expected to be entered as positive amounts to credit'), 'warn');
 } elseif (mb_strlen($_SESSION['SuppTrans']->SuppReference) < 1) {
     $InputError = True;
     prnMsg(_('The credit note as entered cannot be processed because the there is no suppliers credit note number or reference entered') . '. ' . _('The supplier credit note number must be entered'), 'error');
 } elseif (!Is_Date($_SESSION['SuppTrans']->TranDate)) {
     $InputError = True;
     prnMsg(_('The credit note as entered cannot be processed because the date entered is not in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
 } elseif (DateDiff(Date($_SESSION['DefaultDateFormat']), $_SESSION['SuppTrans']->TranDate, 'd') < 0) {
     $InputError = True;
     prnMsg(_('The credit note as entered cannot be processed because the date is after today') . '. ' . _('Purchase credit notes are expected to have a date prior to or today'), 'error');
 } elseif ($_SESSION['SuppTrans']->ExRate <= 0) {
     $InputError = True;
     prnMsg(_('The credit note as entered cannot be processed because the exchange rate for the credit note has been entered as a negative or zero number') . '. ' . _('The exchange rate is expected to show how many of the suppliers currency there are in 1 of the local currency'), 'warn');
 } elseif ($_SESSION['SuppTrans']->OvAmount < round($TotalShiptValue + $TotalGLValue + $TotalAssetValue + $TotalGRNValue, $_SESSION['SuppTrans']->CurrDecimalPlaces)) {
     prnMsg(_('The credit note total as entered is less than the sum of the shipment charges') . ', ' . _('the general ledger entries (if any) and the charges for goods received') . '. ' . _('There must be a mistake somewhere') . ', ' . _('the credit note as entered will not be processed'), 'error');
     $InputError = True;
 } else {
     /* SQL to process the postings for purchase credit note */
     /*Start an SQL transaction */
     DB_Txn_Begin($db);
 if (!Is_Date($_POST['StartDate'])) {
     $InputError = 1;
     prnMsg(_('The date this price is to take effect from must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
 }
 if (!Is_Date($_POST['EndDate'])) {
     $InputError = 1;
     prnMsg(_('The date this price is be in effect to must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
     if (Date1GreaterThanDate2($_POST['StartDate'], $_POST['EndDate'])) {
         $InputError = 1;
         prnMsg(_('The end date is expected to be after the start date, enter an end date after the start date for this price'), 'error');
     }
 }
 if (Is_Date($_POST['EndDate'])) {
     $SQLEndDate = FormatDateForSQL($_POST['EndDate']);
 }
 if (Is_Date($_POST['StartDate'])) {
     $SQLStartDate = FormatDateForSQL($_POST['StartDate']);
 }
 $sql = "SELECT COUNT(salestype)\r\n\t\t\t\tFROM pricematrix\r\n\t\t\tWHERE stockid='" . $StockID . "'\r\n\t\t\tAND startdate='" . $SQLStartDate . "'\r\n\t\t\tAND enddate='" . $SQLEndDate . "'\r\n\t\t        AND salestype='" . $_POST['TypeAbbrev'] . "'\r\n\t\t\tAND currabrev='" . $_POST['currabrev'] . "'\r\n\t\t\tAND quantitybreak='" . $_POST['quantitybreak'] . "'";
 $result = DB_query($sql);
 $myrow = DB_fetch_row($result);
 if ($myrow[0] != 0 and !isset($_POST['OldTypeAbbrev']) and !isset($_POST['OldCurrAbrev'])) {
     prnMsg(_('This price has already been entered. To change it you should edit it'), 'warn');
     $InputError = 1;
 }
 if (isset($_POST['OldTypeAbbrev']) and isset($_POST['OldCurrAbrev']) and mb_strlen($StockID) > 1 and $InputError != 1) {
     /* Update existing prices */
     $sql = "UPDATE pricematrix SET \r\n\t\t\t\t\tsalestype='" . $_POST['SalesType'] . "',\r\n\t\t\t\t\tcurrabrev='" . $_POST['CurrAbrev'] . "',\r\n\t\t\t\t\tprice='" . filter_number_format($_POST['Price']) . "',\r\n\t\t\t\t\tstartdate='" . $SQLStartDate . "',\r\n\t\t\t\t\tenddate='" . $SQLEndDate . "',\r\n\t\t\t\t\tquantitybreak='" . filter_number_format($_POST['QuantityBreak']) . "'\r\n\t\t\t\tWHERE stockid='" . $StockID . "'\r\n\t\t\t\tAND startdate='" . $_POST['OldStartDate'] . "'\r\n\t\t\t\tAND enddate='" . $_POST['OldEndDate'] . "'\r\n\t\t\t\tAND salestype='" . $_POST['OldTypeAbbrev'] . "'\r\n\t\t\t\tAND currabrev='" . $_POST['OldCurrAbrev'] . "'\r\n\t\t\t\tAND quantitybreak='" . filter_number_format($_POST['OldQuantityBreak']) . "'";
     $ErrMsg = _('Could not be update the existing prices');
     $result = DB_query($sql, $ErrMsg);
     ReSequenceEffectiveDates($StockID, $_POST['SalesType'], $_POST['CurrAbrev'], $_POST['QuantityBreak'], $db);
 $pdf->addInfo('Title', _('Price Listing Report'));
 $pdf->addInfo('Subject', _('Price List'));
 $PageNumber = 1;
 $line_height = 12;
 /*Now figure out the inventory data to report for the category range under review */
 if ($_POST['CustomerSpecials'] == _('Customer Special Prices Only')) {
     if ($_SESSION['CustomerID'] == '') {
         $title = _('Special price List - No Customer Selected');
         include 'includes/header.inc';
         echo '<br />';
         prnMsg(_('The customer must first be selected from the select customer link') . '. ' . _('Re-run the price list once the customer has been selected'));
         echo '<br /><br /><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">' . _('Back') . '</a>';
         include 'includes/footer.inc';
         exit;
     }
     if (!Is_Date($_POST['EffectiveDate'])) {
         $title = _('Special price List - No Customer Selected');
         include 'includes/header.inc';
         prnMsg(_('The effective date must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
         echo '<br /><br /><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">' . _('Back') . '</a>';
         include 'includes/footer.inc';
         exit;
     }
     $SQL = "SELECT debtorsmaster.name,\n\t\t\t\tdebtorsmaster.salestype\n\t\t\t\tFROM debtorsmaster\n\t\t\t\tWHERE debtorno = '" . $_SESSION['CustomerID'] . "'";
     $CustNameResult = DB_query($SQL, $db);
     $CustNameRow = DB_fetch_row($CustNameResult);
     $CustomerName = $CustNameRow[0];
     $SalesType = $CustNameRow[1];
     $SQL = "SELECT prices.typeabbrev,\n  \t\t\t\t\t\tprices.stockid,\n  \t\t\t\t\t\tstockmaster.description,\n  \t\t\t\t\t\tstockmaster.longdescription,\n  \t\t\t\t\t\tprices.currabrev,\n  \t\t\t\t\t\tprices.startdate,\n  \t\t\t\t\t\tprices.enddate,\n  \t\t\t\t\t\tprices.price,\n  \t\t\t\t\t\tstockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost AS standardcost,\n  \t\t\t\t\t\tstockmaster.categoryid,\n  \t\t\t\t\t\tstockcategory.categorydescription,\n  \t\t\t\t\t\tprices.debtorno,\n  \t\t\t\t\t\tprices.branchcode,\n  \t\t\t\t\t\tcustbranch.brname,\n  \t\t\t\t\t\tcurrencies.decimalplaces\n\t\t\t\t\t\tFROM stockmaster INNER JOIN\tstockcategory\n\t\t\t\t\t\tON stockmaster.categoryid=stockcategory.categoryid\n\t\t\t\t\t\tINNER JOIN prices\n\t\t\t\t\t\tON stockmaster.stockid=prices.stockid\n\t\t\t\t\t\tINNER JOIN currencies\n\t\t\t\t\t\tON prices.currabrev=currencies.currabrev\n                        LEFT JOIN custbranch\n\t\t\t\t\t\tON prices.debtorno=custbranch.debtorno\n\t\t\t\t\t\tAND prices.branchcode=custbranch.branchcode\n\t\t\t\t\t\tWHERE prices.typeabbrev = '" . $SalesType . "'\n\t\t\t\t\t\tAND stockmaster.categoryid >= '" . $_POST['FromCriteria'] . "'\n\t\t\t\t\t\tAND stockmaster.categoryid <= '" . $_POST['ToCriteria'] . "'\n\t\t\t\t\t\tAND prices.debtorno='" . $_SESSION['CustomerID'] . "'\n\t\t\t\t\t\tAND prices.startdate<='" . FormatDateForSQL($_POST['EffectiveDate']) . "'\n\t\t\t\t\t\tAND (prices.enddate='0000-00-00' OR prices.enddate >'" . FormatDateForSQL($_POST['EffectiveDate']) . "')\n\t\t\t\t\t\tORDER BY prices.currabrev,\n\t\t\t\t\t\t\tstockmaster.categoryid,\n\t\t\t\t\t\t\tstockmaster.stockid,\n\t\t\t\t\t\t\tprices.startdate";
 } else {
     /* the sales type list only */
     $InputError = 1;
     $msg = _('The price entered must be numeric');
 }
 if ($_POST['Branch'] != '') {
     $sql = "SELECT custbranch.branchcode\n\t\t\t\t\t\tFROM custbranch\n\t\t\t\t\t\tWHERE custbranch.debtorno='" . $_SESSION['CustomerID'] . "'\n\t\t\t\t\t\tAND custbranch.branchcode='" . $_POST['Branch'] . "'";
     $result = DB_query($sql, $db);
     if (DB_num_rows($result) == 0) {
         $InputError = 1;
         $msg = _('The branch code entered is not currently defined');
     }
 }
 if (!Is_Date($_POST['StartDate'])) {
     $InputError = 1;
     $msg = _('The date this price is to take effect from must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'];
 }
 if (!Is_Date($_POST['EndDate']) and $_POST['EndDate'] != '') {
     //EndDate can also be blank for default prices
     $InputError = 1;
     $msg = _('The date this price is be in effect to must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'];
 }
 if (Date1GreaterThanDate2($_POST['StartDate'], $_POST['EndDate']) and $_POST['EndDate'] != '') {
     $InputError = 1;
     $msg = _('The end date is expected to be after the start date, enter an end date after the start date for this price');
 }
 if (Date1GreaterThanDate2(Date($_SESSION['DefaultDateFormat']), $_POST['EndDate']) and $_POST['EndDate'] != '') {
     $InputError = 1;
     $msg = _('The end date is expected to be after today. There is no point entering a new price where the effective date is before today!');
 }
 if (isset($_POST['Editing']) and $_POST['Editing'] == 'Yes' and strlen($Item) > 1 and $InputError != 1) {
     //editing an existing price
     $sql = "UPDATE prices SET typeabbrev='" . $SalesType . "',\n\t\t                        currabrev='" . $CurrCode . "',\n\t\t\t\t\t\t\t\tprice='" . filter_currency_input($_POST['Price']) . "',\n\t\t\t\t\t\t\t\tunits='" . $_POST['Units'] . "',\n\t\t\t\t\t\t\t\tconversionfactor='" . filter_number_input($_POST['ConversionFactor']) . "',\n\t\t\t\t\t\t\t\tdecimalplaces='" . round($_POST['DecimalPlaces'], 0) . "',\n\t\t\t\t\t\t\t\tbranchcode='" . $_POST['Branch'] . "',\n\t\t\t\t\t\t\t\tstartdate='" . FormatDateForSQL($_POST['StartDate']) . "',\n\t\t\t\t\t\t\t\tenddate='" . FormatDateForSQL($_POST['EndDate']) . "'\n\t\t\t\tWHERE prices.stockid='" . $Item . "'\n\t\t\t\tAND prices.typeabbrev='" . $SalesType . "'\n\t\t\t\tAND prices.currabrev='" . $CurrCode . "'\n\t\t\t\tAND prices.startdate='" . $_POST['OldStartDate'] . "'\n\t\t\t\tAND prices.enddate='" . $_POST['OldEndDate'] . "'\n\t\t\t\tAND prices.debtorno='" . $_SESSION['CustomerID'] . "'";
function VerifyLastPaidDate($ClientSince, $i, $Errors)
{
    if (!Is_Date($ClientSince)) {
        $Errors[$i] = InvalidLastPaidDate;
    }
    return $Errors;
}
function update(&$db, &$ChangeDate)
{
    // Change manufacturing flag for a date. The value "1" means the date is a manufacturing date.
    // After change the flag, re-calculate the daynumber for all dates.
    $InputError = 0;
    $CalDate = FormatDateForSQL($ChangeDate);
    $sql = "SELECT COUNT(*) FROM mrpcalendar\n\t\t  WHERE calendardate='{$CalDate}'\n\t\t  GROUP BY calendardate";
    $result = DB_query($sql);
    $myrow = DB_fetch_row($result);
    if ($myrow[0] < 1 || !Is_Date($ChangeDate)) {
        $InputError = 1;
        prnMsg(_('Invalid Change Date'), 'error');
    }
    if ($InputError == 1) {
        ShowInputForm($db, $ChangeDate);
        return;
    }
    $sql = "SELECT mrpcalendar.* FROM mrpcalendar WHERE calendardate='{$CalDate}'";
    $result = DB_query($sql);
    $myrow = DB_fetch_row($result);
    $newmanufacturingflag = 0;
    if ($myrow[2] == 0) {
        $newmanufacturingflag = 1;
    }
    $sql = "UPDATE mrpcalendar SET manufacturingflag = '" . $newmanufacturingflag . "'\n\t\t\tWHERE calendardate = '" . $CalDate . "'";
    $ErrMsg = _('Cannot update the MRP Calendar');
    $resultupdate = DB_query($sql, $ErrMsg);
    prnMsg(_('The MRP calendar record for') . ' ' . $ChangeDate . ' ' . _('has been updated'), 'success');
    unset($ChangeDate);
    ShowInputForm($db, $ChangeDate);
    // Have to update daynumber any time change a date from or to a manufacturing date
    // 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, $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);
    }
    // End of while
}
     }
 }
 /*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, locale_number_format($holdcost, $_SESSION['CompanyRecord']['decimalplaces']), 'right', 0, $fill);
 $pdf->addTextWrap(260, $YPos, 50, $FontSize, locale_number_format($totalpartqty, $holddecimalplaces), 'right', 0, $fill);
 $pdf->addTextWrap(310, $YPos, 60, $FontSize, locale_number_format($totalpartcost, $_SESSION['CompanyRecord']['decimalplaces']), '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');
 }
Exemple #9
0
/* $Id: PDFLowGP.php 6165 2013-07-30 10:30:51Z daintree $*/
include 'includes/session.inc';
if (!isset($_POST['FromCat']) or $_POST['FromCat'] == '') {
    $Title = _('Low Gross Profit Sales');
}
$debug = 0;
if (isset($_POST['PrintPDF'])) {
    include 'includes/PDFStarter.php';
    $pdf->addInfo('Title', _('Low Gross Profit Sales'));
    $pdf->addInfo('Subject', _('Low Gross Profit Sales'));
    $FontSize = 10;
    $PageNumber = 1;
    $line_height = 12;
    $Title = _('Low GP sales') . ' - ' . _('Problem Report');
    if (!Is_Date($_POST['FromDate']) or !Is_Date($_POST['ToDate'])) {
        include 'includes/header.inc';
        prnMsg(_('The dates entered must be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
        include 'includes/footer.inc';
        exit;
    }
    /*Now figure out the data to report for the category range under review */
    $SQL = "SELECT stockmaster.categoryid,\n\t\t\t\t\tstockmaster.stockid,\n\t\t\t\t\tstockmoves.transno,\n\t\t\t\t\tstockmoves.trandate,\n\t\t\t\t\tsystypes.typename,\n\t\t\t\t\tstockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost as unitcost,\n\t\t\t\t\tstockmoves.qty,\n\t\t\t\t\tstockmoves.debtorno,\n\t\t\t\t\tstockmoves.branchcode,\n\t\t\t\t\tstockmoves.price*(1-stockmoves.discountpercent) as sellingprice,\n\t\t\t\t\t(stockmoves.price*(1-stockmoves.discountpercent)) - (stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost) AS gp,\n\t\t\t\t\tdebtorsmaster.name\n\t\t\t\tFROM stockmaster INNER JOIN stockmoves\n\t\t\t\t\tON stockmaster.stockid=stockmoves.stockid\n\t\t\t\tINNER JOIN systypes\n\t\t\t\t\tON stockmoves.type=systypes.typeid\n\t\t\t\tINNER JOIN debtorsmaster\n\t\t\t\t\tON stockmoves.debtorno=debtorsmaster.debtorno\n\t\t\t\tWHERE stockmoves.trandate >= '" . FormatDateForSQL($_POST['FromDate']) . "'\n\t\t\t\tAND stockmoves.trandate <= '" . FormatDateForSQL($_POST['ToDate']) . "'\n\t\t\t\tAND ((stockmoves.price*(1-stockmoves.discountpercent)) - (stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost))/(stockmoves.price*(1-stockmoves.discountpercent)) <=" . $_POST['GPMin'] / 100 . "\n\t\t\t\tORDER BY stockmaster.stockid";
    $LowGPSalesResult = DB_query($SQL, $db, '', '', false, false);
    if (DB_error_no($db) != 0) {
        include 'includes/header.inc';
        prnMsg(_('The low GP items could not be retrieved by the SQL because') . ' - ' . DB_error_msg($db), 'error');
        echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>';
        if ($debug == 1) {
            echo '<br />' . $SQL;
        }
<?php

/* $Id: Z_ReverseSuppPaymentRun.php 6941 2014-10-26 23:18:08Z daintree $*/
/* Script to delete all supplier payments entered or created from a payment run on a specified day
 */
include 'includes/session.inc';
$Title = _('Reverse and Delete Supplier Payments');
include 'includes/header.inc';
/*Only do deletions if user hits the button */
if (isset($_POST['RevPayts']) and Is_Date($_POST['PaytDate']) == 1) {
    $SQLTranDate = FormatDateForSQL($_POST['PaytDate']);
    $SQL = "SELECT id,\n\t\t\ttransno,\n\t\t\tsupplierno,\n\t\t\tovamount,\n\t\t\tsuppreference,\n\t\t\trate\n\t\tFROM supptrans\n\t\tWHERE supptrans.type = 22\n\t\tAND trandate = '" . $SQLTranDate . "'";
    $Result = DB_query($SQL);
    prnMsg(_('The number of payments that will be deleted is') . ' :' . DB_num_rows($Result), 'info');
    while ($Payment = DB_fetch_array($Result)) {
        prnMsg(_('Deleting payment number') . ' ' . $Payment['transno'] . ' ' . _('to supplier code') . ' ' . $Payment['supplierno'] . ' ' . _('for an amount of') . ' ' . $Payment['ovamount'], 'info');
        $SQL = "SELECT supptrans.transno,\n\t\t\t\tsupptrans.type,\n\t\t\t\tsuppallocs.amt\n\t\t\tFROM supptrans INNER JOIN suppallocs\n\t\t\tON supptrans.id=suppallocs.transid_allocto\n\t\t\tWHERE suppallocs.transid_allocfrom = " . $Payment['id'];
        $AllocsResult = DB_query($SQL);
        while ($Alloc = DB_fetch_array($AllocsResult)) {
            $SQL = "UPDATE supptrans SET settled=0,\n\t\t\t\t\t\t\t\t\t\talloc=alloc-" . $Alloc['amt'] . ",\n\t\t\t\t\t\t\t\t\t\tdiffonexch = diffonexch - ((" . $Alloc['amt'] . "/rate ) - " . $Alloc['amt'] / $Payment['rate'] . ")\n\t\t\t\t\tWHERE supptrans.type='" . $Alloc['type'] . "'\n\t\t\t\t\tAND transno='" . $Alloc['transno'] . "'";
            $ErrMsg = _('The update to the suppliers charges that were settled by the payment failed because');
            $UpdResult = DB_query($SQL, $ErrMsg);
        }
        prnMsg(' ... ' . _('reversed the allocations'), 'info');
        $SQL = "DELETE FROM suppallocs WHERE transid_allocfrom='" . $Payment['id'] . "'";
        $DelResult = DB_query($SQL);
        prnMsg(' ... ' . _('deleted the SuppAllocs records'), 'info');
        $SQL = "DELETE FROM supptrans\n\t\t\tWHERE type=22\n\t\t\tAND transno='" . $Payment['transno'] . "'\n\t\t\tAND trandate='" . $SQLTranDate . "'";
        $DelResult = DB_query($SQL);
        prnMsg(_('Deleted the SuppTran record'), 'success');
        $SQL = "DELETE FROM gltrans WHERE typeno='" . $Payment['transno'] . "' AND type=22";
    $result = DB_query($sql, $ErrMsg);
    prnMsg(_('Successfully deleted recurring sales order template number') . ' ' . $_POST['ExistingRecurrOrderNo'], 'success');
    echo '<p><a href="' . $RootPath . '/SelectRecurringSalesOrder.php">' . _('Select A Recurring Sales Order Template') . '</a>';
    unset($_SESSION['Items' . $identifier]->LineItems);
    unset($_SESSION['Items' . $identifier]);
    include 'includes/footer.inc';
    exit;
}
if (isset($_POST['Process'])) {
    $Result = DB_Txn_Begin();
    $InputErrors = 0;
    if (!Is_Date($_POST['StartDate'])) {
        $InputErrors = 1;
        prnMsg(_('The last recurrence or start date of this recurring order must be a valid date in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
    }
    if (!Is_Date($_POST['StopDate'])) {
        $InputErrors = 1;
        prnMsg(_('The end date of this recurring order must be a valid date in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
    }
    if (Date1GreaterThanDate2($_POST['StartDate'], $_POST['StopDate'])) {
        $InputErrors = 1;
        prnMsg(_('The end date of this recurring order must be after the start date'), 'error');
    }
    if (isset($_POST['MakeRecurringOrder']) and $_POST['Quotation'] == 1) {
        $InputErrors = 1;
        prnMsg(_('A recurring order cannot be made from a quotation'), 'error');
    }
    if ($InputErrors == 0) {
        /*Error checks above all passed ok so lets go*/
        if ($NewRecurringOrder == 'Yes') {
            /* finally write the recurring order header to the database and then the line details*/
include 'includes/session.inc';
$title = _('Depreciation Journal Entry');
include 'includes/header.inc';
include 'includes/SQL_CommonFunctions.inc';
/*Get the last period depreciation (depn is transtype =44) was posted for */
$result = DB_query("SELECT periods.lastdate_in_period,\n\t\t\t\t\t\t\tmax(fixedassettrans.periodno)\n\t\t\t\t\tFROM fixedassettrans INNER JOIN periods\n\t\t\t\t\tON fixedassettrans.periodno=periods.periodno\n\t\t\t\t\tWHERE transtype=44\n\t\t\t\t\tGROUP BY periods.lastdate_in_period\n\t\t\t\t\tORDER BY periods.lastdate_in_period DESC", $db);
$LastDepnRun = DB_fetch_row($result);
$AllowUserEnteredProcessDate = true;
if (DB_num_rows($result) == 0) {
    //then depn has never been run yet?
    /*in this case default depreciation calc to the last day of last month - and allow user to select a period */
    if (!isset($_POST['ProcessDate'])) {
        $_POST['ProcessDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, date('m'), 0, date('Y')));
    } else {
        //ProcessDate is set - make sure it is on the last day of the month selected
        if (!Is_Date($_POST['ProcessDate'])) {
            prnMsg(_('The date is expected to be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
            $InputError = true;
        } else {
            $_POST['ProcessDate'] = LastDayOfMonth($_POST['ProcessDate']);
        }
    }
} else {
    //depn calc has been run previously
    $AllowUserEnteredProcessDate = false;
    $_POST['ProcessDate'] = LastDayOfMonth(DateAdd(ConvertSQLDate($LastDepnRun[0]), 'd', 28));
}
/* Get list of assets for journal */
$sql = "SELECT fixedassets.assetid,\n\t\t\tfixedassets.description,\n\t\t\tfixedassets.depntype,\n\t\t\tfixedassets.depnrate,\n\t\t\tfixedassets.datepurchased,\n\t\t\tfixedassetcategories.accumdepnact,\n\t\t\tfixedassetcategories.depnact,\n\t\t\tfixedassetcategories.categorydescription,\n\t\t\tSUM(CASE WHEN fixedassettrans.fixedassettranstype='cost' THEN fixedassettrans.amount ELSE 0 END) AS costtotal,\n\t\t\tSUM(CASE WHEN fixedassettrans.fixedassettranstype='depn' THEN fixedassettrans.amount ELSE 0 END) AS depnbfwd\n\t\tFROM fixedassets\n\t\tINNER JOIN fixedassetcategories\n\t\t\tON fixedassets.assetcategoryid=fixedassetcategories.categoryid\n\t\tINNER JOIN fixedassettrans\n\t\t\tON fixedassets.assetid=fixedassettrans.assetid\n\t\tWHERE fixedassettrans.transdate<='" . FormatDateForSQL($_POST['ProcessDate']) . "'\n\t\tGROUP BY fixedassets.assetid,\n\t\t\tfixedassets.description,\n\t\t\tfixedassets.depntype,\n\t\t\tfixedassets.depnrate,\n\t\t\tfixedassets.datepurchased,\n\t\t\tfixedassetcategories.accumdepnact,\n\t\t\tfixedassetcategories.depnact,\n\t\t\tfixedassetcategories.categorydescription\n\t\tORDER BY assetcategoryid, assetid";
$AssetsResult = DB_query($sql, $db);
$InputError = false;
Exemple #13
0
        }
    }
    /*Make sure the same receipt is not double processed by a page refresh */
    $_POST['Cancel'] = 1;
}
if (isset($_POST['Cancel'])) {
    unset($_POST['GLAmount']);
    unset($_POST['GLNarrative']);
    unset($_POST['GLCode']);
    unset($_POST['AccountName']);
}
/*set up the form whatever */
if (!isset($_POST['DatePaid'])) {
    $_POST['DatePaid'] = '';
}
if (isset($_POST['DatePaid']) and ($_POST['DatePaid'] == "" or !Is_Date($_SESSION['PaymentDetail']->DatePaid))) {
    $_POST['DatePaid'] = Date($_SESSION['DefaultDateFormat']);
    $_SESSION['PaymentDetail']->DatePaid = $_POST['DatePaid'];
}
if ($_SESSION['PaymentDetail']->Currency == '' and $_SESSION['PaymentDetail']->SupplierID == '') {
    $_SESSION['PaymentDetail']->Currency = $_SESSION['CompanyRecord']['currencydefault'];
}
if (isset($_POST['BankAccount']) and $_POST['BankAccount'] != '') {
    $SQL = "SELECT bankaccountname\n\t\t\tFROM bankaccounts,\n\t\t\t\tchartmaster\n\t\tWHERE bankaccounts.accountcode= chartmaster.accountcode\n\t\tAND chartmaster.accountcode='" . $_POST['BankAccount'] . "'";
    $ErrMsg = _('The bank account name cannot be retrieved because');
    $DbgMsg = _('SQL used to retrieve the bank account name was');
    $result = DB_query($SQL, $db, $ErrMsg, $DbgMsg);
    if (DB_num_rows($result) == 1) {
        $myrow = DB_fetch_row($result);
        $_SESSION['PaymentDetail']->BankAccountName = $myrow[0];
        unset($result);
Exemple #14
0
function submitcsv(&$db, $PartNumber, $PartNumberOp, $SupplierId, $SupplierIdOp, $SupplierName, $SupplierNameOp, $SaveSummaryType)
{
    //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');
    }
    # Add more to WHERE statement, if user entered something for the part number,supplierid, name
    $WherePart = ' ';
    if (mb_strlen($PartNumber) > 0 && $PartNumberOp == 'LIKE') {
        $PartNumber = $PartNumber . '%';
    } else {
        $PartNumberOp = '=';
    }
    if (mb_strlen($PartNumber) > 0) {
        $WherePart = " AND purchorderdetails.itemcode " . $PartNumberOp . " '" . $PartNumber . "'  ";
    } else {
        $WherePart = ' ';
    }
    $WhereSupplierID = ' ';
    if ($SupplierIdOp == 'LIKE') {
        $SupplierId = $SupplierId . '%';
    } else {
        $SupplierIdOp = '=';
    }
    if (mb_strlen($SupplierId) > 0) {
        $WhereSupplierID = " AND purchorders.supplierno " . $SupplierIdOp . " '" . $SupplierId . "'  ";
    } else {
        $WhereSupplierID = ' ';
    }
    $WhereSupplierName = ' ';
    if (mb_strlen($SupplierName) > 0 && $SupplierNameOp == 'LIKE') {
        $SupplierName = $SupplierName . '%';
    } else {
        $SupplierNameOp = '=';
    }
    if (mb_strlen($SupplierName) > 0) {
        $WhereSupplierName = " AND suppliers.suppname " . $SupplierNameOp . " '" . $SupplierName . "'  ";
    } else {
        $WhereSupplierName = ' ';
    }
    if (mb_strlen($_POST['OrderNo']) > 0) {
        $WhereOrderNo = " AND purchorderdetails.orderno = '" . $_POST['OrderNo'] . "'  ";
    } else {
        $WhereOrderNo = ' ';
    }
    $WhereLineStatus = ' ';
    # Had to use IF statement instead of comparing 'linestatus' to $_POST['LineStatus']
    #in WHERE clause because the WHERE clause didn't recognize
    # that had used the IF statement to create a field called linestatus
    if ($_POST['LineStatus'] != 'All') {
        if ($_POST['DateType'] == 'Order') {
            $WhereLineStatus = " AND IF(purchorderdetails.quantityord = purchorderdetails.qtyinvoiced ||\n\t\t\t  purchorderdetails.completed = 1,'Completed','Open') = '" . $_POST['LineStatus'] . "'";
        } else {
            $WhereLineStatus = " AND IF(grns.qtyrecd - grns.quantityinv <> 0,'Open','Completed') = '" . $_POST['LineStatus'] . "'";
        }
    }
    $WhereCategory = ' ';
    if ($_POST['Category'] != 'All') {
        $WhereCategory = " AND stockmaster.categoryid = '" . $_POST['Category'] . "'";
    }
    if ($InputError != 1) {
        $FromDate = FormatDateForSQL($_POST['FromDate']);
        $ToDate = FormatDateForSQL($_POST['ToDate']);
        if ($_POST['ReportType'] == 'Detail') {
            if ($_POST['DateType'] == 'Order') {
                $sql = "SELECT purchorderdetails.orderno,\n\t\t\t\t\t\t\t   purchorderdetails.itemcode,\n\t\t\t\t\t\t\t   purchorderdetails.deliverydate,\n\t\t\t\t\t\t\t   purchorders.supplierno,\n\t\t\t\t\t\t\t   purchorders.orddate,\n\t\t\t\t\t\t\t   purchorderdetails.quantityord,\n\t\t\t\t\t\t\t   purchorderdetails.qtyinvoiced,\n\t\t\t\t\t\t\t   (purchorderdetails.quantityord * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t   (purchorderdetails.quantityord * purchorderdetails.stdcostunit) as extcost,\n\t\t\t\t\t\t\t   IF(purchorderdetails.quantityord = purchorderdetails.qtyinvoiced ||\n\t\t\t\t\t\t\t\t  purchorderdetails.completed = 1,'Completed','Open') as linestatus,\n\t\t\t\t\t\t\t   suppliers.suppname,\n\t\t\t\t\t\t\t   stockmaster.decimalplaces,\n\t\t\t\t\t\t\t   stockmaster.description\n\t\t\t\t\t\t\t   FROM purchorderdetails\n\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\tWHERE purchorders.orddate >='{$FromDate}'\n\t\t\t\t\t\t AND purchorders.orddate <='{$ToDate}'\n\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\tORDER BY " . $_POST['SortBy'];
            } else {
                // Selects by delivery date from grns
                $sql = "SELECT purchorderdetails.orderno,\n\t\t\t\t\t\t\t   purchorderdetails.itemcode,\n\t\t\t\t\t\t\t   grns.deliverydate,\n\t\t\t\t\t\t\t   purchorders.supplierno,\n\t\t\t\t\t\t\t   purchorders.orddate,\n\t\t\t\t\t\t\t   grns.qtyrecd as quantityord,\n\t\t\t\t\t\t\t   grns.quantityinv as qtyinvoiced,\n\t\t\t\t\t\t\t   (grns.qtyrecd * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t   (grns.qtyrecd * grns.stdcostunit) as extcost,\n\t\t\t\t\t\t\t   IF(grns.qtyrecd - grns.quantityinv <> 0,'Open','Completed') as linestatus,\n\t\t\t\t\t\t\t   suppliers.suppname,\n\t\t\t\t\t\t\t   stockmaster.decimalplaces,\n\t\t\t\t\t\t\t   stockmaster.description\n\t\t\t\t\t\t\t   FROM grns\n\t\t\t\t\t\tLEFT JOIN purchorderdetails ON grns.podetailitem = purchorderdetails.podetailitem\n\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\tWHERE grns.deliverydate >='{$FromDate}'\n\t\t\t\t\t\t AND grns.deliverydate <='{$ToDate}'\n\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\tORDER BY " . $_POST['SortBy'];
            }
        } else {
            // sql for Summary report
            $orderby = $_POST['SummaryType'];
            // The following is because the 'extprice' summary is a special case - with the other
            // summaries, you group and order on the same field; with 'extprice', you are actually
            // grouping on the stkcode and ordering by extprice descending
            if ($_POST['SummaryType'] == 'extprice') {
                $_POST['SummaryType'] = 'itemcode';
                $orderby = 'extprice DESC';
            }
            if ($_POST['DateType'] == 'Order') {
                if ($_POST['SummaryType'] == 'extprice' || $_POST['SummaryType'] == 'itemcode') {
                    $sql = "SELECT purchorderdetails.itemcode,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.qtyinvoiced) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   stockmaster.decimalplaces,\n\t\t\t\t\t\t\t\t   stockmaster.description\n\t\t\t\t\t\t\t\t   FROM purchorderdetails\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE purchorders.orddate >='{$FromDate}'\n\t\t\t\t\t\t\t AND purchorders.orddate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ",stockmaster.decimalplaces,\n\t\t\t\t\t\t\t  stockmaster.description\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'orderno') {
                    $sql = "SELECT purchorderdetails.orderno,\n\t\t\t\t\t\t\t\t   purchorders.supplierno,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.qtyinvoiced) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   suppliers.suppname\n\t\t\t\t\t\t\t\t   FROM purchorderdetails\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE purchorders.orddate >='{$FromDate}'\n\t\t\t\t\t\t\t AND purchorders.orddate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ",purchorders.supplierno,\n\t\t\t\t\t\t\t  suppliers.suppname\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'supplierno' || $_POST['SummaryType'] == 'suppname,suppliers.supplierid') {
                    $sql = "SELECT purchorders.supplierno,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.qtyinvoiced) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   suppliers.suppname\n\t\t\t\t\t\t\t\t   FROM purchorderdetails\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE purchorders.orddate >='{$FromDate}'\n\t\t\t\t\t\t\t AND purchorders.orddate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ",purchorders.supplierno,\n\t\t\t\t\t\t\t  suppliers.suppname\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'month') {
                    $sql = "SELECT EXTRACT(YEAR_MONTH from purchorders.orddate) as month,\n\t\t\t\t\t\t\t\t   CONCAT(MONTHNAME(purchorders.orddate),' ',YEAR(purchorders.orddate)) as monthname,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.qtyinvoiced) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.stdcostunit) as extcost\n\t\t\t\t\t\t\t\t   FROM purchorderdetails\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE purchorders.orddate >='{$FromDate}'\n\t\t\t\t\t\t\t AND purchorders.orddate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ", monthname\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'categoryid') {
                    $sql = "SELECT SUM(purchorderdetails.quantityord) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.qtyinvoiced) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(purchorderdetails.quantityord * purchorderdetails.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   stockmaster.categoryid,\n\t\t\t\t\t\t\t\t   stockcategory.categorydescription\n\t\t\t\t\t\t\t\t   FROM purchorderdetails\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE purchorders.orddate >='{$FromDate}'\n\t\t\t\t\t\t\t AND purchorders.orddate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ", categorydescription\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                }
            } else {
                // Selects by delivery date from grns
                if ($_POST['SummaryType'] == 'extprice' || $_POST['SummaryType'] == 'itemcode') {
                    $sql = "SELECT purchorderdetails.itemcode,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(grns.quantityinv) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * grns.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   stockmaster.description\n\t\t\t\t\t\t\t\t   FROM grns\n\t\t\t\t\t\t\tLEFT JOIN purchorderdetails ON grns.podetailitem = purchorderdetails.podetailitem\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tLEFT JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE grns.deliverydate >='{$FromDate}'\n\t\t\t\t\t\t\t AND grns.deliverydate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ", stockmaster.description\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'orderno') {
                    $sql = "SELECT purchorderdetails.orderno,\n\t\t\t\t\t\t\t\t   purchorders.supplierno,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(grns.quantityinv) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * grns.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   suppliers.suppname\n\t\t\t\t\t\t\t\t   FROM grns\n\t\t\t\t\t\t\tLEFT JOIN purchorderdetails ON grns.podetailitem = purchorderdetails.podetailitem\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE grns.deliverydate >='{$FromDate}'\n\t\t\t\t\t\t\t AND grns.deliverydate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ", purchorders.supplierno,\n\t\t\t\t\t\t\t   suppliers.suppname\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'supplierno' || $_POST['SummaryType'] == 'suppname,suppliers.supplierid') {
                    $sql = "SELECT purchorders.supplierno,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(grns.quantityinv) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * grns.stdcostunit) as extcost,\n\t\t\t\t\t\t\t\t   suppliers.suppname\n\t\t\t\t\t\t\t\t   FROM grns\n\t\t\t\t\t\t\tLEFT JOIN purchorderdetails ON grns.podetailitem = purchorderdetails.podetailitem\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE grns.deliverydate >='{$FromDate}'\n\t\t\t\t\t\t\t AND grns.deliverydate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ", purchorders.supplierno,\n\t\t\t\t\t\t\t   suppliers.suppname\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'month') {
                    $sql = "SELECT EXTRACT(YEAR_MONTH from purchorders.orddate) as month,\n\t\t\t\t\t\t\t\t   CONCAT(MONTHNAME(purchorders.orddate),' ',YEAR(purchorders.orddate)) as monthname,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(grns.quantityinv) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * grns.stdcostunit) as extcost\n\t\t\t\t\t\t\t\t   FROM grns\n\t\t\t\t\t\t\tLEFT JOIN purchorderdetails ON grns.podetailitem = purchorderdetails.podetailitem\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE grns.deliverydate >='{$FromDate}'\n\t\t\t\t\t\t\t AND grns.deliverydate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ",monthname\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                } elseif ($_POST['SummaryType'] == 'categoryid') {
                    $sql = "SELECT stockmaster.categoryid,\n\t\t\t\t\t\t\t\t   stockcategory.categorydescription,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd) as quantityord,\n\t\t\t\t\t\t\t\t   SUM(grns.quantityinv) as qtyinvoiced,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * purchorderdetails.unitprice) as extprice,\n\t\t\t\t\t\t\t\t   SUM(grns.qtyrecd * grns.stdcostunit) as extcost\n\t\t\t\t\t\t\t\t   FROM grns\n\t\t\t\t\t\t\tLEFT JOIN purchorderdetails ON grns.podetailitem = purchorderdetails.podetailitem\n\t\t\t\t\t\t\tINNER JOIN purchorders ON purchorders.orderno=purchorderdetails.orderno\n\t\t\t\t\t\t\tINNER JOIN suppliers ON purchorders.supplierno = suppliers.supplierid\n\t\t\t\t\t\t\tLEFT JOIN stockmaster ON purchorderdetails.itemcode = stockmaster.stockid\n\t\t\t\t\t\t\tINNER JOIN stockcategory ON stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE grns.deliverydate >='{$FromDate}'\n\t\t\t\t\t\t\t AND grns.deliverydate <='{$ToDate}'\n\t\t\t\t\t\t\t{$WherePart}\n\t\t\t\t\t\t\t{$WhereSupplierID}\n\t\t\t\t\t\t\t{$WhereSupplierName}\n\t\t\t\t\t\t\t{$WhereOrderNo}\n\t\t\t\t\t\t\t{$WhereLineStatus}\n\t\t\t\t\t\t\t{$WhereCategory}\n\t\t\t\t\t\t\tGROUP BY " . $_POST['SummaryType'] . ",categorydescription\n\t\t\t\t\t\t\tORDER BY " . $orderby;
                }
            }
        }
        // End of if ($_POST['ReportType']
        //echo "<br/>$sql<br/>";
        $ErrMsg = _('The SQL to find the parts selected failed with the message');
        $result = DB_query($sql, $db, $ErrMsg);
        $ctr = 0;
        $TotalQty = 0;
        $TotalExtCost = 0;
        $TotalExtPrice = 0;
        $TotalInvQty = 0;
        $FileName = $_SESSION['reports_dir'] . '/POReport.csv';
        $FileHandle = fopen($FileName, 'w');
        // Create array for summary type to display in header. Access it with $SaveSummaryType
        $Summary_Array['orderno'] = _('Order Number');
        $Summary_Array['itemcode'] = _('Part Number');
        $Summary_Array['extprice'] = _('Extended Price');
        $Summary_Array['supplierno'] = _('Customer Number');
        $Summary_Array['suppname'] = _('Customer Name');
        $Summary_Array['month'] = _('Month');
        $Summary_Array['categoryid'] = _('Stock Category');
        // Create array for sort for detail report to display in header
        $Detail_Array['purchorderdetails.orderno'] = _('Order Number');
        $Detail_Array['purchorderdetails.itemcode'] = _('Part Number');
        $Detail_Array['suppliers.supplierid,purchorderdetails.orderno'] = _('Supplier Number');
        $Detail_Array['suppliers.suppname,suppliers.supplierid,purchorderdetails.orderno'] = _('Supplier Name');
        // Display Header info
        if ($_POST['ReportType'] == 'Summary') {
            $SortBy_Display = $Summary_Array[$SaveSummaryType];
        } else {
            $SortBy_Display = $Detail_Array[$_POST['SortBy']];
        }
        fprintf($FileHandle, '"' . _('Purchase Order Report') . '","' . $_POST['ReportType'] . ' ' . _('By') . ' ' . $SortBy_Display . "\n");
        fprintf($FileHandle, '"' . _('Date Type') . '","' . $_POST['DateType'] . '"' . "\n");
        fprintf($FileHandle, '"' . _('Date Range') . '","' . $_POST['FromDate'] . _(' To ') . $_POST['ToDate'] . '"' . "\n");
        if (mb_strlen(trim($PartNumber)) > 0) {
            fprintf($FileHandle, '"' . _('Part Number') . '","' . $_POST['PartNumberOp'] . ' ' . $_POST['PartNumber'] . '"' . "\n");
        }
        if (mb_strlen(trim($_POST['SupplierId'])) > 0) {
            fprintf($FileHandle, '"' . _('Supplier Number') . '","' . $_POST['SupplierIdOp'] . ' ' . $_POST['SupplierId'] . '"' . "\n");
        }
        if (mb_strlen(trim($_POST['SupplierName'])) > 0) {
            fprintf($FileHandle, '"' . _('Supplier Name') . '","' . $_POST['SupplierNameOp'] . ' ' . $_POST['SupplierName'] . '"' . "\n");
        }
        fprintf($FileHandle, '"' . _('Line Item Status') . '","' . $_POST['LineStatus'] . '"' . "\n");
        fprintf($FileHandle, '"' . _('Stock Category') . '","' . $_POST['Category'] . '"' . "\n");
        if ($_POST['ReportType'] == 'Detail') {
            if ($_POST['DateType'] == 'Order') {
                fprintf($FileHandle, '"%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s"' . "\n", _('Order No'), _('Part Number'), _('Order Date'), _('Supplier No'), _('Supplier Name'), _('Order Qty'), _('Extended Cost'), _('Extended Price'), _('Invoiced Qty'), _('Line Status'), _('Item Due'), _('Part Description'));
                $linectr = 0;
                while ($myrow = DB_fetch_array($result)) {
                    $linectr++;
                    // Detail for both DateType of Order
                    fprintf($FileHandle, '"%s","%s","%s","%s","%s",%s,%s,%s,%s,"%s","%s","%s"' . "\n", $myrow['orderno'], $myrow['itemcode'], ConvertSQLDate($myrow['orddate']), $myrow['supplierno'], $myrow['suppname'], locale_number_format($myrow['quantityord'], $myrow['decimalplaces']), locale_number_format($myrow['extcost'], 2), locale_number_format($myrow['extprice'], 2), locale_number_format($myrow['qtyinvoiced'], $myrow['decimalplaces']), $myrow['linestatus'], ConvertSQLDate($myrow['deliverydate']), $myrow['description']);
                    $LastDecimalPlaces = $myrow['decimalplaces'];
                    $TotalQty += $myrow['quantityord'];
                    $TotalExtCost += $myrow['extcost'];
                    $TotalExtPrice += $myrow['extprice'];
                    $TotalInvQty += $myrow['qtyinvoiced'];
                }
                //END WHILE LIST LOOP
                // Print totals
                fprintf($FileHandle, '"%s","%s","%s","%s","%s",%s,%s,%s,%s,"%s","%s"' . "\n", 'Totals', _('Lines - ') . $linectr, ' ', ' ', ' ', locale_number_format($TotalQty, 2), locale_number_format($TotalExtCost, 2), locale_number_format($TotalExtPrice, 2), locale_number_format($TotalInvQty, 2), ' ', ' ');
            } else {
                // Header for Date Type of Delivery Date
                fprintf($FileHandle, '"%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s"' . "\n", _('Order No'), _('Part Number'), _('Order Date'), _('Supplier No'), _('Supplier Name'), _('Received'), _('Extended Cost'), _('Extended Price'), _('Invoiced Qty'), _('Line Status'), _('Delivered'), _('Part Description'));
                $linectr = 0;
                while ($myrow = DB_fetch_array($result)) {
                    $linectr++;
                    // Detail for both DateType of Ship
                    // In sql, had to alias grns.qtyrecd as quantityord so could use same name here
                    fprintf($FileHandle, '"%s","%s","%s","%s","%s",%s,%s,%s,%s,"%s","%s","%s"' . "\n", $myrow['orderno'], $myrow['itemcode'], ConvertSQLDate($myrow['orddate']), $myrow['supplierno'], $myrow['suppname'], locale_number_format($myrow['quantityord'], $myrow['decimalplaces']), locale_number_format($myrow['extcost'], 2), locale_number_format($myrow['extprice'], 2), locale_number_format($myrow['qtyinvoiced'], $myrow['decimalplaces']), $myrow['linestatus'], ConvertSQLDate($myrow['deliverydate']), $myrow['description']);
                    $LastDecimalPlaces = $myrow['decimalplaces'];
                    $TotalQty += $myrow['quantityord'];
                    $TotalExtCost += $myrow['extcost'];
                    $TotalExtPrice += $myrow['extprice'];
                    $TotalInvQty += $myrow['qtyinvoiced'];
                }
                //END WHILE LIST LOOP
                // Print totals
                fprintf($FileHandle, '"%s","%s","%s","%s","%s",%s,%s,%s,%s,"%s","%s"' . "\n", 'Totals', _('Lines - ') . $linectr, ' ', ' ', ' ', locale_number_format($TotalQty, $LastDecimalPlaces), locale_number_format($TotalExtCost, 2), locale_number_format($TotalExtPrice, 2), locale_number_format($TotalInvQty, $LastDecimalPlaces), " ", " ");
            }
        } else {
            // Print summary stuff
            $summarytype = $_POST['SummaryType'];
            // For SummaryType 'suppname' had to add supplierid to it for the GROUP BY in the sql,
            // but have to take it away for $myrow[$summarytype] to be valid
            // Set up description based on the Summary Type
            if ($summarytype == 'suppname,suppliers.supplierid') {
                $summarytype = 'suppname';
                $description = 'supplierno';
                $summaryheader = _('Supplier Name');
                $descriptionheader = _('Supplier Number');
            }
            if ($summarytype == 'itemcode' || $summarytype == 'extprice') {
                $description = 'description';
                $summaryheader = _('Part Number');
                $descriptionheader = _('Part Description');
            }
            if ($summarytype == 'supplierno') {
                $description = 'suppname';
                $summaryheader = _('Supplier Number');
                $descriptionheader = _('Supplier Name');
            }
            if ($summarytype == 'orderno') {
                $description = 'supplierno';
                $summaryheader = _('Order Number');
                $descriptionheader = _('Supplier Number');
            }
            if ($summarytype == 'categoryid') {
                $description = 'categorydescription';
                $summaryheader = _('Stock Category');
                $descriptionheader = _('Category Description');
            }
            $summarydesc = $summaryheader;
            if ($orderby == 'extprice DESC') {
                $summarydesc = _('Extended Price');
            }
            if ($summarytype == 'month') {
                $description = 'monthname';
                $summaryheader = _('Month');
                $descriptionheader = _('Month');
            }
            fprintf($FileHandle, '"%s","%s","%s","%s","%s","%s"' . "\n", _($summaryheader), _($descriptionheader), _('Quantity'), _('Extended Cost'), _('Extended Price'), _('Invoiced Qty'));
            $suppname = ' ';
            $linectr = 0;
            while ($myrow = DB_fetch_array($result)) {
                $linectr++;
                if ($summarytype == 'orderno') {
                    $suppname = $myrow['suppname'];
                }
                fprintf($FileHandle, '"%s","%s",%s,%s,%s,%s,"%s"' . "\n", $myrow[$summarytype], $myrow[$description], locale_number_format($myrow['quantityord'], $myrow['decimalplaces']), locale_number_format($myrow['extcost'], 2), locale_number_format($myrow['extprice'], 2), locale_number_format($myrow['qtyinvoiced'], $myrow['decimalplaces']), $suppname);
                print '<br/>';
                $LastDecimalPlaces = $myrow['decimalplaces'];
                $TotalQty += $myrow['quantityord'];
                $TotalExtCost += $myrow['extcost'];
                $TotalExtPrice += $myrow['extprice'];
                $TotalInvQty += $myrow['qtyinvoiced'];
            }
            //END WHILE LIST LOOP
            // Print totals
            fprintf($FileHandle, '"%s","%s",%s,%s,%s,%s,"%s"' . "\n", 'Totals', _('Lines - ') . $linectr, locale_number_format($TotalQty, $LastDecimalPlaces), locale_number_format($TotalExtCost, 2), locale_number_format($TotalExtPrice, 2), locale_number_format($TotalInvQty, $LastDecimalPlaces), ' ');
        }
        // End of if ($_POST['ReportType']
        fclose($FileHandle);
        echo '<div class="centre"><p>' . _('The report has been exported as a csv file.') . '</p>';
        echo '<p><a href="' . $FileName . '">' . _('click here') . '</a> ' . _('to view the file') . '</div></p>';
    }
    // End of if inputerror != 1
}
                } else {
                    $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverto, \n\t\t\t\t\t\tsalesorders.deliverydate, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\t\tFROM salesorders, \n\t\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\t\tcustbranch \n\t\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\t\tAND salesorders.orddate >= '{$DateAfterCriteria}' \n\t\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\t\tGROUP BY salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverydate,  \n\t\t\t\t\t\tsalesorders.deliverto\n\t\t\t\t\tORDER BY salesorders.orderno";
                }
            }
            //end selected customer
        }
        //end not order number selected
        $SalesOrdersResult = DB_query($SQL, $db);
        if (DB_error_no($db) != 0) {
            echo '<br>' . _('No orders were returned by the SQL because') . ' ' . DB_error_msg($db);
            echo "<br>{$SQL}";
        }
    }
}
//end of which button clicked options
if (!isset($_POST['OrdersAfterDate']) or $_POST['OrdersAfterDate'] == '' or !Is_Date($_POST['OrdersAfterDate'])) {
    $_POST['OrdersAfterDate'] = Date($_SESSION['DefaultDateFormat'], Mktime(0, 0, 0, Date('m') - 2, Date('d'), Date('Y')));
}
echo "<table>";
if (!isset($OrderNumber) or $OrderNumber == '') {
    echo '<tr><td>' . _('Order Number') . ':</td><td>' . "<input type='text' name='OrderNumber' maxlength =8 size=9></td><td>" . _('for all orders placed after') . ": </td><td><input type='text' name='OrdersAfterDate' maxlength =10 size=11 value=" . $_POST['OrdersAfterDate'] . "></td><td>" . "<input type='submit' name='SearchOrders' value='" . _('Search Orders') . "'></td></tr>";
    echo '<tr><td>' . _('Customer Ref') . ':</td><td>' . "<input type='text' name='CustomerRef' maxlength =8 size=9></td>\n\t\t\t<td></td><td colspan=2><input type='checkbox' " . $ShowChecked . " name='completed' />" . _('Show Completed orders only') . "</td></tr>";
}
echo '</table>';
if (!isset($SelectedStockItem)) {
    $SQL = 'SELECT categoryid, categorydescription FROM stockcategory ORDER BY categorydescription';
    $result1 = DB_query($SQL, $db);
    echo '<hr>';
    echo '<div class="centre"><font size=1>' . _('To search for sales orders for a specific part use the part selection facilities below') . '   </font>';
    echo '<input type="submit" name="SearchParts" value="' . _('Search Parts Now') . '">';
    if (count($_SESSION['AllowedPageSecurityTokens']) > 1) {
 } elseif ($_POST['CostType'] == 'OtherPriceList') {
     echo _('Price List') . ' ' . $_POST['BasePriceList'];
 } else {
     echo $CostingBasis;
 }
 if ($_POST['PriceList'] == '0') {
     echo '<br />' . _('The price list/sales type to be updated must be selected first');
     include 'includes/footer.inc';
     exit;
 }
 if ($_POST['CurrCode'] == '0') {
     echo '<br />' . _('The currency of prices to be updated must be selected first');
     include 'includes/footer.inc';
     exit;
 }
 if (Is_Date($_POST['PriceEndDate'])) {
     $SQLEndDate = FormatDateForSQL($_POST['PriceEndDate']);
 } else {
     $SQLEndDate = '0000-00-00';
 }
 $sql = "SELECT stockid,\n\t\t\t\t\t\tmaterialcost+labourcost+overheadcost AS cost\n\t\t\t\tFROM stockmaster\n\t\t\t\tWHERE categoryid>='" . $_POST['StkCatFrom'] . "'\n\t\t\t\tAND categoryid <='" . $_POST['StkCatTo'] . "'";
 $PartsResult = DB_query($sql);
 $IncrementPercentage = filter_number_format($_POST['IncreasePercent'] / 100);
 $CurrenciesResult = DB_query("SELECT rate FROM currencies WHERE currabrev='" . $_POST['CurrCode'] . "'");
 $CurrencyRow = DB_fetch_row($CurrenciesResult);
 $CurrencyRate = $CurrencyRow[0];
 while ($myrow = DB_fetch_array($PartsResult)) {
     //Figure out the cost to use
     if ($_POST['CostType'] == 'PreferredSupplier') {
         $sql = "SELECT purchdata.price/purchdata.conversionfactor/currencies.rate AS cost\n\t\t\t\t\t\t\tFROM purchdata INNER JOIN suppliers\n\t\t\t\t\t\t\t\tON purchdata.supplierno=suppliers.supplierid\n\t\t\t\t\t\t\t\tINNER JOIN currencies\n\t\t\t\t\t\t\t\tON suppliers.currcode=currencies.currabrev\n\t\t\t\t\t\t\tWHERE purchdata.preferred=1 AND purchdata.stockid='" . $myrow['stockid'] . "'";
         $ErrMsg = _('Could not get the supplier purchasing information for a preferred supplier for the item') . ' ' . $myrow['stockid'];
<?php

include 'includes/session.inc';
include 'includes/SQL_CommonFunctions.inc';
$InputError = 0;
if (isset($_POST['FromDate']) and !Is_Date($_POST['FromDate'])) {
    $msg = _('The date from must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
    $InputError = 1;
}
if (isset($_POST['ToDate']) and !Is_Date($_POST['ToDate'])) {
    $msg = _('The date to must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
    $InputError = 1;
}
if (!isset($_POST['FromDate']) or !isset($_POST['ToDate']) or $InputError == 1) {
    $Title = _('Delivery Differences Report');
    include 'includes/header.inc';
    echo '<div class="centre"><p class="page_title_text noPrint" ><img src="' . $RootPath . '/css/' . $Theme . '/images/transactions.png" title="' . $Title . '" alt="" />' . ' ' . _('Delivery Differences Report') . '</p></div>';
    echo '<form onSubmit="return VerifyForm(this);" method="post" class="noPrint" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
    echo '<div>';
    echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
    echo '<table class="selection">
			<tr>
				<td>' . _('Enter the date from which variances between orders and deliveries are to be listed') . ':</td>
				<td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="FromDate" autofocus="autofocus" required="required" minlength="1" maxlength="10" size="10" value="' . Date($_SESSION['DefaultDateFormat'], Mktime(0, 0, 0, Date('m') - 1, 0, Date('y'))) . '" /></td>
			</tr>';
    echo '<tr>
			<td>' . _('Enter the date to which variances between orders and deliveries are to be listed') . ':</td>
			<td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '"  name="ToDate" required="required" minlength="1" maxlength="10" size="10" value="' . Date($_SESSION['DefaultDateFormat']) . '" /></td>
		</tr>';
    echo '<tr>
			<td>' . _('Inventory Category') . '</td>
echo '</select></td>
	</tr>';
echo '</table>
	<br />
	<div class="centre">
		<input tabindex="6" type="submit" name="ShowTransactions" value="' . _('Show selected') . ' ' . $TypeName . '" />';
if (isset($_POST['BankAccount'])) {
    echo '<p><a href="' . $RootPath . '/BankReconciliation.php?Account=' . $_POST['BankAccount'] . '">' . _('Show reconciliation') . '</a></p>';
}
echo '</div>';
$InputError = 0;
if (!Is_Date($_POST['BeforeDate'])) {
    $InputError = 1;
    prnMsg(_('The date entered for the field to show') . ' ' . $TypeName . ' ' . _('before') . ', ' . _('is not entered in a recognised date format') . '. ' . _('Entry is expected in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
}
if (!Is_Date($_POST['AfterDate'])) {
    $InputError = 1;
    prnMsg(_('The date entered for the field to show') . ' ' . $Type . ' ' . _('after') . ', ' . _('is not entered in a recognised date format') . '. ' . _('Entry is expected in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
}
if ($InputError != 1 and isset($_POST['BankAccount']) and $_POST['BankAccount'] != '' and isset($_POST['ShowTransactions'])) {
    $SQLBeforeDate = FormatDateForSQL($_POST['BeforeDate']);
    $SQLAfterDate = FormatDateForSQL($_POST['AfterDate']);
    $BankResult = DB_query("SELECT decimalplaces,\n\t\t\t\t\t\t\t\t\tcurrcode\n\t\t\t\t\t\t\tFROM bankaccounts INNER JOIN currencies\n\t\t\t\t\t\t\tON bankaccounts.currcode=currencies.currabrev\n\t\t\t\t\t\t\tWHERE accountcode='" . $_POST['BankAccount'] . "'", $db);
    $BankRow = DB_fetch_array($BankResult);
    $CurrDecimalPlaces = $BankRow['decimalplaces'];
    $CurrCode = $BankRow['currcode'];
    if ($_POST['Ostg_or_All'] == 'All') {
        if ($Type == 'Payments') {
            $sql = "SELECT banktransid,\n\t\t\t\t\t\t\tref,\n\t\t\t\t\t\t\tamountcleared,\n\t\t\t\t\t\t\ttransdate,\n\t\t\t\t\t\t\tamount/exrate as amt,\n\t\t\t\t\t\t\tbanktranstype\n\t\t\t\t\tFROM banktrans\n\t\t\t\t\tWHERE amount < 0\n\t\t\t\t\t\tAND transdate >= '" . $SQLAfterDate . "'\n\t\t\t\t\t\tAND transdate <= '" . $SQLBeforeDate . "'\n\t\t\t\t\t\tAND bankact='" . $_POST['BankAccount'] . "'\n\t\t\t\t\tORDER BY transdate";
        } else {
            /* Type must == Receipts */
            } else {
                echo '<td class="number">' . locale_money_format($OrderLine->Price, $_SESSION['Items' . $identifier]->DefaultCurrency) . '</td>';
                echo '<input type="hidden" name="Price_' . $OrderLine->LineNumber . '" value="' . $OrderLine->Price . '" />';
                echo '<td class="number">' . locale_number_format($OrderLine->DiscountPercent * 100, 2) . '%</td>';
                echo '<input type="hidden" name="Discount_' . $OrderLine->LineNumber . '" value="' . locale_number_format($OrderLine->DiscountPercent * 100, 2) . '" />';
                echo '<td class="number">' . locale_number_format($OrderLine->GPPercent, 2) . '%</td>';
                echo '<input type="hidden" name="GPPercent_' . $OrderLine->LineNumber . '" value="' . locale_number_format($OrderLine->GPPercent, 2) . '" />';
            }
            if ($_SESSION['Items' . $identifier]->Some_Already_Delivered($OrderLine->LineNumber)) {
                $RemTxt = _('Clear Remaining');
            } else {
                $RemTxt = _('Delete');
            }
            echo '</td><td class="number">' . $DisplayLineTotal . '</td>';
            $LineDueDate = $OrderLine->ItemDue;
            if (!Is_Date($OrderLine->ItemDue)) {
                $LineDueDate = DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', $_SESSION['Items' . $identifier]->DeliveryDays);
                $_SESSION['Items' . $identifier]->LineItems[$OrderLine->LineNumber]->ItemDue = $LineDueDate;
            }
            echo '<td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="ItemDue_' . $OrderLine->LineNumber . '" size="10" maxlength="10" value="' . $LineDueDate . '" /></td>';
            echo '<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?identifier=' . $identifier . '&amp;Delete=' . $OrderLine->LineNumber . '" onclick="return confirm(\'' . _('Are You Sure?') . '\');">' . $RemTxt . '</a></td>
				<td>' . $LineComments . '</td></tr>';
            if ($_SESSION['AllowOrderLineItemNarrative'] == 1) {
                echo $RowStarter;
                echo '<td colspan="10">' . _('Narrative') . ':
					<textarea name="Narrative_' . $OrderLine->LineNumber . '" cols="100%" rows="1">' . stripslashes(AddCarriageReturns($OrderLine->Narrative)) . '</textarea>
						<br /></td></tr>';
            } else {
                echo '<input type="hidden" name="Narrative" value="" />';
            }
            $PropertySQL = "SELECT label,\n\t\t\t\t\t\t\t\tcontroltype,\n\t\t\t\t\t\t\t\tstkcatpropid,\n\t\t\t\t\t\t\t\tnumericvalue\n\t\t\t\t\t\t\tFROM stockcatproperties\n\t\t\t\t\t\t\tLEFT JOIN stockmaster\n\t\t\t\t\t\t\tON stockcatproperties.categoryid=stockmaster.categoryid\n\t\t\t\t\t\t\tWHERE stockmaster.stockid='" . $OrderLine->StockID . "'\n\t\t\t\t\t\t\t\tAND reqatsalesorder=1";
     unset($SelectedStockItem);
 }
 if (isset($SampleID) and $SampleID != '') {
     if (!is_numeric($SampleID)) {
         prnMsg(_('The Sample ID entered') . ' <U>' . _('MUST') . '</U> ' . _('be numeric'), 'error');
         unset($SampleID);
     } else {
         echo _('Sample ID') . ' - ' . $SampleID;
     }
 }
 if (!Is_Date($_POST['FromDate'])) {
     $InputError = 1;
     prnMsg(_('Invalid From Date'), 'error');
     $_POST['FromDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, Date('m'), Date('d') - 15, Date('Y')));
 }
 if (!Is_Date($_POST['ToDate'])) {
     $InputError = 1;
     prnMsg(_('Invalid To Date'), 'error');
     $_POST['ToDate'] = Date($_SESSION['DefaultDateFormat']);
 }
 if (isset($_POST['SearchParts'])) {
     if ($_POST['Keywords'] and $_POST['StockCode']) {
         prnMsg(_('Stock description keywords have been used in preference to the Stock code extract entered'), 'info');
     }
     if ($_POST['Keywords']) {
         //insert wildcard characters in spaces
         $SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
         $SQL = "SELECT stockmaster.stockid,\n\t\t\t\t\tstockmaster.description,\n\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\tSUM(locstock.quantity) as qoh,\n\t\t\t\t\tstockmaster.units,\n\t\t\t\tFROM stockmaster INNER JOIN locstock\n\t\t\t\tON stockmaster.stockid = locstock.stockid\n\t\t\t\tINNER JOIN locationusers ON locationusers.loccode = locstock.loccode\n\t\t\t\t\t\tAND locationusers.userid='" . $_SESSION['UserID'] . "'\n\t\t\t\t\t\tAND locationusers.canview=1\n\t\t\t\tWHERE stockmaster.description " . LIKE . " '" . $SearchString . "'\n\t\t\t\tAND stockmaster.categoryid='" . $_POST['StockCat'] . "'\n\t\t\t\tGROUP BY stockmaster.stockid,\n\t\t\t\t\tstockmaster.description,\n\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\tstockmaster.units\n\t\t\t\tORDER BY stockmaster.stockid";
     } elseif ($_POST['StockCode']) {
         $SQL = "SELECT stockmaster.stockid,\n\t\t\t\t\tstockmaster.description,\n\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\tSUM(locstock.quantity) AS qoh,\n\t\t\t\t\tstockmaster.units\n\t\t\t\tFROM stockmaster INNER JOIN locstock\n\t\t\t\t\tON stockmaster.stockid = locstock.stockid\n\t\t\t\tINNER JOIN locationusers ON locationusers.loccode = locstock.loccode\n\t\t\t\t\t\tAND locationusers.userid='" . $_SESSION['UserID'] . "'\n\t\t\t\t\t\tAND locationusers.canview=1\n\t\t\t\tWHERE stockmaster.stockid " . LIKE . " '%" . $_POST['StockCode'] . "%'\n\t\t\t\tAND stockmaster.categoryid='" . $_POST['StockCat'] . "'\n\t\t\t\tGROUP BY stockmaster.stockid,\n\t\t\t\t\tstockmaster.description,\n\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\tstockmaster.units\n\t\t\t\tORDER BY stockmaster.stockid";
     } elseif (!$_POST['StockCode'] and !$_POST['Keywords']) {
Exemple #21
0
        $SQL = "INSERT INTO gltrans (type,\n\t\t\t\t\t\t\t\t\ttypeno,\n\t\t\t\t\t\t\t\t\ttrandate,\n\t\t\t\t\t\t\t\t\tperiodno,\n\t\t\t\t\t\t\t\t\taccount,\n\t\t\t\t\t\t\t\t\tnarrative,\n\t\t\t\t\t\t\t\t\tamount)\n\t\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t\t25,\n\t\t\t\t\t\t\t\t\t'" . $_GET['GRNNo'] . "',\n\t\t\t\t\t\t\t\t\t'" . $GRN['deliverydate'] . "',\n\t\t\t\t\t\t\t\t\t'" . $PeriodNo . "',\n\t\t\t\t\t\t\t\t\t'" . $_SESSION['CompanyRecord']['grnact'] . "', '" . _('GRN Reversal PO') . ': ' . $GRN['orderno'] . " " . $_POST['SupplierID'] . " - " . $GRN['itemcode'] . "-" . $GRN['itemdescription'] . " x " . $QtyToReverse . " @ " . locale_number_format($GRN['stdcostunit'], $GRN['decimalplaces']) . "',\n\t\t\t\t\t\t\t\t\t'" . $GRN['stdcostunit'] * $QtyToReverse . "'\n\t\t\t\t\t\t\t\t)";
        $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GRN suspense side of the GL posting could not be inserted because');
        $DbgMsg = _('The following SQL to insert the GRN Suspense GLTrans record was used');
        $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
    }
    /* end of if GL and stock integrated*/
    $Result = DB_Txn_Commit($db);
    echo '<br />' . _('GRN number') . ' ' . $_GET['GRNNo'] . ' ' . _('for') . ' ' . $QtyToReverse . ' x ' . $GRN['itemcode'] . ' - ' . $GRN['itemdescription'] . ' ' . _('has been reversed') . '<br />';
    unset($_GET['GRNNo']);
    // to ensure it cant be done again!!
    echo '<a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">' . _('Select another GRN to Reverse') . '</a>';
    /*end of Process Goods Received Reversal entry */
} else {
    echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
    echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
    if (!isset($_POST['RecdAfterDate']) or !Is_Date($_POST['RecdAfterDate'])) {
        $_POST['RecdAfterDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, Date('m') - 3, Date('d'), Date('Y')));
    }
    echo '<table class="selection"><tr>';
    echo '<input type="hidden" name="SupplierID" value="' . $_POST['SupplierID'] . '" />';
    echo '<input type="hidden" name="SuppName" value="' . $_POST['SuppName'] . '" />';
    echo '<td>' . _('Show all goods received after') . ': </td>
		<td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="RecdAfterDate" value="' . $_POST['RecdAfterDate'] . '" maxlength="10" size="10" /></td>
			</tr>';
    echo '</table>';
    echo '<br /><div class="centre"><button type="submit" name="ShowGRNS">' . _('Show Outstanding Goods Received') . '</button></div>';
    if (isset($_POST['ShowGRNS'])) {
        $sql = "SELECT grnno,\n\t\t\t\t\t\titemcode,\n\t\t\t\t\t\titemdescription,\n\t\t\t\t\t\tdeliverydate,\n\t\t\t\t\t\tqtyrecd,\n\t\t\t\t\t\tquantityinv,\n\t\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\t\tqtyrecd-quantityinv AS qtytoreverse\n\t\t\t\t\tFROM grns\n\t\t\t\t\tLEFT JOIN stockmaster\n\t\t\t\t\t\tON grns.itemcode=stockmaster.stockid\n\t\t\t\t\tWHERE grns.supplierid = '" . $_POST['SupplierID'] . "'\n\t\t\t\t\t\tAND (grns.qtyrecd-grns.quantityinv) >0";
        $ErrMsg = _('An error occurred in the attempt to get the outstanding GRNs for') . ' ' . $_POST['SuppName'] . '. ' . _('The message was') . ':';
        $DbgMsg = _('The SQL that failed was') . ':';
        $result = DB_query($sql, $db, $ErrMsg, $DbgMsg);
<?php

/* $Id: PDFPeriodStockTransListing.php 4307 2010-12-22 16:06:03Z tim_schofield $*/
include 'includes/SQL_CommonFunctions.inc';
include 'includes/session.inc';
$InputError = 0;
if (isset($_POST['FromDate']) and !Is_Date($_POST['FromDate'])) {
    $msg = _('The date must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
    $InputError = 1;
    unset($_POST['FromDate']);
}
if (!isset($_POST['FromDate'])) {
    $Title = _('Stock Transaction Listing');
    include 'includes/header.inc';
    echo '<div class="centre">
			<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/transactions.png" title="' . $Title . '" alt="" />' . ' ' . _('Stock Transaction Listing') . '</p>
		</div>';
    if ($InputError == 1) {
        prnMsg($msg, 'error');
    }
    echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">
		<div>
		<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
		<table class="selection">
		<tr>
			<td>' . _('Enter the date from which the transactions are to be listed') . ':</td>
			<td><input type="text" required="required" autofocus="autofocus" name="FromDate" maxlength="10" size="10" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" value="' . Date($_SESSION['DefaultDateFormat']) . '" /></td>
		</tr>
		<tr>
			<td>' . _('Enter the date to which the transactions are to be listed') . ':</td>
			<td><input type="text" required="required" name="ToDate" maxlength="10" size="10" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" value="' . Date($_SESSION['DefaultDateFormat']) . '" /></td>
Exemple #23
0
 /*Inputs from the form directly without selecting a stock item from the search */
 $AllowUpdate = true;
 /*always assume the best */
 if (!is_numeric(filter_number_format($_POST['Qty']))) {
     $AllowUpdate = false;
     prnMsg(_('Cannot Enter this order line') . '<br />' . _('The quantity of the order item must be numeric'), 'error');
 }
 if (filter_number_format($_POST['Qty']) < 0) {
     $AllowUpdate = false;
     prnMsg(_('Cannot Enter this order line') . '<br />' . _('The quantity of the ordered item entered must be a positive amount'), 'error');
 }
 if (!is_numeric(filter_number_format($_POST['Price']))) {
     $AllowUpdate = false;
     prnMsg(_('Cannot Enter this order line') . '<br />' . _('The price entered must be numeric'), 'error');
 }
 if (!Is_Date($_POST['ReqDelDate'])) {
     $AllowUpdate = False;
     prnMsg(_('Cannot Enter this order line') . '</b><br />' . _('The date entered must be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
 }
 /*It's not a stock item */
 /*need to check GL Code is valid if GLLink is active */
 if ($_SESSION['PO' . $identifier]->GLLink == 1) {
     $sql = "SELECT accountname\n\t\t\t\tFROM chartmaster\n\t\t\t\tWHERE accountcode ='" . $_POST['GLCode'] . "'";
     $ErrMsg = _('The account details for') . ' ' . $_POST['GLCode'] . ' ' . _('could not be retrieved because');
     $DbgMsg = _('The SQL used to retrieve the details of the account, but failed was');
     $GLValidResult = DB_query($sql, $db, $ErrMsg, $DbgMsg, false, false);
     if (DB_error_no($db) != 0) {
         $AllowUpdate = false;
         prnMsg(_('The validation process for the GL Code entered could not be executed because') . ' ' . DB_error_msg($db), 'error');
         if ($debug == 1) {
             prnMsg(_('The SQL used to validate the code entered was') . ' ' . $sql, 'error');
Exemple #24
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 mrpdemandtype FROM mrpdemandtypes\n\t\t\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 stockid FROM stockmaster\n\t\t\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 stockid FROM mrpdemands\n\t\t\tWHERE stockid='" . $StockID . "'\n\t\t\t\tAND mrpdemandtype='" . $_POST['MRPDemandtype'] . "'\n\t\t\t\tAND duedate='" . $FormatedDuedate . "'\n\t\t\t\tAND demandid <> '" . $DemandID . "'";
    $result = DB_query($sql, $db);
    if (DB_num_rows($result) > 0) {
        $InputError = 1;
        prnMsg(_('Record already exists for part number/demand type/date'), 'error');
    }
    if ($InputError != 1) {
        $sql = "SELECT COUNT(*) FROM mrpdemands\n\t\t\t\t   WHERE demandid='" . $DemandID . "'\n\t\t\t\t   GROUP BY 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(mb_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(mb_strtoupper($_POST['MRPDemandtype'])) . "',\n\t\t\t\t\t\t\t'" . $_POST['Quantity'] . "',\n\t\t\t\t\t\t\t'" . $FormatedDuedate . "'\n\t\t\t\t\t\t)";
            $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');
        echo '<br />';
        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);
}
 		echo "<br>You should enter the suburb in the box provided. Orders cannot be accepted without a valid suburb being entered.<br>";
 	}
 
 */
 // Check the date is OK
 if (isset($_POST['DeliveryDate']) and !Is_Date($_POST['DeliveryDate'])) {
     $InputErrors = 1;
     prnMsg(_('An invalid date entry was made') . '. ' . _('The date entry must be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'warn');
 }
 // Check the date is OK
 if (isset($_POST['QuoteDate']) and !Is_Date($_POST['QuoteDate'])) {
     $InputErrors = 1;
     prnMsg(_('An invalid date entry was made') . '. ' . _('The date entry must be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'warn');
 }
 // Check the date is OK
 if (isset($_POST['ConfirmedDate']) and !Is_Date($_POST['ConfirmedDate'])) {
     $InputErrors = 1;
     prnMsg(_('An invalid date entry was made') . '. ' . _('The date entry must be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'warn');
 }
 /* This check is not appropriate where orders need to be entered in retrospectively in some cases this check will be appropriate and this should be uncommented
 
 	 elseif (Date1GreaterThanDate2(Date($_SESSION['DefaultDateFormat'],$EarliestDispatch), $_POST['DeliveryDate'])){
 		$InputErrors =1;
 		echo '<br><b>' . _('The delivery details cannot be updated because you are attempting to set the date the order is to be dispatched earlier than is possible. No dispatches are made on Saturday and Sunday. Also, the dispatch cut off time is') .  $_SESSION['DispatchCutOffTime']  . _(':00 hrs. Orders placed after this time will be dispatched the following working day.');
 	}
 
 	*/
 if ($InputErrors == 0) {
     if ($_SESSION['DoFreightCalc'] == True) {
         list($_POST['FreightCost'], $BestShipper) = CalcFreightCost($_SESSION['Items' . $identifier]->total, $_POST['BrAdd2'], $_POST['BrAdd3'], $_SESSION['Items' . $identifier]->totalVolume, $_SESSION['Items' . $identifier]->totalWeight, $_SESSION['Items' . $identifier]->Location, $db);
         if (!empty($BestShipper)) {
Exemple #26
0
     $Errors[$i] = 'Email';
     $i++;
 }
 if (mb_strlen($_POST['Email']) > 0 and !IsEmailAddress($_POST['Email'])) {
     $InputError = 1;
     prnMsg(_('The email address is not correctly formed'), 'error');
     $Errors[$i] = 'Email';
     $i++;
 }
 if (mb_strlen($_POST['BankRef']) > 12) {
     $InputError = 1;
     prnMsg(_('The bank reference text must be less than 12 characters long'), 'error');
     $Errors[$i] = 'BankRef';
     $i++;
 }
 if (!Is_Date($_POST['SupplierSince'])) {
     $InputError = 1;
     prnMsg(_('The supplier since field must be a date in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
     $Errors[$i] = 'SupplierSince';
     $i++;
 }
 if ($InputError != 1) {
     $SQL_SupplierSince = FormatDateForSQL($_POST['SupplierSince']);
     //first off validate inputs sensible
     $sql = "SELECT COUNT(supplierid) FROM suppliers WHERE supplierid='" . $SupplierID . "'";
     $result = DB_query($sql, $db);
     $myrow = DB_fetch_row($result);
     $SuppExists = DB_num_rows($result) > 0;
     if ($SuppExists and $_POST['UpdateIfExists'] != 1) {
         $UpdatedNum++;
     } elseif ($SuppExists) {
     $msg = _('The date from must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
     $InputError = 1;
     unset($_POST['FromDate']);
 }
 if (isset($_POST['ToDate']) and !Is_Date($_POST['ToDate'])) {
     $msg = _('The date to must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
     $InputError = 1;
     unset($_POST['ToDate']);
 }
 if (isset($_POST['FromDate']) and isset($_POST['ToDate']) and Date1GreaterThanDate2($_POST['FromDate'], $_POST['ToDate'])) {
     $msg = _('The date to must be after the date from');
     $InputError = 1;
     unset($_POST['ToDate']);
     unset($_POST['FromoDate']);
 }
 if (isset($_POST['DistDate']) and !Is_Date($_POST['DistDate'])) {
     $msg = _('The distribution start date must be specified in the format') . ' ' . $_SESSION['DefaultDateFormat'];
     $InputError = 1;
     unset($_POST['DistDate']);
 }
 if (!is_numeric(filter_number_format($_POST['ExcludeQuantity']))) {
     $msg = _('The quantity below which no demand will be created must be numeric');
     $InputError = 1;
 }
 if (!is_numeric(filter_number_format($_POST['Multiplier']))) {
     $msg = _('The multiplier is expected to be a positive number');
     $InputError = 1;
 }
 if ($InputError == 1) {
     prnMsg($msg, 'error');
 }
Exemple #28
0
     echo '<br />' . _('Row:') . $Row . ' - ' . _('Invalid depreciation type:') . ' ' . $DepnType;
     $InputError = true;
 }
 $result = DB_query("SELECT categoryid FROM fixedassetcategories WHERE categoryid='" . $AssetCategoryID . "'", $db);
 if (DB_num_rows($result) == 0) {
     $InputError = true;
     prnMsg(_('The asset category code entered must be exist in the assetcategories table'), 'error');
     echo '<br />' . _('Row:') . $Row . ' - ' . _('Invalid asset category:') . ' ' . $AssetCategoryID;
 }
 $result = DB_query("SELECT locationid FROM fixedassetlocations WHERE locationid='" . $AssetLocationCode . "'", $db);
 if (DB_num_rows($result) == 0) {
     $InputError = true;
     prnMsg(_('The asset location code entered must be exist in the asset locations table'), 'error');
     echo '<br />' . _('Row:') . $Row . ' - ' . _('Invalid asset location code:') . ' ' . $AssetLocationCode;
 }
 if (!Is_Date($DatePurchased)) {
     $InputError = true;
     prnMsg(_('The date purchased must be entered in the format:') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
     echo '<br />' . _('Row:') . $Row . ' - ' . _('Invalid date format:') . ' ' . $DatePurchased;
 }
 if ($DepnType == 'DV') {
     $DepnType = 1;
 } else {
     $DepnType = 0;
 }
 if ($InputError == false) {
     //no errors
     $TransNo = GetNextTransNo(49, $db);
     $PeriodNo = GetPeriod(ConvertSQLDate($_POST['DateToEnter']), $db);
     //attempt to insert the stock item
     $sql = "INSERT INTO fixedassets (description,\n\t\t\t\t\t\t\t\t\t\t\tlongdescription,\n\t\t\t\t\t\t\t\t\t\t\tassetcategoryid,\n\t\t\t\t\t\t\t\t\t\t\tserialno,\n\t\t\t\t\t\t\t\t\t\t\tbarcode,\n\t\t\t\t\t\t\t\t\t\t\tassetlocation,\n\t\t\t\t\t\t\t\t\t\t\tcost,\n\t\t\t\t\t\t\t\t\t\t\taccumdepn,\n\t\t\t\t\t\t\t\t\t\t\tdepntype,\n\t\t\t\t\t\t\t\t\t\t\tdepnrate,\n\t\t\t\t\t\t\t\t\t\t\tdatepurchased)\n\t\t\t\t\t\t\tVALUES ('" . $Description . "',\n\t\t\t\t\t\t\t\t\t'" . $LongDescription . "',\n\t\t\t\t\t\t\t\t\t'" . $AssetCategoryID . "',\n\t\t\t\t\t\t\t\t\t'" . $SerialNo . "',\n\t\t\t\t\t\t\t\t\t'" . $BarCode . "',\n\t\t\t\t\t\t\t\t\t'" . $AssetLocationCode . "',\n\t\t\t\t\t\t\t\t\t'" . $Cost . "',\n\t\t\t\t\t\t\t\t\t'" . $AccumDepn . "',\n\t\t\t\t\t\t\t\t\t'" . $DepnType . "',\n\t\t\t\t\t\t\t\t\t'" . $DepnRate . "',\n\t\t\t\t\t\t\t\t\t'" . FormatDateForSQL($DatePurchased) . "')";
	<td class="number">' . number_format($FreightTaxTotal + $_POST['ChargeFreightCost'], 2) . '</td>
	</tr>';
$TaxTotal += $FreightTaxTotal;
$DisplaySubTotal = number_format($_SESSION['Items']->total + $_POST['ChargeFreightCost'], 2);
/* round the totals to avoid silly entries */
$TaxTotal = round($TaxTotal, 2);
$_SESSION['Items']->total = round($_SESSION['Items']->total, 2);
$_POST['ChargeFreightCost'] = round($_POST['ChargeFreightCost'], 2);
echo '<tr>
	<td colspan="10" class="number">' . _('Invoice Totals') . '</td>
	<td class="number:><hr><b>' . $DisplaySubTotal . '</b><hr></td>
	<td colspan="2"></td>
	<td class="number"><hr><b>' . number_format($TaxTotal, 2) . '</b><hr></td>
	<td class="number"><hr><b>' . number_format($TaxTotal + ($_SESSION['Items']->total + $_POST['ChargeFreightCost']), 2) . '</b><hr></td>
</tr>';
if (!isset($_POST['DispatchDate']) or !Is_Date($_POST['DispatchDate'])) {
    $DefaultDispatchDate = Date($_SESSION['DefaultDateFormat'], CalcEarliestDispatchDate());
} else {
    $DefaultDispatchDate = $_POST['DispatchDate'];
}
echo '</table><br>';
if (isset($_POST['ProcessInvoice']) && $_POST['ProcessInvoice'] != "") {
    /* SQL to process the postings for sales invoices...
    
    /*First check there are lines on the dipatch with quantities to invoice
    invoices can have a zero amount but there must be a quantity to invoice */
    $QuantityInvoicedIsPositive = false;
    foreach ($_SESSION['Items']->LineItems as $OrderLine) {
        if ($OrderLine->QtyDispatched > 0) {
            $QuantityInvoicedIsPositive = true;
        }
<?php

/* $Id$ */
include 'includes/session.inc';
$title = _('Audit Trail');
include 'includes/header.inc';
echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $title . '</p>';
if (!isset($_POST['FromDate'])) {
    $_POST['FromDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, Date('m') - $_SESSION['MonthsAuditTrail']));
}
if (!isset($_POST['ToDate'])) {
    $_POST['ToDate'] = Date($_SESSION['DefaultDateFormat']);
}
if ((!Is_Date($_POST['FromDate']) or !Is_Date($_POST['ToDate'])) and isset($_POST['View'])) {
    prnMsg(_('Incorrect date format used, please re-enter'), error);
    unset($_POST['View']);
}
if (isset($_POST['ContainingText'])) {
    $ContainingText = trim(mb_strtoupper($_POST['ContainingText']));
} elseif (isset($_GET['ContainingText'])) {
    $ContainingText = trim(mb_strtoupper($_GET['ContainingText']));
}
// Get list of tables
$TableResult = DB_show_tables($db);
// Get list of users
$UserResult = DB_query("SELECT userid FROM www_users", $db);
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
echo '<tr><td>' . _('From Date') . ' ' . $_SESSION['DefaultDateFormat'] . '</td>