| | |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/request" |
| | | "wms/utils" |
| | | ) |
| | | |
| | | type WarehouseMonthFormsService struct{} |
| | |
| | | f.SetColWidth("Sheet1", "A", "F", 30) |
| | | f.SetColWidth("Sheet1", "G", getColumnAlphabet(headerLen), 15) |
| | | |
| | | inputStart := 7 |
| | | outputStart := 7 + len(inputTypes) |
| | | inputStart := 6 |
| | | outputStart := 6 + len(inputTypes) |
| | | for i, v := range dataList { |
| | | column := strconv.Itoa(i + 3) |
| | | f.SetCellValue("Sheet1", "A"+column, v.ProductId) |
| | |
| | | columnStr := strconv.Itoa(column) |
| | | sum := slf.SumItems(items) |
| | | detailMap := models.WarehouseStatsItemMap(items) |
| | | for k := range detailMap { |
| | | if k == "" { |
| | | detailMap["其他"] = detailMap[k] |
| | | delete(detailMap, k) |
| | | } |
| | | } |
| | | |
| | | for i := 0; i < len(dealerTypes); i++ { |
| | | var amount decimal.Decimal |
| | |
| | | } |
| | | productMap := models.MaterialMap(products) |
| | | |
| | | beginTime, endTime := utils.GetLastMonthPeriod() |
| | | //按配置取开始时间和结束时间 |
| | | beginTime, endTime, err := NewSystemConfigService().GetInventoryCutOffTime() |
| | | if err != nil { |
| | | logx.Errorf("MonthStats GetCurrentStats get GetInventoryCutOffTime err:%v", err) |
| | | return |
| | | } |
| | | inputMap, err := GetStatsMulti(beginTime, endTime, constvar.BaseOperationTypeIncoming, warehouseId) |
| | | if err != nil { |
| | | logx.Errorf("MonthStats GetStatsByOperationType input err:%v", err) |
| | |
| | | SalePrice: product.SalePrice, |
| | | EndAmount: amount, |
| | | InputAmount: SumMapAmount(inputMap[productId]), |
| | | InputItems: GetDealerItems(inputMap[productId]), |
| | | InputItems: GetDealerItems(inputMap[productId], models.MonthStatsItemsTypeInput), |
| | | OutputAmount: SumMapAmount(outputMap[productId]), |
| | | OutputItems: GetDealerItems(outputMap[productId]), |
| | | OutputItems: GetDealerItems(outputMap[productId], models.MonthStatsItemsTypeOutput), |
| | | Date: date, |
| | | } |
| | | statRecords = append(statRecords, &record) |
| | |
| | | } |
| | | |
| | | func GetStatsMulti(beginTime, endTime time.Time, operationType constvar.BaseOperationType, warehouseId int) (m map[string]map[string]decimal.Decimal, err error) { |
| | | m = make(map[string]map[string]decimal.Decimal) |
| | | operationIds, err := models.NewOperationSearch().SetBaseOperationType(operationType). |
| | | SetFields("id").SetTimeBetween(beginTime, endTime). |
| | | SetWarehouseId(warehouseId). |
| | | FindIds() |
| | | if err != nil { |
| | | return |
| | | } |
| | | if len(operationIds) == 0 { |
| | | return |
| | | } |
| | | groupSumList, err := models.NewOperationDetailsSearch().SetOperationIds(operationIds). |
| | |
| | | return |
| | | } |
| | | |
| | | func GetDealerItems(m map[string]decimal.Decimal) (items []*models.WarehouseStatsItems) { |
| | | func GetDealerItems(m map[string]decimal.Decimal, tp models.MonthStatsItemsType) (items []*models.WarehouseStatsItems) { |
| | | for k, v := range m { |
| | | name := k |
| | | if name == "" { |
| | | name = "其他" |
| | | } |
| | | items = append(items, &models.WarehouseStatsItems{ |
| | | Type: tp, |
| | | Name: name, |
| | | Amount: v, |
| | | }) |