Example #1
0
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;
}
Example #2
0
function InsertSalesOrderLine($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);
    }
    $OrderLine['orderlineno'] = GetOrderLineNumber($OrderLine['orderno'], sizeof($Errors), $Errors, $db);
    $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);
    }
    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);
    }
    $FieldNames = '';
    $FieldValues = '';
    foreach ($OrderLine as $key => $value) {
        $FieldNames .= $key . ', ';
        $FieldValues .= '"' . $value . '", ';
    }
    $sql = 'INSERT INTO salesorderdetails (' . substr($FieldNames, 0, -2) . ') ' . 'VALUES (' . substr($FieldValues, 0, -2) . ') ';
    if (sizeof($Errors) == 0) {
        $result = DB_Query($sql, $db);
        if (DB_error_no($db) != 0) {
            $Errors[0] = DatabaseUpdateFailed;
        } else {
            $Errors[0] = 0;
        }
    }
    return $Errors;
}