accounting modules
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes_ac/PeriodManager.php';
|
||||
|
||||
$pm = new PeriodManager($pdo2, $company_id);
|
||||
$action = $data['action_type'] ?? '';
|
||||
|
||||
if ($action === 'create_year') {
|
||||
$year = (int)($data['year'] ?? date('Y'));
|
||||
if ($year < 2000 || $year > 2100) exit(json_encode(['message' => 'Invalid year']));
|
||||
$pm->createYear($year);
|
||||
$answer['message'] = "All 12 periods for {$year} created";
|
||||
|
||||
} elseif ($action === 'create_single') {
|
||||
$period = $data['period'] ?? '';
|
||||
if (!preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $period)) {
|
||||
exit(json_encode(['message' => 'Invalid period format (YYYY-MM)']));
|
||||
}
|
||||
$pm->create($period);
|
||||
$answer['message'] = "Period {$period} created";
|
||||
|
||||
} elseif ($action === 'open') {
|
||||
$pm->open((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Period reopened';
|
||||
|
||||
} elseif ($action === 'close') {
|
||||
$pm->close((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Period closed';
|
||||
|
||||
} elseif ($action === 'lock') {
|
||||
$pm->lock((int)($data['id'] ?? 0));
|
||||
$answer['message'] = 'Period locked';
|
||||
|
||||
} else {
|
||||
exit(json_encode(['message' => 'Unknown action']));
|
||||
}
|
||||
|
||||
$answer['success'] = 1;
|
||||
exit(json_encode($answer));
|
||||
Reference in New Issue
Block a user