| | |
| | | data.Cost = material.Cost |
| | | data.Unit = material.Unit |
| | | data.Value = material.Amount.Mul(material.Cost) |
| | | data.ProductType = material.CategoryName |
| | | data.ProductCategory = material.CategoryName |
| | | data.ProductType = material.Type |
| | | data.ProductSpecs = material.Specs |
| | | for _, amount := range productAmounts { |
| | | if material.ID == amount.ProductId { |
| | | data.Amount = data.Amount.Add(amount.Amount) |
| | |
| | | err error) { |
| | | productAmounts = make([]*models.LocationProductAmount, 0) |
| | | locationSearch := models.NewLocationSearch() |
| | | if params.WarehouseCode != "" { |
| | | locationSearch.SetJointName(params.WarehouseCode) |
| | | //if params.WarehouseCode != "" { |
| | | // locationSearch.SetJointName(params.WarehouseCode) |
| | | //} |
| | | if params.WarehouseId > 0 { |
| | | locationSearch.SetWarehouseId(params.WarehouseId) |
| | | } |
| | | |
| | | locations, err := locationSearch.FindNotTotal() |
| | |
| | | |
| | | //查询产品 |
| | | search = models.NewMaterialSearch() |
| | | search.Orm = search.Orm.Model(&models.Material{}). |
| | | Select(`material.id, material.name, material.cost, material.amount, material.unit, material.more_unit, material.more_unit_value, wms_product_category.name as category_name `). |
| | | Joins("left join wms_product_category on material.category_id = wms_product_category.id") |
| | | search.Orm = search.Orm.Model(&models.Material{}). // material |
| | | Select(`material.id, material.name, material.cost, material.amount, material.unit, material.more_unit, material.more_unit_value, wms_product_category.name as category_name `). |
| | | Joins("left join wms_product_category on material.category_id = wms_product_category.id") |
| | | if len(params.CategoryIds) > 0 { |
| | | search.Orm.Where("material.category_id in (?)", params.CategoryIds) |
| | | } |
| | |
| | | var fileName string |
| | | f := excelize.NewFile() |
| | | |
| | | unitData, unitIndexMap := GetAllUnits() |
| | | // 自定义表头 |
| | | headers := []string{"产品", "产品类别", "单位成本", "总价值", "在库", "可用库存", "入库", "出库"} |
| | | // 设置表头 |
| | |
| | | f.SetCellValue("Sheet1", cell, header) |
| | | } |
| | | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(0)+"1", "产品") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(1)+"1", "产品类别") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(2)+"1", "单位成本") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(3)+"1", "总价值") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(4)+"1", "在库") |
| | | f.MergeCell("Sheet1", getColumnAlphabet(4)+"1", getColumnAlphabet(7)+"1") // 合并单元格 |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(1)+"1", "产品") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(2)+"1", "产品类别") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(3)+"1", "单位成本") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(4)+"1", "总价值") |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(5)+"1", "在库") |
| | | f.MergeCell("Sheet1", getColumnAlphabet(5)+"1", getColumnAlphabet(7)+"1") // 合并单元格 |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(8)+"1", "可用库存") |
| | | f.MergeCell("Sheet1", getColumnAlphabet(8)+"1", getColumnAlphabet(11)+"1") // 合并单元格 |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(12)+"1", "入库") |
| | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(16)+"1", "出库") |
| | | f.MergeCell("Sheet1", getColumnAlphabet(16)+"1", getColumnAlphabet(19)+"1") // 合并单元格 |
| | | |
| | | unitData := []string{"件", "匹", "米", "重量"} |
| | | for i, header := range unitData { |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(i+4)+"2", header) |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(i+8)+"2", header) |
| | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(3)+column, v.Value) |
| | | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(4)+column, v.Amount) |
| | | FillMoreUnitToExcel(v.Amount, v.AmountMoreUnits, 5, i+3, f) |
| | | v.AmountMoreUnits = append(v.AmountMoreUnits, models.UnitItems{Amount: v.Amount, Unit: v.Unit}) |
| | | FillMoreUnitToExcel(v.AmountMoreUnits, 5, i+3, unitIndexMap, f) |
| | | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(8)+column, v.AvailableNumber) |
| | | FillMoreUnitToExcel(v.AvailableNumber, v.AvailableNumberMoreUnits, 9, i+3, f) |
| | | v.AvailableNumberMoreUnits = append(v.AvailableNumberMoreUnits, models.UnitItems{Amount: v.AvailableNumber, Unit: v.Unit}) |
| | | FillMoreUnitToExcel(v.AvailableNumberMoreUnits, 9, i+3, unitIndexMap, f) |
| | | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(12)+column, v.In) |
| | | FillMoreUnitToExcel(v.In, v.AmountMoreUnits, 13, i+3, f) |
| | | v.InMoreUnits = append(v.InMoreUnits, models.UnitItems{Amount: v.In, Unit: v.Unit}) |
| | | FillMoreUnitToExcel(v.InMoreUnits, 13, i+3, unitIndexMap, f) |
| | | |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(16)+column, v.Out) |
| | | FillMoreUnitToExcel(v.Out, v.AmountMoreUnits, 17, i+3, f) |
| | | v.OutMoreUnits = append(v.OutMoreUnits, models.UnitItems{Amount: v.Out, Unit: v.Unit}) |
| | | FillMoreUnitToExcel(v.OutMoreUnits, 17, i+3, unitIndexMap, f) |
| | | } |
| | | |
| | | fileName = fmt.Sprintf("库存报表%s.xlsx", time.Now().Format("2006-01-02-1504")) |
| | |
| | | func getColumnAlphabet(index int) string { |
| | | const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| | | if index <= 26 { |
| | | return string(alphabet[index]) |
| | | return string(alphabet[index-1]) |
| | | } |
| | | return getColumnAlphabet((index)/26) + getColumnAlphabet((index)%26+1) |
| | | quotient := (index - 1) / 26 |
| | | remainder := (index - 1) % 26 |
| | | return getColumnAlphabet(quotient) + getColumnAlphabet(remainder+1) |
| | | } |