Added Wizard for Month/Year End Close
This commit is contained in:
@@ -5,6 +5,13 @@ const { hydrateAsset } = require('./assets');
|
||||
|
||||
const DISPOSAL_METHODS = ['sale', 'exchange', 'involuntary_conversion', 'like_kind', 'abandonment'];
|
||||
|
||||
// Reject a subledger write whose effective date falls in a closed period (primary book). No-op until a
|
||||
// period is actually locked. Lazy-required to avoid the closePeriods↔services cycle.
|
||||
function guardSubledger(assetId, date) {
|
||||
const row = one('SELECT entity_id FROM assets WHERE id = ?', [assetId]);
|
||||
if (row && date) require('./closePeriods').assertSubledgerOpen(row.entity_id, date);
|
||||
}
|
||||
|
||||
function yearOf(value) {
|
||||
if (!value) return new Date().getFullYear();
|
||||
return new Date(`${value}T00:00:00`).getFullYear();
|
||||
@@ -76,6 +83,7 @@ function recordDisposal(assetId, input, userId) {
|
||||
const asset = hydrateAsset(assetId);
|
||||
if (!asset) return null;
|
||||
const result = computeDisposal(asset, input);
|
||||
guardSubledger(assetId, result.disposal_date);
|
||||
const timestamp = now();
|
||||
|
||||
return tx(() => {
|
||||
@@ -121,6 +129,7 @@ function recordDisposal(assetId, input, userId) {
|
||||
function reverseDisposal(assetId, disposalId, userId) {
|
||||
const disposal = one('SELECT * FROM disposals WHERE id = ? AND asset_id = ?', [disposalId, assetId]);
|
||||
if (!disposal) return null;
|
||||
guardSubledger(assetId, disposal.disposal_date);
|
||||
const timestamp = now();
|
||||
|
||||
return tx(() => {
|
||||
@@ -149,6 +158,7 @@ function recordAdjustment(assetId, input, userId) {
|
||||
const asset = one('SELECT id FROM assets WHERE id = ?', [assetId]);
|
||||
if (!asset) return null;
|
||||
const timestamp = now();
|
||||
guardSubledger(assetId, input.adjustment_date || timestamp.slice(0, 10));
|
||||
const result = run(
|
||||
`INSERT INTO asset_adjustments (asset_id, adjustment_date, type, amount, book_type, reason, created_by, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
|
||||
Reference in New Issue
Block a user