* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 3. */ /** * \file htdocs/custom/mahnung/class/mahnungcron.class.php * \ingroup mahnung * \brief Cron-Job: Vorschlagsliste ueberfaelliger Rechnungen einsammeln, * Ntfy-Push mit Kennzahl an Eddy. */ require_once DOL_DOCUMENT_ROOT.'/custom/mahnung/class/mahnungvorschlag.class.php'; require_once DOL_DOCUMENT_ROOT.'/custom/mahnung/class/mahnungntfy.class.php'; class MahnungCron { /** @var DoliDB */ public $db; /** @var string */ public $error = ''; /** @var string[] */ public $errors = array(); /** @var string */ public $output = ''; /** @var int|string */ public $lastresult = 0; /** * @param DoliDB $db */ public function __construct($db) { $this->db = $db; } /** * Sucht ueberfaellige Rechnungen, ermittelt Vorschlaege je Stufe, * sendet Ntfy-Push mit Anzahl je Stufe und Gesamtwert. * * @return int 0 bei Erfolg, < 0 bei Fehler */ public function buildVorschlagsliste() { global $conf; $service = new MahnungVorschlag($this->db); $vorschlaege = $service->getVorschlaege(); $count = count($vorschlaege); $counts = array(1 => 0, 2 => 0, 3 => 0); $summe = 0.0; foreach ($vorschlaege as $v) { $stufe = (int) $v['vorgeschlagene_stufe']; if (isset($counts[$stufe])) { $counts[$stufe]++; } $summe += (float) $v['betrag_offen']; } $summe = round($summe, 2); if ($count === 0) { $this->output = 'Keine ueberfaelligen Rechnungen mit faelliger Mahnung.'; $this->lastresult = 0; return 0; } $dolUrl = trim((string) getDolGlobalString('MAIN_INFO_SOCIETE_NOM', '')); $listUrl = self::buildAbsoluteUrl('/custom/mahnung/list.php?mode=vorschlag'); $title = 'Mahnwesen: '.$count.' offene Vorschlaege'; $message = "Stufe 1 (Erinnerung): {$counts[1]}\n"; $message .= "Stufe 2 (Mahnung): {$counts[2]}\n"; $message .= "Stufe 3 (Letzte Mahnung): {$counts[3]}\n"; $message .= 'Offener Betrag: '.number_format($summe, 2, ',', '.').' EUR'; MahnungNtfy::send($title, $message, $listUrl, array('envelope_with_arrow', 'warning')); // Optional: GlobalNotify-Badge ins Dolibarr-UI (wenn Modul aktiv) if (isModEnabled('globalnotify') && class_exists('GlobalNotify') === false) { $gnPath = DOL_DOCUMENT_ROOT.'/custom/globalnotify/class/globalnotify.class.php'; if (file_exists($gnPath)) { require_once $gnPath; } } if (class_exists('GlobalNotify')) { GlobalNotify::actionRequired( 'mahnung', 'Mahnwesen: '.$count.' Vorschlaege', $message, $listUrl, 'Vorschlagsliste oeffnen' ); } $this->output = $title.' — '.$message; $this->lastresult = $count; return 0; } /** * Baut eine absolute URL aus einem relativen Pfad anhand der Dolibarr-URL-Konfig. * * @param string $relPath * @return string */ private static function buildAbsoluteUrl($relPath) { $base = trim((string) getDolGlobalString('DOLIBARR_MAIN_URL_ROOT', '')); if (empty($base) && defined('DOL_MAIN_URL_ROOT')) { $base = DOL_MAIN_URL_ROOT; } if (empty($base)) { return $relPath; } return rtrim($base, '/').$relPath; } }