瀏覽代碼

add:批量导出入/出库单

zoie 2 天之前
父節點
當前提交
4cee5d6d62
共有 2 個文件被更改,包括 373 次插入1 次删除
  1. 369 0
      controllers/Stock.go
  2. 4 1
      routers/Stock.go

+ 369 - 0
controllers/Stock.go

@@ -1473,6 +1473,192 @@ func (c *StockController) StockIn_Excel() {
 	return
 }
 
+// 批量导出出库单
+func (c *StockController) StockIn_Excel_Batch() {
+
+	// 查询
+	T_number_list := c.GetString("T_number_list")
+
+	o := orm.NewOrm()
+	StockInDao := Stock.NewStockIn(o)
+	StockInProductDao := Stock.NewStockInProduct(o)
+	list := strings.Split(strings.Trim(T_number_list, "|"), "|")
+
+	userList, _ := NatsServer.Read_User_List_All()
+	Account.Read_User_All_Map(userList)
+	filename := fmt.Sprintf("冷链产品入库单(%s)", lib.GetRandstring(6, "0123456789", 0))
+
+	f := excelize.NewFile() // 设置单元格的值
+
+	Style1, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
+			Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
+		})
+	Style2, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Size: 11, Family: "宋体"},
+			Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
+		})
+
+	Style3, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Size: 10, Family: "宋体", Bold: true},
+			Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
+			Border: []excelize.Border{
+				{Type: "left", Color: "000000", Style: 1},
+				{Type: "top", Color: "000000", Style: 1},
+				{Type: "bottom", Color: "000000", Style: 1},
+				{Type: "right", Color: "000000", Style: 1},
+			},
+		})
+	Style4, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Size: 11, Family: "宋体"},
+			Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
+			Border: []excelize.Border{
+				{Type: "left", Color: "000000", Style: 1},
+				{Type: "top", Color: "000000", Style: 1},
+				{Type: "bottom", Color: "000000", Style: 1},
+				{Type: "right", Color: "000000", Style: 1},
+			},
+		})
+	var num int
+	for _, T_number := range list {
+		stockIn, err := StockInDao.Read_StockIn_ByT_number(T_number)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
+			c.ServeJSON()
+			return
+		}
+
+		productList := StockInProductDao.Read_StockInProduct_List_ByT_number(stockIn.T_number)
+		productList = append(productList, productList...)
+		productList = append(productList, productList...)
+		productList = append(productList, productList...)
+		var pList []Stock.StockInProduct_R
+		for _, v := range productList {
+			pList = append(pList, Stock.StockInProductToStockInProduct_R(v))
+		}
+
+		stockInDetail := Stock.StockInToStockIn_Detail(stockIn, pList)
+		T_date, _ := lib.DateStrToTime(stockIn.T_date)
+
+		productList2 := lib.ChunkBy(productList, 10)
+
+		for i, products := range productList2 {
+			if len(products) < 10 {
+				products = append(products, make([]Stock.StockInProduct, 10-len(products))...)
+			}
+
+			row := num*18 + 1
+			num += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style1)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("宝智达科技产品进销存统计表"))
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style1)
+			title := "硬件入库单"
+			if len(productList2) > 1 {
+				title += fmt.Sprintf(" %d/%d", i+1, len(productList2))
+			}
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), title)
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("入库单号:%s", stockIn.T_number))
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("项目名称:%s", stockIn.T_remark))
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("入库时间:%s", T_date.Format("2006年01月02日")))
+			f.SetRowHeight("Sheet1", row, 20)
+			// 这里设置表头
+			row += 1
+			f.SetRowHeight("Sheet1", row, 20)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), "序号")
+			f.SetCellValue("Sheet1", fmt.Sprintf("B%d", row), "产品名称")
+			f.SetCellValue("Sheet1", fmt.Sprintf("C%d", row), "型号")
+			f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), "单位")
+			f.SetCellValue("Sheet1", fmt.Sprintf("E%d", row), "领用数量")
+			f.SetCellValue("Sheet1", fmt.Sprintf("F%d", row), "备注")
+
+			// 设置列宽
+			f.SetColWidth("Sheet1", "A", "A", 5)
+			f.SetColWidth("Sheet1", "B", "B", 20)
+			f.SetColWidth("Sheet1", "C", "C", 12)
+			f.SetColWidth("Sheet1", "D", "D", 10)
+			f.SetColWidth("Sheet1", "E", "E", 10)
+			f.SetColWidth("Sheet1", "F", "F", 15)
+			f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row), Style3)
+
+			sRow := row
+			// 循环写入数据
+			for j, v := range products {
+				row += 1
+				product, _ := Basic.Read_Product_ById(v.T_product_id)
+
+				f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), j+1)
+				f.SetCellValue("Sheet1", fmt.Sprintf("B%d", row), product.T_name)
+				f.SetCellValue("Sheet1", fmt.Sprintf("C%d", row), product.T_model)
+				f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), product.T_spec)
+				if v.T_num > 0 {
+					f.SetCellValue("Sheet1", fmt.Sprintf("E%d", row), v.T_num)
+					f.SetCellValue("Sheet1", fmt.Sprintf("F%d", row), stockIn.T_remark)
+				}
+			}
+
+			f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", sRow), fmt.Sprintf("F%d", row), Style4)
+
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("C%d", row))
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("制单:%s", c.User.T_name))
+			f.MergeCell("Sheet1", fmt.Sprintf("D%d", row), fmt.Sprintf("F%d", row))
+			f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), fmt.Sprintf("经办人:%s", stockInDetail.T_submit_name))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetRowHeight("Sheet1", row, 20)
+
+			// 空一行
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style1)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), "")
+
+		}
+	}
+
+	// 保存文件
+	if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
+		fmt.Println(err)
+	}
+	var url string
+	//// 上传 OSS
+	nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
+	url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
+		c.ServeJSON()
+		return
+	}
+	//删除目录
+	err := os.Remove("ofile/" + filename + ".xlsx")
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
+	c.ServeJSON()
+	return
+}
+
 func (c *StockController) StockOut_List() {
 
 	// 分页参数 初始化
@@ -2625,6 +2811,189 @@ func (c *StockController) StockOut_Excel() {
 	c.ServeJSON()
 	return
 }
+func (c *StockController) StockOut_Excel_Batch() {
+
+	// 查询
+	T_number_list := c.GetString("T_number_list")
+
+	o := orm.NewOrm()
+	StockOutDao := Stock.NewStockOut(o)
+	StockOutProductDao := Stock.NewStockOutProduct(o)
+
+	list := strings.Split(strings.Trim(T_number_list, "|"), "|")
+	userList, _ := NatsServer.Read_User_List_All()
+	Account.Read_User_All_Map(userList)
+	filename := fmt.Sprintf("冷链产品出库单(%s)", lib.GetRandstring(6, "0123456789", 0))
+	f := excelize.NewFile() // 设置单元格的值
+	Style1, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
+			Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
+		})
+	Style2, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Size: 11, Family: "宋体"},
+			Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
+		})
+
+	Style3, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Size: 10, Family: "宋体", Bold: true},
+			Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
+			Border: []excelize.Border{
+				{Type: "left", Color: "000000", Style: 1},
+				{Type: "top", Color: "000000", Style: 1},
+				{Type: "bottom", Color: "000000", Style: 1},
+				{Type: "right", Color: "000000", Style: 1},
+			},
+		})
+	Style4, _ := f.NewStyle(
+		&excelize.Style{
+			Font:      &excelize.Font{Size: 11, Family: "宋体"},
+			Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
+			Border: []excelize.Border{
+				{Type: "left", Color: "000000", Style: 1},
+				{Type: "top", Color: "000000", Style: 1},
+				{Type: "bottom", Color: "000000", Style: 1},
+				{Type: "right", Color: "000000", Style: 1},
+			},
+		})
+	var num int
+	for _, T_number := range list {
+		stockOut, err := StockOutDao.Read_StockOut_ByT_number(T_number)
+		if err != nil {
+			c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
+			c.ServeJSON()
+			return
+		}
+
+		productList := StockOutProductDao.Read_StockOutProduct_List(stockOut.T_number)
+		productList = append(productList, productList...)
+		productList = append(productList, productList...)
+		productList = append(productList, productList...)
+		productList = append(productList, productList...)
+
+		var pList []Stock.StockOutProduct_R
+		for _, v := range productList {
+			pList = append(pList, Stock.StockOutProductToStockOutProduct_R(v))
+		}
+
+		stockOutDetail := Stock.StockOutToStockOut_Detail(stockOut, pList)
+		T_date, _ := lib.DateStrToTime(stockOut.T_date)
+
+		productList2 := lib.ChunkBy(productList, 10)
+
+		for i, products := range productList2 {
+			if len(products) < 10 {
+				products = append(products, make([]Stock.StockOutProduct, 10-len(products))...)
+			}
+			row := num*18 + 1
+			num += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style1)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("宝智达科技产品进销存统计表"))
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style1)
+			title := "硬件出库单"
+			if len(productList2) > 1 {
+				title += fmt.Sprintf(" %d/%d", i+1, len(productList2))
+			}
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), title)
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("出库单号:%s", stockOut.T_number))
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("项目名称:%s", stockOut.T_project))
+			f.SetRowHeight("Sheet1", row, 20)
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("领用时间:%s", T_date.Format("2006年01月02日")))
+			f.SetRowHeight("Sheet1", row, 20)
+			// 这里设置表头
+			row += 1
+			f.SetRowHeight("Sheet1", row, 20)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), "序号")
+			f.SetCellValue("Sheet1", fmt.Sprintf("B%d", row), "产品名称")
+			f.SetCellValue("Sheet1", fmt.Sprintf("C%d", row), "型号")
+			f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), "单位")
+			f.SetCellValue("Sheet1", fmt.Sprintf("E%d", row), "领用数量")
+			f.SetCellValue("Sheet1", fmt.Sprintf("F%d", row), "备注")
+
+			// 设置列宽
+			f.SetColWidth("Sheet1", "A", "A", 5)
+			f.SetColWidth("Sheet1", "B", "B", 20)
+			f.SetColWidth("Sheet1", "C", "C", 12)
+			f.SetColWidth("Sheet1", "D", "D", 10)
+			f.SetColWidth("Sheet1", "E", "E", 10)
+			f.SetColWidth("Sheet1", "F", "F", 15)
+			f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row), Style3)
+
+			sRow := row
+			// 循环写入数据
+			for j, v := range products {
+				row += 1
+				product, _ := Basic.Read_Product_ById(v.T_product_id)
+
+				f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), j+1)
+				f.SetCellValue("Sheet1", fmt.Sprintf("B%d", row), product.T_name)
+				f.SetCellValue("Sheet1", fmt.Sprintf("C%d", row), product.T_model)
+				f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), product.T_spec)
+				if v.T_num > 0 {
+					f.SetCellValue("Sheet1", fmt.Sprintf("E%d", row), v.T_num)
+					f.SetCellValue("Sheet1", fmt.Sprintf("F%d", row), stockOut.T_remark)
+				}
+			}
+
+			f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", sRow), fmt.Sprintf("F%d", row), Style4)
+
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("C%d", row))
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("制单:%s", c.User.T_name))
+			f.MergeCell("Sheet1", fmt.Sprintf("D%d", row), fmt.Sprintf("F%d", row))
+			f.SetCellValue("Sheet1", fmt.Sprintf("D%d", row), fmt.Sprintf("领用人:%s", stockOutDetail.T_receive_name))
+			f.SetRowStyle("Sheet1", row, row, Style2)
+			f.SetRowHeight("Sheet1", row, 20)
+
+			// 空一行
+			row += 1
+			f.MergeCell("Sheet1", fmt.Sprintf("A%d", row), fmt.Sprintf("F%d", row))
+			f.SetRowStyle("Sheet1", row, row, Style1)
+			f.SetCellValue("Sheet1", fmt.Sprintf("A%d", row), "")
+
+		}
+	}
+
+	// 保存文件
+	if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
+		fmt.Println(err)
+	}
+	var url string
+	//// 上传 OSS
+	nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
+	url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
+	if !is {
+		c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
+		c.ServeJSON()
+		return
+	}
+	//删除目录
+	err := os.Remove("ofile/" + filename + ".xlsx")
+	if err != nil {
+		logs.Error(lib.FuncName(), err)
+	}
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
+	c.ServeJSON()
+	return
+}
 
 func StockOut_Edit_StockMonth(T_date string, T_depot_id int, allProductList []int) error {
 	date, _ := lib.DateStrToTime(T_date)

+ 4 - 1
routers/Stock.go

@@ -26,6 +26,7 @@ func init() {
 		beego.NSRouter("/Edit", &controllers.StockController{}, "*:StockIn_Edit"),                             // 修改入库
 		beego.NSRouter("/Del", &controllers.StockController{}, "*:StockIn_Del"),                               // 删除入库
 		beego.NSRouter("/Excel", &controllers.StockController{}, "*:StockIn_Excel"),                           // 导出入库
+		beego.NSRouter("/Excel_Batch", &controllers.StockController{}, "*:StockIn_Excel_Batch"),               // 批量导出入库
 
 	)
 	stockOut := beego.NewNamespace("/StockOut",
@@ -37,7 +38,9 @@ func init() {
 		beego.NSRouter("/Edit_Delivery", &controllers.StockController{}, "*:StockOut_Edit_Delivery"),           // 修改发货单
 		beego.NSRouter("/Edit", &controllers.StockController{}, "*:StockOut_Edit"),                             // 修改出库
 		beego.NSRouter("/Del", &controllers.StockController{}, "*:StockOut_Del"),                               // 删除出库
-		beego.NSRouter("/Excel", &controllers.StockController{}, "*:StockOut_Excel"),                           // 导出出库
+		beego.NSRouter("/Excel", &controllers.StockController{}, "*:StockOut_Excel"),
+		beego.NSRouter("/Excel_Batch", &controllers.StockController{}, "*:StockOut_Excel_Batch"), // 批量导出入库
+		// 导出出库
 	)
 	beego.AddNamespace(device, stock, stockIn, stockOut)
 }