Files
data-entry-app/frontend/src/lib/mock.ts
T

499 lines
14 KiB
TypeScript
Raw Normal View History

2026-04-25 22:51:36 +12:00
import type {
ClientAccessAccount,
ClientAccessPowerBiExport,
Mix,
Product,
ProductCostBreakdown,
RawMaterial,
Scenario
} from '$lib/types';
2026-04-25 20:43:37 +12:00
const MODULE_PERMISSIONS = {
superadmin: {
dashboard: 'edit',
raw_materials: 'edit',
mix_master: 'edit',
products: 'edit',
scenarios: 'edit',
powerbi_export: 'edit',
client_access: 'manage'
},
operator: {
dashboard: 'edit',
raw_materials: 'edit',
mix_master: 'edit',
products: 'edit',
scenarios: 'edit',
powerbi_export: 'none',
client_access: 'none'
},
viewer: {
dashboard: 'view',
raw_materials: 'none',
mix_master: 'none',
products: 'view',
scenarios: 'none',
powerbi_export: 'view',
client_access: 'none'
}
} as const;
const MODULE_DETAILS = [
['dashboard', 'Dashboard', 'workspace', 'Top-level operational dashboard'],
['raw_materials', 'Raw Materials', 'costing', 'Maintain live material costs and versions'],
['mix_master', 'Mix Master', 'costing', 'Create and maintain mix worksheets'],
['products', 'Products', 'pricing', 'Review finished product pricing'],
['scenarios', 'Scenarios', 'planning', 'Run scenario overrides and comparisons'],
['powerbi_export', 'Power BI Export', 'reporting', 'Expose client access data to BI consumers'],
['client_access', 'Client Access', 'administration', 'Manage user access, module permissions, and audit history']
] as const;
2026-04-25 20:43:37 +12:00
export const mockRawMaterials: RawMaterial[] = [
{
id: 1,
name: 'Maize',
unit_of_measure: 'tonne',
kg_per_unit: 1000,
status: 'active',
current_price: {
market_value: 520,
waste_percentage: 0.02,
cost_per_kg: 0.5304,
effective_date: '2026-04-01'
}
},
{
id: 2,
name: 'Barley',
unit_of_measure: 'tonne',
kg_per_unit: 1000,
status: 'active',
current_price: {
market_value: 470,
waste_percentage: 0.015,
cost_per_kg: 0.4771,
effective_date: '2026-04-01'
}
}
];
export const mockMixes: Mix[] = [
{
id: 1,
2026-04-25 22:51:36 +12:00
client_name: 'Hunter Premium Produce',
name: 'Hunter Orchard Blend',
2026-04-25 20:43:37 +12:00
status: 'active',
ingredients: [
{
id: 1,
raw_material_id: 1,
raw_material_name: 'Maize',
quantity_kg: 180,
cost_per_kg: 0.5304,
line_cost: 95.472
},
{
id: 2,
raw_material_id: 2,
raw_material_name: 'Barley',
quantity_kg: 100,
cost_per_kg: 0.4771,
line_cost: 47.71
}
],
total_mix_kg: 280,
total_mix_cost: 143.18,
mix_cost_per_kg: 0.5114,
warnings: []
}
];
export const mockProducts: Product[] = [
{
id: 1,
2026-04-25 22:51:36 +12:00
name: 'Hunter Orchard Blend 20kg',
client_name: 'Hunter Premium Produce',
2026-04-25 20:43:37 +12:00
mix_id: 1,
2026-04-25 22:51:36 +12:00
mix_name: 'Hunter Orchard Blend',
2026-04-25 20:43:37 +12:00
sale_type: 'standard',
unit_of_measure: '20kg bag',
distributor_margin: 0.225,
wholesale_margin: 0.18
}
];
export const mockCosts: ProductCostBreakdown[] = [
{
product_id: 1,
2026-04-25 22:51:36 +12:00
product_name: 'Hunter Orchard Blend 20kg',
2026-04-27 21:53:36 +12:00
client_name: 'Hunter Premium Produce',
mix_name: 'Hunter Orchard Blend',
2026-04-25 20:43:37 +12:00
finished_product_delivered: 14.208,
distributor_price: 18.3329,
wholesale_price: 17.3268,
warnings: []
}
];
export const mockScenarios: Scenario[] = [
{
id: 1,
name: 'Current Standard',
status: 'approved',
description: 'Baseline approved pricing',
overrides: {}
}
];
2026-04-25 22:51:36 +12:00
export const mockClientAccess: ClientAccessAccount[] = [
{
id: 1,
tenant_id: 'hunter-premium-produce',
name: 'Hunter Premium Produce',
client_code: 'HPP',
status: 'active',
powerbi_workspace: 'hunter-premium-produce-prod',
notes: 'Primary production client for the Lean 101 admin and access workflows',
created_at: '2026-04-20T09:00:00',
active_user_count: 1,
new_user_count: 1,
enabled_feature_count: 7,
total_feature_count: 7,
2026-04-25 22:51:36 +12:00
users: [
{
id: 1,
client_account_id: 1,
full_name: 'Amelia Hart',
email: 'operator@example.com',
role: 'superadmin',
2026-04-25 22:51:36 +12:00
status: 'active',
is_new_user: false,
last_login_at: '2026-04-24T11:30:00',
created_at: '2026-04-20T09:00:00',
module_permissions: MODULE_DETAILS.map(([module_key, module_name, module_group, description], index) => ({
id: index + 1,
client_account_id: 1,
client_user_id: 1,
module_key,
module_name,
module_group,
description,
access_level: MODULE_PERMISSIONS.superadmin[module_key],
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
}))
2026-04-25 22:51:36 +12:00
},
{
id: 2,
client_account_id: 1,
full_name: 'Ethan Cole',
email: 'ethan.cole@hunterpremiumproduce.example',
role: 'operator',
status: 'invited',
is_new_user: true,
last_login_at: null,
created_at: '2026-04-24T15:00:00',
module_permissions: MODULE_DETAILS.map(([module_key, module_name, module_group, description], index) => ({
id: index + 101,
client_account_id: 1,
client_user_id: 2,
module_key,
module_name,
module_group,
description,
access_level: MODULE_PERMISSIONS.operator[module_key],
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-24T15:00:00'
}))
2026-04-25 22:51:36 +12:00
}
],
features: [
{
id: 1,
client_account_id: 1,
feature_key: 'dashboard',
feature_name: 'Dashboard',
feature_group: 'workspace',
description: 'Top-level operational dashboard',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
},
{
id: 2,
client_account_id: 1,
feature_key: 'raw_materials',
feature_name: 'Raw Materials',
feature_group: 'costing',
description: 'Maintain live material costs and versions',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
},
{
id: 3,
client_account_id: 1,
feature_key: 'mix_master',
feature_name: 'Mix Master',
feature_group: 'costing',
description: 'Create and maintain mix worksheets',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
},
{
id: 4,
client_account_id: 1,
feature_key: 'products',
feature_name: 'Products',
feature_group: 'pricing',
description: 'Review finished product pricing',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
},
{
id: 5,
client_account_id: 1,
feature_key: 'scenarios',
feature_name: 'Scenarios',
feature_group: 'planning',
description: 'Run scenario overrides and comparisons',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
},
{
id: 6,
client_account_id: 1,
feature_key: 'powerbi_export',
feature_name: 'Power BI Export',
feature_group: 'reporting',
description: 'Expose client access data to BI consumers',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
},
{
id: 13,
client_account_id: 1,
feature_key: 'client_access',
feature_name: 'Client Access',
feature_group: 'administration',
description: 'Manage user access, module permissions, and audit history',
enabled: true,
updated_at: '2026-04-24T15:00:00',
created_at: '2026-04-20T09:00:00'
}
],
audit_history: [
{
id: 1,
client_account_id: 1,
actor_type: 'lean_admin',
actor_name: 'Lean 101 Seeder',
actor_email: 'system@lean101.local',
actor_role: 'system',
action: 'client_access.seeded',
target_type: 'client_account',
target_id: 1,
module_key: 'client_access',
summary: 'Initial client access controls, module permissions, and feature flags were seeded.',
created_at: '2026-04-20T09:00:00'
2026-04-25 22:51:36 +12:00
}
]
},
{
id: 2,
tenant_id: 'loft-grains',
name: 'Loft Grains',
client_code: 'LOFT',
status: 'onboarding',
powerbi_workspace: 'farm-ops-sandbox',
notes: 'Onboarding workspace used to test staged user enablement',
created_at: '2026-04-21T10:00:00',
active_user_count: 1,
new_user_count: 0,
enabled_feature_count: 3,
total_feature_count: 7,
2026-04-25 22:51:36 +12:00
users: [
{
id: 3,
client_account_id: 2,
full_name: 'Ruby Singh',
email: 'ruby.singh@loftgrains.example',
role: 'viewer',
status: 'active',
is_new_user: false,
last_login_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00',
module_permissions: MODULE_DETAILS.map(([module_key, module_name, module_group, description], index) => ({
id: index + 201,
client_account_id: 2,
client_user_id: 3,
module_key,
module_name,
module_group,
description,
access_level: MODULE_PERMISSIONS.viewer[module_key],
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
}))
2026-04-25 22:51:36 +12:00
}
],
features: [
{
id: 7,
client_account_id: 2,
feature_key: 'dashboard',
feature_name: 'Dashboard',
feature_group: 'workspace',
description: 'Top-level operational dashboard',
enabled: true,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
},
{
id: 8,
client_account_id: 2,
feature_key: 'raw_materials',
feature_name: 'Raw Materials',
feature_group: 'costing',
description: 'Maintain live material costs and versions',
enabled: false,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
},
{
id: 9,
client_account_id: 2,
feature_key: 'mix_master',
feature_name: 'Mix Master',
feature_group: 'costing',
description: 'Create and maintain mix worksheets',
enabled: false,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
},
{
id: 10,
client_account_id: 2,
feature_key: 'products',
feature_name: 'Products',
feature_group: 'pricing',
description: 'Review finished product pricing',
enabled: true,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
},
{
id: 11,
client_account_id: 2,
feature_key: 'scenarios',
feature_name: 'Scenarios',
feature_group: 'planning',
description: 'Run scenario overrides and comparisons',
enabled: false,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
},
{
id: 12,
client_account_id: 2,
feature_key: 'powerbi_export',
feature_name: 'Power BI Export',
feature_group: 'reporting',
description: 'Expose client access data to BI consumers',
enabled: true,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
},
{
id: 14,
client_account_id: 2,
feature_key: 'client_access',
feature_name: 'Client Access',
feature_group: 'administration',
description: 'Manage user access, module permissions, and audit history',
enabled: false,
updated_at: '2026-04-22T09:10:00',
created_at: '2026-04-21T10:00:00'
2026-04-25 22:51:36 +12:00
}
],
audit_history: []
2026-04-25 22:51:36 +12:00
}
];
export const mockClientAccessExport: ClientAccessPowerBiExport = {
generated_at: '2026-04-25T09:00:00',
client_rows: mockClientAccess.map((client) => ({
client_id: client.id,
tenant_id: client.tenant_id,
client_name: client.name,
client_code: client.client_code,
client_status: client.status,
powerbi_workspace: client.powerbi_workspace,
active_user_count: client.active_user_count,
new_user_count: client.new_user_count,
enabled_feature_count: client.enabled_feature_count,
total_feature_count: client.total_feature_count
})),
user_rows: mockClientAccess.flatMap((client) =>
client.users.map((user) => ({
client_id: client.id,
client_name: client.name,
user_id: user.id,
full_name: user.full_name,
email: user.email,
role: user.role,
status: user.status,
is_new_user: user.is_new_user,
last_login_at: user.last_login_at,
created_at: user.created_at
}))
),
feature_rows: mockClientAccess.flatMap((client) =>
client.features.map((feature) => ({
client_id: client.id,
client_name: client.name,
feature_id: feature.id,
feature_key: feature.feature_key,
feature_name: feature.feature_name,
feature_group: feature.feature_group,
enabled: feature.enabled,
updated_at: feature.updated_at
}))
),
permission_rows: mockClientAccess.flatMap((client) =>
client.users.flatMap((user) =>
user.module_permissions.map((permission) => ({
client_id: client.id,
client_name: client.name,
user_id: user.id,
user_email: user.email,
module_key: permission.module_key,
module_name: permission.module_name,
module_group: permission.module_group,
access_level: permission.access_level,
updated_at: permission.updated_at
}))
)
),
audit_rows: mockClientAccess.flatMap((client) =>
client.audit_history.map((event) => ({
client_id: client.id,
client_name: client.name,
event_id: event.id,
actor_email: event.actor_email,
actor_role: event.actor_role,
action: event.action,
target_type: event.target_type,
target_id: event.target_id,
module_key: event.module_key,
summary: event.summary,
created_at: event.created_at
}))
),
2026-04-25 22:51:36 +12:00
clients: mockClientAccess
};