439 lines
12 KiB
Plaintext
439 lines
12 KiB
Plaintext
// Operations Management Domain
|
|
// Contains Input management, Labor, Equipment, and daily operations
|
|
|
|
// Operations-specific Enums
|
|
enum SupplierType {
|
|
SEED_SUPPLIER
|
|
FERTILIZER_SUPPLIER
|
|
PESTICIDE_SUPPLIER
|
|
EQUIPMENT_SUPPLIER
|
|
GENERAL_SUPPLIER
|
|
COOPERATIVE
|
|
GOVERNMENT_AGENCY
|
|
}
|
|
|
|
enum WorkerRole {
|
|
PERMANENT
|
|
SEASONAL
|
|
DAILY
|
|
CONTRACTOR
|
|
SUPERVISOR
|
|
FOREMAN
|
|
SPECIALIST
|
|
}
|
|
|
|
enum SkillLevel {
|
|
BEGINNER
|
|
INTERMEDIATE
|
|
ADVANCED
|
|
EXPERT
|
|
}
|
|
|
|
enum ContractType {
|
|
PERMANENT
|
|
TEMPORARY
|
|
SEASONAL
|
|
PROJECT_BASED
|
|
DAILY
|
|
}
|
|
|
|
enum EquipmentType {
|
|
TRACTOR
|
|
HARVESTER
|
|
PLANTER
|
|
CULTIVATOR
|
|
IRRIGATION_SYSTEM
|
|
SPRAYER
|
|
THRESHER
|
|
MOWER
|
|
TOOLS
|
|
VEHICLE
|
|
PROCESSING_EQUIPMENT
|
|
STORAGE_EQUIPMENT
|
|
}
|
|
|
|
enum EquipmentCondition {
|
|
EXCELLENT
|
|
GOOD
|
|
FAIR
|
|
POOR
|
|
NEEDS_REPAIR
|
|
OUT_OF_ORDER
|
|
}
|
|
|
|
enum EquipmentStatus {
|
|
ACTIVE
|
|
INACTIVE
|
|
MAINTENANCE
|
|
REPAIR
|
|
RETIRED
|
|
}
|
|
|
|
enum MaintenanceType {
|
|
PREVENTIVE
|
|
CORRECTIVE
|
|
EMERGENCY
|
|
OVERHAUL
|
|
INSPECTION
|
|
CALIBRATION
|
|
}
|
|
|
|
enum AssetType {
|
|
BUILDING
|
|
LAND_IMPROVEMENT
|
|
INFRASTRUCTURE
|
|
VEHICLE
|
|
MACHINERY
|
|
FURNITURE
|
|
TECHNOLOGY
|
|
OTHER
|
|
}
|
|
|
|
enum AssetCondition {
|
|
NEW
|
|
EXCELLENT
|
|
GOOD
|
|
FAIR
|
|
POOR
|
|
DAMAGED
|
|
}
|
|
|
|
// Operations Models
|
|
model FarmInput {
|
|
id String @id @default(cuid())
|
|
farmId String
|
|
plotId String?
|
|
inputType InputType
|
|
productName String
|
|
brand String?
|
|
quantity Decimal
|
|
unit String
|
|
cost Decimal
|
|
supplier String?
|
|
supplierContact String?
|
|
batchNumber String?
|
|
expiryDate DateTime?
|
|
applicationDate DateTime?
|
|
applicationMethod String?
|
|
applicationRate String? // per hectare or per plant
|
|
activeIngredient String? // for pesticides/fertilizers
|
|
concentration Decimal? // percentage
|
|
notes String?
|
|
invoiceNumber String?
|
|
receiptUrl String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farm Farm @relation(fields: [farmId], references: [id])
|
|
plot Plot? @relation(fields: [plotId], references: [id])
|
|
|
|
@@index([farmId, plotId])
|
|
@@index([inputType])
|
|
@@index([applicationDate])
|
|
@@index([supplier])
|
|
@@index([expiryDate])
|
|
@@map("farm_inputs")
|
|
}
|
|
|
|
model InputSchedule {
|
|
id String @id @default(cuid())
|
|
farmId String
|
|
plotId String?
|
|
inputType InputType
|
|
productName String
|
|
scheduledDate DateTime
|
|
quantity Decimal
|
|
unit String
|
|
method String?
|
|
status ScheduleStatus @default(PENDING)
|
|
appliedDate DateTime?
|
|
appliedBy String?
|
|
actualQuantity Decimal?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farm Farm @relation(fields: [farmId], references: [id])
|
|
plot Plot? @relation(fields: [plotId], references: [id])
|
|
|
|
@@index([farmId, plotId])
|
|
@@index([scheduledDate])
|
|
@@index([status])
|
|
@@index([inputType])
|
|
@@map("input_schedules")
|
|
}
|
|
|
|
model Supplier {
|
|
id String @id @default(cuid())
|
|
name String
|
|
contactPerson String?
|
|
phone String?
|
|
email String?
|
|
address String?
|
|
supplierType SupplierType
|
|
paymentTerms String?
|
|
deliveryTerms String?
|
|
qualityCertifications String[]
|
|
isActive Boolean @default(true)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@index([supplierType])
|
|
@@index([isActive])
|
|
@@index([name])
|
|
@@map("suppliers")
|
|
}
|
|
|
|
model FarmWorker {
|
|
id String @id @default(cuid())
|
|
farmerId String
|
|
workerCode String @unique
|
|
name String
|
|
phone String?
|
|
email String?
|
|
address String?
|
|
identityNumber String?
|
|
role WorkerRole
|
|
skillLevel SkillLevel?
|
|
dailyWage Decimal?
|
|
monthlyWage Decimal?
|
|
paymentMethod PaymentMethod?
|
|
bankAccount String?
|
|
emergencyContact String?
|
|
emergencyPhone String?
|
|
hireDate DateTime?
|
|
contractType ContractType?
|
|
contractEnd DateTime?
|
|
isActive Boolean @default(true)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farmer Farmer @relation(fields: [farmerId], references: [id])
|
|
laborRecords LaborRecord[]
|
|
laborSchedules LaborSchedule[]
|
|
|
|
@@index([workerCode])
|
|
@@index([farmerId])
|
|
@@index([role])
|
|
@@index([isActive])
|
|
@@index([contractType])
|
|
@@map("farm_workers")
|
|
}
|
|
|
|
model LaborRecord {
|
|
id String @id @default(cuid())
|
|
farmerId String
|
|
farmId String
|
|
workerId String?
|
|
plotId String?
|
|
workType WorkType
|
|
hoursWorked Decimal
|
|
wages Decimal
|
|
workDate DateTime
|
|
startTime DateTime?
|
|
endTime DateTime?
|
|
description String?
|
|
supervisor String? // supervisor name or ID
|
|
qualityRating Decimal? // 1-5 rating
|
|
weather String?
|
|
notes String?
|
|
approved Boolean @default(false)
|
|
approvedBy String?
|
|
approvedDate DateTime?
|
|
paymentStatus PaymentStatus @default(PENDING)
|
|
paidDate DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farmer Farmer @relation(fields: [farmerId], references: [id])
|
|
farm Farm @relation(fields: [farmId], references: [id])
|
|
worker FarmWorker? @relation(fields: [workerId], references: [id])
|
|
plot Plot? @relation(fields: [plotId], references: [id])
|
|
|
|
@@index([farmerId, farmId])
|
|
@@index([workDate])
|
|
@@index([workType])
|
|
@@index([paymentStatus])
|
|
@@index([workerId])
|
|
@@map("labor_records")
|
|
}
|
|
|
|
model LaborSchedule {
|
|
id String @id @default(cuid())
|
|
farmerId String
|
|
farmId String
|
|
workerId String?
|
|
plotId String?
|
|
workType WorkType
|
|
scheduledDate DateTime
|
|
estimatedHours Decimal
|
|
estimatedWage Decimal?
|
|
status ScheduleStatus @default(PENDING)
|
|
assignedBy String?
|
|
notes String?
|
|
actualRecord String? // reference to LaborRecord ID
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farmer Farmer @relation(fields: [farmerId], references: [id])
|
|
farm Farm @relation(fields: [farmId], references: [id])
|
|
worker FarmWorker? @relation(fields: [workerId], references: [id])
|
|
plot Plot? @relation(fields: [plotId], references: [id])
|
|
|
|
@@index([farmerId, farmId])
|
|
@@index([scheduledDate])
|
|
@@index([status])
|
|
@@index([workType])
|
|
@@index([workerId])
|
|
@@map("labor_schedules")
|
|
}
|
|
|
|
model Equipment {
|
|
id String @id @default(cuid())
|
|
farmerId String
|
|
equipmentCode String @unique
|
|
name String
|
|
type EquipmentType
|
|
brand String?
|
|
model String?
|
|
serialNumber String?
|
|
purchaseDate DateTime?
|
|
purchasePrice Decimal?
|
|
currentValue Decimal?
|
|
condition EquipmentCondition
|
|
status EquipmentStatus @default(ACTIVE)
|
|
location String? // where equipment is stored
|
|
fuelType String? // diesel, petrol, electric, manual
|
|
capacity String? // engine capacity, load capacity
|
|
powerRating String? // horsepower, wattage
|
|
yearManufactured Int?
|
|
warranty String?
|
|
insurancePolicy String?
|
|
insuranceExpiry DateTime?
|
|
lastMaintenance DateTime?
|
|
nextMaintenance DateTime?
|
|
maintenanceCost Decimal?
|
|
operatingHours Decimal? // total operating hours
|
|
isActive Boolean @default(true)
|
|
notes String?
|
|
photoUrl String?
|
|
manualUrl String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farmer Farmer @relation(fields: [farmerId], references: [id])
|
|
maintenanceRecords MaintenanceRecord[]
|
|
usageRecords EquipmentUsage[]
|
|
|
|
@@index([equipmentCode])
|
|
@@index([farmerId])
|
|
@@index([type])
|
|
@@index([status])
|
|
@@index([nextMaintenance])
|
|
@@index([isActive])
|
|
@@map("equipment")
|
|
}
|
|
|
|
model MaintenanceRecord {
|
|
id String @id @default(cuid())
|
|
equipmentId String
|
|
maintenanceType MaintenanceType
|
|
description String
|
|
cost Decimal
|
|
serviceProvider String?
|
|
serviceDate DateTime
|
|
nextServiceDue DateTime?
|
|
partsReplaced String[]
|
|
laborHours Decimal?
|
|
invoiceNumber String?
|
|
receiptUrl String?
|
|
performedBy String?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
equipment Equipment @relation(fields: [equipmentId], references: [id])
|
|
|
|
@@index([equipmentId])
|
|
@@index([serviceDate])
|
|
@@index([maintenanceType])
|
|
@@index([nextServiceDue])
|
|
@@map("maintenance_records")
|
|
}
|
|
|
|
model EquipmentUsage {
|
|
id String @id @default(cuid())
|
|
equipmentId String
|
|
farmId String?
|
|
plotId String?
|
|
operatorName String?
|
|
usageDate DateTime
|
|
startTime DateTime?
|
|
endTime DateTime?
|
|
hoursUsed Decimal
|
|
fuelConsumed Decimal?
|
|
workType WorkType?
|
|
description String?
|
|
meterReading Decimal? // odometer, hour meter reading
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
equipment Equipment @relation(fields: [equipmentId], references: [id])
|
|
farm Farm? @relation(fields: [farmId], references: [id])
|
|
plot Plot? @relation(fields: [plotId], references: [id])
|
|
|
|
@@index([equipmentId])
|
|
@@index([usageDate])
|
|
@@index([farmId, plotId])
|
|
@@index([workType])
|
|
@@map("equipment_usage")
|
|
}
|
|
|
|
model Asset {
|
|
id String @id @default(cuid())
|
|
farmerId String
|
|
assetCode String @unique
|
|
name String
|
|
type AssetType
|
|
category String? // building, land improvement, infrastructure
|
|
description String?
|
|
purchaseDate DateTime?
|
|
purchasePrice Decimal?
|
|
currentValue Decimal?
|
|
depreciation Decimal? // annual depreciation rate
|
|
condition AssetCondition
|
|
location String?
|
|
size String? // dimensions, area
|
|
material String? // construction material
|
|
lifespan Int? // expected lifespan in years
|
|
warrantyExpiry DateTime?
|
|
insurancePolicy String?
|
|
insuranceExpiry DateTime?
|
|
photoUrls String[]
|
|
documentUrls String[]
|
|
isActive Boolean @default(true)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farmer Farmer @relation(fields: [farmerId], references: [id])
|
|
|
|
@@index([assetCode])
|
|
@@index([farmerId])
|
|
@@index([type])
|
|
@@index([condition])
|
|
@@index([isActive])
|
|
@@map("assets")
|
|
} |