mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-26 06:30:29 +01:00
Autoversand_manuell cronjob now able to send orders with delivery date in the future, if selected by user
This commit is contained in:
parent
fc64ced7ea
commit
d9240e184d
@ -59,6 +59,24 @@ if(!defined('FPDF_FONTPATH'))
|
|||||||
|
|
||||||
$cronjobname = 'autoversand_manuell';
|
$cronjobname = 'autoversand_manuell';
|
||||||
|
|
||||||
|
$mutex = $app->DB->Select(
|
||||||
|
"SELECT MAX(`mutex`) FROM `prozessstarter` WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
if($mutex){
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter`
|
||||||
|
SET `mutexcounter`=`mutexcounter`+1
|
||||||
|
WHERE `mutex` = 1 AND (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
|
||||||
|
file_append($debugfile,"MUTEX");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter` SET `mutex`='1', `mutexcounter` = 0 WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
|
||||||
// START APPLICATION
|
// START APPLICATION
|
||||||
|
|
||||||
$objAuftrag = $app->loadModule('auftrag');
|
$objAuftrag = $app->loadModule('auftrag');
|
||||||
@ -71,11 +89,7 @@ $pendingorders = $app->DB->SelectArr(
|
|||||||
"SELECT id
|
"SELECT id
|
||||||
FROM auftrag AS a
|
FROM auftrag AS a
|
||||||
WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='')
|
WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='')
|
||||||
AND a.status='freigegeben' AND a.autoversand='1' AND a.cronjobkommissionierung > 0
|
AND a.status='freigegeben' AND a.cronjobkommissionierung > 0"
|
||||||
AND a.inbearbeitung=0 AND a.nachlieferung!='1' AND a.vorkasse_ok='1'
|
|
||||||
AND a.porto_ok='1' AND a.lager_ok='1' AND a.check_ok='1' AND a.ust_ok='1'
|
|
||||||
AND a.liefertermin_ok='1' AND kreditlimit_ok='1' AND liefersperre_ok='1'
|
|
||||||
"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!is_null($pendingorders)) {
|
if (!is_null($pendingorders)) {
|
||||||
@ -84,7 +98,7 @@ if (!is_null($pendingorders)) {
|
|||||||
foreach ($pendingorders as $pendingorder) {
|
foreach ($pendingorders as $pendingorder) {
|
||||||
/* Process each order */
|
/* Process each order */
|
||||||
|
|
||||||
if($objAuftrag->AuftragVersand($pendingorder['id'])) {
|
if($objAuftrag->AuftragVersand($pendingorder['id'],true)) { // Ignore shipdate -> The order has been marked, send it
|
||||||
$processed_orders_num++;
|
$processed_orders_num++;
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
212
cronjobs/tickets.php
Normal file
212
cronjobs/tickets.php
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fetch all mails for accounts with ticket function
|
||||||
|
* Create tickets or sort mails to existing tickets
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Xentral\Components\Logger\Logger;
|
||||||
|
use Xentral\Components\MailClient\MailClientFactory;
|
||||||
|
use Xentral\Modules\SystemMailClient\MailClientConfigProvider;
|
||||||
|
use Xentral\Modules\SystemMailer\Service\EmailAccountGateway;
|
||||||
|
use Xentral\Modules\Ticket\Importer\TicketFormatter;
|
||||||
|
use Xentral\Modules\Ticket\Task\TicketImportHelperFactory;
|
||||||
|
|
||||||
|
$DEBUG = 0;
|
||||||
|
|
||||||
|
|
||||||
|
$debugfile = "/var/www/html/Xenomporio/debug.txt";
|
||||||
|
|
||||||
|
function file_append($filename,$text) {
|
||||||
|
$oldtext = file_get_contents($filename);
|
||||||
|
file_put_contents($filename,$oldtext.$text);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($debugfile,"0");
|
||||||
|
|
||||||
|
/** @var ApplicationCore $app */
|
||||||
|
|
||||||
|
$erp = $app->erp;
|
||||||
|
$conf = $app->Conf;
|
||||||
|
|
||||||
|
/** @var Logger $logger */
|
||||||
|
$logger = $app->Container->get('Logger');
|
||||||
|
|
||||||
|
$cronjobname = 'tickets';
|
||||||
|
/*
|
||||||
|
$mutex = $app->DB->Select(
|
||||||
|
"SELECT MAX(`mutex`) FROM `prozessstarter` WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
if($mutex){
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter`
|
||||||
|
SET `mutexcounter`=`mutexcounter`+1
|
||||||
|
WHERE `mutex` = 1 AND (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
|
||||||
|
file_append($debugfile,"MUTEX");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter` SET `mutex`='1', `mutexcounter` = 0 WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// get all email Accounts that have the ticket system active
|
||||||
|
/** @var EmailAccountGateway $accountGateway */
|
||||||
|
$accountGateway = $app->Container->get('EmailAccountGateway');
|
||||||
|
$accounts = $accountGateway->getAccountsWithTicketActive();
|
||||||
|
|
||||||
|
file_append($debugfile,"Accs:".count($accounts).";");
|
||||||
|
|
||||||
|
|
||||||
|
// only load services if there is at least one account to import (performance)
|
||||||
|
$ticketModule = null;
|
||||||
|
$factory = null;
|
||||||
|
$configProvider = null;
|
||||||
|
$formatHelper = null;
|
||||||
|
$importHelperFactory = null;
|
||||||
|
if(!empty($accounts)){
|
||||||
|
/** @var Ticket $ticketModule */
|
||||||
|
$ticketModule = $app->erp->LoadModul('ticket');
|
||||||
|
/** @var MailClientFactory $factory */
|
||||||
|
$factory = $app->Container->get('MailClientFactory');
|
||||||
|
/** @var MailClientConfigProvider $configProvider */
|
||||||
|
$configProvider = $app->Container->get('MailClientConfigProvider');
|
||||||
|
/** @var TicketFormatter $formatHelper */
|
||||||
|
$formatHelper = $app->Container->get('TicketFormatter');
|
||||||
|
/** @var TicketImportHelperFactory $importHelperFactory */
|
||||||
|
$importHelperFactory = $app->Container->get('TicketImportHelperFactory');
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalEmailsImportCount = 0;
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$logger->debug(
|
||||||
|
'Start imap ticket import for {email}',
|
||||||
|
['email' => $account->getEmailAddress(), 'account' => $account]
|
||||||
|
);
|
||||||
|
|
||||||
|
file_append($debugfile,"Account ".$account->getemailAddress());
|
||||||
|
|
||||||
|
// create mail client
|
||||||
|
try {
|
||||||
|
$mailConfig = $configProvider->createImapConfigFromAccount($account);
|
||||||
|
$mailClient = $factory->createImapClient($mailConfig);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$logger->error('Failed to create email client', ['error' => (string)$e, 'account' => $account]);
|
||||||
|
|
||||||
|
file_append($debugfile,"Failed 1");
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_append($debugfile,"Connect to ".."SSL: ".$configProvider->isSslEnabled()." auth ".getAuthType()."\n");
|
||||||
|
|
||||||
|
// connect mail client
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
$mailClient->connect();
|
||||||
|
|
||||||
|
file_append($debugfile,"Meh");
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$logger->error('Error during imap connection', ['error' => (string)$e, 'account' => $account]);
|
||||||
|
|
||||||
|
file_append($debugfile,"Error ".(string)$e);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_append($debugfile,"2");
|
||||||
|
|
||||||
|
// connet to INBOX folder
|
||||||
|
try {
|
||||||
|
$mailClient->selectFolder('INBOX');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$logger->error('Failed to select INBOX folder', ['error' => (string)$e, 'account' => $account]);
|
||||||
|
|
||||||
|
|
||||||
|
file_append($debugfile,"Failed 2");
|
||||||
|
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$projectId = $account->getProjectId() > 0 ? $account->getProjectId() : 1;
|
||||||
|
$delete_msg = 0;
|
||||||
|
$daysold = $account->getBackupDeleteAfterDays();
|
||||||
|
|
||||||
|
// determine search criteria for new messages
|
||||||
|
$datet = '2012-12-24';
|
||||||
|
if ($account->getImportStartDateAsString() !== '0000-00-00') {
|
||||||
|
$datesince = date('d-M-Y', strtotime($account->getImportStartDateAsString()));
|
||||||
|
$criteria = 'UNSEEN SINCE ' . $datesince;
|
||||||
|
} else {
|
||||||
|
$criteria = 'UNSEEN';
|
||||||
|
}
|
||||||
|
|
||||||
|
file_append($debugfile,"3");
|
||||||
|
|
||||||
|
// search new messages
|
||||||
|
try {
|
||||||
|
$searchResult = $mailClient->searchMessages($criteria);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$logger->error('Error during imap search', ['exception' => $e]);
|
||||||
|
|
||||||
|
file_append($debugfile,"Failed 3");
|
||||||
|
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$logger->debug('unread emails to import: {message_count}', ['message_count' => count($searchResult)]);
|
||||||
|
|
||||||
|
// set mutex if there is more than 5 emails to import
|
||||||
|
if (count($searchResult) > 5) {
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter`
|
||||||
|
SET `mutex`=1, `mutexcounter` = 0, `letzteausfuerhung` = NOW()
|
||||||
|
WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$importer = $importHelperFactory->create($mailClient, $account, $projectId);
|
||||||
|
$insertedMailsCount = $importer->importMessages($searchResult);
|
||||||
|
$totalEmailsImportCount += $insertedMailsCount;
|
||||||
|
|
||||||
|
// set mutex if the total amount of imported emails is more than 10
|
||||||
|
if ($totalEmailsImportCount > 10) {
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter`
|
||||||
|
SET `mutex`=1, `mutexcounter` = 0, `letzteausfuerhung` = NOW()
|
||||||
|
WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mailClient->expunge();
|
||||||
|
$mailClient->disconnect();
|
||||||
|
|
||||||
|
if (
|
||||||
|
method_exists($app->erp, 'canRunCronjob')
|
||||||
|
&& !$app->erp->canRunCronjob(['supportmails', 'tickets'])
|
||||||
|
) {
|
||||||
|
|
||||||
|
$logger->error('Tickets error');
|
||||||
|
|
||||||
|
file_append($debugfile,"Failed 5");
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter`
|
||||||
|
SET `mutex`=1, `mutexcounter` = 0, `letzteausfuerhung` = NOW()
|
||||||
|
WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$app->DB->Update(
|
||||||
|
"UPDATE `prozessstarter` SET `mutex`=0,`mutexcounter`=0 WHERE (`parameter` = '".$cronjobname."')"
|
||||||
|
);
|
||||||
|
|
||||||
|
file_append($debugfile,"END");
|
@ -695,7 +695,7 @@ class Auftrag extends GenAuftrag
|
|||||||
FROM
|
FROM
|
||||||
auftrag a";
|
auftrag a";
|
||||||
|
|
||||||
$status_where = 'a.cronjobkommissionierung > 0 AND a.lager_ok=1 AND a.porto_ok=1 AND a.ust_ok=1 AND a.vorkasse_ok=1 AND a.nachnahme_ok=1 AND a.autoversand=1 AND a.check_ok=1 AND a.kreditlimit_ok=1 AND a.liefersperre_ok=1'; // liefertermin_ok special treatment
|
$status_where = 'a.cronjobkommissionierung > 0';
|
||||||
|
|
||||||
$where = "a.status = 'freigegeben' AND ".$status_where;
|
$where = "a.status = 'freigegeben' AND ".$status_where;
|
||||||
// $groupby = "";
|
// $groupby = "";
|
||||||
@ -6439,8 +6439,7 @@ Die Gesamtsumme stimmt nicht mehr mit ursprünglich festgelegten Betrag '.
|
|||||||
$unversendet = $this->app->DB->Select("SELECT count(a.id) FROM auftrag as a LEFT JOIN projekt p ON p.id=a.projekt WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='') AND a.status='freigegeben' AND a.inbearbeitung=0 AND a.nachlieferung!='1' AND a.autoversand='1' AND a.cronjobkommissionierung = 0 AND a.liefertermin_ok='1' AND kreditlimit_ok='1' AND liefersperre_ok='1'
|
$unversendet = $this->app->DB->Select("SELECT count(a.id) FROM auftrag as a LEFT JOIN projekt p ON p.id=a.projekt WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='') AND a.status='freigegeben' AND a.inbearbeitung=0 AND a.nachlieferung!='1' AND a.autoversand='1' AND a.cronjobkommissionierung = 0 AND a.liefertermin_ok='1' AND kreditlimit_ok='1' AND liefersperre_ok='1'
|
||||||
AND a.vorkasse_ok='1' AND a.porto_ok='1' AND a.lager_ok='1' AND a.check_ok='1' AND a.ust_ok='1' " . $this->app->erp->ProjektRechte('p.id', true, 'a.vertriebid'));
|
AND a.vorkasse_ok='1' AND a.porto_ok='1' AND a.lager_ok='1' AND a.check_ok='1' AND a.ust_ok='1' " . $this->app->erp->ProjektRechte('p.id', true, 'a.vertriebid'));
|
||||||
|
|
||||||
$warteschleife = $this->app->DB->Select("SELECT count(a.id) FROM auftrag as a LEFT JOIN projekt p ON p.id=a.projekt WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='') AND a.status='freigegeben' AND a.inbearbeitung=0 AND a.nachlieferung!='1' AND a.autoversand='1' AND a.liefertermin_ok='1' AND kreditlimit_ok='1' AND liefersperre_ok='1'
|
$warteschleife = $this->app->DB->Select("SELECT count(a.id) FROM auftrag as a LEFT JOIN projekt p ON p.id=a.projekt WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='') AND a.status='freigegeben' AND a.cronjobkommissionierung > 0 " . $this->app->erp->ProjektRechte('p.id', true, "a.vertriebid"));
|
||||||
AND a.vorkasse_ok='1' AND a.porto_ok='1' AND a.lager_ok='1' AND a.check_ok='1' AND a.ust_ok='1' AND a.cronjobkommissionierung > 0 " . $this->app->erp->ProjektRechte('p.id', true, "a.vertriebid"));
|
|
||||||
|
|
||||||
if($unversendet > 0) {
|
if($unversendet > 0) {
|
||||||
$unversendet ='('.$unversendet.')';
|
$unversendet ='('.$unversendet.')';
|
||||||
|
Loading…
Reference in New Issue
Block a user