Exemple #1
0
function insNewKd($data)
{
    $newID = uniqid(rand(time(), 1));
    //Kundennummer generieren
    if ($GLOBALS["kdnum"] == 1) {
        // von der ERP
        $kdnr = $GLOBALS["preK"] . getNextKnr();
    } else {
        // durch Shop
        $kdnr = $GLOBALS["preK"] . $data["customers_id"];
    }
    $sql = "select count(*) as cnt from customer where customernumber = '{$kdnr}'";
    $rs = getAll("erp", $sql, "insKdData");
    if ($rs[0]["cnt"] > 0) {
        // Kundennummer gibt es schon, eine neue aus ERP
        $kdnr = $GLOBALS["preK"] . getNextKnr();
    }
    $sql = "insert into customer (name,customernumber) values ('{$newID}','{$kdnr}')";
    $rc = query("erp", $sql, "insKdData");
    if ($rc === -99) {
        return false;
    }
    $sql = "select * from customer where name = '{$newID}'";
    $rs = getAll("erp", $sql, "insKdData");
    if (!$rs) {
        return false;
    }
    if ($data["customers_company"]) {
        $set .= "set name='" . $data["customers_company"] . "',contact='" . $data["customers_name"] . "',";
    } else {
        $tmp = strrpos($data["customers_name"], " ");
        if ($tmp > 0) {
            $set .= "set name='" . substr($data["customers_name"], $tmp + 1) . ", " . substr($data["customers_name"], 0, $tmp) . "',";
            $set .= "contact='" . $data["customers_name"] . "',";
        } else {
            $set .= "set name='" . $data["customers_name"] . "',";
        }
    }
    $set .= "street='" . $data["customers_street_address"] . "',";
    $set .= "zipcode='" . $data["customers_postcode"] . "',";
    $set .= "city='" . $data["customers_city"] . "',";
    $set .= "country='" . $GLOBALS["taxarray"][$data["billing_country"]]["code"] . "',";
    $set .= "phone='" . $data["customers_telephone"] . "',";
    $set .= "email='" . $data["customers_email_address"] . "',";
    $tid = in_array($data["billing_country"], array_keys($GLOBALS["taxarray"])) ? $GLOBALS["taxarray"][$data["billing_country"]]["tax"] : 3;
    $set .= "taxzone_id={$tid},";
    $set .= "taxincluded='f' ";
    $sql = "update customer " . $set;
    $sql .= "where id=" . $rs[0]["id"];
    $rc = query("erp", $sql, "insKdData");
    if ($rc === -99) {
        //$sql="delete from customer where id=".$rs[0]["id"];
        //$rc=query("shop",$sql,"insNewKd");
        return false;
    } else {
        return $rs[0]["id"];
    }
}
Exemple #2
0
function insNewKd($data)
{
    $taxid = array("DE" => 0, "CH" => 2, "AU" => 1, "FR" => 1, "IT" => 1, "ES" => 1, "NL" => 1);
    // Muß erweitert werden
    $newID = uniqid(rand(time(), 1));
    //Kundennummer generieren
    if ($GLOBALS["kdnum"] == 1) {
        // von der ERP
        $kdnr = $GLOBALS["preK"] . getNextKnr();
    } else {
        // durch Shop
        $kdnr = $GLOBALS["preK"] . $data["customers_id"];
    }
    $sql = "select count(*) as cnt from customer where customernumber = '{$kdnr}'";
    $rs = getAll("erp", $sql, "insKdData");
    if ($rs[0]["cnt"] > 0) {
        // Kundennummer gibt es schon, eine neue aus ERP
        $kdnr = $GLOBALS["preK"] . getNextKnr();
    }
    $sql = "insert into customer (name,customernumber) values ('{$newID}','{$kdnr}')";
    $rc = query("erp", $sql, "insKdData");
    if ($rc === -99) {
        return false;
    }
    $sql = "select * from customer where name = '{$newID}'";
    $rs = getAll("erp", $sql, "insKdData");
    if (!$rs) {
        return false;
    }
    if ($data["customers_company"]) {
        $set .= "set name='" . $data["customers_company"] . "',contact='" . $data["customers_name"] . "',";
    } else {
        $set .= "set name='" . $data["customers_lastname"] . ", " . $data["customers_firstname"] . "',";
    }
    $set .= "street='" . $data["customers_street_address"] . "',";
    $set .= "zipcode='" . $data["customers_postcode"] . "',";
    $set .= "city='" . $data["customers_city"] . "',";
    $set .= "country='" . $data["billing_country_iso_code_2"] . "',";
    $set .= "phone='" . $data["customers_telephone"] . "',";
    $set .= "email='" . $data["customers_email_address"] . "',";
    $tid = in_array($data["billing_country_iso_code_2"], $taxid) ? $taxid[$data["billing_country_iso_code_2"]] : 3;
    $set .= "taxzone_id={$tid},";
    $set .= "taxincluded='f' ";
    $sql = "update customer " . $set;
    $sql .= "where id=" . $rs[0]["id"];
    $rc = query("erp", $sql, "insKdData");
    if ($rc === -99) {
        return false;
    } else {
        return $rs[0]["id"];
    }
}
Exemple #3
0
function insKdData($data)
{
    global $db2, $preK, $kdnum;
    $newID = $data["Kunden_ID"];
    if ($kdnum == 1) {
        $kdnr = $preK . getNextKnr();
    } else {
        $kdnr = $preK . $data["customers_id"];
    }
    $sql = "insert into customer (name,customernumber) values ('{$newID}','{$kdnr}')";
    $rc = query($db2, $sql);
    $sql = "select * from customer where name = '{$newID}'";
    $rs = $db2->getAll($sql, DB_FETCHMODE_ASSOC);
    if ($data["Firma"]) {
        $set .= "set name='" . $data["Firma"] . "',contact='" . $data["Vorname"] . " " . $data["Nachname"] . "',";
    } else {
        $set .= "set name='" . $data["Nachname"] . ", " . $data["Vorname"] . "',";
    }
    if ($data["Strasse"]) {
        $set .= "street='" . $data["Strasse"] . "',";
    } else {
        if ($data["Postfach"]) {
            $set .= "street='" . $data["Postfach"] . "',";
        }
    }
    $set .= "zipcode='" . $data["PLZ"] . "',";
    $set .= "city='" . $data["Ort"] . "',";
    $set .= "country='" . $data["Land"] . "',";
    $set .= "phone='" . $data["Tel"] . "',";
    $set .= "fax='" . $data["Fax"] . "',";
    $set .= "email='" . $data["Email"] . "',";
    $set .= "notes='" . $data["Beschreibung"] . "',";
    $set .= "taxincluded='f' ";
    $sql = "update customer " . $set;
    $sql .= "where id=" . $rs[0]["id"];
    $sql = utf8_encode($sql);
    echo $sql . "<br>";
    $rc = query($db2, $sql);
    if (DB::isError($rc)) {
        print_r($rc);
        echo "<br>";
    }
    return $rs[0]["id"];
}