@tailor-platform/erp-kit 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/cli.mjs +139 -35
- package/package.json +1 -1
- package/skills/erp-kit-app-5-impl-backend/SKILL.md +10 -5
- package/skills/erp-kit-app-7-impl-review/SKILL.md +1 -1
- package/skills/erp-kit-module-6-impl-review/SKILL.md +39 -17
- package/src/commands/generate-doc.ts +1 -1
- package/src/commands/init-module.test.ts +17 -3
- package/src/commands/init-module.ts +0 -12
- package/src/commands/lib/discovery.test.ts +13 -3
- package/src/commands/lib/discovery.ts +10 -2
- package/src/commands/lib/paths.ts +4 -2
- package/src/commands/lib/sync-check-tests.test.ts +84 -6
- package/src/commands/lib/sync-check-tests.ts +63 -3
- package/src/commands/sync-check.ts +7 -3
- package/src/generator/generate-app-code.ts +51 -16
- package/src/generator/generate-code-boilerplate.test.ts +9 -1
- package/src/generator/generate-stubs.ts +4 -0
- package/src/generator/scaffold.ts +6 -2
- package/src/generator/stub-templates.test.ts +11 -0
- package/src/generator/stub-templates.ts +22 -1
- package/src/mdschema.ts +39 -3
- package/src/modules/inventory/docs/features/inventory-adjustment.md +2 -1
- package/src/modules/inventory/docs/features/scrap-management.md +39 -1
- package/src/modules/manufacturing/README.md +63 -0
- package/src/modules/manufacturing/command/activateBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/activateBillOfMaterial.test.ts +166 -0
- package/src/modules/manufacturing/command/activateBillOfMaterial.ts +173 -0
- package/src/modules/manufacturing/command/activateRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/activateRouting.test.ts +152 -0
- package/src/modules/manufacturing/command/activateRouting.ts +92 -0
- package/src/modules/manufacturing/command/activateWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/activateWorkCenter.test.ts +135 -0
- package/src/modules/manufacturing/command/activateWorkCenter.ts +91 -0
- package/src/modules/manufacturing/command/cancelProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/cancelProductionOrder.test.ts +151 -0
- package/src/modules/manufacturing/command/cancelProductionOrder.ts +114 -0
- package/src/modules/manufacturing/command/closeProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/closeProductionOrder.test.ts +126 -0
- package/src/modules/manufacturing/command/closeProductionOrder.ts +87 -0
- package/src/modules/manufacturing/command/completeProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/completeProductionOrder.test.ts +132 -0
- package/src/modules/manufacturing/command/completeProductionOrder.ts +97 -0
- package/src/modules/manufacturing/command/completeWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/completeWorkOrder.test.ts +369 -0
- package/src/modules/manufacturing/command/completeWorkOrder.ts +212 -0
- package/src/modules/manufacturing/command/createBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/createBillOfMaterial.test.ts +210 -0
- package/src/modules/manufacturing/command/createBillOfMaterial.ts +176 -0
- package/src/modules/manufacturing/command/createProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/createProductionOrder.test.ts +160 -0
- package/src/modules/manufacturing/command/createProductionOrder.ts +129 -0
- package/src/modules/manufacturing/command/createRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/createRouting.test.ts +168 -0
- package/src/modules/manufacturing/command/createRouting.ts +128 -0
- package/src/modules/manufacturing/command/createWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/createWorkCenter.test.ts +148 -0
- package/src/modules/manufacturing/command/createWorkCenter.ts +131 -0
- package/src/modules/manufacturing/command/deactivateBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/deactivateBillOfMaterial.test.ts +103 -0
- package/src/modules/manufacturing/command/deactivateBillOfMaterial.ts +78 -0
- package/src/modules/manufacturing/command/deactivateRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/deactivateRouting.test.ts +112 -0
- package/src/modules/manufacturing/command/deactivateRouting.ts +76 -0
- package/src/modules/manufacturing/command/deactivateWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/deactivateWorkCenter.test.ts +113 -0
- package/src/modules/manufacturing/command/deactivateWorkCenter.ts +85 -0
- package/src/modules/manufacturing/command/pauseWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/pauseWorkOrder.test.ts +118 -0
- package/src/modules/manufacturing/command/pauseWorkOrder.ts +82 -0
- package/src/modules/manufacturing/command/recordInventoryIssueOutcome.generated.ts +6 -0
- package/src/modules/manufacturing/command/recordInventoryIssueOutcome.test.ts +183 -0
- package/src/modules/manufacturing/command/recordInventoryIssueOutcome.ts +139 -0
- package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.generated.ts +6 -0
- package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.test.ts +120 -0
- package/src/modules/manufacturing/command/recordManufacturingCostSettlementAcknowledgment.ts +110 -0
- package/src/modules/manufacturing/command/releaseProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/releaseProductionOrder.test.ts +220 -0
- package/src/modules/manufacturing/command/releaseProductionOrder.ts +450 -0
- package/src/modules/manufacturing/command/reopenProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/reopenProductionOrder.test.ts +196 -0
- package/src/modules/manufacturing/command/reopenProductionOrder.ts +98 -0
- package/src/modules/manufacturing/command/reportWorkOrderProgress.generated.ts +6 -0
- package/src/modules/manufacturing/command/reportWorkOrderProgress.test.ts +204 -0
- package/src/modules/manufacturing/command/reportWorkOrderProgress.ts +129 -0
- package/src/modules/manufacturing/command/rescheduleProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/rescheduleProductionOrder.test.ts +185 -0
- package/src/modules/manufacturing/command/rescheduleProductionOrder.ts +95 -0
- package/src/modules/manufacturing/command/resumeWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/resumeWorkOrder.test.ts +122 -0
- package/src/modules/manufacturing/command/resumeWorkOrder.ts +94 -0
- package/src/modules/manufacturing/command/reviewManufacturingCostSummary.generated.ts +6 -0
- package/src/modules/manufacturing/command/reviewManufacturingCostSummary.test.ts +231 -0
- package/src/modules/manufacturing/command/reviewManufacturingCostSummary.ts +137 -0
- package/src/modules/manufacturing/command/startWorkOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/startWorkOrder.test.ts +118 -0
- package/src/modules/manufacturing/command/startWorkOrder.ts +126 -0
- package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.test.ts +153 -0
- package/src/modules/manufacturing/command/technicallyCompleteProductionOrder.ts +106 -0
- package/src/modules/manufacturing/command/unreleaseProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/unreleaseProductionOrder.test.ts +140 -0
- package/src/modules/manufacturing/command/unreleaseProductionOrder.ts +131 -0
- package/src/modules/manufacturing/command/updateBillOfMaterial.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateBillOfMaterial.test.ts +149 -0
- package/src/modules/manufacturing/command/updateBillOfMaterial.ts +174 -0
- package/src/modules/manufacturing/command/updateProductionOrder.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateProductionOrder.test.ts +112 -0
- package/src/modules/manufacturing/command/updateProductionOrder.ts +145 -0
- package/src/modules/manufacturing/command/updateRouting.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateRouting.test.ts +211 -0
- package/src/modules/manufacturing/command/updateRouting.ts +124 -0
- package/src/modules/manufacturing/command/updateWorkCenter.generated.ts +6 -0
- package/src/modules/manufacturing/command/updateWorkCenter.test.ts +152 -0
- package/src/modules/manufacturing/command/updateWorkCenter.ts +137 -0
- package/src/modules/manufacturing/db/.gitkeep +0 -0
- package/src/modules/manufacturing/db/billOfMaterial.ts +70 -0
- package/src/modules/manufacturing/db/billOfMaterialLine.ts +49 -0
- package/src/modules/manufacturing/db/costVarianceLine.ts +53 -0
- package/src/modules/manufacturing/db/manufacturingCostLine.ts +35 -0
- package/src/modules/manufacturing/db/manufacturingCostSettlementRecord.ts +39 -0
- package/src/modules/manufacturing/db/manufacturingCostSummary.ts +59 -0
- package/src/modules/manufacturing/db/productionOrder.ts +83 -0
- package/src/modules/manufacturing/db/productionOrderBomSnapshot.ts +44 -0
- package/src/modules/manufacturing/db/productionOrderCostBaseline.ts +44 -0
- package/src/modules/manufacturing/db/productionOrderMaterialRequirement.ts +57 -0
- package/src/modules/manufacturing/db/productionOrderRoutingSnapshot.ts +43 -0
- package/src/modules/manufacturing/db/routing.ts +63 -0
- package/src/modules/manufacturing/db/routingOperation.ts +57 -0
- package/src/modules/manufacturing/db/workCenter.ts +87 -0
- package/src/modules/manufacturing/db/workOrder.ts +65 -0
- package/src/modules/manufacturing/db/workOrderExecutionEvent.ts +54 -0
- package/src/modules/manufacturing/docs/commands/ActivateBillOfMaterial.md +50 -0
- package/src/modules/manufacturing/docs/commands/ActivateRouting.md +48 -0
- package/src/modules/manufacturing/docs/commands/ActivateWorkCenter.md +49 -0
- package/src/modules/manufacturing/docs/commands/CancelProductionOrder.md +48 -0
- package/src/modules/manufacturing/docs/commands/CloseProductionOrder.md +46 -0
- package/src/modules/manufacturing/docs/commands/CompleteProductionOrder.md +48 -0
- package/src/modules/manufacturing/docs/commands/CompleteWorkOrder.md +66 -0
- package/src/modules/manufacturing/docs/commands/CreateBillOfMaterial.md +54 -0
- package/src/modules/manufacturing/docs/commands/CreateProductionOrder.md +49 -0
- package/src/modules/manufacturing/docs/commands/CreateRouting.md +50 -0
- package/src/modules/manufacturing/docs/commands/CreateWorkCenter.md +51 -0
- package/src/modules/manufacturing/docs/commands/DeactivateBillOfMaterial.md +45 -0
- package/src/modules/manufacturing/docs/commands/DeactivateRouting.md +45 -0
- package/src/modules/manufacturing/docs/commands/DeactivateWorkCenter.md +45 -0
- package/src/modules/manufacturing/docs/commands/PauseWorkOrder.md +44 -0
- package/src/modules/manufacturing/docs/commands/RecordInventoryIssueOutcome.md +59 -0
- package/src/modules/manufacturing/docs/commands/RecordManufacturingCostSettlementAcknowledgment.md +49 -0
- package/src/modules/manufacturing/docs/commands/ReleaseProductionOrder.md +57 -0
- package/src/modules/manufacturing/docs/commands/ReopenProductionOrder.md +54 -0
- package/src/modules/manufacturing/docs/commands/ReportWorkOrderProgress.md +53 -0
- package/src/modules/manufacturing/docs/commands/RescheduleProductionOrder.md +45 -0
- package/src/modules/manufacturing/docs/commands/ResumeWorkOrder.md +44 -0
- package/src/modules/manufacturing/docs/commands/ReviewManufacturingCostSummary.md +52 -0
- package/src/modules/manufacturing/docs/commands/StartWorkOrder.md +46 -0
- package/src/modules/manufacturing/docs/commands/TechnicallyCompleteProductionOrder.md +51 -0
- package/src/modules/manufacturing/docs/commands/UnreleaseProductionOrder.md +46 -0
- package/src/modules/manufacturing/docs/commands/UpdateBillOfMaterial.md +48 -0
- package/src/modules/manufacturing/docs/commands/UpdateProductionOrder.md +48 -0
- package/src/modules/manufacturing/docs/commands/UpdateRouting.md +52 -0
- package/src/modules/manufacturing/docs/commands/UpdateWorkCenter.md +48 -0
- package/src/modules/manufacturing/docs/features/bill-of-material-management.md +83 -0
- package/src/modules/manufacturing/docs/features/manufacturing-cost-and-variance.md +191 -0
- package/src/modules/manufacturing/docs/features/production-order-lifecycle.md +103 -0
- package/src/modules/manufacturing/docs/features/routing-and-work-center-definition.md +63 -0
- package/src/modules/manufacturing/docs/features/work-order-execution.md +115 -0
- package/src/modules/manufacturing/docs/models/BillOfMaterial.md +60 -0
- package/src/modules/manufacturing/docs/models/ManufacturingCostSummary.md +66 -0
- package/src/modules/manufacturing/docs/models/ProductionOrder.md +76 -0
- package/src/modules/manufacturing/docs/models/Routing.md +58 -0
- package/src/modules/manufacturing/docs/models/WorkCenter.md +56 -0
- package/src/modules/manufacturing/docs/models/WorkOrder.md +63 -0
- package/src/modules/manufacturing/docs/queries/DetectBillOfMaterialCircularReference.md +39 -0
- package/src/modules/manufacturing/docs/queries/ExplodeBillOfMaterial.md +56 -0
- package/src/modules/manufacturing/docs/queries/GetBillOfMaterial.md +37 -0
- package/src/modules/manufacturing/docs/queries/GetManufacturingCostSummary.md +39 -0
- package/src/modules/manufacturing/docs/queries/GetProductionOrder.md +37 -0
- package/src/modules/manufacturing/docs/queries/GetRouting.md +39 -0
- package/src/modules/manufacturing/docs/queries/GetWorkCenter.md +35 -0
- package/src/modules/manufacturing/docs/queries/GetWorkOrder.md +38 -0
- package/src/modules/manufacturing/docs/queries/ListBillOfMaterialsByItem.md +42 -0
- package/src/modules/manufacturing/docs/queries/ListManufacturingCostSummariesByStatus.md +41 -0
- package/src/modules/manufacturing/docs/queries/ListProductionOrdersByStatus.md +41 -0
- package/src/modules/manufacturing/docs/queries/ListRoutingsByItem.md +42 -0
- package/src/modules/manufacturing/docs/queries/ListWorkCentersBySite.md +38 -0
- package/src/modules/manufacturing/docs/queries/ListWorkOrdersByProductionOrder.md +39 -0
- package/src/modules/manufacturing/docs/queries/ListWorkOrdersByWorkCenter.md +43 -0
- package/src/modules/manufacturing/executor/.gitkeep +0 -0
- package/src/modules/manufacturing/generated/enums.ts +113 -0
- package/src/modules/manufacturing/generated/kysely-tailordb.ts +247 -0
- package/src/modules/manufacturing/index.ts +2 -0
- package/src/modules/manufacturing/lib/_db_deps.ts +22 -0
- package/src/modules/manufacturing/lib/errors.generated.ts +592 -0
- package/src/modules/manufacturing/lib/permissions.generated.ts +35 -0
- package/src/modules/manufacturing/lib/types.ts +111 -0
- package/src/modules/manufacturing/module.ts +226 -0
- package/src/modules/manufacturing/permissions.ts +3 -0
- package/src/modules/manufacturing/query/.gitkeep +0 -0
- package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.generated.ts +5 -0
- package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.test.ts +115 -0
- package/src/modules/manufacturing/query/detectBillOfMaterialCircularReference.ts +79 -0
- package/src/modules/manufacturing/query/explodeBillOfMaterial.generated.ts +5 -0
- package/src/modules/manufacturing/query/explodeBillOfMaterial.test.ts +445 -0
- package/src/modules/manufacturing/query/explodeBillOfMaterial.ts +306 -0
- package/src/modules/manufacturing/query/getBillOfMaterial.generated.ts +5 -0
- package/src/modules/manufacturing/query/getBillOfMaterial.test.ts +64 -0
- package/src/modules/manufacturing/query/getBillOfMaterial.ts +27 -0
- package/src/modules/manufacturing/query/getManufacturingCostSummary.generated.ts +5 -0
- package/src/modules/manufacturing/query/getManufacturingCostSummary.test.ts +147 -0
- package/src/modules/manufacturing/query/getManufacturingCostSummary.ts +46 -0
- package/src/modules/manufacturing/query/getProductionOrder.generated.ts +5 -0
- package/src/modules/manufacturing/query/getProductionOrder.test.ts +139 -0
- package/src/modules/manufacturing/query/getProductionOrder.ts +84 -0
- package/src/modules/manufacturing/query/getRouting.generated.ts +5 -0
- package/src/modules/manufacturing/query/getRouting.test.ts +71 -0
- package/src/modules/manufacturing/query/getRouting.ts +34 -0
- package/src/modules/manufacturing/query/getWorkCenter.generated.ts +5 -0
- package/src/modules/manufacturing/query/getWorkCenter.test.ts +37 -0
- package/src/modules/manufacturing/query/getWorkCenter.ts +21 -0
- package/src/modules/manufacturing/query/getWorkOrder.generated.ts +5 -0
- package/src/modules/manufacturing/query/getWorkOrder.test.ts +73 -0
- package/src/modules/manufacturing/query/getWorkOrder.ts +28 -0
- package/src/modules/manufacturing/query/listBillOfMaterialsByItem.generated.ts +5 -0
- package/src/modules/manufacturing/query/listBillOfMaterialsByItem.test.ts +107 -0
- package/src/modules/manufacturing/query/listBillOfMaterialsByItem.ts +58 -0
- package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.generated.ts +5 -0
- package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.test.ts +96 -0
- package/src/modules/manufacturing/query/listManufacturingCostSummariesByStatus.ts +77 -0
- package/src/modules/manufacturing/query/listProductionOrdersByStatus.generated.ts +5 -0
- package/src/modules/manufacturing/query/listProductionOrdersByStatus.test.ts +121 -0
- package/src/modules/manufacturing/query/listProductionOrdersByStatus.ts +83 -0
- package/src/modules/manufacturing/query/listRoutingsByItem.generated.ts +5 -0
- package/src/modules/manufacturing/query/listRoutingsByItem.test.ts +110 -0
- package/src/modules/manufacturing/query/listRoutingsByItem.ts +54 -0
- package/src/modules/manufacturing/query/listWorkCentersBySite.generated.ts +5 -0
- package/src/modules/manufacturing/query/listWorkCentersBySite.test.ts +81 -0
- package/src/modules/manufacturing/query/listWorkCentersBySite.ts +70 -0
- package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.generated.ts +5 -0
- package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.test.ts +102 -0
- package/src/modules/manufacturing/query/listWorkOrdersByProductionOrder.ts +53 -0
- package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.generated.ts +5 -0
- package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.test.ts +143 -0
- package/src/modules/manufacturing/query/listWorkOrdersByWorkCenter.ts +56 -0
- package/src/modules/manufacturing/seed/index.ts +19 -0
- package/src/modules/manufacturing/tailor.config.ts +13 -0
- package/src/modules/manufacturing/tailor.d.ts +13 -0
- package/src/modules/manufacturing/testing/commandTestUtils.ts +29 -0
- package/src/modules/manufacturing/testing/fixtures.ts +402 -0
- package/templates/scaffold/app/backend/package.json +9 -2
- package/templates/scaffold/app/backend/src/tests/utils/graphql-client.ts +66 -0
- package/templates/scaffold/app/backend/src/tests/utils/setup.ts +21 -0
- package/templates/scaffold/app/backend/tsconfig.json +9 -2
- package/templates/scaffold/app/backend/vitest.config.ts +35 -0
- package/templates/scaffold/app/frontend/package.json +2 -2
- package/templates/scaffold/module/__dot__gitignore +3 -0
- package/templates/scaffold/module/eslint.config.js +31 -0
- package/templates/scaffold/module/generated/kysely-tailordb.ts +3 -0
- package/templates/scaffold/module/lib/types.ts +1 -6
- package/templates/scaffold/module/package.json +26 -0
- package/templates/scaffold/module/tsconfig.json +16 -0
- /package/{templates/scaffold/module/generated → src/modules/manufacturing/command}/.gitkeep +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Transaction } from "../generated/kysely-tailordb";
|
|
2
|
+
import {
|
|
3
|
+
WorkCenterNotFoundError,
|
|
4
|
+
InvalidCapacityError,
|
|
5
|
+
InvalidRateError,
|
|
6
|
+
InvalidOverheadMethodError,
|
|
7
|
+
OverheadCurrencyRequiredError,
|
|
8
|
+
ImmutableScopeFieldError,
|
|
9
|
+
} from "../lib/errors.generated";
|
|
10
|
+
import { ok, err, type CommandContext } from "@tailor-platform/erp-kit/module";
|
|
11
|
+
|
|
12
|
+
const VALID_OVERHEAD_METHODS = [
|
|
13
|
+
"PERCENT_OF_LABOR_COST",
|
|
14
|
+
"PERCENT_OF_MACHINE_COST",
|
|
15
|
+
"FIXED_AMOUNT_PER_GOOD_UNIT",
|
|
16
|
+
] as const;
|
|
17
|
+
|
|
18
|
+
const IMMUTABLE_FIELDS = ["companyId", "siteId", "code"] as const;
|
|
19
|
+
|
|
20
|
+
export interface UpdateWorkCenterInput {
|
|
21
|
+
id: string;
|
|
22
|
+
capacityAssumptions?: number | null;
|
|
23
|
+
laborRate?: number | null;
|
|
24
|
+
machineRate?: number | null;
|
|
25
|
+
calendarReference?: string | null;
|
|
26
|
+
overheadAbsorptionMethod?: string | null;
|
|
27
|
+
overheadAbsorptionCurrency?: string | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Function: updateWorkCenter
|
|
32
|
+
*
|
|
33
|
+
* Revises mutable work-center master data such as capacity, calendar,
|
|
34
|
+
* rate assumptions, and overhead policy. Only DRAFT or ACTIVE work centers
|
|
35
|
+
* may be updated.
|
|
36
|
+
*/
|
|
37
|
+
export async function run<CF extends Record<string, unknown>>(
|
|
38
|
+
db: Transaction,
|
|
39
|
+
input: UpdateWorkCenterInput & CF,
|
|
40
|
+
_ctx: CommandContext,
|
|
41
|
+
) {
|
|
42
|
+
const {
|
|
43
|
+
id,
|
|
44
|
+
capacityAssumptions,
|
|
45
|
+
laborRate,
|
|
46
|
+
machineRate,
|
|
47
|
+
calendarReference,
|
|
48
|
+
overheadAbsorptionMethod,
|
|
49
|
+
overheadAbsorptionCurrency,
|
|
50
|
+
...customFields
|
|
51
|
+
} = input;
|
|
52
|
+
|
|
53
|
+
// 1. Reject immutable scope fields
|
|
54
|
+
for (const field of IMMUTABLE_FIELDS) {
|
|
55
|
+
if (field in customFields) {
|
|
56
|
+
return err(new ImmutableScopeFieldError(field));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 2. Check work center exists
|
|
61
|
+
const workCenter = await db
|
|
62
|
+
.selectFrom("WorkCenter")
|
|
63
|
+
.selectAll()
|
|
64
|
+
.where("id", "=", id)
|
|
65
|
+
.forUpdate()
|
|
66
|
+
.executeTakeFirst();
|
|
67
|
+
|
|
68
|
+
if (!workCenter) {
|
|
69
|
+
return err(new WorkCenterNotFoundError(id));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 3. Only DRAFT or ACTIVE allowed
|
|
73
|
+
if (workCenter.status !== "DRAFT" && workCenter.status !== "ACTIVE") {
|
|
74
|
+
return err(new WorkCenterNotFoundError(id));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 4. Validate capacity if provided
|
|
78
|
+
if (capacityAssumptions != null && capacityAssumptions <= 0) {
|
|
79
|
+
return err(new InvalidCapacityError(id));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 5. Validate rates if provided
|
|
83
|
+
if (laborRate != null && laborRate < 0) {
|
|
84
|
+
return err(new InvalidRateError(id));
|
|
85
|
+
}
|
|
86
|
+
if (machineRate != null && machineRate < 0) {
|
|
87
|
+
return err(new InvalidRateError(id));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Resolve the effective overhead method after update
|
|
91
|
+
const effectiveMethod =
|
|
92
|
+
overheadAbsorptionMethod !== undefined
|
|
93
|
+
? overheadAbsorptionMethod
|
|
94
|
+
: workCenter.overheadAbsorptionMethod;
|
|
95
|
+
const effectiveCurrency =
|
|
96
|
+
overheadAbsorptionCurrency !== undefined
|
|
97
|
+
? overheadAbsorptionCurrency
|
|
98
|
+
: workCenter.overheadAbsorptionCurrency;
|
|
99
|
+
|
|
100
|
+
// 6. Validate overhead method
|
|
101
|
+
if (
|
|
102
|
+
effectiveMethod != null &&
|
|
103
|
+
!VALID_OVERHEAD_METHODS.includes(effectiveMethod as (typeof VALID_OVERHEAD_METHODS)[number])
|
|
104
|
+
) {
|
|
105
|
+
return err(new InvalidOverheadMethodError(id));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 7. Overhead currency required for FIXED_AMOUNT_PER_GOOD_UNIT
|
|
109
|
+
if (effectiveMethod === "FIXED_AMOUNT_PER_GOOD_UNIT" && !effectiveCurrency) {
|
|
110
|
+
return err(new OverheadCurrencyRequiredError(id));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 8. Build update set
|
|
114
|
+
const updateSet: Record<string, unknown> = {
|
|
115
|
+
...(customFields as Record<string, unknown>),
|
|
116
|
+
updatedAt: new Date(),
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (capacityAssumptions !== undefined) updateSet.capacityAssumptions = capacityAssumptions;
|
|
120
|
+
if (laborRate !== undefined) updateSet.laborRate = laborRate;
|
|
121
|
+
if (machineRate !== undefined) updateSet.machineRate = machineRate;
|
|
122
|
+
if (calendarReference !== undefined) updateSet.calendarReference = calendarReference;
|
|
123
|
+
if (overheadAbsorptionMethod !== undefined)
|
|
124
|
+
updateSet.overheadAbsorptionMethod = overheadAbsorptionMethod;
|
|
125
|
+
if (overheadAbsorptionCurrency !== undefined)
|
|
126
|
+
updateSet.overheadAbsorptionCurrency = overheadAbsorptionCurrency;
|
|
127
|
+
|
|
128
|
+
// 9. Persist changes
|
|
129
|
+
const updated = await db
|
|
130
|
+
.updateTable("WorkCenter")
|
|
131
|
+
.set(updateSet)
|
|
132
|
+
.where("id", "=", id)
|
|
133
|
+
.returningAll()
|
|
134
|
+
.executeTakeFirstOrThrow();
|
|
135
|
+
|
|
136
|
+
return ok({ workCenter: updated });
|
|
137
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBField,
|
|
4
|
+
type TailorAnyDBType,
|
|
5
|
+
unsafeAllowAllGqlPermission,
|
|
6
|
+
unsafeAllowAllTypePermission,
|
|
7
|
+
} from "@tailor-platform/sdk";
|
|
8
|
+
import { company as companyStub, site as siteStub, item as itemStub } from "../lib/_db_deps";
|
|
9
|
+
|
|
10
|
+
export const BOM_TYPES = ["MANUFACTURE", "PHANTOM", "KIT"] as const;
|
|
11
|
+
export const BASE_BOM_STATUSES = ["DRAFT", "ACTIVE", "INACTIVE"] as const;
|
|
12
|
+
|
|
13
|
+
export interface CreateBillOfMaterialTypeParams<F extends Record<string, TailorAnyDBField>> {
|
|
14
|
+
fields?: F;
|
|
15
|
+
companyType: TailorAnyDBType;
|
|
16
|
+
siteType: TailorAnyDBType;
|
|
17
|
+
itemType: TailorAnyDBType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createBillOfMaterialType<const F extends Record<string, TailorAnyDBField>>(
|
|
21
|
+
params: CreateBillOfMaterialTypeParams<F>,
|
|
22
|
+
) {
|
|
23
|
+
return db
|
|
24
|
+
.type("BillOfMaterial", {
|
|
25
|
+
parentItemId: db
|
|
26
|
+
.uuid()
|
|
27
|
+
.relation({
|
|
28
|
+
type: "n-1",
|
|
29
|
+
toward: { type: params.itemType },
|
|
30
|
+
backward: "billOfMaterials",
|
|
31
|
+
})
|
|
32
|
+
.description("Foreign key to Item – the parent/finished item"),
|
|
33
|
+
companyId: db
|
|
34
|
+
.uuid()
|
|
35
|
+
.relation({
|
|
36
|
+
type: "n-1",
|
|
37
|
+
toward: { type: params.companyType },
|
|
38
|
+
backward: "billOfMaterials",
|
|
39
|
+
})
|
|
40
|
+
.description("Foreign key to Company"),
|
|
41
|
+
siteId: db
|
|
42
|
+
.uuid({ optional: true })
|
|
43
|
+
.relation({
|
|
44
|
+
type: "n-1",
|
|
45
|
+
toward: { type: params.siteType },
|
|
46
|
+
backward: "billOfMaterials",
|
|
47
|
+
})
|
|
48
|
+
.description("Optional foreign key to Site – site scope"),
|
|
49
|
+
bomType: db
|
|
50
|
+
.enum([...BOM_TYPES] as [string, ...string[]])
|
|
51
|
+
.description("BOM type: MANUFACTURE, PHANTOM, KIT"),
|
|
52
|
+
effectivityStartDate: db.datetime({ optional: true }).description("Effectivity start date"),
|
|
53
|
+
effectivityEndDate: db.datetime({ optional: true }).description("Effectivity end date"),
|
|
54
|
+
defaultSelection: db.bool({ optional: true }).description("Default selection flag"),
|
|
55
|
+
revisionNumber: db.string({ optional: true }).description("Revision number"),
|
|
56
|
+
status: db
|
|
57
|
+
.enum([...BASE_BOM_STATUSES] as [string, ...string[]])
|
|
58
|
+
.description("Lifecycle status: DRAFT, ACTIVE, INACTIVE"),
|
|
59
|
+
...((params.fields ?? {}) as F),
|
|
60
|
+
...db.fields.timestamps(),
|
|
61
|
+
})
|
|
62
|
+
.permission(unsafeAllowAllTypePermission)
|
|
63
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const billOfMaterial = createBillOfMaterialType({
|
|
67
|
+
companyType: companyStub,
|
|
68
|
+
siteType: siteStub,
|
|
69
|
+
itemType: itemStub,
|
|
70
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBType,
|
|
4
|
+
unsafeAllowAllGqlPermission,
|
|
5
|
+
unsafeAllowAllTypePermission,
|
|
6
|
+
} from "@tailor-platform/sdk";
|
|
7
|
+
import { item as itemStub } from "../lib/_db_deps";
|
|
8
|
+
import { billOfMaterial } from "./billOfMaterial";
|
|
9
|
+
|
|
10
|
+
export interface CreateBillOfMaterialLineTypeParams {
|
|
11
|
+
billOfMaterialType: TailorAnyDBType;
|
|
12
|
+
itemType: TailorAnyDBType;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createBillOfMaterialLineType(params: CreateBillOfMaterialLineTypeParams) {
|
|
16
|
+
return db
|
|
17
|
+
.type("BillOfMaterialLine", {
|
|
18
|
+
billOfMaterialId: db
|
|
19
|
+
.uuid()
|
|
20
|
+
.relation({
|
|
21
|
+
type: "n-1",
|
|
22
|
+
toward: { type: params.billOfMaterialType },
|
|
23
|
+
backward: "billOfMaterialLines",
|
|
24
|
+
})
|
|
25
|
+
.description("Foreign key to BillOfMaterial"),
|
|
26
|
+
itemId: db
|
|
27
|
+
.uuid()
|
|
28
|
+
.relation({
|
|
29
|
+
type: "n-1",
|
|
30
|
+
toward: { type: params.itemType },
|
|
31
|
+
backward: "bomLineReferences",
|
|
32
|
+
})
|
|
33
|
+
.description("Foreign key to Item – component item"),
|
|
34
|
+
requiredQuantity: db.float().description("Required quantity, must be greater than 0"),
|
|
35
|
+
unitOfMeasure: db.string({ optional: true }).description("Compatible unit of measure"),
|
|
36
|
+
scrapAssumption: db.float({ optional: true }).description("Scrap assumption percentage"),
|
|
37
|
+
isSubassembly: db
|
|
38
|
+
.bool({ optional: true })
|
|
39
|
+
.description("Whether this component is a subassembly"),
|
|
40
|
+
...db.fields.timestamps(),
|
|
41
|
+
})
|
|
42
|
+
.permission(unsafeAllowAllTypePermission)
|
|
43
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const billOfMaterialLine = createBillOfMaterialLineType({
|
|
47
|
+
billOfMaterialType: billOfMaterial,
|
|
48
|
+
itemType: itemStub,
|
|
49
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBType,
|
|
4
|
+
unsafeAllowAllGqlPermission,
|
|
5
|
+
unsafeAllowAllTypePermission,
|
|
6
|
+
} from "@tailor-platform/sdk";
|
|
7
|
+
import { manufacturingCostSummary } from "./manufacturingCostSummary";
|
|
8
|
+
|
|
9
|
+
export const VARIANCE_TYPES = [
|
|
10
|
+
"MATERIAL_PRICE",
|
|
11
|
+
"MATERIAL_USAGE",
|
|
12
|
+
"LABOR_RATE",
|
|
13
|
+
"LABOR_EFFICIENCY",
|
|
14
|
+
"MACHINE_RATE",
|
|
15
|
+
"MACHINE_EFFICIENCY",
|
|
16
|
+
"SCRAP",
|
|
17
|
+
"YIELD",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export interface CreateCostVarianceLineTypeParams {
|
|
21
|
+
costSummaryType: TailorAnyDBType;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createCostVarianceLineType(params: CreateCostVarianceLineTypeParams) {
|
|
25
|
+
return db
|
|
26
|
+
.type("CostVarianceLine", {
|
|
27
|
+
costSummaryId: db
|
|
28
|
+
.uuid()
|
|
29
|
+
.relation({
|
|
30
|
+
type: "n-1",
|
|
31
|
+
toward: { type: params.costSummaryType },
|
|
32
|
+
backward: "varianceLines",
|
|
33
|
+
})
|
|
34
|
+
.description("Foreign key to ManufacturingCostSummary"),
|
|
35
|
+
varianceType: db
|
|
36
|
+
.enum([...VARIANCE_TYPES] as [string, ...string[]])
|
|
37
|
+
.description(
|
|
38
|
+
"Variance type: MATERIAL_PRICE, MATERIAL_USAGE, LABOR_RATE, LABOR_EFFICIENCY, MACHINE_RATE, MACHINE_EFFICIENCY, SCRAP, YIELD",
|
|
39
|
+
),
|
|
40
|
+
amount: db.float().description("Variance amount"),
|
|
41
|
+
accountReference: db
|
|
42
|
+
.string({ optional: true })
|
|
43
|
+
.description("Optional account reference for settlement"),
|
|
44
|
+
variancePercentage: db.float({ optional: true }).description("Variance as a percentage"),
|
|
45
|
+
...db.fields.timestamps(),
|
|
46
|
+
})
|
|
47
|
+
.permission(unsafeAllowAllTypePermission)
|
|
48
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const costVarianceLine = createCostVarianceLineType({
|
|
52
|
+
costSummaryType: manufacturingCostSummary,
|
|
53
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBType,
|
|
4
|
+
unsafeAllowAllGqlPermission,
|
|
5
|
+
unsafeAllowAllTypePermission,
|
|
6
|
+
} from "@tailor-platform/sdk";
|
|
7
|
+
import { manufacturingCostSummary } from "./manufacturingCostSummary";
|
|
8
|
+
|
|
9
|
+
export interface CreateManufacturingCostLineTypeParams {
|
|
10
|
+
costSummaryType: TailorAnyDBType;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createManufacturingCostLineType(params: CreateManufacturingCostLineTypeParams) {
|
|
14
|
+
return db
|
|
15
|
+
.type("ManufacturingCostLine", {
|
|
16
|
+
costSummaryId: db
|
|
17
|
+
.uuid()
|
|
18
|
+
.relation({
|
|
19
|
+
type: "n-1",
|
|
20
|
+
toward: { type: params.costSummaryType },
|
|
21
|
+
backward: "costLines",
|
|
22
|
+
})
|
|
23
|
+
.description("Foreign key to ManufacturingCostSummary"),
|
|
24
|
+
costType: db.string().description("Cost type: e.g. MATERIAL, LABOR, MACHINE, OVERHEAD"),
|
|
25
|
+
plannedAmount: db.float().description("Planned cost amount"),
|
|
26
|
+
actualAmount: db.float().description("Actual cost amount"),
|
|
27
|
+
...db.fields.timestamps(),
|
|
28
|
+
})
|
|
29
|
+
.permission(unsafeAllowAllTypePermission)
|
|
30
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const manufacturingCostLine = createManufacturingCostLineType({
|
|
34
|
+
costSummaryType: manufacturingCostSummary,
|
|
35
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBType,
|
|
4
|
+
unsafeAllowAllGqlPermission,
|
|
5
|
+
unsafeAllowAllTypePermission,
|
|
6
|
+
} from "@tailor-platform/sdk";
|
|
7
|
+
import { manufacturingCostSummary } from "./manufacturingCostSummary";
|
|
8
|
+
|
|
9
|
+
export interface CreateManufacturingCostSettlementRecordTypeParams {
|
|
10
|
+
costSummaryType: TailorAnyDBType;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createManufacturingCostSettlementRecordType(
|
|
14
|
+
params: CreateManufacturingCostSettlementRecordTypeParams,
|
|
15
|
+
) {
|
|
16
|
+
return db
|
|
17
|
+
.type("ManufacturingCostSettlementRecord", {
|
|
18
|
+
costSummaryId: db
|
|
19
|
+
.uuid()
|
|
20
|
+
.relation({
|
|
21
|
+
type: "n-1",
|
|
22
|
+
toward: { type: params.costSummaryType },
|
|
23
|
+
backward: "settlementRecords",
|
|
24
|
+
})
|
|
25
|
+
.description("Foreign key to ManufacturingCostSummary"),
|
|
26
|
+
settlementDate: db.datetime().description("Date of settlement"),
|
|
27
|
+
settlementReference: db.string().description("Reference identifier for the settlement"),
|
|
28
|
+
acknowledgedDate: db
|
|
29
|
+
.datetime({ optional: true })
|
|
30
|
+
.description("Date when settlement was acknowledged"),
|
|
31
|
+
...db.fields.timestamps(),
|
|
32
|
+
})
|
|
33
|
+
.permission(unsafeAllowAllTypePermission)
|
|
34
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const manufacturingCostSettlementRecord = createManufacturingCostSettlementRecordType({
|
|
38
|
+
costSummaryType: manufacturingCostSummary,
|
|
39
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBType,
|
|
4
|
+
unsafeAllowAllGqlPermission,
|
|
5
|
+
unsafeAllowAllTypePermission,
|
|
6
|
+
} from "@tailor-platform/sdk";
|
|
7
|
+
import { productionOrder } from "./productionOrder";
|
|
8
|
+
|
|
9
|
+
export const BASE_COST_SUMMARY_STATUSES = [
|
|
10
|
+
"COLLECTING",
|
|
11
|
+
"PENDING_VARIANCE_REVIEW",
|
|
12
|
+
"VARIANCE_REVIEWED",
|
|
13
|
+
"SETTLED",
|
|
14
|
+
] as const;
|
|
15
|
+
|
|
16
|
+
export interface CreateManufacturingCostSummaryTypeParams {
|
|
17
|
+
productionOrderType: TailorAnyDBType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createManufacturingCostSummaryType(
|
|
21
|
+
params: CreateManufacturingCostSummaryTypeParams,
|
|
22
|
+
) {
|
|
23
|
+
return db
|
|
24
|
+
.type("ManufacturingCostSummary", {
|
|
25
|
+
productionOrderId: db
|
|
26
|
+
.uuid()
|
|
27
|
+
.relation({
|
|
28
|
+
type: "1-1",
|
|
29
|
+
toward: { type: params.productionOrderType },
|
|
30
|
+
backward: "manufacturingCostSummary",
|
|
31
|
+
})
|
|
32
|
+
.description("Foreign key to ProductionOrder"),
|
|
33
|
+
plannedMaterialCost: db.float().description("Planned material cost"),
|
|
34
|
+
plannedLaborCost: db.float().description("Planned labor cost"),
|
|
35
|
+
plannedMachineCost: db.float().description("Planned machine cost"),
|
|
36
|
+
plannedOverheadCost: db.float().description("Planned overhead cost"),
|
|
37
|
+
actualMaterialCost: db.float().description("Actual material cost"),
|
|
38
|
+
actualLaborCost: db.float().description("Actual labor cost"),
|
|
39
|
+
actualMachineCost: db.float().description("Actual machine cost"),
|
|
40
|
+
actualOverheadCost: db.float().description("Actual overhead cost"),
|
|
41
|
+
currencyCode: db.string().description("Currency code (e.g. USD, EUR)"),
|
|
42
|
+
reviewedDate: db
|
|
43
|
+
.datetime({ optional: true })
|
|
44
|
+
.description("Date when cost summary was reviewed"),
|
|
45
|
+
reviewerNotes: db.string({ optional: true }).description("Notes from the reviewer"),
|
|
46
|
+
status: db
|
|
47
|
+
.enum([...BASE_COST_SUMMARY_STATUSES] as [string, ...string[]])
|
|
48
|
+
.description(
|
|
49
|
+
"Lifecycle status: COLLECTING, PENDING_VARIANCE_REVIEW, VARIANCE_REVIEWED, SETTLED",
|
|
50
|
+
),
|
|
51
|
+
...db.fields.timestamps(),
|
|
52
|
+
})
|
|
53
|
+
.permission(unsafeAllowAllTypePermission)
|
|
54
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const manufacturingCostSummary = createManufacturingCostSummaryType({
|
|
58
|
+
productionOrderType: productionOrder,
|
|
59
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBField,
|
|
4
|
+
type TailorAnyDBType,
|
|
5
|
+
unsafeAllowAllGqlPermission,
|
|
6
|
+
unsafeAllowAllTypePermission,
|
|
7
|
+
} from "@tailor-platform/sdk";
|
|
8
|
+
import { company as companyStub, site as siteStub, item as itemStub } from "../lib/_db_deps";
|
|
9
|
+
|
|
10
|
+
export const BASE_PRODUCTION_ORDER_STATUSES = [
|
|
11
|
+
"DRAFT",
|
|
12
|
+
"RELEASED",
|
|
13
|
+
"IN_PROGRESS",
|
|
14
|
+
"COMPLETED",
|
|
15
|
+
"TECHNICALLY_COMPLETE",
|
|
16
|
+
"CLOSED",
|
|
17
|
+
"CANCELLED",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export interface CreateProductionOrderTypeParams<F extends Record<string, TailorAnyDBField>> {
|
|
21
|
+
fields?: F;
|
|
22
|
+
companyType: TailorAnyDBType;
|
|
23
|
+
siteType: TailorAnyDBType;
|
|
24
|
+
itemType: TailorAnyDBType;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createProductionOrderType<const F extends Record<string, TailorAnyDBField>>(
|
|
28
|
+
params: CreateProductionOrderTypeParams<F>,
|
|
29
|
+
) {
|
|
30
|
+
return db
|
|
31
|
+
.type("ProductionOrder", {
|
|
32
|
+
orderedItemId: db
|
|
33
|
+
.uuid()
|
|
34
|
+
.relation({
|
|
35
|
+
type: "n-1",
|
|
36
|
+
toward: { type: params.itemType },
|
|
37
|
+
backward: "productionOrders",
|
|
38
|
+
})
|
|
39
|
+
.description("Foreign key to Item – the item to be manufactured"),
|
|
40
|
+
companyId: db
|
|
41
|
+
.uuid()
|
|
42
|
+
.relation({
|
|
43
|
+
type: "n-1",
|
|
44
|
+
toward: { type: params.companyType },
|
|
45
|
+
backward: "productionOrders",
|
|
46
|
+
})
|
|
47
|
+
.description("Foreign key to Company"),
|
|
48
|
+
siteId: db
|
|
49
|
+
.uuid()
|
|
50
|
+
.relation({
|
|
51
|
+
type: "n-1",
|
|
52
|
+
toward: { type: params.siteType },
|
|
53
|
+
backward: "productionOrders",
|
|
54
|
+
})
|
|
55
|
+
.description("Foreign key to Site"),
|
|
56
|
+
plannedQuantity: db
|
|
57
|
+
.float()
|
|
58
|
+
.description("Planned production quantity, must be greater than 0"),
|
|
59
|
+
plannedStartDate: db.datetime().description("Planned start date for the production order"),
|
|
60
|
+
plannedEndDate: db.datetime().description("Planned end date for the production order"),
|
|
61
|
+
selectedBomVersionId: db
|
|
62
|
+
.uuid({ optional: true })
|
|
63
|
+
.description("Optional reference to BillOfMaterial – resolved at release"),
|
|
64
|
+
selectedRoutingRevisionId: db
|
|
65
|
+
.uuid({ optional: true })
|
|
66
|
+
.description("Optional reference to Routing – resolved at release"),
|
|
67
|
+
status: db
|
|
68
|
+
.enum([...BASE_PRODUCTION_ORDER_STATUSES] as [string, ...string[]])
|
|
69
|
+
.description(
|
|
70
|
+
"Lifecycle status: DRAFT, RELEASED, IN_PROGRESS, COMPLETED, TECHNICALLY_COMPLETE, CLOSED, CANCELLED",
|
|
71
|
+
),
|
|
72
|
+
...((params.fields ?? {}) as F),
|
|
73
|
+
...db.fields.timestamps(),
|
|
74
|
+
})
|
|
75
|
+
.permission(unsafeAllowAllTypePermission)
|
|
76
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const productionOrder = createProductionOrderType({
|
|
80
|
+
companyType: companyStub,
|
|
81
|
+
siteType: siteStub,
|
|
82
|
+
itemType: itemStub,
|
|
83
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBField,
|
|
4
|
+
type TailorAnyDBType,
|
|
5
|
+
unsafeAllowAllGqlPermission,
|
|
6
|
+
unsafeAllowAllTypePermission,
|
|
7
|
+
} from "@tailor-platform/sdk";
|
|
8
|
+
import { productionOrder } from "./productionOrder";
|
|
9
|
+
|
|
10
|
+
export interface CreateProductionOrderBomSnapshotTypeParams<
|
|
11
|
+
F extends Record<string, TailorAnyDBField>,
|
|
12
|
+
> {
|
|
13
|
+
fields?: F;
|
|
14
|
+
productionOrderType: TailorAnyDBType;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createProductionOrderBomSnapshotType<
|
|
18
|
+
const F extends Record<string, TailorAnyDBField>,
|
|
19
|
+
>(params: CreateProductionOrderBomSnapshotTypeParams<F>) {
|
|
20
|
+
return db
|
|
21
|
+
.type("ProductionOrderBomSnapshot", {
|
|
22
|
+
productionOrderId: db
|
|
23
|
+
.uuid()
|
|
24
|
+
.relation({
|
|
25
|
+
type: "1-1",
|
|
26
|
+
toward: { type: params.productionOrderType },
|
|
27
|
+
backward: "bomSnapshot",
|
|
28
|
+
})
|
|
29
|
+
.description("Foreign key to ProductionOrder (one snapshot per order)"),
|
|
30
|
+
parentItemId: db.uuid().description("Item ID of the parent item in the BOM snapshot"),
|
|
31
|
+
bomType: db.string().description("BOM type (e.g., STANDARD, PHANTOM)"),
|
|
32
|
+
snapshotData: db
|
|
33
|
+
.string({ optional: true })
|
|
34
|
+
.description("JSON blob containing the full BOM snapshot"),
|
|
35
|
+
...((params.fields ?? {}) as F),
|
|
36
|
+
...db.fields.timestamps(),
|
|
37
|
+
})
|
|
38
|
+
.permission(unsafeAllowAllTypePermission)
|
|
39
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const productionOrderBomSnapshot = createProductionOrderBomSnapshotType({
|
|
43
|
+
productionOrderType: productionOrder,
|
|
44
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBField,
|
|
4
|
+
type TailorAnyDBType,
|
|
5
|
+
unsafeAllowAllGqlPermission,
|
|
6
|
+
unsafeAllowAllTypePermission,
|
|
7
|
+
} from "@tailor-platform/sdk";
|
|
8
|
+
import { productionOrder } from "./productionOrder";
|
|
9
|
+
|
|
10
|
+
export interface CreateProductionOrderCostBaselineTypeParams<
|
|
11
|
+
F extends Record<string, TailorAnyDBField>,
|
|
12
|
+
> {
|
|
13
|
+
fields?: F;
|
|
14
|
+
productionOrderType: TailorAnyDBType;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createProductionOrderCostBaselineType<
|
|
18
|
+
const F extends Record<string, TailorAnyDBField>,
|
|
19
|
+
>(params: CreateProductionOrderCostBaselineTypeParams<F>) {
|
|
20
|
+
return db
|
|
21
|
+
.type("ProductionOrderCostBaseline", {
|
|
22
|
+
productionOrderId: db
|
|
23
|
+
.uuid()
|
|
24
|
+
.relation({
|
|
25
|
+
type: "1-1",
|
|
26
|
+
toward: { type: params.productionOrderType },
|
|
27
|
+
backward: "costBaseline",
|
|
28
|
+
})
|
|
29
|
+
.description("Foreign key to ProductionOrder (one baseline per order)"),
|
|
30
|
+
plannedMaterialCost: db.float().description("Planned total material cost"),
|
|
31
|
+
plannedLaborCost: db.float().description("Planned total labor cost"),
|
|
32
|
+
plannedMachineCost: db.float().description("Planned total machine cost"),
|
|
33
|
+
plannedOverheadCost: db.float().description("Planned total overhead cost"),
|
|
34
|
+
currencyCode: db.string().description("ISO 4217 currency code (e.g., USD)"),
|
|
35
|
+
...((params.fields ?? {}) as F),
|
|
36
|
+
...db.fields.timestamps(),
|
|
37
|
+
})
|
|
38
|
+
.permission(unsafeAllowAllTypePermission)
|
|
39
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const productionOrderCostBaseline = createProductionOrderCostBaselineType({
|
|
43
|
+
productionOrderType: productionOrder,
|
|
44
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
db,
|
|
3
|
+
type TailorAnyDBField,
|
|
4
|
+
type TailorAnyDBType,
|
|
5
|
+
unsafeAllowAllGqlPermission,
|
|
6
|
+
unsafeAllowAllTypePermission,
|
|
7
|
+
} from "@tailor-platform/sdk";
|
|
8
|
+
import { item as itemStub } from "../lib/_db_deps";
|
|
9
|
+
import { productionOrder } from "./productionOrder";
|
|
10
|
+
|
|
11
|
+
export interface CreateProductionOrderMaterialRequirementTypeParams<
|
|
12
|
+
F extends Record<string, TailorAnyDBField>,
|
|
13
|
+
> {
|
|
14
|
+
fields?: F;
|
|
15
|
+
productionOrderType: TailorAnyDBType;
|
|
16
|
+
itemType: TailorAnyDBType;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createProductionOrderMaterialRequirementType<
|
|
20
|
+
const F extends Record<string, TailorAnyDBField>,
|
|
21
|
+
>(params: CreateProductionOrderMaterialRequirementTypeParams<F>) {
|
|
22
|
+
return db
|
|
23
|
+
.type("ProductionOrderMaterialRequirement", {
|
|
24
|
+
productionOrderId: db
|
|
25
|
+
.uuid()
|
|
26
|
+
.relation({
|
|
27
|
+
type: "n-1",
|
|
28
|
+
toward: { type: params.productionOrderType },
|
|
29
|
+
backward: "materialRequirements",
|
|
30
|
+
})
|
|
31
|
+
.description("Foreign key to ProductionOrder"),
|
|
32
|
+
itemId: db
|
|
33
|
+
.uuid()
|
|
34
|
+
.relation({
|
|
35
|
+
type: "n-1",
|
|
36
|
+
toward: { type: params.itemType },
|
|
37
|
+
backward: "productionOrderMaterialRequirements",
|
|
38
|
+
})
|
|
39
|
+
.description("Foreign key to Item – the required material"),
|
|
40
|
+
requiredQuantity: db.float().description("Required quantity of the material"),
|
|
41
|
+
unitOfMeasure: db
|
|
42
|
+
.string({ optional: true })
|
|
43
|
+
.description("Unit of measure for the required quantity"),
|
|
44
|
+
plannedUnitCost: db
|
|
45
|
+
.float({ optional: true })
|
|
46
|
+
.description("Planned cost per unit of the material"),
|
|
47
|
+
...((params.fields ?? {}) as F),
|
|
48
|
+
...db.fields.timestamps(),
|
|
49
|
+
})
|
|
50
|
+
.permission(unsafeAllowAllTypePermission)
|
|
51
|
+
.gqlPermission(unsafeAllowAllGqlPermission);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const productionOrderMaterialRequirement = createProductionOrderMaterialRequirementType({
|
|
55
|
+
productionOrderType: productionOrder,
|
|
56
|
+
itemType: itemStub,
|
|
57
|
+
});
|