Skip to content

Phase 1 + 2: multi-tenant scoping trait + settings-driven PayFile payment method#5

Open
TLemmAI wants to merge 22 commits intofleetbase:mainfrom
TLemmAI:feat/multi-tenant-hierarchy
Open

Phase 1 + 2: multi-tenant scoping trait + settings-driven PayFile payment method#5
TLemmAI wants to merge 22 commits intofleetbase:mainfrom
TLemmAI:feat/multi-tenant-hierarchy

Conversation

@TLemmAI
Copy link
Copy Markdown

@TLemmAI TLemmAI commented Apr 15, 2026

Summary

Part of the upstream fleetbase Phase 1 + 2 TMS productization consolidation.

Phase 1 (commit 963bef4)

Apply the new Fleetbase\Models\Concerns\ScopedToCompanyContext trait (from core-api) to the tenant-owned ledger models:

  • CarrierInvoice
  • ServiceAgreement
  • PayFile

Local scope only — existing queries are unaffected unless callers explicitly chain ->inCompanyContext().

Phase 2 (commit f149738)

PayFileGeneratorService — replace the hardcoded payment_method = 'ach' default with a resolver lookup via Fleetbase\Support\CompanySettingsResolver::forCompany($uuid)->get('pay_files.default_payment_method'). Per-company overrides and parent→client inheritance now flow through the new settings surface.

Dependencies

  • Requires core-api PR (CompanySettingsResolver + ScopedToCompanyContext + CompanyContextResolver middleware) to land first.

Test plan

  • Core-api Pest suite: docker run ... ./vendor/bin/pest tests/Feature/ → 116 passed
  • Manual verification: set pay_files.default_payment_method = 'wire' on a test company, generate pay file, verify item's payment_method reflects the setting.
  • Smoke test API/SDK 14/14.

TLemmAI and others added 22 commits April 13, 2026 09:20
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sGlAssignments trait

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…egistration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Rule models

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…d auto-approve rules

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…invoices tables

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…odels

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e, InvoiceNumberGenerator

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ents and client invoices

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…culation service, and event integration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Rate unit conversion: benchmark_rate now converted to flat expected_total
   based on rate_unit (flat/per_mile/per_cwt) before comparing to actual cost.
   Missing miles or weight safely skips instead of producing wrong numbers.

2. Loss/break-even tracking: all calculable outcomes now recorded including
   losses, break-even, and below-threshold. New result_type column classifies
   each execution. Shares are 0 for non-savings results.

3. Deduplication: checks for existing execution with same shipment_uuid +
   gainshare_rule_uuid. Updates existing record instead of inserting duplicates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…act future hook

- New benchmark_source field on gainshare_rules (default: cost_benchmark)
- Service branches on benchmark_source: cost_benchmark runs existing logic,
  rate_contract returns null safely (not yet implemented)
- Added getBenchmarkFromRateContract() stub for BUILD-10 integration
- No changes to existing calculation math or result_type logic

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ting engine

- benchmark_source = 'rate_contract' now resolves expected_total via
  RateShopService::calculateForContract() against a deterministically-selected
  RateContract (does NOT rate-shop all carriers).
- Selection priority: customer-specific > generic, dedicated cost_management_benchmark
  usage > both, most recent effective_date, then UUID for full determinism.
- Refactored to share dedup/savings/classification/storage logic between both
  benchmark sources — financial safety guarantees identical for both paths.
- cost_benchmark path remains 100% unchanged.
- benchmark_source recorded in execution.meta for audit visibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
POST /carrier-invoices/batch-approve bulk-approves invoices using the existing
resolve() flow per-invoice so GL assignment and gainshare events fire normally.
Skips invoices not in audited/in_review state with a reason.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant