Skip to content

Allowances & deductions

  • What allowance categories and deduction categories are, and how they feed into the payroll batch allowance_items / deduction_items lines.
  • How to create / rename / delete a category on the mobile POS workspace.
  • The full set of type values, the calculation method discriminator, and how a category’s numeric value is interpreted.
  • The API surface (GET / POST / PUT / DELETE) and the database schema behind both catalogs.
  • Common pitfalls and the migration story.

Reading order: this page documents the catalog of categories. Once a batch is created, the engine copies the relevant rows into the payslip’s allowance_items / deduction_items JSON. For the full payroll lifecycle, see Payrolls.

Allowances and deductions live in separate tables, not a single kind-discriminated table. They never share a row id.

CatalogTableDefault typeSurfaces in mobile
Allowance categoriesvendor_allowancesdaily_fixedMore → Employees → Settings → Payroll → Allowances
Deduction categoriesvendor_deductionsmonthly_fixedMore → Employees → Settings → Payroll → Deductions

Each row is a (vendor, name) unique pair — names are unique within the vendor scope so duplicate categories can never be created by mistake. A vendor in Cambodia operating in two branches still owns one catalog; both branches share the same rows.

  • The payroll engine queries each catalog independently. A future FK from payslip_lines.allowance_id / payslip_lines.deduction_id to one or the other remains a single-column reference (no kind discriminator to remember in joins).
  • The value spaces differ: allowance type is {daily_fixed, monthly_fixed, monthly_standard_days, per_shift}; deduction type is {monthly_fixed, per_shift, social_insurance, tax, advance}. Splitting the tables keeps the DTO validation (@IsIn([...])) from needing a kind discriminator on every endpoint.
  • Mobile UX mirrors the split — the list screen for each category is identical, and each lives on its own route under the “Payroll” sub-tree.

type is a free-form varchar(64) column on the mobile side (the TypeScript union in allowancesDeductionsApi.ts is the source of truth). Adding a new type is a mobile-only release — no backend migration required.

type valueUI labelWhen it triggers
daily_fixedDaily fixed allowanceAdds the allowance once per worked day in the pay period.
monthly_fixedMonthly fixed allowanceAdds the allowance once per month regardless of days worked.
monthly_standard_daysMonthly allowance (prorated by standard working days)Adds value × (actual_days / standard_days) so the employee is paid in proportion to days worked.
per_shiftPer-shift allowanceAdds the allowance once per shift the employee opens.
type valueUI labelWhen it triggers
monthly_fixedMonthly fixed deductionDeducts once per month regardless of days worked.
per_shiftPer-shift deductionDeducts once per shift.
social_insuranceSocial insurance contributionStatutory social insurance (BHXH-style) — payroll engine computes the legal rate.
taxPersonal income taxPersonal income tax (TNCN) — payroll engine applies the bracket table.
advanceSalary advanceOne-shot advance deduction; cleared when paid.

The persisted type is the raw English enum value, not the localised UI label. Localised labels live in the mobile app’s i18n files (employeeSettings.payroll.allowanceForm.types.daily_fixed / …deductionForm.types.monthly_fixed …).

A separate axis from type. A category is paid either as a flat currency amount or as a percentage of the employee’s base salary.

calculation_methodUI labelvalue interpretation
AMOUNTAmount (currency)A currency amount. The mobile UI shows it with the active store’s currency suffix (e.g. VND).
PERCENTAGE% of base salaryA 0–100 percentage. The payroll line reads BASE × value / 100. Values > 100 are rejected with 400 BadRequest on both create and update.

The currency suffix is store-aware — the same category created by a Vietnam store shows VND, but the same store-level data viewed from a Cambodia store shows KHR. This is driven by useStoreDisplayPreferences() on the mobile side and the active vendor_id + store_id on the backend side.

Open More → Employees → Settings → Payroll → Allowances (or Deductions). When the catalog is empty, the screen shows a centred hero with a file illustration, an empty-state message, and a primary action button.

┌──────────────────────────────────────────────┐
│ < Allowance categories │
├──────────────────────────────────────────────┤
│ │
│ ┌──────────┐ │
│ │ 📄 │ │
│ │ │ │
│ └──────────┘ │
│ │
│ You don't have any │
│ allowances yet │
│ │
│ Add an allowance to start │
│ tracking per-employee perks │
│ │
│ ┌──────────────┐ │
│ │ + Add │ │
│ │ allowance… │ │
│ └──────────────┘ │
│ │
└──────────────────────────────────────────────┘

