Skip to main content

Customer Management

Customer Management handles customer draft creation, editing, address/branch maintenance, and approval before customer data becomes usable as SAP customer master data. It is the write-side flow for customer master changes.

App Entry Points​

AppTarget
MobileCustomerManagementList -> detail/edit/address screens
POS TerminalcustomerManagement -> CustomerManagementDetailForm

Draft Lifecycle​

Workflow With Permissions​

Data And API Rules​

Page-Level Flow And Actions​

The draft is not one flat form. Developers must treat profile, addresses, and billable branches as three related resources and refresh the detail after every child mutation.

Area / actionConditions and result
Create draftAvailable only when customer-management access allows creation; starts a draft and does not create SAP master data immediately.
Edit customer dataSave header fields independently from addresses and branch links. Server validation remains authoritative.
Add/edit addressStores address text, address type/context, branch association and latitude/longitude where supplied. Invalid or empty coordinates must not be presented as a usable location.
Delete addressRequires confirmation and deletes only the draft-address child. Reload the parent detail afterward.
Open mapEnabled only when usable coordinates exist; it is a review action and does not save a location.
Add billable branchShow only branches not already linked to the draft. A branch link means the approved customer can open bills in that branch.
Remove billable branchDeletes the relationship, not the branch and not the customer.
Approve/rejectSeparate from edit permission. DRAFT shows approve/reject controls. Approval publishes the reviewed draft; rejection keeps a correction path and should include a reason.
Retry partial SAP approvalA draft with SAP_PARTIAL shows only Retry approval submission to an approver. It calls POST /customer-draft/:id/retry.
OperationService
List draftsgetCustomerDrafts -> GET /customer-draft?branchId=...
DetailgetCustomerDraftById -> GET /customer-draft/:id
Create/update profilecreateCustomerDraft, updateCustomerDraft
Approve/rejectapproveCustomerDraft, rejectCustomerDraft(payload)
Retry partial SAP approvalretryCustomerDraft -> POST /customer-draft/:id/retry
Draft addressescreateCustomerDraftAddress, updateCustomerDraftAddress, deleteCustomerDraftAddress
Draft branch linkscreateCustomerDraftBranch, deleteCustomerDraftBranch

Important implementation notes:

  • Draft list is selected-branch scoped.
  • Approval is separate from saving profile/address data.
  • Rejection should include reviewer context/reason in payload where the UI collects it.
  • Draft addresses and branch links are child resources; changing the profile does not automatically change children.
  • After approval, operational lookup moves to Customers.

SAP B1 Approval Failure And Retry​

  • A new individual customer is always saved as a draft first. If the user chooses immediate B1 approval and it fails, Mobile shows an error and replaces the edit screen with that draft's detail screen. Back therefore returns to the draft list rather than the old edit form.
  • The detail screen reloads the draft after an approval failure before choosing actions from its latest status.
  • DRAFT keeps Approve and Reject. SAP_PARTIAL hides those actions and shows Retry approval submission instead.
  • A retry uses POST /customer-draft/:id/retry; on success it reports approval success and exits the detail flow. If it fails, the detail is reloaded again so the available action matches the server status.

Changing person type changes the form and payload, not only the display label.

Data / behaviorIndividual (Individual)Legal entity (company)
Required nameFirst name and last nameCompany/business/organization name in firstname; lastname is cleared
Tax IDHidden and cleared from payloadRequired, digits only, exactly 13 digits
Name limitCombined first/last name: 200 charactersOrganization name: 200 characters
Address branch fieldsRemoved during normalizationShown on BillTo; choose head office or enter a branch
Default BillTo branchNoneEmpty branch becomes 00000 / สำนักงานใหญ่ (head office)
First saveCan choose immediate B1 approval when approval validation passesRemains a draft awaiting review; it can still be edited
Existing SAP customerSaved as a change request awaiting Marketing approvalSame change-request flow

Both types require customer type, acquisition source, delivery type, a 10-digit primary phone, both billing and shipping addresses at approval, and at least one billable branch. A secondary phone is optional but must also be 10 digits when entered. Date of birth, alias and email are optional; the UI converts the selected Buddhist Era birth year to Gregorian year in the payload.

Address Types And Required Fields​

Field / ruleRequirement
TypeRequired: BillTo (billing) or ShipTo (delivery).
Address nameRequired and unique within the same address type for this customer. The same label can exist once in each different type.
Core addressStreet/house number, subdistrict, district, province and postcode are all required. Address search fills administrative fields and applies Bangkok แขวง/เขต formatting.
LandmarkOptional (checkAddressName).
Legal-entity BillTo branchChoose head office, or enter both branch code and name. Code is digits only, max 5, and left-padded to 5 digits. One field without the other is invalid.
Individual / ShipTo branchBranch code and name are cleared on normalization.
RouteRequired only on ShipTo for route-delivery customers (shippingType = 1); cleared from BillTo.
CoordinatesRequired for route-delivery ShipTo; both values must be finite, non-zero numbers. GPS, map picker and manual input are supported.
Auto-create ShipToAvailable while adding a new non-ShipTo address. Creates a second child, clears branch data, and independently validates duplicate name, route and coordinates.

Save vs Approval Validation​

StageChecks
Save draftHeader fields, phone, legal-entity Tax ID; legal entities require BillTo; route customers require ShipTo with route and coordinates.
Approve to B1Rechecks the header; requires both BillTo and ShipTo for every customer; validates all six address fields, legal-entity branch pairs, route/coordinates, duplicate address names, and duplicate billable branches.
Error outputShows the first five validation errors and a remaining count; approval API is not called until valid.

Billable Branch Rules​

  • A resolvable login branch is prepared as the initial billable branch for a new customer.
  • Duplicate branch identities are ignored when adding and rejected during approval.
  • The last billable branch cannot be deleted; at least one must remain.
  • A billable branch controls which operational branch may issue bills. It is separate from the head-office/branch identity stored on a legal entity's BillTo tax address.

Permissions And Guards​

TopicBehavior
Terminal menu keycustomerManagement
deptCode menu set-2, 1, 2, 3, 4, 7, 29, 21, 8, 9, 13, 14, 16, 27, 30
Approval flagapproveCustomer on the user enables approval/rejection controls.
Branch ruleAvailable by customer-management menu permission and selected branch.

Mobile vs POS Terminal​

TopicMobilePOS Terminal
NavigationMultiple stack screens for list/detail/edit/addressSingle detail form with sections and modals
Address editDedicated address detail screensEmbedded section/actions in CustomerManagementDetailForm
Map/locationMobile can request device location/map helpersTerminal form includes map/search helper code where available
ApprovalDRAFT offers approve/reject; SAP_PARTIAL offers retrySame status-based actions in the split detail form

Developer Handoff Map​

AreaCode
Mobile stackapps/mobile/src/screens/customerManagementStack/*
Terminal detailapps/pos-terminal/src/screens/HomeScreen/CustomerManagementDetailForm.tsx
Customer servicesapps/*/src/services/customers.ts
Terminal split dataapps/pos-terminal/src/services/splitMenuData.ts -> customerManagement
Permission sourceuser field approveCustomer and menu deptCode config