Commit Graph

28 Commits

Author SHA1 Message Date
Adrian Flores Cortes
fd8a0a508e [TASK-2026-01-25-ERP-INTEGRACIONES] feat: Add payment terminals + AI role-based access
Payment Terminals (MercadoPago + Clip):
- TenantTerminalConfig, TerminalPayment, TerminalWebhookEvent entities
- MercadoPagoService: payments, refunds, links, webhooks
- ClipService: payments, refunds, links, webhooks
- Controllers for authenticated and webhook endpoints
- Retry with exponential backoff
- Multi-tenant credential management

AI Role-Based Access:
- ERPRole config: ADMIN, SUPERVISOR, OPERATOR, CUSTOMER
- 70+ tools mapped to roles
- System prompts per role (admin, supervisor, operator, customer)
- RoleBasedAIService with tool filtering
- OpenRouter integration
- Rate limiting per role

Based on: michangarrito INT-004, INT-005, MCH-012, MCH-013

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 01:32:32 -06:00
Adrian Flores Cortes
2d2a562274 [TASK-028] security: Add tenant_id validation to uniqueness checks
- warehouses.service.ts: Add code uniqueness check with tenantId
- products.service.ts: Add SKU/barcode uniqueness checks with tenantId
- accounts.service.ts: Add tenantId to code and parent validation

Fixes 5 RLS gaps in backend services for multi-tenant isolation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 22:22:59 -06:00
Adrian Flores Cortes
7ae745e509 [SYNC] test: Add service unit tests
- billing-usage: invoices.service.spec.ts, subscriptions.service.spec.ts
- financial: payments.service.spec.ts
- inventory: warehouses-new.service.spec.ts
- partners: partners.service.spec.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 18:13:32 -06:00
Adrian Flores Cortes
7d3ad15968 [TASK-2026-01-24-GAPS] feat: Add new entities for products/partners + health module
Changes:
- Add ProductAttribute, ProductAttributeValue, ProductVariant entities
- Add PartnerTaxInfo, PartnerSegment entities
- Add Health module (service, controller, module)
- Update index.ts and module.ts files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 07:27:28 -06:00
8d201c5b58 [TASK-2026-01-20-005] feat: Add multi-tenancy to UOM entities
EPIC-P2-005: UOM Multi-tenancy Sync
- Add tenant_id field to Uom entity
- Add tenant_id field to UomCategory entity
- Add Tenant relation to both entities
- Add UpdateDateColumn for updated_at
- Update indexes for tenant-based unique constraints

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 04:32:10 -06:00
24b6ba9b38 [PROJECTS] feat: Add Timesheet entity and DTOs
Add TypeORM entity and DTOs for Projects timesheets feature:
- TimesheetEntity with all fields matching DDL schema
- Extended DTOs for bulk operations (submit, approve, reject)
- Summary types for reporting (by project, user, task)
- Updated module exports to include new files

Complements existing timesheets.service.ts implementation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 04:28:19 -06:00
b25afada28 [TASK-2026-01-20-004] feat: Add auth entities and fix tests
EPIC-P1-002: Auth entities
- Add user-profile.entity.ts
- Add profile-tool.entity.ts
- Add profile-module.entity.ts
- Add user-profile-assignment.entity.ts
- Add device.entity.ts
- Update auth entities index

EPIC-P1-003: DDL-Entity sync
- Add isSuperadmin, mfaEnabled, mfaSecretEncrypted fields to User
- Add mfaBackupCodes, oauthProvider, oauthProviderId fields to User

EPIC-P1-005: Fix test compilation errors
- Fix accounts.service.spec.ts
- Fix products.service.spec.ts
- Fix warehouses.service.spec.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 04:06:26 -06:00
af3cc5a25d [TASK-2026-01-20-003] feat: Add bank reconciliation and 3-way matching
Bank Reconciliation (financial module):
- Entities: BankStatement, BankStatementLine, BankReconciliationRule
- Service: BankReconciliationService with auto-reconcile
- DTOs: CreateBankStatement, ReconcileLine

3-Way Matching (purchases module):
- Entities: PurchaseOrderMatching, PurchaseMatchingLine, MatchingException
- Service: ThreeWayMatchingService with tolerance validation
- DTOs: MatchingStatus, ResolveException

Tolerances:
- Quantity: 0.5%
- Price: 2%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 03:47:19 -06:00
f63c17df5c test: Add unit tests for Financial and Inventory services
- accounts.service.spec.ts: Tests for account CRUD, account types, chart of accounts
- products.service.spec.ts: Tests for product CRUD, stock levels, validation
- warehouses.service.spec.ts: Tests for warehouse CRUD, locations management

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 10:45:46 -06:00
5357311953 feat(inventory): Register all inventory entities in TypeORM config
Added missing entity registrations for:
- Inventory: StockLevel, StockMovement, InventoryCount, InventoryCountLine,
  InventoryAdjustment, InventoryAdjustmentLine, TransferOrder, TransferOrderLine,
  StockValuationLayer
- Fiscal: TaxCategory, FiscalRegime, CfdiUse, PaymentMethod, PaymentType, WithholdingType
- Core: CurrencyRate, State

This enables TypeORM to properly manage these entities for the inventory module.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 09:54:43 -06:00
5fa451e09f feat(fiscal): Add fiscal module with catalogs (MGN-005)
- Add fiscal entities:
  - TaxCategory, FiscalRegime, CfdiUse
  - PaymentMethod, PaymentType, WithholdingType
- Add fiscal services with filtering capabilities
- Add fiscal controller with REST endpoints
- Add fiscal routes at /api/v1/fiscal
- Register fiscal routes in app.ts

Endpoints:
- GET /fiscal/tax-categories
- GET /fiscal/fiscal-regimes
- GET /fiscal/cfdi-uses
- GET /fiscal/payment-methods
- GET /fiscal/payment-types
- GET /fiscal/withholding-types

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 09:31:47 -06:00
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