From da621f474d28ab041dcf258142eddb506100a8ce Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 31 七月 2024 16:28:37 +0800 Subject: [PATCH] 出入库明细支持动态多单位 --- service/history_forms.go | 50 +++++++++++++++++++++++++++++--------------------- 1 files changed, 29 insertions(+), 21 deletions(-) diff --git a/service/history_forms.go b/service/history_forms.go index 075317a..4564caa 100644 --- a/service/history_forms.go +++ b/service/history_forms.go @@ -51,7 +51,7 @@ } moreUnit := v.Product.MoreUnit if moreUnit != nil && *moreUnit { - data.AmountMoreUnits = CreateMoreUnit(v.Amount, v.Product.MoreUnitList) + data.AmountMoreUnits = v.MoreUnitList } result = append(result, data) } @@ -77,7 +77,7 @@ search.Orm = search.Orm.Model(&models.MoveHistory{}). Select("number, updated_at, product_name, from_location_id, operation_id,to_location_id, amount, " + - "unit, operator, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc") + "unit, operator, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight, more_unit_value").Order("id desc") if len(ids) > 0 { search.Orm = search.Orm.Where("id in ?", ids) } @@ -141,10 +141,19 @@ // 鑷畾涔夎〃澶� headers := []interface{}{"鏃ユ湡", "鍗曞彿", "浜у搧", "浜у搧缂栫爜", "涓氬姟绫诲瀷", "浠�", "鑷�", map[string][]string{"鏁伴噺": unitData}, "鍗曚綅", "閲嶉噺"} - - // 璁剧疆琛ㄥご - if err := SetExcelHeader(headers, f); err != nil { + lastColumnNumber, err := SetExcelHeaders(headers, f) + if err != nil { return "", err + } + + for i := 1; i <= 7; i++ { + column := getColumnAlphabet(i) + f.MergeCell("Sheet1", column+"1", column+"2") // 鍚堝苟鍗曞厓鏍� + } + + for i := lastColumnNumber - 2; i <= lastColumnNumber; i++ { + column := getColumnAlphabet(i) + f.MergeCell("Sheet1", column+"1", column+"2") // 鍚堝苟鍗曞厓鏍� } style, err := SetHeaderStyle(f) @@ -152,25 +161,24 @@ return "", err } - lastColumn := getColumnAlphabet(13) - f.SetCellStyle("Sheet1", "A1", lastColumn+"2", style) + lastColumn := getColumnAlphabet(lastColumnNumber) + f.SetCellStyle("Sheet1", "A1", lastColumn, style) // 璁剧疆鍒楀 - f.SetColWidth("Sheet1", "A", "G", 30) - f.SetColWidth("Sheet1", "H", "K", 15) + f.SetColWidth("Sheet1", "A", lastColumn, 20) for i, v := range dataList { - column := strconv.Itoa(i + 3) - f.SetCellValue("Sheet1", "A"+column, v.Date) - f.SetCellValue("Sheet1", "B"+column, v.Number) - f.SetCellValue("Sheet1", "C"+column, v.ProductName) - f.SetCellValue("Sheet1", "D"+column, v.ProductId) - f.SetCellValue("Sheet1", "E"+column, v.OperationTypeName) - f.SetCellValue("Sheet1", "F"+column, v.FromLocation) - f.SetCellValue("Sheet1", "G"+column, v.ToLocation) - f.SetCellValue("Sheet1", "H"+column, v.Amount) - FillMoreUnitToExcel(v.AmountMoreUnits, 7, i+3, unitIndexMap, f) - f.SetCellValue("Sheet1", "L"+column, v.Unit) - f.SetCellValue("Sheet1", "M"+column, v.Weight) + row := strconv.Itoa(i + 3) + f.SetCellValue("Sheet1", "A"+row, v.Date) + f.SetCellValue("Sheet1", "B"+row, v.Number) + f.SetCellValue("Sheet1", "C"+row, v.ProductName) + f.SetCellValue("Sheet1", "D"+row, v.ProductId) + f.SetCellValue("Sheet1", "E"+row, v.OperationTypeName) + f.SetCellValue("Sheet1", "F"+row, v.FromLocation) + f.SetCellValue("Sheet1", "G"+row, v.ToLocation) + v.AmountMoreUnits = append(v.AmountMoreUnits, models.UnitItems{Amount: v.Amount, Unit: v.Unit}) + FillMoreUnitToExcel(v.AmountMoreUnits, 8, i+3, unitIndexMap, f) + f.SetCellValue("Sheet1", getColumnAlphabet(8+len(unitData))+row, v.Unit) + f.SetCellValue("Sheet1", getColumnAlphabet(9+len(unitData))+row, v.Weight) } if params.BaseOperationType == constvar.BaseOperationTypeIncoming { -- Gitblit v1.8.0