Add Asset Management app
Assets from purchase invoice lines, straight-line depreciation/amortization with salvage value, disposals, and [Asset Mgmt] sources in Batch GL Entries. Green third workspace with an app access guard.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../../../assets/utils/db_auth.php';
|
||||
require_app_access('asset');
|
||||
require_once '../../../assets/utils/classes/UsageGuard.php';
|
||||
require_once '../../../assets/utils/classes_ac/PostingWindowGuard.php';
|
||||
require_once '../../../assets/utils/classes_ac/GlManager.php';
|
||||
require_once '../../../assets/utils/classes_as/AssetRunManager.php';
|
||||
|
||||
$action = (string)($data['action'] ?? 'list');
|
||||
$class = trim((string)($data['asset_class'] ?? ''));
|
||||
$through = trim((string)($data['through_period'] ?? ''));
|
||||
$run_id = (int)($data['run_id'] ?? 0);
|
||||
|
||||
if (in_array($action, ['run', 'void'], true)) {
|
||||
require_role($user_role, ['owner', 'admin']);
|
||||
}
|
||||
|
||||
try {
|
||||
$runs = new AssetRunManager($pdo2, $company_id);
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
$answer['output'] = $runs->getList($class);
|
||||
break;
|
||||
|
||||
case 'preview':
|
||||
$answer['output'] = $runs->preview($class, $through);
|
||||
break;
|
||||
|
||||
case 'detail':
|
||||
$answer['output'] = $runs->getDetail($run_id);
|
||||
break;
|
||||
|
||||
case 'run':
|
||||
$created = dbTransaction($pdo2, fn($pdo) => (new AssetRunManager($pdo, $company_id))->run($class, $through, $user_id));
|
||||
(new UsageGuard($pdo1, $company_id, $packages))->increment();
|
||||
$answer['output'] = $created;
|
||||
$answer['message'] = count($created) . ' run(s) created. Accounting posts them from Batch GL Entries.';
|
||||
break;
|
||||
|
||||
case 'void':
|
||||
dbTransaction($pdo2, function ($pdo) use ($company_id, $run_id, $pdo1) {
|
||||
$gl = new GlManager($pdo, $company_id, new PostingWindowGuard($pdo1, $company_id));
|
||||
(new AssetRunManager($pdo, $company_id))->void($run_id, $gl);
|
||||
});
|
||||
$answer['message'] = 'Run voided.';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('Invalid action.');
|
||||
}
|
||||
|
||||
$answer['success'] = 1;
|
||||
} catch (PDOException $e) {
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
} catch (Exception $e) {
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
Reference in New Issue
Block a user