The list, when populated, shows one row per category:

┌──────────────────────────────────────────────┐
│ < Allowance categories │
├──────────────────────────────────────────────┤
│ ┌──────────────────────────────────────┐ │
│ │ Fuel › │ │
│ │ Daily fixed │ │
│ │ Amount · 50,000 VND │ │
│ └──────────────────────────────────────┘ │
│ ┌──────────────────────────────────────┐ │
│ │ Lunch › │ │
│ │ Monthly fixed │ │
│ │ Amount · 1,000,000 VND │ │
│ └──────────────────────────────────────┘ │
│ ┌──────────────────────────────────────┐ │
│ │ Seniority › │ │
│ │ Monthly (standard days) │ │
│ │ % of base · 12.5 % │ │
│ └──────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────┘

Each row carries:

FieldSource
Name (bold)name (the user-visible label, e.g. “Fuel”, “Lunch”).
TypeResolved via typeLabel(row.type) — the localised UI label, not the raw enum.
Method · Valuee.g. “Amount · 50,000 VND” or ”% of base · 12.5 %”.
ChevronTap → opens the edit form.

A long-press on a row triggers delete with a confirmation toast on success.

Tap the + Add new button (empty state) or any existing row (edit). The form has four fields:

┌──────────────────────────────────────────────┐
│ < Add allowance type [ Save ] │
├──────────────────────────────────────────────┤
│ │
│ Allowance name │
│ ┌────────────────────────────────────┐ │
│ │ Fuel │ │
│ └────────────────────────────────────┘ │
│ │
│ Allowance type │
│ ┌────────────────────────────────────┐ │
│ │ Daily fixed ▾ │ │
│ └────────────────────────────────────┘ │
│ │
│ Calculation method │
│ ◉ Amount │
│ ○ % of base salary │
│ │
│ Value │
│ ┌────────────────────────┐ VND │
│ │ 50,000 │ │
│ └────────────────────────┘ │
│ │
└──────────────────────────────────────────────┘
FieldWhat you enter
Allowance name (name)Free text, 1–191 chars.
Allowance type (type)Single-select bottom sheet — the canonical type value space for allowances (4 options).
Calculation method (calculation_method)Radio group: Amount vs % of base salary. Drives the suffix on the value input.
Value (value)Numeric input. Suffix switches to VND when AMOUNT, % when PERCENTAGE. 0 is allowed (renders as 0 VND / 0 %).

The AppBar’s Save button (top right) is disabled until name is non-empty and value parses as a number. Save calls POST /api/v1/vendor/allowances (create) or PUT /api/v1/vendor/allowances/:id (update) and on success invalidates ["allowances"] so the list refetches.

The edit form pre-fetches the row from the cached list (["allowances"]) before falling back to a single-row GET /api/v1/vendor/allowances/:id. If the row is in the list cache (the common case — the user just tapped the row), the form hydrates instantly without a network round-trip.

StateWhat you see
Loading (initial)Static shell (AppBar + chrome) renders immediately. Three skeleton rows occupy the list area until the query resolves.
ErrorFull-screen error message with a Retry button calling refetch().
EmptyCentred hero + + Add button.
SuccessPopulated list with rows as in V.1.

The static shell renders for the entire loading window per the targeted-skeleton rule — skeletons only appear where dynamic data is being fetched (the list rows and the form’s edit-mode values).

The HR dashboard surfaces the same catalogs under HR → Payroll → Allowances (planned). The vendor-web route will reuse the same NestJS endpoints with the same DTOs; no backend work is pending. Until the vendor-web page ships, the mobile POS workspace is the canonical editor for both catalogs.

