accounting workflows
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/CompanySettingManager.php';
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
|
||||
$csm = new CompanySettingManager($pdo1, $company_id);
|
||||
|
||||
if ($data['action'] === 'read') {
|
||||
$open_from = $csm->get('posting_open_from');
|
||||
if ($open_from === null || $open_from === '') {
|
||||
$open_from = $csm->get('gl_open_from') ?: '';
|
||||
}
|
||||
|
||||
$open_to = $csm->get('posting_open_to');
|
||||
if ($open_to === null || $open_to === '') {
|
||||
$open_to = $csm->get('gl_open_to') ?: '';
|
||||
}
|
||||
|
||||
$answer['output'] = [
|
||||
'open_from' => $open_from ?: '',
|
||||
'open_to' => $open_to ?: '',
|
||||
];
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if ($data['action'] === 'save') {
|
||||
$from = trim((string)($data['open_from'] ?? ''));
|
||||
$to = trim((string)($data['open_to'] ?? ''));
|
||||
|
||||
if ($from !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) {
|
||||
$answer['message'] = 'Invalid open_from date. Use YYYY-MM-DD.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
if ($to !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
|
||||
$answer['message'] = 'Invalid open_to date. Use YYYY-MM-DD.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
if ($from && $to && $from > $to) {
|
||||
$answer['message'] = 'Open From must be on or before Open To.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$csm->set('posting_open_from', $from);
|
||||
$csm->set('posting_open_to', $to);
|
||||
|
||||
$answer['success'] = 1;
|
||||
$answer['message'] = 'Posting window saved.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$answer['message'] = 'Invalid action.';
|
||||
exit(json_encode($answer));
|
||||
Reference in New Issue
Block a user