demo_emp_types: Departments and Employees

Two independent classification axes on Employee (employment type, military status), with the business rules that govern them.

1. The things this system knows about

Commission Order

Table commission_order. Named Order here per the requirement's wording.

Each Commission Order has at most one Commissioned Employee via sold by — commission_order.employee_id. Range CommissionedEmployee: only commissioned employees may have orders.

FieldKind of valueNotes
Amountamount
Customer nametext

Department

Each Department has many Employee via has employee

FieldKind of valueNotes
Budgetamount
Nametext
Total salaryamountcomputed by rule “Department.total_salary = sum(Employee.salary)”

Employee

Each Employee has at most one System Configuration via governed by — employee.sys_config_id. Source of copied thresholds/rates.

Each Employee has at most one Department via works in — employee.dept_id (required).

FieldKind of valueNotes
Employee typeone of: salaried, hourly, commissionedColumn employee.type. (JSON:API wire name is 'Type'.)
Max hourly weekly salaryamountcomputed by rule “Employee.max_hourly_weekly_salary copied from SysConfig”
Militaryone of: yes, noColumn employee.military.
Military stipendnumbercomputed by rule “military_stipend = service_years * rate (military only, else 0)” 0 for non-military employees.
Military stipend rate per yearnumbercomputed by rule “Employee.military_stipend_rate_per_year copied from SysConfig”
Nametext
Salaryamountcomputed by rule “Employee.salary, by employment type” Derived for hourly and commissioned; entered directly for salaried.
Total compensationamountcomputed by rule “total_compensation = salary + military_stipend”

Labor Union

Each Labor Union has many Hourly Employee via has member

FieldKind of valueNotes
Dues ratenumber
Nametext

System Configuration

Singleton of global, runtime-configurable settings (rates and thresholds).

FieldKind of valueNotes
Max hourly weekly salary configamountsys_config.max_hourly_weekly_salary (source of the copy).
Military stipend rate per yearnumbercomputed by rule “Employee.military_stipend_rate_per_year copied from SysConfig”

2. Kinds of Employee

Employees are classified two independent ways. Every employee is one kind on the first axis, and may also be military.

By employee type

Exactly one of these:

Commissioned Employee employee type = commissioned

Commission Order records can belong only to this kind of employee.

FieldKind of valueNotes
Base salaryamount
Commission totalamountcomputed by rule “Commissioned commission_total = sum(Order.amount)”

Hourly Employee employee type = hourly

May have a Labor Union. No other kind of employee can.

FieldKind of valueNotes
Hourly ratenumber
Hours workednumber
Union duesamountcomputed by rule “Hourly union_dues = hours_worked * union.dues_rate”

Salaried Employee employee type = salaried

No additional fields. Salary is entered directly.

By military

Independent of the other classification:

Military Employee military = yes

FieldKind of valueNotes
Branchone of: Army, Navy, Air Force, Marines, Coast Guard
Ranktext
Service yearswhole number

3. Business rules

Each rule is enforced automatically on every change, and traces to the requirement that asked for it. added by AI marks rules nobody asked for in the requirements, so a person should confirm them.

Department Budget

RuleTypeRequirement
Department total_salary must not exceed budgetCheckDepartment.total_salary must not exceed Department.budget.
If violated: Department total_salary ([total_salary]) exceeds budget ([budget])
Department.total_salary = sum(Employee.salary)TotalDepartment.total_salary = sum of Employee.salary (all types).

Employee Compensation

RuleTypeRequirement
Commissioned commission_total = sum(Order.amount)TotalCommissioned employees: commission_total = sum of Order.amount.
Employee.max_hourly_weekly_salary copied from SysConfigCopied valueHourly employees: salary must not exceed 5000 per week. (threshold lives in SysConfig, not a literal)
Hourly salary must not exceed weekly capCheckHourly employees: salary must not exceed 5000 per week.
If violated: Hourly salary ([salary]) exceeds weekly cap ([max_hourly_weekly_salary])
base_salary null unless commissioned
added by AI
Check(inferred from single-table inheritance)
If violated: base_salary must be null for non-commissioned employees
hours_worked null unless hourly
added by AI
Check(inferred from single-table inheritance: subtype columns are null for other types)
If violated: hours_worked must be null for non-hourly employees
hourly_rate null unless hourly
added by AI
Check(inferred from single-table inheritance)
If violated: hourly_rate must be null for non-hourly employees
Order amount > 0
added by AI
Check(not stated; domain-standard validation added by the AI, see ad-libs.md)
If violated: Order amount ([amount]) must be greater than 0
Orders only for commissioned employeesCheckCommissioned employees are employees who can have Orders; only Commissioned employees may have Orders.
If violated: Orders can only be assigned to commissioned employees
Employee.salary, by employment typeCalculationHourly employees: salary = hours_worked * hourly_rate. Commissioned employees: salary = base_salary + commission_total.
Hourly union_dues = hours_worked * union.dues_rateCalculationHourly employees: union_dues = hours_worked * union.dues_rate (0 if no union assigned).
Only hourly employees may have a unionCheckHourly employees may be assigned to a Union (optional); only Hourly employees may have a union_id.
If violated: union_id must be null for non-hourly employees

Military Classification

RuleTypeRequirement
Employee.military_stipend_rate_per_year copied from SysConfigCopied valueMilitary employees receive a military_stipend (REAL) = service_years * 100. (the 100 lives in SysConfig)
military_stipend = service_years * rate (military only, else 0)CalculationMilitary employees receive a military_stipend (REAL) = service_years * 100.
branch null unless military
added by AI
Check(inferred from the military classification axis)
If violated: branch must be null for non-military employees
rank null unless military
added by AI
Check(inferred from the military classification axis)
If violated: rank must be null for non-military employees
service_years null unless military
added by AI
Check(inferred from the military classification axis)
If violated: service_years must be null for non-military employees
total_compensation = salary + military_stipendCalculationTotal compensation for military employees = salary + military_stipend. Total compensation for non-military employees = salary.
branch must be a recognized service branchCheckMilitary employees have a branch (TEXT: 'Army', 'Navy', 'Air Force', 'Marines', 'Coast Guard')
If violated: branch ([branch]) is not a recognized military branch