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