Distribution_GL Initialization

This commit is contained in:
2026-10-20 13:07:07 +05:30
commit 3f16e0cb44
194 changed files with 35659 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
using General_Ledger_Service.Infra;
using General_Ledger_Service.Interfaces.Repositories;
using General_Ledger_Service.Models;
using Microsoft.EntityFrameworkCore;
namespace General_Ledger_Service.Repositories
{
public class FixedAssetRepository(AppDBContext context) : IFixedAssetRepository
{
private readonly AppDBContext _context = context;
public Task<FixedAsset?> GetByIdAsync(long assetId) =>
RepositoryHelpers.GetByIdAsync(_context.FixedAssets, assetId);
public async Task<FixedAsset?> GetByCodeAsync(string assetCode) =>
await _context.FixedAssets.FirstOrDefaultAsync(a => a.AssetCode == assetCode);
public Task<FixedAsset> AddAsync(FixedAsset asset) =>
RepositoryHelpers.AddAsync(_context.FixedAssets, asset);
public async Task<List<FixedAsset>> GetAllAsync() =>
await _context.FixedAssets.OrderBy(a => a.AssetCode).ToListAsync();
public async Task<DepreciationSchedule?> GetLatestScheduleByAssetIdAsync(long assetId) =>
await _context.DepreciationSchedules
.Where(s => s.AssetId == assetId)
.OrderByDescending(s => s.CreatedAt)
.FirstOrDefaultAsync();
public Task<DepreciationSchedule> AddScheduleAsync(DepreciationSchedule schedule) =>
RepositoryHelpers.AddAsync(_context.DepreciationSchedules, schedule);
public Task<AssetDisposal> AddDisposalAsync(AssetDisposal disposal) =>
RepositoryHelpers.AddAsync(_context.AssetDisposals, disposal);
// Accounting_System_Design_LKAS.md Section 11.5 - the only non-cash add-back this system
// currently tracks. ROUND(...,10) guards the same decimal-overflow class of bug fixed
// elsewhere in the report queries (03_Progress_Tracker.md's 2026-07-21 bugfix entry).
public async Task<decimal> GetDepreciationAddBackAsync(DateOnly periodStart, DateOnly periodEnd)
{
return await _context.DepreciationSchedules
.Where(ds => ds.Journal != null
&& ds.Journal.IsPosted
&& ds.Journal.EntryDate >= periodStart
&& ds.Journal.EntryDate <= periodEnd)
.SumAsync(ds => (decimal?)ds.DepreciationAmount) ?? 0m;
}
}
}