cronjobs/shop_rueckmeldungen.php format

This commit is contained in:
OpenXE 2024-07-02 13:54:50 +02:00
parent 4ed783a7ca
commit ea515b0727

View File

@ -1,89 +1,86 @@
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if(!class_exists('ApplicationCore') && is_file(dirname(__DIR__).'/xentral_autoloader.php')) {
include_once dirname(__DIR__).'/xentral_autoloader.php';
if (!class_exists('ApplicationCore') && is_file(dirname(__DIR__) . '/xentral_autoloader.php')) {
include_once dirname(__DIR__) . '/xentral_autoloader.php';
}
include_once dirname(__DIR__).'/conf/main.conf.php';
include_once dirname(__DIR__).'/phpwf/plugins/class.mysql.php';
include_once dirname(__DIR__).'/phpwf/plugins/class.secure.php';
include_once dirname(__DIR__).'/phpwf/plugins/class.user.php';
if(file_exists(dirname(__DIR__).'/conf/user_defined.php')) {
include_once dirname(__DIR__).'/conf/user_defined.php';
include_once dirname(__DIR__) . '/conf/main.conf.php';
include_once dirname(__DIR__) . '/phpwf/plugins/class.mysql.php';
include_once dirname(__DIR__) . '/phpwf/plugins/class.secure.php';
include_once dirname(__DIR__) . '/phpwf/plugins/class.user.php';
if (file_exists(dirname(__DIR__) . '/conf/user_defined.php')) {
include_once dirname(__DIR__) . '/conf/user_defined.php';
}
if(!class_exists('FPDFWAWISION')){
if(file_exists(dirname(__DIR__).'/conf/user_defined.php')){
if (!class_exists('FPDFWAWISION')) {
if (file_exists(dirname(__DIR__) . '/conf/user_defined.php')) {
include_once dirname(__DIR__) . '/conf/user_defined.php';
}
if(defined('USEFPDF3') && USEFPDF3 && file_exists(dirname(__DIR__) . '/www/lib/pdf/fpdf_3.php')){
if (defined('USEFPDF3') && USEFPDF3 && file_exists(dirname(__DIR__) . '/www/lib/pdf/fpdf_3.php')) {
require_once dirname(__DIR__) . '/www/lib/pdf/fpdf_3.php';
}else if(defined('USEFPDF2') && USEFPDF2 && file_exists(dirname(__DIR__) . '/www/lib/pdf/fpdf_2.php')){
} else if (defined('USEFPDF2') && USEFPDF2 && file_exists(dirname(__DIR__) . '/www/lib/pdf/fpdf_2.php')) {
require_once dirname(__DIR__) . '/www/lib/pdf/fpdf_2.php';
}else{
} else {
require_once dirname(__DIR__) . '/www/lib/pdf/fpdf.php';
}
}
include_once dirname(__DIR__).'/www/lib/pdf/fpdf_final.php';
include_once dirname(__DIR__).'/www/lib/imap.inc.php';
include_once dirname(__DIR__).'/www/lib/class.erpapi.php';
include_once dirname(__DIR__).'/www/lib/class.remote.php';
include_once dirname(__DIR__).'/www/lib/class.httpclient.php';
include_once dirname(__DIR__) . '/www/lib/pdf/fpdf_final.php';
include_once dirname(__DIR__) . '/www/lib/imap.inc.php';
include_once dirname(__DIR__) . '/www/lib/class.erpapi.php';
include_once dirname(__DIR__) . '/www/lib/class.remote.php';
include_once dirname(__DIR__) . '/www/lib/class.httpclient.php';
$aes = '';
$phpversion = (String)phpversion();
if($phpversion[0] == '7' && (int)$phpversion[2] > 0) {
$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{
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'))
{
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)
{
function GetLandLang($isocode) {
$flipped = array_flip($this->GetLaender());
if(isset($flipped[$isocode]))
if (isset($flipped[$isocode]))
$land = $flipped[$isocode];
else {
$land = 'unkown';
}
return $land;
}
}
function GetLaender()
{
function GetLaender() {
$laender = array(
'Afghanistan' => 'AF',
'&Auml;gypten' => 'EG',
@ -329,65 +326,64 @@ function GetLaender()
'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')){
}
$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{
} 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(
$shops = $app->DB->SelectFirstCols(
'SELECT id FROM shopexport WHERE auftragabgleich = 1 AND aktiv = 1 AND demomodus <> 1 AND sendonlywithtracking = 0'
);
if(empty($shops)) {
);
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);
$sql = "SELECT a.id,apro.zeit, a.shop, l.id as lieferschein, v.id as versandid, l.projekt
$subwhere = sprintf(' a.shop IN (%s) ', implode(',', $shops));
$join = '';
$where = '';
$app->erp->RunHook('shop_rueckmeldung', 2, $join, $where);
$sql = "SELECT a.id,apro.zeit, a.shop, l.id as lieferschein, v.id as versandid, l.projekt
FROM auftrag AS a
LEFT JOIN lieferschein AS l on l.auftragid = a.id
LEFT JOIN auftrag_protokoll AS apro ON a.id = apro.auftrag AND apro.grund LIKE 'Auftrag importiert vom Shop'
@ -403,13 +399,13 @@ 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
";
$auftraege = $app->DB->SelectArr($sql);
if(!empty($auftraege)) {
$auftraege = $app->DB->SelectArr($sql);
if (!empty($auftraege)) {
$app->DB->Update(
"UPDATE prozessstarter
SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now()
@ -417,12 +413,12 @@ function GetLaender()
);
$auftragid = null;
$countRequests = 0;
foreach($auftraege as $auftrag) {
if($auftrag['id'] != $auftragid) {
foreach ($auftraege as $auftrag) {
if ($auftrag['id'] != $auftragid) {
$countRequests++;
$auftragid = $auftrag['id'];
$app->remote->RemoteUpdateAuftrag($auftrag['shop'], $auftrag['id']);
if($countRequests % 10 === 0) {
if ($countRequests % 10 === 0) {
$app->DB->Update(
"UPDATE prozessstarter
SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now()
@ -432,11 +428,11 @@ function GetLaender()
}
}
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(
//Zahlungsstatus
$query = $app->DB->Query(
"SELECT a.id
FROM `auftrag` AS `a`
LEFT JOIN `rechnung` AS `r1` ON r1.id = a.rechnungid
@ -448,13 +444,13 @@ 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)) {
while ($row = $app->DB->Fetch_Assoc($query)) {
$app->erp->ImportUpdateZahlungsstatus($row['id']);
$countRequests++;
if($countRequests % 10 === 0) {
if ($countRequests % 10 === 0) {
$app->DB->Update(
"UPDATE prozessstarter
SET mutex = 1 , mutexcounter = 0, letzteausfuerhung = now()
@ -463,6 +459,7 @@ function GetLaender()
}
}
$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");