| | |
| | | BeginAmount decimal.Decimal `json:"beginAmount" gorm:"type:decimal(30,10);not null;comment:数量"` //期初数量 |
| | | EndAmount decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;comment:数量"` //期末结余数量 |
| | | |
| | | InputAmount decimal.Decimal `json:"inputAmount" gorm:"type:decimal(30,10);not null;comment:数量"` //入库数量 |
| | | InputItems []*WarehouseStatsItems `json:"inputItems"` //入库明细 |
| | | |
| | | InputAmount decimal.Decimal `json:"inputAmount" gorm:"type:decimal(30,10);not null;comment:数量"` //入库数量 |
| | | InputItems []*WarehouseStatsItems `json:"inputItems" gorm:"-"` //入库明细 |
| | | Items []*WarehouseStatsItems `json:"-"` |
| | | OutputAmount decimal.Decimal `json:"outputAmount" gorm:"type:decimal(30,10);not null;comment:数量"` //出库数量 |
| | | OutputItems []*WarehouseStatsItems `json:"outputItems"` //出库明细 |
| | | OutputItems []*WarehouseStatsItems `json:"outputItems" gorm:"-"` //出库明细 |
| | | |
| | | Date string `json:"date" gorm:"index;type:varchar(255); not null;default ''"` //日期 2024-04 |
| | | } |
| | | |
| | | WarehouseStatsItems struct { |
| | | WarehouseMonthStatsId int `json:"warehouseMonthStatsId"` |
| | | Name string `json:"name" gorm:"type:varchar(255);not null;default:''"` //入库来源,出库去处 |
| | | Amount decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;"` //数量 |
| | | WarehouseMonthStatsId int `json:"warehouseMonthStatsId"` |
| | | Type MonthStatsItemsType `json:"type" gorm:"type:tinyint;not null;default:1"` |
| | | Name string `json:"name" gorm:"type:varchar(255);not null;default:''"` //入库来源,出库去处 |
| | | Amount decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;"` //数量 |
| | | } |
| | | |
| | | WarehouseMonthStatsSearch struct { |
| | |
| | | } |
| | | ) |
| | | |
| | | type MonthStatsItemsType int |
| | | |
| | | const ( |
| | | MonthStatsItemsTypeInput MonthStatsItemsType = 1 //入库 |
| | | MonthStatsItemsTypeOutput MonthStatsItemsType = 2 //出库 |
| | | ) |
| | | |
| | | func (slf *WarehouseStatsItems) TableName() string { |
| | | return "wms_warehouse_month_stats_items" |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStats) TableName() string { |
| | | return "wms_warehouse_month_stats" |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStats) BeforeCreate(tx *gorm.DB) error { |
| | | if len(slf.InputItems) != 0 || len(slf.OutputItems) != 0 { |
| | | items := make([]*WarehouseStatsItems, 0, len(slf.InputItems)+len(slf.OutputItems)) |
| | | for _, item := range slf.InputItems { |
| | | items = append(items, &WarehouseStatsItems{ |
| | | Type: MonthStatsItemsTypeInput, |
| | | Name: item.Name, |
| | | Amount: item.Amount, |
| | | }) |
| | | } |
| | | |
| | | for _, item := range slf.OutputItems { |
| | | items = append(items, &WarehouseStatsItems{ |
| | | Type: MonthStatsItemsTypeOutput, |
| | | Name: item.Name, |
| | | Amount: item.Amount, |
| | | }) |
| | | } |
| | | |
| | | slf.Items = items |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf *WarehouseMonthStats) AfterFind(tx *gorm.DB) error { |
| | | if len(slf.Items) != 0 { |
| | | inputItems := make([]*WarehouseStatsItems, 0) |
| | | outputItems := make([]*WarehouseStatsItems, 0) |
| | | for _, v := range slf.Items { |
| | | item := WarehouseStatsItems{ |
| | | Type: v.Type, |
| | | Name: v.Name, |
| | | Amount: v.Amount, |
| | | } |
| | | if v.Type == MonthStatsItemsTypeInput { |
| | | inputItems = append(inputItems, &item) |
| | | } else { |
| | | outputItems = append(outputItems, &item) |
| | | } |
| | | } |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func NewWarehouseMonthStatsSearch() *WarehouseMonthStatsSearch { |
| | |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Preload("InputItems").Preload("OutputItems") |
| | | db = db.Preload("Items") |
| | | } |
| | | |
| | | return db |