Commit Graph

17 Commits

Author SHA1 Message Date
6b7ea745d8 test(core): Add comprehensive tests for core catalog services
- Add tests for countries.service.ts (findAll, findById, create, update)
- Add tests for currencies.service.ts (CRUD, rates, conversion)
- Add tests for states.service.ts (CRUD, country filtering)
- Add tests for uom.service.ts (CRUD, conversion, categories)
- Add mock factories for core entities (Country, State, Currency, etc.)
- Fix Jest config for proper CJS/TS interop
- All 592 tests passing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 09:21:22 -06:00
d809e23b5c feat(core): Add States, CurrencyRates, and UoM conversion (MGN-005)
- State entity and service with CRUD operations
- CurrencyRate entity and service with conversion support
- UoM conversion methods (convertQuantity, getConversionTable)
- New API endpoints for states, currency rates, UoM conversions
- Updated controller and routes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 08:57:21 -06:00
028c037160 test(billing-usage): Add comprehensive service tests (184 tests)
- subscription-plans.service.test.ts: 24 tests for CRUD, filters, comparisons
- subscriptions.service.test.ts: 34 tests for lifecycle, payments, renewals
- usage-tracking.service.test.ts: 20 tests for metrics, limits, reports
- invoices.service.test.ts: 42 tests for billing, payments, refunds

Coverage improved from ~30% to 80%+ for billing-usage module.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 08:34:59 -06:00
b194f59599 feat(billing-usage): Add services, middleware and tests for FASE 4
- Add CouponsService for discount coupon management
- Add PlanLimitsService for plan limit validation
- Add StripeWebhookService for Stripe event processing
- Add plan-enforcement middleware (requireLimit, requireFeature, planBasedRateLimit)
- Add 68 unit tests for all billing-usage services
- Update TenantSubscription entity with Stripe integration fields
- Export new services from module index

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 08:03:57 -06:00
0bdb2eed65 [FASE 4] feat: Add SaaS billing entities and fix unit tests
- Add PlanLimit entity for plan limits tracking
- Add Coupon entity for discount coupons
- Add CouponRedemption entity for coupon usage
- Add StripeEvent entity for webhook processing
- Fix purchases.service tests (mock sequencesService)
- Fix orders.service tests (mock stockReservation)
- Add partners.controller tests (13 new tests)

Test Results: 361 tests passing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 07:47:24 -06:00
edadaf3180 [FASE 3-4] feat: Complete Financial, Inventory, CRM, and Projects modules
EPIC-005 - Financial Module:
- Add AccountMapping entity for GL account configuration
- Create GLPostingService for automatic journal entries
- Integrate GL posting with invoice validation
- Fix tax calculation in invoice lines

EPIC-006 - Inventory Automation:
- Integrate FIFO valuation with pickings
- Create ReorderAlertsService for stock monitoring
- Add lot validation for tracked products
- Integrate valuation with inventory adjustments

EPIC-007 - CRM Improvements:
- Create ActivitiesService for activity management
- Create ForecastingService for pipeline analytics
- Add win/loss reporting and user performance metrics

EPIC-008 - Project Billing:
- Create BillingService with billing rate management
- Add getUnbilledTimesheets and createInvoiceFromTimesheets
- Support grouping options for invoice generation

EPIC-009 - HR-Projects Integration:
- Create HRIntegrationService for employee-user linking
- Add employee cost rate management
- Implement project profitability calculations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 05:49:20 -06:00
6054102774 [BACKEND] feat: EPIC-001 & EPIC-002 - Core module completion and entity consolidation
EPIC-001: Complete Core Module
- Add PaymentTerm entity with multi-line support (30/60/90 days, early payment discounts)
- Add PaymentTerms service with calculateDueDate() functionality
- Add DiscountRule entity with volume/time-based conditions
- Add DiscountRules service with applyDiscounts() and rule combination logic
- Add REST endpoints for payment-terms and discount-rules in core module
- Register new entities in TypeORM configuration

EPIC-002: Entity Consolidation
- Add inventoryProductId FK to products.products for linking to inventory module
- Consolidate Warehouse entity in warehouses module as canonical source
- Add companyId and Location relation to canonical Warehouse
- Update inventory module to re-export Warehouse from warehouses module
- Remove deprecated warehouse.entity.ts from inventory module
- Update inventory/warehouses.service.ts to use canonical Warehouse

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 05:13:34 -06:00
a7bf403367 test(fase3): Add unit tests for business modules
Add comprehensive unit tests for FASE 3 modules:
- Sales: quotations.service (15 tests), orders.service (27 tests)
- Purchases: purchases.service (21 tests), rfqs.service (39 tests)
- CRM: leads.service (25 tests), opportunities.service (23 tests), stages.service (19 tests)
- Projects: projects.service (15 tests), tasks.service (19 tests)

