70 lines
2.4 KiB
PHP
Executable file
70 lines
2.4 KiB
PHP
Executable file
<?php
|
|
define('NOTOKENRENEWAL', 1);
|
|
|
|
$res = 0;
|
|
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
|
|
if (!$res && file_exists("../../../../main.inc.php")) $res = @include "../../../../main.inc.php";
|
|
if (!$res) die("Include of main fails");
|
|
require_once __DIR__.'/../lib/subtotaltitle.lib.php';
|
|
require_once __DIR__.'/../class/DocumentTypeHelper.class.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$textline_id = GETPOST('textline_id', 'int');
|
|
$text = GETPOST('text', 'restricthtml');
|
|
|
|
subtotaltitle_debug_log('edit_textline: id=' . $textline_id);
|
|
|
|
if (!$textline_id || !$text) {
|
|
echo json_encode(array('success' => false, 'error' => 'Missing parameters'));
|
|
exit;
|
|
}
|
|
|
|
// Hole erst document_type und FK zur Detail-Tabelle
|
|
$sql_get = "SELECT document_type, fk_facturedet, fk_propaldet, fk_commandedet FROM ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql_get .= " WHERE rowid = ".(int)$textline_id;
|
|
$sql_get .= " AND line_type = 'text'";
|
|
$resql = $db->query($sql_get);
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
if (!$obj) {
|
|
echo json_encode(array('success' => false, 'error' => 'Textline not found'));
|
|
exit;
|
|
}
|
|
|
|
$docType = $obj->document_type ?: 'invoice';
|
|
$tables = DocumentTypeHelper::getTableNames($docType);
|
|
|
|
// Ermittle FK zur Detail-Tabelle basierend auf Dokumenttyp
|
|
$fk_detail = null;
|
|
if ($docType == 'invoice' && $obj->fk_facturedet > 0) {
|
|
$fk_detail = $obj->fk_facturedet;
|
|
} elseif ($docType == 'propal' && $obj->fk_propaldet > 0) {
|
|
$fk_detail = $obj->fk_propaldet;
|
|
} elseif ($docType == 'order' && $obj->fk_commandedet > 0) {
|
|
$fk_detail = $obj->fk_commandedet;
|
|
}
|
|
|
|
// Update Manager-Tabelle
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql .= " SET title = '".$db->escape($text)."'";
|
|
$sql .= " WHERE rowid = ".(int)$textline_id;
|
|
$sql .= " AND line_type = 'text'";
|
|
|
|
if (!$db->query($sql)) {
|
|
echo json_encode(array('success' => false, 'error' => $db->lasterror()));
|
|
exit;
|
|
}
|
|
|
|
// Falls in Detail-Tabelle vorhanden, dort auch updaten
|
|
if ($fk_detail > 0 && $tables) {
|
|
$sql_fd = "UPDATE ".MAIN_DB_PREFIX.$tables['lines_table'];
|
|
$sql_fd .= " SET description = '".$db->escape($text)."'";
|
|
$sql_fd .= " WHERE rowid = ".(int)$fk_detail;
|
|
$db->query($sql_fd);
|
|
subtotaltitle_debug_log('Textzeile + Detail geaendert (docType='.$docType.')');
|
|
} else {
|
|
subtotaltitle_debug_log('Textzeile geaendert (nicht in Detail-Tabelle)');
|
|
}
|
|
|
|
echo json_encode(array('success' => true, 'synced_detail' => ($fk_detail > 0)));
|