Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ timestamps: true, collection: 'depreciation_schedules' }) export class DepreciationSchedule extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true }) assetId: MongooseSchema.Types.ObjectId; @Prop({ required: true }) fiscalYearId: string; @Prop({ required: true }) periodNumber: number; // 1 to 12 @Prop({ required: true, default: 0 }) depreciationAmountMinor: number; @Prop({ required: true, default: 0 }) bookValueBeforeMinor: number; @Prop({ required: true, default: 0 }) bookValueAfterMinor: number; @Prop({ default: 'pending' }) status: string; // 'pending' | 'posted' | 'recalibrated' } export const DepreciationScheduleSchema = SchemaFactory.createForClass(DepreciationSchedule); DepreciationScheduleSchema.index({ tenantId: 1, assetId: 1, status: 1 }); @Schema({ timestamps: true, collection: 'depreciation_runs' }) export class DepreciationRun extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true }) runNumber: string; // e.g. "DEP-2026-07" @Prop({ required: true }) fiscalYearId: string; @Prop({ required: true }) periodNumber: number; @Prop({ required: true, default: 0 }) totalDepreciationMinor: number; @Prop({ default: 'draft' }) status: string; // 'draft' | 'posting_ready' | 'posted' | 'failed' @Prop({ default: null }) postedAt?: Date; @Prop({ default: null }) postedBy?: string; } export const DepreciationRunSchema = SchemaFactory.createForClass(DepreciationRun); DepreciationRunSchema.index({ tenantId: 1, runNumber: 1 }, { unique: true }); @Schema({ timestamps: true, collection: 'asset_disposals' }) export class AssetDisposal extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true }) assetId: MongooseSchema.Types.ObjectId; @Prop({ required: true }) disposalType: string; // 'Sale' | 'Scrap' | 'Write-off' | 'Donation' @Prop({ required: true, default: () => new Date() }) disposalDate: Date; @Prop({ required: true, default: 0 }) proceedsMinor: number; // Sale price or recovery value @Prop({ required: true, default: 0 }) netBookValueMinor: number; // NBV at time of disposal @Prop({ required: true, default: 0 }) gainLossMinor: number; // Proceeds - NetBookValue (positive = gain, negative = loss) @Prop({ default: 'pending_posting' }) status: string; // 'pending_posting' | 'completed' | 'cancelled' } export const AssetDisposalSchema = SchemaFactory.createForClass(AssetDisposal); AssetDisposalSchema.index({ tenantId: 1, assetId: 1 }); |