Phase F: Add Invoice Write-Off, Fixed Assets, Period Locking, and 1099 Tracking

- Invoice Write-Off: WriteOff POST action in InvoicesController posts bad-debt JE
  (DR bad debt expense / CR AR), reduces customer balance, marks invoice WrittenOff;
  write-off modal added to Invoice Details view with expense account selector
- Fixed Assets: FixedAsset + FixedAssetDepreciationEntry entities with straight-line
  depreciation; FixedAssetsController (Index/Create/Edit/Details/PostDepreciation/Delete);
  PostDepreciation auto-generates one JE per asset per period, skips already-posted,
  fully-depreciated, and disposed assets; full CRUD views + nav link
- Period Locking: Company.BookLockedThrough field; AccountingPeriodValidator static helper;
  lock check added to JE Post and Bill Create (blocks backdating into closed periods);
  SetPeriodLock action + date picker UI in Company Settings Accounting section
- 1099 Tracking: Is1099Vendor flag on Vendor entity + DTOs; checkbox in Create/Edit views;
  TaxReporting1099 report action + view lists payments by year, flags vendors >= $600;
  report card added to Reports Landing
- Migration AddFixedAssetsLockAnd1099 applied

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 12:19:32 -04:00
parent a255893ada
commit fde24b09c9
29 changed files with 12520 additions and 3 deletions
@@ -160,6 +160,10 @@ public class CompanySettingsController : Controller
UpdatedAt = t.UpdatedAt
}).ToList();
ViewBag.BookLockedThrough = company.BookLockedThrough.HasValue
? (DateTime?)company.BookLockedThrough.Value.ToLocalTime()
: null;
return View(dto);
}
catch (FormatException fex)
@@ -227,6 +231,34 @@ public class CompanySettingsController : Controller
}
}
/// <summary>
/// Locks the books through the given date, preventing new or edited accounting entries
/// (JEs, bills, expenses) from being dated on or before this date. Null clears the lock.
/// </summary>
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> SetPeriodLock(DateTime? lockThrough)
{
var companyId = _tenantContext.GetCurrentCompanyId();
if (companyId == null) return BadRequest();
var company = await _unitOfWork.Companies.GetByIdAsync(companyId.Value);
if (company == null) return NotFound();
company.BookLockedThrough = lockThrough.HasValue
? DateTime.SpecifyKind(lockThrough.Value.Date, DateTimeKind.Utc)
: null;
company.UpdatedAt = DateTime.UtcNow;
await _unitOfWork.Companies.UpdateAsync(company);
await _unitOfWork.CompleteAsync();
TempData["Success"] = lockThrough.HasValue
? $"Books locked through {lockThrough.Value:MMMM d, yyyy}."
: "Period lock cleared — all periods are now open.";
return RedirectToAction(nameof(Index), null, "company-info");
}
/// <summary>
/// Serves the current company's logo as a binary file response. Logos are stored on the filesystem
/// via <see cref="ICompanyLogoService"/> (primary) or as raw bytes in <c>Company.LogoData</c>