Example #1
0
function ModifySalesOrderHeader($OrderHeader, $user, $password)
{
    $Errors = array();
    $db = db($user, $password);
    if (gettype($db) == 'integer') {
        $Errors[0] = NoAuthorisation;
        return $Errors;
    }
    foreach ($OrderHeader as $key => $value) {
        $OrderHeader[$key] = DB_escape_string($value);
    }
    $Errors = VerifyOrderHeaderExists($OrderHeader['orderno'], sizeof($Errors), $Errors, $db);
    $Errors = VerifyDebtorExists($OrderHeader['debtorno'], sizeof($Errors), $Errors, $db);
    $Errors = VerifyBranchNoExists($OrderHeader['debtorno'], $OrderHeader['branchcode'], sizeof($Errors), $Errors, $db);
    if (isset($OrderHeader['customerref'])) {
        $Errors = VerifyCustomerRef($OrderHeader['customerref'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['buyername'])) {
        $Errors = VerifyBuyerName($OrderHeader['buyername'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['comments'])) {
        $Errors = VerifyComments($OrderHeader['comments'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['orddate'])) {
        $Errors = VerifyOrderDate($OrderHeader['orddate'], sizeof($Errors), $Errors, $db);
    }
    if (isset($OrderHeader['ordertype'])) {
        $Errors = VerifyOrderType($OrderHeader['ordertype'], sizeof($Errors), $Errors, $db);
    }
    if (isset($OrderHeader['shipvia'])) {
        $Errors = VerifyShipVia($OrderHeader['shipvia'], sizeof($Errors), $Errors, $db);
    }
    if (isset($OrderHeader['deladd1'])) {
        $Errors = VerifyAddressLine($OrderHeader['deladd1'], 40, sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deladd2'])) {
        $Errors = VerifyAddressLine($OrderHeader['deladd2'], 40, sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deladd3'])) {
        $Errors = VerifyAddressLine($OrderHeader['deladd3'], 40, sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deladd4'])) {
        $Errors = VerifyAddressLine($OrderHeader['deladd4'], 40, sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deladd5'])) {
        $Errors = VerifyAddressLine($OrderHeader['deladd5'], 20, sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deladd6'])) {
        $Errors = VerifyAddressLine($OrderHeader['deladd6'], 15, sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['contactphone'])) {
        $Errors = VerifyPhoneNumber($OrderHeader['contactphone'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['contactemail'])) {
        $Errors = VerifyEmailAddress($OrderHeader['contactemail'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deliverto'])) {
        $Errors = VerifyDeliverTo($OrderHeader['deliverto'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['deliverblind'])) {
        $Errors = VerifyDeliverBlind($OrderHeader['deliverblind'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['freightcost'])) {
        $Errors = VerifyFreightCost($OrderHeader['freightcost'], sizeof($Errors), $Errors);
    }
    if (isset($OrderHeader['fromstkloc'])) {
        $Errors = VerifyFromStockLocation($OrderHeader['fromstkloc'], sizeof($Errors), $Errors, $db);
    }
    if (isset($OrderHeader['deliverydate'])) {
        $Errors = VerifyDeliveryDate($OrderHeader['deliverydate'], sizeof($Errors), $Errors, $db);
    }
    if (isset($OrderHeader['quotation'])) {
        $Errors = VerifyQuotation($OrderHeader['quotation'], sizeof($Errors), $Errors);
    }
    global $SOH_DateFields;
    $sql = 'UPDATE salesorders SET ';
    foreach ($OrderHeader as $key => $value) {
        if (in_array($key, $SOH_DateFields)) {
            $value = FormatDateforSQL($value);
        }
        // Fix dates
        $sql .= $key . '="' . $value . '", ';
    }
    $sql = substr($sql, 0, -2) . ' WHERE orderno="' . $OrderHeader['orderno'] . '"';
    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;
}
function InsertSalesCredit($CreditDetails, $user, $password)
{
    $Errors = array();
    $db = db($user, $password);
    if (gettype($db) == 'integer') {
        $Errors[0] = NoAuthorisation;
        return $Errors;
    }
    foreach ($CreditDetails as $key => $value) {
        $CreditDetails[$key] = DB_escape_string($value);
    }
    $PartCode = $CreditDetails['partcode'];
    $Errors = VerifyStockCodeExists($PartCode, sizeof($Errors), $Errors, $db);
    unset($CreditDetails['partcode']);
    $SalesArea = $CreditDetails['salesarea'];
    unset($CreditDetails['salesarea']);
    $CreditDetails['transno'] = GetNextTransactionNo(11, $db);
    $CreditDetails['type'] = 10;
    $Errors = VerifyDebtorExists($CreditDetails['debtorno'], sizeof($Errors), $Errors, $db);
    $Errors = VerifyBranchNoExists($CreditDetails['debtorno'], $CreditDetails['branchcode'], sizeof($Errors), $Errors, $db);
    $Errors = VerifyTransNO($CreditDetails['transno'], 10, sizeof($Errors), $Errors, $db);
    $Errors = VerifyTransactionDate($CreditDetails['trandate'], sizeof($Errors), $Errors, $db);
    if (isset($CreditDetails['settled'])) {
        $Errors = VerifySettled($CreditDetails['settled'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['reference'])) {
        $Errors = VerifyReference($CreditDetails['reference'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['tpe'])) {
        $Errors = VerifyTpe($CreditDetails['tpe'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['order_'])) {
        $Errors = VerifyOrderNumber($CreditDetails['order_'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['rate'])) {
        $Errors = VerifyExchangeRate($CreditDetails['rate'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['ovamount'])) {
        $Errors = VerifyOVAmount($CreditDetails['ovamount'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['ovgst'])) {
        $Errors = VerifyOVGst($CreditDetails['ovgst'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['ovfreight'])) {
        $Errors = VerifyOVFreight($CreditDetails['ovfreight'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['ovdiscount'])) {
        $Errors = VerifyOVDiscount($CreditDetails['ovdiscount'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['diffonexch'])) {
        $Errors = VerifyDiffOnExchange($CreditDetails['diffonexch'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['alloc'])) {
        $Errors = VerifyAllocated($CreditDetails['alloc'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['invtext'])) {
        $Errors = VerifyInvoiceText($CreditDetails['invtext'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['shipvia'])) {
        $Errors = VerifyShipVia($CreditDetails['shipvia'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['edisent'])) {
        $Errors = VerifyEdiSent($CreditDetails['edisent'], sizeof($Errors), $Errors);
    }
    if (isset($CreditDetails['consignment'])) {
        $Errors = VerifyConsignment($CreditDetails['consignment'], sizeof($Errors), $Errors);
    }
    $FieldNames = '';
    $FieldValues = '';
    $CreditDetails['trandate'] = ConvertToSQLDate($CreditDetails['trandate']);
    $CreditDetails['prd'] = GetPeriodFromTransactionDate($CreditDetails['trandate'], sizeof($Errors), $Errors, $db);
    foreach ($CreditDetails as $key => $value) {
        $FieldNames .= $key . ', ';
        $FieldValues .= '"' . $value . '", ';
    }
    if (sizeof($Errors) == 0) {
        $result = DB_Txn_Begin($db);
        $sql = "INSERT INTO debtortrans (" . mb_substr($FieldNames, 0, -2) . ")\n\t\t\t\t\t\tVALUES ('" . mb_substr($FieldValues, 0, -2) . "') ";
        $result = DB_Query($sql, $db);
        $sql = "UPDATE systypes SET typeno='" . GetNextTransactionNo(11, $db) . "' WHERE typeid=10";
        $result = DB_Query($sql, $db);
        $SalesGLCode = GetSalesGLCode($SalesArea, $PartCode, $db);
        $DebtorsGLCode = GetDebtorsGLCode($db);
        $sql = "INSERT INTO gltrans VALUES(null,\n\t\t\t\t\t\t\t\t\t\t\t10,\n\t\t\t\t\t\t\t\t\t\t\t'" . GetNextTransactionNo(11, $db) . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['trandate'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['prd'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $DebtorsGLCode . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . _('Invoice for') . ' - ' . $CreditDetails['debtorno'] . ' ' . -'Total' . ' - ' . $CreditDetails['ovamount'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['ovamount'] . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['jobref'] . "')";
        $result = DB_Query($sql, $db);
        $sql = "INSERT INTO gltrans VALUES(null,\n\t\t\t\t\t\t\t\t\t\t\t10,\n\t\t\t\t\t\t\t\t\t\t\t'" . GetNextTransactionNo(11, $db) . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['trandate'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['prd'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $SalesGLCode . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . _('Invoice for') . ' - ' . $CreditDetails['debtorno'] . ' ' . _('Total') . ' - ' . $CreditDetails['ovamount'] . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . -intval($CreditDetails['ovamount']) . "',\n\t\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t\t'" . $CreditDetails['jobref'] . "')";
        $result = DB_Query($sql, $db);
        $result = DB_Txn_Commit($db);
        if (DB_error_no($db) != 0) {
            $Errors[0] = DatabaseUpdateFailed;
        } else {
            $Errors[0] = 0;
        }
        return $Errors;
    } else {
        return $Errors;
    }
}