MethodPathPurpose
GET/api/v1/vendor/allowancesList all allowance categories for the active vendor. No store_id — categories are vendor-scoped.
GET/api/v1/vendor/allowances/:idOne category.
POST/api/v1/vendor/allowancesCreate. Body: { name, type, calculation_method, value }. Rejects duplicate (vendor_id, name) with 400.
PUT/api/v1/vendor/allowances/:idPartial update. Only the keys you send are written.
DELETE/api/v1/vendor/allowances/:idRemove. Cascades nothing — payslips that already reference the category keep their JSON snapshot.
GET/api/v1/vendor/deductionsSame shape for deductions.
GET/api/v1/vendor/deductions/:id”
POST/api/v1/vendor/deductions”
PUT/api/v1/vendor/deductions/:id”
DELETE/api/v1/vendor/deductions/:id”

All routes require the vendor JWT (@UseGuards(VendorJwtAuthGuard)); vendor_id is read from the JWT and is not a query param. The service layer rejects unknown type values (checked against the canonical VENDOR_ALLOWANCE_TYPE_VALUES / VENDOR_DEDUCTION_TYPE_VALUES enums) and PERCENTAGE > 100 with 400 BadRequest. Cross-vendor id (e.g. another vendor’s category id) resolves to 404 NotFound to avoid leaking ids.

DDL is written with the TypeORM object-form (new Table({...})) so the DDL stays in lockstep with the entity decorators.

vendor_allowances:

ColumnTypeNotes
idchar(13)Crockford Base32, minted by PublicIdSubscriber.
vendor_idchar(13)Owning vendor (FK to vendors.id).
namevarchar(191)Display label. Unique per vendor_id.
typevarchar(64)Free-form discriminator — see §III.
calculation_methodvarchar(16)AMOUNT | PERCENTAGE.
valuedecimal(15,2)Numeric value. AMOUNT rows store the currency amount; PERCENTAGE rows store the 0..100 percentage.
sort_orderint unsignedStable sort order (lower first). Default 0.
created_at, updated_atdatetime(6)Timestamps.

Indexes:

  • idx_vendor_allowances_vendor on (vendor_id) — list query path.
  • uniq_vendor_allowances_vendor_name on (vendor_id, name) — duplicate-name gate.

vendor_deductions mirrors vendor_allowances 1:1 — same column types, same indexes (with deduction in place of allowance), same fp(...) prefix rules. The default type is monthly_fixed instead of daily_fixed.

DDL lives in apps/backend/src/database/migrations/2000000000212-CreateVendorAllowanceAndDeductionTables.ts. Entities are apps/backend/src/database/entities/vendor-allowance.entity.ts and vendor-deduction.entity.ts.

  • Cross-store leakage never happens at this layer. Both tables are vendor-scoped, not store-scoped — every store in the same vendor sees the same catalog rows.
  • type is free-form on the DB but validated at the service layer. If the mobile app extends the enum without a backend release, the new value passes the column constraint (varchar(64)) and is caught by the service’s @IsIn([...]). The wire payload always returns the canonical enum value.
  • Editing a category does not retroactively re-derive payslip allowance_items / deduction_items lines. The payslip stores its own JSON snapshot, so renaming or repricing a category only affects batches created after the edit. This matches the wage engine upstream — payslips are user-edited numbers, not derived values.
  • Deleting a category in use. Existing payslips that referenced it keep their JSON snapshot. The mobile form pre-populates from the list cache; if the row was deleted server-side before the user opened the form, the form falls back to a single-row GET /:id and surfaces an error toast.
  • Percentage values must be 0–100. value = 150 with calculation_method = PERCENTAGE is rejected with 400. The mobile form does not enforce this client-side — it relies on the backend response.
  • Migration ordering. The new tables are introduced by migration 2000000000212-CreateVendorAllowanceAndDeductionTables.ts. If the deployment targets an environment where migration < 212 has not yet run (e.g. a half-applied cutover), the tables are absent and the API returns ER_NO_SUCH_TABLE instead of 404 — re-run pending migrations before opening the editor.

X. Where this feeds into the payroll engine

Section titled “X. Where this feeds into the payroll engine”

When a payslip is generated for an employee during a pay period, the wage engine reads every category for the vendor (no per-store filtering) and emits one allowance_items / deduction_items row per category whose trigger fires for that employee. The line’s total is computed by the engine from category.value × the trigger’s multiplier (days, shifts, base-salary percentage). The mobile editor only defines the categories — it does not run the engine.

See Payrolls → §IV for the payslip layout, including the allowance_items / deduction_items JSON shape.