|
@@ -9,7 +9,6 @@ import (
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
- "github.com/xuri/excelize/v2"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
)
|
|
@@ -33,10 +32,10 @@ func ProductPlan(r *GinRouter) {
|
|
r.POST("/plan/delete/:id", DelProductPlan)
|
|
r.POST("/plan/delete/:id", DelProductPlan)
|
|
|
|
|
|
// 下载部件打印单
|
|
// 下载部件打印单
|
|
- r.GET("/bill/plan/download", DownLoadPlan)
|
|
|
|
|
|
+ // r.GET("/bill/plan/download", DownLoadPlan)
|
|
|
|
|
|
// 生产成本表
|
|
// 生产成本表
|
|
- r.GET("/plan/cost/download", DownLoadPlanCost)
|
|
|
|
|
|
+ // r.GET("/plan/cost/download", DownLoadPlanCost)
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -45,150 +44,155 @@ type SupplierPlanCost struct {
|
|
SupplierId string
|
|
SupplierId string
|
|
}
|
|
}
|
|
|
|
|
|
-func DownLoadPlanCost(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
- _planId := c.Query("id")
|
|
|
|
- supplierId := c.Query("supplierId")
|
|
|
|
- planId, err := primitive.ObjectIDFromHex(_planId)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, errors.New("planId错误")
|
|
|
|
- }
|
|
|
|
- supplierPlanCost := &SupplierPlanCost{}
|
|
|
|
-
|
|
|
|
- plan := model.ProductPlan{}
|
|
|
|
- found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
- CollectName: repo.CollectionProductPlan,
|
|
|
|
- Query: repo.Map{"_id": planId},
|
|
|
|
- }, &plan)
|
|
|
|
- if !found || err != nil {
|
|
|
|
- return nil, errors.New("数据未找到")
|
|
|
|
- }
|
|
|
|
- supplierPlanCost.ProductPlan = &plan
|
|
|
|
- supplierPlanCost.SupplierId = supplierId
|
|
|
|
-
|
|
|
|
- f := excelize.NewFile()
|
|
|
|
- index := f.NewSheet("Sheet1")
|
|
|
|
- f.SetActiveSheet(index)
|
|
|
|
- f.SetDefaultFont("宋体")
|
|
|
|
- planCostExcel := NewPlanCostExcel(f)
|
|
|
|
- planCostExcel.Title = fmt.Sprintf("生产成本表(%s)%d盒", plan.Name, plan.Total)
|
|
|
|
- planCostExcel.Content = supplierPlanCost
|
|
|
|
- planCostExcel.Draws()
|
|
|
|
-
|
|
|
|
- c.Header("Content-Type", "application/octet-stream")
|
|
|
|
- c.Header("Content-Disposition", "attachment; filename="+"planCost.xlsx")
|
|
|
|
- c.Header("Content-Transfer-Encoding", "binary")
|
|
|
|
-
|
|
|
|
- err = f.Write(c.Writer)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
- return nil, nil
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
- _planId := c.Query("id")
|
|
|
|
- compId := c.Query("compId")
|
|
|
|
- planId, err := primitive.ObjectIDFromHex(_planId)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, errors.New("planId错误")
|
|
|
|
- }
|
|
|
|
- plan := model.ProductPlan{}
|
|
|
|
- found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
- CollectName: repo.CollectionProductPlan,
|
|
|
|
- Query: repo.Map{"_id": planId},
|
|
|
|
- }, &plan)
|
|
|
|
- if !found || err != nil {
|
|
|
|
- return nil, errors.New("数据未找到")
|
|
|
|
- }
|
|
|
|
- // 获取部件单据
|
|
|
|
- curComp := &model.PackComponent{}
|
|
|
|
- for _, comp := range plan.Pack.Components {
|
|
|
|
- if comp.Id == compId {
|
|
|
|
- curComp = comp
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if curComp.Id == "" {
|
|
|
|
- return nil, errors.New("该组件不存在")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 获取bill
|
|
|
|
- if len(curComp.Stages) == 0 {
|
|
|
|
- return nil, errors.New("该组件数据不存在")
|
|
|
|
- }
|
|
|
|
- f := excelize.NewFile()
|
|
|
|
- // Create a new sheet.
|
|
|
|
- index := f.NewSheet("Sheet1")
|
|
|
|
- f.SetActiveSheet(index)
|
|
|
|
- f.SetDefaultFont("宋体")
|
|
|
|
-
|
|
|
|
- companyName := getCompanyName(apictx)
|
|
|
|
-
|
|
|
|
- offset := 0
|
|
|
|
- for _, mat := range curComp.Stages {
|
|
|
|
- // 采购单
|
|
|
|
- _purchaseId := mat.BillId
|
|
|
|
- purchaseId, err := primitive.ObjectIDFromHex(_purchaseId)
|
|
|
|
- if err == nil {
|
|
|
|
- purchase := model.PurchaseBill{}
|
|
|
|
- found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
- CollectName: repo.CollectionBillPurchase,
|
|
|
|
- Query: repo.Map{"_id": purchaseId},
|
|
|
|
- }, &purchase)
|
|
|
|
- fmt.Println(purchase)
|
|
|
|
- if found {
|
|
|
|
- var billExcel *PurchaseBillExcel
|
|
|
|
- if len(purchase.Paper) > 0 {
|
|
|
|
- billExcel = NewPurchaseBill(f)
|
|
|
|
- }
|
|
|
|
- if billExcel == nil {
|
|
|
|
- return nil, errors.New("数据未找到")
|
|
|
|
- }
|
|
|
|
- billExcel.Content = &purchase
|
|
|
|
- billExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
|
|
|
|
- billExcel.Offset = offset
|
|
|
|
- billExcel.Draws()
|
|
|
|
-
|
|
|
|
- offset += 15
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // if len(mat.Crafts) > 0 {
|
|
|
|
- // for _, carft := range mat.Crafts {
|
|
|
|
- // // 加工单
|
|
|
|
- // _produceId := carft.BillId
|
|
|
|
- // produceId, err := primitive.ObjectIDFromHex(_produceId)
|
|
|
|
- // if err == nil {
|
|
|
|
- // produce := model.ProduceBill{}
|
|
|
|
- // found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
- // CollectName: repo.CollectionBillProduce,
|
|
|
|
- // Query: repo.Map{"_id": produceId},
|
|
|
|
- // }, &produce)
|
|
|
|
- // if found {
|
|
|
|
- // produceExcel := NewProduceBill(f)
|
|
|
|
- // produceExcel.Content = &produce
|
|
|
|
- // produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
|
|
|
|
- // //设置对应的数据
|
|
|
|
- // produceExcel.Offset = offset
|
|
|
|
- // produceExcel.Draws()
|
|
|
|
-
|
|
|
|
- // offset += 15
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- c.Header("Content-Type", "application/octet-stream")
|
|
|
|
- c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
|
|
|
|
- c.Header("Content-Transfer-Encoding", "binary")
|
|
|
|
-
|
|
|
|
- err = f.Write(c.Writer)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return nil, nil
|
|
|
|
-}
|
|
|
|
|
|
+// func DownLoadPlanCost(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
+// _planId := c.Query("id")
|
|
|
|
+// supplierId := c.Query("supplierId")
|
|
|
|
+// planId, err := primitive.ObjectIDFromHex(_planId)
|
|
|
|
+// if err != nil {
|
|
|
|
+// return nil, errors.New("planId错误")
|
|
|
|
+// }
|
|
|
|
+// supplierPlanCost := &SupplierPlanCost{}
|
|
|
|
+
|
|
|
|
+// plan := model.ProductPlan{}
|
|
|
|
+// found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
+// CollectName: repo.CollectionProductPlan,
|
|
|
|
+// Query: repo.Map{"_id": planId},
|
|
|
|
+// }, &plan)
|
|
|
|
+// if !found || err != nil {
|
|
|
|
+// return nil, errors.New("数据未找到")
|
|
|
|
+// }
|
|
|
|
+// supplierPlanCost.ProductPlan = &plan
|
|
|
|
+// supplierPlanCost.SupplierId = supplierId
|
|
|
|
+
|
|
|
|
+// f := excelize.NewFile()
|
|
|
|
+// index := f.NewSheet("Sheet1")
|
|
|
|
+// f.SetActiveSheet(index)
|
|
|
|
+// f.SetDefaultFont("宋体")
|
|
|
|
+// planCostExcel := NewPlanCostExcel(f)
|
|
|
|
+// planCostExcel.Title = fmt.Sprintf("生产成本表(%s)%d盒", plan.Name, plan.Total)
|
|
|
|
+// planCostExcel.Content = supplierPlanCost
|
|
|
|
+// planCostExcel.Draws()
|
|
|
|
+
|
|
|
|
+// c.Header("Content-Type", "application/octet-stream")
|
|
|
|
+// c.Header("Content-Disposition", "attachment; filename="+"planCost.xlsx")
|
|
|
|
+// c.Header("Content-Transfer-Encoding", "binary")
|
|
|
|
+
|
|
|
|
+// err = f.Write(c.Writer)
|
|
|
|
+// if err != nil {
|
|
|
|
+// return nil, err
|
|
|
|
+// }
|
|
|
|
+// return nil, nil
|
|
|
|
+
|
|
|
|
+// }
|
|
|
|
+// func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
+// _planId := c.Query("id")
|
|
|
|
+// compId := c.Query("compId")
|
|
|
|
+// planId, err := primitive.ObjectIDFromHex(_planId)
|
|
|
|
+// if err != nil {
|
|
|
|
+// return nil, errors.New("planId错误")
|
|
|
|
+// }
|
|
|
|
+// plan := model.ProductPlan{}
|
|
|
|
+// found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
+// CollectName: repo.CollectionProductPlan,
|
|
|
|
+// Query: repo.Map{"_id": planId},
|
|
|
|
+// }, &plan)
|
|
|
|
+// if !found || err != nil {
|
|
|
|
+// return nil, errors.New("数据未找到")
|
|
|
|
+// }
|
|
|
|
+// // 获取部件单据
|
|
|
|
+// curComp := &model.PackComponent{}
|
|
|
|
+// for _, comp := range plan.Pack.Components {
|
|
|
|
+// if comp.Id == compId {
|
|
|
|
+// curComp = comp
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if curComp.Id == "" {
|
|
|
|
+// return nil, errors.New("该组件不存在")
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// // 获取bill
|
|
|
|
+// if len(curComp.Stages) == 0 {
|
|
|
|
+// return nil, errors.New("该组件数据不存在")
|
|
|
|
+// }
|
|
|
|
+// f := excelize.NewFile()
|
|
|
|
+// // Create a new sheet.
|
|
|
|
+// index := f.NewSheet("Sheet1")
|
|
|
|
+// f.SetActiveSheet(index)
|
|
|
|
+// f.SetDefaultFont("宋体")
|
|
|
|
+
|
|
|
|
+// companyName := getCompanyName(apictx)
|
|
|
|
+
|
|
|
|
+// offset := 0
|
|
|
|
+// for _, mat := range curComp.Stages {
|
|
|
|
+// // 采购单
|
|
|
|
+// _purchaseId := mat.BillId
|
|
|
|
+// purchaseId, err := primitive.ObjectIDFromHex(_purchaseId)
|
|
|
|
+// if err == nil {
|
|
|
|
+// purchase := model.PurchaseBill{}
|
|
|
|
+// found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
+// CollectName: repo.CollectionBillPurchase,
|
|
|
|
+// Query: repo.Map{"_id": purchaseId},
|
|
|
|
+// }, &purchase)
|
|
|
|
+// fmt.Println(purchase)
|
|
|
|
+// if found {
|
|
|
|
+// var billExcel IPurchBill
|
|
|
|
+// if purchase.Process != nil {
|
|
|
|
+// billExcel = NewProcessBill(f)
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// if len(purchase.Paper) > 0 {
|
|
|
|
+// billExcel = NewPurchaseBill(f)
|
|
|
|
+// }
|
|
|
|
+// // purchaseExcel := NewPurchaseBill(f)
|
|
|
|
+// billExcel.SetContent(&purchase)
|
|
|
|
+// billExcel.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
|
|
|
|
+// billExcel.SetOffset(offset)
|
|
|
|
+// // billExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
|
|
|
|
+// //设置对应的数据
|
|
|
|
+// // purchaseExcel.Offset = offset
|
|
|
|
+// billExcel.Draws()
|
|
|
|
+
|
|
|
|
+// offset += 15
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// // if len(mat.Crafts) > 0 {
|
|
|
|
+// // for _, carft := range mat.Crafts {
|
|
|
|
+// // // 加工单
|
|
|
|
+// // _produceId := carft.BillId
|
|
|
|
+// // produceId, err := primitive.ObjectIDFromHex(_produceId)
|
|
|
|
+// // if err == nil {
|
|
|
|
+// // produce := model.ProduceBill{}
|
|
|
|
+// // found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
+// // CollectName: repo.CollectionBillProduce,
|
|
|
|
+// // Query: repo.Map{"_id": produceId},
|
|
|
|
+// // }, &produce)
|
|
|
|
+// // if found {
|
|
|
|
+// // produceExcel := NewProduceBill(f)
|
|
|
|
+// // produceExcel.Content = &produce
|
|
|
|
+// // produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
|
|
|
|
+// // //设置对应的数据
|
|
|
|
+// // produceExcel.Offset = offset
|
|
|
|
+// // produceExcel.Draws()
|
|
|
|
+
|
|
|
|
+// // offset += 15
|
|
|
|
+// // }
|
|
|
|
+
|
|
|
|
+// // }
|
|
|
|
+// // }
|
|
|
|
+// // }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// c.Header("Content-Type", "application/octet-stream")
|
|
|
|
+// c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
|
|
|
|
+// c.Header("Content-Transfer-Encoding", "binary")
|
|
|
|
+
|
|
|
|
+// err = f.Write(c.Writer)
|
|
|
|
+// if err != nil {
|
|
|
|
+// return nil, err
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// return nil, nil
|
|
|
|
+// }
|
|
|
|
|
|
// 创建生产计划
|
|
// 创建生产计划
|
|
func CreateProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
func CreateProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|