Dokumenttikansiot asiakaskohtaisiksi
- Lisää customer_id sarake document_folders-tauluun (ALTER TABLE migraatio) - dbLoadFolders() tukee nyt customer_id suodatusta - dbSaveFolder() tallentaa customer_id:n kansioon - API document_folders endpoint vastaanottaa customer_id parametrin - JS: kansiot ladataan ja luodaan asiakaskohtaisesti (currentDocCustomerId) - Jokaisen asiakkaan kansiorakenne on nyt itsenäinen Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
3
api.php
3
api.php
@@ -4287,7 +4287,8 @@ switch ($action) {
|
||||
case 'document_folders':
|
||||
requireAuth();
|
||||
$companyId = requireCompany();
|
||||
echo json_encode(dbLoadFolders($companyId));
|
||||
$customerId = $_GET['customer_id'] ?? null;
|
||||
echo json_encode(dbLoadFolders($companyId, $customerId));
|
||||
break;
|
||||
|
||||
case 'document_folder_save':
|
||||
|
||||
11
db.php
11
db.php
@@ -615,6 +615,7 @@ function initDatabase(): void {
|
||||
"ALTER TABLE documents ADD COLUMN max_versions INT DEFAULT 10 AFTER current_version",
|
||||
"ALTER TABLE document_versions ADD COLUMN content MEDIUMTEXT DEFAULT NULL AFTER mime_type",
|
||||
"ALTER TABLE devices ADD COLUMN laitetila_id VARCHAR(20) DEFAULT NULL AFTER site_id",
|
||||
"ALTER TABLE document_folders ADD COLUMN customer_id VARCHAR(20) DEFAULT NULL AFTER company_id",
|
||||
];
|
||||
foreach ($alters as $sql) {
|
||||
try { $db->query($sql); } catch (\Throwable $e) { /* sarake on jo olemassa / jo ajettu */ }
|
||||
@@ -1749,7 +1750,10 @@ function dbDeleteTodoSubtask(string $subtaskId): void {
|
||||
|
||||
// ==================== DOKUMENTTIKANSIOT ====================
|
||||
|
||||
function dbLoadFolders(string $companyId): array {
|
||||
function dbLoadFolders(string $companyId, ?string $customerId = null): array {
|
||||
if ($customerId) {
|
||||
return _dbFetchAll("SELECT * FROM document_folders WHERE company_id = ? AND customer_id = ? ORDER BY name", [$companyId, $customerId]);
|
||||
}
|
||||
return _dbFetchAll("SELECT * FROM document_folders WHERE company_id = ? ORDER BY name", [$companyId]);
|
||||
}
|
||||
|
||||
@@ -1757,12 +1761,13 @@ function dbSaveFolder(string $companyId, array $folder): string {
|
||||
$id = $folder['id'] ?? generateId();
|
||||
$now = date('Y-m-d H:i:s');
|
||||
_dbExecute("
|
||||
INSERT INTO document_folders (id, company_id, name, parent_id, created_by, luotu)
|
||||
VALUES (:id, :companyId, :name, :parentId, :createdBy, :luotu)
|
||||
INSERT INTO document_folders (id, company_id, customer_id, name, parent_id, created_by, luotu)
|
||||
VALUES (:id, :companyId, :customerId, :name, :parentId, :createdBy, :luotu)
|
||||
ON DUPLICATE KEY UPDATE name = VALUES(name), parent_id = VALUES(parent_id)
|
||||
", [
|
||||
'id' => $id,
|
||||
'companyId' => $companyId,
|
||||
'customerId' => !empty($folder['customer_id']) ? $folder['customer_id'] : null,
|
||||
'name' => $folder['name'] ?? '',
|
||||
'parentId' => !empty($folder['parent_id']) ? $folder['parent_id'] : null,
|
||||
'createdBy' => $folder['created_by'] ?? '',
|
||||
|
||||
@@ -4877,13 +4877,13 @@ function showDocEditView() {
|
||||
async function loadDocuments() {
|
||||
try {
|
||||
allDocuments = await apiCall('documents');
|
||||
try { allDocFolders = await apiCall('document_folders'); } catch (e2) { allDocFolders = []; }
|
||||
// Lataa kansiot asiakaskohtaisesti
|
||||
if (currentDocCustomerId) {
|
||||
// Ollaan asiakkaan kansion sisällä → näytä dokumenttilista
|
||||
try { allDocFolders = await apiCall('document_folders&customer_id=' + currentDocCustomerId); } catch (e2) { allDocFolders = []; }
|
||||
renderDocFolderBar();
|
||||
renderDocumentsList();
|
||||
} else {
|
||||
// Näytä asiakaskansiot
|
||||
allDocFolders = [];
|
||||
renderDocCustomerFolders();
|
||||
}
|
||||
} catch (e) { console.error('Dokumenttien lataus epäonnistui:', e); }
|
||||
@@ -5341,7 +5341,8 @@ document.getElementById('btn-new-folder')?.addEventListener('click', async () =>
|
||||
try {
|
||||
await apiCall('document_folder_save', 'POST', {
|
||||
name: name.trim(),
|
||||
parent_id: currentDocFolderId || null
|
||||
parent_id: currentDocFolderId || null,
|
||||
customer_id: currentDocCustomerId || null
|
||||
});
|
||||
await loadDocuments();
|
||||
} catch (e) { alert('Kansion luonti epäonnistui: ' + e.message); }
|
||||
|
||||
Reference in New Issue
Block a user