function ModifySalesOrderLine($OrderLine, $user, $password)
{
    $Errors = array();
    $db = db($user, $password);
    if (gettype($db) == 'integer') {
        $Errors[0] = NoAuthorisation;
        return $Errors;
    }
    foreach ($OrderLine as $key => $value) {
        $OrderLine[$key] = DB_escape_string($value);
    }
    $Errors = VerifyOrderHeaderExists($OrderLine['orderno'], sizeof($Errors), $Errors, $db);
    $Errors = VerifyStockCodeExists($OrderLine['stkcode'], sizeof($Errors), $Errors, $db);
    if (isset($OrderLine['unitprice'])) {
        $Errors = VerifyUnitPrice($OrderLine['unitprice'], sizeof($Errors), $Errors);
    }
    if (isset($OrderLine['quantity'])) {
        $Errors = VerifyQuantity($OrderLine['quantity'], sizeof($Errors), $Errors);
    }
    if (isset($OrderLine['discountpercent'])) {
        //$OrderLine['discountpercent'] = $OrderLine['discountpercent'] * 100;
        $Errors = VerifyDiscountPercent($OrderLine['discountpercent'], sizeof($Errors), $Errors);
        $OrderLine['discountpercent'] = $OrderLine['discountpercent'] / 100;
    }
    if (isset($OrderLine['narrative'])) {
        $Errors = VerifyNarrative($OrderLine['narrative'], sizeof($Errors), $Errors);
    }
    if (isset($OrderLine['itemdue'])) {
        $Errors = VerifyItemDueDate($OrderLine['itemdue'], sizeof($Errors), $Errors);
    }
    if (isset($OrderLine['poline'])) {
        $Errors = VerifyPOLine($OrderLine['poline'], sizeof($Errors), $Errors);
    }
    $sql = 'UPDATE salesorderdetails SET ';
    foreach ($OrderLine as $key => $value) {
        if ($key == 'actualdispatchdate') {
            $value = FormatDateWithTimeForSQL($value);
        } elseif ($key == 'itemdue') {
            $value = FormatDateForSQL($value);
        }
        $sql .= $key . '="' . $value . '", ';
    }
    //$sql = substr($sql,0,-2).' WHERE orderno="'.$OrderLine['orderno'].'" and
    //	" orderlineno='.$OrderLine['orderlineno'];
    $sql = substr($sql, 0, -2) . ' WHERE orderno="' . $OrderLine['orderno'] . '" and stkcode="' . $OrderLine['stkcode'] . '"';
    //echo $sql;
    //exit;
    if (sizeof($Errors) == 0) {
        $result = api_DB_Query($sql, $db);
        echo DB_error_no($db);
        if (DB_error_no($db) != 0) {
            $Errors[0] = DatabaseUpdateFailed;
        } else {
            $Errors[0] = 0;
        }
    }
    return $Errors;
}
Exemple #2
0
function ModifyPurchData($PurchDataDetails, $user, $password)
{
    $Errors = array();
    $db = db($user, $password);
    if (gettype($db) == 'integer') {
        $Errors[0] = NoAuthorisation;
        return $Errors;
    }
    foreach ($PurchDataDetails as $key => $value) {
        $PurchDataDetails[$key] = DB_escape_string($value);
    }
    $Errors = VerifyPurchDataLineExists($PurchDataDetails['supplierno'], $PurchDataDetails['stockid'], sizeof($Errors), $Errors, $db);
    $Errors = VerifyStockCodeExists($PurchDataDetails['stockid'], sizeof($Errors), $Errors, $db);
    $Errors = VerifySupplierNoExists($PurchDataDetails['supplierno'], sizeof($Errors), $Errors, $db);
    if (isset($StockItemDetails['price'])) {
        $Errors = VerifyUnitPrice($PurchDataDetails['price'], sizeof($Errors), $Errors);
    }
    if (isset($StockItemDetails['suppliersuom'])) {
        $Errors = VerifySuppliersUOM($PurchDataDetails['suppliersuom'], sizeof($Errors), $Errors);
    }
    if (isset($StockItemDetails['conversionfactor'])) {
        $Errors = VerifyConversionFactor($PurchDataDetails['conversionfactor'], sizeof($Errors), $Errors);
    }
    if (isset($StockItemDetails['supplierdescription'])) {
        $Errors = VerifySupplierDescription($PurchDataDetails['supplierdescription'], sizeof($Errors), $Errors);
    }
    if (isset($StockItemDetails['leadtime'])) {
        $Errors = VerifyLeadTime($PurchDataDetails['leadtime'], sizeof($Errors), $Errors);
    }
    if (isset($StockItemDetails['preferred'])) {
        $Errors = VerifyPreferredFlag($PurchDataDetails['preferred'], sizeof($Errors), $Errors);
    }
    $sql = "UPDATE purchdata SET ";
    foreach ($PurchDataDetails as $key => $value) {
        $sql .= $key . "='" . $value . "', ";
    }
    $sql = mb_substr($sql, 0, -2) . " WHERE stockid='" . $PurchDataDetails['stockid'] . "'\n\t\t\t\t\t\t\t\tAND supplierno='" . $PurchDataDetails['supplierno'] . "'";
    if (sizeof($Errors) == 0) {
        $result = DB_Query($sql, $db);
        echo DB_error_no($db);
        if (DB_error_no($db) != 0) {
            $Errors[0] = DatabaseUpdateFailed;
        } else {
            $Errors[0] = 0;
        }
    }
    return $Errors;
}