animeic 2 anos atrás
pai
commit
64aaf687d6
7 arquivos alterados com 178 adições e 166 exclusões
  1. 1 1
      boxcost/api/bill-product.go
  2. 151 147
      boxcost/api/plan.go
  3. 5 1
      boxcost/api/router.go
  4. 4 3
      boxcost/api/supplier.go
  5. 1 1
      boxcost/db/db.go
  6. 15 12
      boxcost/db/model/bill.go
  7. 1 1
      comm

+ 1 - 1
boxcost/api/bill-product.go

@@ -14,7 +14,7 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
-// 单据管理
+// 成品采购单据管理
 func BillProduct(r *GinRouter) {
 
 	// 创建单据

+ 151 - 147
boxcost/api/plan.go

@@ -9,7 +9,6 @@ import (
 	"time"
 
 	"github.com/gin-gonic/gin"
-	"github.com/xuri/excelize/v2"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
@@ -33,10 +32,10 @@ func ProductPlan(r *GinRouter) {
 	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
 }
 
-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) {

+ 5 - 1
boxcost/api/router.go

@@ -36,11 +36,15 @@ func RegRouters(svc *Service) {
 	// 生产计划管理
 	ProductPlan(boxcost)
 
-	// 单据管理
+	//材料采购单据管理
 	Bill(boxcost)
 
+	//加工单据
 	BillProduce(boxcost)
 
+	//成品采购
+	BillProduct(boxcost)
+
 	//设置
 	Setting(boxcost)
 

+ 4 - 3
boxcost/api/supplier.go

@@ -92,9 +92,10 @@ func GetSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
-	// if cate,ok := query["category"];ok{
-	// 	delete(query,"category")
-	// }
+	if cate, ok := query["category"]; ok {
+		delete(query, "category")
+		query["categorys"] = bson.M{"$in": []string{cate.(string)}}
+	}
 
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionSupplier,

+ 1 - 1
boxcost/db/db.go

@@ -35,7 +35,7 @@ func (db *MongoDB) GetOrCreateDatabase(name string) *mongo.Database {
 }
 
 func NewMongoDB(bus *comm.NatsBus) *MongoDB {
-	inst, err := bus.NewMongoDBFromConfig("box-mongo")
+	inst, err := bus.NewMongoDBFromConfigDev("box-mongo")
 	if err != nil {
 		panic(err)
 	}

+ 15 - 12
boxcost/db/model/bill.go

@@ -163,6 +163,8 @@ type ProduceBill struct {
 	// 序号
 	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
 }
+
+// 成品采购单据
 type ProductBill struct {
 	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
 	PackId     primitive.ObjectID `bson:"packId,omitempty" json:"packId"`
@@ -200,38 +202,39 @@ type ProductBill struct {
 	//商品名字
 	ProductName string `bson:"productName,omitempty" json:"productName"`
 
-	//纸张类采购
+	//有哪些成品采购数据
 	Products []*ProductBillData `bson:"products,omitempty" json:"products"`
 
 	// 序号
 	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
 
-	Remark string `bson:"remark,omitempty" json:"remark"`
+	//备注
+	Remark string `bson:"serialNumber,omitempty" json:"serialNumber"`
 }
 
-// 成品采购单
+// 工艺生产数
 type ProductBillData struct {
 	//名字
-	Name     string `bson:"name,omitempty" json:"name"`
-	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+	Name string `bson:"name,omitempty" json:"name"`
 
-	Type string `bson:"type,omitempty" json:"type"`
 	//规格(质量要求)
 	Norm string `bson:"norm,omitempty" json:"norm"`
 
+	//单价 数量
+	Price float64 `bson:"price,omitempty" json:"price"`
+
 	// 下单数量
 	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
-	// 单位
-	Unit string `bson:"unit,omitempty" json:"unit"`
-	//单价
-	Price float64 `bson:"price,omitempty" json:"price"`
-	// 金额
+
 	//备注
 	Remark string `bson:"remark,omitempty" json:"remark"`
 
 	//交货时间
 	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
 
-	//确认收货数量
+	// 确认收货数量
 	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	//纸张
+	Unit string `bson:"unit,omitempty" json:"unit"`
 }

+ 1 - 1
comm

@@ -1 +1 @@
-Subproject commit 7001469cabb57b8ac042bbca0e8d45786415f257
+Subproject commit 03721d7b9d3dd23b9cffdf9388845c89ace40049