company_credit_charge_defaults on goal-data-db): master credit_charge_enabled + default tier matrix (charges.charges[] with days / value %).online_store_credit_charges): operational matrix per distribution center (existing admin tab).apply_credit_charge = Y|N on business_partners, business_partner_addresses, sales_team_customers). Default Y at all levels.New distribution centers auto-create a store DC charge row from company defaults when none exists (ProvisionOnlineStoreCreditChargeFromCompanyDefaultsAction). Existing DC rows are not overwritten when company defaults change.
{
"charges": [
{ "days": 7, "value": 0.5 },
{ "days": 14, "value": 1.0 },
{ "days": 21, "value": 1.5 },
{ "days": 28, "value": 2.0 }
]
}
Canonical PHP constant: Domain\ExternalSales\CreditCharge\CreditChargeDefaults::CHARGES_PAYLOAD.
File: goal-backend/database/migrations/2026_10_27_120000_add_credit_charge_hierarchy_fields.php
Connection: goal-data-db (Blueprint::goal() / DB::goal()).
| Change |
|---|
apply_credit_charge CHAR(1) default Y on business_partners, business_partner_addresses, sales_team_customers |
Table company_credit_charge_defaults (company_id unique, credit_charge_enabled, JSON charges) |
Backfill null flags to Y |
Seed one default row per transactional company only (companies.type = 'T' on core DB) |
Global (G), system (S), and reserved (R) companies do not receive seed rows; runtime uses CompanyCreditChargeDefault::forCompanyOrDefault() when no row exists.
CreditChargeSchemaSupport::isReady() checks table + columns on goal-data-db. Until migration runs:
GET .../credit-summary returns 200 with apply_credit_charge = 'Y' and credit_charge_applicable = true (no queries on missing columns).ResolveCreditChargeApplicabilityAction treats charges as applicable with reason charge_schema_not_migrated.Charge applies only when:
credit_charge_enabled = Yapply_credit_charge = YDomain: ResolveCreditChargeApplicabilityAction.
Rate by payment-term days: ResolveCreditChargeRateAction (store DC matrix or company defaults).
Order line: ResolveOrderCreditSurchargeAction.
Mandatory headers: Authorization: Bearer <token>, x-app-stage, x-app-uid.
Responses use ActionResult (success, message, data) unless noted for BEES raw JSON endpoints.
GET /v1/base/master/companies/{id}/credit-charge-defaults?companyId={contextCompanyId}
PUT /v1/base/master/companies/{id}/credit-charge-defaults?companyId={contextCompanyId}
Content-Type: application/json
{
"credit_charge_enabled": "Y",
"charges": {
"charges": [
{ "days": 7, "value": 0.5 },
{ "days": 14, "value": 1.0 }
]
}
}
| HTTP | When |
|---|---|
200 |
Success |
400 / 422 |
Validation (invalid tiers, missing companyId) |
401 / 403 |
Auth / permission |
| Method | Path |
|---|---|
| PUT | /v1/base/business-partners/{id}/credit-charge-flag?companyId= |
| PUT | /v1/base/business-partners/{id}/addresses/{addressId}/credit-charge-flag?companyId= |
| PUT | /v1/base/business-partners/{id}/sales-teams/{stcId}/credit-charge-flag?companyId= |
{ "apply_credit_charge": "Y" }
GET /v1/base/business-partners/{id}/credit-summary?companyId=
data includes partner-level apply_credit_charge, credit_charge_applicable, and the same fields on each shipping_addresses[] and sales_teams[] entry. See business-partners API § Credit Line Management.
Store DC CRUD remains under /v1/external-sales/online-store-credit-charges (unchanged).
GET /v1/bees/accounts/charges returns creditChargeEnabled and empty charges when company master is off.apply_credit_charge per account group (ListBeesAccountCreditsAction).Action: Domain\Integrations\Bees\Process\RegisterBeesOrderAction
When: GOAL order exists with lines; registers SB1 PreviewOrder from Couch external-orders + GOAL orders row.
add_surcharge| Value | Behavior |
|---|---|
true |
GOAL recalculates recargo with ResolveOrderCreditSurchargeAction (credit payment, apply_credit_charge hierarchy, company + store/DC tier matrix). Base amount: GOAL orders.total_amount. |
false or omitted (default) |
Do not recalculate — assume BEES already included recargo in summary.total. Copy rate/amount from the external payload into SAP preview fields. |
Resolution order (first non-empty): orders.add_surcharge (column, if migrated) → orders.metadata.add_surcharge → Couch document add_surcharge / addSurcharge.
Truthy values: true, 1, Y, YES, TRUE, T.
add_surcharge is not true)Read from document root or summary (snake_case or camelCase):
| Purpose | Accepted keys |
|---|---|
| Apply flag | apply_surcharge, applySurcharge, summary.apply_surcharge, summary.applySurcharge |
| Rate (%) | surcharge_rate, surchargeRate, summary.surcharge_rate, summary.surchargeRate |
| Amount | surcharge_value, surchargeValue, summary.surcharge_value, summary.surchargeValue, summary.surcharge, summary.financialSurcharge |
If apply_* is missing but rate or amount > 0, SAP applySurcharge is set to Y.
| GOAL / resolver | SB1 PreviewOrder column |
|---|---|
apply_surcharge |
applySurcharge (Y / N) |
surcharge_rate |
surchargeRate |
surcharge_value |
surchargeValue |
Integration note: BEES B2B orders that compute recargo client-side should leave add_surcharge unset (or false) and send surcharge_rate / surcharge_value on the order document. Use add_surcharge: true only when GOAL must own recalculation (e.g. legacy flows or missing BEES surcharge fields).
credit_purchase_allowed: business-partner-payment-terms-sync.md