From b35cd5d22d817212bb5853c43f4be4801a32a550 Mon Sep 17 00:00:00 2001 From: Eduard Wisch Date: Mon, 7 Sep 2026 21:28:36 +0200 Subject: [PATCH] Reiter am Kunden nur bei vorhandenen Auftraegen (1.1.1) [deploy] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der Reiter Aufmass stand auf jeder Kundenkarte, auch ohne einen einzigen Auftrag — der Reiter listet Auftraege und fuehrt je Auftrag per Link in die externe Aufmass-PWA, ohne Auftrag ist er also leer. Auf Prod haben 25 von 99 Kunden einen Auftrag. Er erscheint jetzt nur bei Bestand, mit Anzahl. Am AUFTRAG bleibt er unveraendert fest. Als Hook (class/actions_eplan.class.php, completeTabsHead) statt festem Tab, Muster wie bei den anderen Modulen dieser Reihe. ⚠ Nur per Code-Review und SQL-Gegenprobe verifiziert, nicht per Browser- Klick: das lokale Testmodul war nie vollstaendig aktiviert (keine Rechte-Zeilen), und ein Rechte-Nachtrag mitten in der Sitzung greift wegen des Dolibarr-Sitzungs-Caches nicht sofort. Nach dem Deploy einmal an einem Kunden mit Auftrag gegenpruefen. Co-Authored-By: Claude Opus 5 (1M context) --- class/actions_eplan.class.php | 111 ++++++++++++++++++++++++++++++++ core/modules/modEplan.class.php | 8 ++- 2 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 class/actions_eplan.class.php diff --git a/class/actions_eplan.class.php b/class/actions_eplan.class.php new file mode 100644 index 0000000..c5f8045 --- /dev/null +++ b/class/actions_eplan.class.php @@ -0,0 +1,111 @@ +db = $db; + } + + /** + * Hook completeTabsHead: Reiter „Aufmaß" an der Kundenkarte — nur bei + * vorhandenen Aufträgen. + * + * @param array $parameters Hook-Parameter (context, head, mode, filterorigmodule) + * @param CommonObject $object Societe + * @param string $action Aktuelle Aktion + * @param HookManager $hookmanager Hook-Verwaltung + * @return int 0 = weiter + */ + public function completeTabsHead($parameters, &$object, &$action, $hookmanager) + { + global $langs, $user; + + $contexts = explode(':', $parameters['context'] ?? ''); + if (!in_array('thirdpartycard', $contexts, true)) { + return 0; + } + if (empty($object->id) || !isset($parameters['head']) || !is_array($parameters['head'])) { + return 0; + } + if (($parameters['mode'] ?? '') !== 'add' || ($parameters['filterorigmodule'] ?? '') !== 'external') { + return 0; + } + if (!$user->hasRight('eplan', 'read')) { + return 0; + } + + $anzahl = $this->zaehleAuftraege((int) $object->id); + if ($anzahl < 1) { + return 0; + } + + $langs->load('eplan@eplan'); + + $head = &$parameters['head']; + $pos = count($head); + $head[$pos][0] = DOL_URL_ROOT.'/custom/eplan/aufmass_thirdparty.php?socid='.((int) $object->id); + $head[$pos][1] = $langs->trans('Aufmaß').' '.$anzahl.''; + $head[$pos][2] = 'aufmass'; + + return 0; + } + + /** + * Wie viele Aufträge hat dieser Kunde? (Grundlage: der Reiter listet Aufträge, + * kein eigenes Messdaten-Schema.) + * + * @param int $socId Kunde + * @return int Anzahl + */ + private function zaehleAuftraege($socId) + { + if ($socId <= 0) { + return 0; + } + + $sql = "SELECT COUNT(*) AS anzahl FROM ".MAIN_DB_PREFIX."commande"; + $sql .= " WHERE fk_soc = ".((int) $socId); + + $resql = $this->db->query($sql); + if (!$resql) { + return 0; + } + $obj = $this->db->fetch_object($resql); + + return $obj ? (int) $obj->anzahl : 0; + } +} diff --git a/core/modules/modEplan.class.php b/core/modules/modEplan.class.php index ce4c6ba..fc77798 100644 --- a/core/modules/modEplan.class.php +++ b/core/modules/modEplan.class.php @@ -24,14 +24,15 @@ class modEplan extends DolibarrModules $this->editor_name = 'Alles Watt läuft'; $this->editor_url = ''; - $this->version = '1.1.0'; + $this->version = '1.1.1'; $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); $this->picto = 'fa-drafting-compass'; $this->module_parts = array( 'triggers' => 0, 'login' => 0, 'substitutions' => 0, 'menus' => 0, 'tpl' => 0, 'barcode' => 0, 'models' => 0, 'printing' => 0, - 'theme' => 0, 'css' => array(), 'js' => array(), 'hooks' => array(), + 'theme' => 0, 'css' => array(), 'js' => array(), + 'hooks' => array('data' => array('thirdpartycard'), 'entity' => '0'), 'moduleforexternal' => 0, ); @@ -57,7 +58,8 @@ class modEplan extends DolibarrModules // Tabs auf Auftrag + Kundenkarte $this->tabs = array( 'order:+aufmass:Aufmaß:eplan@eplan:$user->hasRight("eplan","read"):/custom/eplan/aufmass_order.php?id=__ID__', - 'thirdparty:+aufmass:Aufmaß:eplan@eplan:$user->hasRight("eplan","read"):/custom/eplan/aufmass_thirdparty.php?socid=__ID__', + // Am KUNDEN setzt den Reiter die Hook-Klasse (nur bei vorhandenen Auftraegen — + // ohne Auftrag gibt es nichts zu vermessen). Der Reiter am AUFTRAG bleibt fest. ); // Rechte