Example #1
0
function chkKunden()
{
    $felder = array("firstname", "lastname", "company", "street_address", "city", "postcode", "country");
    foreach ($GLOBALS["bestellungen"] as $bestellung) {
        $rc = query("erp", "BEGIN", "chkKunde");
        if ($rc === -99) {
            echo "Probleme mit Datenbank, Abbruch!";
            exit;
        }
        if ($bestellung["kdnr"] > 0) {
            $msg = "update ";
            $kdnr = chkOldKd($bestellung);
            if ($kdnr == -1) {
                //Kunde nicht gefunden, neu anlegen.
                $msg = "insert ";
                $kdnr = insNewKd($bestellung);
                $GLOBALS["neuKd"]++;
            }
        } else {
            $msg = "insert ";
            $kdnr = insNewKd($bestellung);
            $GLOBALS["neuKd"]++;
        }
        echo $bestellung["customers_company"] . " " . $bestellung["customers_name"] . " {$kdnr}<br>";
        $GLOBALS["bestellungen"][$GLOBALS["gesKd"]]["kdnr"] = $kdnr;
        $sql = "delete from " . PREFIX . "customers_number where customers_id=" . $bestellung["customers_id"];
        $rc = query("shop", $sql, "chkKunde");
        $sql = "insert into " . PREFIX . "customers_number (customers_id,kdnr) values(" . $bestellung["customers_id"] . "," . $kdnr . ")";
        $rc = query("shop", $sql, "chkKunde");
        if ($kdnr > 0) {
            foreach ($felder as $feld) {
                if ($bestellung["delivery_{$feld}"] != $bestellung["customers_{$feld}"]) {
                    $rc = insShData($bestellung, $kdnr);
                    if ($rc > 0) {
                        $GLOBALS["bestellungen"][$GLOBALS["gesKd"]]["shipto"] = $rc;
                    }
                    break;
                }
            }
        }
        if (!$kdnr || $rc === -99) {
            $rc = query("erp", "ROLLBACK", "chkKunde");
            echo $msg . " " . $bestellung["customers_name"] . " fehlgeschlagen!<br>";
            return false;
        } else {
            $rc = query("erp", "COMMIT", "chkKunde");
        }
        $GLOBALS["gesKd"]++;
    }
    return true;
}
function chkKunden() {
	$felder=array("firstname","lastname","company","street_address","city","postcode","country");
	foreach ($GLOBALS["bestellungen"] as $bestellung) {
		$rc=query("erp","BEGIN WORK","chkKunden");
		if ($rc === -99) { echo "Probleme mit Transaktion. Abbruch!"; exit(); };
		if ($bestellung["kdnr"]>0) { // Bestandskunde; kdnr == ID in customers
			$msg="update ";
			$kdnr=chkOldKd($bestellung);
			if ($kdnr == -1) { //Kunde nicht gefunden, neu anlegen.
				$msg="insert ";
				$kdnr=insNewKd($bestellung);
				$GLOBALS["neuKd"]++;
			} else if (!$kdnr) {
				echo $msg." ".$bestellung["customers_name"]." fehlgeschlagen!<br>";
				$GLOBALS["gesKd"]++;
				continue;
			}
		} else { // Neukunde
			$msg="insert ";
			$kdnr=insNewKd($bestellung);
			$GLOBALS["neuKd"]++;
		}
		echo $bestellung["customers_company"]." ".$bestellung["customers_name"]." $kdnr<br>";
		$GLOBALS["bestellungen"][$GLOBALS["gesKd"]]["kdnr"]=$kdnr;
		$sql="delete from customers_number where customers_id=".$bestellung["customers_id"];
        	$rc=query("shop",$sql,"chkKunde");
        	$sql="insert into customers_number (customers_id,kdnr) values(".$bestellung["customers_id"].",".$kdnr.")";
        	$rc=query("shop",$sql,"chkKunde");
		if ($kdnr>0) {
			foreach($felder as $feld) {
				if ($bestellung["delivery_$feld"]<>$bestellung["customers_$feld"]) {
					$rc=insShData($bestellung,$kdnr);
					if ($rc>0) $GLOBALS["bestellungen"][$GLOBALS["gesKd"]]["shipto"]=$rc;
					break;
				}
			}
		}
		if (!$kdnr || $rc === -99) {
			echo $msg." ".$bestellung["customers_name"]." fehlgeschlagen! ($kdnr,$rc)<br>";
			$rc=query("erp","ROLLBACK WORK","chkKunde");
			if ($rc === -99) { echo "Probleme mit Transaktion. Abbruch!"; exit(); };
		} else {
			$rc=query("erp","COMMIT WORK","chkKunde");
			if ($rc === -99) { echo "Probleme mit Transaktion. Abbruch!"; exit(); };
		}		$GLOBALS["gesKd"]++;
	}
	return true;
}