123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- package controllers
- import (
- "Medical_ERP/common/global"
- _ "Medical_ERP/common/response"
- "Medical_ERP/dto"
- "Medical_ERP/models"
- "Medical_ERP/services"
- "Medical_ERP/utils"
- "errors"
- "fmt"
- "github.com/signintech/gopdf"
- "github.com/xuri/excelize/v2"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
- "os"
- "time"
- )
- type SalesController struct {
- BaseController
- }
- // SalesList 销售管理
- // @Summary 销售管理
- // @Description 销售管理
- // @Tags 销售管理
- // @Param body body dto.SalesPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /sales/list [post]
- // @Security Bearer
- func (c SalesController) SalesList() {
- s := services.Sales{}
- reqData := dto.SalesPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.SalesList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- // SalesExcel 二类销售清单
- // @Summary 二类销售清单
- // @Description 二类销售清单
- // @Tags 销售管理
- // @Param body body dto.SalesPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /sales/excel [post]
- // @Security Bearer
- func (c SalesController) SalesExcel() {
- s := services.Sales{}
- reqData := dto.SalesPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- deptName := beegouser.GetDeptName(c.Ctx)
- list, _, err := s.SalesListExcel(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- f := excelize.NewFile() // 设置单元格的值
- StyleTitle, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- f.MergeCell("Sheet1", "A1", "N1")
- f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
- f.SetRowHeight("Sheet1", 1, 50)
- var interval string
- if len(reqData.StartDate) > 0 && len(reqData.EndDate) > 0 {
- interval = fmt.Sprintf("%s至%s", reqData.StartDate, reqData.EndDate)
- }
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s%s销售清单", deptName, interval))
- // 这里设置表头
- f.SetCellValue("Sheet1", "A2", "日期")
- f.SetCellValue("Sheet1", "B2", "购货单位")
- f.SetCellValue("Sheet1", "C2", "品种")
- f.SetCellValue("Sheet1", "D2", "生产企业")
- f.SetCellValue("Sheet1", "E2", "规格")
- f.SetCellValue("Sheet1", "F2", "剂型")
- f.SetCellValue("Sheet1", "G2", "批号")
- f.SetCellValue("Sheet1", "H2", "数量")
- f.SetCellValue("Sheet1", "I2", "单位")
- f.SetCellValue("Sheet1", "J2", "单价")
- f.SetCellValue("Sheet1", "K2", "金额")
- //f.SetCellValue("Sheet1", "L2", "销售单价")
- //f.SetCellValue("Sheet1", "M2", "销售金额")
- f.SetCellValue("Sheet1", "L2", "批准文号")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 12)
- f.SetColWidth("Sheet1", "B", "C", 15)
- f.SetColWidth("Sheet1", "C", "E", 23)
- f.SetColWidth("Sheet1", "E", "F", 15)
- f.SetColWidth("Sheet1", "F", "G", 12)
- f.SetColWidth("Sheet1", "H", "I", 10)
- f.SetColWidth("Sheet1", "J", "L", 12)
- line := 2
- // 循环写入数据
- for _, v := range list {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v["date"])
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v["receiving_unit"])
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldProductName])
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldEnterpriseName])
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldSpecName])
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v[models.FieldDosageFormName])
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v[models.FieldBatchNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v["quantity"])
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v[models.FieldUnitName])
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["unit_price"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), utils.ToFloat64(v["money"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("L%d", line), v[models.FieldApprovalNumber])
- }
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, 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},
- },
- })
- f.SetCellStyle("Sheet1", "A2", "N2", Style1)
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, 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},
- },
- })
- f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("N%d", line), Style2)
- filename := "二类销售清单" + time.Now().Format("20060102150405") + ".xlsx"
- // 保存文件
- if err := f.SaveAs("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // SalesReportExcel 销售报表
- // @Summary 销售报表
- // @Description 销售报表
- // @Tags 销售管理
- // @Param body body dto.SalesPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /sales/excel [post]
- // @Security Bearer
- func (c SalesController) SalesReportExcel() {
- s := services.Sales{}
- reqData := dto.SalesPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- deptName := beegouser.GetDeptName(c.Ctx)
- list, err := s.SalesReportList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- f := excelize.NewFile() // 设置单元格的值
- StyleTitle, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- f.MergeCell("Sheet1", "A1", "G1")
- f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
- f.SetRowHeight("Sheet1", 1, 50)
- var interval string
- if len(reqData.StartDate) > 0 && len(reqData.EndDate) > 0 {
- interval = fmt.Sprintf("%s至%s", reqData.StartDate, reqData.EndDate)
- }
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s%s销售报表", deptName, interval))
- // 这里设置表头
- f.SetRowHeight("Sheet1", 2, 25)
- f.SetCellValue("Sheet1", "A2", "品种")
- f.SetCellValue("Sheet1", "B2", "生产企业")
- f.SetCellValue("Sheet1", "C2", "规格")
- f.SetCellValue("Sheet1", "D2", "数量")
- f.SetCellValue("Sheet1", "E2", "单位")
- f.SetCellValue("Sheet1", "F2", "单价")
- f.SetCellValue("Sheet1", "G2", "金额")
- //f.SetCellValue("Sheet1", "H2", "销售单价")
- //f.SetCellValue("Sheet1", "I2", "销售金额")
- //f.SetCellValue("Sheet1", "J2", "利润金额")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "C", 27)
- f.SetColWidth("Sheet1", "D", "E", 10)
- f.SetColWidth("Sheet1", "F", "G", 12)
- line := 2
- // 循环写入数据
- for _, v := range list {
- line++
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v[models.FieldProductName])
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v[models.FieldEnterpriseName])
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldSpecName])
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), utils.ToInt(v["total"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldUnitName])
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), utils.ToFloat64(v["unit_price"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), utils.ToFloat64(v["money"]))
- //f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToFloat64(v["sales_unit_price"]))
- //f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), utils.ToFloat64(v["sales_money"]))
- //f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["profit_money"]))
- }
- line += 1
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "合计")
- f.SetCellFormula("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("SUM(D3:D%d)", line-1))
- f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", line), fmt.Sprintf("SUM(G3:G%d)", line-1))
- //f.SetCellFormula("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("SUM(I3:I%d)", line-1))
- //f.SetCellFormula("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("SUM(J3:J%d)", line-1))
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 14, 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},
- },
- })
- f.SetCellStyle("Sheet1", "A2", "G2", Style1)
- Style2, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, 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},
- },
- })
- f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("G%d", line), Style2)
- filename := "销售报表" + time.Now().Format("20060102150405") + ".xlsx"
- // 保存文件
- if err := f.SaveAs("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // SalesOrderList 销售订单
- // @Summary 销售订单
- // @Description 销售订单
- // @Tags 销售管理
- // @Param body body dto.SalesOrderPageReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /sales/order_list [post]
- // @Security Bearer
- func (c SalesController) SalesOrderList() {
- s := services.Sales{}
- reqData := dto.SalesOrderPageReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- deptId := beegouser.GetDeptId(c.Ctx)
- list, count, err := s.SalesOrderList(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- c.PageOK(list, int(count), reqData.GetPageIndex(), reqData.GetPageSize(), "查询成功")
- }
- func (c SalesController) SalesStockOutExcel(reqData dto.SalesStockOutExcelReq) {
- s := services.Sales{}
- deptId := beegouser.GetDeptId(c.Ctx)
- list, err := s.SalesStockOutExcel(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- f := excelize.NewFile() // 设置单元格的值
- StyleTitle, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
- Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
- })
- f.MergeCell("Sheet1", "A1", "K1")
- f.SetRowStyle("Sheet1", 1, 1, StyleTitle)
- f.SetRowHeight("Sheet1", 1, 40)
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s二类出库单", beegouser.GetDeptName(c.Ctx)))
- // 这里设置表头
- f.SetRowHeight("Sheet1", 2, 25)
- f.MergeCell("Sheet1", "A2", "C2")
- f.MergeCell("Sheet1", "D2", "F2")
- f.MergeCell("Sheet1", "G2", "G2")
- f.MergeCell("Sheet1", "H2", "K2")
- f.SetRowHeight("Sheet1", 3, 40)
- f.SetCellValue("Sheet1", "A2", "购货单位:"+reqData.ReceivingUnit)
- f.SetCellValue("Sheet1", "D2", "下单日期:"+reqData.Date)
- //f.SetCellValue("Sheet1", "G2", "编号:")
- //f.SetCellValue("Sheet1", "I2", "第1联,共3联(第1联,库房处留存)")
- f.SetCellValue("Sheet1", "A3", "品种")
- f.SetCellValue("Sheet1", "B3", "剂型")
- f.SetCellValue("Sheet1", "C3", "规格")
- f.SetCellValue("Sheet1", "D3", "生产企业")
- f.SetCellValue("Sheet1", "E3", "批号")
- f.SetCellValue("Sheet1", "F3", "失效日期")
- f.SetCellValue("Sheet1", "G3", "批准文号")
- f.SetCellValue("Sheet1", "H3", "数量")
- f.SetCellValue("Sheet1", "I3", "单位")
- f.SetCellValue("Sheet1", "J3", "销售单价")
- f.SetCellValue("Sheet1", "K3", "销售金额")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "B", 15)
- f.SetColWidth("Sheet1", "B", "B", 6)
- f.SetColWidth("Sheet1", "C", "C", 15)
- f.SetColWidth("Sheet1", "D", "D", 10)
- f.SetColWidth("Sheet1", "E", "G", 12)
- f.SetColWidth("Sheet1", "H", "I", 6)
- f.SetColWidth("Sheet1", "J", "K", 10)
- line := 3
- var money float64
- // 循环写入数据
- for _, v := range list {
- line++
- //f.SetRowHeight("Sheet1", line, 25)
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), v[models.FieldProductName])
- f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v[models.FieldDosageFormName])
- f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v[models.FieldSpecName])
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v[models.FieldEnterpriseName])
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v[models.FieldBatchNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v[models.FieldExpiryDate])
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v[models.FieldApprovalNumber])
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), utils.ToInt(v["quantity"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), v[models.FieldUnitName])
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), utils.ToFloat64(v["sales_unit_price"]))
- f.SetCellValue("Sheet1", fmt.Sprintf("K%d", line), utils.ToFloat64(v["sales_money"]))
- money += utils.ToFloat64(v["sales_money"])
- }
- line += 1
- f.SetRowHeight("Sheet1", line, 25)
- line += 1
- f.SetRowHeight("Sheet1", line, 25)
- f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("D%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("K%d", line))
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("整单合计金额(小写):¥%.2f元", money))
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), fmt.Sprintf("整单合计金额(发货人签名:):%s", utils.AmountConvert(money, true)))
- line += 1
- f.SetRowHeight("Sheet1", line, 25)
- f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("C%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("E%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("I%d", line))
- f.MergeCell("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("K%d", line))
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("开票日期:%s", time.Now().Format("2006年01月02日")))
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), fmt.Sprintf("开票员:%s", reqData.Drawer))
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("发货人:%s 财务:%s", reqData.Consigner, reqData.Finance))
- f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), fmt.Sprintf("收货人:%s", reqData.Consignee))
- Style0, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 10, Family: "宋体", Bold: true},
- Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true},
- })
- f.SetCellStyle("Sheet1", "A2", "K2", Style0)
- Style1, _ := f.NewStyle(
- &excelize.Style{
- Font: &excelize.Font{Size: 12, 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},
- },
- })
- f.SetCellStyle("Sheet1", "A3", "K3", Style1)
- Style2, _ := 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},
- },
- })
- f.SetCellStyle("Sheet1", "A4", fmt.Sprintf("k%d", line-1), Style2)
- f.SetCellStyle("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("k%d", line), Style0)
- filename := "二类出库单" + time.Now().Format("20060102150405") + ".xlsx"
- // 保存文件
- if err := f.SaveAs("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- func (c SalesController) SalesStockOutPdf(reqData dto.SalesStockOutExcelReq) {
- s := services.Sales{}
- deptId := beegouser.GetDeptId(c.Ctx)
- list, err := s.SalesStockOutExcel(&reqData, deptId)
- if err != nil {
- c.Error(500, err, err.Error())
- return
- }
- cols := []float64{65, 29.5, 65, 53, 59, 59, 59, 29.5, 29.5, 53, 53}
- header := []string{"品种", "剂型", "规格", "生产企业", "批号", "失效日期", "批准文号", "数量", "单位", "销售单价", "销售金额"}
- rows := [][]string{}
- money := 0.0
- for _, row := range list {
- temp := []string{}
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldProductName]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldDosageFormName]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldSpecName]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldEnterpriseName]))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldBatchNumber]))
- temp = append(temp, fmt.Sprintf("%s", utils.ToDate(row[models.FieldExpiryDate])))
- if row[models.FieldApprovalNumber] == nil {
- temp = append(temp, "")
- } else {
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldApprovalNumber]))
- }
- temp = append(temp, fmt.Sprintf("%d", utils.ToInt(row["quantity"])))
- temp = append(temp, fmt.Sprintf("%s", row[models.FieldUnitName]))
- temp = append(temp, fmt.Sprintf("%.2f", utils.ToFloat64(row["sales_unit_price"])))
- temp = append(temp, fmt.Sprintf("%.2f", utils.ToFloat64(row["sales_money"])))
- rows = append(rows, temp)
- money += utils.ToFloat64(row["sales_money"])
- }
- rows = append(rows, []string{"", "", "", "", "", "", "", "", "", "", ""})
- pdf := &gopdf.GoPdf{}
- pdf.Start(gopdf.Config{PageSize: gopdf.Rect{W: 595.28, H: 841.89}})
- pdf.SetMarginTop(20)
- pdf.SetMarginBottom(40)
- pdf.AddPage()
- pdf.AddTTFFont("simsun", "static/fonts/MiSans-Medium.ttf")
- pdf.SetFont("simsun", "", 22)
- titleStr := fmt.Sprintf("%s二类出库单", beegouser.GetDeptName(c.Ctx))
- titleWd, _ := pdf.MeasureTextWidth(titleStr)
- pdf.SetX((595 / 2) - (titleWd / 2))
- pdf.SetY(40)
- pdf.Text(titleStr)
- curx, y := 20., 70.
- pdf.SetXY(curx, y)
- pdf.SetFont("simsun", "", 11)
- pdf.Text(fmt.Sprintf("购货单位:%s", reqData.ReceivingUnit))
- pdf.SetXY(curx+cols[0]+cols[1]+cols[2], y)
- pdf.Text(fmt.Sprintf("下单日期:%s", reqData.Date))
- //pdf.Text(titleX*2+20, y, fmt.Sprintf("编号:"))
- //pdf.Text(titleX*3, y, "第1联,共3联(第1联,库房处留存)")
- h := 25.0
- pdf.SetFont("simsun", "", 12)
- x := curx
- y += 10
- pdf.SetXY(curx, y)
- for i := 0; i < len(header); i++ {
- utils.RectFillColorMultiCell(pdf, header[i], 11, x, y, cols[i], h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += cols[i]
- }
- pdf.SetFont("simsun", "", 10)
- y += h
- pdf.SetXY(curx, y)
- h = 20.0
- for _, row := range rows {
- y = pdf.GetY()
- x = curx
- height := h
- for j, txt := range row {
- lineTexts, _ := pdf.SplitText(txt, cols[j])
- //lineHt := h * float64(len(lineTexts))
- if len(lineTexts) > 1 {
- lineTexts, _ = pdf.SplitText(txt, cols[j]-4)
- lineHt := h * float64(len(lineTexts)) * 0.8
- if lineHt > height {
- height = lineHt
- }
- }
- }
- for i, txt := range row {
- width := cols[i]
- utils.RectFillColorMultiCell(pdf, txt, 9, x, y, width, height, 0, 0, 0, gopdf.Center, gopdf.Middle)
- x += width
- }
- pdf.SetNewY(y+height, height)
- }
- y = pdf.GetY()
- pdf.SetXY(curx, y)
- width1 := cols[0] + cols[1] + cols[2] + cols[3]
- utils.RectFillColor(pdf, fmt.Sprintf("整单合计金额(小写):¥%.2f元", money), 9, curx, y, width1, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- width2 := cols[4] + cols[5] + cols[6] + cols[7] + cols[8] + cols[9] + cols[10]
- utils.RectFillColor(pdf, fmt.Sprintf("整单合计金额(大写):%s", utils.AmountConvert(money, true)), 9, curx+width1, y, width2, h, 0, 0, 0, gopdf.Center, gopdf.Middle)
- y += h
- y += 15
- pdf.SetNewY(y, h+15)
- pdf.SetX(curx)
- pdf.Text(fmt.Sprintf("开票日期:%s", time.Now().Format("2006年01月02日")))
- width := cols[0] + cols[1] + cols[2]
- curx += width
- pdf.SetX(curx)
- pdf.Text(fmt.Sprintf("开票员:%s", reqData.Drawer))
- width = cols[3] + cols[4]
- curx += width
- pdf.SetX(curx)
- pdf.Text(fmt.Sprintf("发货人:%s 财务:%s", reqData.Consigner, reqData.Finance))
- width = cols[5] + cols[6] + cols[7] + cols[8]
- curx += width
- pdf.SetX(curx)
- pdf.Text(fmt.Sprintf("收货人:%s", reqData.Consignee))
- filename := "二类出库单" + time.Now().Format("20060102150405") + ".pdf"
- // 保存文件
- if err = pdf.WritePdf("ofile/" + filename); err != nil {
- fmt.Println(err)
- }
- defer func() {
- os.Remove("ofile/" + filename)
- }()
- // 返回生成的 Excel 文件
- c.Ctx.Output.Download("ofile/" + filename)
- }
- // SalesStockOutExport 二类出库单
- // @Summary 二类出库单
- // @Description 二类出库单
- // @Tags 销售管理
- // @Param body body dto.SalesStockOutExcelReq true "body"
- // @Success 200 {object} response.Page "{"code": 200, "data": [...]}"
- // @Router /sales/order_list [post]
- // @Security Bearer
- func (c SalesController) SalesStockOutExport() {
- reqData := dto.SalesStockOutExcelReq{}
- if err := c.ParseAndValidate(&c.Ctx.Input.RequestBody, &reqData); err != nil {
- err = errors.New("解析表单数据异常")
- c.Error(global.ParseFormErr, err, err.Error())
- return
- }
- if reqData.Type == "excel" {
- c.SalesStockOutExcel(reqData)
- }
- if reqData.Type == "pdf" {
- c.SalesStockOutPdf(reqData)
- }
- }
|