π IrbyImaging.DomainClasses/AccountBalances.cs Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- UML Class Diagram
- Data Model: AccountBalances Entity
- Key Properties Explained
- Sample Code Blocks & Usage Examples
- Integration & Typical Usage Scenarios
- Conclusion
π 1. Overview & Purpose
The AccountBalances class is a Domain Model that maps directly to the irby.AccountBalances table in your database. It represents the monthly financial snapshot of jobs tracked by Irby Imaging:
- Revenue earned
- Cost incurred
- ManHours spent
It is designed for Entity Framework Core (EF Core) and uses Data Annotations for schema mapping and validation.
π― Intended Use
- Persisting and querying monthly financial data.
- Powering reporting dashboards, cost-analysis tools, and invoicing modules.
π οΈ 2. Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| .NET 6.0+ / .NET Framework 4.8+ | Runtime and base class library |
| Microsoft.EntityFrameworkCore | ORM for database mapping |
| System.ComponentModel.DataAnnotations | Data validation and schema mapping |
| System.ComponentModel.DataAnnotations.Schema | Table/column mapping |
π 3. UML Class Diagram
ββββββββββββββββββββββββββββββββββββββββββββ
β AccountBalances β
ββββββββββββββββββββββββββββββββββββββββββββ
β <<Table("AccountBalances","irby")>> β
ββββββββββββββββββββββββββββββββββββββββββββ
β + Guid AccountBalanceId {PK} β
β + int ReportingYear β
β + int ReportingMonth β
β + string JobNumber β
β + string JobName β
β + string CostCode β
β + string CostCodeDescription β
β + string AccountingCode β
β + string LedgerType β
β + string ObjectAccount β
β + decimal Revenue β
β + decimal Cost β
β + decimal ManHours β
β + string State β
β + string Customer β
β + string TypeOfWork β
β + string FieldOffice β
β + string Lead β
ββββββββββββββββββββββββββββββββββββββββββββ
ποΈ 4. Data Model: AccountBalances Entity
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.DomainClasses
{
[Table("AccountBalances", Schema = "irby")]
public class AccountBalances
{
[Key]
public Guid AccountBalanceId { get; set; }
public int ReportingYear { get; set; }
public int ReportingMonth { get; set; }
public string JobNumber { get; set; }
public string JobName { get; set; }
public string CostCode { get; set; }
public string CostCodeDescription { get; set; }
public string AccountingCode { get; set; }
public string LedgerType { get; set; }
public string ObjectAccount { get; set; }
// Financials
public decimal Revenue { get; set; }
public decimal Cost { get; set; }
public decimal ManHours { get; set; }
// Classification
public string State { get; set; }
public string Customer { get; set; }
public string TypeOfWork { get; set; }
public string FieldOffice { get; set; }
public string Lead { get; set; }
}
}
π 5. Key Properties Explained
| Property | Type | Description |
|---|---|---|
| AccountBalanceId | Guid | Primary Key β Unique identifier for this balance record. |
| ReportingYear | int | Year of the reporting period (e.g., 2023). |
| ReportingMonth | int | Month of the reporting period (1 = Jan, 12 = Dec). |
| JobNumber | string | Internal job/project number. |
| JobName | string | Descriptive name of the job/project. |
| CostCode | string | Cost code for categorizing expenses. |
| CostCodeDescription | string | Human-readable description of the cost code. |
| AccountingCode | string | GL account code for financial posting. |
| LedgerType | string | Type of ledger (e.g., βRevenueβ, βExpenseβ). |
| ObjectAccount | string | Detailed account number (sub-ledger) if needed. |
| Revenue | decimal | Total revenue recognized in this period. |
| Cost | decimal | Total cost incurred in this period. |
| ManHours | decimal | Total labor hours tracked. |
| State | string | Geographic or operational state of the job. |
| Customer | string | Customer name or ID. |
| TypeOfWork | string | Classification of work performed (e.g., Installation). |
| FieldOffice | string | Office location managing the job. |
| Lead | string | Responsible project lead or manager. |
π§© 6. Sample Code Blocks & Usage Examples
6.1 Entity Framework Core Configuration
public class IrbyDbContext : DbContext
{
public DbSet<AccountBalances> AccountBalances { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<AccountBalances>()
.ToTable("AccountBalances", schema: "irby")
.HasKey(ab => ab.AccountBalanceId);
// Additional Fluent API configurations (optional)...
}
}
6.2 CRUD Operations
Create a New Record
var newBalance = new AccountBalances
{
AccountBalanceId = Guid.NewGuid(),
ReportingYear = 2024,
ReportingMonth = 5,
JobNumber = "JOB-12345",
JobName = "Fiber Optic Installation",
CostCode = "CC-001",
CostCodeDescription = "Labor Charge",
AccountingCode = "AC-5000",
LedgerType = "Expense",
ObjectAccount = "OBJ-900",
Revenue = 15000.00m,
Cost = 8000.00m,
ManHours = 120.5m,
State = "TX",
Customer = "Acme Corp",
TypeOfWork = "Installation",
FieldOffice = "Houston",
Lead = "John Doe"
};
dbContext.AccountBalances.Add(newBalance);
await dbContext.SaveChangesAsync();
Read / Query Records
// Get May 2024 balances
var mayBalances = await dbContext.AccountBalances
.Where(ab => ab.ReportingYear == 2024 && ab.ReportingMonth == 5)
.ToListAsync();
Update an Existing Record
var balance = await dbContext.AccountBalances
.FirstOrDefaultAsync(ab => ab.AccountBalanceId == existingId);
if (balance != null)
{
balance.Cost += 500.00m; // Add additional cost
await dbContext.SaveChangesAsync();
}
Delete a Record
var balanceToRemove = new AccountBalances { AccountBalanceId = existingId };
dbContext.AccountBalances.Remove(balanceToRemove);
await dbContext.SaveChangesAsync();
6.3 LINQ Queries & Reporting
- Total Revenue per Job:
var revenueByJob = await dbContext.AccountBalances
.GroupBy(ab => ab.JobNumber)
.Select(g => new {
JobNumber = g.Key,
TotalRevenue = g.Sum(x => x.Revenue)
}).ToListAsync();
- Cost vs Revenue Trend Over Time:
var monthlyTrend = await dbContext.AccountBalances
.GroupBy(ab => new { ab.ReportingYear, ab.ReportingMonth })
.OrderBy(g => g.Key.ReportingYear).ThenBy(g => g.Key.ReportingMonth)
.Select(g => new {
YearMonth = g.Key,
TotalCost = g.Sum(x => x.Cost),
TotalRevenue = g.Sum(x => x.Revenue)
}).ToListAsync();
π 7. Integration & Typical Usage Scenarios
-
Dashboard Reporting
- Populating charts showing cost vs. revenue by month.
- Filtering by FieldOffice or TypeOfWork.
-
Project Accounting
- Feeding data into the GL system via AccountingCode and LedgerType.
- Monthly close processes.
-
Resource Planning
- Analyzing ManHours logged per job for capacity planning.
-
Data Exports
- Generating CSV/PDF reports for internal and client distribution.
π― 8. Conclusion
The AccountBalances entity is the cornerstone of financial reporting within the Irby Imaging system. By adhering to EF Core conventions and providing a rich set of properties, it allows developers and analysts to:
- Effortlessly persist financial snapshots.
- Query with LINQ for advanced reporting.
- Integrate seamlessly into broader accounting and BI workflows.
With this documentation, you now have a comprehensive guide to how the AccountBalances class works, how to configure it, and how to leverage it in real-world scenarios. π
Happy Coding! β¨