@axova/shared 1.0.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/CONFIGURATION_GUIDE.md +1 -0
- package/README.md +384 -0
- package/SCHEMA_ORGANIZATION.md +209 -0
- package/dist/configs/index.d.ts +85 -0
- package/dist/configs/index.js +555 -0
- package/dist/events/kafka.d.ts +40 -0
- package/dist/events/kafka.js +311 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +41 -0
- package/dist/interfaces/customer-events.d.ts +85 -0
- package/dist/interfaces/customer-events.js +2 -0
- package/dist/interfaces/inventory-events.d.ts +453 -0
- package/dist/interfaces/inventory-events.js +3 -0
- package/dist/interfaces/inventory-types.d.ts +894 -0
- package/dist/interfaces/inventory-types.js +3 -0
- package/dist/interfaces/order-events.d.ts +320 -0
- package/dist/interfaces/order-events.js +3 -0
- package/dist/lib/auditLogger.d.ts +162 -0
- package/dist/lib/auditLogger.js +626 -0
- package/dist/lib/authOrganization.d.ts +24 -0
- package/dist/lib/authOrganization.js +110 -0
- package/dist/lib/db.d.ts +6 -0
- package/dist/lib/db.js +88 -0
- package/dist/middleware/serviceAuth.d.ts +60 -0
- package/dist/middleware/serviceAuth.js +272 -0
- package/dist/middleware/storeOwnership.d.ts +15 -0
- package/dist/middleware/storeOwnership.js +156 -0
- package/dist/middleware/storeValidationMiddleware.d.ts +44 -0
- package/dist/middleware/storeValidationMiddleware.js +180 -0
- package/dist/middleware/userAuth.d.ts +27 -0
- package/dist/middleware/userAuth.js +218 -0
- package/dist/schemas/admin/admin-schema.d.ts +741 -0
- package/dist/schemas/admin/admin-schema.js +111 -0
- package/dist/schemas/ai-moderation/ai-moderation-schema.d.ts +648 -0
- package/dist/schemas/ai-moderation/ai-moderation-schema.js +88 -0
- package/dist/schemas/common/common-schemas.d.ts +436 -0
- package/dist/schemas/common/common-schemas.js +94 -0
- package/dist/schemas/compliance/compliance-schema.d.ts +3388 -0
- package/dist/schemas/compliance/compliance-schema.js +472 -0
- package/dist/schemas/compliance/kyc-schema.d.ts +2642 -0
- package/dist/schemas/compliance/kyc-schema.js +361 -0
- package/dist/schemas/customer/customer-schema.d.ts +2727 -0
- package/dist/schemas/customer/customer-schema.js +399 -0
- package/dist/schemas/index.d.ts +27 -0
- package/dist/schemas/index.js +138 -0
- package/dist/schemas/inventory/inventory-tables.d.ts +9476 -0
- package/dist/schemas/inventory/inventory-tables.js +1470 -0
- package/dist/schemas/inventory/lot-tables.d.ts +3281 -0
- package/dist/schemas/inventory/lot-tables.js +608 -0
- package/dist/schemas/order/order-schema.d.ts +5825 -0
- package/dist/schemas/order/order-schema.js +954 -0
- package/dist/schemas/product/discount-relations.d.ts +15 -0
- package/dist/schemas/product/discount-relations.js +34 -0
- package/dist/schemas/product/discount-schema.d.ts +1975 -0
- package/dist/schemas/product/discount-schema.js +297 -0
- package/dist/schemas/product/product-relations.d.ts +41 -0
- package/dist/schemas/product/product-relations.js +133 -0
- package/dist/schemas/product/product-schema.d.ts +4544 -0
- package/dist/schemas/product/product-schema.js +671 -0
- package/dist/schemas/store/store-audit-schema.d.ts +4135 -0
- package/dist/schemas/store/store-audit-schema.js +556 -0
- package/dist/schemas/store/store-schema.d.ts +3100 -0
- package/dist/schemas/store/store-schema.js +381 -0
- package/dist/schemas/store/store-settings-schema.d.ts +665 -0
- package/dist/schemas/store/store-settings-schema.js +141 -0
- package/dist/schemas/types.d.ts +50 -0
- package/dist/schemas/types.js +3 -0
- package/dist/types/events.d.ts +2396 -0
- package/dist/types/events.js +505 -0
- package/dist/utils/errorHandler.d.ts +12 -0
- package/dist/utils/errorHandler.js +36 -0
- package/dist/utils/subdomain.d.ts +6 -0
- package/dist/utils/subdomain.js +20 -0
- package/nul +8 -0
- package/package.json +43 -0
- package/src/configs/index.ts +654 -0
- package/src/events/kafka.ts +429 -0
- package/src/index.ts +26 -0
- package/src/interfaces/customer-events.ts +106 -0
- package/src/interfaces/inventory-events.ts +545 -0
- package/src/interfaces/inventory-types.ts +1004 -0
- package/src/interfaces/order-events.ts +381 -0
- package/src/lib/auditLogger.ts +1117 -0
- package/src/lib/authOrganization.ts +153 -0
- package/src/lib/db.ts +64 -0
- package/src/middleware/serviceAuth.ts +328 -0
- package/src/middleware/storeOwnership.ts +199 -0
- package/src/middleware/storeValidationMiddleware.ts +247 -0
- package/src/middleware/userAuth.ts +248 -0
- package/src/schemas/admin/admin-schema.ts +208 -0
- package/src/schemas/ai-moderation/ai-moderation-schema.ts +180 -0
- package/src/schemas/common/common-schemas.ts +108 -0
- package/src/schemas/compliance/compliance-schema.ts +927 -0
- package/src/schemas/compliance/kyc-schema.ts +649 -0
- package/src/schemas/customer/customer-schema.ts +576 -0
- package/src/schemas/index.ts +189 -0
- package/src/schemas/inventory/inventory-tables.ts +1927 -0
- package/src/schemas/inventory/lot-tables.ts +799 -0
- package/src/schemas/order/order-schema.ts +1400 -0
- package/src/schemas/product/discount-relations.ts +44 -0
- package/src/schemas/product/discount-schema.ts +464 -0
- package/src/schemas/product/product-relations.ts +187 -0
- package/src/schemas/product/product-schema.ts +955 -0
- package/src/schemas/store/ethiopian_business_api.md.resolved +212 -0
- package/src/schemas/store/store-audit-schema.ts +1257 -0
- package/src/schemas/store/store-schema.ts +661 -0
- package/src/schemas/store/store-settings-schema.ts +231 -0
- package/src/schemas/types.ts +67 -0
- package/src/types/events.ts +646 -0
- package/src/utils/errorHandler.ts +44 -0
- package/src/utils/subdomain.ts +19 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,1470 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.purchaseOrderStatusEnum = exports.suppliers = exports.supplierRatingEnum = exports.supplierTypeEnum = exports.supplierStatusEnum = exports.supplierQualityRatings = exports.qualityTemplates = exports.qualityControls = exports.inspectionTypeEnum = exports.qualityStatusEnum = exports.inventoryTransferItems = exports.inventoryTransfers = exports.inventoryTransferTypeEnum = exports.inventoryTransferStatusEnum = exports.posLocations = exports.warehouses = exports.inventoryMovements = exports.inventory = exports.WarehouseSchema = exports.POSLocationSchema = exports.SupplierQualityRatingSchema = exports.QualityTemplateSchema = exports.QualityControlSchema = exports.InventoryTransferSchema = exports.InventoryMovementSchema = exports.InventorySchema = exports.DefectSeverityEnum = exports.QualityGradeEnum = exports.InspectionTypeEnum = exports.QualityStatusEnum = exports.SupplierRatingEnum = exports.SupplierTypeEnum = exports.SupplierStatusEnum = exports.PurchaseOrderStatusEnum = exports.InventoryTransferTypeEnum = exports.InventoryTransferStatusEnum = exports.LocationTypeEnum = exports.InventoryStatusEnum = exports.WarehouseTypeEnum = exports.WarehouseStatusEnum = exports.POSLocationStatusEnum = exports.POSLocationTypeEnum = exports.warehouseTypeEnum = exports.warehouseStatusEnum = exports.movementStatusEnum = exports.movementTypeEnum = exports.damageSeverityEnum = exports.damageTypeEnum = exports.inventoryStatusEnum = exports.inventoryLocationTypeEnum = void 0;
|
|
4
|
+
exports.productSuppliers = exports.purchaseOrderItems = exports.purchaseOrders = void 0;
|
|
5
|
+
const cuid2_1 = require("@paralleldrive/cuid2");
|
|
6
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const common_schemas_1 = require("../common/common-schemas");
|
|
9
|
+
// =====================================================
|
|
10
|
+
// ENUMS
|
|
11
|
+
// =====================================================
|
|
12
|
+
exports.inventoryLocationTypeEnum = (0, pg_core_1.pgEnum)("inventory_location_type", [
|
|
13
|
+
"WAREHOUSE",
|
|
14
|
+
"POS",
|
|
15
|
+
]);
|
|
16
|
+
exports.inventoryStatusEnum = (0, pg_core_1.pgEnum)("inventory_status", [
|
|
17
|
+
"IN_STOCK",
|
|
18
|
+
"OUT_OF_STOCK",
|
|
19
|
+
"RESERVED",
|
|
20
|
+
"DAMAGED",
|
|
21
|
+
"IN_TRANSIT",
|
|
22
|
+
"QUARANTINED",
|
|
23
|
+
"RETURNED",
|
|
24
|
+
"EXPIRED",
|
|
25
|
+
"LOST",
|
|
26
|
+
"ADJUSTED",
|
|
27
|
+
]);
|
|
28
|
+
exports.damageTypeEnum = (0, pg_core_1.pgEnum)("damage_type", [
|
|
29
|
+
"PHYSICAL_DAMAGE",
|
|
30
|
+
"WATER_DAMAGE",
|
|
31
|
+
"FIRE_DAMAGE",
|
|
32
|
+
"MANUFACTURING_DEFECT",
|
|
33
|
+
"PACKAGING_DAMAGE",
|
|
34
|
+
"EXPIRED",
|
|
35
|
+
"CONTAMINATED",
|
|
36
|
+
"MISSING_PARTS",
|
|
37
|
+
"WRONG_ITEM",
|
|
38
|
+
"CUSTOMER_RETURN_DAMAGED",
|
|
39
|
+
"TRANSIT_DAMAGE",
|
|
40
|
+
"STORAGE_DAMAGE",
|
|
41
|
+
"THEFT_PARTIAL",
|
|
42
|
+
"OBSOLETE",
|
|
43
|
+
"OTHER",
|
|
44
|
+
]);
|
|
45
|
+
exports.damageSeverityEnum = (0, pg_core_1.pgEnum)("damage_severity", [
|
|
46
|
+
"MINOR",
|
|
47
|
+
"MODERATE",
|
|
48
|
+
"SEVERE",
|
|
49
|
+
"COSMETIC",
|
|
50
|
+
]);
|
|
51
|
+
exports.movementTypeEnum = (0, pg_core_1.pgEnum)("movement_type", [
|
|
52
|
+
"PURCHASE_RECEIPT",
|
|
53
|
+
"TRANSFER_IN",
|
|
54
|
+
"RETURN_FROM_CUSTOMER",
|
|
55
|
+
"PRODUCTION_COMPLETE",
|
|
56
|
+
"ADJUSTMENT_INCREASE",
|
|
57
|
+
"FOUND_INVENTORY",
|
|
58
|
+
"SALE",
|
|
59
|
+
"TRANSFER_OUT",
|
|
60
|
+
"RETURN_TO_SUPPLIER",
|
|
61
|
+
"DAMAGED_GOODS",
|
|
62
|
+
"EXPIRED_GOODS",
|
|
63
|
+
"THEFT_LOSS",
|
|
64
|
+
"ADJUSTMENT_DECREASE",
|
|
65
|
+
"WASTE",
|
|
66
|
+
"SAMPLE",
|
|
67
|
+
"PROMOTIONAL_USE",
|
|
68
|
+
"LOCATION_TRANSFER",
|
|
69
|
+
"ZONE_TRANSFER",
|
|
70
|
+
"BIN_TRANSFER",
|
|
71
|
+
"CYCLE_COUNT_ADJUSTMENT",
|
|
72
|
+
"PHYSICAL_COUNT_ADJUSTMENT",
|
|
73
|
+
"RESERVE",
|
|
74
|
+
"UNRESERVE",
|
|
75
|
+
"ALLOCATE",
|
|
76
|
+
"DEALLOCATE",
|
|
77
|
+
"MARK_DAMAGED",
|
|
78
|
+
"REPAIR_DAMAGED",
|
|
79
|
+
"DISPOSE_DAMAGED",
|
|
80
|
+
"QUARANTINE",
|
|
81
|
+
"RELEASE_QUARANTINE",
|
|
82
|
+
"STOCK_RECONCILIATION",
|
|
83
|
+
]);
|
|
84
|
+
exports.movementStatusEnum = (0, pg_core_1.pgEnum)("movement_status", [
|
|
85
|
+
"DRAFT",
|
|
86
|
+
"PENDING",
|
|
87
|
+
"IN_PROGRESS",
|
|
88
|
+
"COMPLETED",
|
|
89
|
+
"CANCELLED",
|
|
90
|
+
"FAILED",
|
|
91
|
+
]);
|
|
92
|
+
exports.warehouseStatusEnum = (0, pg_core_1.pgEnum)("warehouse_status", [
|
|
93
|
+
"ACTIVE",
|
|
94
|
+
"INACTIVE",
|
|
95
|
+
"CLOSED",
|
|
96
|
+
]);
|
|
97
|
+
exports.warehouseTypeEnum = (0, pg_core_1.pgEnum)("warehouse_type", [
|
|
98
|
+
"DISTRIBUTION_CENTER",
|
|
99
|
+
"FULFILLMENT_CENTER",
|
|
100
|
+
"COLD_STORAGE",
|
|
101
|
+
"BULK_STORAGE",
|
|
102
|
+
"CROSS_DOCK",
|
|
103
|
+
"RETAIL_WAREHOUSE",
|
|
104
|
+
"MANUFACTURING_WAREHOUSE",
|
|
105
|
+
"3PL_WAREHOUSE",
|
|
106
|
+
]);
|
|
107
|
+
// =====================================================
|
|
108
|
+
// Zod Enums and Schemas (co-located for single-source-of-truth)
|
|
109
|
+
// =====================================================
|
|
110
|
+
exports.POSLocationTypeEnum = zod_1.z.enum([
|
|
111
|
+
"RETAIL",
|
|
112
|
+
"KIOSK",
|
|
113
|
+
"POPUP",
|
|
114
|
+
"OTHER",
|
|
115
|
+
]);
|
|
116
|
+
exports.POSLocationStatusEnum = zod_1.z.enum(["ACTIVE", "INACTIVE", "CLOSED"]);
|
|
117
|
+
exports.WarehouseStatusEnum = zod_1.z.enum(["ACTIVE", "INACTIVE", "CLOSED"]);
|
|
118
|
+
exports.WarehouseTypeEnum = zod_1.z.enum([
|
|
119
|
+
"DISTRIBUTION_CENTER",
|
|
120
|
+
"FULFILLMENT_CENTER",
|
|
121
|
+
"COLD_STORAGE",
|
|
122
|
+
"BULK_STORAGE",
|
|
123
|
+
"CROSS_DOCK",
|
|
124
|
+
"RETAIL_WAREHOUSE",
|
|
125
|
+
"MANUFACTURING_WAREHOUSE",
|
|
126
|
+
"3PL_WAREHOUSE",
|
|
127
|
+
]);
|
|
128
|
+
exports.InventoryStatusEnum = zod_1.z.enum([
|
|
129
|
+
"IN_STOCK",
|
|
130
|
+
"OUT_OF_STOCK",
|
|
131
|
+
"RESERVED",
|
|
132
|
+
"DAMAGED",
|
|
133
|
+
"IN_TRANSIT",
|
|
134
|
+
"QUARANTINED",
|
|
135
|
+
"RETURNED",
|
|
136
|
+
"EXPIRED",
|
|
137
|
+
"LOST",
|
|
138
|
+
"ADJUSTED",
|
|
139
|
+
]);
|
|
140
|
+
exports.LocationTypeEnum = zod_1.z.enum(["WAREHOUSE", "POS"]);
|
|
141
|
+
exports.InventoryTransferStatusEnum = zod_1.z.enum([
|
|
142
|
+
"PENDING",
|
|
143
|
+
"IN_TRANSIT",
|
|
144
|
+
"COMPLETED",
|
|
145
|
+
"CANCELLED",
|
|
146
|
+
"FAILED",
|
|
147
|
+
"PARTIAL",
|
|
148
|
+
"RETURNED",
|
|
149
|
+
]);
|
|
150
|
+
exports.InventoryTransferTypeEnum = zod_1.z.enum([
|
|
151
|
+
"WAREHOUSE_TO_WAREHOUSE",
|
|
152
|
+
"WAREHOUSE_TO_POS",
|
|
153
|
+
"POS_TO_WAREHOUSE",
|
|
154
|
+
"POS_TO_POS",
|
|
155
|
+
"SUPPLIER_TO_WAREHOUSE",
|
|
156
|
+
"WAREHOUSE_TO_CUSTOMER",
|
|
157
|
+
"INTERNAL_TRANSFER",
|
|
158
|
+
]);
|
|
159
|
+
exports.PurchaseOrderStatusEnum = zod_1.z.enum([
|
|
160
|
+
"DRAFT",
|
|
161
|
+
"SENT",
|
|
162
|
+
"ACKNOWLEDGED",
|
|
163
|
+
"APPROVED",
|
|
164
|
+
"PENDING_APPROVAL",
|
|
165
|
+
"PARTIALLY_RECEIVED",
|
|
166
|
+
"RECEIVED",
|
|
167
|
+
"COMPLETED",
|
|
168
|
+
"CANCELLED",
|
|
169
|
+
"DISPUTED",
|
|
170
|
+
]);
|
|
171
|
+
exports.SupplierStatusEnum = zod_1.z.enum([
|
|
172
|
+
"ACTIVE",
|
|
173
|
+
"INACTIVE",
|
|
174
|
+
"SUSPENDED",
|
|
175
|
+
"UNDER_REVIEW",
|
|
176
|
+
"PENDING_APPROVAL",
|
|
177
|
+
"BLACKLISTED",
|
|
178
|
+
]);
|
|
179
|
+
exports.SupplierTypeEnum = zod_1.z.enum([
|
|
180
|
+
"MANUFACTURER",
|
|
181
|
+
"DISTRIBUTOR",
|
|
182
|
+
"WHOLESALER",
|
|
183
|
+
"DROPSHIPPER",
|
|
184
|
+
"SERVICE_PROVIDER",
|
|
185
|
+
"LOCAL_VENDOR",
|
|
186
|
+
"INTERNATIONAL_VENDOR",
|
|
187
|
+
"BROKER",
|
|
188
|
+
"IMPORTER",
|
|
189
|
+
"EXPORTER",
|
|
190
|
+
"RETAILER",
|
|
191
|
+
"RESELLER",
|
|
192
|
+
"CONTRACTOR",
|
|
193
|
+
"CONSULTANT",
|
|
194
|
+
"PARTS_SUPPLIER",
|
|
195
|
+
"RAW_MATERIALS_SUPPLIER",
|
|
196
|
+
"PACKAGING_SUPPLIER",
|
|
197
|
+
"EQUIPMENT_SUPPLIER",
|
|
198
|
+
"MAINTENANCE_SUPPLIER",
|
|
199
|
+
"LOGISTICS_PROVIDER",
|
|
200
|
+
"FREIGHT_FORWARDER",
|
|
201
|
+
"CUSTOMS_BROKER",
|
|
202
|
+
"TECHNOLOGY_VENDOR",
|
|
203
|
+
"SOFTWARE_VENDOR",
|
|
204
|
+
"HARDWARE_VENDOR",
|
|
205
|
+
"OFFICE_SUPPLIES_VENDOR",
|
|
206
|
+
"UTILITIES_PROVIDER",
|
|
207
|
+
"CLEANING_SERVICES",
|
|
208
|
+
"SECURITY_SERVICES",
|
|
209
|
+
"MARKETING_SERVICES",
|
|
210
|
+
"PROFESSIONAL_SERVICES",
|
|
211
|
+
"TEMPORARY_STAFFING",
|
|
212
|
+
"SPECIALIZED_SUPPLIER",
|
|
213
|
+
"OTHER",
|
|
214
|
+
]);
|
|
215
|
+
exports.SupplierRatingEnum = zod_1.z.enum([
|
|
216
|
+
"EXCELLENT",
|
|
217
|
+
"GOOD",
|
|
218
|
+
"AVERAGE",
|
|
219
|
+
"POOR",
|
|
220
|
+
"UNRATED",
|
|
221
|
+
]);
|
|
222
|
+
exports.QualityStatusEnum = zod_1.z.enum([
|
|
223
|
+
"PENDING_INSPECTION",
|
|
224
|
+
"PASSED",
|
|
225
|
+
"FAILED",
|
|
226
|
+
"CONDITIONALLY_PASSED",
|
|
227
|
+
"QUARANTINED",
|
|
228
|
+
"REJECTED",
|
|
229
|
+
"REWORK_REQUIRED",
|
|
230
|
+
"RELEASED",
|
|
231
|
+
"HOLD",
|
|
232
|
+
]);
|
|
233
|
+
exports.InspectionTypeEnum = zod_1.z.enum([
|
|
234
|
+
"INCOMING_INSPECTION",
|
|
235
|
+
"IN_PROCESS_INSPECTION",
|
|
236
|
+
"OUTGOING_INSPECTION",
|
|
237
|
+
"RANDOM_INSPECTION",
|
|
238
|
+
"CUSTOMER_COMPLAINT_INSPECTION",
|
|
239
|
+
"SUPPLIER_AUDIT",
|
|
240
|
+
"PERIODIC_REVIEW",
|
|
241
|
+
"EXPIRY_CHECK",
|
|
242
|
+
"DAMAGE_ASSESSMENT",
|
|
243
|
+
]);
|
|
244
|
+
exports.QualityGradeEnum = zod_1.z.enum(["A", "B", "C", "D", "F"]);
|
|
245
|
+
exports.DefectSeverityEnum = zod_1.z.enum([
|
|
246
|
+
"CRITICAL",
|
|
247
|
+
"MAJOR",
|
|
248
|
+
"MINOR",
|
|
249
|
+
"COSMETIC",
|
|
250
|
+
]);
|
|
251
|
+
// Zod schemas for key resources
|
|
252
|
+
exports.InventorySchema = zod_1.z.object({
|
|
253
|
+
id: common_schemas_1.CuidSchema,
|
|
254
|
+
storeId: zod_1.z.string(),
|
|
255
|
+
productId: zod_1.z.string(),
|
|
256
|
+
variantId: zod_1.z.string().optional(),
|
|
257
|
+
sku: zod_1.z.string(),
|
|
258
|
+
barcode: zod_1.z.string(),
|
|
259
|
+
locationId: zod_1.z.string(),
|
|
260
|
+
locationType: exports.LocationTypeEnum,
|
|
261
|
+
quantity: zod_1.z.number().int().nonnegative(),
|
|
262
|
+
reserved: zod_1.z.number().int().nonnegative().optional(),
|
|
263
|
+
committed: zod_1.z.number().int().nonnegative().optional(),
|
|
264
|
+
unitCost: zod_1.z.number().nonnegative().optional(),
|
|
265
|
+
status: exports.InventoryStatusEnum.default("IN_STOCK"),
|
|
266
|
+
batchNumber: zod_1.z.string().optional(),
|
|
267
|
+
lotNumber: zod_1.z.string().optional(),
|
|
268
|
+
expiryDate: zod_1.z.coerce.date().optional(),
|
|
269
|
+
lowStockThreshold: zod_1.z.number().int().nonnegative().optional(),
|
|
270
|
+
criticalStockThreshold: zod_1.z.number().int().nonnegative().optional(),
|
|
271
|
+
available: zod_1.z.number().int().nonnegative().default(0),
|
|
272
|
+
notes: zod_1.z.string().optional(),
|
|
273
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
274
|
+
version: zod_1.z.number().int().default(1),
|
|
275
|
+
isActive: zod_1.z.boolean().default(true),
|
|
276
|
+
createdAt: zod_1.z.date(),
|
|
277
|
+
updatedAt: zod_1.z.date(),
|
|
278
|
+
createdBy: zod_1.z.string().optional(),
|
|
279
|
+
updatedBy: zod_1.z.string().optional(),
|
|
280
|
+
});
|
|
281
|
+
exports.InventoryMovementSchema = zod_1.z
|
|
282
|
+
.object({
|
|
283
|
+
id: common_schemas_1.CuidSchema,
|
|
284
|
+
storeId: zod_1.z.string(),
|
|
285
|
+
movementNumber: zod_1.z.string(),
|
|
286
|
+
movementType: zod_1.z.enum([
|
|
287
|
+
"PURCHASE_RECEIPT",
|
|
288
|
+
"TRANSFER_IN",
|
|
289
|
+
"RETURN_FROM_CUSTOMER",
|
|
290
|
+
"PRODUCTION_COMPLETE",
|
|
291
|
+
"ADJUSTMENT_INCREASE",
|
|
292
|
+
"FOUND_INVENTORY",
|
|
293
|
+
"SALE",
|
|
294
|
+
"TRANSFER_OUT",
|
|
295
|
+
"RETURN_TO_SUPPLIER",
|
|
296
|
+
"DAMAGED_GOODS",
|
|
297
|
+
"EXPIRED_GOODS",
|
|
298
|
+
"THEFT_LOSS",
|
|
299
|
+
"ADJUSTMENT_DECREASE",
|
|
300
|
+
"WASTE",
|
|
301
|
+
"SAMPLE",
|
|
302
|
+
"PROMOTIONAL_USE",
|
|
303
|
+
"LOCATION_TRANSFER",
|
|
304
|
+
"ZONE_TRANSFER",
|
|
305
|
+
"BIN_TRANSFER",
|
|
306
|
+
"CYCLE_COUNT_ADJUSTMENT",
|
|
307
|
+
"PHYSICAL_COUNT_ADJUSTMENT",
|
|
308
|
+
"RESERVE",
|
|
309
|
+
"UNRESERVE",
|
|
310
|
+
"ALLOCATE",
|
|
311
|
+
"DEALLOCATE",
|
|
312
|
+
]),
|
|
313
|
+
status: zod_1.z.enum([
|
|
314
|
+
"DRAFT",
|
|
315
|
+
"PENDING",
|
|
316
|
+
"IN_PROGRESS",
|
|
317
|
+
"COMPLETED",
|
|
318
|
+
"CANCELLED",
|
|
319
|
+
"FAILED",
|
|
320
|
+
]),
|
|
321
|
+
productId: zod_1.z.string(),
|
|
322
|
+
variantId: zod_1.z.string().optional(),
|
|
323
|
+
sku: zod_1.z.string(),
|
|
324
|
+
quantityMoved: zod_1.z.number(),
|
|
325
|
+
fromLocationId: zod_1.z.string().optional(),
|
|
326
|
+
toLocationId: zod_1.z.string().optional(),
|
|
327
|
+
unitCost: zod_1.z.number().optional(),
|
|
328
|
+
reason: zod_1.z.string().optional(),
|
|
329
|
+
movementDate: zod_1.z.coerce.date(),
|
|
330
|
+
createdAt: zod_1.z.date(),
|
|
331
|
+
updatedAt: zod_1.z.date(),
|
|
332
|
+
})
|
|
333
|
+
.catchall(zod_1.z.any());
|
|
334
|
+
exports.InventoryTransferSchema = zod_1.z
|
|
335
|
+
.object({ id: common_schemas_1.CuidSchema })
|
|
336
|
+
.catchall(zod_1.z.any());
|
|
337
|
+
exports.QualityControlSchema = zod_1.z
|
|
338
|
+
.object({
|
|
339
|
+
id: common_schemas_1.CuidSchema,
|
|
340
|
+
qcNumber: zod_1.z.string(),
|
|
341
|
+
inspectedBy: zod_1.z.string(),
|
|
342
|
+
inspectionDate: zod_1.z.date(),
|
|
343
|
+
createdAt: zod_1.z.date(),
|
|
344
|
+
updatedAt: zod_1.z.date(),
|
|
345
|
+
})
|
|
346
|
+
.catchall(zod_1.z.any());
|
|
347
|
+
exports.QualityTemplateSchema = zod_1.z
|
|
348
|
+
.object({
|
|
349
|
+
id: common_schemas_1.CuidSchema,
|
|
350
|
+
createdAt: zod_1.z.date(),
|
|
351
|
+
updatedAt: zod_1.z.date(),
|
|
352
|
+
createdBy: zod_1.z.string().optional(),
|
|
353
|
+
updatedBy: zod_1.z.string().optional(),
|
|
354
|
+
})
|
|
355
|
+
.catchall(zod_1.z.any());
|
|
356
|
+
exports.SupplierQualityRatingSchema = zod_1.z
|
|
357
|
+
.object({
|
|
358
|
+
id: common_schemas_1.CuidSchema,
|
|
359
|
+
reviewedBy: zod_1.z.string().optional(),
|
|
360
|
+
reviewedAt: zod_1.z.date().optional(),
|
|
361
|
+
createdAt: zod_1.z.date(),
|
|
362
|
+
updatedAt: zod_1.z.date(),
|
|
363
|
+
})
|
|
364
|
+
.catchall(zod_1.z.any());
|
|
365
|
+
exports.POSLocationSchema = zod_1.z.object({
|
|
366
|
+
id: common_schemas_1.CuidSchema,
|
|
367
|
+
storeId: zod_1.z.string(),
|
|
368
|
+
code: zod_1.z.string(),
|
|
369
|
+
name: zod_1.z.string(),
|
|
370
|
+
displayName: zod_1.z.string().optional(),
|
|
371
|
+
type: exports.POSLocationTypeEnum,
|
|
372
|
+
posType: exports.POSLocationTypeEnum.optional(),
|
|
373
|
+
status: exports.POSLocationStatusEnum,
|
|
374
|
+
geoLocation: common_schemas_1.GeoLocationSchema,
|
|
375
|
+
address: zod_1.z
|
|
376
|
+
.object({
|
|
377
|
+
street: zod_1.z.string().optional(),
|
|
378
|
+
line1: zod_1.z.string().optional(),
|
|
379
|
+
line2: zod_1.z.string().optional(),
|
|
380
|
+
city: zod_1.z.string(),
|
|
381
|
+
state: zod_1.z.string(),
|
|
382
|
+
postalCode: zod_1.z.string(),
|
|
383
|
+
country: zod_1.z.string(),
|
|
384
|
+
coordinates: zod_1.z.object({ lat: zod_1.z.number(), lng: zod_1.z.number() }).optional(),
|
|
385
|
+
})
|
|
386
|
+
.optional(),
|
|
387
|
+
timezone: zod_1.z.string().default("UTC"),
|
|
388
|
+
primaryContact: common_schemas_1.ContactInfoSchema.optional(),
|
|
389
|
+
managementContacts: zod_1.z.array(common_schemas_1.ContactInfoSchema).optional(),
|
|
390
|
+
emergencyContact: common_schemas_1.ContactInfoSchema.optional(),
|
|
391
|
+
businessHours: common_schemas_1.BusinessHoursSchema.optional(),
|
|
392
|
+
posSystemInfo: zod_1.z
|
|
393
|
+
.object({
|
|
394
|
+
systemName: zod_1.z.string().optional(),
|
|
395
|
+
version: zod_1.z.string().optional(),
|
|
396
|
+
lastSync: zod_1.z.coerce.date().optional(),
|
|
397
|
+
supportedPaymentMethods: zod_1.z.array(zod_1.z.string()).optional(),
|
|
398
|
+
isActive: zod_1.z.boolean().default(true),
|
|
399
|
+
})
|
|
400
|
+
.optional(),
|
|
401
|
+
allowBackorders: zod_1.z.boolean().default(false).optional(),
|
|
402
|
+
autoFulfillment: zod_1.z.boolean().default(true).optional(),
|
|
403
|
+
supportedFeatures: zod_1.z
|
|
404
|
+
.array(zod_1.z.enum([
|
|
405
|
+
"CASH_PAYMENT",
|
|
406
|
+
"CARD_PAYMENT",
|
|
407
|
+
"MOBILE_PAYMENT",
|
|
408
|
+
"GIFT_CARDS",
|
|
409
|
+
"LAYAWAY",
|
|
410
|
+
"RETURNS_EXCHANGES",
|
|
411
|
+
"PRODUCT_LOOKUP",
|
|
412
|
+
"INVENTORY_CHECK",
|
|
413
|
+
"CUSTOMER_ORDERS",
|
|
414
|
+
"RESERVATIONS",
|
|
415
|
+
"LOYALTY_PROGRAM",
|
|
416
|
+
"PROMOTIONS",
|
|
417
|
+
"TAX_CALCULATION",
|
|
418
|
+
"RECEIPT_PRINTING",
|
|
419
|
+
"EMAIL_RECEIPTS",
|
|
420
|
+
"BARCODE_SCANNING",
|
|
421
|
+
"PRICE_CHECKING",
|
|
422
|
+
]))
|
|
423
|
+
.optional(),
|
|
424
|
+
hardware: zod_1.z
|
|
425
|
+
.array(zod_1.z.object({
|
|
426
|
+
id: zod_1.z.string(),
|
|
427
|
+
type: zod_1.z.enum([
|
|
428
|
+
"POS_TERMINAL",
|
|
429
|
+
"CASH_REGISTER",
|
|
430
|
+
"BARCODE_SCANNER",
|
|
431
|
+
"RECEIPT_PRINTER",
|
|
432
|
+
"CARD_READER",
|
|
433
|
+
"SCALE",
|
|
434
|
+
"SECURITY_CAMERA",
|
|
435
|
+
"CASH_DRAWER",
|
|
436
|
+
"DISPLAY_MONITOR",
|
|
437
|
+
"TABLET",
|
|
438
|
+
]),
|
|
439
|
+
brand: zod_1.z.string().optional(),
|
|
440
|
+
model: zod_1.z.string().optional(),
|
|
441
|
+
serialNumber: zod_1.z.string().optional(),
|
|
442
|
+
status: zod_1.z.enum(["ACTIVE", "MAINTENANCE", "INACTIVE"]),
|
|
443
|
+
lastMaintenance: zod_1.z.coerce.date().optional(),
|
|
444
|
+
}))
|
|
445
|
+
.optional(),
|
|
446
|
+
inventorySettings: zod_1.z
|
|
447
|
+
.object({
|
|
448
|
+
allowNegativeInventory: zod_1.z.boolean().default(false),
|
|
449
|
+
autoReorderEnabled: zod_1.z.boolean().default(false),
|
|
450
|
+
lowStockWarningEnabled: zod_1.z.boolean().default(true),
|
|
451
|
+
stockCountRequired: zod_1.z.boolean().default(false),
|
|
452
|
+
barcodeRequired: zod_1.z.boolean().default(false),
|
|
453
|
+
})
|
|
454
|
+
.optional(),
|
|
455
|
+
salesSettings: zod_1.z
|
|
456
|
+
.object({
|
|
457
|
+
taxRate: zod_1.z.number().min(0).max(100).optional(),
|
|
458
|
+
taxExemptAvailable: zod_1.z.boolean().default(false),
|
|
459
|
+
discountingEnabled: zod_1.z.boolean().default(true),
|
|
460
|
+
maxDiscountPercent: zod_1.z.number().min(0).max(100).optional(),
|
|
461
|
+
returnsEnabled: zod_1.z.boolean().default(true),
|
|
462
|
+
returnDayLimit: zod_1.z.number().int().nonnegative().optional(),
|
|
463
|
+
receiptRequired: zod_1.z.boolean().default(true),
|
|
464
|
+
})
|
|
465
|
+
.optional(),
|
|
466
|
+
customerServices: zod_1.z
|
|
467
|
+
.array(zod_1.z.enum([
|
|
468
|
+
"PERSONAL_SHOPPING",
|
|
469
|
+
"ALTERATIONS",
|
|
470
|
+
"GIFT_WRAPPING",
|
|
471
|
+
"DELIVERY",
|
|
472
|
+
"INSTALLATION",
|
|
473
|
+
"REPAIR_SERVICE",
|
|
474
|
+
"CONSULTATION",
|
|
475
|
+
"TRAINING",
|
|
476
|
+
"RENTAL",
|
|
477
|
+
"CUSTOM_ORDERS",
|
|
478
|
+
]))
|
|
479
|
+
.optional(),
|
|
480
|
+
operationalCosts: zod_1.z
|
|
481
|
+
.object({
|
|
482
|
+
monthlyRent: zod_1.z.number().nonnegative().optional(),
|
|
483
|
+
utilities: zod_1.z.number().nonnegative().optional(),
|
|
484
|
+
labor: zod_1.z.number().nonnegative().optional(),
|
|
485
|
+
maintenance: zod_1.z.number().nonnegative().optional(),
|
|
486
|
+
insurance: zod_1.z.number().nonnegative().optional(),
|
|
487
|
+
currency: zod_1.z.string().length(3).default("USD"),
|
|
488
|
+
})
|
|
489
|
+
.optional(),
|
|
490
|
+
securityFeatures: zod_1.z.array(zod_1.z.string()).optional(),
|
|
491
|
+
complianceRequirements: zod_1.z.array(zod_1.z.string()).optional(),
|
|
492
|
+
lastSecurityAudit: zod_1.z.coerce.date().optional(),
|
|
493
|
+
description: zod_1.z.string().optional(),
|
|
494
|
+
notes: zod_1.z.string().optional(),
|
|
495
|
+
internalNotes: zod_1.z.string().optional(),
|
|
496
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
497
|
+
customAttributes: zod_1.z.record(zod_1.z.any()).optional(),
|
|
498
|
+
version: zod_1.z.number().int().default(1),
|
|
499
|
+
isActive: zod_1.z.boolean().default(true),
|
|
500
|
+
createdAt: zod_1.z.date(),
|
|
501
|
+
updatedAt: zod_1.z.date(),
|
|
502
|
+
createdBy: zod_1.z.string().optional(),
|
|
503
|
+
updatedBy: zod_1.z.string().optional(),
|
|
504
|
+
auditTrail: zod_1.z.array(common_schemas_1.AuditTrailSchema).optional(),
|
|
505
|
+
});
|
|
506
|
+
exports.WarehouseSchema = zod_1.z.object({
|
|
507
|
+
id: common_schemas_1.CuidSchema,
|
|
508
|
+
storeId: zod_1.z.string(),
|
|
509
|
+
code: zod_1.z.string(),
|
|
510
|
+
name: zod_1.z.string(),
|
|
511
|
+
displayName: zod_1.z.string().optional(),
|
|
512
|
+
type: exports.WarehouseTypeEnum,
|
|
513
|
+
status: exports.WarehouseStatusEnum,
|
|
514
|
+
address: zod_1.z
|
|
515
|
+
.object({
|
|
516
|
+
street: zod_1.z.string(),
|
|
517
|
+
city: zod_1.z.string(),
|
|
518
|
+
state: zod_1.z.string(),
|
|
519
|
+
postalCode: zod_1.z.string(),
|
|
520
|
+
country: zod_1.z.string(),
|
|
521
|
+
coordinates: zod_1.z.object({ lat: zod_1.z.number(), lng: zod_1.z.number() }).optional(),
|
|
522
|
+
})
|
|
523
|
+
.optional(),
|
|
524
|
+
timezone: zod_1.z.string().default("UTC"),
|
|
525
|
+
primaryContact: zod_1.z
|
|
526
|
+
.object({ name: zod_1.z.string(), email: zod_1.z.string(), phone: zod_1.z.string() })
|
|
527
|
+
.optional(),
|
|
528
|
+
totalArea: zod_1.z.number().nonnegative().optional(),
|
|
529
|
+
storageArea: zod_1.z.number().nonnegative().optional(),
|
|
530
|
+
ceilingHeight: zod_1.z.number().nonnegative().optional(),
|
|
531
|
+
capacity: zod_1.z
|
|
532
|
+
.object({
|
|
533
|
+
volumetric: zod_1.z.number().nonnegative().optional(),
|
|
534
|
+
weight: zod_1.z.number().nonnegative().optional(),
|
|
535
|
+
palletPositions: zod_1.z.number().int().nonnegative().optional(),
|
|
536
|
+
pickingLocations: zod_1.z.number().int().nonnegative().optional(),
|
|
537
|
+
unit: zod_1.z.string().optional(),
|
|
538
|
+
})
|
|
539
|
+
.optional(),
|
|
540
|
+
zones: zod_1.z
|
|
541
|
+
.array(zod_1.z.object({
|
|
542
|
+
id: zod_1.z.string(),
|
|
543
|
+
code: zod_1.z.string(),
|
|
544
|
+
name: zod_1.z.string(),
|
|
545
|
+
type: zod_1.z.string(),
|
|
546
|
+
description: zod_1.z.string().optional(),
|
|
547
|
+
capacity: zod_1.z.number().nonnegative().optional(),
|
|
548
|
+
temperature: zod_1.z
|
|
549
|
+
.object({ min: zod_1.z.number(), max: zod_1.z.number(), unit: zod_1.z.string() })
|
|
550
|
+
.optional(),
|
|
551
|
+
humidity: zod_1.z
|
|
552
|
+
.object({
|
|
553
|
+
min: zod_1.z.number().min(0).max(100),
|
|
554
|
+
max: zod_1.z.number().min(0).max(100),
|
|
555
|
+
})
|
|
556
|
+
.optional(),
|
|
557
|
+
binLocations: zod_1.z
|
|
558
|
+
.array(zod_1.z.object({
|
|
559
|
+
id: zod_1.z.string(),
|
|
560
|
+
code: zod_1.z.string(),
|
|
561
|
+
row: zod_1.z.string().optional(),
|
|
562
|
+
bay: zod_1.z.string().optional(),
|
|
563
|
+
level: zod_1.z.string().optional(),
|
|
564
|
+
capacity: zod_1.z.number().nonnegative().optional(),
|
|
565
|
+
isActive: zod_1.z.boolean().default(true),
|
|
566
|
+
}))
|
|
567
|
+
.optional(),
|
|
568
|
+
isActive: zod_1.z.boolean().default(true),
|
|
569
|
+
}))
|
|
570
|
+
.optional(),
|
|
571
|
+
description: zod_1.z.string().optional(),
|
|
572
|
+
notes: zod_1.z.string().optional(),
|
|
573
|
+
internalNotes: zod_1.z.string().optional(),
|
|
574
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
575
|
+
version: zod_1.z.number().int().default(1),
|
|
576
|
+
isActive: zod_1.z.boolean().default(true),
|
|
577
|
+
createdAt: zod_1.z.date(),
|
|
578
|
+
updatedAt: zod_1.z.date(),
|
|
579
|
+
createdBy: zod_1.z.string().optional(),
|
|
580
|
+
updatedBy: zod_1.z.string().optional(),
|
|
581
|
+
auditTrail: zod_1.z.array(common_schemas_1.AuditTrailSchema).optional(),
|
|
582
|
+
});
|
|
583
|
+
// =====================================================
|
|
584
|
+
// INVENTORY TABLE
|
|
585
|
+
// =====================================================
|
|
586
|
+
exports.inventory = (0, pg_core_1.pgTable)("inventory", {
|
|
587
|
+
id: (0, pg_core_1.text)("id")
|
|
588
|
+
.primaryKey()
|
|
589
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
590
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
591
|
+
productId: (0, pg_core_1.text)("product_id").notNull(),
|
|
592
|
+
variantId: (0, pg_core_1.text)("variant_id"),
|
|
593
|
+
sku: (0, pg_core_1.varchar)("sku", { length: 255 }).notNull(),
|
|
594
|
+
barcode: (0, pg_core_1.varchar)("barcode", { length: 255 }).notNull(),
|
|
595
|
+
locationId: (0, pg_core_1.text)("location_id").notNull(),
|
|
596
|
+
locationType: (0, exports.inventoryLocationTypeEnum)("location_type").notNull(),
|
|
597
|
+
// Zone and Bin Information
|
|
598
|
+
zoneId: (0, pg_core_1.text)("zone_id"),
|
|
599
|
+
binLocation: (0, pg_core_1.varchar)("bin_location", { length: 100 }),
|
|
600
|
+
// Batch and Serial Tracking
|
|
601
|
+
batchNumber: (0, pg_core_1.varchar)("batch_number", { length: 255 }),
|
|
602
|
+
lotNumber: (0, pg_core_1.varchar)("lot_number", { length: 255 }),
|
|
603
|
+
serialNumbers: (0, pg_core_1.jsonb)("serial_numbers").$type(),
|
|
604
|
+
// Quantity Management
|
|
605
|
+
quantity: (0, pg_core_1.integer)("quantity").notNull().default(0),
|
|
606
|
+
reserved: (0, pg_core_1.integer)("reserved").notNull().default(0),
|
|
607
|
+
available: (0, pg_core_1.integer)("available").notNull().default(0),
|
|
608
|
+
committed: (0, pg_core_1.integer)("committed").notNull().default(0),
|
|
609
|
+
inTransit: (0, pg_core_1.integer)("in_transit").notNull().default(0),
|
|
610
|
+
onOrder: (0, pg_core_1.integer)("on_order").notNull().default(0),
|
|
611
|
+
// Stock Level Management
|
|
612
|
+
reorderPoint: (0, pg_core_1.integer)("reorder_point"),
|
|
613
|
+
maxStockLevel: (0, pg_core_1.integer)("max_stock_level"),
|
|
614
|
+
safetyStock: (0, pg_core_1.integer)("safety_stock").notNull().default(0),
|
|
615
|
+
// Unit of Measure
|
|
616
|
+
baseUnitId: (0, pg_core_1.text)("base_unit_id").notNull(),
|
|
617
|
+
unitOfMeasure: (0, pg_core_1.varchar)("unit_of_measure", { length: 50 })
|
|
618
|
+
.notNull()
|
|
619
|
+
.default("EACH"),
|
|
620
|
+
// Cost Information
|
|
621
|
+
unitCost: (0, pg_core_1.decimal)("unit_cost", { precision: 12, scale: 4 }),
|
|
622
|
+
averageCost: (0, pg_core_1.decimal)("average_cost", { precision: 12, scale: 4 }),
|
|
623
|
+
lastCost: (0, pg_core_1.decimal)("last_cost", { precision: 12, scale: 4 }),
|
|
624
|
+
standardCost: (0, pg_core_1.decimal)("standard_cost", { precision: 12, scale: 4 }),
|
|
625
|
+
costingMethod: (0, pg_core_1.varchar)("costing_method", { length: 20 }),
|
|
626
|
+
// Status and Condition
|
|
627
|
+
status: (0, exports.inventoryStatusEnum)("status").notNull().default("IN_STOCK"),
|
|
628
|
+
condition: (0, pg_core_1.varchar)("condition", { length: 100 }),
|
|
629
|
+
qualityGrade: (0, pg_core_1.varchar)("quality_grade", { length: 50 }),
|
|
630
|
+
// Date Information
|
|
631
|
+
expiryDate: (0, pg_core_1.timestamp)("expiry_date", { withTimezone: true }),
|
|
632
|
+
manufactureDate: (0, pg_core_1.timestamp)("manufacture_date", { withTimezone: true }),
|
|
633
|
+
receivedDate: (0, pg_core_1.timestamp)("received_date", { withTimezone: true }),
|
|
634
|
+
lastCountedAt: (0, pg_core_1.timestamp)("last_counted_at", { withTimezone: true }),
|
|
635
|
+
lastMovementDate: (0, pg_core_1.timestamp)("last_movement_date", { withTimezone: true }),
|
|
636
|
+
// Supplier Information
|
|
637
|
+
supplierId: (0, pg_core_1.text)("supplier_id"),
|
|
638
|
+
supplierSku: (0, pg_core_1.varchar)("supplier_sku", { length: 255 }),
|
|
639
|
+
// Alert Thresholds
|
|
640
|
+
lowStockThreshold: (0, pg_core_1.integer)("low_stock_threshold"),
|
|
641
|
+
criticalStockThreshold: (0, pg_core_1.integer)("critical_stock_threshold"),
|
|
642
|
+
expiryWarningDays: (0, pg_core_1.integer)("expiry_warning_days").notNull().default(30),
|
|
643
|
+
// Tracking Configuration
|
|
644
|
+
trackSerial: (0, pg_core_1.boolean)("track_serial").notNull().default(false),
|
|
645
|
+
trackBatch: (0, pg_core_1.boolean)("track_batch").notNull().default(false),
|
|
646
|
+
trackExpiry: (0, pg_core_1.boolean)("track_expiry").notNull().default(false),
|
|
647
|
+
// Damaged Stock Tracking
|
|
648
|
+
damagedQuantity: (0, pg_core_1.integer)("damaged_quantity").notNull().default(0),
|
|
649
|
+
damageType: (0, exports.damageTypeEnum)("damage_type"),
|
|
650
|
+
damageSeverity: (0, exports.damageSeverityEnum)("damage_severity"),
|
|
651
|
+
damageReason: (0, pg_core_1.text)("damage_reason"),
|
|
652
|
+
damageValue: (0, pg_core_1.decimal)("damage_value", { precision: 12, scale: 4 }),
|
|
653
|
+
damageDate: (0, pg_core_1.timestamp)("damage_date", { withTimezone: true }),
|
|
654
|
+
damageReportedBy: (0, pg_core_1.text)("damage_reported_by"),
|
|
655
|
+
damageNotes: (0, pg_core_1.text)("damage_notes"),
|
|
656
|
+
isRepairable: (0, pg_core_1.boolean)("is_repairable").notNull().default(false),
|
|
657
|
+
repairCost: (0, pg_core_1.decimal)("repair_cost", { precision: 12, scale: 4 }),
|
|
658
|
+
disposalDate: (0, pg_core_1.timestamp)("disposal_date", { withTimezone: true }),
|
|
659
|
+
disposalMethod: (0, pg_core_1.varchar)("disposal_method", { length: 100 }),
|
|
660
|
+
insuranceClaim: (0, pg_core_1.jsonb)("insurance_claim").$type(),
|
|
661
|
+
// Quality Tracking
|
|
662
|
+
qualityScore: (0, pg_core_1.integer)("quality_score"),
|
|
663
|
+
lastQualityCheck: (0, pg_core_1.timestamp)("last_quality_check", { withTimezone: true }),
|
|
664
|
+
// Quarantine Tracking
|
|
665
|
+
quarantinedQuantity: (0, pg_core_1.integer)("quarantined_quantity").notNull().default(0),
|
|
666
|
+
quarantineReason: (0, pg_core_1.text)("quarantine_reason"),
|
|
667
|
+
quarantineDate: (0, pg_core_1.timestamp)("quarantine_date", { withTimezone: true }),
|
|
668
|
+
quarantineReleaseDate: (0, pg_core_1.timestamp)("quarantine_release_date", { withTimezone: true }),
|
|
669
|
+
// Multi-location Tracking
|
|
670
|
+
isVirtualLocation: (0, pg_core_1.boolean)("is_virtual_location").notNull().default(false),
|
|
671
|
+
parentInventoryId: (0, pg_core_1.text)("parent_inventory_id"),
|
|
672
|
+
// ABC Classification
|
|
673
|
+
abcClassification: (0, pg_core_1.varchar)("abc_classification", { length: 1 }),
|
|
674
|
+
// Notes and Metadata
|
|
675
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
676
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"),
|
|
677
|
+
metadata: (0, pg_core_1.jsonb)("metadata").$type().default({}),
|
|
678
|
+
customAttributes: (0, pg_core_1.jsonb)("custom_attributes")
|
|
679
|
+
.$type()
|
|
680
|
+
.default({}),
|
|
681
|
+
// Version Control
|
|
682
|
+
version: (0, pg_core_1.integer)("version").notNull().default(1),
|
|
683
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(true),
|
|
684
|
+
// Timestamps
|
|
685
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
686
|
+
.defaultNow()
|
|
687
|
+
.notNull(),
|
|
688
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
689
|
+
.defaultNow()
|
|
690
|
+
.notNull(),
|
|
691
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
692
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
693
|
+
}, (table) => ({
|
|
694
|
+
// Performance indexes
|
|
695
|
+
storeIdIndex: (0, pg_core_1.index)("idx_inventory_store_id").on(table.storeId),
|
|
696
|
+
productIdIndex: (0, pg_core_1.index)("idx_inventory_product_id").on(table.productId),
|
|
697
|
+
locationIdIndex: (0, pg_core_1.index)("idx_inventory_location_id").on(table.locationId),
|
|
698
|
+
skuIndex: (0, pg_core_1.index)("idx_inventory_sku").on(table.sku),
|
|
699
|
+
barcodeIndex: (0, pg_core_1.index)("idx_inventory_barcode").on(table.barcode),
|
|
700
|
+
statusIndex: (0, pg_core_1.index)("idx_inventory_status").on(table.status),
|
|
701
|
+
// Unique constraints
|
|
702
|
+
uniqueProductLocation: (0, pg_core_1.unique)("idx_inventory_product_location_unique").on(table.storeId, table.productId, table.locationId, table.variantId),
|
|
703
|
+
uniqueSkuBarcode: (0, pg_core_1.unique)("idx_inventory_sku_barcode_unique").on(table.storeId, table.locationId, table.sku, table.barcode),
|
|
704
|
+
// Quantity and alerts indexes
|
|
705
|
+
quantityIndex: (0, pg_core_1.index)("idx_inventory_quantity").on(table.quantity),
|
|
706
|
+
lowStockIndex: (0, pg_core_1.index)("idx_inventory_low_stock").on(table.lowStockThreshold),
|
|
707
|
+
expiryIndex: (0, pg_core_1.index)("idx_inventory_expiry").on(table.expiryDate),
|
|
708
|
+
}));
|
|
709
|
+
// =====================================================
|
|
710
|
+
// INVENTORY MOVEMENTS TABLE
|
|
711
|
+
// =====================================================
|
|
712
|
+
exports.inventoryMovements = (0, pg_core_1.pgTable)("inventory_movements", {
|
|
713
|
+
id: (0, pg_core_1.text)("id")
|
|
714
|
+
.primaryKey()
|
|
715
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
716
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
717
|
+
movementNumber: (0, pg_core_1.varchar)("movement_number", { length: 100 }).notNull(),
|
|
718
|
+
// Movement Classification
|
|
719
|
+
movementType: (0, exports.movementTypeEnum)("movement_type").notNull(),
|
|
720
|
+
reason: (0, pg_core_1.varchar)("reason", { length: 255 }),
|
|
721
|
+
status: (0, exports.movementStatusEnum)("status").notNull().default("DRAFT"),
|
|
722
|
+
// Product Information
|
|
723
|
+
productId: (0, pg_core_1.text)("product_id").notNull(),
|
|
724
|
+
variantId: (0, pg_core_1.text)("variant_id"),
|
|
725
|
+
sku: (0, pg_core_1.varchar)("sku", { length: 255 }).notNull(),
|
|
726
|
+
productName: (0, pg_core_1.varchar)("product_name", { length: 255 }),
|
|
727
|
+
// Location Information
|
|
728
|
+
fromLocationId: (0, pg_core_1.text)("from_location_id"),
|
|
729
|
+
fromLocationType: (0, pg_core_1.varchar)("from_location_type", { length: 50 }),
|
|
730
|
+
fromZoneId: (0, pg_core_1.text)("from_zone_id"),
|
|
731
|
+
fromBinLocation: (0, pg_core_1.varchar)("from_bin_location", { length: 100 }),
|
|
732
|
+
toLocationId: (0, pg_core_1.text)("to_location_id"),
|
|
733
|
+
toLocationType: (0, pg_core_1.varchar)("to_location_type", { length: 50 }),
|
|
734
|
+
toZoneId: (0, pg_core_1.text)("to_zone_id"),
|
|
735
|
+
toBinLocation: (0, pg_core_1.varchar)("to_bin_location", { length: 100 }),
|
|
736
|
+
// Quantity Information
|
|
737
|
+
quantityMoved: (0, pg_core_1.integer)("quantity_moved").notNull(),
|
|
738
|
+
unitOfMeasure: (0, pg_core_1.varchar)("unit_of_measure", { length: 50 })
|
|
739
|
+
.notNull()
|
|
740
|
+
.default("EACH"),
|
|
741
|
+
// Batch and Serial Tracking
|
|
742
|
+
batchNumber: (0, pg_core_1.varchar)("batch_number", { length: 255 }),
|
|
743
|
+
lotNumber: (0, pg_core_1.varchar)("lot_number", { length: 255 }),
|
|
744
|
+
serialNumbers: (0, pg_core_1.jsonb)("serial_numbers").$type(),
|
|
745
|
+
expiryDate: (0, pg_core_1.timestamp)("expiry_date", { withTimezone: true }),
|
|
746
|
+
manufacturingDate: (0, pg_core_1.timestamp)("manufacturing_date", { withTimezone: true }),
|
|
747
|
+
// Cost Information
|
|
748
|
+
unitCost: (0, pg_core_1.decimal)("unit_cost", { precision: 12, scale: 4 }),
|
|
749
|
+
totalCost: (0, pg_core_1.decimal)("total_cost", { precision: 12, scale: 4 }),
|
|
750
|
+
costingMethod: (0, pg_core_1.varchar)("costing_method", { length: 20 }),
|
|
751
|
+
// Reference Information
|
|
752
|
+
referenceType: (0, pg_core_1.varchar)("reference_type", { length: 50 }),
|
|
753
|
+
referenceId: (0, pg_core_1.text)("reference_id"),
|
|
754
|
+
referenceNumber: (0, pg_core_1.varchar)("reference_number", { length: 100 }),
|
|
755
|
+
// Quality and Condition
|
|
756
|
+
conditionBefore: (0, pg_core_1.varchar)("condition_before", { length: 100 }),
|
|
757
|
+
conditionAfter: (0, pg_core_1.varchar)("condition_after", { length: 100 }),
|
|
758
|
+
qualityGrade: (0, pg_core_1.varchar)("quality_grade", { length: 50 }),
|
|
759
|
+
// Date Information
|
|
760
|
+
movementDate: (0, pg_core_1.timestamp)("movement_date", { withTimezone: true }).notNull(),
|
|
761
|
+
scheduledDate: (0, pg_core_1.timestamp)("scheduled_date", { withTimezone: true }),
|
|
762
|
+
completedDate: (0, pg_core_1.timestamp)("completed_date", { withTimezone: true }),
|
|
763
|
+
// Processing Information
|
|
764
|
+
processedBy: (0, pg_core_1.text)("processed_by"),
|
|
765
|
+
approvedBy: (0, pg_core_1.text)("approved_by"),
|
|
766
|
+
approvedAt: (0, pg_core_1.timestamp)("approved_at", { withTimezone: true }),
|
|
767
|
+
// Notes
|
|
768
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
769
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"),
|
|
770
|
+
// Timestamps
|
|
771
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
772
|
+
.defaultNow()
|
|
773
|
+
.notNull(),
|
|
774
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
775
|
+
.defaultNow()
|
|
776
|
+
.notNull(),
|
|
777
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
778
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
779
|
+
}, (table) => ({
|
|
780
|
+
// Performance indexes
|
|
781
|
+
storeIdIndex: (0, pg_core_1.index)("idx_movements_store_id").on(table.storeId),
|
|
782
|
+
productIdIndex: (0, pg_core_1.index)("idx_movements_product_id").on(table.productId),
|
|
783
|
+
movementTypeIndex: (0, pg_core_1.index)("idx_movements_type").on(table.movementType),
|
|
784
|
+
statusIndex: (0, pg_core_1.index)("idx_movements_status").on(table.status),
|
|
785
|
+
movementDateIndex: (0, pg_core_1.index)("idx_movements_date").on(table.movementDate),
|
|
786
|
+
// Unique movement number per store
|
|
787
|
+
uniqueMovementNumber: (0, pg_core_1.unique)("idx_movements_number_unique").on(table.storeId, table.movementNumber),
|
|
788
|
+
}));
|
|
789
|
+
// =====================================================
|
|
790
|
+
// WAREHOUSES TABLE
|
|
791
|
+
// =====================================================
|
|
792
|
+
exports.warehouses = (0, pg_core_1.pgTable)("warehouses", {
|
|
793
|
+
id: (0, pg_core_1.text)("id")
|
|
794
|
+
.primaryKey()
|
|
795
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
796
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
797
|
+
code: (0, pg_core_1.varchar)("code", { length: 100 }).notNull(),
|
|
798
|
+
name: (0, pg_core_1.varchar)("name", { length: 255 }).notNull(),
|
|
799
|
+
displayName: (0, pg_core_1.varchar)("display_name", { length: 255 }),
|
|
800
|
+
type: (0, exports.warehouseTypeEnum)("type").notNull(),
|
|
801
|
+
status: (0, exports.warehouseStatusEnum)("status").notNull().default("ACTIVE"),
|
|
802
|
+
// Location Information
|
|
803
|
+
address: (0, pg_core_1.jsonb)("address").$type(),
|
|
804
|
+
timezone: (0, pg_core_1.varchar)("timezone", { length: 50 }).notNull().default("UTC"),
|
|
805
|
+
// Contact Information
|
|
806
|
+
primaryContact: (0, pg_core_1.jsonb)("primary_contact").$type(),
|
|
807
|
+
// Physical Characteristics
|
|
808
|
+
totalArea: (0, pg_core_1.decimal)("total_area", { precision: 10, scale: 2 }),
|
|
809
|
+
storageArea: (0, pg_core_1.decimal)("storage_area", { precision: 10, scale: 2 }),
|
|
810
|
+
ceilingHeight: (0, pg_core_1.decimal)("ceiling_height", { precision: 8, scale: 2 }),
|
|
811
|
+
numberOfDocks: (0, pg_core_1.integer)("number_of_docks"),
|
|
812
|
+
// Capacity Management
|
|
813
|
+
capacity: (0, pg_core_1.jsonb)("capacity").$type(),
|
|
814
|
+
// Zone Configuration
|
|
815
|
+
zones: (0, pg_core_1.jsonb)("zones")
|
|
816
|
+
.$type()
|
|
817
|
+
.default([]),
|
|
818
|
+
// Notes and Metadata
|
|
819
|
+
description: (0, pg_core_1.text)("description"),
|
|
820
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
821
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"),
|
|
822
|
+
metadata: (0, pg_core_1.jsonb)("metadata").$type().default({}),
|
|
823
|
+
// Version Control
|
|
824
|
+
version: (0, pg_core_1.integer)("version").notNull().default(1),
|
|
825
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(true),
|
|
826
|
+
// Timestamps
|
|
827
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
828
|
+
.defaultNow()
|
|
829
|
+
.notNull(),
|
|
830
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
831
|
+
.defaultNow()
|
|
832
|
+
.notNull(),
|
|
833
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
834
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
835
|
+
}, (table) => ({
|
|
836
|
+
// Performance indexes
|
|
837
|
+
storeIdIndex: (0, pg_core_1.index)("idx_warehouses_store_id").on(table.storeId),
|
|
838
|
+
statusIndex: (0, pg_core_1.index)("idx_warehouses_status").on(table.status),
|
|
839
|
+
typeIndex: (0, pg_core_1.index)("idx_warehouses_type").on(table.type),
|
|
840
|
+
// Unique constraints
|
|
841
|
+
uniqueCodePerStore: (0, pg_core_1.unique)("idx_warehouses_code_unique").on(table.storeId, table.code),
|
|
842
|
+
}));
|
|
843
|
+
// =====================================================
|
|
844
|
+
// POS LOCATIONS TABLE
|
|
845
|
+
// =====================================================
|
|
846
|
+
exports.posLocations = (0, pg_core_1.pgTable)("pos_locations", {
|
|
847
|
+
id: (0, pg_core_1.text)("id")
|
|
848
|
+
.primaryKey()
|
|
849
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
850
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
851
|
+
code: (0, pg_core_1.varchar)("code", { length: 100 }).notNull(),
|
|
852
|
+
name: (0, pg_core_1.varchar)("name", { length: 255 }).notNull(),
|
|
853
|
+
displayName: (0, pg_core_1.varchar)("display_name", { length: 255 }),
|
|
854
|
+
status: (0, pg_core_1.varchar)("status", { length: 20 }).notNull().default("ACTIVE"),
|
|
855
|
+
// Location Information
|
|
856
|
+
// Keep simple address for backward compatibility
|
|
857
|
+
address: (0, pg_core_1.jsonb)("address").$type(),
|
|
858
|
+
// Advanced geo location object
|
|
859
|
+
geoLocation: (0, pg_core_1.jsonb)("geo_location").$type(),
|
|
860
|
+
timezone: (0, pg_core_1.varchar)("timezone", { length: 50 }).notNull().default("UTC"),
|
|
861
|
+
// Contact Information
|
|
862
|
+
primaryContact: (0, pg_core_1.jsonb)("primary_contact").$type(),
|
|
863
|
+
managementContacts: (0, pg_core_1.jsonb)("management_contacts").$type(),
|
|
864
|
+
emergencyContact: (0, pg_core_1.jsonb)("emergency_contact").$type(),
|
|
865
|
+
// Business Hours
|
|
866
|
+
businessHours: (0, pg_core_1.jsonb)("business_hours").$type(),
|
|
867
|
+
// Physical Characteristics
|
|
868
|
+
floorArea: (0, pg_core_1.decimal)("floor_area", { precision: 10, scale: 2 }),
|
|
869
|
+
storageArea: (0, pg_core_1.decimal)("storage_area", { precision: 10, scale: 2 }),
|
|
870
|
+
customerArea: (0, pg_core_1.decimal)("customer_area", { precision: 10, scale: 2 }),
|
|
871
|
+
numberOfRegister: (0, pg_core_1.integer)("number_of_register"),
|
|
872
|
+
parkingSpaces: (0, pg_core_1.integer)("parking_spaces"),
|
|
873
|
+
// POS Configuration
|
|
874
|
+
posType: (0, pg_core_1.varchar)("pos_type", { length: 50 }).notNull().default("RETAIL"),
|
|
875
|
+
allowBackorders: (0, pg_core_1.boolean)("allow_backorders").notNull().default(false),
|
|
876
|
+
autoFulfillment: (0, pg_core_1.boolean)("auto_fulfillment").notNull().default(true),
|
|
877
|
+
// Equipment and Technology
|
|
878
|
+
posSystemInfo: (0, pg_core_1.jsonb)("pos_system_info").$type(),
|
|
879
|
+
supportedFeatures: (0, pg_core_1.jsonb)("supported_features").$type(),
|
|
880
|
+
hardware: (0, pg_core_1.jsonb)("hardware").$type(),
|
|
881
|
+
// Inventory & Sales Configuration
|
|
882
|
+
inventorySettings: (0, pg_core_1.jsonb)("inventory_settings").$type(),
|
|
883
|
+
salesSettings: (0, pg_core_1.jsonb)("sales_settings").$type(),
|
|
884
|
+
// Customer Services
|
|
885
|
+
customerServices: (0, pg_core_1.jsonb)("customer_services").$type(),
|
|
886
|
+
// Financial Information
|
|
887
|
+
operationalCosts: (0, pg_core_1.jsonb)("operational_costs").$type(),
|
|
888
|
+
// Security and Compliance
|
|
889
|
+
securityFeatures: (0, pg_core_1.jsonb)("security_features").$type(),
|
|
890
|
+
complianceRequirements: (0, pg_core_1.jsonb)("compliance_requirements").$type(),
|
|
891
|
+
lastSecurityAudit: (0, pg_core_1.timestamp)("last_security_audit", { withTimezone: true }),
|
|
892
|
+
// Notes and Metadata
|
|
893
|
+
description: (0, pg_core_1.text)("description"),
|
|
894
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
895
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"),
|
|
896
|
+
metadata: (0, pg_core_1.jsonb)("metadata").$type().default({}),
|
|
897
|
+
customAttributes: (0, pg_core_1.jsonb)("custom_attributes")
|
|
898
|
+
.$type()
|
|
899
|
+
.default({}),
|
|
900
|
+
// Version Control
|
|
901
|
+
version: (0, pg_core_1.integer)("version").notNull().default(1),
|
|
902
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(true),
|
|
903
|
+
// Timestamps & Audit
|
|
904
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
905
|
+
.defaultNow()
|
|
906
|
+
.notNull(),
|
|
907
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
908
|
+
.defaultNow()
|
|
909
|
+
.notNull(),
|
|
910
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
911
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
912
|
+
auditTrail: (0, pg_core_1.jsonb)("audit_trail").$type(),
|
|
913
|
+
}, (table) => ({
|
|
914
|
+
// Performance indexes
|
|
915
|
+
storeIdIndex: (0, pg_core_1.index)("idx_pos_locations_store_id").on(table.storeId),
|
|
916
|
+
statusIndex: (0, pg_core_1.index)("idx_pos_locations_status").on(table.status),
|
|
917
|
+
posTypeIndex: (0, pg_core_1.index)("idx_pos_locations_pos_type").on(table.posType),
|
|
918
|
+
// Unique constraints
|
|
919
|
+
uniqueCodePerStore: (0, pg_core_1.unique)("idx_pos_locations_code_unique").on(table.storeId, table.code),
|
|
920
|
+
}));
|
|
921
|
+
// =====================================================
|
|
922
|
+
// INVENTORY TRANSFERS TABLE
|
|
923
|
+
// =====================================================
|
|
924
|
+
exports.inventoryTransferStatusEnum = (0, pg_core_1.pgEnum)("inventory_transfer_status", [
|
|
925
|
+
"PENDING",
|
|
926
|
+
"IN_TRANSIT",
|
|
927
|
+
"COMPLETED",
|
|
928
|
+
"CANCELLED",
|
|
929
|
+
"FAILED",
|
|
930
|
+
"PARTIAL",
|
|
931
|
+
"RETURNED",
|
|
932
|
+
]);
|
|
933
|
+
exports.inventoryTransferTypeEnum = (0, pg_core_1.pgEnum)("inventory_transfer_type", [
|
|
934
|
+
"WAREHOUSE_TO_WAREHOUSE",
|
|
935
|
+
"WAREHOUSE_TO_POS",
|
|
936
|
+
"POS_TO_WAREHOUSE",
|
|
937
|
+
"POS_TO_POS",
|
|
938
|
+
"SUPPLIER_TO_WAREHOUSE",
|
|
939
|
+
"WAREHOUSE_TO_CUSTOMER",
|
|
940
|
+
"INTERNAL_TRANSFER",
|
|
941
|
+
]);
|
|
942
|
+
exports.inventoryTransfers = (0, pg_core_1.pgTable)("inventory_transfers", {
|
|
943
|
+
id: (0, pg_core_1.text)("id")
|
|
944
|
+
.primaryKey()
|
|
945
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
946
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
947
|
+
transferNumber: (0, pg_core_1.varchar)("transfer_number", { length: 100 }).notNull(),
|
|
948
|
+
// Location Information
|
|
949
|
+
fromLocationId: (0, pg_core_1.text)("from_location_id").notNull(),
|
|
950
|
+
fromLocationType: (0, pg_core_1.varchar)("from_location_type", { length: 50 }).notNull(),
|
|
951
|
+
toLocationId: (0, pg_core_1.text)("to_location_id").notNull(),
|
|
952
|
+
toLocationType: (0, pg_core_1.varchar)("to_location_type", { length: 50 }).notNull(),
|
|
953
|
+
// Transfer Details
|
|
954
|
+
status: (0, exports.inventoryTransferStatusEnum)("status").notNull().default("PENDING"),
|
|
955
|
+
transferType: (0, exports.inventoryTransferTypeEnum)("transfer_type").notNull(),
|
|
956
|
+
priority: (0, pg_core_1.varchar)("priority", { length: 20 }).notNull().default("NORMAL"),
|
|
957
|
+
// Shipping and Tracking
|
|
958
|
+
shippingMethod: (0, pg_core_1.varchar)("shipping_method", { length: 100 }),
|
|
959
|
+
trackingNumber: (0, pg_core_1.varchar)("tracking_number", { length: 100 }),
|
|
960
|
+
carrierName: (0, pg_core_1.varchar)("carrier_name", { length: 100 }),
|
|
961
|
+
// Cost Information
|
|
962
|
+
shippingCost: (0, pg_core_1.decimal)("shipping_cost", { precision: 12, scale: 4 }).default("0"),
|
|
963
|
+
totalCost: (0, pg_core_1.decimal)("total_cost", { precision: 12, scale: 4 }),
|
|
964
|
+
currency: (0, pg_core_1.varchar)("currency", { length: 3 }).notNull().default("USD"),
|
|
965
|
+
// Date Management
|
|
966
|
+
requestedDate: (0, pg_core_1.timestamp)("requested_date", { withTimezone: true }),
|
|
967
|
+
scheduledDate: (0, pg_core_1.timestamp)("scheduled_date", { withTimezone: true }),
|
|
968
|
+
shippedDate: (0, pg_core_1.timestamp)("shipped_date", { withTimezone: true }),
|
|
969
|
+
expectedDeliveryDate: (0, pg_core_1.timestamp)("expected_delivery_date", {
|
|
970
|
+
withTimezone: true,
|
|
971
|
+
}),
|
|
972
|
+
actualDeliveryDate: (0, pg_core_1.timestamp)("actual_delivery_date", {
|
|
973
|
+
withTimezone: true,
|
|
974
|
+
}),
|
|
975
|
+
initiatedAt: (0, pg_core_1.timestamp)("initiated_at", { withTimezone: true }).notNull(),
|
|
976
|
+
completedAt: (0, pg_core_1.timestamp)("completed_at", { withTimezone: true }),
|
|
977
|
+
cancelledAt: (0, pg_core_1.timestamp)("cancelled_at", { withTimezone: true }),
|
|
978
|
+
// Authorization and Approval
|
|
979
|
+
requiresApproval: (0, pg_core_1.boolean)("requires_approval").notNull().default(false),
|
|
980
|
+
approvedBy: (0, pg_core_1.text)("approved_by"),
|
|
981
|
+
approvedAt: (0, pg_core_1.timestamp)("approved_at", { withTimezone: true }),
|
|
982
|
+
rejectedBy: (0, pg_core_1.text)("rejected_by"),
|
|
983
|
+
rejectedAt: (0, pg_core_1.timestamp)("rejected_at", { withTimezone: true }),
|
|
984
|
+
rejectionReason: (0, pg_core_1.text)("rejection_reason"),
|
|
985
|
+
// Document References
|
|
986
|
+
referenceOrderNumber: (0, pg_core_1.varchar)("reference_order_number", { length: 100 }),
|
|
987
|
+
internalReference: (0, pg_core_1.varchar)("internal_reference", { length: 100 }),
|
|
988
|
+
externalReference: (0, pg_core_1.varchar)("external_reference", { length: 100 }),
|
|
989
|
+
// Quality Control
|
|
990
|
+
requiresInspection: (0, pg_core_1.boolean)("requires_inspection").notNull().default(false),
|
|
991
|
+
inspectedBy: (0, pg_core_1.text)("inspected_by"),
|
|
992
|
+
inspectedAt: (0, pg_core_1.timestamp)("inspected_at", { withTimezone: true }),
|
|
993
|
+
qualityNotes: (0, pg_core_1.text)("quality_notes"),
|
|
994
|
+
// Discrepancy Tracking
|
|
995
|
+
hasDiscrepancies: (0, pg_core_1.boolean)("has_discrepancies").notNull().default(false),
|
|
996
|
+
discrepancyNotes: (0, pg_core_1.text)("discrepancy_notes"),
|
|
997
|
+
// Notes
|
|
998
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
999
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"),
|
|
1000
|
+
shippingInstructions: (0, pg_core_1.text)("shipping_instructions"),
|
|
1001
|
+
// Timestamps
|
|
1002
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1003
|
+
.defaultNow()
|
|
1004
|
+
.notNull(),
|
|
1005
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1006
|
+
.defaultNow()
|
|
1007
|
+
.notNull(),
|
|
1008
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
1009
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
1010
|
+
}, (table) => ({
|
|
1011
|
+
storeIdIndex: (0, pg_core_1.index)("idx_transfers_store_id").on(table.storeId),
|
|
1012
|
+
statusIndex: (0, pg_core_1.index)("idx_transfers_status").on(table.status),
|
|
1013
|
+
transferNumberIndex: (0, pg_core_1.index)("idx_transfers_number").on(table.transferNumber),
|
|
1014
|
+
uniqueTransferNumber: (0, pg_core_1.unique)("idx_transfers_number_unique").on(table.storeId, table.transferNumber),
|
|
1015
|
+
}));
|
|
1016
|
+
exports.inventoryTransferItems = (0, pg_core_1.pgTable)("inventory_transfer_items", {
|
|
1017
|
+
id: (0, pg_core_1.text)("id")
|
|
1018
|
+
.primaryKey()
|
|
1019
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1020
|
+
transferId: (0, pg_core_1.text)("transfer_id").notNull(),
|
|
1021
|
+
productId: (0, pg_core_1.text)("product_id").notNull(),
|
|
1022
|
+
variantId: (0, pg_core_1.text)("variant_id"),
|
|
1023
|
+
sku: (0, pg_core_1.varchar)("sku", { length: 255 }).notNull(),
|
|
1024
|
+
quantity: (0, pg_core_1.integer)("quantity").notNull(),
|
|
1025
|
+
receivedQuantity: (0, pg_core_1.integer)("received_quantity").default(0),
|
|
1026
|
+
batchNumber: (0, pg_core_1.varchar)("batch_number", { length: 255 }),
|
|
1027
|
+
lotNumber: (0, pg_core_1.varchar)("lot_number", { length: 255 }),
|
|
1028
|
+
serialNumbers: (0, pg_core_1.jsonb)("serial_numbers").$type(),
|
|
1029
|
+
expiryDate: (0, pg_core_1.timestamp)("expiry_date", { withTimezone: true }),
|
|
1030
|
+
metadata: (0, pg_core_1.jsonb)("metadata").$type().default({}),
|
|
1031
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1032
|
+
.defaultNow()
|
|
1033
|
+
.notNull(),
|
|
1034
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1035
|
+
.defaultNow()
|
|
1036
|
+
.notNull(),
|
|
1037
|
+
}, (table) => ({
|
|
1038
|
+
transferIdIndex: (0, pg_core_1.index)("idx_transfer_items_transfer_id").on(table.transferId),
|
|
1039
|
+
productIdIndex: (0, pg_core_1.index)("idx_transfer_items_product_id").on(table.productId),
|
|
1040
|
+
}));
|
|
1041
|
+
// =====================================================
|
|
1042
|
+
// QUALITY CONTROLS TABLE
|
|
1043
|
+
// =====================================================
|
|
1044
|
+
exports.qualityStatusEnum = (0, pg_core_1.pgEnum)("quality_status", [
|
|
1045
|
+
"PENDING_INSPECTION",
|
|
1046
|
+
"PASSED",
|
|
1047
|
+
"FAILED",
|
|
1048
|
+
"CONDITIONALLY_PASSED",
|
|
1049
|
+
"QUARANTINED",
|
|
1050
|
+
"REJECTED",
|
|
1051
|
+
"REWORK_REQUIRED",
|
|
1052
|
+
"RELEASED",
|
|
1053
|
+
"HOLD",
|
|
1054
|
+
]);
|
|
1055
|
+
exports.inspectionTypeEnum = (0, pg_core_1.pgEnum)("inspection_type", [
|
|
1056
|
+
"INCOMING_INSPECTION",
|
|
1057
|
+
"IN_PROCESS_INSPECTION",
|
|
1058
|
+
"OUTGOING_INSPECTION",
|
|
1059
|
+
"RANDOM_INSPECTION",
|
|
1060
|
+
"CUSTOMER_COMPLAINT_INSPECTION",
|
|
1061
|
+
"SUPPLIER_AUDIT",
|
|
1062
|
+
"PERIODIC_REVIEW",
|
|
1063
|
+
"EXPIRY_CHECK",
|
|
1064
|
+
"DAMAGE_ASSESSMENT",
|
|
1065
|
+
]);
|
|
1066
|
+
exports.qualityControls = (0, pg_core_1.pgTable)("quality_controls", {
|
|
1067
|
+
id: (0, pg_core_1.text)("id")
|
|
1068
|
+
.primaryKey()
|
|
1069
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1070
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
1071
|
+
qcNumber: (0, pg_core_1.varchar)("qc_number", { length: 100 }).notNull(),
|
|
1072
|
+
// Product Information
|
|
1073
|
+
productId: (0, pg_core_1.text)("product_id").notNull(),
|
|
1074
|
+
variantId: (0, pg_core_1.text)("variant_id"),
|
|
1075
|
+
sku: (0, pg_core_1.varchar)("sku", { length: 255 }).notNull(),
|
|
1076
|
+
productName: (0, pg_core_1.varchar)("product_name", { length: 255 }),
|
|
1077
|
+
// Batch/Lot Information
|
|
1078
|
+
lotId: (0, pg_core_1.text)("lot_id"), // FK to inventory_lots
|
|
1079
|
+
batchNumber: (0, pg_core_1.varchar)("batch_number", { length: 100 }),
|
|
1080
|
+
lotNumber: (0, pg_core_1.varchar)("lot_number", { length: 100 }),
|
|
1081
|
+
serialNumbers: (0, pg_core_1.jsonb)("serial_numbers"),
|
|
1082
|
+
autoQuarantined: (0, pg_core_1.boolean)("auto_quarantined").notNull().default(false),
|
|
1083
|
+
// Location and Quantity
|
|
1084
|
+
locationId: (0, pg_core_1.text)("location_id").notNull(),
|
|
1085
|
+
quantity: (0, pg_core_1.integer)("quantity").notNull(),
|
|
1086
|
+
sampleSize: (0, pg_core_1.integer)("sample_size"),
|
|
1087
|
+
// Inspection Details
|
|
1088
|
+
inspectionType: (0, exports.inspectionTypeEnum)("inspection_type").notNull(),
|
|
1089
|
+
inspectionDate: (0, pg_core_1.timestamp)("inspection_date", {
|
|
1090
|
+
withTimezone: true,
|
|
1091
|
+
}).notNull(),
|
|
1092
|
+
inspectedBy: (0, pg_core_1.text)("inspected_by").notNull(),
|
|
1093
|
+
inspectionDuration: (0, pg_core_1.integer)("inspection_duration"), // minutes
|
|
1094
|
+
// Quality Assessment
|
|
1095
|
+
overallStatus: (0, exports.qualityStatusEnum)("overall_status").notNull(),
|
|
1096
|
+
qualityGrade: (0, pg_core_1.varchar)("quality_grade", { length: 20 }),
|
|
1097
|
+
qualityScore: (0, pg_core_1.decimal)("quality_score", { precision: 5, scale: 2 }),
|
|
1098
|
+
// Inspection Criteria and Results
|
|
1099
|
+
criteria: (0, pg_core_1.jsonb)("criteria").notNull(),
|
|
1100
|
+
defects: (0, pg_core_1.jsonb)("defects"),
|
|
1101
|
+
measurements: (0, pg_core_1.jsonb)("measurements"),
|
|
1102
|
+
certificates: (0, pg_core_1.jsonb)("certificates"),
|
|
1103
|
+
// Documentation
|
|
1104
|
+
imageUrls: (0, pg_core_1.jsonb)("image_urls"),
|
|
1105
|
+
documentUrls: (0, pg_core_1.jsonb)("document_urls"),
|
|
1106
|
+
// Supplier Information (for incoming inspections)
|
|
1107
|
+
supplierId: (0, pg_core_1.text)("supplier_id"),
|
|
1108
|
+
supplierName: (0, pg_core_1.varchar)("supplier_name", { length: 255 }),
|
|
1109
|
+
purchaseOrderNumber: (0, pg_core_1.varchar)("purchase_order_number", { length: 100 }),
|
|
1110
|
+
// Action Required
|
|
1111
|
+
actionRequired: (0, pg_core_1.boolean)("action_required").notNull().default(false),
|
|
1112
|
+
correctionActions: (0, pg_core_1.jsonb)("correction_actions"),
|
|
1113
|
+
// Follow-up Requirements
|
|
1114
|
+
requiresReInspection: (0, pg_core_1.boolean)("requires_re_inspection")
|
|
1115
|
+
.notNull()
|
|
1116
|
+
.default(false),
|
|
1117
|
+
reInspectionDate: (0, pg_core_1.timestamp)("re_inspection_date", { withTimezone: true }),
|
|
1118
|
+
reInspectionNotes: (0, pg_core_1.text)("re_inspection_notes"),
|
|
1119
|
+
// Disposition
|
|
1120
|
+
dispositionDate: (0, pg_core_1.timestamp)("disposition_date", { withTimezone: true }),
|
|
1121
|
+
dispositionAction: (0, pg_core_1.varchar)("disposition_action", { length: 50 }),
|
|
1122
|
+
dispositionNotes: (0, pg_core_1.text)("disposition_notes"),
|
|
1123
|
+
dispositionBy: (0, pg_core_1.text)("disposition_by"),
|
|
1124
|
+
// Status Updates
|
|
1125
|
+
completedAt: (0, pg_core_1.timestamp)("completed_at", { withTimezone: true }),
|
|
1126
|
+
approvedBy: (0, pg_core_1.text)("approved_by"),
|
|
1127
|
+
approvedAt: (0, pg_core_1.timestamp)("approved_at", { withTimezone: true }),
|
|
1128
|
+
// Customer Notification
|
|
1129
|
+
customerNotified: (0, pg_core_1.boolean)("customer_notified").notNull().default(false),
|
|
1130
|
+
customerNotificationDate: (0, pg_core_1.timestamp)("customer_notification_date", {
|
|
1131
|
+
withTimezone: true,
|
|
1132
|
+
}),
|
|
1133
|
+
customerResponse: (0, pg_core_1.text)("customer_response"),
|
|
1134
|
+
// Notes
|
|
1135
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
1136
|
+
// Timestamps
|
|
1137
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1138
|
+
.defaultNow()
|
|
1139
|
+
.notNull(),
|
|
1140
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1141
|
+
.defaultNow()
|
|
1142
|
+
.notNull(),
|
|
1143
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
1144
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
1145
|
+
}, (table) => ({
|
|
1146
|
+
storeIdIndex: (0, pg_core_1.index)("idx_quality_controls_store_id").on(table.storeId),
|
|
1147
|
+
qcNumberIndex: (0, pg_core_1.index)("idx_quality_controls_qc_number").on(table.qcNumber),
|
|
1148
|
+
statusIndex: (0, pg_core_1.index)("idx_quality_controls_status").on(table.overallStatus),
|
|
1149
|
+
inspectionDateIndex: (0, pg_core_1.index)("idx_quality_controls_inspection_date").on(table.inspectionDate),
|
|
1150
|
+
uniqueQcNumber: (0, pg_core_1.unique)("idx_quality_controls_number_unique").on(table.storeId, table.qcNumber),
|
|
1151
|
+
}));
|
|
1152
|
+
exports.qualityTemplates = (0, pg_core_1.pgTable)("quality_templates", {
|
|
1153
|
+
id: (0, pg_core_1.text)("id")
|
|
1154
|
+
.primaryKey()
|
|
1155
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1156
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
1157
|
+
name: (0, pg_core_1.varchar)("name", { length: 255 }).notNull(),
|
|
1158
|
+
version: (0, pg_core_1.varchar)("version", { length: 50 }).notNull(),
|
|
1159
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(true),
|
|
1160
|
+
// Template Configuration
|
|
1161
|
+
criteria: (0, pg_core_1.jsonb)("criteria").$type().default([]),
|
|
1162
|
+
inspectionTypes: (0, pg_core_1.jsonb)("inspection_types").$type().default([]),
|
|
1163
|
+
// Notes
|
|
1164
|
+
description: (0, pg_core_1.text)("description"),
|
|
1165
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
1166
|
+
// Timestamps
|
|
1167
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1168
|
+
.defaultNow()
|
|
1169
|
+
.notNull(),
|
|
1170
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1171
|
+
.defaultNow()
|
|
1172
|
+
.notNull(),
|
|
1173
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
1174
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
1175
|
+
}, (table) => ({
|
|
1176
|
+
storeIdIndex: (0, pg_core_1.index)("idx_quality_templates_store_id").on(table.storeId),
|
|
1177
|
+
nameIndex: (0, pg_core_1.index)("idx_quality_templates_name").on(table.name),
|
|
1178
|
+
isActiveIndex: (0, pg_core_1.index)("idx_quality_templates_active").on(table.isActive),
|
|
1179
|
+
}));
|
|
1180
|
+
// =====================================================
|
|
1181
|
+
// SUPPLIER QUALITY RATINGS TABLE
|
|
1182
|
+
// =====================================================
|
|
1183
|
+
exports.supplierQualityRatings = (0, pg_core_1.pgTable)("supplier_quality_ratings", {
|
|
1184
|
+
id: (0, pg_core_1.text)("id")
|
|
1185
|
+
.primaryKey()
|
|
1186
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1187
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
1188
|
+
supplierId: (0, pg_core_1.text)("supplier_id").notNull(),
|
|
1189
|
+
// Rating Period
|
|
1190
|
+
ratingPeriod: (0, pg_core_1.jsonb)("rating_period")
|
|
1191
|
+
.$type()
|
|
1192
|
+
.notNull(),
|
|
1193
|
+
// Inspection Metrics
|
|
1194
|
+
totalInspections: (0, pg_core_1.integer)("total_inspections").notNull(),
|
|
1195
|
+
passedInspections: (0, pg_core_1.integer)("passed_inspections").notNull(),
|
|
1196
|
+
failedInspections: (0, pg_core_1.integer)("failed_inspections").notNull(),
|
|
1197
|
+
// Performance Metrics
|
|
1198
|
+
qualityScore: (0, pg_core_1.decimal)("quality_score", { precision: 5, scale: 2 }),
|
|
1199
|
+
onTimeDeliveryRate: (0, pg_core_1.decimal)("on_time_delivery_rate", {
|
|
1200
|
+
precision: 5,
|
|
1201
|
+
scale: 2,
|
|
1202
|
+
}),
|
|
1203
|
+
defectRate: (0, pg_core_1.decimal)("defect_rate", { precision: 5, scale: 2 }),
|
|
1204
|
+
// Overall Rating
|
|
1205
|
+
overallRating: (0, pg_core_1.varchar)("overall_rating", { length: 20 }),
|
|
1206
|
+
// Notes
|
|
1207
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
1208
|
+
// Timestamps
|
|
1209
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1210
|
+
.defaultNow()
|
|
1211
|
+
.notNull(),
|
|
1212
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1213
|
+
.defaultNow()
|
|
1214
|
+
.notNull(),
|
|
1215
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
1216
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
1217
|
+
}, (table) => ({
|
|
1218
|
+
storeIdIndex: (0, pg_core_1.index)("idx_supplier_quality_ratings_store_id").on(table.storeId),
|
|
1219
|
+
supplierIdIndex: (0, pg_core_1.index)("idx_supplier_quality_ratings_supplier_id").on(table.supplierId),
|
|
1220
|
+
}));
|
|
1221
|
+
// =====================================================
|
|
1222
|
+
// SUPPLIERS TABLE
|
|
1223
|
+
// =====================================================
|
|
1224
|
+
exports.supplierStatusEnum = (0, pg_core_1.pgEnum)("supplier_status", [
|
|
1225
|
+
"ACTIVE",
|
|
1226
|
+
"INACTIVE",
|
|
1227
|
+
"SUSPENDED",
|
|
1228
|
+
"UNDER_REVIEW",
|
|
1229
|
+
"PENDING_APPROVAL",
|
|
1230
|
+
"BLACKLISTED",
|
|
1231
|
+
]);
|
|
1232
|
+
exports.supplierTypeEnum = (0, pg_core_1.pgEnum)("supplier_type", [
|
|
1233
|
+
"MANUFACTURER",
|
|
1234
|
+
"DISTRIBUTOR",
|
|
1235
|
+
"WHOLESALER",
|
|
1236
|
+
"DROPSHIPPER",
|
|
1237
|
+
"SERVICE_PROVIDER",
|
|
1238
|
+
"LOCAL_VENDOR",
|
|
1239
|
+
"INTERNATIONAL_VENDOR",
|
|
1240
|
+
"BROKER",
|
|
1241
|
+
"IMPORTER",
|
|
1242
|
+
"EXPORTER",
|
|
1243
|
+
"RETAILER",
|
|
1244
|
+
"RESELLER",
|
|
1245
|
+
"CONTRACTOR",
|
|
1246
|
+
"CONSULTANT",
|
|
1247
|
+
"PARTS_SUPPLIER",
|
|
1248
|
+
"RAW_MATERIALS_SUPPLIER",
|
|
1249
|
+
"PACKAGING_SUPPLIER",
|
|
1250
|
+
"EQUIPMENT_SUPPLIER",
|
|
1251
|
+
"MAINTENANCE_SUPPLIER",
|
|
1252
|
+
"LOGISTICS_PROVIDER",
|
|
1253
|
+
"FREIGHT_FORWARDER",
|
|
1254
|
+
"CUSTOMS_BROKER",
|
|
1255
|
+
"TECHNOLOGY_VENDOR",
|
|
1256
|
+
"SOFTWARE_VENDOR",
|
|
1257
|
+
"HARDWARE_VENDOR",
|
|
1258
|
+
"OFFICE_SUPPLIES_VENDOR",
|
|
1259
|
+
"UTILITIES_PROVIDER",
|
|
1260
|
+
"CLEANING_SERVICES",
|
|
1261
|
+
"SECURITY_SERVICES",
|
|
1262
|
+
"MARKETING_SERVICES",
|
|
1263
|
+
"PROFESSIONAL_SERVICES",
|
|
1264
|
+
"TEMPORARY_STAFFING",
|
|
1265
|
+
"SPECIALIZED_SUPPLIER",
|
|
1266
|
+
"OTHER",
|
|
1267
|
+
]);
|
|
1268
|
+
exports.supplierRatingEnum = (0, pg_core_1.pgEnum)("supplier_rating", [
|
|
1269
|
+
"EXCELLENT",
|
|
1270
|
+
"GOOD",
|
|
1271
|
+
"AVERAGE",
|
|
1272
|
+
"POOR",
|
|
1273
|
+
"UNRATED",
|
|
1274
|
+
]);
|
|
1275
|
+
exports.suppliers = (0, pg_core_1.pgTable)("suppliers", {
|
|
1276
|
+
id: (0, pg_core_1.text)("id")
|
|
1277
|
+
.primaryKey()
|
|
1278
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1279
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
1280
|
+
name: (0, pg_core_1.varchar)("name", { length: 255 }).notNull(),
|
|
1281
|
+
code: (0, pg_core_1.varchar)("code", { length: 100 }).notNull(),
|
|
1282
|
+
status: (0, exports.supplierStatusEnum)("status").notNull().default("ACTIVE"),
|
|
1283
|
+
type: (0, exports.supplierTypeEnum)("type").notNull().default("MANUFACTURER"),
|
|
1284
|
+
// Contact Information
|
|
1285
|
+
primaryContact: (0, pg_core_1.jsonb)("primary_contact").$type(),
|
|
1286
|
+
// Address Information
|
|
1287
|
+
address: (0, pg_core_1.jsonb)("address").$type(),
|
|
1288
|
+
billingAddress: (0, pg_core_1.jsonb)("billing_address").$type(),
|
|
1289
|
+
// Payment Terms
|
|
1290
|
+
paymentTerms: (0, pg_core_1.jsonb)("payment_terms").$type(),
|
|
1291
|
+
// Business Information
|
|
1292
|
+
taxId: (0, pg_core_1.varchar)("tax_id", { length: 100 }),
|
|
1293
|
+
businessLicense: (0, pg_core_1.varchar)("business_license", { length: 100 }),
|
|
1294
|
+
certifications: (0, pg_core_1.jsonb)("certifications").$type().default([]),
|
|
1295
|
+
// Performance Metrics
|
|
1296
|
+
rating: (0, exports.supplierRatingEnum)("rating"),
|
|
1297
|
+
onTimeDeliveryRate: (0, pg_core_1.decimal)("on_time_delivery_rate", {
|
|
1298
|
+
precision: 5,
|
|
1299
|
+
scale: 2,
|
|
1300
|
+
}),
|
|
1301
|
+
qualityRating: (0, pg_core_1.decimal)("quality_rating", { precision: 5, scale: 2 }),
|
|
1302
|
+
// Business Terms
|
|
1303
|
+
minimumOrderAmount: (0, pg_core_1.decimal)("minimum_order_amount", {
|
|
1304
|
+
precision: 12,
|
|
1305
|
+
scale: 4,
|
|
1306
|
+
}),
|
|
1307
|
+
leadTimeDays: (0, pg_core_1.integer)("lead_time_days"),
|
|
1308
|
+
deliveryMethod: (0, pg_core_1.varchar)("delivery_method", { length: 100 }),
|
|
1309
|
+
currency: (0, pg_core_1.varchar)("currency", { length: 3 }).notNull().default("USD"),
|
|
1310
|
+
// Metadata
|
|
1311
|
+
tags: (0, pg_core_1.jsonb)("tags").$type().default([]),
|
|
1312
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
1313
|
+
metadata: (0, pg_core_1.jsonb)("metadata").$type().default({}),
|
|
1314
|
+
// Status
|
|
1315
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(true),
|
|
1316
|
+
// Timestamps
|
|
1317
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1318
|
+
.defaultNow()
|
|
1319
|
+
.notNull(),
|
|
1320
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1321
|
+
.defaultNow()
|
|
1322
|
+
.notNull(),
|
|
1323
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
1324
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
1325
|
+
}, (table) => ({
|
|
1326
|
+
storeIdIndex: (0, pg_core_1.index)("idx_suppliers_store_id").on(table.storeId),
|
|
1327
|
+
statusIndex: (0, pg_core_1.index)("idx_suppliers_status").on(table.status),
|
|
1328
|
+
typeIndex: (0, pg_core_1.index)("idx_suppliers_type").on(table.type),
|
|
1329
|
+
ratingIndex: (0, pg_core_1.index)("idx_suppliers_rating").on(table.rating),
|
|
1330
|
+
uniqueCodePerStore: (0, pg_core_1.unique)("idx_suppliers_code_unique").on(table.storeId, table.code),
|
|
1331
|
+
}));
|
|
1332
|
+
// =====================================================
|
|
1333
|
+
// PURCHASE ORDERS TABLE
|
|
1334
|
+
// =====================================================
|
|
1335
|
+
exports.purchaseOrderStatusEnum = (0, pg_core_1.pgEnum)("purchase_order_status", [
|
|
1336
|
+
"DRAFT",
|
|
1337
|
+
"SENT",
|
|
1338
|
+
"ACKNOWLEDGED",
|
|
1339
|
+
"APPROVED",
|
|
1340
|
+
"PENDING_APPROVAL",
|
|
1341
|
+
"PARTIALLY_RECEIVED",
|
|
1342
|
+
"RECEIVED",
|
|
1343
|
+
"COMPLETED",
|
|
1344
|
+
"CANCELLED",
|
|
1345
|
+
"DISPUTED",
|
|
1346
|
+
]);
|
|
1347
|
+
exports.purchaseOrders = (0, pg_core_1.pgTable)("purchase_orders", {
|
|
1348
|
+
id: (0, pg_core_1.text)("id")
|
|
1349
|
+
.primaryKey()
|
|
1350
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1351
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
1352
|
+
supplierId: (0, pg_core_1.text)("supplier_id").notNull(),
|
|
1353
|
+
orderNumber: (0, pg_core_1.varchar)("order_number", { length: 100 }).notNull(),
|
|
1354
|
+
status: (0, exports.purchaseOrderStatusEnum)("status").notNull().default("DRAFT"),
|
|
1355
|
+
// Order Details
|
|
1356
|
+
orderDate: (0, pg_core_1.timestamp)("order_date", { withTimezone: true }).notNull(),
|
|
1357
|
+
requestedDeliveryDate: (0, pg_core_1.timestamp)("requested_delivery_date", {
|
|
1358
|
+
withTimezone: true,
|
|
1359
|
+
}),
|
|
1360
|
+
expectedDeliveryDate: (0, pg_core_1.timestamp)("expected_delivery_date", {
|
|
1361
|
+
withTimezone: true,
|
|
1362
|
+
}),
|
|
1363
|
+
actualDeliveryDate: (0, pg_core_1.timestamp)("actual_delivery_date", {
|
|
1364
|
+
withTimezone: true,
|
|
1365
|
+
}),
|
|
1366
|
+
// Financial Information
|
|
1367
|
+
subtotal: (0, pg_core_1.decimal)("subtotal", { precision: 12, scale: 4 }).notNull(),
|
|
1368
|
+
taxAmount: (0, pg_core_1.decimal)("tax_amount", { precision: 12, scale: 4 }).default("0"),
|
|
1369
|
+
discountAmount: (0, pg_core_1.decimal)("discount_amount", {
|
|
1370
|
+
precision: 12,
|
|
1371
|
+
scale: 4,
|
|
1372
|
+
}).default("0"),
|
|
1373
|
+
shippingAmount: (0, pg_core_1.decimal)("shipping_amount", {
|
|
1374
|
+
precision: 12,
|
|
1375
|
+
scale: 4,
|
|
1376
|
+
}).default("0"),
|
|
1377
|
+
totalAmount: (0, pg_core_1.decimal)("total_amount", { precision: 12, scale: 4 }).notNull(),
|
|
1378
|
+
currency: (0, pg_core_1.varchar)("currency", { length: 3 }).notNull().default("USD"),
|
|
1379
|
+
// Shipping Information
|
|
1380
|
+
shippingAddress: (0, pg_core_1.jsonb)("shipping_address").$type(),
|
|
1381
|
+
// Payment Terms
|
|
1382
|
+
paymentTerms: (0, pg_core_1.varchar)("payment_terms", { length: 50 }).notNull(),
|
|
1383
|
+
// Status Tracking
|
|
1384
|
+
approvedBy: (0, pg_core_1.text)("approved_by"),
|
|
1385
|
+
approvedAt: (0, pg_core_1.timestamp)("approved_at", { withTimezone: true }),
|
|
1386
|
+
sentDate: (0, pg_core_1.timestamp)("sent_date", { withTimezone: true }),
|
|
1387
|
+
acknowledgedDate: (0, pg_core_1.timestamp)("acknowledged_date", { withTimezone: true }),
|
|
1388
|
+
// Notes
|
|
1389
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
1390
|
+
internalNotes: (0, pg_core_1.text)("internal_notes"),
|
|
1391
|
+
// Timestamps
|
|
1392
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1393
|
+
.defaultNow()
|
|
1394
|
+
.notNull(),
|
|
1395
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1396
|
+
.defaultNow()
|
|
1397
|
+
.notNull(),
|
|
1398
|
+
createdBy: (0, pg_core_1.text)("created_by"),
|
|
1399
|
+
updatedBy: (0, pg_core_1.text)("updated_by"),
|
|
1400
|
+
}, (table) => ({
|
|
1401
|
+
storeIdIndex: (0, pg_core_1.index)("idx_purchase_orders_store_id").on(table.storeId),
|
|
1402
|
+
supplierIdIndex: (0, pg_core_1.index)("idx_purchase_orders_supplier_id").on(table.supplierId),
|
|
1403
|
+
statusIndex: (0, pg_core_1.index)("idx_purchase_orders_status").on(table.status),
|
|
1404
|
+
orderDateIndex: (0, pg_core_1.index)("idx_purchase_orders_order_date").on(table.orderDate),
|
|
1405
|
+
uniqueOrderNumber: (0, pg_core_1.unique)("idx_purchase_orders_number_unique").on(table.storeId, table.orderNumber),
|
|
1406
|
+
}));
|
|
1407
|
+
exports.purchaseOrderItems = (0, pg_core_1.pgTable)("purchase_order_items", {
|
|
1408
|
+
id: (0, pg_core_1.text)("id")
|
|
1409
|
+
.primaryKey()
|
|
1410
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1411
|
+
orderId: (0, pg_core_1.text)("order_id").notNull(),
|
|
1412
|
+
productId: (0, pg_core_1.text)("product_id").notNull(),
|
|
1413
|
+
variantId: (0, pg_core_1.text)("variant_id"),
|
|
1414
|
+
sku: (0, pg_core_1.varchar)("sku", { length: 255 }).notNull(),
|
|
1415
|
+
// Quantity and Pricing
|
|
1416
|
+
quantity: (0, pg_core_1.integer)("quantity").notNull(),
|
|
1417
|
+
receivedQuantity: (0, pg_core_1.integer)("received_quantity").default(0),
|
|
1418
|
+
unitPrice: (0, pg_core_1.decimal)("unit_price", { precision: 12, scale: 4 }).notNull(),
|
|
1419
|
+
totalPrice: (0, pg_core_1.decimal)("total_price", { precision: 12, scale: 4 }).notNull(),
|
|
1420
|
+
taxRate: (0, pg_core_1.decimal)("tax_rate", { precision: 5, scale: 2 }).default("0"),
|
|
1421
|
+
discountRate: (0, pg_core_1.decimal)("discount_rate", { precision: 5, scale: 2 }).default("0"),
|
|
1422
|
+
// Notes
|
|
1423
|
+
notes: (0, pg_core_1.text)("notes"),
|
|
1424
|
+
// Timestamps
|
|
1425
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1426
|
+
.defaultNow()
|
|
1427
|
+
.notNull(),
|
|
1428
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1429
|
+
.defaultNow()
|
|
1430
|
+
.notNull(),
|
|
1431
|
+
}, (table) => ({
|
|
1432
|
+
orderIdIndex: (0, pg_core_1.index)("idx_purchase_order_items_order_id").on(table.orderId),
|
|
1433
|
+
productIdIndex: (0, pg_core_1.index)("idx_purchase_order_items_product_id").on(table.productId),
|
|
1434
|
+
}));
|
|
1435
|
+
exports.productSuppliers = (0, pg_core_1.pgTable)("product_suppliers", {
|
|
1436
|
+
id: (0, pg_core_1.text)("id")
|
|
1437
|
+
.primaryKey()
|
|
1438
|
+
.$defaultFn(() => (0, cuid2_1.createId)()),
|
|
1439
|
+
storeId: (0, pg_core_1.text)("store_id").notNull(),
|
|
1440
|
+
productId: (0, pg_core_1.text)("product_id").notNull(),
|
|
1441
|
+
supplierId: (0, pg_core_1.text)("supplier_id").notNull(),
|
|
1442
|
+
// Supplier Product Information
|
|
1443
|
+
supplierSku: (0, pg_core_1.varchar)("supplier_sku", { length: 255 }),
|
|
1444
|
+
supplierProductName: (0, pg_core_1.varchar)("supplier_product_name", { length: 255 }),
|
|
1445
|
+
// Pricing and Terms
|
|
1446
|
+
unitCost: (0, pg_core_1.decimal)("unit_cost", { precision: 12, scale: 4 }),
|
|
1447
|
+
cost: (0, pg_core_1.decimal)("cost", { precision: 12, scale: 4 }),
|
|
1448
|
+
currency: (0, pg_core_1.varchar)("currency", { length: 3 }).notNull().default("USD"),
|
|
1449
|
+
minimumOrderQuantity: (0, pg_core_1.integer)("minimum_order_quantity"),
|
|
1450
|
+
leadTime: (0, pg_core_1.integer)("lead_time"),
|
|
1451
|
+
packSize: (0, pg_core_1.integer)("pack_size").default(1),
|
|
1452
|
+
availability: (0, pg_core_1.varchar)("availability", { length: 20 }).default("IN_STOCK"),
|
|
1453
|
+
// Status
|
|
1454
|
+
isActive: (0, pg_core_1.boolean)("is_active").notNull().default(true),
|
|
1455
|
+
isPreferred: (0, pg_core_1.boolean)("is_preferred").notNull().default(false),
|
|
1456
|
+
// Timestamps
|
|
1457
|
+
createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone: true })
|
|
1458
|
+
.defaultNow()
|
|
1459
|
+
.notNull(),
|
|
1460
|
+
updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone: true })
|
|
1461
|
+
.defaultNow()
|
|
1462
|
+
.notNull(),
|
|
1463
|
+
lastOrderDate: (0, pg_core_1.timestamp)("last_order_date", { withTimezone: true }),
|
|
1464
|
+
lastCostUpdate: (0, pg_core_1.timestamp)("last_cost_update", { withTimezone: true }),
|
|
1465
|
+
}, (table) => ({
|
|
1466
|
+
storeIdIndex: (0, pg_core_1.index)("idx_product_suppliers_store_id").on(table.storeId),
|
|
1467
|
+
productIdIndex: (0, pg_core_1.index)("idx_product_suppliers_product_id").on(table.productId),
|
|
1468
|
+
supplierIdIndex: (0, pg_core_1.index)("idx_product_suppliers_supplier_id").on(table.supplierId),
|
|
1469
|
+
uniqueProductSupplier: (0, pg_core_1.unique)("idx_product_suppliers_unique").on(table.storeId, table.productId, table.supplierId),
|
|
1470
|
+
}));
|