diff --git a/classes/Components/Logger/Logger.php b/classes/Components/Logger/Logger.php index ea3a8b45..6371faba 100644 --- a/classes/Components/Logger/Logger.php +++ b/classes/Components/Logger/Logger.php @@ -10,6 +10,15 @@ use Xentral\Components\Logger\Handler\LogHandlerInterface; final class Logger extends AbstractLogger { + const EMERGENCY = 'emergency'; + const ALERT = 'alert'; + const CRITICAL = 'critical'; + const ERROR = 'error'; + const WARNING = 'warning'; + const NOTICE = 'notice'; + const INFO = 'info'; + const DEBUG = 'debug'; + /** @var LogHandlerInterface[] $levelHandlers */ private $logHandlers; diff --git a/cronjobs/artikeluebertragen.php b/cronjobs/artikeluebertragen.php index 88e7391f..d23f55f5 100644 --- a/cronjobs/artikeluebertragen.php +++ b/cronjobs/artikeluebertragen.php @@ -1,198 +1,270 @@ Container->get('Logger'); -class app_t { - var $DB; - var $erp; - var $user; - var $remote; +if (file_exists(dirname(__DIR__) . '/www/lib/class.erpapi_custom.php') && !class_exists('erpAPICustom')) { + include_once dirname(__DIR__) . '/www/lib/class.erpapi_custom.php'; } -*/ -//ENDE -if(file_exists(dirname(__DIR__).'/www/lib/class.erpapi_custom.php') && !class_exists('erpAPICustom')){ - include_once dirname(__DIR__) . '/www/lib/class.erpapi_custom.php'; +if (empty($app->Conf)) { + $conf = new Config(); + $app->Conf = $conf; } -if(empty($app->Conf)) { - $conf = new Config(); - $app->Conf = $conf; +if (empty($app->DB) || empty($app->DB->connection)) { + $app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport); } -if(empty($app->DB) || empty($app->DB->connection)) { - $app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport); -} -if(!isset($app->erp) || !$app->erp) { - if (class_exists('erpAPICustom')) { - $erp = new erpAPICustom($app); - } else { - $erp = new erpAPI($app); - } -//$remote = new Remote($app); - $app->erp = $erp; -//$app->remote= $remote; -} -if(empty($app->remote)) { - if(is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) { - if(!class_exists('RemoteCustom')){ - require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; +if (!isset($app->erp) || !$app->erp) { + if (class_exists('erpAPICustom')) { + $erp = new erpAPICustom($app); + } else { + $erp = new erpAPI($app); + } + $app->erp = $erp; +} +if (empty($app->remote)) { + if (is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) { + if (!class_exists('RemoteCustom')) { + require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; + } + $app->remote = new RemoteCustom($app); + } else { + $app->remote = new Remote($app); } - $app->remote = new RemoteCustom($app); - } - else { - $app->remote = new Remote($app); - } } -$app->erp->LogFile('Cronjob Artikeluebertragung Start'); +$logger->debug( + 'Start' +); $app->DB->Update( - "UPDATE `prozessstarter` + "UPDATE `prozessstarter` SET `mutexcounter` = `mutexcounter` + 1 WHERE `mutex` = 1 AND (`parameter` = 'artikeluebertragen') AND `aktiv` = 1" ); -if($app->DB->Select("SELECT `mutex` FROM `prozessstarter` WHERE (`parameter` = 'artikeluebertragen') LIMIT 1") == 1){ - return; +if ($app->DB->Select("SELECT `mutex` FROM `prozessstarter` WHERE (`parameter` = 'artikeluebertragen') LIMIT 1") == 1) { + $logger->debug( + 'Läuft bereits' + ); + return; } $articles = $app->DB->SelectArr( - 'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id` LIMIT 10' + 'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id`' ); -if(!empty($articles)) { - /** @var Shopexport $objShopexport */ - $objShopexport = $app->loadModule('shopexport'); - if($objShopexport !== null && method_exists($objShopexport, 'addChangedArticles')) { - $objShopexport->addChangedArticles(); - } +if (!empty($articles)) { + /** @var Shopexport $objShopexport */ + $objShopexport = $app->loadModule('shopexport'); + if ($objShopexport !== null && method_exists($objShopexport, 'addChangedArticles')) { + $objShopexport->addChangedArticles(); + } } +$logger->debug( + 'Prepare', + [ + 'articles' => $articles + ] +); + $anzChecked = []; $anzChanged = []; $lastids = []; -while(!empty($articles)) { - foreach($articles as $article) { - if(empty($anzChanged[$article['shop']])) { - $anzChanged[$article['shop']] = 0; +while (!empty($articles)) { + foreach ($articles as $article) { + if (empty($anzChanged[$article['shop']])) { + $anzChanged[$article['shop']] = 0; + } + if (empty($anzChecked[$article['shop']])) { + $anzChecked[$article['shop']] = 0; + } + if (!isset($lastids[$article['shop']])) { + $lastids[$article['shop']] = (int) $app->erp->GetKonfiguration( + 'shopexport_artikeluebertragen_check_lastid_' . $article['shop'] + ); + } + $changed = $objShopexport->hasArticleHashChanged($article['artikel'], $article['shop']); + if ($changed['changed']) { + $app->DB->Insert( + sprintf( + 'INSERT INTO `shopexport_artikeluebertragen` (`artikel`, `shop`, `check_nr`) VALUES (%d, %d, %d)', + $article['artikel'], $article['shop'], $lastids[$article['shop']] + ) + ); + $anzChanged[$article['shop']]++; + } + $anzChecked[$article['shop']]++; + $app->DB->Delete( + sprintf( + 'DELETE FROM `shopexport_artikeluebertragen_check` WHERE `id` = %d', + $article['id'] + ) + ); + $app->DB->Update( + sprintf( + "UPDATE `shopexport` SET `autosendarticle_last` = NOW() WHERE `id` = %d", + $article['shop'] + ) + ); } - if(empty($anzChecked[$article['shop']])) { - $anzChecked[$article['shop']] = 0; + $app->erp->SetKonfigurationValue( + 'shopexport_artikeluebertragen_check_changed_' . $article['shop'], + $anzChanged[$article['shop']] + ); + $app->erp->SetKonfigurationValue( + 'shopexport_artikeluebertragen_check_checked_' . $article['shop'], + $anzChecked[$article['shop']] + ); + if (method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) { + $logger->debug( + '!canRunCronjob' + ); + return; } - if(!isset($lastids[$article['shop']])) { - $lastids[$article['shop']] = (int)$app->erp->GetKonfiguration( - 'shopexport_artikeluebertragen_check_lastid_' . $article['shop'] - ); - } - $changed = $objShopexport->hasArticleHashChanged($article['artikel'], $article['shop']); - if($changed['changed']) { - $app->DB->Insert( - sprintf( - 'INSERT INTO `shopexport_artikeluebertragen` (`artikel`, `shop`, `check_nr`) VALUES (%d, %d, %d)', - $article['artikel'], $article['shop'], $lastids[$article['shop']] - ) - ); - $anzChanged[$article['shop']]++; - } - $anzChecked[$article['shop']]++; - $app->DB->Delete( - sprintf( - 'DELETE FROM `shopexport_artikeluebertragen_check` WHERE `id` = %d', - $article['id'] - ) + $articles = $app->DB->SelectArr( + 'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id` LIMIT 10' ); $app->DB->Update( - sprintf( - "UPDATE `shopexport` SET `autosendarticle_last` = NOW() WHERE `id` = %d", - $article['shop'] - ) - ); - } - $app->erp->SetKonfigurationValue( - 'shopexport_artikeluebertragen_check_changed_'.$article['shop'], - $anzChanged[$article['shop']] - ); - $app->erp->SetKonfigurationValue( - 'shopexport_artikeluebertragen_check_checked_'.$article['shop'], - $anzChecked[$article['shop']] - ); - if(method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) { - return; - } - $articles = $app->DB->SelectArr( - 'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id` LIMIT 10' - ); - $app->DB->Update( - "UPDATE `prozessstarter` + "UPDATE `prozessstarter` SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0 WHERE `parameter` = 'artikeluebertragen'" - ); + ); } $check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`'); $app->DB->Update( - "UPDATE `prozessstarter` + "UPDATE `prozessstarter` SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0 WHERE `parameter` = 'artikeluebertragen'" ); -while($check > 0) { - $shopartikel = $app->DB->Query( - "SELECT `id`,`shop`,`artikel`,`check_nr` FROM `shopexport_artikeluebertragen` ORDER BY `id` LIMIT 10" - ); - if(!empty($shopartikel)) { - $anz = 0; - while ($row = $app->DB->Fetch_Assoc($shopartikel)) { - if(!isset($lastids[$row['shop']])) { - $lastids[$row['shop']] = (int)$app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_lastid_' . $row['shop']); - } - $anz++; - try { - $app->remote->RemoteSendArticleList($row['shop'], array($row['artikel'])); - $app->erp->LagerSync($row['artikel'], true); - } - catch (Execption $exception) { - $app->erp->LogFile($app->DB->real_escape_string($exception->getMessage())); - } - $app->DB->Delete( - sprintf( - 'DELETE FROM `shopexport_artikeluebertragen` WHERE `id`= %d LIMIT 1', - $row['id'] - ) - ); +/* +while ($check > 0) { + $shopartikel = $app->DB->Query( + "SELECT `id`,`shop`,`artikel`,`check_nr` FROM `shopexport_artikeluebertragen` ORDER BY `id` LIMIT 10" + ); + if (!empty($shopartikel)) { + $anz = 0; + while ($row = $app->DB->Fetch_Assoc($shopartikel)) { + if (!isset($lastids[$row['shop']])) { + $lastids[$row['shop']] = (int) $app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_lastid_' . $row['shop']); + } - if(!empty($row['check_nr']) && $row['check_nr'] == $lastids[$row['shop']]) { - $transfered = 1+(int)$app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_transfered_'.$row['shop']); - $app->erp->SetKonfigurationValue('shopexport_artikeluebertragen_check_transfered_'.$row['shop'], $transfered); - } + $anz++; + try { + $app->remote->RemoteSendArticleList($row['shop'], array($row['artikel'])); + $app->erp->LagerSync($row['artikel'], true); + } catch (Execption $exception) { + $app->erp->LogFile($app->DB->real_escape_string($exception->getMessage())); + } + $app->DB->Delete( + sprintf( + 'DELETE FROM `shopexport_artikeluebertragen` WHERE `id`= %d LIMIT 1', + $row['id'] + ) + ); - $app->DB->Update( - "UPDATE `prozessstarter` + if (!empty($row['check_nr']) && $row['check_nr'] == $lastids[$row['shop']]) { + $transfered = 1 + (int) $app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_transfered_' . $row['shop']); + $app->erp->SetKonfigurationValue('shopexport_artikeluebertragen_check_transfered_' . $row['shop'], $transfered); + } + + $app->DB->Update( + "UPDATE `prozessstarter` SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0 WHERE `parameter` = 'artikeluebertragen'" - ); + ); + } + + $app->DB->free($shopartikel); } - $app->DB->free($shopartikel); - } + if (method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) { + return; + } - if(method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) { - return; - } + $check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`'); +}*/ - //sleep(20); // das performance nicht total spinnt - $check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`'); + +$sql = "SELECT DISTINCT `shop`, shopexport.`bezeichnung` FROM `shopexport_artikeluebertragen` INNER JOIN shopexport ON shopexport.id = `shop`"; +$shops_to_transmit = $app->DB->SelectArr($sql); + +//$app->erp->LogFile('Cronjob artikeluebertragen '.(!empty($shops_to_transmit)?count($shops_to_transmit):0)." shops", print_r($shops_to_transmit, true)); +$logger->debug( + '{count} Shops', + [ + 'count' => (!empty($shops_to_transmit)?count($shops_to_transmit):0), + 'shops_to_transmit' => $shops_to_transmit + ] +); + +foreach ($shops_to_transmit as $shop_to_transmit) { + $sql = "SELECT `artikel` FROM `shopexport_artikeluebertragen` WHERE `shop` = '".$shop_to_transmit['shop']."'"; + $articles_to_transmit = $app->DB->SelectArr($sql); + + $logger->debug( + '{bezeichnung} (Shop {shop_to_transmit}) {count} Artikel', + [ + 'shop_to_transmit' => $shop_to_transmit['shop'], + 'bezeichnung' => $shop_to_transmit['bezeichnung'], + 'count' => (!empty($articles_to_transmit)?count($articles_to_transmit):0), + 'articles_to_transmit' => $articles_to_transmit + ] + ); + + if (!empty($articles_to_transmit)) { + + $article_ids_to_transmit = array_column($articles_to_transmit, 'artikel'); + + try { + $result = $app->remote->RemoteSendArticleList($shop_to_transmit['shop'], $article_ids_to_transmit); // Expected result is array $articles_to_transmit, field status contains transmission status + } catch (Execption $exception) { + $logger->error( + 'Fehler {bezeichnung} (Shop {shop_to_transmit}) {count} Artikel', + [ + 'shop_to_transmit' => $shop_to_transmit['shop'], + 'bezeichnung' => $shop_to_transmit['bezeichnung'], + 'count' => (!empty($articles_to_transmit)?count($articles_to_transmit):0), + 'exception' => $exception + ] + ); + } + + $logger->debug( + 'Ende {bezeichnung} (Shop {shop_to_transmit}) {count} Artikel', + [ + 'shop_to_transmit' => $shop_to_transmit['shop'], + 'bezeichnung' => $shop_to_transmit['bezeichnung'], + 'count' => (!empty($articles_to_transmit)?count($articles_to_transmit):0), + 'result' => $result + ] + ); + + // See description of return format in function class.remote.php -> RemoteSendArticleList() + foreach ($result['articlelist'] as $article) { + $app->DB->Delete( + sprintf( + 'DELETE FROM `shopexport_artikeluebertragen` WHERE `artikel`= %d AND `shop` = %d', + $article['artikel'], + $shop_to_transmit['shop'] + ) + ); + $app->erp->LagerSync($article['artikel'], true); + } + } else { + + } } + +$logger->debug( + 'Ende' +); + $app->DB->Update( - "UPDATE `prozessstarter` + "UPDATE `prozessstarter` SET `letzteausfuerhung`= NOW(), `mutex` = 0,`mutexcounter`=0 WHERE `parameter` = 'artikeluebertragen'" ); - - diff --git a/cronjobs/lagerzahlen.php b/cronjobs/lagerzahlen.php index 4466331e..bd50830c 100644 --- a/cronjobs/lagerzahlen.php +++ b/cronjobs/lagerzahlen.php @@ -1,38 +1,37 @@ Conf)) { - $conf = new Config(); - $app->Conf = $conf; +if (empty($app->Conf)) { + $conf = new Config(); + $app->Conf = $conf; } -if(empty($app->DB)) { - $app->DB = new DB($app->Conf->WFdbhost,$app->Conf->WFdbname,$app->Conf->WFdbuser,$app->Conf->WFdbpass,null,$app->Conf->WFdbport); +if (empty($app->DB)) { + $app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport); } -if(empty($app->erp)) { - if(class_exists('erpAPICustom')) { - $erp = new erpAPICustom($app); - } - else { - $erp = new erpAPI($app); - } - $app->erp = $erp; -} -if(empty($app->remote)) { - if(is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')){ - if(!class_exists('RemoteCustom')) { - require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; +if (empty($app->erp)) { + if (class_exists('erpAPICustom')) { + $erp = new erpAPICustom($app); + } else { + $erp = new erpAPI($app); + } + $app->erp = $erp; +} +if (empty($app->remote)) { + if (is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) { + if (!class_exists('RemoteCustom')) { + require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; + } + $app->remote = new RemoteCustom($app); + } else { + $app->remote = new Remote($app); } - $app->remote = new RemoteCustom($app); - } - else { - $app->remote = new Remote($app); - } } $app->erp->LogFile("Lagerzahlen-Synchronisation Start"); @@ -40,34 +39,33 @@ $app->erp->LogFile("Lagerzahlen-Synchronisation Start"); $firmendatenid = $app->DB->Select("SELECT MAX(id) FROM firmendaten LIMIT 1"); - $app->DB->Update( +$app->DB->Update( "UPDATE `prozessstarter` SET `mutexcounter` = `mutexcounter` + 1 WHERE `mutex` = 1 AND `parameter` = 'lagerzahlen' AND `aktiv` = 1" - ); - if(!$app->DB->Select( +); +if (!$app->DB->Select( "SELECT `id` FROM `prozessstarter` WHERE `mutex` = 0 AND `parameter` = 'lagerzahlen' AND `aktiv` = 1" - )) { +)) { + $app->erp->LogFile("Lagerzahlen-Synchronisation Ende: Prozessstarter-Mutex nicht bereit"); return; - } - - $shops = $app->DB->SelectArr('SELECT * FROM `shopexport` WHERE `aktiv` = 1'); - if(empty($shops)) { +} +$shops = $app->DB->SelectArr('SELECT * FROM `shopexport` WHERE `aktiv` = 1'); +if (empty($shops)) { $app->erp->LogFile("Lagerzahlen-Synchronisation Ende: Keine aktiven Shops"); - return; - } - $shopByIds = []; - foreach($shops as $shop) { +} +$shopByIds = []; +foreach ($shops as $shop) { $shopByIds[$shop['id']] = $shop; - } - $shopIds = array_keys($shopByIds); - $shopIdsStr = implode(',', $shopIds); - $hours = 12; - $hoursShop = 48; - $lagerartikel = $app->DB->SelectFirstCols( - "SELECT a.id +} +$shopIds = array_keys($shopByIds); +$shopIdsStr = implode(',', $shopIds); +$hours = 12; +$hoursShop = 48; +$lagerartikel = $app->DB->SelectFirstCols( + "SELECT a.id FROM `artikel` AS `a` LEFT JOIN ( SELECT ao2.artikel, 1 AS `autolagerlampe`, @@ -97,91 +95,86 @@ $firmendatenid = $app->DB->Select("SELECT MAX(id) FROM firmendaten LIMIT 1"); ORDER BY a.cache_lagerplatzinhaltmenge = -999 DESC, ao.cache_reseted DESC, a.laststorage_sync" - ); - - if(empty($lagerartikel)) { +); +if (empty($lagerartikel)) { $app->erp->LogFile("Lagerzahlen-Synchronisation Ende: Keine fälligen Artikel"); - return; - } +} - try { +try { $r = new ReflectionMethod($app->erp, 'LagerSync'); $params = $r->getParameters(); $anzargs = count($params); - } - catch(Exception $e) { +} catch (Exception $e) { $anzargs = 2; - } +} - $clagerartikel = $lagerartikel?count($lagerartikel):0; - $app->erp->LogFile('Lagerzahlen-Synchronisation, Artikel gesamt: '.$clagerartikel); - foreach($lagerartikel as $ij => $articleId) { +$clagerartikel = $lagerartikel ? count($lagerartikel) : 0; +$app->erp->LogFile('Lagerzahlen-Synchronisation, Artikel gesamt: ' . $clagerartikel); +foreach ($lagerartikel as $articleCounter => $articleId) { $app->DB->Update( - "UPDATE `prozessstarter` + "UPDATE `prozessstarter` SET `mutex` = 1 , `mutexcounter` = 0, `letzteausfuerhung` = NOW() WHERE `parameter` = 'lagerzahlen' AND `aktiv` = 1" ); try { - if($anzargs > 2){ - $message .= $app->erp->LagerSync($articleId, false, $shopByIds); // 2nd parameter is print_echo -> prints via echo to logfile (big print_r) - }else{ - $message .= $app->erp->LagerSync($articleId, false); - } + if ($anzargs > 2) { + $message .= $app->erp->LagerSync($articleId, false, $shopByIds); // 2nd parameter is print_echo -> prints via echo to logfile (big print_r) + } else { + $message .= $app->erp->LagerSync($articleId, false); + } + } catch (Exception $exception) { + $message .= '
' . $exception->getMessage(); } - catch (Exception $exception) { - $message .= '
' . $exception->getMessage(); + if ($message != '') { + $message .= '
'; } - if($message!='') { - $message .='
'; + if ($articleCounter % 10 === 0 && method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['lagerzahlen'])) { + $app->DB->Update( + "UPDATE `prozessstarter` + SET `mutex` = 0 , `mutexcounter` = 0, `letzteausfuerhung` = NOW() + WHERE `parameter` = 'lagerzahlen' AND `aktiv` = 1" + ); + $app->erp->LogFile("Lagerzahlen-Synchronisation Ende: lagerzahlen-Job kann nicht geladen werden"); + return; } - if($ij % 10 === 0 && method_exists($app->erp, 'canRunCronjob') - && !$app->erp->canRunCronjob(['lagerzahlen'])) { - $app->DB->Update( - "UPDATE `prozessstarter` - SET `mutex` = 0 , `mutexcounter` = 0, `letzteausfuerhung` = NOW() - WHERE `parameter` = 'lagerzahlen' AND `aktiv` = 1" - ); - return; - } - usleep(10000); - } - $app->DB->Update( +// $app->erp->LogFile("Lagerzahlen-Synchronisation: Warte 10 Sekunden"); +// usleep(10000); +} +$app->DB->Update( "UPDATE `prozessstarter` SET `mutex` = 0 , `mutexcounter` = 0, `letzteausfuerhung` = NOW() WHERE `parameter` = 'lagerzahlen' AND `aktiv` = 1" - ); - if($message !='' && $erp->Firmendaten('systemmailsabschalten') == 0 && $erp->GetFirmaMail()!='') { +); +if ($message != '' && $erp->Firmendaten('systemmailsabschalten') == 0 && $erp->GetFirmaMail() != '') { try { - if($erp->Firmendaten('systemmailsempfaenger') != ''){ - $erp->MailSend( - $erp->GetFirmaMail(), - $erp->GetFirmaName(), - $erp->Firmendaten('systemmailsempfaenger'), - 'Lagerverwaltung', - 'Systemmeldung: Auto Update Lagerlampen', - $message - ); - - }else{ - if($erp->GetFirmaBCC1() != ''){ - $erp->MailSend( - $erp->GetFirmaMail(), - $erp->GetFirmaName(), - $erp->GetFirmaBCC1(), - 'Lagerverwaltung', - 'Systemmeldung: Auto Update Lagerlampen', - $message - ); + if ($erp->Firmendaten('systemmailsempfaenger') != '') { + $erp->MailSend( + $erp->GetFirmaMail(), + $erp->GetFirmaName(), + $erp->Firmendaten('systemmailsempfaenger'), + 'Lagerverwaltung', + 'Systemmeldung: Auto Update Lagerlampen', + $message + ); + } else { + if ($erp->GetFirmaBCC1() != '') { + $erp->MailSend( + $erp->GetFirmaMail(), + $erp->GetFirmaName(), + $erp->GetFirmaBCC1(), + 'Lagerverwaltung', + 'Systemmeldung: Auto Update Lagerlampen', + $message + ); + } } - } + } catch (Exception $exception) { + $app->erp->LogFile("Lagerzahlen-Synchronisation Exception:" . $app->DB->real_escape_string($exception->getMessage())); } - catch (Exception $exception) { - $app->erp->LogFile("Lagerzahlen-Synchronisation Exception:".$app->DB->real_escape_string($exception->getMessage())); - } - } +} - $app->erp->LogFile("Lagerzahlen-Synchronisation Ende"); +$app->erp->LogFile("Lagerzahlen-Synchronisation Ende"); diff --git a/cronjobs/shop_rueckmeldungen.php b/cronjobs/shop_rueckmeldungen.php index 0b01845a..3ec4dc97 100644 --- a/cronjobs/shop_rueckmeldungen.php +++ b/cronjobs/shop_rueckmeldungen.php @@ -1,392 +1,388 @@ 0) { - $aes = '2'; +$phpversion = (String) phpversion(); +if ($phpversion[0] == '7' && (int) $phpversion[2] > 0) { + $aes = '2'; } -if($aes == 2 && is_file(dirname(__DIR__).'/www/lib/class.aes2.php')) { - include_once dirname(__DIR__).'/www/lib/class.aes2.php'; -} -else{ - include_once dirname(__DIR__) . '/www/lib/class.aes.php'; +if ($aes == 2 && is_file(dirname(__DIR__) . '/www/lib/class.aes2.php')) { + include_once dirname(__DIR__) . '/www/lib/class.aes2.php'; +} else { + include_once dirname(__DIR__) . '/www/lib/class.aes.php'; } -$classes = array('briefpapier','lieferschein','auftrag','anfrage','gutschrift','bestellung','rechnung','mahnwesen'); -foreach($classes as $class) -{ - if(file_exists(dirname(__DIR__).'/www/lib/dokumente/class.'.$class.'_custom.php')) - { - include_once dirname(__DIR__).'/www/lib/dokumente/class.'.$class.'_custom.php'; - } - elseif(file_exists(dirname(__DIR__).'/www/lib/dokumente/class.'.$class.'.php')) { - include_once dirname(__DIR__).'/www/lib/dokumente/class.'.$class.'.php'; - } +$classes = array('briefpapier', 'lieferschein', 'auftrag', 'anfrage', 'gutschrift', 'bestellung', 'rechnung', 'mahnwesen'); +foreach ($classes as $class) { + if (file_exists(dirname(__DIR__) . '/www/lib/dokumente/class.' . $class . '_custom.php')) { + include_once dirname(__DIR__) . '/www/lib/dokumente/class.' . $class . '_custom.php'; + } elseif (file_exists(dirname(__DIR__) . '/www/lib/dokumente/class.' . $class . '.php')) { + include_once dirname(__DIR__) . '/www/lib/dokumente/class.' . $class . '.php'; + } } /* -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.briefpapier.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.lieferschein.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.auftrag.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.angebot.php"); -if(file_exists(dirname(__FILE__)."/../www/lib/dokumente/class.anfrage.php"))include_once(dirname(__FILE__)."/../www/lib/dokumente/class.anfrage.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.gutschrift.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.bestellung.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.rechnung.php"); -include_once(dirname(__FILE__)."/../www/lib/dokumente/class.mahnwesen.php");*/ -include_once dirname(__DIR__).'/phpwf/plugins/class.string.php'; -if(!class_exists('app_t2')) -{ - class app_t2 extends ApplicationCore { - var $DB; - var $erp; - var $User; - var $mail; - var $remote; - var $Secure; -function GetLandLang($isocode) -{ - $flipped = array_flip($this->GetLaender()); - if(isset($flipped[$isocode])) - $land = $flipped[$isocode]; - else { - $land = 'unkown'; - } - return $land; -} + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.briefpapier.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.lieferschein.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.auftrag.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.angebot.php"); + if(file_exists(dirname(__FILE__)."/../www/lib/dokumente/class.anfrage.php"))include_once(dirname(__FILE__)."/../www/lib/dokumente/class.anfrage.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.gutschrift.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.bestellung.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.rechnung.php"); + include_once(dirname(__FILE__)."/../www/lib/dokumente/class.mahnwesen.php"); */ +include_once dirname(__DIR__) . '/phpwf/plugins/class.string.php'; +if (!class_exists('app_t2')) { + + class app_t2 extends ApplicationCore { + + var $DB; + var $erp; + var $User; + var $mail; + var $remote; + var $Secure; + + function GetLandLang($isocode) { + $flipped = array_flip($this->GetLaender()); + if (isset($flipped[$isocode])) + $land = $flipped[$isocode]; + else { + $land = 'unkown'; + } + return $land; + } + + function GetLaender() { + $laender = array( + 'Afghanistan' => 'AF', + 'Ägypten' => 'EG', + 'Albanien' => 'AL', + 'Algerien' => 'DZ', + 'Andorra' => 'AD', + 'Angola' => 'AO', + 'Anguilla' => 'AI', + 'Antarktis' => 'AQ', + 'Antigua und Barbuda' => 'AG', + 'Äquatorial Guinea' => 'GQ', + 'Argentinien' => 'AR', + 'Armenien' => 'AM', + 'Aruba' => 'AW', + 'Aserbaidschan' => 'AZ', + 'Äthiopien' => 'ET', + 'Australien' => 'AU', + 'Bahamas' => 'BS', + 'Bahrain' => 'BH', + 'Bangladesh' => 'BD', + 'Barbados' => 'BB', + 'Belgien' => 'BE', + 'Belize' => 'BZ', + 'Benin' => 'BJ', + 'Bermudas' => 'BM', + 'Bhutan' => 'BT', + 'Birma' => 'MM', + 'Bolivien' => 'BO', + 'Bosnien-Herzegowina' => 'BA', + 'Botswana' => 'BW', + 'Bouvet Inseln' => 'BV', + 'Brasilien' => 'BR', + 'Britisch-Indischer Ozean' => 'IO', + 'Brunei' => 'BN', + 'Bulgarien' => 'BG', + 'Burkina Faso' => 'BF', + 'Burundi' => 'BI', + 'Chile' => 'CL', + 'China' => 'CN', + 'Christmas Island' => 'CX', + 'Cook Inseln' => 'CK', + 'Costa Rica' => 'CR', + 'Dänemark' => 'DK', + 'Deutschland' => 'DE', + 'Djibuti' => 'DJ', + 'Dominika' => 'DM', + 'Dominikanische Republik' => 'DO', + 'Ecuador' => 'EC', + 'El Salvador' => 'SV', + 'Elfenbeinküste' => 'CI', + 'Eritrea' => 'ER', + 'Estland' => 'EE', + 'Falkland Inseln' => 'FK', + 'Färöer Inseln' => 'FO', + 'Fidschi' => 'FJ', + 'Finnland' => 'FI', + 'Frankreich' => 'FR', + 'Französisch Guyana' => 'GF', + 'Französisch Polynesien' => 'PF', + 'Französisches Süd-Territorium' => 'TF', + 'Gabun' => 'GA', + 'Gambia' => 'GM', + 'Georgien' => 'GE', + 'Ghana' => 'GH', + 'Gibraltar' => 'GI', + 'Grenada' => 'GD', + 'Griechenland' => 'GR', + 'Grönland' => 'GL', + 'Großbritannien' => 'UK', + 'Großbritannien (UK)' => 'GB', + 'Guadeloupe' => 'GP', + 'Guam' => 'GU', + 'Guatemala' => 'GT', + 'Guinea' => 'GN', + 'Guinea Bissau' => 'GW', + 'Guyana' => 'GY', + 'Haiti' => 'HT', + 'Heard und McDonald Islands' => 'HM', + 'Honduras' => 'HN', + 'Hong Kong' => 'HK', + 'Indien' => 'IN', + 'Indonesien' => 'ID', + 'Irak' => 'IQ', + 'Iran' => 'IR', + 'Irland' => 'IE', + 'Island' => 'IS', + 'Israel' => 'IL', + 'Italien' => 'IT', + 'Jamaika' => 'JM', + 'Japan' => 'JP', + 'Jemen' => 'YE', + 'Jordanien' => 'JO', + 'Jugoslawien' => 'YU', + 'Kaiman Inseln' => 'KY', + 'Kambodscha' => 'KH', + 'Kamerun' => 'CM', + 'Kanada' => 'CA', + 'Kap Verde' => 'CV', + 'Kasachstan' => 'KZ', + 'Kenia' => 'KE', + 'Kirgisistan' => 'KG', + 'Kiribati' => 'KI', + 'Kokosinseln' => 'CC', + 'Kolumbien' => 'CO', + 'Komoren' => 'KM', + 'Kongo' => 'CG', + 'Kongo, Demokratische Republik' => 'CD', + 'Kosovo' => 'KO', + 'Kroatien' => 'HR', + 'Kuba' => 'CU', + 'Kuwait' => 'KW', + 'Laos' => 'LA', + 'Lesotho' => 'LS', + 'Lettland' => 'LV', + 'Libanon' => 'LB', + 'Liberia' => 'LR', + 'Libyen' => 'LY', + 'Liechtenstein' => 'LI', + 'Litauen' => 'LT', + 'Luxemburg' => 'LU', + 'Macao' => 'MO', + 'Madagaskar' => 'MG', + 'Malawi' => 'MW', + 'Malaysia' => 'MY', + 'Malediven' => 'MV', + 'Mali' => 'ML', + 'Malta' => 'MT', + 'Marianen' => 'MP', + 'Marokko' => 'MA', + 'Marshall Inseln' => 'MH', + 'Martinique' => 'MQ', + 'Mauretanien' => 'MR', + 'Mauritius' => 'MU', + 'Mayotte' => 'YT', + 'Mazedonien' => 'MK', + 'Mexiko' => 'MX', + 'Mikronesien' => 'FM', + 'Mocambique' => 'MZ', + 'Moldavien' => 'MD', + 'Monaco' => 'MC', + 'Mongolei' => 'MN', + 'Montenegro' => 'ME', + 'Montserrat' => 'MS', + 'Namibia' => 'NA', + 'Nauru' => 'NR', + 'Nepal' => 'NP', + 'Neukaledonien' => 'NC', + 'Neuseeland' => 'NZ', + 'Nicaragua' => 'NI', + 'Niederlande' => 'NL', + 'Niederländische Antillen' => 'AN', + 'Niger' => 'NE', + 'Nigeria' => 'NG', + 'Niue' => 'NU', + 'Nord Korea' => 'KP', + 'Norfolk Inseln' => 'NF', + 'Norwegen' => 'NO', + 'Oman' => 'OM', + 'Österreich' => 'AT', + 'Pakistan' => 'PK', + 'Palästina' => 'PS', + 'Palau' => 'PW', + 'Panama' => 'PA', + 'Papua Neuguinea' => 'PG', + 'Paraguay' => 'PY', + 'Peru' => 'PE', + 'Philippinen' => 'PH', + 'Pitcairn' => 'PN', + 'Polen' => 'PL', + 'Portugal' => 'PT', + 'Puerto Rico' => 'PR', + 'Qatar' => 'QA', + 'Reunion' => 'RE', + 'Ruanda' => 'RW', + 'Rumänien' => 'RO', + 'Rußland' => 'RU', + 'Saint Lucia' => 'LC', + 'Sambia' => 'ZM', + 'Samoa' => 'AS', + 'Samoa' => 'WS', + 'San Marino' => 'SM', + 'Sao Tome' => 'ST', + 'Saudi Arabien' => 'SA', + 'Schweden' => 'SE', + 'Schweiz' => 'CH', + 'Senegal' => 'SN', + 'Serbien' => 'RS', + 'Seychellen' => 'SC', + 'Sierra Leone' => 'SL', + 'Singapur' => 'SG', + 'Slowakei -slowakische Republik-' => 'SK', + 'Slowenien' => 'SI', + 'Solomon Inseln' => 'SB', + 'Somalia' => 'SO', + 'South Georgia, South Sandwich Isl.' => 'GS', + 'Spanien' => 'ES', + 'Sri Lanka' => 'LK', + 'St. Helena' => 'SH', + 'St. Kitts Nevis Anguilla' => 'KN', + 'St. Pierre und Miquelon' => 'PM', + 'St. Vincent' => 'VC', + 'Süd Korea' => 'KR', + 'Südafrika' => 'ZA', + 'Sudan' => 'SD', + 'Surinam' => 'SR', + 'Svalbard und Jan Mayen Islands' => 'SJ', + 'Swasiland' => 'SZ', + 'Syrien' => 'SY', + 'Tadschikistan' => 'TJ', + 'Taiwan' => 'TW', + 'Tansania' => 'TZ', + 'Thailand' => 'TH', + 'Timor' => 'TP', + 'Togo' => 'TG', + 'Tokelau' => 'TK', + 'Tonga' => 'TO', + 'Trinidad Tobago' => 'TT', + 'Tschad' => 'TD', + 'Tschechische Republik' => 'CZ', + 'Tunesien' => 'TN', + 'Türkei' => 'TR', + 'Turkmenistan' => 'TM', + 'Turks und Kaikos Inseln' => 'TC', + 'Tuvalu' => 'TV', + 'Uganda' => 'UG', + 'Ukraine' => 'UA', + 'Ungarn' => 'HU', + 'Uruguay' => 'UY', + 'Usbekistan' => 'UZ', + 'Vanuatu' => 'VU', + 'Vatikan' => 'VA', + 'Venezuela' => 'VE', + 'Vereinigte Arabische Emirate' => 'AE', + 'Vereinigte Staaten von Amerika' => 'US', + 'Vietnam' => 'VN', + 'Virgin Island (Brit.)' => 'VG', + 'Virgin Island (USA)' => 'VI', + 'Wallis et Futuna' => 'WF', + 'Weißrußland' => 'BY', + 'Westsahara' => 'EH', + 'Zentralafrikanische Republik' => 'CF', + 'Zimbabwe' => 'ZW', + 'Zypern' => 'CY' + ); + return $laender; + } + } -function GetLaender() -{ - $laender = array( - 'Afghanistan' => 'AF', - 'Ägypten' => 'EG', - 'Albanien' => 'AL', - 'Algerien' => 'DZ', - 'Andorra' => 'AD', - 'Angola' => 'AO', - 'Anguilla' => 'AI', - 'Antarktis' => 'AQ', - 'Antigua und Barbuda' => 'AG', - 'Äquatorial Guinea' => 'GQ', - 'Argentinien' => 'AR', - 'Armenien' => 'AM', - 'Aruba' => 'AW', - 'Aserbaidschan' => 'AZ', - 'Äthiopien' => 'ET', - 'Australien' => 'AU', - 'Bahamas' => 'BS', - 'Bahrain' => 'BH', - 'Bangladesh' => 'BD', - 'Barbados' => 'BB', - 'Belgien' => 'BE', - 'Belize' => 'BZ', - 'Benin' => 'BJ', - 'Bermudas' => 'BM', - 'Bhutan' => 'BT', - 'Birma' => 'MM', - 'Bolivien' => 'BO', - 'Bosnien-Herzegowina' => 'BA', - 'Botswana' => 'BW', - 'Bouvet Inseln' => 'BV', - 'Brasilien' => 'BR', - 'Britisch-Indischer Ozean' => 'IO', - 'Brunei' => 'BN', - 'Bulgarien' => 'BG', - 'Burkina Faso' => 'BF', - 'Burundi' => 'BI', - 'Chile' => 'CL', - 'China' => 'CN', - 'Christmas Island' => 'CX', - 'Cook Inseln' => 'CK', - 'Costa Rica' => 'CR', - 'Dänemark' => 'DK', - 'Deutschland' => 'DE', - 'Djibuti' => 'DJ', - 'Dominika' => 'DM', - 'Dominikanische Republik' => 'DO', - 'Ecuador' => 'EC', - 'El Salvador' => 'SV', - 'Elfenbeinküste' => 'CI', - 'Eritrea' => 'ER', - 'Estland' => 'EE', - 'Falkland Inseln' => 'FK', - 'Färöer Inseln' => 'FO', - 'Fidschi' => 'FJ', - 'Finnland' => 'FI', - 'Frankreich' => 'FR', - 'Französisch Guyana' => 'GF', - 'Französisch Polynesien' => 'PF', - 'Französisches Süd-Territorium' => 'TF', - 'Gabun' => 'GA', - 'Gambia' => 'GM', - 'Georgien' => 'GE', - 'Ghana' => 'GH', - 'Gibraltar' => 'GI', - 'Grenada' => 'GD', - 'Griechenland' => 'GR', - 'Grönland' => 'GL', - 'Großbritannien' => 'UK', - 'Großbritannien (UK)' => 'GB', - 'Guadeloupe' => 'GP', - 'Guam' => 'GU', - 'Guatemala' => 'GT', - 'Guinea' => 'GN', - 'Guinea Bissau' => 'GW', - 'Guyana' => 'GY', - 'Haiti' => 'HT', - 'Heard und McDonald Islands' => 'HM', - 'Honduras' => 'HN', - 'Hong Kong' => 'HK', - 'Indien' => 'IN', - 'Indonesien' => 'ID', - 'Irak' => 'IQ', - 'Iran' => 'IR', - 'Irland' => 'IE', - 'Island' => 'IS', - 'Israel' => 'IL', - 'Italien' => 'IT', - 'Jamaika' => 'JM', - 'Japan' => 'JP', - 'Jemen' => 'YE', - 'Jordanien' => 'JO', - 'Jugoslawien' => 'YU', - 'Kaiman Inseln' => 'KY', - 'Kambodscha' => 'KH', - 'Kamerun' => 'CM', - 'Kanada' => 'CA', - 'Kap Verde' => 'CV', - 'Kasachstan' => 'KZ', - 'Kenia' => 'KE', - 'Kirgisistan' => 'KG', - 'Kiribati' => 'KI', - 'Kokosinseln' => 'CC', - 'Kolumbien' => 'CO', - 'Komoren' => 'KM', - 'Kongo' => 'CG', - 'Kongo, Demokratische Republik' => 'CD', - 'Kosovo' => 'KO', - 'Kroatien' => 'HR', - 'Kuba' => 'CU', - 'Kuwait' => 'KW', - 'Laos' => 'LA', - 'Lesotho' => 'LS', - 'Lettland' => 'LV', - 'Libanon' => 'LB', - 'Liberia' => 'LR', - 'Libyen' => 'LY', - 'Liechtenstein' => 'LI', - 'Litauen' => 'LT', - 'Luxemburg' => 'LU', - 'Macao' => 'MO', - 'Madagaskar' => 'MG', - 'Malawi' => 'MW', - 'Malaysia' => 'MY', - 'Malediven' => 'MV', - 'Mali' => 'ML', - 'Malta' => 'MT', - 'Marianen' => 'MP', - 'Marokko' => 'MA', - 'Marshall Inseln' => 'MH', - 'Martinique' => 'MQ', - 'Mauretanien' => 'MR', - 'Mauritius' => 'MU', - 'Mayotte' => 'YT', - 'Mazedonien' => 'MK', - 'Mexiko' => 'MX', - 'Mikronesien' => 'FM', - 'Mocambique' => 'MZ', - 'Moldavien' => 'MD', - 'Monaco' => 'MC', - 'Mongolei' => 'MN', - 'Montenegro' => 'ME', - 'Montserrat' => 'MS', - 'Namibia' => 'NA', - 'Nauru' => 'NR', - 'Nepal' => 'NP', - 'Neukaledonien' => 'NC', - 'Neuseeland' => 'NZ', - 'Nicaragua' => 'NI', - 'Niederlande' => 'NL', - 'Niederländische Antillen' => 'AN', - 'Niger' => 'NE', - 'Nigeria' => 'NG', - 'Niue' => 'NU', - 'Nord Korea' => 'KP', - 'Norfolk Inseln' => 'NF', - 'Norwegen' => 'NO', - 'Oman' => 'OM', - 'Österreich' => 'AT', - 'Pakistan' => 'PK', - 'Palästina' => 'PS', - 'Palau' => 'PW', - 'Panama' => 'PA', - 'Papua Neuguinea' => 'PG', - 'Paraguay' => 'PY', - 'Peru' => 'PE', - 'Philippinen' => 'PH', - 'Pitcairn' => 'PN', - 'Polen' => 'PL', - 'Portugal' => 'PT', - 'Puerto Rico' => 'PR', - 'Qatar' => 'QA', - 'Reunion' => 'RE', - 'Ruanda' => 'RW', - 'Rumänien' => 'RO', - 'Rußland' => 'RU', - 'Saint Lucia' => 'LC', - 'Sambia' => 'ZM', - 'Samoa' => 'AS', - 'Samoa' => 'WS', - 'San Marino' => 'SM', - 'Sao Tome' => 'ST', - 'Saudi Arabien' => 'SA', - 'Schweden' => 'SE', - 'Schweiz' => 'CH', - 'Senegal' => 'SN', - 'Serbien' => 'RS', - 'Seychellen' => 'SC', - 'Sierra Leone' => 'SL', - 'Singapur' => 'SG', - 'Slowakei -slowakische Republik-' => 'SK', - 'Slowenien' => 'SI', - 'Solomon Inseln' => 'SB', - 'Somalia' => 'SO', - 'South Georgia, South Sandwich Isl.' => 'GS', - 'Spanien' => 'ES', - 'Sri Lanka' => 'LK', - 'St. Helena' => 'SH', - 'St. Kitts Nevis Anguilla' => 'KN', - 'St. Pierre und Miquelon' => 'PM', - 'St. Vincent' => 'VC', - 'Süd Korea' => 'KR', - 'Südafrika' => 'ZA', - 'Sudan' => 'SD', - 'Surinam' => 'SR', - 'Svalbard und Jan Mayen Islands' => 'SJ', - 'Swasiland' => 'SZ', - 'Syrien' => 'SY', - 'Tadschikistan' => 'TJ', - 'Taiwan' => 'TW', - 'Tansania' => 'TZ', - 'Thailand' => 'TH', - 'Timor' => 'TP', - 'Togo' => 'TG', - 'Tokelau' => 'TK', - 'Tonga' => 'TO', - 'Trinidad Tobago' => 'TT', - 'Tschad' => 'TD', - 'Tschechische Republik' => 'CZ', - 'Tunesien' => 'TN', - 'Türkei' => 'TR', - 'Turkmenistan' => 'TM', - 'Turks und Kaikos Inseln' => 'TC', - 'Tuvalu' => 'TV', - 'Uganda' => 'UG', - 'Ukraine' => 'UA', - 'Ungarn' => 'HU', - 'Uruguay' => 'UY', - 'Usbekistan' => 'UZ', - 'Vanuatu' => 'VU', - 'Vatikan' => 'VA', - 'Venezuela' => 'VE', - 'Vereinigte Arabische Emirate' => 'AE', - 'Vereinigte Staaten von Amerika' => 'US', - 'Vietnam' => 'VN', - 'Virgin Island (Brit.)' => 'VG', - 'Virgin Island (USA)' => 'VI', - 'Wallis et Futuna' => 'WF', - 'Weißrußland' => 'BY', - 'Westsahara' => 'EH', - 'Zentralafrikanische Republik' => 'CF', - 'Zimbabwe' => 'ZW', - 'Zypern' => 'CY' - ); - return $laender; -} - } } //ENDE - if(empty($app) || !class_exists('ApplicationCore') || !($app instanceof ApplicationCore)) { +if (empty($app) || !class_exists('ApplicationCore') || !($app instanceof ApplicationCore)) { $app = new app_t2(); - } - if(empty($app->Conf)){ +} +if (empty($app->Conf)) { $conf = new Config(); $app->Conf = $conf; - } - if(empty($app->DB)){ +} +if (empty($app->DB)) { $app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport); - } - if(empty($app->erp)){ +} +if (empty($app->erp)) { $erp = new erpAPI($app); $app->erp = $erp; - } - $app->String = new WawiString(); - if(empty($app->remote)){ - if(is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')){ - require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; - $app->remote = new RemoteCustom($app); +} +$app->String = new WawiString(); +if (empty($app->remote)) { + if (is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) { + require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; + $app->remote = new RemoteCustom($app); + } else { + $app->remote = new Remote($app); } - else{ - $app->remote = new Remote($app); - } - } - //$app->remote = new Remote($app); - $app->Secure = new Secure($app); - $app->User = new User($app); - if(!defined('FPDF_FONTPATH')) { - define('FPDF_FONTPATH',dirname(__DIR__).'/www/lib/pdf/font/'); - } - +} +//$app->remote = new Remote($app); +$app->Secure = new Secure($app); +$app->User = new User($app); +if (!defined('FPDF_FONTPATH')) { + define('FPDF_FONTPATH', dirname(__DIR__) . '/www/lib/pdf/font/'); +} //ENDE - const MAXIMUM_NUMBER_OF_TRIES = 10; +const MAXIMUM_NUMBER_OF_TRIES = 10; - $shops = $app->DB->SelectFirstCols( - 'SELECT id FROM shopexport WHERE auftragabgleich = 1 AND aktiv = 1 AND demomodus <> 1 AND sendonlywithtracking = 0' - ); - if(empty($shops)) { +$shops = $app->DB->SelectFirstCols( + 'SELECT id FROM shopexport WHERE auftragabgleich = 1 AND aktiv = 1 AND demomodus <> 1 AND sendonlywithtracking = 0' +); +if (empty($shops)) { return; - } - $app->DB->Update("UPDATE prozessstarter SET mutexcounter = mutexcounter + 1 WHERE mutex = 1 AND (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); - if(!$app->DB->Select("SELECT id FROM prozessstarter WHERE mutex = 0 AND (parameter = 'shop_rueckmeldungen') AND aktiv = 1")) { +} +$app->DB->Update("UPDATE prozessstarter SET mutexcounter = mutexcounter + 1 WHERE mutex = 1 AND (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); +if (!$app->DB->Select("SELECT id FROM prozessstarter WHERE mutex = 0 AND (parameter = 'shop_rueckmeldungen') AND aktiv = 1")) { return; - } - $app->DB->Update("UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); +} +$app->DB->Update("UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); - $subwhere = sprintf(' a.shop IN (%s) ', implode(',', $shops)); - $join = ''; - $where = ''; - $app->erp->RunHook('shop_rueckmeldung', 2, $join, $where); +$subwhere = sprintf(' a.shop IN (%s) ', implode(',', $shops)); +$join = ''; +$where = ''; +$app->erp->RunHook('shop_rueckmeldung', 2, $join, $where); $sql = "SELECT DISTINCT a.id, a.shop FROM auftrag a LEFT JOIN lieferschein l on l.auftragid = a.id @@ -404,7 +400,7 @@ function GetLaender() ((pr.kommissionierverfahren = 'lieferschein' OR pr.kommissionierverfahren = 'rechnungsmail') AND isnull(v.id)) ) AND (ISNULL(a.shop_status_update_last_attempt_at) OR a.shop_status_update_last_attempt_at < DATE_SUB(NOW(), INTERVAL 4 HOUR)) - AND a.shop_status_update_attempt <= ".MAXIMUM_NUMBER_OF_TRIES." + AND a.shop_status_update_attempt <= " . MAXIMUM_NUMBER_OF_TRIES . " $where ORDER BY a.id, l.id DESC, v.id DESC "; @@ -412,33 +408,33 @@ function GetLaender() $auftraege = $app->DB->SelectArr($sql); if(!empty($auftraege)) { $app->DB->Update( - "UPDATE prozessstarter + "UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1" ); $auftragid = null; $countRequests = 0; - foreach($auftraege as $auftrag) { - if($auftrag['id'] != $auftragid) { - $countRequests++; - $auftragid = $auftrag['id']; - $app->remote->RemoteUpdateAuftrag($auftrag['shop'], $auftrag['id']); - if($countRequests % 10 === 0) { - $app->DB->Update( - "UPDATE prozessstarter + foreach ($auftraege as $auftrag) { + if ($auftrag['id'] != $auftragid) { + $countRequests++; + $auftragid = $auftrag['id']; + $app->remote->RemoteUpdateAuftrag($auftrag['shop'], $auftrag['id']); + if ($countRequests % 10 === 0) { + $app->DB->Update( + "UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE parameter = 'shop_rueckmeldungen' AND aktiv = 1" - ); + ); + } } - } } unset($auftraege); - } - $app->DB->Update("UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); +} +$app->DB->Update("UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); - //Zahlungsstatus - $query = $app->DB->Query( - "SELECT a.id +//Zahlungsstatus +$query = $app->DB->Query( + "SELECT a.id FROM `auftrag` AS `a` LEFT JOIN `rechnung` AS `r1` ON r1.id = a.rechnungid LEFT JOIN `rechnung` AS `r2` ON r2.auftragid = a.id @@ -449,21 +445,22 @@ function GetLaender() AND (r1.zahlungsstatus = 'bezahlt' OR r2.zahlungsstatus = 'bezahlt') AND DATEDIFF(NOW(), a.datum) <= 28 GROUP BY a.id LIMIT 1000" - ); - if($query) { +); +if ($query) { $countRequests = 0; - while($row = $app->DB->Fetch_Assoc($query)) { - $app->erp->ImportUpdateZahlungsstatus($row['id']); - $countRequests++; - if($countRequests % 10 === 0) { - $app->DB->Update( - "UPDATE prozessstarter + while ($row = $app->DB->Fetch_Assoc($query)) { + $app->erp->ImportUpdateZahlungsstatus($row['id']); + $countRequests++; + if ($countRequests % 10 === 0) { + $app->DB->Update( + "UPDATE prozessstarter SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now() WHERE parameter = 'shop_rueckmeldungen' AND aktiv = 1" - ); - } + ); + } } $app->DB->free($query); - } +} + +$app->DB->Update("UPDATE prozessstarter SET mutex = 0, mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); - $app->DB->Update("UPDATE prozessstarter SET mutex = 0, mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = 'shop_rueckmeldungen' ) AND aktiv = 1"); diff --git a/upgrade/data/db_schema.json b/upgrade/data/db_schema.json index 553f4e2e..0b440a32 100644 --- a/upgrade/data/db_schema.json +++ b/upgrade/data/db_schema.json @@ -18692,6 +18692,14 @@ "id" ], "Non_unique": "" + }, + { + "Key_name": "eigenschaft_unique", + "Index_type": "BTREE", + "columns": [ + "name" + ], + "Non_unique": "UNIQUE" } ] }, @@ -18802,6 +18810,15 @@ "artikel" ], "Non_unique": "" + }, + { + "Key_name": "eigenschaft_artikel_unique", + "Index_type": "BTREE", + "columns": [ + "artikel", + "artikeleigenschaften" + ], + "Non_unique": "UNIQUE" } ] }, diff --git a/www/lib/ShopimporterBase.php b/www/lib/ShopimporterBase.php index 0e3795a7..716b1469 100644 --- a/www/lib/ShopimporterBase.php +++ b/www/lib/ShopimporterBase.php @@ -1329,6 +1329,46 @@ Class ShopimporterBase{ 'metabeschreibung' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], 'metakeywords' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], 'freifelder' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + ], + 'shopimporter_mirakl' => [ + 'auftrag' => ['createarticle' => self::UNDEFINED, 'updatearticle' => self::UNDEFINED, 'importarticle' => self::UNDEFINED, 'importorder' => self::UNDEFINED], + 'artikelname' => ['createarticle' => self::MUST, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CAN], + 'artikelnummer' => ['createarticle' => self::MUST, 'updatearticle' => self::MUST, 'importarticle' => self::CANNOT, 'importorder' => self::CAN], + 'aktiv' => ['createarticle' => self::MUST, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'restmenge' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'beschreibung' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CAN], + 'ean' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'hersteller' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'herstellerlink' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'herstellernummer' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'zolltarifnummer' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'gewicht' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'einheit' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'laenge' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'hoehe' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'breite' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'verkaufspreis' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CAN], + 'pseudopreis' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'lagerzahlen' => ['createarticle' => self::MUST, 'updatearticle' => self::MUST, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'pseudolager' => ['createarticle' => self::MUST, 'updatearticle' => self::MUST, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'staffelpreise' => ['createarticle' => self::MUST, 'updatearticle' => self::MUST, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'gruppenpreise' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'fremdsprachen' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'kategorie' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'kategoriebaum' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'bilder' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'varianten' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'matrixeigenschaften' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'über 5000 Varianten' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'eigenschaften' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'crossselling' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'kurztext' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'herkunftsland' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'umsatzsteuer' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'metatitel' => ['createarticle' => self::CANNOT, 'updatearticle' => self::CANNOT, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'metabeschreibung' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'metakeywords' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], + 'freifelder' => ['createarticle' => self::CAN, 'updatearticle' => self::CAN, 'importarticle' => self::CANNOT, 'importorder' => self::CANNOT], ], 'shopimporter_modified' => [ 'auftrag' => ['createarticle' => self::UNDEFINED, 'updatearticle' => self::UNDEFINED, 'importarticle' => self::UNDEFINED, 'importorder' => self::UNDEFINED], diff --git a/www/lib/class.erpapi.php b/www/lib/class.erpapi.php index 9b153b78..20ea009e 100644 --- a/www/lib/class.erpapi.php +++ b/www/lib/class.erpapi.php @@ -17199,7 +17199,7 @@ function CheckShopTabelle($artikel) return $taxrates; } - function ImportAuftrag($adresse,$warenkorb,$projekt,$shop="",$auftrag=0) + function ImportAuftrag($adresse,$warenkorb,$projekt,$shop="",$auftrag=0) : array { $this->RunHook('ImportAuftragBefore',4, $adresse,$warenkorb,$projekt,$shop); if(!empty($this->app->stringcleaner)){ @@ -17711,6 +17711,9 @@ function CheckShopTabelle($artikel) if($doctype === 'angebot'){ $this->app->DB->Update("UPDATE angebot SET anfrage = '".$this->app->DB->real_escape_string($warenkorb['onlinebestellnummer'])."' WHERE id = '$auftrag' LIMIT 1"); } + if($doctype === 'auftrag'){ + $this->app->DB->Update("UPDATE auftrag SET ihrebestellnummer = '".$this->app->DB->real_escape_string($warenkorb['ihrebestellnummer'])."' WHERE id = '$auftrag' LIMIT 1"); + } $this->app->DB->Update("UPDATE $doctype SET belegnr='$belegnr', @@ -18674,16 +18677,24 @@ function CheckShopTabelle($artikel) $artikelporto = $artikelportoermaessigt; } - if(empty($artikelporto) && $this->app->DB->Select("SELECT portoartikelanlegen FROM shopexport WHERE id = '$shop' LIMIT 1")) - { - if($warenkorb['versandkostennetto'] != 0 || $warenkorb['versandkostenbrutto'] != 0 || $portocheck == 1){ - $portoartikelarr = array('projekt'=>$projekt,'porto'=>1, 'lagerartikel'=>0,'name_de'=>'Porto','umsatzsteuer'=>'normal'); - $artikelporto = $this->app->erp->InsertUpdateArtikel($portoartikelarr); - if($artikelporto){ - $this->app->DB->Update("UPDATE shopexport SET artikelporto = '$artikelporto' WHERE id = '$shop' AND artikelporto = 0 LIMIT 1"); - } + if(empty($artikelporto)) { + if ($this->app->DB->Select("SELECT portoartikelanlegen FROM shopexport WHERE id = '$shop' LIMIT 1")) + { + if($warenkorb['versandkostennetto'] != 0 || $warenkorb['versandkostenbrutto'] != 0 || $portocheck == 1) + { + $portoartikelarr = array('projekt'=>$projekt,'porto'=>1, 'lagerartikel'=>0,'name_de'=>'Porto','umsatzsteuer'=>'normal'); + $artikelporto = $this->app->erp->InsertUpdateArtikel($portoartikelarr); + if($artikelporto) + { + $this->app->DB->Update("UPDATE shopexport SET artikelporto = '$artikelporto' WHERE id = '$shop' AND artikelporto = 0 LIMIT 1"); + } + } + } else { + $error_msg = 'Importauftrag Shop '.$shop.' Fehler: Kein Portoartikel vorhanden'; + $this->LogFile($error_msg,['Onlinebestellnummer' => $warenkorb['onlinebestellnummer']]); + return(array("status" => false, "message" => $error_msg, "onlinebestellnummer" => $warenkorb['onlinebestellnummer'])); + } } - } $umsatzsteuer_porto = $this->app->DB->Select("SELECT umsatzsteuer FROM artikel WHERE id='$artikelporto' LIMIT 1"); $versandname = ''; @@ -19029,7 +19040,7 @@ function CheckShopTabelle($artikel) } } - return $auftrag; + return array("status" => true, "$auftragid" => $auftrag); } @@ -21022,7 +21033,7 @@ function ChargenMHDAuslagern($artikel, $menge, $lagerplatztyp, $lpid,$typ,$wert, $anzges = 0; $anzfehler = 0; - $result = null; // 1 on success + $result = null; // $result['status'] == 1 on success if(!empty($extnummer) && is_array($extnummer)) { foreach($extnummer as $nummer) { @@ -21053,9 +21064,9 @@ function ChargenMHDAuslagern($artikel, $menge, $lagerplatztyp, $lpid,$typ,$wert, } - $this->LogFile('*** UPDATE '.$lagerartikel[$ij]['nummer'].' '.$lagerartikel[$ij]['name_de'].' Shop: '.$shop.' Lagernd: '.$verkaufbare_menge.' Korrektur: '.round((float) ($verkaufbare_menge_korrektur - $verkaufbare_menge),7).' Pseudolager: '.round((float) $pseudolager,8).' Result: '.gettype($result).' '.$result); + $this->LogFile('*** UPDATE '.$lagerartikel[$ij]['nummer'].' '.$lagerartikel[$ij]['name_de'].' Shop: '.$shop.' Lagernd: '.$verkaufbare_menge.' Korrektur: '.round((float) ($verkaufbare_menge_korrektur - $verkaufbare_menge),7).' Pseudolager: '.round((float) $pseudolager,8).' Result: '.(is_array($result)?$result['status']:$result), $result); - if ($result == 1) { + if ((is_array($result)?$result['status'] == 1:false) || $status === 1) { $cacheQuantity = (int) $verkaufbare_menge_korrektur + (int) $pseudolager; $this->app->DB->Update( "UPDATE `artikel` SET `cache_lagerplatzinhaltmenge` = '{$cacheQuantity}' diff --git a/www/pages/appstore.php b/www/pages/appstore.php index 6c9c7c89..c118ecaf 100644 --- a/www/pages/appstore.php +++ b/www/pages/appstore.php @@ -2628,6 +2628,10 @@ class Appstore { 'Link'=>'index.php?module=onlineshops&action=create&cmd=shopimporter_presta', 'Icon'=>'Icons_dunkel_1.gif', 'Versionen'=>'ALL','install'=>true, 'beta' => false,'kategorie'=>'{|Shop Schnittstelle|}') + ,'shopimporter_mirakl'=>array('Bezeichnung'=>'Mirakl', + 'Link'=>'index.php?module=onlineshops&action=create&cmd=shopimporter_mirakl', + 'Icon'=>'Icons_dunkel_1.gif', + 'Versionen'=>'ALL','install'=>true, 'beta' => false,'kategorie'=>'{|Shop Schnittstelle|}') ,'shopimporter_shopify'=>array( 'Bezeichnung'=>'Shopify API Advanced', 'Link'=>'index.php?module=onlineshops&action=create&cmd=shopimporter_shopify', @@ -3967,7 +3971,6 @@ class Appstore { } } - if(isset($module['installiert'])) { foreach($module['installiert'] as $k => $v) { $moduleInstallKey = $module['installiert'][$k]['key']; diff --git a/www/pages/artikel.php b/www/pages/artikel.php index 8826b614..1d201002 100644 --- a/www/pages/artikel.php +++ b/www/pages/artikel.php @@ -2841,100 +2841,82 @@ class Artikel extends GenArtikel { return ['status'=>$isOk, 'info'=>$info, 'msg_encoded' => $msg, 'error' => $error]; } - public function ArtikelShopexport() - { - $id = $this->app->Secure->GetGET('id'); - $shop = $this->app->Secure->GetGET('shop'); - $artikel = array($id); - $artikelshopid = (int)$this->app->Secure->GetGET('artikelshopid'); - - if($artikelshopid > 0) - { - $shop = $this->app->DB->Select("SELECT shop FROM artikel_onlineshops WHERE id = '$artikelshopid' AND artikel = '$id' AND aktiv = 1 LIMIT 1"); - $this->app->User->SetParameter('artikel_shopexport_shop', ''); - }else{ - if($shop=='1'){ - $shop = $this->app->DB->Select("SELECT shop FROM artikel WHERE id='$id' LIMIT 1"); - } - elseif($shop=='2'){ - $shop = $this->app->DB->Select("SELECT shop2 FROM artikel WHERE id='$id' LIMIT 1"); - } - elseif($shop=='3'){ - $shop = $this->app->DB->Select("SELECT shop3 FROM artikel WHERE id='$id' LIMIT 1"); - } - } - - $artikelexport = $this->app->DB->Select("SELECT artikelexport FROM shopexport WHERE id='$shop' LIMIT 1"); - $lagerexport = $this->app->DB->Select("SELECT lagerexport FROM shopexport WHERE id='$shop' LIMIT 1"); + public function ArtikelShopexport() { + $id = $this->app->Secure->GetGET('id'); + $shop = $this->app->Secure->GetGET('shop'); + $artikel = array($id); + $artikelshopid = (int) $this->app->Secure->GetGET('artikelshopid'); - $externenummer = $this->app->DB->Select("SELECT nummer FROM artikelnummer_fremdnummern WHERE artikel = '$id' AND aktiv = 1 AND shopid = '$shop' AND nummer <> '' ORDER BY bezeichnung = 'SHOPID' DESC LIMIT 1"); - - if($externenummer) - { - $extartikelnummer = array($externenummer); - }else{ - $extartikelnummer = ''; - } - - $pageContents = $this->app->remote->RemoteSendArticleList($shop,$artikel,$extartikelnummer); - $check = strpos($pageContents ,'error:'); - $msg = ''; - if(!empty($pageContents) && is_array($pageContents)) { - if(!empty($pageContents['status']) && !empty($pageContents['message'])) { - $msg = $this->app->erp->base64_url_encode('
'.$pageContents['message'].'
'); - } - elseif(isset($pageContents['status']) && !empty($pageContents['message'])) { - $msg = $this->app->erp->base64_url_encode('
'.$pageContents['message'].'
'); - } - } - elseif($pageContents=='1') { - $pageContents='success'; - } - - if(empty($msg) && $pageContents!='') { - $pageContents = " ($pageContents)"; - } - - $this->app->erp->LogFile($this->app->DB->real_escape_string('manueller Shopexport Artikel: '.$this->app->DB->Select("SELECT nummer FROM artikel WHERE id = '$id' LIMIT 1").' Shop: '.$shop.' Status: '.$pageContents)); - // keine fehlermeldung vom shop - if(empty($msg)) { - $linkToImporterSettings = ''; - if($this->app->erp->RechteVorhanden('onlineshops', 'edit')){ - $url = 'index.php?module=onlineshops&action=edit&id='.$shop; - $linkToImporterSettings = "Zu den Shopeinstellungen"; - } - - if($check === 0){ - $msg = $this->app->erp->base64_url_encode("
Es gab einen Fehler beim Aktualisieren des Artikels im Shop!$pageContents
"); - } - else if($pageContents == ''){ - if($artikelexport != 1 && $lagerexport != 1){ - $msg = $this->app->erp->base64_url_encode("
Der Artikel konnte nicht zum Shop übertragen werden! In den Shopeinstellungen ist festgelegt, dass die Artikelinformation- und Lagerbestandsübertragung nicht erlaubt ist!$pageContents $linkToImporterSettings
"); + if ($artikelshopid > 0) { + $shop = $this->app->DB->Select("SELECT shop FROM artikel_onlineshops WHERE id = '$artikelshopid' AND artikel = '$id' AND aktiv = 1 LIMIT 1"); + $this->app->User->SetParameter('artikel_shopexport_shop', ''); + } else { + if ($shop == '1') { + $shop = $this->app->DB->Select("SELECT shop FROM artikel WHERE id='$id' LIMIT 1"); + } elseif ($shop == '2') { + $shop = $this->app->DB->Select("SELECT shop2 FROM artikel WHERE id='$id' LIMIT 1"); + } elseif ($shop == '3') { + $shop = $this->app->DB->Select("SELECT shop3 FROM artikel WHERE id='$id' LIMIT 1"); + } } - else{ - if($pageContents === '0' || $pageContents === 0){ - $msg = $this->app->erp->base64_url_encode("
Es gab einen Fehler beim Aktualisieren des Artikels im Shop! Stellen Sie sicher, dass die Zugangsdaten und URL's korrekt sind! Möglicherweise kein Artikelpreis hinterlegt
"); - }else{ - $msg = $this->app->erp->base64_url_encode("
Es gab einen Fehler beim Aktualisieren des Artikels im Shop! Stellen Sie sicher, dass die Zugangsdaten und URL's korrekt sind!$pageContents $linkToImporterSettings
"); - } - } - } - else{ - if($artikelexport != 1 && $lagerexport == 1){ - $msg = $this->app->erp->base64_url_encode("
Es wurde nur der Lagerbestand (nicht die Artikelinfos entsprechend der Einstellungen) im Shop aktualisiert!$pageContents $linkToImporterSettings
"); - } - else if($lagerexport != 1 && $artikelexport == 1){ - $msg = $this->app->erp->base64_url_encode("
Es wurde nur der Artikel (nicht der Lagerbestand entsprechend der Einstellungen) im Shop aktualisiert!$pageContents $linkToImporterSettings
"); - } - else{ - $msg = $this->app->erp->base64_url_encode("
Der Artikel wurde im Shop aktualisiert!$pageContents
"); - } - } - } - $this->app->erp->LagerSync($artikel); - $this->app->Location->execute("index.php?module=artikel&action=edit&id=$id&msg=$msg#tabs-4"); - } + $artikelexport = $this->app->DB->Select("SELECT artikelexport FROM shopexport WHERE id='$shop' LIMIT 1"); + $lagerexport = $this->app->DB->Select("SELECT lagerexport FROM shopexport WHERE id='$shop' LIMIT 1"); + + $externenummer = $this->app->DB->Select("SELECT nummer FROM artikelnummer_fremdnummern WHERE artikel = '$id' AND aktiv = 1 AND shopid = '$shop' AND nummer <> '' ORDER BY bezeichnung = 'SHOPID' DESC LIMIT 1"); + + if ($externenummer) { + $extartikelnummer = array($externenummer); + } else { + $extartikelnummer = ''; + } + + $remote_result = $this->app->remote->RemoteSendArticleList($shop, $artikel, $extartikelnummer); + + if (is_array($remote_result)) { + $remote_status = $remote_result['status']; + $remote_message = $remote_result['message']; + } else if (is_numeric($remote_result)) { + if ($remote_result == 1) { + $remote_status = true; + } else { + $remote_status = false; + $remote_message = "Der Artikel konnte nicht zum Shop übertragen werden!"; + } + } else if ($remote_result === null) { + $remote_status = false; + $remote_message = "Keine Aktion durchgeführt"; + } else { + $remote_message = $remote_result; + if (strpos((string) $remote_result, 'error:') === 0) { + $remote_status = false; + } else { + $remote_status = true; + } + } + + if ($remote_status) { + $msg = $this->app->erp->base64_url_encode('
' . $remote_message . '
'); + } else { + $msg = $this->app->erp->base64_url_encode('
' . $remote_message . '
'); + } + + $this->app->erp->LogFile($this->app->DB->real_escape_string('manueller Shopexport Artikel: '.$this->app->DB->Select("SELECT nummer FROM artikel WHERE id = '$id' LIMIT 1").' Shop: '.$shop.' Status: '.((int) $remote_status)), $remote_message); + + // keine fehlermeldung vom shop + if ($remote_status) { + $linkToImporterSettings = ''; + if ($this->app->erp->RechteVorhanden('onlineshops', 'edit')) { + $url = 'index.php?module=onlineshops&action=edit&id=' . $shop; + $linkToImporterSettings = "Zu den Shopeinstellungen"; + } + } + + $this->app->erp->LagerSync($artikel); + + $this->app->Location->execute("index.php?module=artikel&action=edit&id=$id&msg=$msg#tabs-4"); + } + public function ArtikelShopexportFiles() { diff --git a/www/pages/content/laender_edit.tpl b/www/pages/content/laender_edit.tpl index 802be0f3..978e1eba 100644 --- a/www/pages/content/laender_edit.tpl +++ b/www/pages/content/laender_edit.tpl @@ -22,6 +22,7 @@ {|Land|} + diff --git a/www/pages/importvorlage.php b/www/pages/importvorlage.php index ea9be2ee..a7aec0e7 100644 --- a/www/pages/importvorlage.php +++ b/www/pages/importvorlage.php @@ -4067,6 +4067,25 @@ class Importvorlage extends GenImportvorlage { } } // Sprachen + // Artikeleigenschaften + // leer = löschen + + $artikeleigenschaften = array(); + foreach ($tmp as $feldname => $feldwerte) { + if (strpos($feldname,'eigenschaftname') !== false) { + $eigenschaftspaltennummer = substr($feldname,strlen('eigenschaftname')); + $artikeleigenschaften[$feldwerte[$i]] = $tmp['eigenschaftwert'.$eigenschaftspaltennummer][$i]; + } + } + foreach ($artikeleigenschaften as $key => $value) { + $sql = "INSERT INTO artikeleigenschaften (name) VALUES ('".$key."') ON DUPLICATE KEY UPDATE name = '".$key."'"; + $this->app->DB->Update($sql); + $sql = "INSERT INTO artikeleigenschaftenwerte (artikel, artikeleigenschaften, wert) VALUES ('".$artikelid."' ,(SELECT id FROM artikeleigenschaften WHERE name = '".$key."'), '".$value."') ON DUPLICATE KEY UPDATE wert = '".$value."'"; + $this->app->DB->Update($sql); + } + $sql = "DELETE FROM artikeleigenschaftenwerte WHERE wert = ''"; + $this->app->DB->Delete($sql); + //freifelduebersetzungen foreach ($tmp as $feldname => $feldwerte) { if(strpos($feldname,'freifeld') !== false && strpos($feldname,'_')>0){ diff --git a/www/pages/laender.php b/www/pages/laender.php index 4870a83f..45550818 100644 --- a/www/pages/laender.php +++ b/www/pages/laender.php @@ -1,215 +1,219 @@ -Conf->WFconf['defaulttheme']}/images/edit.svg\" border=\"0\"> Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\">"; - - $where = " l.id > 0 "; - - $sql = "SELECT SQL_CALC_FOUND_ROWS l.id, l.iso, l.bezeichnung_de, l.bezeichnung_en, if(l.eu,'EU',''), l.id FROM laender l"; - - $count = "SELECT count(l.id) FROM laender l WHERE $where"; - break; - - } - - $erg = false; - - foreach($erlaubtevars as $k => $v) - { - if(isset($$v))$erg[$v] = $$v; - } - return $erg; - } - - function __construct($app, $intern = false) { - $this->app=$app; - if($intern)return; - $this->app->ActionHandlerInit($this); - - // ab hier alle Action Handler definieren die das Modul hat - $this->app->ActionHandler("list", "LaenderList"); - $this->app->ActionHandler("create", "LaenderCreate"); - $this->app->ActionHandler("edit", "LaenderEdit"); - $this->app->ActionHandler("delete", "LaenderDelete"); - $this->app->ActionHandler('test', 'LaenderTest'); - - $this->app->ActionHandlerListen($app); - } - - function LaenderTest(){ - $countryModule = $this->app->Container->get('CountryMigrationService'); - if($countryModule->needsMigration()){ - $countryModule->doMigration(); - } - } - - function LaenderMenu() - { - $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Zurück zur Übersicht"); - } - - function LaenderList() - { - $this->app->erp->MenuEintrag("index.php?module=laender&action=create","Neues Land"); - $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Übersicht"); - - $this->app->YUI->TableSearch('TAB1','laender_list', "show","","",basename(__FILE__), __CLASS__); - $this->app->Tpl->Parse("PAGE","laender_list.tpl"); - } - - function LaenderEdit() - { - $id = (int)$this->app->Secure->GetGET('id'); - $submit = $this->app->Secure->GetPOST('submitland'); - - $this->app->Tpl->Add('KURZUEBERSCHRIFT2',$bezeichnung_de); - - - - $input = array(); - - $this->app->erp->MenuEintrag("index.php?module=laender&action=edit&id=$id","Details"); - - $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Zurück zur Übersicht"); - - $input = $this->GetInput(); - - if(is_numeric($id) && $submit!=''){ - - $error = ''; - if($input['iso']=='' || strlen(trim($input['iso'])) > 2) $error .= 'Geben Sie bitte einen zweistelligen ISO-Code ein.
'; - if($input['bezeichnung_de'] == '') $error .= 'Geben Sie bitte eine deutsche Länderbezeichnung ein.
'; - if($input['bezeichnung_en'] =='') $error .= 'Geben Sie bitte eine englische Länderbezeichnung ein.
'; - - if($error!=''){ - $this->app->Tpl->Set('MESSAGE', "
$error
"); - }else{ - if($error == ""){ - $this->app->DB->Update("UPDATE laender SET iso='{$input['iso']}', bezeichnung_de='{$input['bezeichnung_de']}', bezeichnung_en='{$input['bezeichnung_en']}', eu='{$input['eu']}' WHERE id = '$id' LIMIT 1"); - if($input['eu']==1){ - $this->app->Tpl->Set('EU', "checked"); - } - $this->app->Tpl->Set('MESSAGE', "
Die Einstellungen wurden erfolgreich übernommen.
"); - } - } - } - $iso = $this->app->DB->Select("SELECT iso FROM laender WHERE id = '$id'"); - $bezeichnung_de = $this->app->DB->Select("SELECT bezeichnung_de FROM laender WHERE id = '$id'"); - $bezeichnung_en = $this->app->DB->Select("SELECT bezeichnung_en FROM laender WHERE id = '$id'"); - $eu = $this->app->DB->Select("SELECT eu FROM laender WHERE id = '$id'"); - - - $this->app->Tpl->Set('ISO', $iso); - $this->app->Tpl->Set('BEZEICHNUNG_DE', $bezeichnung_de); - $this->app->Tpl->Set('BEZEICHNUNG_EN', $bezeichnung_en); - if($eu == 1){ - $this->app->Tpl->Set('EU', "checked"); - } - - - //$this->SetInput($input); - - $this->app->Tpl->Parse('PAGE', "laender_edit.tpl"); - } - - function LaenderDelete() - { - $ref = $_SERVER['HTTP_REFERER']; - $id = $this->app->Secure->GetGET("id"); - $this->app->DB->DELETE("DELETE FROM laender WHERE id = '$id' LIMIT 1"); - - //$this->VorlageList(); - header("Location: $ref"); - exit; - } - - function LaenderCreate(){ - // $this->app->Tpl->Add(KURZUEBERSCHRIFT,"Benutzer"); - $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Zurück zur Übersicht"); - - $input = $this->GetInput(); - $submit = $this->app->Secure->GetPOST('submitland'); - - if($submit!='') { - - $error = ''; - - if($input['iso']=='' || strlen(trim($input['iso'])) > 2) $error .= 'Geben Sie bitte einen zweistelligen ISO-Code ein.
'; - if($input['bezeichnung_de']=='') $error .= 'Geben Sie bitte eine deutsche Länderbezeichnung ein.
'; - if($input['bezeichnung_en']=='') $error .= 'Geben Sie bitte eine englische Länderbezeichnung ein.
'; - - if($this->app->DB->Select("SELECT '1' FROM laender WHERE iso='{$input['iso']}' LIMIT 1")=='1') - $error .= "Es existiert bereits ein ISO-Code mit diesem Namen.
"; - - if($error!=''){ - $this->app->Tpl->Set('MESSAGE', "
$error
"); - }else { - $this->app->DB->Insert("INSERT INTO laender (iso, bezeichnung_de, bezeichnung_en, eu) VALUES ('{$input['iso']}', '{$input['bezeichnung_de']}', '{$input['bezeichnung_en']}', '{$input['eu']}')"); - $newid = $this->app->DB->GetInsertID(); - $msg = $this->app->erp->base64_url_encode("
Der Ländereintrag wurde erfolgreich angelegt.
"); - header("Location: index.php?module=laender&action=edit&id=$newid&msg=$msg"); - exit; - } - } - - $this->SetInput($input); - - $this->app->Tpl->Parse('PAGE', "laender_edit.tpl"); - } - - - function GetInput(){ - $input = array(); - $input['iso'] = $this->app->Secure->GetPOST('iso'); - $input['bezeichnung_de'] = $this->app->Secure->GetPOST('bezeichnung_de'); - $input['bezeichnung_en'] = $this->app->Secure->GetPOST('bezeichnung_en'); - $input['eu'] = (int)$this->app->Secure->GetPOST('eu'); - return $input; - - } - - function SetInput($input){ - $this->app->Tpl->Set('ISO', $input['iso']); - $this->app->Tpl->Set('BEZEICHNUNG_DE', $input['bezeichnung_de']); - $this->app->Tpl->Set('BEZEICHNUNG_EN', $input['bezeichnung_en']); - if($input['eu']==1){ - $this->app->Tpl->Set('EU', "checked"); - } - - - } - -} +Conf->WFconf['defaulttheme']}/images/edit.svg\" border=\"0\"> Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\">"; + + $where = " l.id > 0 "; + + $sql = "SELECT SQL_CALC_FOUND_ROWS l.id, l.iso, l.iso3, l.bezeichnung_de, l.bezeichnung_en, if(l.eu,'EU',''), l.id FROM laender l"; + + $count = "SELECT count(l.id) FROM laender l WHERE $where"; + break; + + } + + $erg = false; + + foreach($erlaubtevars as $k => $v) + { + if(isset($$v))$erg[$v] = $$v; + } + return $erg; + } + + function __construct($app, $intern = false) { + $this->app=$app; + if($intern)return; + $this->app->ActionHandlerInit($this); + + // ab hier alle Action Handler definieren die das Modul hat + $this->app->ActionHandler("list", "LaenderList"); + $this->app->ActionHandler("create", "LaenderCreate"); + $this->app->ActionHandler("edit", "LaenderEdit"); + $this->app->ActionHandler("delete", "LaenderDelete"); + $this->app->ActionHandler('test', 'LaenderTest'); + + $this->app->ActionHandlerListen($app); + } + + function LaenderTest(){ + $countryModule = $this->app->Container->get('CountryMigrationService'); + if($countryModule->needsMigration()){ + $countryModule->doMigration(); + } + } + + function LaenderMenu() + { + $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Zurück zur Übersicht"); + } + + function LaenderList() + { + $this->app->erp->MenuEintrag("index.php?module=laender&action=create","Neues Land"); + $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Übersicht"); + + $this->app->YUI->TableSearch('TAB1','laender_list', "show","","",basename(__FILE__), __CLASS__); + $this->app->Tpl->Parse("PAGE","laender_list.tpl"); + } + + function LaenderEdit() + { + $id = (int)$this->app->Secure->GetGET('id'); + $submit = $this->app->Secure->GetPOST('submitland'); + + $this->app->Tpl->Add('KURZUEBERSCHRIFT2',$bezeichnung_de); + + + + $input = array(); + + $this->app->erp->MenuEintrag("index.php?module=laender&action=edit&id=$id","Details"); + + $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Zurück zur Übersicht"); + + $input = $this->GetInput(); + + if(is_numeric($id) && $submit!=''){ + + $error = ''; + if($input['iso']=='' || strlen(trim($input['iso'])) > 2) $error .= 'Geben Sie bitte einen zweistelligen ISO-Code ein.
'; + if($input['bezeichnung_de'] == '') $error .= 'Geben Sie bitte eine deutsche Länderbezeichnung ein.
'; + if($input['bezeichnung_en'] =='') $error .= 'Geben Sie bitte eine englische Länderbezeichnung ein.
'; + + if($error!=''){ + $this->app->Tpl->Set('MESSAGE', "
$error
"); + }else{ + if($error == ""){ + $this->app->DB->Update("UPDATE laender SET iso='{$input['iso']}', iso3='{$input['iso3']}', bezeichnung_de='{$input['bezeichnung_de']}', bezeichnung_en='{$input['bezeichnung_en']}', eu='{$input['eu']}' WHERE id = '$id' LIMIT 1"); + if($input['eu']==1){ + $this->app->Tpl->Set('EU', "checked"); + } + $this->app->Tpl->Set('MESSAGE', "
Die Einstellungen wurden erfolgreich übernommen.
"); + } + } + } + $iso = $this->app->DB->Select("SELECT iso FROM laender WHERE id = '$id'"); + $iso3 = $this->app->DB->Select("SELECT iso3 FROM laender WHERE id = '$id'"); + $bezeichnung_de = $this->app->DB->Select("SELECT bezeichnung_de FROM laender WHERE id = '$id'"); + $bezeichnung_en = $this->app->DB->Select("SELECT bezeichnung_en FROM laender WHERE id = '$id'"); + $eu = $this->app->DB->Select("SELECT eu FROM laender WHERE id = '$id'"); + + + $this->app->Tpl->Set('ISO', $iso); + $this->app->Tpl->Set('ISO3', $iso3); + $this->app->Tpl->Set('BEZEICHNUNG_DE', $bezeichnung_de); + $this->app->Tpl->Set('BEZEICHNUNG_EN', $bezeichnung_en); + if($eu == 1){ + $this->app->Tpl->Set('EU', "checked"); + } + + + //$this->SetInput($input); + + $this->app->Tpl->Parse('PAGE', "laender_edit.tpl"); + } + + function LaenderDelete() + { + $ref = $_SERVER['HTTP_REFERER']; + $id = $this->app->Secure->GetGET("id"); + $this->app->DB->DELETE("DELETE FROM laender WHERE id = '$id' LIMIT 1"); + + //$this->VorlageList(); + header("Location: $ref"); + exit; + } + + function LaenderCreate(){ + // $this->app->Tpl->Add(KURZUEBERSCHRIFT,"Benutzer"); + $this->app->erp->MenuEintrag("index.php?module=laender&action=list","Zurück zur Übersicht"); + + $input = $this->GetInput(); + $submit = $this->app->Secure->GetPOST('submitland'); + + if($submit!='') { + + $error = ''; + + if($input['iso']=='' || strlen(trim($input['iso'])) > 2) $error .= 'Geben Sie bitte einen zweistelligen ISO-Code ein.
'; + if($input['bezeichnung_de']=='') $error .= 'Geben Sie bitte eine deutsche Länderbezeichnung ein.
'; + if($input['bezeichnung_en']=='') $error .= 'Geben Sie bitte eine englische Länderbezeichnung ein.
'; + + if($this->app->DB->Select("SELECT '1' FROM laender WHERE iso='{$input['iso']}' LIMIT 1")=='1') + $error .= "Es existiert bereits ein ISO-Code mit diesem Namen.
"; + + if($error!=''){ + $this->app->Tpl->Set('MESSAGE', "
$error
"); + }else { + $this->app->DB->Insert("INSERT INTO laender (iso, iso3, bezeichnung_de, bezeichnung_en, eu) VALUES ('{$input['iso']}', '{$input['iso3']}', '{$input['bezeichnung_de']}', '{$input['bezeichnung_en']}', '{$input['eu']}')"); + $newid = $this->app->DB->GetInsertID(); + $msg = $this->app->erp->base64_url_encode("
Der Ländereintrag wurde erfolgreich angelegt.
"); + header("Location: index.php?module=laender&action=edit&id=$newid&msg=$msg"); + exit; + } + } + + $this->SetInput($input); + + $this->app->Tpl->Parse('PAGE', "laender_edit.tpl"); + } + + + function GetInput(){ + $input = array(); + $input['iso'] = $this->app->Secure->GetPOST('iso'); + $input['iso3'] = $this->app->Secure->GetPOST('iso3'); + $input['bezeichnung_de'] = $this->app->Secure->GetPOST('bezeichnung_de'); + $input['bezeichnung_en'] = $this->app->Secure->GetPOST('bezeichnung_en'); + $input['eu'] = (int)$this->app->Secure->GetPOST('eu'); + return $input; + + } + + function SetInput($input){ + $this->app->Tpl->Set('ISO', $input['iso']); + $this->app->Tpl->Set('ISO3', $input['iso3']); + $this->app->Tpl->Set('BEZEICHNUNG_DE', $input['bezeichnung_de']); + $this->app->Tpl->Set('BEZEICHNUNG_EN', $input['bezeichnung_en']); + if($input['eu']==1){ + $this->app->Tpl->Set('EU', "checked"); + } + + + } + +} diff --git a/www/pages/onlineshops.php b/www/pages/onlineshops.php index 9cfda337..bccf47ed 100644 --- a/www/pages/onlineshops.php +++ b/www/pages/onlineshops.php @@ -3339,7 +3339,7 @@ INNER JOIN shopexport s ON } if($this->app->Secure->GetPOST('pruefen')) { - + $className = 'Remote'; $methodName = 'RemoteConnection'; $r = new ReflectionMethod($className, $methodName); diff --git a/www/pages/shopimport.php b/www/pages/shopimport.php index e093318d..576ffdf9 100644 --- a/www/pages/shopimport.php +++ b/www/pages/shopimport.php @@ -1,4 +1,5 @@ app=$app; - if($intern) { - return; - } - $this->app->ActionHandlerInit($this); + const MODULE_NAME = 'Shopimport'; - $this->app->ActionHandler("login","ShopimportLogin"); - $this->app->ActionHandler("main","ShopimportMain"); - $this->app->ActionHandler("list","ShopimportList"); - $this->app->ActionHandler("alle","ShopimportAlle"); - $this->app->ActionHandler("import","ShopimportImport"); - $this->app->ActionHandler("einzelimport","ShopimportEinzelimport"); - $this->app->ActionHandler("navigation","ShopimportNavigation"); - $this->app->ActionHandler("logout","ShopimportLogout"); - $this->app->ActionHandler("archiv","ShopimportArchiv"); + public $javascript = [ + './classes/Modules/Shopimport/www/js/shopimport.js' + ]; - $this->app->DefaultActionHandler("list"); + /** + * Shopimport constructor. + * + * @param Application $app + * @param bool $intern + */ + public function __construct($app, $intern = false) { + $this->app = $app; + if ($intern) { + return; + } + $this->app->ActionHandlerInit($this); + $this->app->ActionHandler("login", "ShopimportLogin"); + $this->app->ActionHandler("main", "ShopimportMain"); + $this->app->ActionHandler("list", "ShopimportList"); + $this->app->ActionHandler("alle", "ShopimportAlle"); + $this->app->ActionHandler("import", "ShopimportImport"); + $this->app->ActionHandler("view", "ShopimportView"); + $this->app->ActionHandler("einzelimport", "ShopimportEinzelimport"); + $this->app->ActionHandler("navigation", "ShopimportNavigation"); + $this->app->ActionHandler("logout", "ShopimportLogout"); + $this->app->ActionHandler("archiv", "ShopimportArchiv"); - $this->app->Tpl->Set('UEBERSCHRIFT','Shop Import'); - $this->app->ActionHandlerListen($app); - } + $this->app->DefaultActionHandler("list"); - /** - * @param int $shopId - * @param array $data - * - * @return int - * - * @throws Exception - */ - public function Refund($shopId, $data) - { - if(empty($shopId)) { - throw new Exception('no Shop given'); - } - if(empty($data)) { - throw new Exception('no Data given'); + $this->app->Tpl->Set('UEBERSCHRIFT', 'Shop Import'); + $this->app->ActionHandlerListen($app); } - $shop = $this->app->DB->SelectRow( - sprintf( - 'SELECT `aktiv`, `id`, `artikelrabatt` FROM `shopexport` WHERE `id` = %d', - $shopId - ) - ); - if(empty($shop)) { - throw new Exception('Shop not found'); - } - if(empty($shop['aktiv'])) { - throw new Exception('Shop is not active'); - } + /** + * @param int $shopId + * @param array $data + * + * @return int + * + * @throws Exception + */ + public function Refund($shopId, $data) { + if (empty($shopId)) { + throw new Exception('no Shop given'); + } + if (empty($data)) { + throw new Exception('no Data given'); + } - if(!empty($data->extid)) { - $order = $this->app->DB->SelectRow( - sprintf( - "SELECT * + $shop = $this->app->DB->SelectRow( + sprintf( + 'SELECT `aktiv`, `id`, `artikelrabatt` FROM `shopexport` WHERE `id` = %d', + $shopId + ) + ); + if (empty($shop)) { + throw new Exception('Shop not found'); + } + if (empty($shop['aktiv'])) { + throw new Exception('Shop is not active'); + } + + if (!empty($data->extid)) { + $order = $this->app->DB->SelectRow( + sprintf( + "SELECT * FROM `auftrag` WHERE `shop` = %d AND `shopextid` = '%s' AND `shopextid` <> '' AND `status` <> 'storniert' LIMIT 1", - $shopId, $this->app->DB->real_escape_string((string)$data->extid) - ) - ); - } - elseif(!empty($data->internet)) { - $order = $this->app->DB->SelectRow( - sprintf( - "SELECT * + $shopId, $this->app->DB->real_escape_string((string) $data->extid) + ) + ); + } elseif (!empty($data->internet)) { + $order = $this->app->DB->SelectRow( + sprintf( + "SELECT * FROM `auftrag` WHERE `shop` = %d AND `internet` = '%s' AND `internet` <> '' AND `status` <> 'storniert' LIMIT 1", - $shopId, $this->app->DB->real_escape_string((string)$data->extid) - ) - ); - } - else { - throw new Exception('No order given'); - } + $shopId, $this->app->DB->real_escape_string((string) $data->extid) + ) + ); + } else { + throw new Exception('No order given'); + } - if(empty($order)) { - throw new Exception('order not found'); - } + if (empty($order)) { + throw new Exception('order not found'); + } - $invoice = $this->app->DB->SelectRow( - sprintf( - "SELECT * FROM `rechnung` WHERE `auftragid` = %d ORDER BY `status` = 'storniert' LIMIT 1", - $order['id'] - ) - ); + $invoice = $this->app->DB->SelectRow( + sprintf( + "SELECT * FROM `rechnung` WHERE `auftragid` = %d ORDER BY `status` = 'storniert' LIMIT 1", + $order['id'] + ) + ); - if(empty($invoice)) { - if(empty($data->createinvoice)){ - throw new Exception('order has no invoice'); - } - $invoiceId = $this->app->erp->WeiterfuehrenAuftragZuRechnung($order['id']); - $this->app->erp->AuftragProtokoll($order['id'], 'Rechnung erstellt durch Shop-Trigger'); - $this->app->erp->RechnungProtokoll($invoiceId, 'Rechnung erstellt durch Shop-Trigger'); - $this->app->erp->BelegFreigabe('rechnung', $invoiceId); - $this->app->erp->RechnungNeuberechnen($invoiceId); - $invoice = $this->app->DB->SelectRow( - sprintf( - "SELECT * FROM `rechnung` WHERE `auftragid` = %d ORDER BY `status` = 'storniert' LIMIT 1", - $order['id'] - ) - ); - } + if (empty($invoice)) { + if (empty($data->createinvoice)) { + throw new Exception('order has no invoice'); + } + $invoiceId = $this->app->erp->WeiterfuehrenAuftragZuRechnung($order['id']); + $this->app->erp->AuftragProtokoll($order['id'], 'Rechnung erstellt durch Shop-Trigger'); + $this->app->erp->RechnungProtokoll($invoiceId, 'Rechnung erstellt durch Shop-Trigger'); + $this->app->erp->BelegFreigabe('rechnung', $invoiceId); + $this->app->erp->RechnungNeuberechnen($invoiceId); + $invoice = $this->app->DB->SelectRow( + sprintf( + "SELECT * FROM `rechnung` WHERE `auftragid` = %d ORDER BY `status` = 'storniert' LIMIT 1", + $order['id'] + ) + ); + } - if($invoice['status'] === 'storniert') { - throw new Exception('order invoice is already cancelled'); - } - if(!empty($data->positions)) { - $positions = $this->app->DB->SelectArr( - sprintf( - "SELECT `op`.webid, ip.artikel, ip.menge,ip.preis, ip.rabatt, ip.auftrag_position_id + if ($invoice['status'] === 'storniert') { + throw new Exception('order invoice is already cancelled'); + } + if (!empty($data->positions)) { + $positions = $this->app->DB->SelectArr( + sprintf( + "SELECT `op`.webid, ip.artikel, ip.menge,ip.preis, ip.rabatt, ip.auftrag_position_id FROM `rechnung_position` AS `ip` INNER JOIN `auftrag_position` AS `op` ON ip.auftrag_position_id = op.id WHERE `ip`.rechnung = %d", - $invoice['id'] - ) - ); - if(empty($positions)) { - throw new Exception('invoice has no positions'); - } - $webIds = []; - $foundWebIds = []; - foreach($positions as $position) { - if(!empty($position['webid'])) { - $webIds[] = $position['webid']; - } - } + $invoice['id'] + ) + ); + if (empty($positions)) { + throw new Exception('invoice has no positions'); + } + $webIds = []; + $foundWebIds = []; + foreach ($positions as $position) { + if (!empty($position['webid'])) { + $webIds[] = $position['webid']; + } + } - $webIdToPosition = []; + $webIdToPosition = []; - foreach($data->positions as $position) { - if(!empty($position->webid)){ - if(!in_array((string)$position->webid, $webIds)){ - throw new Exception(sprintf('position %s not found', (string)$position->webid)); - } - $foundWebIds[] = (string)$position->webid; - $webIdToPosition[$position->webid] = $position; - } - else { - throw new Exception('no webId given'); - } - } + foreach ($data->positions as $position) { + if (!empty($position->webid)) { + if (!in_array((string) $position->webid, $webIds)) { + throw new Exception(sprintf('position %s not found', (string) $position->webid)); + } + $foundWebIds[] = (string) $position->webid; + $webIdToPosition[$position->webid] = $position; + } else { + throw new Exception('no webId given'); + } + } - if(empty($foundWebIds)) { - throw new Exception('positions empty'); - } + if (empty($foundWebIds)) { + throw new Exception('positions empty'); + } - $toDeleteInvoicePositionIds = [0]; - foreach($positions as $position) { - if(empty($position['webid']) || !in_array($position['webid'], $foundWebIds)) { - $toDeleteInvoicePositionIds[] = (int)$position['auftrag_position_id']; - } - } + $toDeleteInvoicePositionIds = [0]; + foreach ($positions as $position) { + if (empty($position['webid']) || !in_array($position['webid'], $foundWebIds)) { + $toDeleteInvoicePositionIds[] = (int) $position['auftrag_position_id']; + } + } - $creditNoteId = $this->app->erp->WeiterfuehrenRechnungZuGutschrift($invoice['id']); - $this->app->erp->RechnungProtokoll($invoice['id'], 'Rechnung durch Shop-Trigger storniert'); - $this->app->erp->GutschriftProtokoll($creditNoteId, 'Gutschrift durch Shop-Trigger angelegt'); - $this->app->erp->BelegFreigabe('gutschrift', $creditNoteId); - $this->app->DB->Delete( - sprintf( - "DELETE FROM `gutschrift_position` WHERE `gutschrift` = %d AND `auftrag_position_id` IN (%s)", - $creditNoteId, implode(',', $toDeleteInvoicePositionIds) - ) - ); - $hasCreditNoteTax = !empty($this->app->erp->GutschriftMitUmsatzeuer($creditNoteId)); - $this->app->erp->GutschriftNeuberechnen($creditNoteId); - $creditNote = $this->app->DB->SelectRow( - sprintf( - 'SELECT * FROM `gutschrift` WHERE `id` = %d', - $creditNoteId - ) - ); - $creditNotePositions = $this->app->DB->SelectArr( - sprintf( - "SELECT op.webid, cnp.id, cnp.menge, cnp.preis, cnp.rabatt, cnp.umsatzsteuer, + $creditNoteId = $this->app->erp->WeiterfuehrenRechnungZuGutschrift($invoice['id']); + $this->app->erp->RechnungProtokoll($invoice['id'], 'Rechnung durch Shop-Trigger storniert'); + $this->app->erp->GutschriftProtokoll($creditNoteId, 'Gutschrift durch Shop-Trigger angelegt'); + $this->app->erp->BelegFreigabe('gutschrift', $creditNoteId); + $this->app->DB->Delete( + sprintf( + "DELETE FROM `gutschrift_position` WHERE `gutschrift` = %d AND `auftrag_position_id` IN (%s)", + $creditNoteId, implode(',', $toDeleteInvoicePositionIds) + ) + ); + $hasCreditNoteTax = !empty($this->app->erp->GutschriftMitUmsatzeuer($creditNoteId)); + $this->app->erp->GutschriftNeuberechnen($creditNoteId); + $creditNote = $this->app->DB->SelectRow( + sprintf( + 'SELECT * FROM `gutschrift` WHERE `id` = %d', + $creditNoteId + ) + ); + $creditNotePositions = $this->app->DB->SelectArr( + sprintf( + "SELECT op.webid, cnp.id, cnp.menge, cnp.preis, cnp.rabatt, cnp.umsatzsteuer, cnp.steuersatz FROM `gutschrift_position` AS `cnp` INNER JOIN `auftrag_position` AS `op` ON cnp.auftrag_position_id = op.id WHERE cnp.gutschrift = %d", - $creditNoteId - ) - ); - foreach($creditNotePositions as $creditNotePosition) { - if(isset($webIdToPosition[$creditNotePosition['webid']])) { - $position = $webIdToPosition[$creditNotePosition['webid']]; - if(!empty($position->quantity)) { - $this->app->DB->Update( - sprintf( - "UPDATE `gutschrift_position` SET `menge` = %f WHERE `id` = %d", - (float)$position->quantity, $creditNotePosition['id'] - ) + $creditNoteId + ) ); - } - elseif(!empty($position->menge)) { - $this->app->DB->Update( - sprintf( - "UPDATE `gutschrift_position` SET `menge` = %f WHERE `id` = %d", - (float)$position->menge, $creditNotePosition['id'] - ) - ); - } - $preis = null; - if(isset($position->price)) { - $preis = (float)$position->price; - } - elseif(isset($position->preis)) { - $preis = (float)$position->preis; - } - elseif(isset($position->amount)) { - $preis = (float)$position->amount; - } - if($preis !== null) { - if($hasCreditNoteTax) { - if($creditNotePosition['steuersatz'] !== null && $creditNotePosition['steuersatz'] >= 0) { - $preis /= 1+ $creditNotePosition['steuersatz'] / 100; - } - elseif($creditNotePosition['umsatzsteuer'] === 'ermaessigt') { - $preis /= 1+ $creditNote['steuersatz_ermaessigt'] / 100; - } - elseif($creditNotePosition['umsatzsteuer'] !== 'befreit') { - $preis /= 1+ $creditNote['steuersatz_normal'] / 100; - } + foreach ($creditNotePositions as $creditNotePosition) { + if (isset($webIdToPosition[$creditNotePosition['webid']])) { + $position = $webIdToPosition[$creditNotePosition['webid']]; + if (!empty($position->quantity)) { + $this->app->DB->Update( + sprintf( + "UPDATE `gutschrift_position` SET `menge` = %f WHERE `id` = %d", + (float) $position->quantity, $creditNotePosition['id'] + ) + ); + } elseif (!empty($position->menge)) { + $this->app->DB->Update( + sprintf( + "UPDATE `gutschrift_position` SET `menge` = %f WHERE `id` = %d", + (float) $position->menge, $creditNotePosition['id'] + ) + ); + } + $preis = null; + if (isset($position->price)) { + $preis = (float) $position->price; + } elseif (isset($position->preis)) { + $preis = (float) $position->preis; + } elseif (isset($position->amount)) { + $preis = (float) $position->amount; + } + if ($preis !== null) { + if ($hasCreditNoteTax) { + if ($creditNotePosition['steuersatz'] !== null && $creditNotePosition['steuersatz'] >= 0) { + $preis /= 1 + $creditNotePosition['steuersatz'] / 100; + } elseif ($creditNotePosition['umsatzsteuer'] === 'ermaessigt') { + $preis /= 1 + $creditNote['steuersatz_ermaessigt'] / 100; + } elseif ($creditNotePosition['umsatzsteuer'] !== 'befreit') { + $preis /= 1 + $creditNote['steuersatz_normal'] / 100; + } + } + $this->app->DB->Update( + sprintf( + 'UPDATE `gutschrift_position` SET `preis` = %f, `rabatt` = 0 WHERE `id` = %d', + $preis, $creditNotePosition['id'] + ) + ); + } + } } - $this->app->DB->Update( - sprintf( - 'UPDATE `gutschrift_position` SET `preis` = %f, `rabatt` = 0 WHERE `id` = %d', - $preis, $creditNotePosition['id'] - ) + + $this->app->erp->GutschriftNeuberechnen($creditNoteId); + + if (!empty($data->amount)) { + $soll = $this->app->DB->Select(sprintf('SELECT `soll` FROM `gutschrift` WHERE `id` = %d', $creditNoteId)); + $diff = round($soll, 2) - round((float) $data->amount, 2); + if ($diff == 0) { + return $creditNoteId; + } + $this->app->erp->AddPositionManuellPreis( + 'gutschrift', $creditNoteId, $shop['artikelrabatt'], 1, 'Differenz', -$diff, 'befreit', $invoice['waehrung'] + ); + } + + return (int) $creditNoteId; + } + $creditNoteId = $this->app->erp->WeiterfuehrenRechnungZuGutschrift($invoice['id']); + $this->app->erp->RechnungProtokoll($invoice['id'], 'Rechnung durch Shop-Trigger storniert'); + $this->app->erp->GutschriftProtokoll($creditNoteId, 'Gutschrift durch Shop-Trigger angelegt'); + $this->app->erp->BelegFreigabe('gutschrift', $creditNoteId); + $this->app->erp->GutschriftNeuberechnen($creditNoteId); + if (!empty($data->amount)) { + $soll = $this->app->DB->Select(sprintf('SELECT `soll` FROM `gutschrift` WHERE `id` = %d', $creditNoteId)); + $diff = round($soll, 2) - round((float) $data->amount, 2); + if ($diff == 0) { + return $creditNoteId; + } + $this->app->erp->AddPositionManuellPreis( + 'gutschrift', $creditNoteId, $shop['artikelrabatt'], 1, 'Differenz', -$diff, 'befreit', $invoice['waehrung'] ); - } } - } - $this->app->erp->GutschriftNeuberechnen($creditNoteId); + return (int) $creditNoteId; + } - if(!empty($data->amount)) { - $soll = $this->app->DB->Select(sprintf('SELECT `soll` FROM `gutschrift` WHERE `id` = %d', $creditNoteId)); - $diff = round($soll,2) - round((float)$data->amount, 2); - if($diff == 0) { - return $creditNoteId; + public function ShopimportList() { + $msg = $this->app->Secure->GetGET('msg'); + if (!empty($msg)) { + $msg = $this->app->erp->base64_url_decode($msg); + $this->app->Tpl->Set('MESSAGE', $msg); } - $this->app->erp->AddPositionManuellPreis( - 'gutschrift', $creditNoteId, $shop['artikelrabatt'], 1, 'Differenz', -$diff,'befreit', $invoice['waehrung'] - ); - } + $this->app->erp->MenuEintrag('index.php?module=importvorlage&action=uebersicht', 'Zurück zur Übersicht'); - return (int)$creditNoteId; - } - $creditNoteId = $this->app->erp->WeiterfuehrenRechnungZuGutschrift($invoice['id']); - $this->app->erp->RechnungProtokoll($invoice['id'], 'Rechnung durch Shop-Trigger storniert'); - $this->app->erp->GutschriftProtokoll($creditNoteId, 'Gutschrift durch Shop-Trigger angelegt'); - $this->app->erp->BelegFreigabe('gutschrift', $creditNoteId); - $this->app->erp->GutschriftNeuberechnen($creditNoteId); - if(!empty($data->amount)) { - $soll = $this->app->DB->Select(sprintf('SELECT `soll` FROM `gutschrift` WHERE `id` = %d', $creditNoteId)); - $diff = round($soll,2) - round((float)$data->amount, 2); - if($diff == 0) { - return $creditNoteId; - } - $this->app->erp->AddPositionManuellPreis( - 'gutschrift', $creditNoteId, $shop['artikelrabatt'], 1, 'Differenz', -$diff,'befreit', $invoice['waehrung'] - ); - } + //$this->app->Tpl->Add(TABS,"
  • Shopimport

  • "); + $this->app->erp->Headlines('Shopimport'); + //$this->app->erp->MenuEintrag("index.php?module=shopimport&action=alle","Alle importieren"); + $this->app->erp->MenuEintrag('index.php?module=shopimport&action=list', 'Übersicht'); - return (int)$creditNoteId; - } - - public function ShopimportList() - { - $msg = $this->app->Secure->GetGET('msg'); - if(!empty($msg)) - { - $msg = $this->app->erp->base64_url_decode($msg); - $this->app->Tpl->Set('MESSAGE',$msg); - } - $this->app->erp->MenuEintrag('index.php?module=importvorlage&action=uebersicht','Zurück zur Übersicht'); - - //$this->app->Tpl->Add(TABS,"
  • Shopimport

  • "); - $this->app->erp->Headlines('Shopimport'); - //$this->app->erp->MenuEintrag("index.php?module=shopimport&action=alle","Alle importieren"); - $this->app->erp->MenuEintrag('index.php?module=shopimport&action=list','Übersicht'); - - if($this->app->erp->RechteVorhanden('shopimport','alle')){ - $this->app->Tpl->Add('INHALT', "


    "); - } - //$this->app->Tpl->Set('SUBHEADING',"Imports"); - //Jeder der in Nachbesserung war egal ob auto oder manuell wandert anschliessend in Manuelle-Freigabe"); - $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); - if($runningcronjob) - { - $this->app->Tpl->Set('TAB1','
    Es läuft gerade ein Cronjob der Aufträge abholt. Die manuelle Auftragsabholung ist in dieser Zeit gesperrt. Bitte warten Sie ein paar Minuten und versuchen Sie es erneut.
    '); - }else{ - $table = new EasyTable($this->app); - $table->Query("SELECT ae.bezeichnung,p.abkuerzung, + if ($this->app->erp->RechteVorhanden('shopimport', 'alle')) { + $this->app->Tpl->Add('INHALT', "


    "); + } + //$this->app->Tpl->Set('SUBHEADING',"Imports"); + //Jeder der in Nachbesserung war egal ob auto oder manuell wandert anschliessend in Manuelle-Freigabe"); + $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); + if ($runningcronjob) { + $this->app->Tpl->Set('TAB1', '
    Es läuft gerade ein Cronjob der Aufträge abholt. Die manuelle Auftragsabholung ist in dieser Zeit gesperrt. Bitte warten Sie ein paar Minuten und versuchen Sie es erneut.
    '); + } else { + $table = new EasyTable($this->app); + $table->Query("SELECT ae.bezeichnung,p.abkuerzung as Projekt, ae.id FROM shopexport ae LEFT JOIN projekt p ON p.id=ae.projekt WHERE ae.aktiv='1'"); - $table->DisplayNew('INHALT',"  "); - $this->app->Tpl->Parse('TAB1','rahmen.tpl'); - } - $this->app->Tpl->Set('INHALT',''); + $table->DisplayNew('INHALT', "   "); + $this->app->Tpl->Parse('TAB1', 'rahmen.tpl'); + } + $this->app->Tpl->Set('INHALT', ''); - - // Archiv GESTERN - $table = new EasyTable($this->app); - $table->Query("SELECT a.datum, a.internet, a.transaktionsnummer,a.name, a.land, a.gesamtsumme as betrag, (SELECT SUM(r.soll) FROM rechnung r WHERE r.adresse=a.adresse AND r.status='offen') as mahnwesen, a.zahlungsweise, a.partnerid as Partner, a.id FROM auftrag a WHERE + // Archiv GESTERN + $table = new EasyTable($this->app); + $table->Query("SELECT a.datum, a.internet, a.transaktionsnummer,a.name, a.land, a.gesamtsumme as betrag, (SELECT SUM(r.soll) FROM rechnung r WHERE r.adresse=a.adresse AND r.status='offen') as mahnwesen, a.zahlungsweise, a.partnerid as Partner, a.id FROM auftrag a WHERE (datum=DATE_FORMAT( DATE_SUB( NOW() , INTERVAL 1 DAY ) , '%Y-%m-%d' ) OR (datum=DATE_FORMAT( NOW(), '%Y-%m-%d' ))) AND a.internet>0 ORDER by a.id DESC"); - $table->DisplayNew('INHALT',"app->Conf->WFconf['defaulttheme']."/images/edit.svg\"> - app->Conf->WFconf['defaulttheme']."/images/pdf.svg\">"); + $table->DisplayNew('INHALT', "app->Conf->WFconf['defaulttheme'] . "/images/edit.svg\"> + app->Conf->WFconf['defaulttheme'] . "/images/pdf.svg\">"); - $this->app->Tpl->Parse('TAB2','rahmen.tpl'); - $this->app->Tpl->Set('INHALT',''); + $this->app->Tpl->Parse('TAB2', 'rahmen.tpl'); + $this->app->Tpl->Set('INHALT', ''); - - $summe_heute = $this->app->DB->Select("SELECT SUM(a.gesamtsumme) FROM auftrag a WHERE + $summe_heute = $this->app->DB->Select("SELECT SUM(a.gesamtsumme) FROM auftrag a WHERE a.datum=DATE_FORMAT( NOW(), '%Y-%m-%d' ) AND a.internet>0 "); - $summe_gestern = $this->app->DB->Select("SELECT SUM(a.gesamtsumme) FROM auftrag a WHERE + $summe_gestern = $this->app->DB->Select("SELECT SUM(a.gesamtsumme) FROM auftrag a WHERE a.datum=DATE_FORMAT( DATE_SUB( NOW() , INTERVAL 1 DAY ) , '%Y-%m-%d' ) AND a.internet>0 "); - $this->app->Tpl->Add('TAB2',"
    Heute: $summe_heute EUR (inkl. Steuer und Versand) Umsatz aus den Online-Shop
    "); - $this->app->Tpl->Add('TAB2',"
    Gestern: $summe_gestern EUR (inkl. Steuer und Versand) Umsatz aus den Online-Shop
    "); + $this->app->Tpl->Add('TAB2', "
    Heute: $summe_heute EUR (inkl. Steuer und Versand) Umsatz aus den Online-Shop
    "); + $this->app->Tpl->Add('TAB2', "
    Gestern: $summe_gestern EUR (inkl. Steuer und Versand) Umsatz aus den Online-Shop
    "); - $this->app->Tpl->Set('SUBHEADING',''); - $this->app->Tpl->Parse('PAGE','shopimport_list.tpl'); - } - - - public function ShopimportArchiv() - { - $id = $this->app->Secure->GetGET('id'); - $more = $this->app->Secure->GetGET('more'); - $datum = $this->app->Secure->GetGET('datum'); - - $this->app->Tpl->Set('TABTEXT','Shopimport - Archiv'); - - - //$this->app->YUI->TableSearch('TAB1',"shopimportarchiv"); - - //$this->app->Tpl->Set('TAB1',"Shopimport - Archiv"); - - if($datum=='') - { - $datum = date('Y-m-d'); + $this->app->Tpl->Set('SUBHEADING', ''); + $this->app->Tpl->Parse('PAGE', 'shopimport_list.tpl'); } - $result = $this->app->DB->SelectArr("SELECT * FROM shopimport_auftraege WHERE DATE_FORMAT(logdatei,'%Y-%m-%d') = '$datum'"); + public function ShopimportArchiv() { + $id = $this->app->Secure->GetGET('id'); + $more = $this->app->Secure->GetGET('more'); + $datum = $this->app->Secure->GetGET('datum'); + $this->app->Tpl->Set('TABTEXT', 'Shopimport - Archiv'); - $table = '
    Zweistelliger ISO Code:
    Dreistelliger ISO Code:
    Bezeichnung Deutsch:
    Bezeichnung Englisch:
    EU:
    '; + //$this->app->YUI->TableSearch('TAB1',"shopimportarchiv"); + //$this->app->Tpl->Set('TAB1',"Shopimport - Archiv"); - if(is_array($result)) - { - foreach($result as $key=>$row) - { - //$table = $row['imported']; - if(isset($row['jsonencoded']) && $row['jsonencoded']) - { - $warenkorb = json_decode(base64_decode($row['warenkorb']), true); - }else{ - $warenkorb = unserialize(base64_decode($row['warenkorb'])); - } - $this->app->stringcleaner->XMLArray_clean($warenkorb); - - $table .= ""; - - } - } - - $table .= '
    ".$warenkorb["onlinebestellnummer"]."/".$warenkorb["transaktionsnummer"]."".$warenkorb["name"]."".$warenkorb["email"]."".$warenkorb["gesamtsumme"]." - mehr Informationen
    '; - - if($more > 0) - { - $result = $this->app->DB->Select("SELECT warenkorb FROM shopimport_auftraege WHERE id='$more' LIMIT 1"); - if($this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE id='$more' AND jsonencoded = 1 LIMIT 1")) - { - $warenkorb = json_decode(base64_decode($result), true); - }else{ - $warenkorb = unserialize(base64_decode($result)); - } - - ob_start(); - var_dump($warenkorb); - $var_dump_result = ob_get_clean(); - - $table .='
    '.$var_dump_result.'
    '; - - } - - $this->app->Tpl->Set('TAB1',$table); - $this->app->Tpl->Parse('PAGE','tabview.tpl'); - } - - - public function ShopimportAlle() - { - $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); - if(!empty($runningcronjob)) - { - $this->app->Location->execute('index.php?module=shopimport&action=list'); - } - $lastshop = false; - $shops = $this->app->DB->SelectArr("SELECT ae.id as id FROM shopexport ae LEFT JOIN projekt p ON p.id=ae.projekt WHERE ae.aktiv='1' and ae.demomodus <> '1'"); - if(!empty($shops)) - { - $anz = 0; - $fp = $this->app->erp->ProzessLock('shopimport_alle'); - $cshops = (!empty($shops)?count($shops):0); - for($i=0;$i<$cshops-1;$i++) - { - $anz += $this->ShopimportImport($shops[$i]['id'],$anz,true); - } - $lastshop=$shops[(!empty($shops)?count($shops):0)-1]['id']; - $this->app->erp->ProzessUnlock($fp); - } - if($lastshop && is_numeric($lastshop)){ - $this->app->Location->execute('index.php?module=shopimport&action=import&id='.$lastshop); - } - else{ - $this->app->Location->execute('index.php?module=shopimport&action=list'); - } - } - - /** - * @param int $shopId - * @param string $shopOrderNumber - * @param bool $changeShopOrderStatus - * @param int $projectId - * @param bool $allStati - * - * @return array - */ - public function importSingleOrder($shopId, $shopOrderNumber, $changeShopOrderStatus, $projectId, $allStati = false) - { - $pageContents = $this->app->remote->RemoteConnection($shopId); - if($pageContents==='success') - { - $orderCount = $this->app->remote->RemoteGetAuftraegeAnzahlNummer($shopId, $shopOrderNumber); - - if($orderCount > 0) - { - if($allStati){ - $result = $this->app->remote->RemoteCommand($shopId, 'getauftrag', ['nummer' => $shopOrderNumber]); - } - else { - $result = $this->app->remote->RemoteGetAuftragNummer($shopId, $shopOrderNumber); + if ($datum == '') { + $datum = date('Y-m-d'); } - if(is_array($result)) - { - $result = reset($result); - $shopExtId = $result['id']; - $sessionid = $result['sessionid']; - $jsonEncoded = 0; - if(empty(!$result['warenkorbjson'])) { - $jsonEncoded = 1; - $warenkorb = $result['warenkorbjson']; - } else{ - $warenkorb = $result['warenkorb']; - } - $logdatei = $result['logdatei']; - $username = !empty($this->app->User)?$this->app->User->GetName():'Cronjob'; - $this->app->DB->Insert( - sprintf( - "INSERT INTO shopimport_auftraege (extid,sessionid,warenkorb,imported,projekt,bearbeiter,logdatei, jsonencoded, shopid) + $result = $this->app->DB->SelectArr("SELECT * FROM shopimport_auftraege WHERE DATE_FORMAT(logdatei,'%Y-%m-%d') = '$datum'"); + + $table = ''; + + if (is_array($result)) { + foreach ($result as $key => $row) { + //$table = $row['imported']; + if (isset($row['jsonencoded']) && $row['jsonencoded']) { + $warenkorb = json_decode(base64_decode($row['warenkorb']), true); + } else { + $warenkorb = unserialize(base64_decode($row['warenkorb'])); + } + $this->app->stringcleaner->XMLArray_clean($warenkorb); + + $table .= ""; + } + } + + $table .= '
    " . $warenkorb["onlinebestellnummer"] . "/" . $warenkorb["transaktionsnummer"] . "" . $warenkorb["name"] . "" . $warenkorb["email"] . "" . $warenkorb["gesamtsumme"] . " + mehr Informationen
    '; + + if ($more > 0) { + $result = $this->app->DB->Select("SELECT warenkorb FROM shopimport_auftraege WHERE id='$more' LIMIT 1"); + if ($this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE id='$more' AND jsonencoded = 1 LIMIT 1")) { + $warenkorb = json_decode(base64_decode($result), true); + } else { + $warenkorb = unserialize(base64_decode($result)); + } + + ob_start(); + var_dump($warenkorb); + $var_dump_result = ob_get_clean(); + + $table .= '
    ' . $var_dump_result . '
    '; + } + + $this->app->Tpl->Set('TAB1', $table); + $this->app->Tpl->Parse('PAGE', 'tabview.tpl'); + } + + public function ShopimportAlle() { + $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); + if (!empty($runningcronjob)) { + $this->app->Location->execute('index.php?module=shopimport&action=list'); + } + $lastshop = false; + $shops = $this->app->DB->SelectArr("SELECT ae.id as id FROM shopexport ae LEFT JOIN projekt p ON p.id=ae.projekt WHERE ae.aktiv='1' and ae.demomodus <> '1'"); + if (!empty($shops)) { + $anz = 0; + $fp = $this->app->erp->ProzessLock('shopimport_alle'); + $cshops = (!empty($shops) ? count($shops) : 0); + for ($i = 0; $i < $cshops - 1; $i++) { + $anz += $this->ShopimportImport($shops[$i]['id'], $anz, true); + } + $lastshop = $shops[(!empty($shops) ? count($shops) : 0) - 1]['id']; + $this->app->erp->ProzessUnlock($fp); + } + if ($lastshop && is_numeric($lastshop)) { + $this->app->Location->execute('index.php?module=shopimport&action=import&id=' . $lastshop); + } else { + $this->app->Location->execute('index.php?module=shopimport&action=list'); + } + } + + /** + * @param int $shopId + * @param string $shopOrderNumber + * @param bool $changeShopOrderStatus + * @param int $projectId + * @param bool $allStati + * + * @return array + */ + public function importSingleOrder($shopId, $shopOrderNumber, $changeShopOrderStatus, $projectId, $allStati = false) { + $pageContents = $this->app->remote->RemoteConnection($shopId); + if ($pageContents === 'success') { + $orderCount = $this->app->remote->RemoteGetAuftraegeAnzahlNummer($shopId, $shopOrderNumber); + + if ($orderCount > 0) { + if ($allStati) { + $result = $this->app->remote->RemoteCommand($shopId, 'getauftrag', ['nummer' => $shopOrderNumber]); + } else { + $result = $this->app->remote->RemoteGetAuftragNummer($shopId, $shopOrderNumber); + } + + if (is_array($result)) { + $result = reset($result); + $shopExtId = $result['id']; + $sessionid = $result['sessionid']; + $jsonEncoded = 0; + if (empty(!$result['warenkorbjson'])) { + $jsonEncoded = 1; + $warenkorb = $result['warenkorbjson']; + } else { + $warenkorb = $result['warenkorb']; + } + $logdatei = $result['logdatei']; + $username = !empty($this->app->User) ? $this->app->User->GetName() : 'Cronjob'; + $this->app->DB->Insert( + sprintf( + "INSERT INTO shopimport_auftraege (extid,sessionid,warenkorb,imported,projekt,bearbeiter,logdatei, jsonencoded, shopid) VALUES('%s','%s','%s',0,%d, '%s','%s', %d, %d)", - $this->app->DB->real_escape_string($shopExtId), - $this->app->DB->real_escape_string($sessionid), - $this->app->DB->real_escape_string($warenkorb), - (int)$projectId, - $this->app->DB->real_escape_string($username), - $this->app->DB->real_escape_string($logdatei), - $jsonEncoded, - (int)$shopId - ) - ); - $insid = $this->app->DB->GetInsertID(); - if($changeShopOrderStatus && (String)$shopExtId !== '') - { - $this->app->remote->RemoteDeleteAuftrag($shopId, $shopExtId); - } - return ['status'=>1,'id'=>$insid,'info'=>'Auftrag wurde abgeholt.']; + $this->app->DB->real_escape_string($shopExtId), + $this->app->DB->real_escape_string($sessionid), + $this->app->DB->real_escape_string($warenkorb), + (int) $projectId, + $this->app->DB->real_escape_string($username), + $this->app->DB->real_escape_string($logdatei), + $jsonEncoded, + (int) $shopId + ) + ); + $insid = $this->app->DB->GetInsertID(); + if ($changeShopOrderStatus && (String) $shopExtId !== '') { + $this->app->remote->RemoteDeleteAuftrag($shopId, $shopExtId); + } + return ['status' => 1, 'id' => $insid, 'info' => 'Auftrag wurde abgeholt.']; + } + } + return ['status' => 0, 'error' => 'Auftrag wurde nicht gefunden!']; } - } - return ['status'=>0,'error'=>'Auftrag wurde nicht gefunden!']; + return ['status' => 0, 'error' => 'Verbindung fehlgeschlagen!']; } - return ['status'=>0,'error'=>'Verbindung fehlgeschlagen!']; - } - public function ShopimportEinzelimport() - { - $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); - if(!empty($runningcronjob)) - { - $this->app->Location->execute('index.php?module=shopimport&action=list'); - } - $id = (int)$this->app->Secure->GetGET('id'); - $nummer = (String)$this->app->Secure->GetGET('nummer'); - if($nummer === '') - { - $nummer = (String)$this->app->Secure->GetPOST('nummer'); - } - $deleteauftrag = (int)$this->app->Secure->GetPOST('deleteauftrag'); - if(!empty($id) && !empty($nummer)) - { - $shoparr = $this->app->DB->SelectRow("SELECT projekt,holealle FROM shopexport WHERE id = '$id' LIMIT 1"); - $projekt = $shoparr['projekt'];//$this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '$id' LIMIT 1"); - $holealle = $shoparr['holealle'];//$this->app->DB->Select("SELECT holealle FROM shopexport WHERE id = '$id' LIMIT 1"); - if($holealle) - { + public function ShopimportEinzelimport() { + $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); + if (!empty($runningcronjob)) { + $this->app->Location->execute('index.php?module=shopimport&action=list'); + } + $id = (int) $this->app->Secure->GetGET('id'); + $nummer = (String) $this->app->Secure->GetGET('nummer'); + if ($nummer === '') { + $nummer = (String) $this->app->Secure->GetPOST('nummer'); + } + $deleteauftrag = (int) $this->app->Secure->GetPOST('deleteauftrag'); + if (!empty($id) && !empty($nummer)) { + $shoparr = $this->app->DB->SelectRow("SELECT projekt,holealle FROM shopexport WHERE id = '$id' LIMIT 1"); + $projekt = $shoparr['projekt']; //$this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '$id' LIMIT 1"); + $holealle = $shoparr['holealle']; //$this->app->DB->Select("SELECT holealle FROM shopexport WHERE id = '$id' LIMIT 1"); + if ($holealle) { - $res = $this->importSingleOrder($id, $nummer, $deleteauftrag, $projekt); - if($res['status'] == 1){ - $this->app->Tpl->Add('MESSAGE','
    '.$res['info'].'
    '); + $res = $this->importSingleOrder($id, $nummer, $deleteauftrag, $projekt); + if ($res['status'] == 1) { + $this->app->Tpl->Add('MESSAGE', '
    ' . $res['info'] . '
    '); + } else { + $this->app->Tpl->Add('MESSAGE', '
    ' . $res['error'] . '
    '); + } + } else { + $this->app->Tpl->Add('MESSAGE', '
    Shop nicht auf alle Aufträge eingstellt!
    '); + } + } elseif ($id <= 0) { + $msg = $this->app->erp->base64_url_encode('
    Kein Shop gewählt!
    '); + $this->app->Location->execute('index.php?module=shopimport&action=list&msg=' . $msg); } else { - $this->app->Tpl->Add('MESSAGE','
    '.$res['error'].'
    '); + $this->app->Tpl->Add('MESSAGE', '
    Keine Nummer angegeben!
    '); } - }else{ - $this->app->Tpl->Add('MESSAGE','
    Shop nicht auf alle Aufträge eingstellt!
    '); - } - } elseif($id <= 0) { - $msg = $this->app->erp->base64_url_encode('
    Kein Shop gewählt!
    '); - $this->app->Location->execute('index.php?module=shopimport&action=list&msg='.$msg); - } else { - $this->app->Tpl->Add('MESSAGE','
    Keine Nummer angegeben!
    '); - } - $this->app->erp->MenuEintrag('index.php?module=shopimport&action=einzelimport&id='.$id,'Einzelimport'); - $this->app->erp->MenuEintrag('index.php?module=shopimport&action=import','Shopauftrag-Liste'); - $this->app->Tpl->Parse('PAGE','shopimport_einzelimport.tpl'); - } - - public function KundeAnlegenUpdate($shopimportid,$shopextid, $warenkorb, $kundennummer = 0, $import_kundennummer, &$unbekanntezahlungsweisen) - { - if(empty($warenkorb)) { - return 0; - } - if(!empty($this->app->stringcleaner)){ - $this->app->stringcleaner->XMLArray_clean($warenkorb); - } - $i = 0; - $sucess_import = 0; - $shopid = $this->app->DB->Select("SELECT shopid FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1"); - $shopexportArr = $this->app->DB->SelectRow(sprintf('SELECT * FROM shopexport WHERE id=%d', $shopid)); - $projekt = $shopexportArr['projekt'];//$this->app->DB->Select("SELECT projekt FROM shopexport WHERE id='$shopid'"); - if(!empty($warenkorb['projekt']) && $this->app->DB->Select("SELECT id FROM projekt WHERE id = '".(int)$warenkorb['projekt']."' LIMIT 1")) - { - $projekt = (int)$warenkorb['projekt']; - } - $adresseprojekt = ''; - $kundenurvonprojekt = $shopexportArr['kundenurvonprojekt'];//$this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '".$shopid."' LIMIT 1"); - if($kundenurvonprojekt) - { - $adresseprojekt = $projekt; + $this->app->erp->MenuEintrag('index.php?module=shopimport&action=einzelimport&id=' . $id, 'Einzelimport'); + $this->app->erp->MenuEintrag('index.php?module=shopimport&action=import', 'Shopauftrag-Liste'); + $this->app->Tpl->Parse('PAGE', 'shopimport_einzelimport.tpl'); } - if(isset($warenkorb['subshop']) && $warenkorb['subshop']) - { - $subshopprojekt = $this->app->DB->SelectArr("SELECT * FROM shopexport_subshop WHERE shop = '".$shopid."' AND aktiv = 1 AND subshopkennung = '".$this->app->DB->real_escape_string($warenkorb['subshop'])."' LIMIT 1"); - if($subshopprojekt) - { - if($subshopprojekt[0]['projekt']) - { - $adresseprojekt = $subshopprojekt[0]['projekt']; - $projekt = $subshopprojekt[0]['projekt']; - $arr[$i]['abkuerzung'] = $this->app->DB->Select("SELECT abkuerzung FROM projekt WHERE id = '$adresseprojekt' LIMIT 1"); + public function KundeAnlegenUpdate($shopimportid, $shopextid, $warenkorb, $kundennummer = 0, $import_kundennummer, &$unbekanntezahlungsweisen) { + if (empty($warenkorb)) { + return 0; } - if($subshopprojekt[0]['sprache']) - { - $defaultsprache = $this->app->DB->Select("SELECT sprache FROM shopexport_sprachen WHERE shop = '$shopid' AND (projekt = '$projekt' OR projekt = 0) AND - land = '' ORDER BY projekt = '$projekt' DESC, land = '".$warenkorb['land']."' DESC LIMIT 1"); - $checksprache = $this->app->DB->Select("SELECT sprache FROM shopexport_sprachen WHERE shop = '$shopid' AND (projekt = '$projekt' OR projekt = 0) AND - land = '".(isset($warenkorb['land'])?$warenkorb['land']:$this->app->erp->Firmendaten('land'))."' ORDER BY projekt = '$projekt' DESC, land = '".$warenkorb['land']."' DESC LIMIT 1"); - if($checksprache != ''){ - if(empty($warenkorb['kunde_sprache'])) - { - $warenkorb['kunde_sprache'] = $checksprache; + if (!empty($this->app->stringcleaner)) { + $this->app->stringcleaner->XMLArray_clean($warenkorb); + } + $i = 0; + $success_import = 0; + $shopid = $this->app->DB->Select("SELECT shopid FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1"); + $shopexportArr = $this->app->DB->SelectRow(sprintf('SELECT * FROM shopexport WHERE id=%d', $shopid)); + $projekt = $shopexportArr['projekt']; //$this->app->DB->Select("SELECT projekt FROM shopexport WHERE id='$shopid'"); + if (!empty($warenkorb['projekt']) && $this->app->DB->Select("SELECT id FROM projekt WHERE id = '" . (int) $warenkorb['projekt'] . "' LIMIT 1")) { + $projekt = (int) $warenkorb['projekt']; + } + $adresseprojekt = ''; + $kundenurvonprojekt = $shopexportArr['kundenurvonprojekt']; //$this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '".$shopid."' LIMIT 1"); + if ($kundenurvonprojekt) { + $adresseprojekt = $projekt; + } + + if (isset($warenkorb['subshop']) && $warenkorb['subshop']) { + $subshopprojekt = $this->app->DB->SelectArr("SELECT * FROM shopexport_subshop WHERE shop = '" . $shopid . "' AND aktiv = 1 AND subshopkennung = '" . $this->app->DB->real_escape_string($warenkorb['subshop']) . "' LIMIT 1"); + if ($subshopprojekt) { + if ($subshopprojekt[0]['projekt']) { + $adresseprojekt = $subshopprojekt[0]['projekt']; + $projekt = $subshopprojekt[0]['projekt']; + $arr[$i]['abkuerzung'] = $this->app->DB->Select("SELECT abkuerzung FROM projekt WHERE id = '$adresseprojekt' LIMIT 1"); + } + if ($subshopprojekt[0]['sprache']) { + $defaultsprache = $this->app->DB->Select("SELECT sprache FROM shopexport_sprachen WHERE shop = '$shopid' AND (projekt = '$projekt' OR projekt = 0) AND + land = '' ORDER BY projekt = '$projekt' DESC, land = '" . $warenkorb['land'] . "' DESC LIMIT 1"); + $checksprache = $this->app->DB->Select("SELECT sprache FROM shopexport_sprachen WHERE shop = '$shopid' AND (projekt = '$projekt' OR projekt = 0) AND + land = '" . (isset($warenkorb['land']) ? $warenkorb['land'] : $this->app->erp->Firmendaten('land')) . "' ORDER BY projekt = '$projekt' DESC, land = '" . $warenkorb['land'] . "' DESC LIMIT 1"); + if ($checksprache != '') { + if (empty($warenkorb['kunde_sprache'])) { + $warenkorb['kunde_sprache'] = $checksprache; + } + } else { + if (empty($warenkorb['kunde_sprache'])) { + $warenkorb['kunde_sprache'] = $defaultsprache; + } + } + + if (empty($warenkorb['kunde_sprache'])) { + $warenkorb['kunde_sprache'] = $subshopprojekt[0]['sprache']; + } + } + } else { + if (!$this->app->DB->Select("SELECT id FROM shopexport_subshop WHERE shop = '" . $shopid . "' AND subshopkennung = '" . $this->app->DB->real_escape_string($warenkorb['subshop']) . "' LIMIT 1")) { + $this->app->DB->Insert("INSERT INTO shopexport_subshop (shop, subshopkennung, aktiv, projekt) VALUES ('" . $shopid . "','" . $this->app->DB->real_escape_string($warenkorb['subshop']) . "','0','$projekt')"); + } } - } - else{ - if(empty($warenkorb['kunde_sprache'])) - { - $warenkorb['kunde_sprache'] = $defaultsprache; + } + + $kundenurvonprojekt = $this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '$shopid' LIMIT 1"); + if ($kundenurvonprojekt) { + $adresseprojekt = " AND projekt = '" . $adresseprojekt . "' "; + } else { + $adresseprojekt = ''; + } + + if (empty($warenkorb['name'])) { + $warenkorb['name'] = $warenkorb['ansprechpartner']; + $warenkorb['ansprechpartner'] = ''; + } + if (empty($warenkorb['name']) && !empty($warenkorb['lieferadresse_name'])) { + $warenkorb['name'] = $warenkorb['lieferadresse_name']; + } + if (empty($warenkorb['lieferadresse_name'])) { + $warenkorb['lieferadresse_name'] = $warenkorb['lieferadresse_ansprechpartner']; + $warenkorb['lieferadresse_ansprechpartner'] = ''; + } + $warenkorb['email'] = trim($warenkorb['email'], " \t\n\r\0\x0B\xc2\xa0"); + if (empty($warenkorb['name'])) { + return 0; + } + //$projekt = $arr[0][projekt]; + + if ($kundennummer == '1') { + $warenkorb['kundennummer'] = $import_kundennummer; + if (strlen($warenkorb['kundennummer']) != '') { + $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='{$warenkorb['kundennummer']}' AND geloescht!=1 $adresseprojekt LIMIT 1"); } - } - - if(empty($warenkorb['kunde_sprache'])) - { - $warenkorb['kunde_sprache'] = $subshopprojekt[0]['sprache']; - } - } - }else{ - if(!$this->app->DB->Select("SELECT id FROM shopexport_subshop WHERE shop = '".$shopid."' AND subshopkennung = '".$this->app->DB->real_escape_string($warenkorb['subshop'])."' LIMIT 1")) - { - $this->app->DB->Insert("INSERT INTO shopexport_subshop (shop, subshopkennung, aktiv, projekt) VALUES ('".$shopid."','".$this->app->DB->real_escape_string($warenkorb['subshop'])."','0','$projekt')"); - } - } - } + if ($adresse <= 0) { + $adresse = $this->app->erp->KundeAnlegen($warenkorb['anrede'], $warenkorb['name'], $warenkorb['abteilung'], + $warenkorb['unterabteilung'], $warenkorb['ansprechpartner'], $warenkorb['adresszusatz'], $warenkorb['strasse'], $warenkorb['land'], $warenkorb['plz'], $warenkorb['ort'], $warenkorb['email'], + $warenkorb['telefon'], $warenkorb['telefax'], $warenkorb['ustid'], $warenkorb['affiliate_ref'], $projekt); + $warenkorb['customer_created'] = true; + if (isset($warenkorb['kunde_sprache'])) { + if ($warenkorb['kunde_sprache'] == 'englisch' || $warenkorb['kunde_sprache'] == 'english') { + $this->app->DB->Update("UPDATE adresse SET sprache = 'englisch' WHERE id = '$adresse' LIMIT 1"); + } elseif ($warenkorb['kunde_sprache'] == 'deutsch' || $warenkorb['kunde_sprache'] == 'german') { + $this->app->DB->Update("UPDATE adresse SET sprache = 'deutsch' WHERE id = '$adresse' LIMIT 1"); + } elseif (method_exists($this->app->erp, 'GetSprachenSelect')) { + $sprachen = $this->app->erp->GetSprachenSelect; + if (isset($sprachen[strtolower($warenkorb['kunde_sprache'])])) { + $this->app->DB->Update("UPDATE adresse SET sprache = '" . strtolower($warenkorb['kunde_sprache']) . "' WHERE id = '$adresse' LIMIT 1"); + } + } + } + if ($warenkorb['titel'] != '') { + $this->app->DB->Update("UPDATE adresse SET titel = '" . $this->app->DB->real_escape_string($warenkorb['titel']) . "' WHERE id = '$adresse' LIMIT 1"); + } + if (isset($warenkorb['ust_befreit'])) { + $this->app->DB->Update("UPDATE adresse SET ust_befreit = '" . (int) $warenkorb['ust_befreit'] . "' WHERE id = '$adresse' LIMIT 1"); + } - $kundenurvonprojekt = $this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '$shopid' LIMIT 1"); - if($kundenurvonprojekt) - { - $adresseprojekt = " AND projekt = '".$adresseprojekt."' "; - }else{ - $adresseprojekt = ''; - } + $kundenGruppen = $this->app->DB->SelectArr("SELECT gruppeid,type FROM shopexport_kundengruppen WHERE shopid=$shopid AND aktiv=1 AND apply_to_new_customers=1 AND type<>'Artikel' AND (projekt=0 OR projekt='$projekt')"); + if (!empty($kundenGruppen)) { + foreach ($kundenGruppen as $gruppe) { + $this->app->erp->AddRolleZuAdresse($adresse, $gruppe['type'], 'von', 'Gruppe', $gruppe['gruppeid']); + } + } - if(empty($warenkorb['name'])){ - $warenkorb['name']=$warenkorb['ansprechpartner']; - $warenkorb['ansprechpartner'] = ''; - } - if(empty($warenkorb['name']) && !empty($warenkorb['lieferadresse_name'])) { - $warenkorb['name'] = $warenkorb['lieferadresse_name']; - } - if(empty($warenkorb['lieferadresse_name'])){ - $warenkorb['lieferadresse_name']=$warenkorb['lieferadresse_ansprechpartner']; - $warenkorb['lieferadresse_ansprechpartner'] = ''; - } - $warenkorb['email'] = trim($warenkorb['email']," \t\n\r\0\x0B\xc2\xa0"); - if(empty($warenkorb['name'])) { - return 0; - } - //$projekt = $arr[0][projekt]; + if (isset($warenkorb['kundengruppe'])) { + $this->shopimportAdresseGruppenMapping($warenkorb['kundengruppe'], $adresse, $shopid, $projekt); + } + if ($shopexportArr['vertrieb']) { + $this->app->DB->Update( + sprintf( + 'UPDATE adresse SET vertrieb = %d WHERE id = %d', + $shopexportArr['vertrieb'], $adresse + ) + ); + } + $this->app->DB->Update( + sprintf( + 'UPDATE adresse SET fromshop = %d WHERE fromshop = 0 AND id = %d', + $shopexportArr['id'], $adresse + ) + ); + } else { + if (!empty($warenkorb['anrede'])) { + $typ = $warenkorb['anrede']; + } else { + $typ = $this->app->DB->Select("SELECT typ FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + $name = $warenkorb['name']; - if($kundennummer=='1') - { - $warenkorb['kundennummer']= $import_kundennummer; - if(strlen($warenkorb['kundennummer'])!=''){ - $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='{$warenkorb['kundennummer']}' AND geloescht!=1 $adresseprojekt LIMIT 1"); - } - if($adresse<=0) { - $adresse = $this->app->erp->KundeAnlegen($warenkorb['anrede'],$warenkorb['name'],$warenkorb['abteilung'], - $warenkorb['unterabteilung'],$warenkorb['ansprechpartner'],$warenkorb['adresszusatz'],$warenkorb['strasse'],$warenkorb['land'],$warenkorb['plz'],$warenkorb['ort'],$warenkorb['email'], - $warenkorb['telefon'],$warenkorb['telefax'],$warenkorb['ustid'],$warenkorb['affiliate_ref'],$projekt); - $warenkorb['customer_created'] = true; - if(isset($warenkorb['kunde_sprache'])) - { - if($warenkorb['kunde_sprache'] == 'englisch' || $warenkorb['kunde_sprache'] == 'english') - { - $this->app->DB->Update("UPDATE adresse SET sprache = 'englisch' WHERE id = '$adresse' LIMIT 1"); - }elseif($warenkorb['kunde_sprache'] == 'deutsch' || $warenkorb['kunde_sprache'] == 'german') - { - $this->app->DB->Update("UPDATE adresse SET sprache = 'deutsch' WHERE id = '$adresse' LIMIT 1"); - }elseif(method_exists($this->app->erp, 'GetSprachenSelect')){ - $sprachen = $this->app->erp->GetSprachenSelect; - if(isset($sprachen[strtolower($warenkorb['kunde_sprache'])])) - { - $this->app->DB->Update("UPDATE adresse SET sprache = '".strtolower($warenkorb['kunde_sprache'])."' WHERE id = '$adresse' LIMIT 1"); - } + if (!empty($warenkorb['abteilung'])) { + $abteilung = $warenkorb['abteilung']; + } else { + $abteilung = $this->app->DB->Select("SELECT abteilung FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + if (!empty($warenkorb['unterabteilung'])) { + $unterabteilung = $warenkorb['unterabteilung']; + } else { + $unterabteilung = $this->app->DB->Select("SELECT unterabteilung FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + + $ansprechpartner = $warenkorb['ansprechpartner']; + $adresszusatz = $warenkorb['adresszusatz']; + $strasse = $warenkorb['strasse']; + $land = $warenkorb['land']; + $plz = $warenkorb['plz']; + $ort = $warenkorb['ort']; + if (!empty($warenkorb['email'])) { + $email = $warenkorb['email']; + } else { + $email = $this->app->DB->Select("SELECT email FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + if (!empty($warenkorb['telefon'])) { + $telefon = $warenkorb['telefon']; + } else { + $telefon = $this->app->DB->Select("SELECT telefon FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + if (!empty($warenkorb['telefax'])) { + $telefax = $warenkorb['telefax']; + } else { + $telefax = $this->app->DB->Select("SELECT telefax FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + if (!empty($warenkorb['ustid'])) { + $ustid = $warenkorb['ustid']; + } else { + $ustid = $this->app->DB->Select("SELECT ustid FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + if (!empty($warenkorb['affiliate_ref'])) { + $partner = $warenkorb['affiliate_ref']; + } else { + $partner = $this->app->DB->Select("SELECT partner FROM adresse WHERE id = '$adresse' LIMIT 1"); + } + // Update + protokoll + if (!$this->app->DB->Select("SELECT adressennichtueberschreiben FROM shopexport WHERE id = '$shopid' LIMIT 1")) { + if ($warenkorb['mobil'] != '') { + $this->app->DB->Update("UPDATE adresse SET mobil = '" . $this->app->DB->real_escape_string($warenkorb['mobil']) . "' WHERE id = '$adresse' LIMIT 1"); + } + if ($warenkorb['titel'] != '') { + $this->app->DB->Update("UPDATE adresse SET titel = '" . $this->app->DB->real_escape_string($warenkorb['titel']) . "' WHERE id = '$adresse' LIMIT 1"); + } + if ($warenkorb['geburtstag'] != '') { + $this->app->DB->Update("UPDATE adresse SET geburtstag = '" . $this->app->DB->real_escape_string($warenkorb['geburtstag']) . "' WHERE id = '$adresse' AND ISNULL(geburtstag) LIMIT 1"); + } + if (isset($warenkorb['ust_befreit'])) { + $query = sprintf('UPDATE `adresse` SET `ust_befreit` = %d WHERE `id` = %d LIMIT 1', + $warenkorb['ust_befreit'], $adresse); + $this->app->DB->Update($query); + } + $this->app->erp->KundeUpdate($adresse, $typ, $name, $abteilung, + $unterabteilung, $ansprechpartner, $adresszusatz, $strasse, $land, $plz, $ort, $email, $telefon, $telefax, $ustid, $partner, $projekt); + + if (!empty($warenkorb['bundesland'])) { + $this->app->DB->Update("UPDATE adresse SET bundesland = '" . $this->app->DB->real_escape_string($warenkorb['bundesland']) . "' WHERE id = '$adresse' LIMIT 1"); + } + } } - } - if($warenkorb['titel'] != ''){ - $this->app->DB->Update("UPDATE adresse SET titel = '".$this->app->DB->real_escape_string($warenkorb['titel'])."' WHERE id = '$adresse' LIMIT 1"); - } - if(isset($warenkorb['ust_befreit'])) - { - $this->app->DB->Update("UPDATE adresse SET ust_befreit = '".(int)$warenkorb['ust_befreit']."' WHERE id = '$adresse' LIMIT 1"); - } - - $kundenGruppen = $this->app->DB->SelectArr("SELECT gruppeid,type FROM shopexport_kundengruppen WHERE shopid=$shopid AND aktiv=1 AND apply_to_new_customers=1 AND type<>'Artikel' AND (projekt=0 OR projekt='$projekt')"); - if(!empty($kundenGruppen)){ - foreach ($kundenGruppen as $gruppe){ - $this->app->erp->AddRolleZuAdresse($adresse, $gruppe['type'], 'von', 'Gruppe', $gruppe['gruppeid']); - } - } - - if(isset($warenkorb['kundengruppe'])){ - $this->shopimportAdresseGruppenMapping($warenkorb['kundengruppe'],$adresse,$shopid,$projekt); - } - if($shopexportArr['vertrieb']) { - $this->app->DB->Update( - sprintf( - 'UPDATE adresse SET vertrieb = %d WHERE id = %d', - $shopexportArr['vertrieb'], $adresse - ) - ); - } - $this->app->DB->Update( - sprintf( - 'UPDATE adresse SET fromshop = %d WHERE fromshop = 0 AND id = %d', - $shopexportArr['id'], $adresse - ) - ); - } - else { - if(!empty($warenkorb['anrede'])) - { + } else { + //echo "import als Neu-Kunde $shopimportid
    "; $typ = $warenkorb['anrede']; - }else{ - $typ = $this->app->DB->Select("SELECT typ FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - $name= $warenkorb['name']; - - if(!empty($warenkorb['abteilung'])) - { + $name = $warenkorb['name']; $abteilung = $warenkorb['abteilung']; - }else{ - $abteilung = $this->app->DB->Select("SELECT abteilung FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - if(!empty($warenkorb['unterabteilung'])) - { $unterabteilung = $warenkorb['unterabteilung']; - }else{ - $unterabteilung = $this->app->DB->Select("SELECT unterabteilung FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - - $ansprechpartner = $warenkorb['ansprechpartner']; - $adresszusatz = $warenkorb['adresszusatz']; - $strasse = $warenkorb['strasse']; - $land = $warenkorb['land']; - $plz = $warenkorb['plz']; - $ort = $warenkorb['ort']; - if(!empty($warenkorb['email'])) - { + $ansprechpartner = $warenkorb['ansprechpartner']; + $adresszusatz = $warenkorb['adresszusatz']; + $strasse = $warenkorb['strasse']; + $land = $warenkorb['land']; + $plz = $warenkorb['plz']; + $ort = $warenkorb['ort']; $email = $warenkorb['email']; - }else{ - $email = $this->app->DB->Select("SELECT email FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - if(!empty($warenkorb['telefon'])) - { $telefon = $warenkorb['telefon']; - }else{ - $telefon = $this->app->DB->Select("SELECT telefon FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - if(!empty($warenkorb['telefax'])) - { $telefax = $warenkorb['telefax']; - }else{ - $telefax = $this->app->DB->Select("SELECT telefax FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - if(!empty($warenkorb['ustid'])) - { $ustid = $warenkorb['ustid']; - }else{ - $ustid = $this->app->DB->Select("SELECT ustid FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - if(!empty($warenkorb['affiliate_ref'])) - { $partner = $warenkorb['affiliate_ref']; - }else{ - $partner = $this->app->DB->Select("SELECT partner FROM adresse WHERE id = '$adresse' LIMIT 1"); - } - // Update + protokoll - if(!$this->app->DB->Select("SELECT adressennichtueberschreiben FROM shopexport WHERE id = '$shopid' LIMIT 1")) - { - if($warenkorb['mobil'] != ''){ - $this->app->DB->Update("UPDATE adresse SET mobil = '".$this->app->DB->real_escape_string($warenkorb['mobil'])."' WHERE id = '$adresse' LIMIT 1"); - } - if($warenkorb['titel'] != ''){ - $this->app->DB->Update("UPDATE adresse SET titel = '".$this->app->DB->real_escape_string($warenkorb['titel'])."' WHERE id = '$adresse' LIMIT 1"); - } - if($warenkorb['geburtstag'] != ''){ - $this->app->DB->Update("UPDATE adresse SET geburtstag = '".$this->app->DB->real_escape_string($warenkorb['geburtstag'])."' WHERE id = '$adresse' AND ISNULL(geburtstag) LIMIT 1"); - } - if(isset($warenkorb['ust_befreit'])){ - $query = sprintf('UPDATE `adresse` SET `ust_befreit` = %d WHERE `id` = %d LIMIT 1', - $warenkorb['ust_befreit'], $adresse); - $this->app->DB->Update($query); - } - $this->app->erp->KundeUpdate($adresse,$typ,$name,$abteilung, - $unterabteilung,$ansprechpartner,$adresszusatz,$strasse,$land,$plz,$ort,$email,$telefon,$telefax,$ustid,$partner,$projekt); - - if(!empty($warenkorb['bundesland'])) - { - $this->app->DB->Update("UPDATE adresse SET bundesland = '".$this->app->DB->real_escape_string($warenkorb['bundesland'])."' WHERE id = '$adresse' LIMIT 1"); - } - } - } - } - else { - //echo "import als Neu-Kunde $shopimportid
    "; - $typ = $warenkorb['anrede']; - $name= $warenkorb['name']; - $abteilung = $warenkorb['abteilung']; - $unterabteilung = $warenkorb['unterabteilung']; - $ansprechpartner = $warenkorb['ansprechpartner']; - $adresszusatz = $warenkorb['adresszusatz']; - $strasse = $warenkorb['strasse']; - $land = $warenkorb['land']; - $plz = $warenkorb['plz']; - $ort = $warenkorb['ort']; - $email = $warenkorb['email']; - $telefon = $warenkorb['telefon']; - $telefax = $warenkorb['telefax']; - $ustid = $warenkorb['ustid']; - $partner = $warenkorb['affiliate_ref']; - - // denn fall das es kunde 1:1 schon gibt = alte Kundennummer verwenden kommt vor allem vor, wenn ein Kunde an einem Tag oefters bestellt hat - // $adresse = $this->app->erp->KundeAnlegen($typ,$name,$abteilung, - // $unterabteilung,$ansprechpartner,$adresszusatz,$strasse,$land,$plz,$ort,$email,$telefon,$telefax,$ustid,$partner,$projekt); - if(!empty($warenkorb['kundennummer'])){ - $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='{$warenkorb['kundennummer']}' $adresseprojekt AND geloescht!=1 LIMIT 1"); - } - if(empty($adresse)){ - $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE email='{$warenkorb['email']}' and email <> '' $adresseprojekt AND geloescht!=1 LIMIT 1"); - } - - if($adresse<=0) { - $adresse = $this->app->erp->KundeAnlegen($typ,$name,$abteilung, - $unterabteilung,$ansprechpartner,$adresszusatz,$strasse,$land,$plz,$ort,$email,$telefon,$telefax,$ustid,$partner,$projekt); - $warenkorb['customer_created'] = true; - if(!empty($warenkorb['bundesland'])) - { - $this->app->DB->Update("UPDATE adresse SET bundesland = '".$this->app->DB->real_escape_string($warenkorb['bundesland'])."' WHERE id = '$adresse' LIMIT 1"); - } - - if(isset($warenkorb['kunde_sprache'])) - { - if($warenkorb['kunde_sprache'] === 'englisch' || $warenkorb['kunde_sprache'] === 'english') - { - $this->app->DB->Update("UPDATE adresse SET sprache = 'englisch' WHERE id = '$adresse' LIMIT 1"); - }elseif($warenkorb['kunde_sprache'] === 'deutsch' || $warenkorb['kunde_sprache'] === 'german') - { - $this->app->DB->Update("UPDATE adresse SET sprache = 'deutsch' WHERE id = '$adresse' LIMIT 1"); - }elseif(method_exists($this->app->erp, 'GetAdressSprachen')){ - $sprachen = $this->app->erp->GetAdressSprachen(); - if(isset($sprachen[strtolower($warenkorb['kunde_sprache'])])) - { - $this->app->DB->Update("UPDATE adresse SET sprache = '".strtolower($warenkorb['kunde_sprache'])."' WHERE id = '$adresse' LIMIT 1"); - } + // denn fall das es kunde 1:1 schon gibt = alte Kundennummer verwenden kommt vor allem vor, wenn ein Kunde an einem Tag oefters bestellt hat + // $adresse = $this->app->erp->KundeAnlegen($typ,$name,$abteilung, + // $unterabteilung,$ansprechpartner,$adresszusatz,$strasse,$land,$plz,$ort,$email,$telefon,$telefax,$ustid,$partner,$projekt); + if (!empty($warenkorb['kundennummer'])) { + $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='{$warenkorb['kundennummer']}' $adresseprojekt AND geloescht!=1 LIMIT 1"); } - } - if($warenkorb['titel'] != ''){ - $this->app->DB->Update("UPDATE adresse SET titel = '".$this->app->DB->real_escape_string($warenkorb['titel'])."' WHERE id = '$adresse' LIMIT 1"); - } - if(isset($warenkorb['ust_befreit'])) - { - $this->app->DB->Update("UPDATE adresse SET ust_befreit = '".(int)$warenkorb['ust_befreit']."' WHERE id = '$adresse' LIMIT 1"); - } - if($warenkorb['mobil'] != ''){ - $this->app->DB->Update("UPDATE adresse SET mobil = '".$this->app->DB->real_escape_string($warenkorb['mobil'])."' WHERE id = '$adresse' LIMIT 1"); - } - if(!empty($warenkorb['geburtstag'])){ - $query = sprintf("UPDATE `adresse` SET `geburtstag` = '%s' WHERE `id` = %d", - $this->app->DB->real_escape_string($warenkorb['geburtstag']), - $adresse); - $this->app->DB->Update($query); - } - $kundenGruppen = $this->app->DB->SelectArr("SELECT gruppeid,type FROM shopexport_kundengruppen WHERE shopid=$shopid AND aktiv=1 AND apply_to_new_customers=1 AND (projekt=0 OR projekt='$projekt')"); - if(!empty($kundenGruppen)){ - foreach ($kundenGruppen as $gruppe){ - $this->app->erp->AddRolleZuAdresse($adresse, $gruppe['type'], 'von', 'Gruppe', $gruppe['gruppeid']); - } - } - if(isset($warenkorb['kundengruppe'])){ - $this->shopimportAdresseGruppenMapping($warenkorb['kundengruppe'],$adresse,$shopid,$projekt); - } - if($shopexportArr['vertrieb']) { - $this->app->DB->Update( - sprintf( - 'UPDATE adresse SET vertrieb = %d WHERE id = %d AND geloescht <> 1 AND vertrieb = 0', - $shopexportArr['vertrieb'], $adresse - ) - ); - } - $this->app->DB->Update( - sprintf( - 'UPDATE adresse SET fromshop = %d WHERE fromshop = 0 AND id = %d', - $shopexportArr['id'], $adresse - ) - ); - } else { - // Update + protokoll - if(!$this->app->DB->Select("SELECT adressennichtueberschreiben FROM shopexport WHERE id = '$shopid' LIMIT 1")) - { - $this->app->erp->KundeUpdate($adresse,$typ,$name,$abteilung, - $unterabteilung,$ansprechpartner,$adresszusatz,$strasse,$land,$plz,$ort,$email,$telefon,$telefax,$ustid,$partner,$projekt); - if(!empty($warenkorb['bundesland'])) - { - $this->app->DB->Update("UPDATE adresse SET bundesland = '".$this->app->DB->real_escape_string($warenkorb['bundesland'])."' WHERE id = '$adresse' LIMIT 1"); + if (empty($adresse)) { + $adresse = $this->app->DB->Select("SELECT id FROM adresse WHERE email='{$warenkorb['email']}' and email <> '' $adresseprojekt AND geloescht!=1 LIMIT 1"); } - } - } - // abweichende lieferadresse gleich angelegen? - if(strlen($warenkorb['lieferadresse_ansprechpartner'])>3) - { - $this->app->DB->Insert("INSERT INTO lieferadressen (typ,name,abteilung,unterabteilung,land,strasse,ort,plz,adresszusatz,adresse) VALUES + + if ($adresse <= 0) { + $adresse = $this->app->erp->KundeAnlegen($typ, $name, $abteilung, + $unterabteilung, $ansprechpartner, $adresszusatz, $strasse, $land, $plz, $ort, $email, $telefon, $telefax, $ustid, $partner, $projekt); + $warenkorb['customer_created'] = true; + if (!empty($warenkorb['bundesland'])) { + $this->app->DB->Update("UPDATE adresse SET bundesland = '" . $this->app->DB->real_escape_string($warenkorb['bundesland']) . "' WHERE id = '$adresse' LIMIT 1"); + } + + if (isset($warenkorb['kunde_sprache'])) { + if ($warenkorb['kunde_sprache'] === 'englisch' || $warenkorb['kunde_sprache'] === 'english') { + $this->app->DB->Update("UPDATE adresse SET sprache = 'englisch' WHERE id = '$adresse' LIMIT 1"); + } elseif ($warenkorb['kunde_sprache'] === 'deutsch' || $warenkorb['kunde_sprache'] === 'german') { + $this->app->DB->Update("UPDATE adresse SET sprache = 'deutsch' WHERE id = '$adresse' LIMIT 1"); + } elseif (method_exists($this->app->erp, 'GetAdressSprachen')) { + $sprachen = $this->app->erp->GetAdressSprachen(); + if (isset($sprachen[strtolower($warenkorb['kunde_sprache'])])) { + $this->app->DB->Update("UPDATE adresse SET sprache = '" . strtolower($warenkorb['kunde_sprache']) . "' WHERE id = '$adresse' LIMIT 1"); + } + } + } + if ($warenkorb['titel'] != '') { + $this->app->DB->Update("UPDATE adresse SET titel = '" . $this->app->DB->real_escape_string($warenkorb['titel']) . "' WHERE id = '$adresse' LIMIT 1"); + } + if (isset($warenkorb['ust_befreit'])) { + $this->app->DB->Update("UPDATE adresse SET ust_befreit = '" . (int) $warenkorb['ust_befreit'] . "' WHERE id = '$adresse' LIMIT 1"); + } + if ($warenkorb['mobil'] != '') { + $this->app->DB->Update("UPDATE adresse SET mobil = '" . $this->app->DB->real_escape_string($warenkorb['mobil']) . "' WHERE id = '$adresse' LIMIT 1"); + } + if (!empty($warenkorb['geburtstag'])) { + $query = sprintf("UPDATE `adresse` SET `geburtstag` = '%s' WHERE `id` = %d", + $this->app->DB->real_escape_string($warenkorb['geburtstag']), + $adresse); + $this->app->DB->Update($query); + } + $kundenGruppen = $this->app->DB->SelectArr("SELECT gruppeid,type FROM shopexport_kundengruppen WHERE shopid=$shopid AND aktiv=1 AND apply_to_new_customers=1 AND (projekt=0 OR projekt='$projekt')"); + if (!empty($kundenGruppen)) { + foreach ($kundenGruppen as $gruppe) { + $this->app->erp->AddRolleZuAdresse($adresse, $gruppe['type'], 'von', 'Gruppe', $gruppe['gruppeid']); + } + } + + if (isset($warenkorb['kundengruppe'])) { + $this->shopimportAdresseGruppenMapping($warenkorb['kundengruppe'], $adresse, $shopid, $projekt); + } + if ($shopexportArr['vertrieb']) { + $this->app->DB->Update( + sprintf( + 'UPDATE adresse SET vertrieb = %d WHERE id = %d AND geloescht <> 1 AND vertrieb = 0', + $shopexportArr['vertrieb'], $adresse + ) + ); + } + $this->app->DB->Update( + sprintf( + 'UPDATE adresse SET fromshop = %d WHERE fromshop = 0 AND id = %d', + $shopexportArr['id'], $adresse + ) + ); + } else { + // Update + protokoll + if (!$this->app->DB->Select("SELECT adressennichtueberschreiben FROM shopexport WHERE id = '$shopid' LIMIT 1")) { + $this->app->erp->KundeUpdate($adresse, $typ, $name, $abteilung, + $unterabteilung, $ansprechpartner, $adresszusatz, $strasse, $land, $plz, $ort, $email, $telefon, $telefax, $ustid, $partner, $projekt); + if (!empty($warenkorb['bundesland'])) { + $this->app->DB->Update("UPDATE adresse SET bundesland = '" . $this->app->DB->real_escape_string($warenkorb['bundesland']) . "' WHERE id = '$adresse' LIMIT 1"); + } + } + } + // abweichende lieferadresse gleich angelegen? + if (strlen($warenkorb['lieferadresse_ansprechpartner']) > 3) { + $this->app->DB->Insert("INSERT INTO lieferadressen (typ,name,abteilung,unterabteilung,land,strasse,ort,plz,adresszusatz,adresse) VALUES ('','{$warenkorb['lieferadresse_ansprechpartner']}', '{$warenkorb['lieferadresse_abteilung']}','{$warenkorb['lieferadresse_unterabteilung']}','{$warenkorb['lieferadresse_land']}', '{$warenkorb['lieferadresse_strasse']}','{$warenkorb['lieferadresse_ort']}','{$warenkorb['lieferadresse_plz']}','{$warenkorb['lieferadresse_adresszusatz']}','$adresse')"); - } + } - if(strlen($warenkorb['lieferadresse_name'])>3 && $warenkorb['lieferadresse_ansprechpartner']=='') - { - $this->app->DB->Insert("INSERT INTO lieferadressen (typ,name,abteilung,unterabteilung,land,strasse,ort,plz,adresszusatz,adresse) VALUES + if (strlen($warenkorb['lieferadresse_name']) > 3 && $warenkorb['lieferadresse_ansprechpartner'] == '') { + $this->app->DB->Insert("INSERT INTO lieferadressen (typ,name,abteilung,unterabteilung,land,strasse,ort,plz,adresszusatz,adresse) VALUES ('','{$warenkorb['lieferadresse_name']}', '{$warenkorb['lieferadresse_abteilung']}','{$warenkorb['lieferadresse_unterabteilung']}','{$warenkorb['lieferadresse_land']}', '{$warenkorb['lieferadresse_strasse']}','{$warenkorb['lieferadresse_ort']}','{$warenkorb['lieferadresse_plz']}','{$warenkorb['lieferadresse_adresszusatz']}','$adresse')"); + } } - } - //print_r($warenkorb); - //echo "

    Ende"; - //exit; - //imort auf kunde - //$bekanntezahlungsweisen = array('rechnung','vorkasse','nachnahme','kreditkarte','einzugsermaechtigung','bar','paypal','amazon','amazon_bestellung','sofortueberweisung','amazoncba','secupay','lastschrift'); + //print_r($warenkorb); + //echo "

    Ende"; + //exit; + //imort auf kunde + //$bekanntezahlungsweisen = array('rechnung','vorkasse','nachnahme','kreditkarte','einzugsermaechtigung','bar','paypal','amazon','amazon_bestellung','sofortueberweisung','amazoncba','secupay','lastschrift'); - $bekanntezahlungsweisen = $this->app->erp->GetZahlungsweise(); + $bekanntezahlungsweisen = $this->app->erp->GetZahlungsweise(); - $tmpauftragid = $this->app->erp->ImportAuftrag($adresse,$warenkorb,$projekt,$shopid); - $doctype = 'auftrag'; - if($this->app->DB->Select("SELECT angeboteanlegen FROM shopexport WHERE id = '$shopid' LIMIT 1")) - { - $doctype = 'angebot'; - } + $import_result = $this->app->erp->ImportAuftrag($adresse, $warenkorb, $projekt, $shopid); - if(isset($warenkorb['doctype']) && $warenkorb['doctype']==='angebot'){ - $doctype = 'angebot'; - } + if ($import_result['status']) { + $tmpauftragid = $import_result['auftragid']; + $success_import = true; - $warenkorb['zahlungsweise'] = $this->app->DB->Select("SELECT zahlungsweise FROM $doctype WHERE id = '$tmpauftragid' LIMIT 1"); - if($warenkorb['zahlungsweise'] != ''){ - if(!isset($bekanntezahlungsweisen[$warenkorb['zahlungsweise']])){ - if(!$unbekanntezahlungsweisen || !isset($unbekanntezahlungsweisen[strtolower($warenkorb['zahlungsweise'])])){ - $unbekanntezahlungsweisen[strtolower($warenkorb['zahlungsweise'])] = false; - } - $tmp = array(); - $tmp['bestellnummer'] = $warenkorb['onlinebestellnummer']; - $unbekanntezahlungsweisen[strtolower($warenkorb['zahlungsweise'])][] = $tmp; + $doctype = 'auftrag'; + if ($this->app->DB->Select("SELECT angeboteanlegen FROM shopexport WHERE id = '$shopid' LIMIT 1")) { + $doctype = 'angebot'; + } + + if (isset($warenkorb['doctype']) && $warenkorb['doctype'] === 'angebot') { + $doctype = 'angebot'; + } + + $warenkorb['zahlungsweise'] = $this->app->DB->Select("SELECT zahlungsweise FROM $doctype WHERE id = '$tmpauftragid' LIMIT 1"); + if ($warenkorb['zahlungsweise'] != '') { + if (!isset($bekanntezahlungsweisen[$warenkorb['zahlungsweise']])) { + if (!$unbekanntezahlungsweisen || !isset($unbekanntezahlungsweisen[strtolower($warenkorb['zahlungsweise'])])) { + $unbekanntezahlungsweisen[strtolower($warenkorb['zahlungsweise'])] = false; + } + $tmp = array(); + $tmp['bestellnummer'] = $warenkorb['onlinebestellnummer']; + $unbekanntezahlungsweisen[strtolower($warenkorb['zahlungsweise'])][] = $tmp; + } + } + + if ($shopimportid && $tmpauftragid) { + $this->app->DB->Update("UPDATE shopimport_auftraege SET imported='1' WHERE id='$shopimportid' LIMIT 1"); + } + if ($shopimportid) { + $shopextid = $this->app->DB->real_escape_string($this->app->DB->Select("SELECT extid FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1")); + } + if ($shopextid) { + $this->app->DB->Select("UPDATE $doctype SET shopextid='$shopextid' WHERE id='$tmpauftragid' LIMIT 1"); + } + $this->app->erp->RunHook('Shopimportwarenkorb', 4, $doctype, $tmpauftragid, $shopid, $warenkorb); + $this->app->erp->RunHook('Shopimport', 3, $doctype, $tmpauftragid, $shopid); + $adresse = ''; + } else { + // Error... } - } - - if($shopimportid) - { - $this->app->DB->Update("UPDATE shopimport_auftraege SET imported='1' WHERE id='$shopimportid' LIMIT 1"); - } - if($shopimportid) - { - $shopextid = $this->app->DB->real_escape_string($this->app->DB->Select("SELECT extid FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1")); - } - if($shopextid) - { - $this->app->DB->Select("UPDATE $doctype SET shopextid='$shopextid' WHERE id='$tmpauftragid' LIMIT 1"); - } - $this->app->erp->RunHook('Shopimportwarenkorb', 4, $doctype, $tmpauftragid, $shopid, $warenkorb); - $this->app->erp->RunHook('Shopimport', 3, $doctype, $tmpauftragid, $shopid); - - $adresse =''; - $sucess_import++; - - return $sucess_import; - } - - /** - * @param String $gruppenBezeichnung im Shop - * @param int $adresseId - * @param int $shopId - * @param int $projektId - * - * @return string - */ - private function shopimportAdresseGruppenMapping($gruppenBezeichnung, $adresseId, $shopId, $projektId){ - $kundenGruppen = $this->getShopimportKundenGruppenZuordnungen($gruppenBezeichnung, $shopId, $projektId); - if(empty($kundenGruppen)) { - return ''; - } - foreach ($kundenGruppen as $gruppe => $rolle){ - $this->app->erp->AddRolleZuAdresse($adresseId, $rolle, 'von', 'Gruppe', $gruppe); + return $success_import; } - return ''; - } + /** + * @param String $gruppenBezeichnung im Shop + * @param int $adresseId + * @param int $shopId + * @param int $projektId + * + * @return string + */ + private function shopimportAdresseGruppenMapping($gruppenBezeichnung, $adresseId, $shopId, $projektId) { + $kundenGruppen = $this->getShopimportKundenGruppenZuordnungen($gruppenBezeichnung, $shopId, $projektId); + if (empty($kundenGruppen)) { + return ''; + } + foreach ($kundenGruppen as $gruppe => $rolle) { + $this->app->erp->AddRolleZuAdresse($adresseId, $rolle, 'von', 'Gruppe', $gruppe); + } - /** - * @param String $gruppenBezeichnung im Shop - * @param int $shopId - * @param int $projektId - * - * @return array - */ - private function getShopimportKundenGruppenZuordnungen($gruppenBezeichnung, $shopId, $projektId){ - $gefundeneGruppen = $this->app->DB->SelectArr("SELECT gruppeid, type FROM shopexport_kundengruppen WHERE shopid='$shopId' AND extgruppename='$gruppenBezeichnung' AND projekt='$projektId'"); - - if(empty($gefundeneGruppen)){ - //Fallback, falls kein projektspezifisches Mapping gefunden - $gefundeneGruppen = $this->app->DB->SelectArr("SELECT gruppeid, type FROM shopexport_kundengruppen WHERE shopid='$shopId' AND extgruppename='$gruppenBezeichnung' AND projekt='0'"); + return ''; } - if(empty($gefundeneGruppen)) { - return []; + /** + * @param String $gruppenBezeichnung im Shop + * @param int $shopId + * @param int $projektId + * + * @return array + */ + private function getShopimportKundenGruppenZuordnungen($gruppenBezeichnung, $shopId, $projektId) { + $gefundeneGruppen = $this->app->DB->SelectArr("SELECT gruppeid, type FROM shopexport_kundengruppen WHERE shopid='$shopId' AND extgruppename='$gruppenBezeichnung' AND projekt='$projektId'"); + + if (empty($gefundeneGruppen)) { + //Fallback, falls kein projektspezifisches Mapping gefunden + $gefundeneGruppen = $this->app->DB->SelectArr("SELECT gruppeid, type FROM shopexport_kundengruppen WHERE shopid='$shopId' AND extgruppename='$gruppenBezeichnung' AND projekt='0'"); + } + + if (empty($gefundeneGruppen)) { + return []; + } + + $kundenGruppen = []; + foreach ($gefundeneGruppen as $gruppe) { + $kundenGruppen[$gruppe['gruppeid']] = $gruppe['type']; + } + + return $kundenGruppen; } - $kundenGruppen = []; - foreach ($gefundeneGruppen as $gruppe){ - $kundenGruppen[$gruppe['gruppeid']] = $gruppe['type']; + /** + * @param $shopImportedOrderId + * + * @return bool + */ + public function setShopImportedOrderTrash($shopImportedOrderId) { + $this->app->DB->Update( + sprintf( + 'UPDATE shopimport_auftraege SET trash=1 WHERE id= %d LIMIT 1', + (int) $shopImportedOrderId + ) + ); + return $this->app->DB->affected_rows() > 0; } - return $kundenGruppen; - } + public function importShopOrder($shopImportedOrderId, $utf8coding, $customerNumber, $custumerNumberImported, &$unknownPaymentTypes) { + $shopImportedOrder = $this->app->DB->SelectRow( + sprintf( + 'SELECT * FROM shopimport_auftraege WHERE imported=0 AND trash=0 AND id=%d LIMIT 1', + $shopImportedOrderId + ) + ); + if (empty($shopImportedOrder)) { + return ['success' => 0]; + } - /** - * @param $shopImportedOrderId - * - * @return bool - */ - public function setShopImportedOrderTrash($shopImportedOrderId) { - $this->app->DB->Update( - sprintf( - 'UPDATE shopimport_auftraege SET trash=1 WHERE id= %d LIMIT 1', - (int)$shopImportedOrderId - ) - ); - return $this->app->DB->affected_rows() > 0; - } + if (isset($shopImportedOrder['jsonencoded']) && $shopImportedOrder['jsonencoded']) { + $shopOrder = json_decode(base64_decode($shopImportedOrder['warenkorb']), true); + } else { + $shopOrder = unserialize(base64_decode($shopImportedOrder['warenkorb'])); + } - public function importShopOrder($shopImportedOrderId, $utf8coding, $customerNumber, $custumerNumberImported, &$unknownPaymentTypes) { - $shopImportedOrder = $this->app->DB->SelectRow( - sprintf( - 'SELECT * FROM shopimport_auftraege WHERE imported=0 AND trash=0 AND id=%d LIMIT 1', - $shopImportedOrderId - ) - ); - if(empty($shopImportedOrder)) { - return ['success' => 0]; + //alle leerzeichen am amfang und ende entfernen + umbrueche komplett entfernen + if ($utf8coding == '1') { + $shopOrderCleaned = $this->app->erp->CleanDataBeforImportUTF8($shopOrder, false); + } else { + $shopOrderCleaned = $this->app->erp->CleanDataBeforImport($shopOrder, false); + } + if ($shopOrderCleaned['name'] === '') { + $shopOrderCleaned['name'] = $shopOrderCleaned['ansprechpartner']; + $shopOrderCleaned['ansprechpartner'] = ''; + } + if ($shopOrderCleaned['lieferadresse_name'] === '') { + $shopOrderCleaned['lieferadresse_name'] = $shopOrderCleaned['lieferadresse_ansprechpartner']; + $shopOrderCleaned['lieferadresse_ansprechpartner'] = ''; + } + + if ($shopOrderCleaned['name'] === '' && !empty($shopOrderCleaned['lieferadresse_name'])) { + $shopOrderCleaned['name'] = $shopOrderCleaned['lieferadresse_name']; + } + + foreach ($shopOrderCleaned as $k => $v) { + if (!is_array($v)) { + $shopOrderCleaned[$k] = $this->app->erp->fixeUmlaute($v); + } + } + $umlautefehler = false; + if ((String) $shopOrder['name'] !== '' && (String) $shopOrderCleaned['name'] === '') { + $umlautefehler = true; + $this->app->erp->LogFile('Kodierungsfehler in shopimport_auftraege ' . $shopImportedOrderId); + } + $succes = $this->KundeAnlegenUpdate($shopImportedOrderId, '', $shopOrderCleaned, $customerNumber, $custumerNumberImported, $unknownPaymentTypes); + + return ['codingerror' => $umlautefehler, 'success' => $succes]; } - if(isset($shopImportedOrder['jsonencoded']) && $shopImportedOrder['jsonencoded']) - { - $shopOrder = json_decode(base64_decode($shopImportedOrder['warenkorb']), true); - }else{ - $shopOrder = unserialize(base64_decode($shopImportedOrder['warenkorb'])); + public function ShopimportView() { + $this->ShopimportImport(showonly: true); } - //alle leerzeichen am amfang und ende entfernen + umbrueche komplett entfernen - if($utf8coding=='1') - { - $shopOrderCleaned = $this->app->erp->CleanDataBeforImportUTF8($shopOrder, false); - } else { - $shopOrderCleaned = $this->app->erp->CleanDataBeforImport($shopOrder, false); - } - if($shopOrderCleaned['name']===''){ - $shopOrderCleaned['name']=$shopOrderCleaned['ansprechpartner']; - $shopOrderCleaned['ansprechpartner'] = ''; - } - if($shopOrderCleaned['lieferadresse_name']==='') - { - $shopOrderCleaned['lieferadresse_name']=$shopOrderCleaned['lieferadresse_ansprechpartner']; - $shopOrderCleaned['lieferadresse_ansprechpartner'] = ''; - } - - if($shopOrderCleaned['name']==='' && !empty($shopOrderCleaned['lieferadresse_name'])) - { - $shopOrderCleaned['name'] = $shopOrderCleaned['lieferadresse_name']; - } - - foreach($shopOrderCleaned as $k => $v) - { - if(!is_array($v)){ - $shopOrderCleaned[$k] = $this->app->erp->fixeUmlaute($v); - } - } - $umlautefehler = false; - if((String)$shopOrder['name'] !== '' && (String)$shopOrderCleaned['name'] === '') - { - $umlautefehler = true; - $this->app->erp->LogFile('Kodierungsfehler in shopimport_auftraege '.$shopImportedOrderId); - } - $succes = $this->KundeAnlegenUpdate($shopImportedOrderId,'', $shopOrderCleaned, $customerNumber, $custumerNumberImported,$unknownPaymentTypes); - - return ['codingerror'=>$umlautefehler, 'success' => $succes]; - } - - public function ShopimportImport($id='', $count = 0, $returncount = false, $showonly = false) - { - $deletedRows = 0; - if(!is_numeric($id) && $this->app->Secure->GetPOST('deletedouble')) { - $id = (int)$this->app->Secure->GetGET('id'); - $this->app->DB->Update( - sprintf( - 'UPDATE shopimport_auftraege AS sa + public function ShopimportImport($id = '', $count = 0, $returncount = false, $showonly = false) { + $deletedRows = 0; + if (!is_numeric($id) && $this->app->Secure->GetPOST('deletedouble')) { + $showonly = true; + $id = (int) $this->app->Secure->GetGET('id'); + $this->app->DB->Update( + sprintf( + 'UPDATE shopimport_auftraege AS sa INNER JOIN auftrag a ON sa.bestellnummer = a.internet AND sa.shopid = a.shop SET sa.trash = 1 WHERE IFNULL(a.internet,\'\') <> \'\' AND sa.trash = 0 AND sa.imported = 0 AND (sa.shopid = %d OR %d = 0)', - $id, $id - ) - ); - $deletedRows = (int)$this->app->DB->affected_rows(); - $this->app->Tpl->Add('IMPORT','
    Es wurden '.$deletedRows.' bereits importierte Datensätze entfernt.
    '); - } - $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); - if($runningcronjob && !$showonly) - { - $this->app->Location->execute('index.php?module=shopimport&action=list'); - } - if(!is_numeric($id)){ - $id = $this->app->Secure->GetGET('id'); - } - - $shopexportarr = $this->app->DB->SelectRow("SELECT * FROM shopexport WHERE id='$id'"); - $projekt = $shopexportarr['projekt'];//$this->app->DB->Select("SELECT projekt FROM shopexport WHERE id='$id'"); - $demomodus = $shopexportarr['demomodus'];//$this->app->DB->Select("SELECT demomodus FROM shopexport WHERE id='$id'"); - $einzelsync = $shopexportarr['einzelsync'];//$this->app->DB->Select("SELECT einzelsync FROM shopexport WHERE id='$id'"); - $utf8codierung = $shopexportarr['utf8codierung'];//$this->app->DB->Select("SELECT utf8codierung FROM shopexport WHERE id='$id'"); - - if(!$returncount) - { - $this->app->erp->Headlines('Shopimport'); - $this->app->erp->MenuEintrag('index.php?module=shopimport&action=list','Zurück zur Übersicht'); - } - //name, strasse, ort, plz und kundenummer, emailadresse oder bestellung kam von login account ==> Kunde aus DB verwenden - //ACHTUNG Lieferadresse immer aus Auftrag!!! aber Lieferadresse extra bei Kunden anlegen - if($this->app->Secure->GetPOST('submit')!='') - { - $auftraege = $this->app->Secure->GetPOST('auftrag'); - $kundennummer = $this->app->Secure->GetPOST('kundennummer'); - $import= $this->app->Secure->GetPOST('import'); - $import_kundennummer= $this->app->Secure->GetPOST('import_kundennummer'); - - $sucess_import = 0; - $insgs_import = 0; - $unbekanntezahlungsweisen = null; - $cauftraege = $auftraege?count($auftraege):0; - for($i=0;$i<$cauftraege;$i++) - { - $adresse = ''; - $shopimportid = $auftraege[$i]; - $shopid = $this->app->DB->Select("SELECT shopid FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1"); - if($shopid) - { - $demomodus = $this->app->DB->Select("SELECT demomodus FROM shopexport WHERE id='$shopid'"); - $einzelsync = $this->app->DB->Select("SELECT einzelsync FROM shopexport WHERE id='$shopid'"); - $utf8codierung = $this->app->DB->Select("SELECT utf8codierung FROM shopexport WHERE id='$shopid'"); - } - $projekt = $this->app->DB->Select("SELECT projekt FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1"); - if($import[$shopimportid]==='warten') - { - - } - else if($import[$shopimportid]==='muell') - { - $this->setShopImportedOrderTrash($shopimportid); - } else if($import[$shopimportid]==='import') { - - $res = $this->importShopOrder($shopimportid, $utf8codierung, $kundennummer[$shopimportid], $import_kundennummer[$shopimportid], $unbekanntezahlungsweisen); - if($res['codingerror']) { - $umlautefehler = true; - } - if($res['success']) { - $sucess_import += $res['success']; - } - $insgs_import++; - } - } // ende for - - - if($unbekanntezahlungsweisen) - { - $meldung = ''; - foreach($unbekanntezahlungsweisen as $k => $v) - { - $meldung .= 'Unbekannte Zahlungsart: '.$k.' in Bestellung(en): '; - $first = true; - foreach($v as $k2 => $v2) - { - if(!$first) - { - $meldung .= ', '; - } - $first = false; - $meldung .= $v2['bestellnummer']; - - } - $meldung .= "
    \r\n"; - - } - - if(isset($this->app->User) && method_exists($this->app->User,'GetID') && $this->app->User->GetID()) - { - $this->app->erp->EventMitSystemLog($this->app->User->GetID(), $meldung, -1,'', 'warning', 1); - } - } - if(!empty($umlautefehler)) - { - $msg = $this->app->erp->base64_url_encode("
    $sucess_import".($sucess_import != $insgs_import?" von $insgs_import ":'')." Aufträge importiert. Aufträge mit Kodierungsprobleme. Bitte prüfen Sie sie UTF8-Einstellung in der Shopschnittstelle!
    "); - }else{ - $msg = $this->app->erp->base64_url_encode("
    $sucess_import".($sucess_import != $insgs_import?" von $insgs_import ":'')." Aufträge importiert!
    "); - } - $this->app->Location->execute('index.php?module=shopimport&action=list&msg='.$msg); - } - - - if(!$showonly && $id) - { - try { - $pageContents = $this->app->remote->RemoteConnection($id); - }catch(Exception $e){ - $pageContents = $e->getMessage(); - } - if($pageContents==='success') - { - $shopexportarr = $this->app->DB->SelectRow("SELECT * FROM shopexport WHERE id = '$id' LIMIT 1"); - $holealle = $shopexportarr['holealle'];//$this->app->DB->Select("SELECT holealle FROM shopexport WHERE id = '$id' LIMIT 1"); - $statusaendern = $shopexportarr['nummersyncstatusaendern'];//$this->app->DB->Select("SELECT nummersyncstatusaendern FROM shopexport WHERE id = '$id' LIMIT 1"); - $auftragabgleich = $shopexportarr['auftragabgleich'];//$this->app->DB->Select("SELECT auftragabgleich FROM shopexport WHERE id = '$id' LIMIT 1"); - $zeitraum = array('datumvon'=>$shopexportarr['datumvon'], 'datumbis'=>$shopexportarr['datumbis'],'tmpdatumvon'=>$shopexportarr['tmpdatumvon'], 'tmpdatumbis'=>$shopexportarr['tmpdatumbis'], 'anzgleichzeitig'=>$shopexportarr['anzgleichzeitig']); - //$this->app->DB->SelectArr("SELECT datumvon, datumbis,tmpdatumvon, tmpdatumbis, anzgleichzeitig FROM shopexport WHERE id = '$id' LIMIT 1"); - /*if(!empty($zeitraum)) - { - $zeitraum = reset($zeitraum); - }*/ - $anzgleichzeitig = 1; - if(isset($zeitraum['anzgleichzeitig'])){ - $anzgleichzeitig = (int)$zeitraum['anzgleichzeitig']; - } - - if($anzgleichzeitig > 1) - { - $result = $this->app->remote->RemoteGetAuftrag($id); - if(!empty($result) && is_array($result) && isset($result[0])) - { - $maxtime = false; - $mintime = false; - $gesamtanzahl = (!empty($result)?count($result):0); - for($i = 0; $i < $gesamtanzahl; $i++) - { - $projekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '$id' LIMIT 1"); - $auftrag = $result[$i]['id']; - if(isset($result[$i]['warenkorbjson'])) - { - $isjson = true; - $tmpwarenkorb = json_decode(base64_decode($result[$i]['warenkorbjson']), true); - }else{ - $isjson = false; - $tmpwarenkorb = unserialize(base64_decode($result[$i]['warenkorb'])); - } - if(!empty($tmpwarenkorb['projekt']) && $this->app->DB->Select("SELECT id FROM projekt WHERE id = '".(int)$tmpwarenkorb['projekt']."' LIMIT 1")) - { - $projekt = (int)$tmpwarenkorb['projekt']; - } - if(!empty($tmpwarenkorb['zeitstempel'])) - { - $time = strtotime($tmpwarenkorb['zeitstempel']); - if($time < 0) - { - $time = 0; - } - if($maxtime === false) - { - $maxtime = $time; - } - if($mintime === false) - { - $mintime = $time; - } - if($time > $maxtime) - { - $maxtime = $time; - } - if($time < $mintime) - { - $mintime = $time; - } - } - $onlinebestellnummer = $tmpwarenkorb['onlinebestellnummer']; - if(!empty($tmpwarenkorb['useorderid']) || - (!is_numeric($onlinebestellnummer) && trim((String)$onlinebestellnummer) !== '')) - { - $onlinebestellnummer = $tmpwarenkorb['auftrag']; - } - - if($holealle && $onlinebestellnummer) - { - $neue_nummer = (int)$onlinebestellnummer+1; - $this->app->DB->Update("UPDATE shopexport SET ab_nummer = '$neue_nummer' WHERE id = '$id'"); - } - $sessionid = isset($result[$i]['sessionid'])?$result[$i]['sessionid']:''; - if($isjson) - { - $warenkorb = $result[$i]['warenkorbjson']; - }else{ - $warenkorb = $result[$i]['warenkorb']; - } - $logdatei = isset($result[$i]['logdatei'])?$result[$i]['logdatei']:null; - if(empty($logdatei)) - { - $logdatei = date('Y-m-d H:i:s'); - } - if(isset($tmpwarenkorb['subshop']) && $tmpwarenkorb['subshop']) - { - $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '$id' AND aktiv = 1 AND subshopkennung = '".$this->app->DB->real_escape_string($tmpwarenkorb['subshop'])."' LIMIT 1"); - if($subshopprojekt) - { - $projekt = $subshopprojekt; - } - } - $letzteonlinebestellnummer = $tmpwarenkorb['onlinebestellnummer']; - unset($tmpwarenkorb); - - //globalerauftragsnummernkreis - $standardcheck = true; - $modulename = $this->app->DB->Select( - sprintf( - "SELECT modulename FROM shopexport WHERE id = %d AND modulename <> '' AND (shoptyp = 'intern')", - $id - ) - ); - $shopIds = [$id]; - $otherModules= empty($modulename)?null: - $this->app->DB->SelectFirstCols( - sprintf( - "SELECT id - FROM shopexport - WHERE modulename = '%s' AND id <> %d", - $this->app->DB->real_escape_string($modulename), $id - ) - ); - if(!empty($otherModules) && $this->app->erp->ModulVorhanden($modulename)) { - $obj = $this->app->erp->LoadModul($modulename); - if(!empty($obj) && method_exists($obj, 'EinstellungenStruktur')){ - $konfiguration = $obj->EinstellungenStruktur(); - if($konfiguration && isset($konfiguration['globalerauftragsnummernkreis']) && $konfiguration['globalerauftragsnummernkreis']) { - $shopIds = array_merge([$id], $otherModules); - $standardcheck = false; - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') and warenkorb = '".$this->app->DB->real_escape_string($warenkorb)."' AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1");*/ - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1");*/ - } - } - } - $checkdoppeltimported = $this->app->DB->Select( - sprintf( - "SELECT id - FROM shopimport_auftraege - WHERE extid = '%s' and shopid IN (%s) AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1", - $this->app->DB->real_escape_string($auftrag), implode(',', $shopIds) - ) - ); - /*if($standardcheck) - {*/ - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and shopid = '$id' and warenkorb = '".$this->app->DB->real_escape_string($warenkorb)."' AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1");*/ - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and shopid = '$id' AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1"); - }*/ - $insid = null; - if(empty($checkdoppeltimported)) - { - $this->app->DB->Insert("INSERT INTO shopimport_auftraege (id,extid,sessionid,warenkorb,imported,projekt,bearbeiter,logdatei) - VALUES('','".$this->app->DB->real_escape_string($auftrag)."','".$this->app->DB->real_escape_string($sessionid)."','".$this->app->DB->real_escape_string($warenkorb)."','0','$projekt','".$this->app->DB->real_escape_string($this->app->User->GetName())."','".$this->app->DB->real_escape_string($logdatei)."')"); - $insid = $this->app->DB->GetInsertID(); - if($insid) - { - if($isjson) - { - $this->app->DB->Update("UPDATE shopimport_auftraege set jsonencoded = 1 where id = '$insid'"); - } - $this->app->DB->Update("UPDATE shopimport_auftraege set shopid = '$id' where id = '$insid'"); - $this->app->DB->Update("UPDATE shopimport_auftraege set bestellnummer = '".$this->app->DB->real_escape_string($letzteonlinebestellnummer)."' where id = '$insid'"); - } - } - if($demomodus!='1') - { - $this->app->remote->RemoteDeleteAuftrag($id,$auftrag,$letzteonlinebestellnummer); - } - elseif($demomodus == '1') - { - break; - } - unset($letzteonlinebestellnummer); - - } - if(!$demomodus) - { - if(empty($maxtime)) - { - $maxtime = strtotime(date('Y-m-d H:i:s')); - } - $datumvon = strtotime($zeitraum['datumvon']); - $datumbis = strtotime($zeitraum['datumbis']); - $tmpdatumvon = strtotime($zeitraum['tmpdatumvon']); - $tmpdatumbis = strtotime($zeitraum['tmpdatumbis']); - if($datumvon < 0){ - $datumvon = 0; - } - if($datumbis < 0){ - $datumbis = 0; - } - if($tmpdatumvon < 0){ - $tmpdatumvon = 0; - } - if($tmpdatumbis < 0) - { - $tmpdatumbis = 0; - } - $this->app->DB->Update("UPDATE shopexport SET datumvon = '".date('Y-m-d H:i:s',$maxtime)."', tmpdatumbis = '0000-00-00' WHERE id = '$id' LIMIT 1"); - } - }else{ - if(!$demomodus) - { - if(is_array($result) && !empty($result['zeitstempel'])) - { - $this->app->DB->Update("UPDATE shopexport SET datumvon = '".date('Y-m-d H:i:s',strtotime($result['zeitstempel']))."', tmpdatumbis = '0000-00-00' WHERE id = '$id' AND datumvon < '".date('Y-m-d H:i:s',strtotime($result['zeitstempel']))."' LIMIT 1"); - } - if(empty($maxtime)) - { - $maxtime = strtotime(date('Y-m-d H:i:s')); - } - $datumvon = strtotime($zeitraum['datumvon']); - $datumbis = strtotime($zeitraum['datumbis']); - $tmpdatumvon = strtotime($zeitraum['tmpdatumvon']); - $tmpdatumbis = strtotime($zeitraum['tmpdatumbis']); - if($datumvon < 0){ - $datumvon = 0; - } - if($datumbis < 0){ - $datumbis = 0; - } - if($tmpdatumvon < 0){ - $tmpdatumvon = 0; - } - if($tmpdatumbis < 0){ - $tmpdatumbis = 0; - } - if($tmpdatumbis) - { - $this->app->DB->Update("UPDATE shopexport SET tmpdatumbis = '0000-00-00' WHERE id = '$id' LIMIT 1"); - } - } - } - }else{ - $gesamtanzahl = $this->app->remote->RemoteGetAuftraegeAnzahl($id); - $maxmanuell = (int)$this->app->DB->Select("SELECT maxmanuell FROM shopexport WHERE id = '$id' LIMIT 1"); - if($maxmanuell <= 0){ - $maxmanuell = 100; - } - if($gesamtanzahl > $maxmanuell){ - $gesamtanzahl = $maxmanuell; - } - if($einzelsync=='1' && $gesamtanzahl > 1 && $maxmanuell <= 1){ - $gesamtanzahl = 1; - } - if($gesamtanzahl > 0) - { - for($i=0;$i<$gesamtanzahl;$i++) - { - //import au - $result = $this->app->remote->RemoteGetAuftrag($id); - - if(is_array($result)) - { - $auftrag = $result[0]['id']; - if(isset($result[0]['warenkorbjson'])) - { - $isjson = true; - $tmpwarenkorb = json_decode(base64_decode($result[0]['warenkorbjson']), true); - }else{ - $isjson = false; - $tmpwarenkorb = unserialize(base64_decode($result[0]['warenkorb'])); - } - $onlinebestellnummer = $tmpwarenkorb['onlinebestellnummer']; - if(!empty($tmpwarenkorb['useorderid']) || (!is_numeric($onlinebestellnummer) && trim((String)$onlinebestellnummer) !== '')) - { - $onlinebestellnummer = $tmpwarenkorb['auftrag']; - } - if($holealle && $onlinebestellnummer) - { - $neue_nummer = (int)$onlinebestellnummer+1; - $this->app->DB->Update("UPDATE shopexport SET ab_nummer = '$neue_nummer' WHERE id = '$id'"); - } - $sessionid = $result[0]['sessionid']; - if($isjson) - { - $warenkorb = $result[0]['warenkorbjson']; - }else{ - $warenkorb = $result[0]['warenkorb']; - } - $logdatei = $result[0]['logdatei']; - if(empty($logdatei)) - { - $logdatei = date('Y-m-d H:i:s'); - } - $projekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '$id' LIMIT 1"); - if(!empty($tmpwarenkorb['projekt']) && $this->app->DB->Select("SELECT id FROM projekt WHERE id = '".(int)$tmpwarenkorb['projekt']."' LIMIT 1")) - { - $projekt = (int)$tmpwarenkorb['projekt']; - } - if(isset($tmpwarenkorb['subshop']) && $tmpwarenkorb['subshop']) - { - $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '$id' AND aktiv = 1 AND subshopkennung = '".$this->app->DB->real_escape_string($tmpwarenkorb['subshop'])."' LIMIT 1"); - if($subshopprojekt) - { - $projekt = $subshopprojekt; - } - } - unset($tmpwarenkorb); - - $standardcheck = true; - $modulename = $this->app->DB->Select( - sprintf( - "SELECT modulename FROM shopexport WHERE id = %d AND modulename <> '' AND (shoptyp = 'intern')", - $id - ) - ); - $shopIds = [$id]; - $otherModules= empty($modulename)?null: - $this->app->DB->SelectFirstCols( - sprintf( - "SELECT id - FROM shopexport - WHERE modulename = '%s' AND id <> %d", - $this->app->DB->real_escape_string($modulename), $id + $id, $id ) - ); - if(!empty($otherModules) && $this->app->erp->ModulVorhanden($modulename)) { - $obj = $this->app->erp->LoadModul($modulename); - if(!empty($obj) && method_exists($obj, 'EinstellungenStruktur')){ - $konfiguration = $obj->EinstellungenStruktur(); - if($konfiguration && isset($konfiguration['globalerauftragsnummernkreis']) && $konfiguration['globalerauftragsnummernkreis']) { - $shopIds = array_merge([$id], $otherModules); - $standardcheck = false; - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') and warenkorb = '".$this->app->DB->real_escape_string($warenkorb)."' AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1");*/ - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1");*/ - } - } + ); + $deletedRows = (int) $this->app->DB->affected_rows(); + $this->app->Tpl->Add('IMPORT', '
    Es wurden ' . $deletedRows . ' bereits importierte Datensätze entfernt.
    '); + } + $runningcronjob = $this->app->DB->Select("SELECT id FROM prozessstarter WHERE parameter = 'shopimport' AND aktiv=1 AND mutex = 1 AND UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(letzteausfuerhung) < 300 LIMIT 1"); + if ($runningcronjob && !$showonly) { + $this->app->Location->execute('index.php?module=shopimport&action=list'); + } + if (!is_numeric($id)) { + $id = $this->app->Secure->GetGET('id'); + } + + $shopexportarr = $this->app->DB->SelectRow("SELECT * FROM shopexport WHERE id='$id'"); + $projekt = $shopexportarr['projekt']; //$this->app->DB->Select("SELECT projekt FROM shopexport WHERE id='$id'"); + $demomodus = $shopexportarr['demomodus']; //$this->app->DB->Select("SELECT demomodus FROM shopexport WHERE id='$id'"); + $einzelsync = $shopexportarr['einzelsync']; //$this->app->DB->Select("SELECT einzelsync FROM shopexport WHERE id='$id'"); + $utf8codierung = $shopexportarr['utf8codierung']; //$this->app->DB->Select("SELECT utf8codierung FROM shopexport WHERE id='$id'"); + + if (!$returncount) { + $this->app->erp->Headlines('Shopimport'); + $this->app->erp->MenuEintrag('index.php?module=shopimport&action=list', 'Zurück zur Übersicht'); + } + //name, strasse, ort, plz und kundenummer, emailadresse oder bestellung kam von login account ==> Kunde aus DB verwenden + //ACHTUNG Lieferadresse immer aus Auftrag!!! aber Lieferadresse extra bei Kunden anlegen + if ($this->app->Secure->GetPOST('submit') != '') { + $auftraege = $this->app->Secure->GetPOST('auftrag'); + $kundennummer = $this->app->Secure->GetPOST('kundennummer'); + $import = $this->app->Secure->GetPOST('import'); + $import_kundennummer = $this->app->Secure->GetPOST('import_kundennummer'); + + $success_import = 0; + $insgs_import = 0; + $unbekanntezahlungsweisen = null; + $cauftraege = $auftraege ? count($auftraege) : 0; + for ($i = 0; $i < $cauftraege; $i++) { + $adresse = ''; + $shopimportid = $auftraege[$i]; + $shopid = $this->app->DB->Select("SELECT shopid FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1"); + if ($shopid) { + $demomodus = $this->app->DB->Select("SELECT demomodus FROM shopexport WHERE id='$shopid'"); + $einzelsync = $this->app->DB->Select("SELECT einzelsync FROM shopexport WHERE id='$shopid'"); + $utf8codierung = $this->app->DB->Select("SELECT utf8codierung FROM shopexport WHERE id='$shopid'"); } - $checkdoppeltimported = $this->app->DB->Select( - sprintf( - "SELECT id + $projekt = $this->app->DB->Select("SELECT projekt FROM shopimport_auftraege WHERE id='$shopimportid' LIMIT 1"); + if ($import[$shopimportid] === 'warten') { + + } else if ($import[$shopimportid] === 'muell') { + $this->setShopImportedOrderTrash($shopimportid); + } else if ($import[$shopimportid] === 'import') { + + $res = $this->importShopOrder($shopimportid, $utf8codierung, $kundennummer[$shopimportid], $import_kundennummer[$shopimportid], $unbekanntezahlungsweisen); + if ($res['codingerror']) { + $umlautefehler = true; + } + if ($res['success']) { + $success_import += $res['success']; + } + $insgs_import++; + } + } // ende for + + + if ($unbekanntezahlungsweisen) { + $meldung = ''; + foreach ($unbekanntezahlungsweisen as $k => $v) { + $meldung .= 'Unbekannte Zahlungsart: ' . $k . ' in Bestellung(en): '; + $first = true; + foreach ($v as $k2 => $v2) { + if (!$first) { + $meldung .= ', '; + } + $first = false; + $meldung .= $v2['bestellnummer']; + } + $meldung .= "
    \r\n"; + } + + if (isset($this->app->User) && method_exists($this->app->User, 'GetID') && $this->app->User->GetID()) { + $this->app->erp->EventMitSystemLog($this->app->User->GetID(), $meldung, -1, '', 'warning', 1); + } + } + if (!empty($umlautefehler)) { + $msg = $this->app->erp->base64_url_encode("
    $success_import" . ($success_import != $insgs_import ? " von $insgs_import " : '') . " Aufträge importiert. Aufträge mit Kodierungsprobleme. Bitte prüfen Sie sie UTF8-Einstellung in der Shopschnittstelle!
    "); + } else { + $msg = $this->app->erp->base64_url_encode("
    $success_import" . ($success_import != $insgs_import ? " von $insgs_import " : '') . " Aufträge importiert!
    "); + } + $this->app->Location->execute('index.php?module=shopimport&action=list&msg=' . $msg); + } + + + if (!$showonly && $id) { + try { + $pageContents = $this->app->remote->RemoteConnection($id); + } catch (Exception $e) { + $pageContents = $e->getMessage(); + } + if ($pageContents === 'success') { + $shopexportarr = $this->app->DB->SelectRow("SELECT * FROM shopexport WHERE id = '$id' LIMIT 1"); + $holealle = $shopexportarr['holealle']; //$this->app->DB->Select("SELECT holealle FROM shopexport WHERE id = '$id' LIMIT 1"); + $statusaendern = $shopexportarr['nummersyncstatusaendern']; //$this->app->DB->Select("SELECT nummersyncstatusaendern FROM shopexport WHERE id = '$id' LIMIT 1"); + $auftragabgleich = $shopexportarr['auftragabgleich']; //$this->app->DB->Select("SELECT auftragabgleich FROM shopexport WHERE id = '$id' LIMIT 1"); + $zeitraum = array('datumvon' => $shopexportarr['datumvon'], 'datumbis' => $shopexportarr['datumbis'], 'tmpdatumvon' => $shopexportarr['tmpdatumvon'], 'tmpdatumbis' => $shopexportarr['tmpdatumbis'], 'anzgleichzeitig' => $shopexportarr['anzgleichzeitig']); + //$this->app->DB->SelectArr("SELECT datumvon, datumbis,tmpdatumvon, tmpdatumbis, anzgleichzeitig FROM shopexport WHERE id = '$id' LIMIT 1"); + /* if(!empty($zeitraum)) + { + $zeitraum = reset($zeitraum); + } */ + $anzgleichzeitig = 1; + if (isset($zeitraum['anzgleichzeitig'])) { + $anzgleichzeitig = (int) $zeitraum['anzgleichzeitig']; + } + + if ($anzgleichzeitig > 1) { + $result = $this->app->remote->RemoteGetAuftrag($id); + if (!empty($result) && is_array($result) && isset($result[0])) { + $maxtime = false; + $mintime = false; + $gesamtanzahl = (!empty($result) ? count($result) : 0); + for ($i = 0; $i < $gesamtanzahl; $i++) { + $projekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '$id' LIMIT 1"); + $auftrag = $result[$i]['id']; + if (isset($result[$i]['warenkorbjson'])) { + $isjson = true; + $tmpwarenkorb = json_decode(base64_decode($result[$i]['warenkorbjson']), true); + } else { + $isjson = false; + $tmpwarenkorb = unserialize(base64_decode($result[$i]['warenkorb'])); + } + if (!empty($tmpwarenkorb['projekt']) && $this->app->DB->Select("SELECT id FROM projekt WHERE id = '" . (int) $tmpwarenkorb['projekt'] . "' LIMIT 1")) { + $projekt = (int) $tmpwarenkorb['projekt']; + } + if (!empty($tmpwarenkorb['zeitstempel'])) { + $time = strtotime($tmpwarenkorb['zeitstempel']); + if ($time < 0) { + $time = 0; + } + if ($maxtime === false) { + $maxtime = $time; + } + if ($mintime === false) { + $mintime = $time; + } + if ($time > $maxtime) { + $maxtime = $time; + } + if ($time < $mintime) { + $mintime = $time; + } + } + $onlinebestellnummer = $tmpwarenkorb['onlinebestellnummer']; + if (!empty($tmpwarenkorb['useorderid']) || + (!is_numeric($onlinebestellnummer) && trim((String) $onlinebestellnummer) !== '')) { + $onlinebestellnummer = $tmpwarenkorb['auftrag']; + } + + if ($holealle && $onlinebestellnummer) { + $neue_nummer = (int) $onlinebestellnummer + 1; + $this->app->DB->Update("UPDATE shopexport SET ab_nummer = '$neue_nummer' WHERE id = '$id'"); + } + $sessionid = isset($result[$i]['sessionid']) ? $result[$i]['sessionid'] : ''; + if ($isjson) { + $warenkorb = $result[$i]['warenkorbjson']; + } else { + $warenkorb = $result[$i]['warenkorb']; + } + $logdatei = isset($result[$i]['logdatei']) ? $result[$i]['logdatei'] : null; + if (empty($logdatei)) { + $logdatei = date('Y-m-d H:i:s'); + } + if (isset($tmpwarenkorb['subshop']) && $tmpwarenkorb['subshop']) { + $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '$id' AND aktiv = 1 AND subshopkennung = '" . $this->app->DB->real_escape_string($tmpwarenkorb['subshop']) . "' LIMIT 1"); + if ($subshopprojekt) { + $projekt = $subshopprojekt; + } + } + $letzteonlinebestellnummer = $tmpwarenkorb['onlinebestellnummer']; + unset($tmpwarenkorb); + + //globalerauftragsnummernkreis + $standardcheck = true; + $modulename = $this->app->DB->Select( + sprintf( + "SELECT modulename FROM shopexport WHERE id = %d AND modulename <> '' AND (shoptyp = 'intern')", + $id + ) + ); + $shopIds = [$id]; + $otherModules = empty($modulename) ? null : + $this->app->DB->SelectFirstCols( + sprintf( + "SELECT id + FROM shopexport + WHERE modulename = '%s' AND id <> %d", + $this->app->DB->real_escape_string($modulename), $id + ) + ); + if (!empty($otherModules) && $this->app->erp->ModulVorhanden($modulename)) { + $obj = $this->app->erp->LoadModul($modulename); + if (!empty($obj) && method_exists($obj, 'EinstellungenStruktur')) { + $konfiguration = $obj->EinstellungenStruktur(); + if ($konfiguration && isset($konfiguration['globalerauftragsnummernkreis']) && $konfiguration['globalerauftragsnummernkreis']) { + $shopIds = array_merge([$id], $otherModules); + $standardcheck = false; + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') and warenkorb = '".$this->app->DB->real_escape_string($warenkorb)."' AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); */ + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); */ + } + } + } + $checkdoppeltimported = $this->app->DB->Select( + sprintf( + "SELECT id FROM shopimport_auftraege WHERE extid = '%s' and shopid IN (%s) AND trash = 0 AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) LIMIT 1", - $this->app->DB->real_escape_string($auftrag), implode(',', $shopIds) - ) - ); - - /*if($standardcheck){*/ - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '" . $this->app->DB->real_escape_string($auftrag) . "' and shopid = '$id' and warenkorb = '" . $this->app->DB->real_escape_string($warenkorb) . "' AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1");*/ - /*$checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '" . $this->app->DB->real_escape_string($auftrag) . "' and shopid = '$id' AND trash = 0 - AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) - LIMIT 1"); - }*/ - - $insid = null; - if($demomodus == '1') - { - $checkdoppeltimported = null; - } - if(!$checkdoppeltimported) - { - $this->app->DB->Insert("INSERT INTO shopimport_auftraege (id,extid,sessionid,warenkorb,imported,projekt,bearbeiter,logdatei) - VALUES('','$auftrag','$sessionid','$warenkorb','0','$projekt','".$this->app->User->GetName()."','$logdatei')"); - $insid = $this->app->DB->GetInsertID(); - if($insid){ - $this->app->DB->Update("UPDATE shopimport_auftraege set shopid = '$id' where id = '$insid'"); - $this->app->DB->Update("UPDATE shopimport_auftraege set logdatei = now() where id = '$insid' AND logdatei = '0000-00-00' OR logdatei > now()"); - if($isjson){ - $this->app->DB->Update("UPDATE shopimport_auftraege set jsonencoded = 1 where id = '$insid'"); + $this->app->DB->real_escape_string($auftrag), implode(',', $shopIds) + ) + ); + /* if($standardcheck) + { */ + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and shopid = '$id' and warenkorb = '".$this->app->DB->real_escape_string($warenkorb)."' AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); */ + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and shopid = '$id' AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); + } */ + $insid = null; + if (empty($checkdoppeltimported)) { + $this->app->DB->Insert("INSERT INTO shopimport_auftraege (id,extid,sessionid,warenkorb,imported,projekt,bearbeiter,logdatei) + VALUES('','" . $this->app->DB->real_escape_string($auftrag) . "','" . $this->app->DB->real_escape_string($sessionid) . "','" . $this->app->DB->real_escape_string($warenkorb) . "','0','$projekt','" . $this->app->DB->real_escape_string($this->app->User->GetName()) . "','" . $this->app->DB->real_escape_string($logdatei) . "')"); + $insid = $this->app->DB->GetInsertID(); + if ($insid) { + if ($isjson) { + $this->app->DB->Update("UPDATE shopimport_auftraege set jsonencoded = 1 where id = '$insid'"); + } + $this->app->DB->Update("UPDATE shopimport_auftraege set shopid = '$id' where id = '$insid'"); + $this->app->DB->Update("UPDATE shopimport_auftraege set bestellnummer = '" . $this->app->DB->real_escape_string($letzteonlinebestellnummer) . "' where id = '$insid'"); + } + } + if ($demomodus != '1') { + $this->app->remote->RemoteDeleteAuftrag($id, $auftrag, $letzteonlinebestellnummer); + } elseif ($demomodus == '1') { + break; + } + unset($letzteonlinebestellnummer); + } + if (!$demomodus) { + if (empty($maxtime)) { + $maxtime = strtotime(date('Y-m-d H:i:s')); + } + $datumvon = strtotime($zeitraum['datumvon']); + $datumbis = strtotime($zeitraum['datumbis']); + $tmpdatumvon = strtotime($zeitraum['tmpdatumvon']); + $tmpdatumbis = strtotime($zeitraum['tmpdatumbis']); + if ($datumvon < 0) { + $datumvon = 0; + } + if ($datumbis < 0) { + $datumbis = 0; + } + if ($tmpdatumvon < 0) { + $tmpdatumvon = 0; + } + if ($tmpdatumbis < 0) { + $tmpdatumbis = 0; + } + $this->app->DB->Update("UPDATE shopexport SET datumvon = '" . date('Y-m-d H:i:s', $maxtime) . "', tmpdatumbis = '0000-00-00' WHERE id = '$id' LIMIT 1"); + } + } else { + if (!$demomodus) { + if (is_array($result) && !empty($result['zeitstempel'])) { + $this->app->DB->Update("UPDATE shopexport SET datumvon = '" . date('Y-m-d H:i:s', strtotime($result['zeitstempel'])) . "', tmpdatumbis = '0000-00-00' WHERE id = '$id' AND datumvon < '" . date('Y-m-d H:i:s', strtotime($result['zeitstempel'])) . "' LIMIT 1"); + } + if (empty($maxtime)) { + $maxtime = strtotime(date('Y-m-d H:i:s')); + } + $datumvon = strtotime($zeitraum['datumvon']); + $datumbis = strtotime($zeitraum['datumbis']); + $tmpdatumvon = strtotime($zeitraum['tmpdatumvon']); + $tmpdatumbis = strtotime($zeitraum['tmpdatumbis']); + if ($datumvon < 0) { + $datumvon = 0; + } + if ($datumbis < 0) { + $datumbis = 0; + } + if ($tmpdatumvon < 0) { + $tmpdatumvon = 0; + } + if ($tmpdatumbis < 0) { + $tmpdatumbis = 0; + } + if ($tmpdatumbis) { + $this->app->DB->Update("UPDATE shopexport SET tmpdatumbis = '0000-00-00' WHERE id = '$id' LIMIT 1"); + } + } } - } - } + } else { + $gesamtanzahl = $this->app->remote->RemoteGetAuftraegeAnzahl($id); + $maxmanuell = (int) $this->app->DB->Select("SELECT maxmanuell FROM shopexport WHERE id = '$id' LIMIT 1"); + if ($maxmanuell <= 0) { + $maxmanuell = 100; + } + if ($gesamtanzahl > $maxmanuell) { + $gesamtanzahl = $maxmanuell; + } + if ($einzelsync == '1' && $gesamtanzahl > 1 && $maxmanuell <= 1) { + $gesamtanzahl = 1; + } + if ($gesamtanzahl > 0) { + for ($i = 0; $i < $gesamtanzahl; $i++) { + //import au + $result = $this->app->remote->RemoteGetAuftrag($id); - if($demomodus!='1') - { - $this->app->remote->RemoteDeleteAuftrag($id,$auftrag); + if (is_array($result)) { + $auftrag = $result[0]['id']; + if (isset($result[0]['warenkorbjson'])) { + $isjson = true; + $tmpwarenkorb = json_decode(base64_decode($result[0]['warenkorbjson']), true); + } else { + $isjson = false; + $tmpwarenkorb = unserialize(base64_decode($result[0]['warenkorb'])); + } + $onlinebestellnummer = $tmpwarenkorb['onlinebestellnummer']; + if (!empty($tmpwarenkorb['useorderid']) || (!is_numeric($onlinebestellnummer) && trim((String) $onlinebestellnummer) !== '')) { + $onlinebestellnummer = $tmpwarenkorb['auftrag']; + } + if ($holealle && $onlinebestellnummer) { + $neue_nummer = (int) $onlinebestellnummer + 1; + $this->app->DB->Update("UPDATE shopexport SET ab_nummer = '$neue_nummer' WHERE id = '$id'"); + } + $sessionid = $result[0]['sessionid']; + if ($isjson) { + $warenkorb = $result[0]['warenkorbjson']; + } else { + $warenkorb = $result[0]['warenkorb']; + } + $logdatei = $result[0]['logdatei']; + if (empty($logdatei)) { + $logdatei = date('Y-m-d H:i:s'); + } + $projekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '$id' LIMIT 1"); + if (!empty($tmpwarenkorb['projekt']) && $this->app->DB->Select("SELECT id FROM projekt WHERE id = '" . (int) $tmpwarenkorb['projekt'] . "' LIMIT 1")) { + $projekt = (int) $tmpwarenkorb['projekt']; + } + if (isset($tmpwarenkorb['subshop']) && $tmpwarenkorb['subshop']) { + $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '$id' AND aktiv = 1 AND subshopkennung = '" . $this->app->DB->real_escape_string($tmpwarenkorb['subshop']) . "' LIMIT 1"); + if ($subshopprojekt) { + $projekt = $subshopprojekt; + } + } + unset($tmpwarenkorb); + + $standardcheck = true; + $modulename = $this->app->DB->Select( + sprintf( + "SELECT modulename FROM shopexport WHERE id = %d AND modulename <> '' AND (shoptyp = 'intern')", + $id + ) + ); + $shopIds = [$id]; + $otherModules = empty($modulename) ? null : + $this->app->DB->SelectFirstCols( + sprintf( + "SELECT id + FROM shopexport + WHERE modulename = '%s' AND id <> %d", + $this->app->DB->real_escape_string($modulename), $id + ) + ); + if (!empty($otherModules) && $this->app->erp->ModulVorhanden($modulename)) { + $obj = $this->app->erp->LoadModul($modulename); + if (!empty($obj) && method_exists($obj, 'EinstellungenStruktur')) { + $konfiguration = $obj->EinstellungenStruktur(); + if ($konfiguration && isset($konfiguration['globalerauftragsnummernkreis']) && $konfiguration['globalerauftragsnummernkreis']) { + $shopIds = array_merge([$id], $otherModules); + $standardcheck = false; + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') and warenkorb = '".$this->app->DB->real_escape_string($warenkorb)."' AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); */ + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '".$this->app->DB->real_escape_string($auftrag)."' and ((modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern') OR shopid = '$id') AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); */ + } + } + } + $checkdoppeltimported = $this->app->DB->Select( + sprintf( + "SELECT id + FROM shopimport_auftraege + WHERE extid = '%s' and shopid IN (%s) AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1", + $this->app->DB->real_escape_string($auftrag), implode(',', $shopIds) + ) + ); + + /* if($standardcheck){ */ + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '" . $this->app->DB->real_escape_string($auftrag) . "' and shopid = '$id' and warenkorb = '" . $this->app->DB->real_escape_string($warenkorb) . "' AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); */ + /* $checkdoppeltimported = $this->app->DB->Select("SELECT id FROM shopimport_auftraege WHERE extid = '" . $this->app->DB->real_escape_string($auftrag) . "' and shopid = '$id' AND trash = 0 + AND (imported = 0 OR (imported = 1 AND DATE_SUB(NOW(),INTERVAL 10 MINUTE)>logdatei )) + LIMIT 1"); + } */ + + $insid = null; + if ($demomodus == '1') { + $checkdoppeltimported = null; + } + if (!$checkdoppeltimported) { + $this->app->DB->Insert("INSERT INTO shopimport_auftraege (id,extid,sessionid,warenkorb,imported,projekt,bearbeiter,logdatei) + VALUES('','$auftrag','$sessionid','$warenkorb','0','$projekt','" . $this->app->User->GetName() . "','$logdatei')"); + $insid = $this->app->DB->GetInsertID(); + if ($insid) { + $this->app->DB->Update("UPDATE shopimport_auftraege set shopid = '$id' where id = '$insid'"); + $this->app->DB->Update("UPDATE shopimport_auftraege set logdatei = now() where id = '$insid' AND logdatei = '0000-00-00' OR logdatei > now()"); + if ($isjson) { + $this->app->DB->Update("UPDATE shopimport_auftraege set jsonencoded = 1 where id = '$insid'"); + } + } + } + + if ($demomodus != '1') { + $this->app->remote->RemoteDeleteAuftrag($id, $auftrag); + } elseif ($demomodus == '1') { + $i = $gesamtanzahl; + } + } + } + } } - elseif($demomodus == '1') - { - $i=$gesamtanzahl; + } else { + if (!$returncount) { + $this->app->Tpl->Set('IMPORT', "
    Verbindungsprobleme! Bitte Administrator kontaktieren! ($pageContents)
    "); + } else { + $this->error = "
    Verbindungsprobleme! Bitte Administrator kontaktieren! ($pageContents)
    "; } - } } - } } - } else { - if(!$returncount) - { - $this->app->Tpl->Set('IMPORT',"
    Verbindungsprobleme! Bitte Administrator kontaktieren! ($pageContents)
    "); - }else { - $this->error = "
    Verbindungsprobleme! Bitte Administrator kontaktieren! ($pageContents)
    "; + + if (!$returncount) { + $this->drawShopOrderTable($deletedRows); + } else { + return $count + (is_numeric($gesamtanzahl) ? $gesamtanzahl : 0); } - } } - if(!$returncount) - { - $this->drawShopOrderTable($deletedRows); - } else - { - return $count+(is_numeric($gesamtanzahl)?$gesamtanzahl:0); - } - } - - /** - * @param array $arr - * - * @return array - */ - public function getCustomerNumberFromShopCart($arr) - { - $validkundennummer = ''; - if(!empty($arr['jsonencoded'])) - { - $warenkorb = json_decode(base64_decode($arr['warenkorb']),true); - }else{ - $warenkorb = unserialize(base64_decode($arr['warenkorb'])); - } - foreach($warenkorb as $key=>$value) { - if(is_string($warenkorb[$key])){ - $warenkorb[$key] = trim($warenkorb[$key]); - } - } - foreach($warenkorb as $k => $v) { - $warenkorb[$k] = $this->app->erp->fixeUmlaute($v); - } - - $kundenurvonprojekt = $this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '".$arr['shopid']."' LIMIT 1"); - $adresseprojekt = ''; - if($kundenurvonprojekt) - { - $adresseprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '".$arr['shopid']."' LIMIT 1"); - } - if(!empty($warenkorb['kundennummer'])) { - $validkundennummer = $this->app->DB->Select( - "SELECT kundennummer - FROM adresse - WHERE kundennummer='".$warenkorb['kundennummer']."' and email <> '' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' - LIMIT 1" - ); - } - if(isset($warenkorb['subshop']) && $warenkorb['subshop']) - { - $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '".$arr['shopid']."' AND aktiv = 1 AND subshopkennung = '".$this->app->DB->real_escape_string($warenkorb['subshop'])."' LIMIT 1"); - if($subshopprojekt) - { - if(!$kundenurvonprojekt) - { - $adresseprojekt = $subshopprojekt; + /** + * @param array $arr + * + * @return array + */ + public function getCustomerNumberFromShopCart($arr) { + $validkundennummer = ''; + if (!empty($arr['jsonencoded'])) { + $warenkorb = json_decode(base64_decode($arr['warenkorb']), true); + } else { + $warenkorb = unserialize(base64_decode($arr['warenkorb'])); } - $arr['abkuerzung'] = $this->app->DB->Select("SELECT abkuerzung FROM projekt WHERE id = '$adresseprojekt' LIMIT 1"); - } - } - if($kundenurvonprojekt) - { - $adresseprojekt = " AND projekt = '".$adresseprojekt."' "; - }else { - $adresseprojekt = ''; - } - - $checkid = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE `name`='".$this->app->DB->real_escape_string($warenkorb['name'])."' AND abteilung='".$this->app->DB->real_escape_string($warenkorb['abteilung'])."' - AND strasse='".$this->app->DB->real_escape_string($warenkorb['strasse'])."' AND plz='".$this->app->DB->real_escape_string($warenkorb['plz'])."' AND ort='".$this->app->DB->real_escape_string($warenkorb['ort'])."' AND kundennummer <> '' AND geloescht!=1 $adresseprojekt - ORDER BY email='".$this->app->DB->real_escape_string($warenkorb['email'])."' DESC - LIMIT 1"); - - - if($warenkorb['email'] != '') - { - if($warenkorb['email']!=='amazon_import_bounce@nfxmedia.de') - { - $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE email='".$warenkorb['email']."' and email <> '' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); - } - if((String)$checkidemail === ''){ - $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name LIKE '" . $warenkorb['name'] . "' AND ort LIKE '" . $warenkorb['ort'] . "' AND geloescht!=1 $adresseprojekt AND kundennummer <> '' LIMIT 1"); - } - }else{ - $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name='".$this->app->DB->real_escape_string($warenkorb['name'])."' AND strasse='".$this->app->DB->real_escape_string($warenkorb['strasse'])."' AND plz='".$this->app->DB->real_escape_string($warenkorb['plz'])."' AND ort='".$this->app->DB->real_escape_string($warenkorb['ort'])."' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); - } - - if($warenkorb['kundennummer']!='' && !empty($validkundennummer) && $validkundennummer==$warenkorb['kundennummer']) - { - $kdrnummer = $warenkorb['kundennummer']; - } - elseif ($checkid!='') - { - $kdrnummer = $checkid; - } - elseif ($checkidemail!='') - { - $kdrnummer = $checkidemail; - } - else { - $kdrnummer=''; - $checkidemail=''; - } - - return [$checkidemail, $kdrnummer]; - } - - public function drawShopOrderTable($deletedRows) { - $checkglobal = null; - $htmltable = new HTMLTable(0,'100%','',3,1,'font-size:85%'); - $htmltable->AddRowAsHeading(array('Import','Müll','Später','Projekt','Internet','Name','Bemerkung','Strasse','PLZ','Ort','Kd.Nr.','vorhanden','Land','Betrag','Offen','Zahlung','Partner')); - $htmltable->ChangingRowColors('#e0e0e0','#fff'); - - $shopid = $this->app->Secure->GetGET('shopid'); - $where = ''; - if(!empty($shopid)){ - $where = 'AND sa.shopid='.(int)$shopid; - } - - $bestellnummer = $this->app->Secure->GetGET('bestellnummer'); - if(!empty($bestellnummer)){ - $bestellnummer = preg_replace('/[^\w-]/', '', $bestellnummer); - $where .= " AND sa.bestellnummer='$bestellnummer'"; - } - - $arr = $this->app->DB->SelectArr("SELECT sa.*, p.abkuerzung FROM shopimport_auftraege sa left join projekt p on sa.projekt = p.id WHERE sa.imported='0' AND sa.trash='0' $where ORDER BY sa.logdatei LIMIT 100"); - if(is_array($arr) && (!empty($arr)?count($arr):0) > 0) - { - - //Alte Auftraege prüfen - $alteauftraegeohnebestellnummer = $this->app->DB->Query("SELECT sa.* FROM shopimport_auftraege sa WHERE isnull(bestellnummer) AND sa.trash='0' LIMIT 100"); - while($row = $this->app->DB->Fetch_Assoc($alteauftraegeohnebestellnummer)) - { - if($row['warenkorb'] != '') - { - if(!empty($row['jsonencoded'])) - { - $warenkorb = json_decode(base64_decode($row['warenkorb']),true); - }else{ - $warenkorb = unserialize(base64_decode($row['warenkorb'])); - } - $this->app->DB->Update("UPDATE shopimport_auftraege set bestellnummer = '".(isset($warenkorb['onlinebestellnummer'])?$warenkorb['onlinebestellnummer']:'')."' where id = '".$row['id']."'"); - }else{ - $this->app->DB->Update("UPDATE shopimport_auftraege set bestellnummer = '' where id = '".$row['id']."'"); - } - } - $this->app->DB->free($alteauftraegeohnebestellnummer); - - $unbekanntezahlungsweisen = null; - $enthaeltdoppeltenummern = false; - $carr = $arr?count($arr):0; - for($i=0;$i<$carr;$i++) - { - if(empty($checkglobal) || !isset($checkglobal[$arr[$i]['shopid']])) - { - $checkglobal[$arr[$i]['shopid']] = null; - - if(($modulename = $this->app->DB->Select("SELECT modulename FROM shopexport WHERE id = '".$arr[$i]['shopid']."' AND modulename <> '' AND shoptyp = 'intern'")) - && $this->app->DB->Select("SELECT id FROM shopexport WHERE modulename = '".$this->app->DB->real_escape_string($modulename)."' AND id <> '".$arr[$i]['shopid']."' LIMIT 1") - ) - { - $shopsintern = $this->app->DB->SelectArr("SELECT id FROM shopexport WHERE id = '".$arr[$i]['shopid']."' OR (modulename = '".$this->app->DB->real_escape_string($modulename)."' AND shoptyp = 'intern')"); - if($shopsintern) - { - foreach($shopsintern as $vs) - { - $checkglobal[$arr[$i]['shopid']][] = " shopid = '". $vs['id']."' "; - } - if($this->app->erp->ModulVorhanden($modulename)) - { - /** @var ShopimporterBase $obj */ - $obj = $this->app->erp->LoadModul($modulename); - if($obj && method_exists($obj, 'EinstellungenStruktur')){ - $konfiguration = $obj->EinstellungenStruktur(); - if($konfiguration && isset($konfiguration['globalerauftragsnummernkreis']) && $konfiguration['globalerauftragsnummernkreis']) - { - - }else - { - $checkglobal[$arr[$i]['shopid']] = null; - } - }else { - $checkglobal[$arr[$i]['shopid']] = null; - } - }else { - $checkglobal[$arr[$i]['shopid']] = null; - } + foreach ($warenkorb as $key => $value) { + if (is_string($warenkorb[$key])) { + $warenkorb[$key] = trim($warenkorb[$key]); } - } } - } + foreach ($warenkorb as $k => $v) { + $warenkorb[$k] = $this->app->erp->fixeUmlaute($v); + } - $carr = $arr?count($arr):0; - for($i=0;$i<$carr;$i++) - { - $projekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '".$arr[$i]['shopid']."' LIMIT 1"); - $auftraegeaufspaeter = $this->app->DB->Select("SELECT auftraegeaufspaeter FROM shopexport WHERE id='".$arr[$i]['shopid']."'"); - if(!empty($arr[$i]['jsonencoded'])) - { - $warenkorb = json_decode(base64_decode($arr[$i]['warenkorb']),true); - }else{ - $warenkorb = unserialize(base64_decode($arr[$i]['warenkorb'])); - } - foreach($warenkorb as $key=>$value) { - if(is_string($warenkorb[$key])){ - $warenkorb[$key] = trim($warenkorb[$key]); - } - } - foreach($warenkorb as $k => $v) { - $warenkorb[$k] = $this->app->erp->fixeUmlaute($v); - } - $kundenurvonprojekt = $this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '".$arr[$i]['shopid']."' LIMIT 1"); + $kundenurvonprojekt = $this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '" . $arr['shopid'] . "' LIMIT 1"); $adresseprojekt = ''; - if($kundenurvonprojekt) - { - $adresseprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '".$arr[$i]['shopid']."' LIMIT 1"); + if ($kundenurvonprojekt) { + $adresseprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '" . $arr['shopid'] . "' LIMIT 1"); } - if(isset($warenkorb['subshop']) && $warenkorb['subshop']) - { - $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '".$arr[$i]['shopid']."' AND aktiv = 1 AND subshopkennung = '".$this->app->DB->real_escape_string($warenkorb['subshop'])."' LIMIT 1"); - if($subshopprojekt) - { - if(!$kundenurvonprojekt) - { - $adresseprojekt = $subshopprojekt; + if (!empty($warenkorb['kundennummer'])) { + $validkundennummer = $this->app->DB->Select( + "SELECT kundennummer + FROM adresse + WHERE kundennummer='" . $warenkorb['kundennummer'] . "' and email <> '' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' + LIMIT 1" + ); + } + if (isset($warenkorb['subshop']) && $warenkorb['subshop']) { + $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '" . $arr['shopid'] . "' AND aktiv = 1 AND subshopkennung = '" . $this->app->DB->real_escape_string($warenkorb['subshop']) . "' LIMIT 1"); + if ($subshopprojekt) { + if (!$kundenurvonprojekt) { + $adresseprojekt = $subshopprojekt; + } + $arr['abkuerzung'] = $this->app->DB->Select("SELECT abkuerzung FROM projekt WHERE id = '$adresseprojekt' LIMIT 1"); } - $arr[$i]['abkuerzung'] = $this->app->DB->Select("SELECT abkuerzung FROM projekt WHERE id = '$adresseprojekt' LIMIT 1"); - } } - if($kundenurvonprojekt) - { - $adresseprojekt = " AND projekt = '".$adresseprojekt."' "; - }else { - $adresseprojekt = ''; + if ($kundenurvonprojekt) { + $adresseprojekt = " AND projekt = '" . $adresseprojekt . "' "; + } else { + $adresseprojekt = ''; } - $checkid = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE `name`='".$this->app->DB->real_escape_string($warenkorb['name'])."' AND abteilung='".$this->app->DB->real_escape_string($warenkorb['abteilung'])."' - AND strasse='".$this->app->DB->real_escape_string($warenkorb['strasse'])."' AND plz='".$this->app->DB->real_escape_string($warenkorb['plz'])."' AND ort='".$this->app->DB->real_escape_string($warenkorb['ort'])."' AND kundennummer <> '' AND geloescht!=1 $adresseprojekt - ORDER BY email='".$this->app->DB->real_escape_string($warenkorb['email'])."' DESC + $checkid = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE `name`='" . $this->app->DB->real_escape_string($warenkorb['name']) . "' AND abteilung='" . $this->app->DB->real_escape_string($warenkorb['abteilung']) . "' + AND strasse='" . $this->app->DB->real_escape_string($warenkorb['strasse']) . "' AND plz='" . $this->app->DB->real_escape_string($warenkorb['plz']) . "' AND ort='" . $this->app->DB->real_escape_string($warenkorb['ort']) . "' AND kundennummer <> '' AND geloescht!=1 $adresseprojekt + ORDER BY email='" . $this->app->DB->real_escape_string($warenkorb['email']) . "' DESC LIMIT 1"); + if ($warenkorb['email'] != '') { + if ($warenkorb['email'] !== 'amazon_import_bounce@nfxmedia.de') { + $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE email='" . $warenkorb['email'] . "' and email <> '' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); + } + if ((String) $checkidemail === '') { + $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name LIKE '" . $warenkorb['name'] . "' AND ort LIKE '" . $warenkorb['ort'] . "' AND geloescht!=1 $adresseprojekt AND kundennummer <> '' LIMIT 1"); + } + } else { + $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name='" . $this->app->DB->real_escape_string($warenkorb['name']) . "' AND strasse='" . $this->app->DB->real_escape_string($warenkorb['strasse']) . "' AND plz='" . $this->app->DB->real_escape_string($warenkorb['plz']) . "' AND ort='" . $this->app->DB->real_escape_string($warenkorb['ort']) . "' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); + } - if($warenkorb['email'] != '') - { - if($warenkorb['email']!=='amazon_import_bounce@nfxmedia.de') - { + if ($warenkorb['kundennummer'] != '' && !empty($validkundennummer) && $validkundennummer == $warenkorb['kundennummer']) { + $kdrnummer = $warenkorb['kundennummer']; + } elseif ($checkid != '') { + $kdrnummer = $checkid; + } elseif ($checkidemail != '') { + $kdrnummer = $checkidemail; + } else { + $kdrnummer = ''; + $checkidemail = ''; + } + + return [$checkidemail, $kdrnummer]; + } + + public function drawShopOrderTable($deletedRows) { + $checkglobal = null; + $htmltable = new HTMLTable(0, '100%', '', 3, 1, 'font-size:85%'); + $htmltable->AddRowAsHeading(array('Import', 'Müll', 'Später', 'Projekt', 'Internet', 'Name', 'Bemerkung', 'Strasse', 'PLZ', 'Ort', 'Kd.Nr.', 'vorhanden', 'Land', 'Betrag', 'Offen', 'Zahlung', 'Partner')); + $htmltable->ChangingRowColors('#e0e0e0', '#fff'); + + $shopid = $this->app->Secure->GetGET('shopid'); + $where = ''; + if (!empty($shopid)) { + $where = 'AND sa.shopid=' . (int) $shopid; + } + + $bestellnummer = $this->app->Secure->GetGET('bestellnummer'); + if (!empty($bestellnummer)) { + $bestellnummer = preg_replace('/[^\w-]/', '', $bestellnummer); + $where .= " AND sa.bestellnummer='$bestellnummer'"; + } + + $arr = $this->app->DB->SelectArr("SELECT sa.*, p.abkuerzung FROM shopimport_auftraege sa left join projekt p on sa.projekt = p.id WHERE sa.imported='0' AND sa.trash='0' $where ORDER BY sa.logdatei LIMIT 100"); + if (is_array($arr) && (!empty($arr) ? count($arr) : 0) > 0) { + + //Alte Auftraege prüfen + $alteauftraegeohnebestellnummer = $this->app->DB->Query("SELECT sa.* FROM shopimport_auftraege sa WHERE isnull(bestellnummer) AND sa.trash='0' LIMIT 100"); + while ($row = $this->app->DB->Fetch_Assoc($alteauftraegeohnebestellnummer)) { + if ($row['warenkorb'] != '') { + if (!empty($row['jsonencoded'])) { + $warenkorb = json_decode(base64_decode($row['warenkorb']), true); + } else { + $warenkorb = unserialize(base64_decode($row['warenkorb'])); + } + $this->app->DB->Update("UPDATE shopimport_auftraege set bestellnummer = '" . (isset($warenkorb['onlinebestellnummer']) ? $warenkorb['onlinebestellnummer'] : '') . "' where id = '" . $row['id'] . "'"); + } else { + $this->app->DB->Update("UPDATE shopimport_auftraege set bestellnummer = '' where id = '" . $row['id'] . "'"); + } + } + $this->app->DB->free($alteauftraegeohnebestellnummer); + + $unbekanntezahlungsweisen = null; + $enthaeltdoppeltenummern = false; + $carr = $arr ? count($arr) : 0; + for ($i = 0; $i < $carr; $i++) { + if (empty($checkglobal) || !isset($checkglobal[$arr[$i]['shopid']])) { + $checkglobal[$arr[$i]['shopid']] = null; + + if (($modulename = $this->app->DB->Select("SELECT modulename FROM shopexport WHERE id = '" . $arr[$i]['shopid'] . "' AND modulename <> '' AND shoptyp = 'intern'")) && $this->app->DB->Select("SELECT id FROM shopexport WHERE modulename = '" . $this->app->DB->real_escape_string($modulename) . "' AND id <> '" . $arr[$i]['shopid'] . "' LIMIT 1") + ) { + $shopsintern = $this->app->DB->SelectArr("SELECT id FROM shopexport WHERE id = '" . $arr[$i]['shopid'] . "' OR (modulename = '" . $this->app->DB->real_escape_string($modulename) . "' AND shoptyp = 'intern')"); + if ($shopsintern) { + foreach ($shopsintern as $vs) { + $checkglobal[$arr[$i]['shopid']][] = " shopid = '" . $vs['id'] . "' "; + } + if ($this->app->erp->ModulVorhanden($modulename)) { + /** @var ShopimporterBase $obj */ + $obj = $this->app->erp->LoadModul($modulename); + if ($obj && method_exists($obj, 'EinstellungenStruktur')) { + $konfiguration = $obj->EinstellungenStruktur(); + if ($konfiguration && isset($konfiguration['globalerauftragsnummernkreis']) && $konfiguration['globalerauftragsnummernkreis']) { + + } else { + $checkglobal[$arr[$i]['shopid']] = null; + } + } else { + $checkglobal[$arr[$i]['shopid']] = null; + } + } else { + $checkglobal[$arr[$i]['shopid']] = null; + } + } + } + } + } + + $carr = $arr ? count($arr) : 0; + for ($i = 0; $i < $carr; $i++) { + $projekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '" . $arr[$i]['shopid'] . "' LIMIT 1"); + $auftraegeaufspaeter = $this->app->DB->Select("SELECT auftraegeaufspaeter FROM shopexport WHERE id='" . $arr[$i]['shopid'] . "'"); + if (!empty($arr[$i]['jsonencoded'])) { + $warenkorb = json_decode(base64_decode($arr[$i]['warenkorb']), true); + } else { + $warenkorb = unserialize(base64_decode($arr[$i]['warenkorb'])); + } + foreach ($warenkorb as $key => $value) { + if (is_string($warenkorb[$key])) { + $warenkorb[$key] = trim($warenkorb[$key]); + } + } + foreach ($warenkorb as $k => $v) { + $warenkorb[$k] = $this->app->erp->fixeUmlaute($v); + } + $kundenurvonprojekt = $this->app->DB->Select("SELECT kundenurvonprojekt FROM shopexport WHERE id = '" . $arr[$i]['shopid'] . "' LIMIT 1"); + $adresseprojekt = ''; + if ($kundenurvonprojekt) { + $adresseprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport WHERE id = '" . $arr[$i]['shopid'] . "' LIMIT 1"); + } + if (isset($warenkorb['subshop']) && $warenkorb['subshop']) { + $subshopprojekt = $this->app->DB->Select("SELECT projekt FROM shopexport_subshop WHERE shop = '" . $arr[$i]['shopid'] . "' AND aktiv = 1 AND subshopkennung = '" . $this->app->DB->real_escape_string($warenkorb['subshop']) . "' LIMIT 1"); + if ($subshopprojekt) { + if (!$kundenurvonprojekt) { + $adresseprojekt = $subshopprojekt; + } + $arr[$i]['abkuerzung'] = $this->app->DB->Select("SELECT abkuerzung FROM projekt WHERE id = '$adresseprojekt' LIMIT 1"); + } + } + if ($kundenurvonprojekt) { + $adresseprojekt = " AND projekt = '" . $adresseprojekt . "' "; + } else { + $adresseprojekt = ''; + } + + $checkid = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE `name`='" . $this->app->DB->real_escape_string($warenkorb['name']) . "' AND abteilung='" . $this->app->DB->real_escape_string($warenkorb['abteilung']) . "' + AND strasse='" . $this->app->DB->real_escape_string($warenkorb['strasse']) . "' AND plz='" . $this->app->DB->real_escape_string($warenkorb['plz']) . "' AND ort='" . $this->app->DB->real_escape_string($warenkorb['ort']) . "' AND kundennummer <> '' AND geloescht!=1 $adresseprojekt + ORDER BY email='" . $this->app->DB->real_escape_string($warenkorb['email']) . "' DESC + LIMIT 1"); + + if ($warenkorb['email'] != '') { + if ((String) $checkidemail === '') { $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE email='".$this->app->DB->real_escape_string($warenkorb['email'])."' and email <> '' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); - } - if((String)$checkidemail === ''){ $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name LIKE '" . $this->app->DB->real_escape_string($warenkorb['name']) . "' AND ort LIKE '" . $this->app->DB->real_escape_string($warenkorb['ort']) . "' AND geloescht!=1 $adresseprojekt AND kundennummer <> '' LIMIT 1"); - } - }else{ - $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name='".$this->app->DB->real_escape_string($warenkorb['name'])."' AND strasse='".$this->app->DB->real_escape_string($warenkorb['strasse'])."' AND plz='".$this->app->DB->real_escape_string($warenkorb['plz'])."' AND ort='".$this->app->DB->real_escape_string($warenkorb['ort'])."' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); + } + } else { + $checkidemail = $this->app->DB->Select("SELECT kundennummer FROM adresse WHERE name='" . $this->app->DB->real_escape_string($warenkorb['name']) . "' AND strasse='" . $this->app->DB->real_escape_string($warenkorb['strasse']) . "' AND plz='" . $this->app->DB->real_escape_string($warenkorb['plz']) . "' AND ort='" . $this->app->DB->real_escape_string($warenkorb['ort']) . "' $adresseprojekt AND geloescht!=1 AND kundennummer <> '' LIMIT 1"); + } + + if ($warenkorb['kundennummer'] != '' && !empty($validkundennummer) && $validkundennummer == $warenkorb['kundennummer']) { + $kdrnummer = $warenkorb['kundennummer']; + $kdr_name = $this->app->DB->Select("SELECT name FROM adresse WHERE kundennummer='$kdrnummer' $adresseprojekt AND geloescht!=1 LIMIT 1"); + $email = $this->app->DB->Select("SELECT email FROM adresse WHERE kundennummer='$kdrnummer' $adresseprojekt AND geloescht!=1 LIMIT 1"); + $parts = explode("\n", wordwrap($kdr_name, 20, "\n")); + $kdr_name = $parts[0]; + $kdr_name = '
    ' . $kdr_name . ''; + $email = '
    ' . $email . ''; + + $kdr_strasse = $this->app->DB->Select("SELECT strasse FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); + $parts = explode("\n", wordwrap($kdr_strasse, 20, "\n")); + $kdr_strasse = $parts[0]; + $kdr_strasse = '
    ' . $kdr_strasse . ''; + + $kdr_plz = '
    ' . $this->app->DB->Select("SELECT plz FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1") . ''; + $kdr_ort = '
    ' . $this->app->DB->Select("SELECT ort FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1") . ''; + $checked = ''; + } elseif ($checkid != '') { + $checked = 'checked'; + $kdrnummer = $checkid; + //$kdr_name = "
    ".$this->app->DB->Select("SELECT name FROM adresse WHERE kundennummer='$kdrnummer' AND firma='".$this->app->User->GetFirma()."' LIMIT 1").""; + $kdrArr = $this->app->DB->SelectRow("SELECT name, email, strasse, ort, plz FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); + $kdr_name = $kdrArr['name']; + $email = $kdrArr['email']; + $parts = explode("\n", wordwrap($kdr_name, 20, "\n")); + $kdr_name = $parts[0]; + $kdr_name = '
    ' . $kdr_name . ''; + $email = '
    ' . $email . ''; + + $kdr_strasse = $kdrArr['strasse']; + $parts = explode("\n", wordwrap($kdr_strasse, 20, "\n")); + $kdr_strasse = $parts[0]; + $kdr_strasse = '
    ' . $kdr_strasse . ''; + + $kdr_plz = '
    ' . $kdrArr['plz'] . ''; + $kdr_ort = '
    ' . $kdrArr['or'] . ''; + } elseif ($checkidemail != '') { + $checked = 'checked'; + $kdrnummer = $checkidemail; + $warenkorb['kundennummer'] = $kdrnummer; + //$kdr_name = "
    ".$this->app->DB->Select("SELECT name FROM adresse WHERE kundennummer='$kdrnummer' AND firma='".$this->app->User->GetFirma()."' LIMIT 1").""; + $kdrArr = $this->app->DB->SelectRow("SELECT name, email, strasse, ort, plz FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); + $kdr_name = $kdrArr['name']; + $email = $kdrArr['email']; + $parts = explode("\n", wordwrap($kdr_name, 20, "\n")); + $kdr_name = $parts[0]; + $kdr_name = '
    ' . $kdr_name . ''; + $email = '
    ' . $email . ''; + + $kdr_strasse = $kdrArr['strasse']; + $parts = explode("\n", wordwrap($kdr_strasse, 40, "\n")); + $kdr_strasse = $parts[0]; + $kdr_strasse = '
    ' . $kdr_strasse . ''; + + $kdr_plz = '
    ' . $kdrArr['plz'] . ''; + $kdr_ort = '
    ' . $kdrArr['ort'] . ''; + } else { + $checked = ''; + $checkid = ''; + $kdrnummer = ''; + $checkidemail = ''; + $kdr_name = ''; + $kdr_strasse = ''; + $kdr_plz = ''; + $kdr_ort = ''; + $email = ''; + } + if ($kdrnummer != '') { + $kdr_addresse_id = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); + } else { + $kdr_addresse_id = ''; + } + + $warenkorb['name'] = $this->app->erp->LimitWord($warenkorb['name'], 20); + $warenkorb['strasse'] = $this->app->erp->LimitWord($warenkorb['strasse'], 20); + + $htmltable->NewRow(); + + $doppelteonlinebestellnummer = false; + if (!empty($warenkorb['onlinebestellnummer'])) { + $check = $this->app->DB->Select("SELECT id from shopimport_auftraege where id <> '" . $arr[$i]['id'] . "' and shopid = '" . $arr[$i]['shopid'] . "' and bestellnummer = '" . $warenkorb['onlinebestellnummer'] . "' and trash = '0' LIMIT 1"); + if ($check) { + $doppelteonlinebestellnummer = true; + $enthaeltdoppeltenummern = true; + } elseif (!empty($checkglobal) && isset($checkglobal[$arr[$i]['shopid']]) && $checkglobal[$arr[$i]['shopid']]) { + $check = $this->app->DB->Select("SELECT id from shopimport_auftraege where id <> '" . $arr[$i]['id'] . "' and (shopid = '" . $arr[$i]['shopid'] . "' OR " . (implode(" OR ", $checkglobal[$arr[$i]['shopid']])) . ") and bestellnummer = '" . $warenkorb['onlinebestellnummer'] . "' and trash = '0' LIMIT 1"); + if ($check) { + $doppelteonlinebestellnummer = true; + $enthaeltdoppeltenummern = true; + } + } + } + + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol($arr[$i]['abkuerzung']); + + $htmltable->AddCol(($doppelteonlinebestellnummer ? '' : '') . $warenkorb['onlinebestellnummer'] . ($doppelteonlinebestellnummer ? '' : '')); + $htmltable->AddCol($warenkorb['name'] . $kdr_name . '
    ' . $warenkorb['email'] . $email); + $htmltable->AddCol($warenkorb['internebezeichnung']); + + $htmltable->AddCol($warenkorb['strasse'] . $kdr_strasse); + $htmltable->AddCol($warenkorb['plz'] . $kdr_plz); + $htmltable->AddCol($warenkorb['ort'] . $kdr_ort); + if ($checkid != '') { + $htmltable->AddCol(''); + } else { + $htmltable->AddCol(''); + } + + $htmltable->AddCol(''); + //$htmltable->AddCol(' '); + $htmltable->AddCol($warenkorb['land']); + $htmltable->AddCol(number_format($warenkorb['gesamtsumme'], 2, ',', '.')); + $saldo_kunde = round($this->app->erp->SaldoAdresse($kdr_addresse_id), 2); + if ($saldo_kunde > 0) { + $saldo_kunde = '' . number_format($saldo_kunde, 2, ',', '.') . ''; + } else { + $saldo_kunde = '-'; + } + $htmltable->AddCol($saldo_kunde); + $htmltable->AddCol($warenkorb['zahlungsweise']); + + $htmltable->AddCol($warenkorb['affiliate_ref']); + //$htmltable->AddCol('Einzelimport verwerfen'); + //$warenkorb[gesamtsumme] = str_replace(".","",$warenkorb[gesamtsumme]); + $gesamtsumme = (isset($gesamtsumme) ? $gesamtsumme : 0) + $warenkorb['gesamtsumme']; + $checkid = ''; + $checkidemail = ''; + $validkundennummer = ''; + //$this->app->Tpl->Add('INHALT',"{$warenkorb[onlinebestellnummer]}{$warenkorb[name]}{$warenkorb[land]}{$warenkorb[gesamtsumme]}"); + } + } else { + if ($deletedRows > 0) { + $msg = $this->app->erp->base64_url_encode('
    Es wurden ' . $deletedRows . ' bereits importierte Datensätze entfernt.
    '); + } else { + $msg = $this->app->erp->base64_url_encode('
    Aktuell sind keine Aufträge in den Online-Shops vorhanden!
    '); + } + $this->app->Location->execute('Location: index.php?module=shopimport&action=list&msg=' . $msg); } - if($warenkorb['kundennummer']!='' && !empty($validkundennummer) && $validkundennummer==$warenkorb['kundennummer']) - { - $kdrnummer = $warenkorb['kundennummer']; - $kdr_name = $this->app->DB->Select("SELECT name FROM adresse WHERE kundennummer='$kdrnummer' $adresseprojekt AND geloescht!=1 LIMIT 1"); - $email = $this->app->DB->Select("SELECT email FROM adresse WHERE kundennummer='$kdrnummer' $adresseprojekt AND geloescht!=1 LIMIT 1"); - $parts= explode("\n", wordwrap($kdr_name, 20, "\n")); - $kdr_name = $parts[0]; - $kdr_name = '
    '.$kdr_name.''; - $email = '
    '.$email.''; - - $kdr_strasse = $this->app->DB->Select("SELECT strasse FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); - $parts= explode("\n", wordwrap($kdr_strasse, 20, "\n")); - $kdr_strasse = $parts[0]; - $kdr_strasse = '
    '.$kdr_strasse.''; - - $kdr_plz = '
    '.$this->app->DB->Select("SELECT plz FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1").''; - $kdr_ort = '
    '.$this->app->DB->Select("SELECT ort FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1").''; - $checked=''; - } - elseif ($checkid!='') - { - $checked='checked'; - $kdrnummer = $checkid; - //$kdr_name = "
    ".$this->app->DB->Select("SELECT name FROM adresse WHERE kundennummer='$kdrnummer' AND firma='".$this->app->User->GetFirma()."' LIMIT 1").""; - $kdrArr = $this->app->DB->SelectRow("SELECT name, email, strasse, ort, plz FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); - $kdr_name = $kdrArr['name']; - $email = $kdrArr['email']; - $parts= explode("\n", wordwrap($kdr_name, 20, "\n")); - $kdr_name = $parts[0]; - $kdr_name = '
    '.$kdr_name.''; - $email = '
    '.$email.''; - - $kdr_strasse = $kdrArr['strasse']; - $parts= explode("\n", wordwrap($kdr_strasse, 20, "\n")); - $kdr_strasse = $parts[0]; - $kdr_strasse = '
    '.$kdr_strasse.''; - - $kdr_plz = '
    '.$kdrArr['plz'].''; - $kdr_ort = '
    '.$kdrArr['or'].''; - - } - elseif ($checkidemail!='') - { - $checked='checked'; - $kdrnummer = $checkidemail; - $warenkorb['kundennummer'] = $kdrnummer; - //$kdr_name = "
    ".$this->app->DB->Select("SELECT name FROM adresse WHERE kundennummer='$kdrnummer' AND firma='".$this->app->User->GetFirma()."' LIMIT 1").""; - $kdrArr = $this->app->DB->SelectRow("SELECT name, email, strasse, ort, plz FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); - $kdr_name = $kdrArr['name']; - $email = $kdrArr['email']; - $parts= explode("\n", wordwrap($kdr_name, 20, "\n")); - $kdr_name = $parts[0]; - $kdr_name = '
    '.$kdr_name.''; - $email = '
    '.$email.''; - - $kdr_strasse = $kdrArr['strasse']; - $parts= explode("\n", wordwrap($kdr_strasse, 40, "\n")); - $kdr_strasse = $parts[0]; - $kdr_strasse = '
    '.$kdr_strasse.''; - - $kdr_plz = '
    '.$kdrArr['plz'].''; - $kdr_ort = '
    '.$kdrArr['ort'].''; - } - - - else { - $checked=''; - $checkid=''; - $kdrnummer=''; - $checkidemail=''; - $kdr_name=''; - $kdr_strasse=''; - $kdr_plz=''; - $kdr_ort=''; - $email=''; - } - if($kdrnummer != ''){ - $kdr_addresse_id = $this->app->DB->Select("SELECT id FROM adresse WHERE kundennummer='$kdrnummer' AND geloescht!=1 $adresseprojekt LIMIT 1"); - } - else { - $kdr_addresse_id = ''; - } - - $warenkorb['name'] = $this->app->erp->LimitWord($warenkorb['name'],20); - $warenkorb['strasse'] = $this->app->erp->LimitWord($warenkorb['strasse'],20); $htmltable->NewRow(); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(''); + $htmltable->AddCol(number_format($gesamtsumme, 2, ',', '.')); + $htmltable->AddCol(''); + $htmltable->AddCol(''); - $doppelteonlinebestellnummer = false; - if(!empty($warenkorb['onlinebestellnummer'])) - { - $check = $this->app->DB->Select("SELECT id from shopimport_auftraege where id <> '".$arr[$i]['id']."' and shopid = '".$arr[$i]['shopid']."' and bestellnummer = '".$warenkorb['onlinebestellnummer']."' and trash = '0' LIMIT 1"); - if($check) - { - $doppelteonlinebestellnummer = true; - $enthaeltdoppeltenummern = true; - }elseif(!empty($checkglobal) && isset($checkglobal[$arr[$i]['shopid']]) && $checkglobal[$arr[$i]['shopid']]) - { - $check = $this->app->DB->Select("SELECT id from shopimport_auftraege where id <> '".$arr[$i]['id']."' and (shopid = '".$arr[$i]['shopid']."' OR ".(implode( " OR ", $checkglobal[$arr[$i]['shopid']])).") and bestellnummer = '".$warenkorb['onlinebestellnummer']."' and trash = '0' LIMIT 1"); - if($check) - { - $doppelteonlinebestellnummer = true; - $enthaeltdoppeltenummern = true; - } - } + if ($enthaeltdoppeltenummern) { + $this->app->Tpl->Add('INHALT', '
    Es wurde ein Auftrag aus einem Shop geholt, der bereits importiert wurde!
    '); } + $this->app->Tpl->Add('INHALT', $htmltable->Get()); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol($arr[$i]['abkuerzung']); - - - $htmltable->AddCol(($doppelteonlinebestellnummer?'':'').$warenkorb['onlinebestellnummer'].($doppelteonlinebestellnummer?'':'')); - $htmltable->AddCol($warenkorb['name'].$kdr_name.'
    '.$warenkorb['email'].$email); - $htmltable->AddCol($warenkorb['internebezeichnung']); - - $htmltable->AddCol($warenkorb['strasse'].$kdr_strasse); - $htmltable->AddCol($warenkorb['plz'].$kdr_plz); - $htmltable->AddCol($warenkorb['ort'].$kdr_ort); - if($checkid!=''){ - $htmltable->AddCol(''); - } - else{ - $htmltable->AddCol(''); - } - - $htmltable->AddCol(''); - //$htmltable->AddCol(' '); - $htmltable->AddCol($warenkorb['land']); - $htmltable->AddCol(number_format($warenkorb['gesamtsumme'],2,',','.')); - $saldo_kunde = round($this->app->erp->SaldoAdresse($kdr_addresse_id),2); - if($saldo_kunde > 0){ - $saldo_kunde = '' . number_format($saldo_kunde, 2, ',','.') . ''; - } - else{ - $saldo_kunde = '-'; - } - $htmltable->AddCol($saldo_kunde); - $htmltable->AddCol($warenkorb['zahlungsweise']); - - - $htmltable->AddCol($warenkorb['affiliate_ref']); - //$htmltable->AddCol('Einzelimport verwerfen'); - //$warenkorb[gesamtsumme] = str_replace(".","",$warenkorb[gesamtsumme]); - $gesamtsumme = (isset($gesamtsumme)?$gesamtsumme:0) + $warenkorb['gesamtsumme']; - $checkid = ''; - $checkidemail = ''; - $validkundennummer = ''; - //$this->app->Tpl->Add('INHALT',"{$warenkorb[onlinebestellnummer]}{$warenkorb[name]}{$warenkorb[land]}{$warenkorb[gesamtsumme]}"); - } - - - } else { - if($deletedRows > 0){ - $msg = $this->app->erp->base64_url_encode('
    Es wurden ' . $deletedRows . ' bereits importierte Datensätze entfernt.
    '); - }else{ - $msg = $this->app->erp->base64_url_encode('
    Aktuell sind keine Aufträge in den Online-Shops vorhanden!
    '); - } - $this->app->Location->execute('Location: index.php?module=shopimport&action=list&msg='.$msg); - } - - - $htmltable->NewRow(); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - $htmltable->AddCol(number_format($gesamtsumme,2,',','.')); - $htmltable->AddCol(''); - $htmltable->AddCol(''); - - if($enthaeltdoppeltenummern) - { - $this->app->Tpl->Add('INHALT','
    Es wurde ein Auftrag aus einem Shop geholt, der bereits importiert wurde!
    '); - } - $this->app->Tpl->Add('INHALT',$htmltable->Get()); - - $this->app->Tpl->Add('INHALT',"

    Bedeutung: