179 lines
4.6 KiB
PHP
179 lines
4.6 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* \file subtotaltitle/class/DocumentTypeHelper.class.php
|
|
* \ingroup subtotaltitle
|
|
* \brief Helper class für verschiedene Dokumenttypen (Rechnung, Angebot, Auftrag)
|
|
*/
|
|
|
|
/**
|
|
* Class DocumentTypeHelper
|
|
* Hilfsklasse um mit verschiedenen Dokumenttypen zu arbeiten
|
|
*/
|
|
class DocumentTypeHelper
|
|
{
|
|
/**
|
|
* Erkennt den Dokumenttyp aus dem Context
|
|
*
|
|
* @param string $context Hook-Context (z.B. 'invoicecard', 'propalcard', 'ordercard')
|
|
* @return string|null Dokumenttyp ('invoice', 'propal', 'order') oder null
|
|
*/
|
|
public static function getTypeFromContext($context)
|
|
{
|
|
if (strpos($context, 'invoicecard') !== false) {
|
|
return 'invoice';
|
|
}
|
|
if (strpos($context, 'propalcard') !== false) {
|
|
return 'propal';
|
|
}
|
|
if (strpos($context, 'ordercard') !== false) {
|
|
return 'order';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Holt den Dokumenttyp aus dem Object
|
|
*
|
|
* @param object $object Dolibarr Objekt
|
|
* @return string|null Dokumenttyp ('invoice', 'propal', 'order') oder null
|
|
*/
|
|
public static function getTypeFromObject($object)
|
|
{
|
|
if (!is_object($object) || !isset($object->element)) {
|
|
return null;
|
|
}
|
|
|
|
if ($object->element == 'facture') {
|
|
return 'invoice';
|
|
}
|
|
if ($object->element == 'propal') {
|
|
return 'propal';
|
|
}
|
|
if ($object->element == 'commande') {
|
|
return 'order';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Holt die Tabellennamen für einen Dokumenttyp
|
|
*
|
|
* @param string $type Dokumenttyp ('invoice', 'propal', 'order')
|
|
* @return array Array mit Tabellennamen (parent_table, lines_table, fk_parent, fk_line)
|
|
*/
|
|
public static function getTableNames($type)
|
|
{
|
|
$tables = array(
|
|
'invoice' => array(
|
|
'parent_table' => 'facture',
|
|
'lines_table' => 'facturedet',
|
|
'fk_parent' => 'fk_facture',
|
|
'fk_line' => 'fk_facturedet',
|
|
'element' => 'facture'
|
|
),
|
|
'propal' => array(
|
|
'parent_table' => 'propal',
|
|
'lines_table' => 'propaldet',
|
|
'fk_parent' => 'fk_propal',
|
|
'fk_line' => 'fk_propaldet',
|
|
'element' => 'propal'
|
|
),
|
|
'order' => array(
|
|
'parent_table' => 'commande',
|
|
'lines_table' => 'commandedet',
|
|
'fk_parent' => 'fk_commande',
|
|
'fk_line' => 'fk_commandedet',
|
|
'element' => 'commande'
|
|
)
|
|
);
|
|
|
|
return isset($tables[$type]) ? $tables[$type] : null;
|
|
}
|
|
|
|
/**
|
|
* Holt die Hook-Contexts für einen Dokumenttyp
|
|
*
|
|
* @param string $type Dokumenttyp ('invoice', 'propal', 'order')
|
|
* @return string Hook-Context
|
|
*/
|
|
public static function getContext($type)
|
|
{
|
|
$contexts = array(
|
|
'invoice' => 'invoicecard',
|
|
'propal' => 'propalcard',
|
|
'order' => 'ordercard'
|
|
);
|
|
|
|
return isset($contexts[$type]) ? $contexts[$type] : '';
|
|
}
|
|
|
|
/**
|
|
* Laedt ein Dokument basierend auf Typ und ID
|
|
*
|
|
* @param string $type Dokumenttyp ('invoice', 'propal', 'order')
|
|
* @param int $id Dokument-ID
|
|
* @param DoliDB $db Datenbankverbindung
|
|
* @return object|null Dolibarr Objekt oder null
|
|
*/
|
|
public static function loadDocument($type, $id, $db)
|
|
{
|
|
$object = null;
|
|
|
|
if ($type == 'invoice') {
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
|
$object = new Facture($db);
|
|
} elseif ($type == 'propal') {
|
|
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
|
$object = new Propal($db);
|
|
} elseif ($type == 'order') {
|
|
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
|
|
$object = new Commande($db);
|
|
}
|
|
|
|
if ($object && $object->fetch($id) > 0) {
|
|
return $object;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Prueft ob ein Dokument im Entwurfsstatus ist
|
|
*
|
|
* @param object $object Dolibarr Objekt
|
|
* @param string $type Dokumenttyp ('invoice', 'propal', 'order')
|
|
* @return bool true wenn Entwurf, sonst false
|
|
*/
|
|
public static function isDraft($object, $type)
|
|
{
|
|
if (!$object) {
|
|
return false;
|
|
}
|
|
|
|
// Verschiedene Dokumenttypen haben unterschiedliche Status-Felder
|
|
if (isset($object->statut)) {
|
|
return ($object->statut == 0);
|
|
}
|
|
if (isset($object->status)) {
|
|
return ($object->status == 0);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|