document number sequence
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../../../assets/utils/db_auth.php';
|
||||
require_once '../../../assets/utils/classes/DocumentNumberManager.php';
|
||||
|
||||
$mgr = new DocumentNumberManager($pdo2, $company_id);
|
||||
$action = $data['action'] ?? '';
|
||||
|
||||
try {
|
||||
switch ($action) {
|
||||
|
||||
case 'list':
|
||||
$answer['data'] = $mgr->getAllConfigs();
|
||||
$answer['success'] = 1;
|
||||
break;
|
||||
|
||||
case 'options':
|
||||
$key = trim((string)($data['doc_type_key'] ?? ''));
|
||||
if ($key === '') throw new Exception('doc_type_key is required.');
|
||||
$answer['data'] = $mgr->getConfigsForType($key);
|
||||
$answer['success'] = 1;
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
$id = isset($data['id']) && (int)$data['id'] > 0 ? (int)$data['id'] : null;
|
||||
$new_id = $mgr->saveConfig($data, $id);
|
||||
$answer['id'] = $new_id;
|
||||
$answer['message'] = $id ? 'Configuration updated.' : 'Configuration saved.';
|
||||
$answer['success'] = 1;
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
$mgr->deleteConfig((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Configuration deleted.';
|
||||
$answer['success'] = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
$answer['message'] = 'Unknown action.';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
Reference in New Issue
Block a user