99 lines
3.0 KiB
Go
99 lines
3.0 KiB
Go
package models
|
|
|
|
var AssetModels = []interface{}{
|
|
&Land{},
|
|
&Plant{},
|
|
&Machine{},
|
|
&Seed{},
|
|
&Fertilizer{},
|
|
&FertilizerIngredient{},
|
|
&Pesticide{},
|
|
&Product{},
|
|
}
|
|
|
|
type _Asset struct {
|
|
ID uint `gorm:"primaryKey`
|
|
Name string `gorm:"not null"`
|
|
Notes string
|
|
}
|
|
|
|
type Land struct {
|
|
_Asset
|
|
FID string `gorm:"not null"`
|
|
IsWaterProtectionArea bool `gorm:"not null"`
|
|
IsRedArea bool `gorm:"not null"`
|
|
Area float64 `gorm:"not null"`
|
|
}
|
|
|
|
type Plant struct {
|
|
_Asset
|
|
LandId uint `gorm:"not null"`
|
|
Land Land `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
CropID uint `gorm:"not null"`
|
|
Crop Crop `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
CoverCropID uint `gorm:"not null"`
|
|
CoverCrop Crop `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
Year uint `gorm:"not null"`
|
|
AreaPercentage float64 `gorm:"not null"`
|
|
}
|
|
type _Resource struct {
|
|
_Asset
|
|
UnitID uint `gorm:"not null"`
|
|
Unit Unit `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
Cost decimal.Decimal `gorm:"not null; type:decimal(10,2);"` // in euro/unit
|
|
}
|
|
|
|
type Machine struct {
|
|
_Resource
|
|
}
|
|
|
|
type _BoughtResource struct {
|
|
_Resource
|
|
BuyDate Datetime.Time `gorm:"type:date;default:CURRENT_DATE"`
|
|
BoughtFromID uint `gorm:"not null"`
|
|
BoughtFrom Seller `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
}
|
|
|
|
type _SoldResource struct {
|
|
_Resource
|
|
SaleDate Datetime.Time `gorm:"type:date;default:CURRENT_DATE"`
|
|
SoldToID uint `gorm:"not null"`
|
|
SoldTo Customer `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
}
|
|
|
|
type Seed struct {
|
|
_BoughtResource
|
|
SeedTypeID uint `gorm:"not null"`
|
|
SeedType SeedType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
}
|
|
|
|
type Fertilizer struct {
|
|
_Asset
|
|
_BoughtResource
|
|
FertilizerTypeID uint `gorm:"not null"`
|
|
FertilizerType FertilizerType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
// Association to the ingredients. This represents the composition.
|
|
Ingredients []FertilizerIngredient `gorm:"not null; many2many:fertilizer_ingredient"`
|
|
}
|
|
|
|
type FertilizerIngredient struct {
|
|
FertilizerAssetID uint `gorm:"primaryKey"` // foreign key to the fertilizer asset
|
|
IngredientID uint `gorm:"primaryKey"` // foreign key to the ingredient
|
|
Amount float64 `gorm:"not null"` // amount of the ingredient
|
|
|
|
// Preload the ingredient details if needed.
|
|
Ingredient Ingredient `gorm:"not null"`
|
|
}
|
|
|
|
type Pesticide struct {
|
|
_BoughtResource
|
|
PesticideTypeID uint `gorm:"not null"`
|
|
PesticideType PesticideType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
}
|
|
|
|
type Product struct {
|
|
_SoldResource
|
|
ProductTypeID uint `gorm:"not null"`
|
|
ProductType ProductType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
}
|