<?php
/**
* jtlwawi_Connector/dbeS/Artikel.php
* Synchronisationsscript
*
* Es gelten die Nutzungs- und Lizenzhinweise unter [url]http://www.jtl-software.de/jtlwawi.php[/url]
*
* @author JTL-Software <thomas@jtl-software.de>
* @copyright 2006, JTL-Software
* @link [url]http://jtl-software.de/jtlwawi.php[/url]
* @version v1.03 / 16.09.06
*/
require_once("syncinclude.php");
$return=3;
if (auth())
{
if (intval($_POST["action"]) == 1 && intval($_POST['KeyArtikel']))
{
$return = 0;
//hole einstellungen
$cur_query = eS_execute_query("select * from eazysales_einstellungen");
$einstellungen = mysql_fetch_object($cur_query);
$artikel->kArtikel = realEscape($_POST["KeyArtikel"]);
$artikel->cArtNr = realEscape($_POST["ArtikelNo"]);
$artikel->cName = realEscape($_POST["ArtikelName"]);
$artikel->cBeschreibung = realEscape($_POST["ArtikelBeschreibung"]);
$artikel->fVKBrutto = realEscape($_POST["ArtikelVKBrutto"]);
$artikel->fVKNetto = realEscape($_POST["ArtikelVKNetto"]);
$artikel->fMwSt = realEscape($_POST["ArtikelMwSt"]);
$artikel->cAnmerkung = realEscape($_POST["ArtikelAnmerkung"]);
$artikel->nLagerbestand = max(realEscape($_POST["ArtikelLagerbestand"]),0);
$artikel->cEinheit = realEscape($_POST["ArtikelEinheit"]);
$artikel->nMindestbestellmaenge = realEscape($_POST["ArtikelMindBestell"]);
$artikel->cBarcode = realEscape($_POST["ArtikelBarcode"]);
$artikel->fVKHaendlerBrutto = realEscape($_POST["ArtikelVKHaendlerBrutto"]);
$artikel->fVKHaendlerNetto = realEscape($_POST["ArtikelVKHaendlerNetto"]);
$artikel->cTopArtikel = realEscape($_POST["TopAngebot"]);
$artikel->fGewicht = realEscape($_POST["Gewicht"]);
$artikel->cNeu = realEscape($_POST["Neu"]);
$artikel->cKurzBeschreibung = realEscape($_POST["ArtikelKurzBeschreibung"]);
$artikel->fUVP = realEscape($_POST["ArtikelUVP"]);
$artikel->cHersteller = realEscape(htmlentities($_POST["Hersteller"]));
$startseite=0;
switch (strtoupper($_POST["ArtikelEinheit"])){
case 'ST':
$artikel->cEinheit = 'St';
$grundwert = '1';
break;
case 'KG':
$artikel->cEinheit = 'kg';
$grundwert = '1';
break;
case 'L':
$artikel->cEinheit = 'l';
$grundwert = '1';
break;
case 'G':
$artikel->cEinheit = 'g';
$grundwert = '100';
break;
case 'ML':
$artikel->cEinheit = 'ml';
$grundwert = '100';
break;
};
if ((floatval($artikel->fUVP) == '0') && ($artikel->cEinheit == ''))
$artikel->fUVP = '1';
if ($artikel->cTopArtikel=="Y")
$startseite=1;
//update oder insert?
$products_id = getFremdArtikel($artikel->kArtikel);
if ($products_id>0)
{
//update
//attribute löschen
eS_execute_query("delete from products_attributes where products_id=".$products_id);
//KategorieArtikel löschen
eS_execute_query("delete from products_to_categories where products_id=".$products_id);
//evtl. andere MwSt?
$products_tax_class_id = holeSteuerId($artikel->fMwSt);
//evtl. neuer Hersteller?
$manufacturers_id = holeHerstellerId($artikel->cHersteller);
//update products
eS_execute_query("update products set products_model=\"$artikel->cArtNr\", products_price=\"$artikel->fVKNetto\",products_base_price=\"$artikel->fUVP\",products_base_value=\"$grundwert\",products_base_unit=\"".$artikel->cEinheit."\", products_tax_class_id=\"$products_tax_class_id\", products_quantity=\"$artikel->nLagerbestand\", products_weight=\"$artikel->fGewicht\", manufacturers_id=\"$manufacturers_id\", products_status=1, products_last_modified=now() where products_id=".$products_id);
//update products_description
eS_execute_query("update products_description set products_name=\"$artikel->cName\", products_description=\"$artikel->cBeschreibung\" where products_id=".$products_id." and language_id=".$einstellungen->languages_id);
//kundengrp preise
$updater='true';
insertPreise($products_id,$updater);
}
else
{
//insert
//hole Mwst classId
$products_tax_class_id = holeSteuerId($artikel->fMwSt);
//setze Hersteller, falls es ihn noch nicht gibt
$manufacturers_id = holeHerstellerId($artikel->cHersteller);
eS_execute_query("insert into products (products_model, products_price, products_base_price, products_base_value, products_base_unit, products_tax_class_id, products_quantity, products_weight, manufacturers_id, products_status, products_date_added) values (\"".$artikel->cArtNr."\",$artikel->fVKNetto,$artikel->fUVP,$grundwert,\"".$artikel->cEinheit."\",$products_tax_class_id,$artikel->nLagerbestand,$artikel->fGewicht,$manufacturers_id,1,now())");
//hole id
$query = eS_execute_query("select LAST_INSERT_ID()");
$products_id_arr = mysql_fetch_row($query);
if ($products_id_arr[0]>0)
{
//müssen Preise in spezielle tabellen?
$updater='false';
insertPreise($products_id_arr[0],$updater);
eS_execute_query("insert into products_description (products_id, products_name, products_description, language_id) values (".$products_id_arr[0].",\"".$artikel->cName."\", \"".$artikel->cBeschreibung."\", $einstellungen->languages_id)");
setMappingArtikel($artikel->kArtikel,$products_id_arr[0]);
//erstelle leere description für alle anderen Sprachen
$sonstigeSprachen = getSonstigeSprachen($einstellungen->languages_id);
if (is_array($sonstigeSprachen))
{
foreach ($sonstigeSprachen as $sonstigeSprache)
{
//eS_execute_query("insert into products_description (products_id, products_name, language_id) values (".$products_id_arr[0].",\"".$artikel->cName."\", $sonstigeSprache)");
eS_execute_query("insert into products_description (products_id, products_name, products_description, language_id) values (".$products_id_arr[0].",\"".$artikel->cName."\", \"".$artikel->cBeschreibung."\", $sonstigeSprache)");
}
}
}
else
{
//Fehler aufgetreten
$return=1;
}
}
}
else
$return=5;
if (intval($_POST["action"]) == 3 && intval($_POST['KeyArtikel']))
{
$products_id = getFremdArtikel(intval($_POST['KeyArtikel']));
if ($products_id>0)
eS_execute_query("update products set products_status=0 where products_id=".$products_id);
$return = 0;
}
}
mysql_close();
echo($return);
logge($return);
function insertPreise($products_id,$updater)
{
if (!$updater){
//Neuer Artikel Nettopreise Kundengruppen einspielen
$specialOfferTable = "products_groups";
$table = $specialOfferTable;
$endKunden_arr = array(intval($_POST["PAnz1"]),intval($_POST["PAnz2"]),intval($_POST["PAnz3"]),intval($_POST["PAnz4"]),intval($_POST["PAnz5"]));
$SSPinArr = count ($endKunden_arr);
for ($num = 1; $num < $SSPinArr; $num++){
$num2 = $num-1;
$SPPCGruppe = $endKunden_arr[$num2];
if (($endKunden_arr[$num-1] < '6') && (floatval($_POST["PPreis".$num.""]) > '0')){
eS_execute_query("insert into $table (customers_group_id, customers_group_price , products_id) values ($SPPCGruppe,".floatval($_POST["PPreis".$num.""]).",$products_id)")
;} // end if
} // end for
//Neuer Artikel Sonderangebote Kundengruppen einspielen
$specialOfferTable = "specials";
$table = $specialOfferTable;
eS_execute_query("delete from $table where products_id=".$products_id);
$haendlerKunden_arr = array(intval($_POST["HAnz1"]),intval($_POST["HAnz2"]),intval($_POST["HAnz3"]),intval($_POST["HAnz4"]),intval($_POST["HAnz5"]));
if (floatval($_POST["ArtikelVKHaendlerNetto"]) == '0'){
$num = 1;
foreach ($haendlerKunden_arr as $hkgruppe) {
switch ($hkgruppe){
case 1:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_date_added) values ($products_id,'1',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 2:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_date_added) values ($products_id,'2',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 3:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_date_added) values ($products_id,'3',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 4:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_date_added) values ($products_id,'4',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 5:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_date_added) values ($products_id,'5',".floatval($_POST["HPreis".$num.""]).",now())");
break;
}; //end switch
$num++;
}; // end foreach
}else{
$num1 = 0;
for ($num1 = 0; $num1 < 6; $num1++){
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_date_added) values ($products_id,$num1,".floatval($_POST["ArtikelVKHaendlerNetto"]).",now())");
}; //end for
$num = 1;
foreach ($haendlerKunden_arr as $hkgruppe) {
switch ($hkgruppe){
case 1:
eS_execute_query("update $table set specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='1'");
break;
case 2:
eS_execute_query("update $table set customers_group_id='2', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='2'");
break;
case 3:
eS_execute_query("update $table set customers_group_id='3', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='3'");
break;
case 4:
eS_execute_query("update $table set customers_group_id='4', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='4'");
break;
case 5:
eS_execute_query("update $table set customers_group_id='5', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='5'");
break;
}; //end switch
$num++;
}; // end foreach
}; //endifelse
}else{
//Update Artikel Nettopreise Kundengruppen einspielen
$specialOfferTable = "products_groups";
$table = $specialOfferTable;
$endKunden_arr = array(intval($_POST["PAnz1"]),intval($_POST["PAnz2"]),intval($_POST["PAnz3"]),intval($_POST["PAnz4"]),intval($_POST["PAnz5"]));
$SSPinArr = count ($endKunden_arr);
eS_execute_query("delete from $table where products_id=".$products_id);
for ($num = 1; $num < $SSPinArr; $num++){
$num2 = $num -1;
$SPPCGruppe = $endKunden_arr[$num2];
if (($endKunden_arr[$num-1] < '6') && (floatval($_POST["PPreis".$num.""]) > '0')){
eS_execute_query("insert into $table (customers_group_id, customers_group_price , products_id) values ($SPPCGruppe,".floatval($_POST["PPreis".$num.""]).",$products_id)");
}; //end if
}; //end for
//Update Artikel Sonderangebote Kundengruppen einspielen
$specialOfferTable = "specials";
$table = $specialOfferTable;
eS_execute_query("delete from $table where products_id=".$products_id);
$haendlerKunden_arr = array(intval($_POST["HAnz1"]),intval($_POST["HAnz2"]),intval($_POST["HAnz3"]),intval($_POST["HAnz4"]),intval($_POST["HAnz5"]));
if (floatval($_POST["ArtikelVKHaendlerNetto"]) == '0'){
$num = 1;
foreach ($haendlerKunden_arr as $hkgruppe) {
switch ($hkgruppe){
case 1:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_last_modified) values ($products_id,'1',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 2:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_last_modified) values ($products_id,'2',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 3:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_last_modified) values ($products_id,'3',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 4:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_last_modified) values ($products_id,'4',".floatval($_POST["HPreis".$num.""]).",now())");
break;
case 5:
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_last_modified) values ($products_id,'5',".floatval($_POST["HPreis".$num.""]).",now())");
break;
}; //end switch
$num++;
}; // end foreach
}else{
$num1 = 0;
for ($num1 = 0; $num1 < 6; $num1++){
eS_execute_query("insert into $table (products_id, customers_group_id, specials_new_products_price, specials_last_modified) values ($products_id,$num1,".floatval($_POST["ArtikelVKHaendlerNetto"]).",now())");
}; //end for
$num = 1;
foreach ($haendlerKunden_arr as $hkgruppe) {
switch ($hkgruppe){
case 1:
eS_execute_query("update $table set specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='1'");
break;
case 2:
eS_execute_query("update $table set customers_group_id='2', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='2'");
break;
case 3:
eS_execute_query("update $table set customers_group_id='3', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='3'");
break;
case 4:
eS_execute_query("update $table set customers_group_id='4', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='4'");
break;
case 5:
eS_execute_query("update $table set customers_group_id='5', specials_new_products_price=".floatval($_POST["HPreis".$num.""])." where products_id=\"".$products_id."\" AND customers_group_id='5'");
break;
}; //end switch
$num++;
}; // end foreach
}; //end ifelse
}; //end if
}
function holeHerstellerId($cHersteller)
{
if (strlen($cHersteller)>0)
{
//ex. dieser Hersteller?
$cur_query = eS_execute_query("select manufacturers_id from manufacturers where manufacturers_name=\"".$cHersteller."\"");
$manu = mysql_fetch_object($cur_query);
if ($manu->manufacturers_id>0)
return $manu->manufacturers_id;
else
{
//erstelle diesen Hersteller
eS_execute_query("insert into manufacturers (manufacturers_name, date_added) values (\"".$cHersteller."\", now())");
$query = eS_execute_query("select LAST_INSERT_ID()");
$manu_id_arr = mysql_fetch_row($query);
eS_execute_query("insert into manufacturers_info (manufacturers_id, languages_id) values (".$manu_id_arr[0].", ".$GLOBALS['einstellungen']->languages_id.")");
return $manu_id_arr[0];
}
}
return 0;
}
function holeSteuerId($MwSt)
{
//existiert so ein Steuersatz ?
$cur_query = eS_execute_query("select tax_class_id from tax_rates where tax_zone_id=".$GLOBALS['einstellungen']->tax_zone_id." and tax_rate=".$MwSt);
$tax = mysql_fetch_object($cur_query);
if ($tax->tax_class_id>0)
return $tax->tax_class_id;
else
{
//erstelle klasse
eS_execute_query("insert into tax_class (tax_class_title, date_added) values (\"JTL-Wawi Steuerklasse ".$MwSt."%\", now())");
$query = eS_execute_query("select LAST_INSERT_ID()");
$tax_class_id_arr = mysql_fetch_row($query);
//füge diesen Steuersatz ein
eS_execute_query("insert into tax_rates (tax_zone_id, tax_class_id, tax_priority, tax_rate, date_added) values (".$GLOBALS['einstellungen']->tax_zone_id.",".$tax_class_id_arr[0].", ".$GLOBALS['einstellungen']->tax_priority.", ".$MwSt.", now())");
return $tax_class_id_arr[0];
}
}
?>