Updated helpers.ts with factory functions for all new entity types.
Total: 203 new tests (348 tests total, all passing)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 04:36:21 -06:00
301628f759 test(fase2): Add unit tests for FASE 2 modules
Add comprehensive unit tests for Business Core modules:
- Partners: 22 tests (CRUD, filters, tenant isolation)
- Products: 23 tests (CRUD, categories, search)
- Invoices: 31 tests (CRUD, payments, state transitions)
- Warehouses: 24 tests (CRUD, locations, default handling)
- HR Employees: 24 tests (CRUD, terminate/reactivate, subordinates)

Test infrastructure:
- jest.config.js with ts-jest and ESM support
- setup.ts with mocks for AppDataSource and database
- helpers.ts with factory functions for test data

Total: 114 tests passing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 04:18:40 -06:00
a127a4a424 feat(routes): Add independent routes for Invoices, Products, Warehouses modules
- Create invoices.controller.ts and invoices.routes.ts with singleton service
- Create products.service.ts, products.controller.ts, products.routes.ts
- Create warehouses.service.ts, warehouses.controller.ts, warehouses.routes.ts
- Register all routes in app.ts
- Use Zod validation schemas in all controllers
- Apply multi-tenant isolation via tenantId
- Update invoices.module.ts to use singleton pattern

All business modules now have API routes registered and build passes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 03:43:43 -06:00
d456ad4aca docs(entities): Document Warehouse/Product duplications and domain separation
- Add deprecation notice to inventory/warehouse.entity.ts
  - Duplicated with warehouses/warehouse.entity.ts (same table)
  - Plan unification in warehouses module with all fields and relations

- Document that Product entities are NOT duplicates
  - products.products: Commerce/retail focused (SAT, pricing, dimensions)
  - inventory.products: Warehouse management focused (Odoo-style, valuation)
  - Intentionally separate by domain
2026-01-18 02:50:13 -06:00
d9778eb632 feat(invoices): Unify billing and commercial Invoice entities
- Create unified Invoice entity in invoices module with all fields:
  - Commercial fields: salesOrderId, purchaseOrderId, partnerId
  - SaaS fields: subscriptionId, periodStart, periodEnd
  - Context discriminator: invoiceContext ('commercial' | 'saas')
- Mark billing-usage/invoice.entity.ts as deprecated, re-export from invoices
- Update billing-usage/services/invoices.service.ts for unified entity
- Add missing InvoiceStatus values (validated, cancelled, voided)
- Export types from both modules for backward compatibility

Note: financial/invoice.entity.ts remains separate (different schema)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 02:36:06 -06:00
ffd5ffe56a fix: Resolve remaining TypeScript build errors (19→0)
- Fix api keys controller scope type handling
- Fix billing-usage invoices/subscriptions undefined assignments
- Fix branches service type casting
- Fix financial controller Zod schemas (accounts camelCase, journals snake_case)
- Fix inventory controller with type assertions for enums
- Fix valuation controller meta type
- Fix notifications service channel type casting
- Fix payment-terminals transactions service undefined assignments
- Fix CircuitBreaker constructor signature

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 02:33:43 -06:00
d616370440 fix: Resolve entity/service field mismatches and build errors (84→19)
- Add class-validator and class-transformer dependencies
- Fix inventory entities index.ts exports
- Add ConflictError to shared types
- Fix ai.service.ts quota field names
- Fix audit.service.ts field names and remove missing methods
- Fix storage.service.ts bucket and file field names
- Rewrite partners.service.ts/controller.ts to match entity
- Fix product.entity.ts computed column syntax
- Fix inventory-adjustment-line.entity.ts computed column
- Fix webhooks.service.ts field names
- Fix whatsapp.service.ts order field names
- Fix swagger.config.ts import.meta.url issue

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 02:27:03 -06:00
e846b715c1 feat: Add billing and feature-flags entities
- Added plan-feature entity for billing
- Added flag-evaluation entity for feature flags
- Updated module configurations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 12:13:18 -06:00
ca07b4268d feat: Add complete module structure for ERP backend
- Add modules: ai, audit, billing-usage, biometrics, branches, dashboard,
  feature-flags, invoices, mcp, mobile, notifications, partners,
  payment-terminals, products, profiles, purchases, reports, sales,
  storage, warehouses, webhooks, whatsapp
- Add controllers, DTOs, entities, and services for each module
- Add shared services and utilities

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 00:40:54 -06:00
12fb6eeee8 Initial commit - erp-core-backend 2026-01-04 06:40:14 -06:00