AW: Auftragsimport : Amazon Seller Central -> JTL Wawi Konver
<?php
/*
************************************************************************
* Amazon Seller Central -> JTL
Wawi Converter 1.2
* ======================================================================
*
* Based on Version 1.1 Copyright (c) 2008 by Marc Isemann
*
Solunas Hotel Booking Engine | Download Solunas Hotel Booking Engine software for free at SourceForge.net
*
Marc Isemann Blog
*
* Extended by Vygi
*
DreamTimeShop
*
info@dreamtimeshop.com
*
* This program is free software. You can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
************************************************************************
*/
// Constants
$BASE_DIR = "/jtl";
$UPLOADDIR = $_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/amazon_import/';
$UPLOADFILE = $UPLOADDIR . $_FILES['userfile']['name'];
$TIME_STAMP = date('Y-m-d_Hi', time());
$CARRIER_CODE = 'Other'; // Tranporteur-Code ("UPS", "DHL", "GLS" ... oder "Other" für die "Deutsche Post"!)
$CARRIER_NAME = 'Deutsche Post'; // Leer, falls Code = "UPS", "DHL", "GLS" ... oder "Deutsche Post"
$SHIP_METHOD = 'Brief'; // Versandmethode ("Paket", "Päckchen", "Brief")
$COUNTRIES = array('AT' => 'Österreich',
'BE' => 'Belgien',
'CH' => 'Schweiz',
'CZ' => 'Tschechische Republik',
'DE' => 'Deutschland',
'DK' => 'Dänemark / Denmark',
'EE' => 'Estland / Estonia',
'ES' => 'Spanien / Spain',
'FI' => 'Finnland / Finland',
'FR' => 'Frankreich / France',
'GB' => 'Großbritannien / UK',
'GR' => 'Griechenland / Greece',
'HU' => 'Ungarn / Hungary',
'IE' => 'Irland / Ireland',
'IS' => 'Island / Iceland',
'IT' => 'Italien / Italy',
'LI' => 'Liechtenstein',
'LT' => 'Litauen / Lithuania',
'LU' => 'Luxemburg',
'LV' => 'Lettland / Latvia',
'MC' => 'Monaco',
'MT' => 'Malta',
'NL' => 'Niederlande',
'NO' => 'Norwegen / Norway',
'PL' => 'Polen / Poland',
'PT' => 'Portugal',
'RO' => 'Rumänien / Romania',
'SE' => 'Schweden / Sweden',
'SI' => 'Slowenien / Slovenia',
'SK' => 'Slowakei / Slovakia',
);
error_reporting(7);
?>
<html>
<head>
<title>Amazon-zu-WAWI Schnittstelle</title>
</head>
<body>
<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
Amazon Bestellbericht: <input name="userfile" type="file">
<input type="submit" value="Verarbeiten">
</form>
<?php
if ($_FILES AND move_uploaded_file($_FILES['userfile']['tmp_name'], $UPLOADFILE)) {
print "<p>Die Datei wurde erfolgreich hochgeladen.</p>\n";
require($_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/smarty/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = $_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/smarty/templates';
$smarty->compile_dir = $_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/smarty/templates_c';
$smarty->cache_dir = $_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/smarty/
cache';
$smarty->config_dir = $_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/smarty/configs';
$handle = fopen ($UPLOADFILE, "r");
$row = 0;
while (($data = fgetcsv ($handle, 1000, "\t")) !== false) {
if ($row > 0) {
// Stamm
$order[$data[0]]["ORDERID"] = $data[0];
$order[$data[0]]["PURCHASE_DATE"] = $data[2];
$order[$data[0]]["PAYMENT_DATE"] = $data[3];
$order[$data[0]]["TOTAL"] = $order[$data[0]]["TOTAL"] + $data[11] + $data[13];
$order[$data[0]]["
SHIPPING"] = $order[$data[0]]["SHIPPING"] + $data[13];
// Kunde
$order[$data[0]]["kunde"]["EMAIL"] = $data[4];
$name = htmlspecialchars($data[16]);
$firstName = '';
if (substr_count($name, ' ') == 1) {
$firstName = substr($name, 0, strpos($name, ' '));
$name = substr($name, strpos($name, ' ') + 1);
}
$order[$data[0]]["kunde"]["VORNAME"] = $firstName;
$order[$data[0]]["kunde"]["NAME"] = $name;
$order[$data[0]]["kunde"]["FON"] = $data[24];
if ($data[18] != "") {
$order[$data[0]]["kunde"]["FIRMA"] = htmlspecialchars($data[17]);
$order[$data[0]]["kunde"]["STRASSE"] = htmlspecialchars($data[18]);
} else {
$order[$data[0]]["kunde"]["FIRMA"] = "";
$order[$data[0]]["kunde"]["STRASSE"] = htmlspecialchars($data[17]);
}
$order[$data[0]]["kunde"]["PLZ"] = $data[22];
$order[$data[0]]["kunde"]["ORT"] = htmlspecialchars($data[20]);
// Kunde LAND
$country = $COUNTRIES[$data[23]];
if (!$country) $country = $data[23];
$order[$data[0]]["kunde"]["LAND"] = $country;
$order[$data[0]]["kunde"]["LIEFERLAND"] = $data[23] == "DE" ? '' : $country;
// schreibe artikelnummer in temp array
$product[artikelnr] = $data[7];
$product[qty] = $data[9];
$product[price] = $data[11] / $data[9];
$product[name] = htmlspecialchars($data[8]);
$product[shipping] = $data[13];
// Produkte
$order[$data[0]]["produkte"][] = $product;
}
$row++;
}
$smarty->assign('ORDERS', $order);
$output = $smarty->fetch($_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . '/amazon_vorlage.xml');
fclose($handle);
$handle = fopen($_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . "/amazon_export/jtl_{$TIME_STAMP}.xml", "w");
if (fwrite($handle, $output) === false) {
echo "<p>FEHLER: konnte die JTL-Auftragsdatei nicht schreiben!</p>\n";
exit;
} else {
$orders = sizeof($order);
echo "<blockquote>\n<p>$orders Bestellung(en) bearbeitet.</p>\n";
echo "<p>JTL-Auftragsdatei: <a href='amazon_export/jtl_{$TIME_STAMP}.xml'>jtl_{$TIME_STAMP}.xml</a></p>\n";
}
fclose($handle);
$shipingData = "order-id\torder-item-id\tquantity\tship-date\tcarrier-code\tcarrier-name\ttracking-number\tship-method\n";
foreach($order as $key => $value) {
// order-id order-item-id quantity ship-date carrier-code carrier-name tracking-number ship-method
$shipingData .= $key . "\t\t\t";
$shipingData .= date('Y-m-d', time()) . "\t";
$shipingData .= "$CARRIER_CODE\t$CARRIER_NAME\t\t$SHIP_METHOD\n";
}
$handle3 = fopen($_SERVER["DOCUMENT_ROOT"] . $BASE_DIR . "/amazon_export/ship_{$TIME_STAMP}.csv", "w");
if (fwrite($handle3, $shipingData) === false) {
echo "<p>FEHLER: konnte die Amazon-Lieferdatei nicht schreiben!</p>\n";
exit;
} else {
echo "<p>Amazon-Lieferdatei: <a href='amazon_export/ship_{$TIME_STAMP}.csv'>ship_{$TIME_STAMP}.csv</a></p>\n</blockquote>\n";
}
fclose($handle3);
}
?>
</body>
</html>