|
@@ -3,14 +3,19 @@ package controllers
|
|
|
import (
|
|
|
"ERP_storage/Nats/NatsServer"
|
|
|
"ERP_storage/conf"
|
|
|
+ "ERP_storage/logs"
|
|
|
"ERP_storage/models/Account"
|
|
|
"ERP_storage/models/Purchase"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/adapter/orm"
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
|
|
|
"gogs.baozhida.cn/zoie/ERP_libs/lib"
|
|
|
"math"
|
|
|
+ "net/url"
|
|
|
+ "os"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type PurchaseController struct {
|
|
@@ -270,6 +275,9 @@ func (c *PurchaseController) Purchase_Edit() {
|
|
|
clos = append(clos, "T_approver")
|
|
|
}
|
|
|
if T_State > 0 {
|
|
|
+ if T_State == Purchase.NotPass {
|
|
|
+ T_State = Purchase.WaitAudit
|
|
|
+ }
|
|
|
purchase.T_State = T_State
|
|
|
clos = append(clos, "T_State")
|
|
|
}
|
|
@@ -320,3 +328,331 @@ func (c *PurchaseController) Purchase_Del() {
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 下载采购申请
|
|
|
+func (c *PurchaseController) Purchase_Excel() {
|
|
|
+
|
|
|
+ T_id, _ := c.GetInt("T_id")
|
|
|
+
|
|
|
+ o := orm.NewOrm()
|
|
|
+ PurchaseDao := Purchase.NewPurchase(o)
|
|
|
+ purchase, err := PurchaseDao.Read_Purchase_ById(T_id)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+ detail := Purchase.PurchaseToPurchase_Detail(purchase)
|
|
|
+
|
|
|
+ f := excelize.NewFile() //设置单元格值
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ Style1, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 16, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
|
|
|
+ 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},
|
|
|
+ },
|
|
|
+ })
|
|
|
+ Style2, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 15, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "left", 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},
|
|
|
+ },
|
|
|
+ })
|
|
|
+ Style3, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 13, 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},
|
|
|
+ },
|
|
|
+ })
|
|
|
+ Style4, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 13, 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.MergeCell("Sheet1", "A1", "I1")
|
|
|
+ f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%d宝智达冷链采购申请", time.Now().Year()))
|
|
|
+ f.SetCellStyle("Sheet1", "A1", "I1", Style1)
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", "A2", "E2")
|
|
|
+ date, _ := lib.DateStrToTime(detail.T_date)
|
|
|
+ f.SetCellValue("Sheet1", "A2", fmt.Sprintf("申请时间:%s", date.Format("2006年01月02日")))
|
|
|
+ f.MergeCell("Sheet1", "F2", "I2")
|
|
|
+ f.SetCellValue("Sheet1", "F2", fmt.Sprintf("申请人:%-10s负责人审批:", detail.T_uuid_name))
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", "A3", "E3")
|
|
|
+ f.SetCellValue("Sheet1", "A3", "执行时间:")
|
|
|
+ f.MergeCell("Sheet1", "F3", "I3")
|
|
|
+ f.SetCellValue("Sheet1", "F3", fmt.Sprintf("执行部门:%-15s执行人:", ""))
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", "A4", "E4")
|
|
|
+ f.SetCellValue("Sheet1", "A4", fmt.Sprintf("审批人:%s", detail.T_approver_name))
|
|
|
+ f.MergeCell("Sheet1", "F4", "I4")
|
|
|
+ approver_date := ""
|
|
|
+ if len(detail.T_approver_date) > 0 {
|
|
|
+ date2, _ := lib.DateStrToTime(detail.T_approver_date)
|
|
|
+ approver_date = date2.Format("2006年01月02日")
|
|
|
+ }
|
|
|
+ f.SetCellValue("Sheet1", "F4", fmt.Sprintf("审批时间:%s", approver_date))
|
|
|
+
|
|
|
+ f.SetCellStyle("Sheet1", "A2", "I4", Style2)
|
|
|
+ f.SetRowHeight("Sheet1", 1, 40)
|
|
|
+ height := 30.0
|
|
|
+ f.SetRowHeight("Sheet1", 2, height)
|
|
|
+ f.SetRowHeight("Sheet1", 3, height)
|
|
|
+ f.SetRowHeight("Sheet1", 4, height)
|
|
|
+ f.SetRowHeight("Sheet1", 5, height)
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", "A5", "I5")
|
|
|
+ f.SetCellValue("Sheet1", "A5", "申请采购明细")
|
|
|
+ f.SetCellStyle("Sheet1", "A5", "I5", Style1)
|
|
|
+
|
|
|
+ f.SetCellValue("Sheet1", "A6", "序号")
|
|
|
+ f.SetCellValue("Sheet1", "B6", "名称")
|
|
|
+ f.SetCellValue("Sheet1", "C6", "型号")
|
|
|
+ f.SetCellValue("Sheet1", "D6", "规格")
|
|
|
+ f.SetCellValue("Sheet1", "E6", "数量")
|
|
|
+ f.SetCellValue("Sheet1", "F6", "参考网址")
|
|
|
+ f.SetCellValue("Sheet1", "G6", "需求")
|
|
|
+ f.SetCellValue("Sheet1", "H6", "备注")
|
|
|
+ f.SetCellValue("Sheet1", "I6", "采购金额")
|
|
|
+ // 这里设置表头
|
|
|
+ f.SetCellStyle("Sheet1", "A6", "H6", Style3)
|
|
|
+ f.SetRowHeight("Sheet1", 2, 25)
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ f.SetColWidth("Sheet1", "A", "A", 6)
|
|
|
+ f.SetColWidth("Sheet1", "B", "B", 12)
|
|
|
+ f.SetColWidth("Sheet1", "C", "C", 10)
|
|
|
+ f.SetColWidth("Sheet1", "D", "D", 10)
|
|
|
+ f.SetColWidth("Sheet1", "E", "E", 6)
|
|
|
+ f.SetColWidth("Sheet1", "F", "F", 30)
|
|
|
+ f.SetColWidth("Sheet1", "G", "G", 12)
|
|
|
+ f.SetColWidth("Sheet1", "H", "H", 15)
|
|
|
+ f.SetColWidth("Sheet1", "I", "I", 15)
|
|
|
+
|
|
|
+ line := 6
|
|
|
+ for i, v := range detail.T_Detail {
|
|
|
+ line++
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_name)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_model)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_spec)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_quantity)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_reference_site)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_demand)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_remark)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("%.2f", v.T_unit_price*float32(v.T_quantity)))
|
|
|
+ }
|
|
|
+ line++
|
|
|
+ f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("H%d", line))
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "合计")
|
|
|
+ f.SetCellFormula("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("SUM(I7:I%d)", line-1))
|
|
|
+ f.SetCellStyle("Sheet1", "A6", fmt.Sprintf("I%d", line), Style4)
|
|
|
+
|
|
|
+ timeStr := time.Now().Format("20060102150405")
|
|
|
+ fileName := fmt.Sprintf("%d宝智达冷链采购申请%v.xlsx", time.Now().Year(), timeStr)
|
|
|
+ filePath := "ofile/" + fileName
|
|
|
+ // 保存文件
|
|
|
+ if err = f.SaveAs(filePath); err != nil {
|
|
|
+ logs.Error("保存文件失败:", err)
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath)
|
|
|
+ }()
|
|
|
+ c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
|
+ c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
|
+ c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
|
|
|
+ c.Ctx.Output.Download(filePath, fileName)
|
|
|
+}
|
|
|
+
|
|
|
+// 下载采购统计
|
|
|
+func (c *PurchaseController) Purchase_Stat_Excel() {
|
|
|
+
|
|
|
+ T_uuid := c.GetString("T_uuid")
|
|
|
+ T_dept := c.GetString("T_dept")
|
|
|
+
|
|
|
+ T_start_date := c.GetString("T_start_date") // 开始时间
|
|
|
+ T_end_date := c.GetString("T_end_date") // 结束时间
|
|
|
+
|
|
|
+ T_state, _ := c.GetInt("T_state")
|
|
|
+
|
|
|
+ userList, _ := NatsServer.Read_User_List_All()
|
|
|
+ Account.Read_User_All_Map(userList)
|
|
|
+
|
|
|
+ PurchaseDao := Purchase.NewPurchase(orm.NewOrm())
|
|
|
+ R_List, _ := PurchaseDao.Read_Purchase_Stat(T_dept, T_uuid, "", T_state, true, T_start_date, T_end_date, 0, 9999)
|
|
|
+
|
|
|
+ f := excelize.NewFile() //设置单元格值
|
|
|
+ // 这里设置表头ÒÒ
|
|
|
+ Style1, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 20, Family: "宋体"},
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
|
|
|
+ })
|
|
|
+ Style2, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 15, 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},
|
|
|
+ },
|
|
|
+ Fill: excelize.Fill{Type: "pattern", Color: []string{"D9D9D9"}, Pattern: 1},
|
|
|
+ })
|
|
|
+ Style3, _ := f.NewStyle(
|
|
|
+ &excelize.Style{
|
|
|
+ Font: &excelize.Font{Size: 15, 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.MergeCell("Sheet1", "A1", "M1")
|
|
|
+ f.SetCellValue("Sheet1", "A1", "资金一览表")
|
|
|
+ f.SetCellStyle("Sheet1", "A1", "I1", Style1)
|
|
|
+
|
|
|
+ // 写入表头
|
|
|
+ headers := []string{"序号", "采购物品", "规格", "单价", "数量", "实际金额", "合计金额", "用途", "采购申请人", "采购申请时间", "是否已有发票", "报销上报时间", "备注"}
|
|
|
+ for col, header := range headers {
|
|
|
+ cell := fmt.Sprintf("%c%d", rune('A'+col), 2)
|
|
|
+ f.SetCellValue("Sheet1", cell, header)
|
|
|
+ }
|
|
|
+ // 这里设置表头
|
|
|
+ f.SetCellStyle("Sheet1", "A2", "M2", Style2)
|
|
|
+ f.SetRowHeight("Sheet1", 2, 25)
|
|
|
+
|
|
|
+ colsWidth := []float64{6, 12, 10, 10, 6, 30, 12, 15, 15, 15, 15, 15, 15}
|
|
|
+
|
|
|
+ for col, width := range colsWidth {
|
|
|
+ cell := fmt.Sprintf("%c", rune('A'+col))
|
|
|
+ f.SetColWidth("Sheet1", cell, cell, width)
|
|
|
+ }
|
|
|
+ line := 2
|
|
|
+ for i, purchase := range R_List {
|
|
|
+ // 写入数据
|
|
|
+ startRow := line + 1
|
|
|
+ for _, v := range purchase.T_Detail {
|
|
|
+ line++
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_name)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_model)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_unit_price)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_quantity)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_amount)
|
|
|
+ if len(purchase.T_Detail) == 1 {
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_amount)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), purchase.T_uuid_name)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), purchase.T_date)
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), purchase.T_remark)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(purchase.T_Detail) > 1 {
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", fmt.Sprintf("G%d", startRow), fmt.Sprintf("G%d", line))
|
|
|
+ f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", startRow), fmt.Sprintf("SUM(F%d:F%d)", startRow, line))
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", fmt.Sprintf("I%d", startRow), fmt.Sprintf("I%d", line))
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("I%d", startRow), purchase.T_uuid_name)
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", fmt.Sprintf("J%d", startRow), fmt.Sprintf("J%d", line))
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("J%d", startRow), purchase.T_date)
|
|
|
+
|
|
|
+ f.MergeCell("Sheet1", fmt.Sprintf("M%d", startRow), fmt.Sprintf("M%d", line))
|
|
|
+ f.SetCellValue("Sheet1", fmt.Sprintf("M%d", startRow), purchase.T_remark)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("M%d", line), Style3)
|
|
|
+
|
|
|
+ timeStr := time.Now().Format("20060102150405")
|
|
|
+ fileName := fmt.Sprintf("%d资金一览表%v.xlsx", time.Now().Year(), timeStr)
|
|
|
+ filePath := "ofile/" + fileName
|
|
|
+ // 保存文件
|
|
|
+ if err := f.SaveAs(filePath); err != nil {
|
|
|
+ logs.Error("保存文件失败:", err)
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ os.Remove(filePath)
|
|
|
+ }()
|
|
|
+ c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
|
|
|
+ c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
|
|
|
+ c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
|
|
|
+ c.Ctx.Output.Download(filePath, fileName)
|
|
|
+}
|
|
|
+
|
|
|
+func (c *PurchaseController) User_List() {
|
|
|
+ var r_jsons lib.R_JSONS
|
|
|
+ // 分页参数 初始化
|
|
|
+ page, _ := c.GetInt("page")
|
|
|
+ if page < 1 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ page_z, _ := c.GetInt("page_z")
|
|
|
+ if page_z < 1 {
|
|
|
+ page_z = conf.Page_size
|
|
|
+ }
|
|
|
+
|
|
|
+ T_name := c.GetString("T_name")
|
|
|
+
|
|
|
+ PurchaseDao := Purchase.NewPurchase(orm.NewOrm())
|
|
|
+
|
|
|
+ uuidList := PurchaseDao.Read_T_uuid_List()
|
|
|
+ if len(uuidList) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var U_List []userlibs.User
|
|
|
+ for _, user := range R_List {
|
|
|
+ U_List = append(U_List, user)
|
|
|
+ }
|
|
|
+
|
|
|
+ r_jsons.Num = R_cnt
|
|
|
+ r_jsons.Data = U_List
|
|
|
+ r_jsons.Page = page
|
|
|
+ r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|