cronjob lagerzahlen added information

This commit is contained in:
OpenXE 2024-05-24 18:59:43 +02:00
parent 57a9aa23ff
commit 5b9a04031a

View File

@ -1,38 +1,37 @@
<?php
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 (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) || !class_exists('ApplicationCore') || !($app instanceof ApplicationCore)) {
$app = new app_t();
if (empty($app) || !class_exists('ApplicationCore') || !($app instanceof ApplicationCore)) {
$app = new app_t();
}
if(empty($app->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 .= '<br>' . $exception->getMessage();
}
catch (Exception $exception) {
$message .= '<br>' . $exception->getMessage();
if ($message != '') {
$message .= '<br>';
}
if($message!='') {
$message .='<br>';
}
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;
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;
}
$app->erp->LogFile("Lagerzahlen-Synchronisation: Warte 10 Sekunden");
usleep(10000);
}
$app->DB->Update(
}
$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");