animeic 2 éve
szülő
commit
fd40da4b92

BIN
boxcost/GFAtrK截图 2022-11-22 18-04-25.png


+ 4 - 7
boxcost/api/bill-produce-excel.go

@@ -3,7 +3,6 @@ package api
 import (
 	"box-cost/db/model"
 	"fmt"
-	"strconv"
 
 	"github.com/xuri/excelize/v2"
 )
@@ -194,11 +193,9 @@ func (b *ProduceBillExcel) drawTableContent() error {
 
 			confirmCount := "-"
 			realAmount := "-"
-			price, err := strconv.ParseFloat(produce.Price, 64)
-			if err != nil {
-				price = 0.00
-			}
-
+			price := produce.Price
+			priceStr := fmt.Sprintf("%.2f", price)
+			b.FormatToEmpty(&priceStr)
 			// 预算金额
 			budgetAmount := fmt.Sprintf("%.2f", float64(produce.Count)*price)
 			b.FormatToEmpty(&budgetAmount)
@@ -214,7 +211,7 @@ func (b *ProduceBillExcel) drawTableContent() error {
 			}
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.Count), confirmCount, produce.Price, budgetAmount, realAmount, deliveryTime, produce.Remark)
+			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.Count), confirmCount, priceStr, budgetAmount, realAmount, deliveryTime, produce.Remark)
 			row++
 			b.Row++
 		}

+ 24 - 2
boxcost/api/bill-produce.go

@@ -6,6 +6,7 @@ import (
 	"box-cost/log"
 	"errors"
 	"fmt"
+	"strconv"
 	"time"
 
 	"github.com/gin-gonic/gin"
@@ -211,12 +212,33 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		}
 	}
 
+	bill.UpdateTime = time.Now()
+	result, err := repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, bill.Id.Hex(), &bill)
+
+	// 计算结算价格
 	if bill.Status == "complete" {
 		bill.CompleteTime = time.Now()
+		// 计算结算数量和结算金额
+		produce := &model.ProduceBill{}
+		repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+			CollectName: repo.CollectionBillProduce,
+			Query:       repo.Map{"_id": bill.Id},
+		}, produce)
+		if len(produce.Produces) > 0 {
+			// 取数组最后一个元素的下单数为整个流程结算的基础数
+			last := produce.Produces[len(produce.Produces)-1]
+			baseSet := last.ConfirmCount
+			baseNumer := baseSet * last.BatchSize
+			for _, pd := range produce.Produces {
+				pd.SetCount = baseNumer / pd.BatchSize
+				setAmount := float64(pd.SetCount) * pd.Price
+				pd.SetAmount, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", setAmount), 64)
+			}
+		}
+		repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, bill.Id.Hex(), produce)
 	}
 
-	bill.UpdateTime = time.Now()
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, bill.Id.Hex(), &bill)
+	return result, err
 }
 
 // 删除单据

+ 5 - 6
boxcost/api/report-produce-excel.go

@@ -3,7 +3,6 @@ package api
 import (
 	"box-cost/db/model"
 	"fmt"
-	"strconv"
 
 	"github.com/xuri/excelize/v2"
 )
@@ -196,10 +195,10 @@ func (b *ReportProduceExcel) drawTableContent() error {
 
 			confirmCount := "-"
 			realAmount := "-"
-			price, err := strconv.ParseFloat(produce.Price, 64)
-			if err != nil {
-				price = 0.00
-			}
+			price := produce.Price
+
+			priceStr := fmt.Sprintf("%.2f", price)
+			b.FormatToEmpty(&priceStr)
 
 			// 预算金额
 			budgetAmount := fmt.Sprintf("%.2f", float64(produce.Count)*price)
@@ -218,7 +217,7 @@ func (b *ReportProduceExcel) drawTableContent() error {
 			b.RealCount += float64(b.Content.ConfirmCount) * price
 
 			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.Count), confirmCount, produce.Price, budgetAmount, realAmount, deliveryTime, produce.Remark)
+			DrawRow(row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.Count), confirmCount, priceStr, budgetAmount, realAmount, deliveryTime, produce.Remark)
 			row++
 			b.Row++
 		}

+ 58 - 0
boxcost/api/supplier-price.go

@@ -148,6 +148,64 @@ func SupplierPrice(r *GinRouter) {
 		SearchProject: []string{"price", "supplierId", "productId", "updateTime", "_id"},
 	})
 
+	CreateCRUD(r, "/supplier/process", &CRUDOption{
+		Collection: repo.CollectionSupplierCraftprice,
+		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+			entity := &model.SupplierPrice{}
+			c.ShouldBindJSON(entity)
+
+			if entity.ProductId == primitive.NilObjectID || entity.SupplierId == primitive.NilObjectID {
+				return nil, fmt.Errorf("产品ID或供应商Id不能为空")
+			}
+
+			curr := &model.SupplierPrice{}
+			ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+				CollectName: repo.CollectionSupplierProcessprice,
+				Query:       repo.Map{"productId": entity.ProductId, "supplierId": entity.SupplierId},
+				Project:     []string{"_id"},
+			}, curr)
+			if err != nil {
+				return nil, err
+			}
+			if ok {
+				return nil, fmt.Errorf("该工序已经在供应列表里面了")
+			}
+
+			entity.CreateTime = time.Now()
+			entity.UpdateTime = time.Now()
+			return entity, nil
+		},
+		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
+			return &model.SupplierPrice{}
+		},
+		JWT: true,
+		OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}) {
+			calc := entity.(*model.SupplierPrice)
+			calc.UpdateTime = time.Now()
+		},
+		SearchFilter: func(c *gin.Context, apictx *ApiSession, query map[string]interface{}) map[string]interface{} {
+			if query["supplierId"] != nil {
+				query["supplierId"], _ = primitive.ObjectIDFromHex(query["supplierId"].(string))
+			}
+			return query
+		},
+		SearchPostProcess: func(page *repo.PageResult, c *gin.Context, apictx *ApiSession, query map[string]interface{}) (interface{}, error) {
+			//查询材料对应的材料信息
+			for _, ps := range page.List {
+				_id, _ := ps["productId"].(primitive.ObjectID)
+
+				process := &model.Process{}
+				repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+					CollectName: repo.CollectionProcess,
+					Query:       repo.Map{"_id": _id},
+				}, process)
+				ps["processInfo"] = process
+			}
+			return page, nil
+		},
+		SearchProject: []string{"price", "supplierId", "productId", "updateTime", "_id"},
+	})
+
 	//添加计价方案
 	SupplierCalcPriceColl := "supplier-calcprice"
 	CreateCRUD(r, "/supplier/calc", &CRUDOption{

+ 18 - 0
boxcost/api/supplier.go

@@ -194,6 +194,24 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		}
 	}
 
+	if query["processId"] != nil {
+		processId := query["processId"].(string)
+		if len(processId) < 1 {
+			return nil, fmt.Errorf("processId(string)为空")
+		}
+		id, _ := primitive.ObjectIDFromHex(processId)
+		ok, list := repo.RepoSeachDocsMap(apictx.CreateRepoCtx(), &repo.DocsSearchOptions{
+			CollectName: repo.CollectionSupplierProcessprice,
+			Query:       repo.Map{"productId": id},
+			Project:     []string{"supplierId"},
+		})
+		if !ok {
+			return emtyPage, nil
+		}
+
+		listOut = list
+	}
+
 	//获取供应商列表
 	suppliers := []primitive.ObjectID{}
 	suppliersMap := map[string]bool{}

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

@@ -85,9 +85,9 @@ type ProduceBillData struct {
 	Norm string `bson:"norm,omitempty" json:"norm"`
 
 	//单价 数量
-	Price string `bson:"price,omitempty" json:"price"`
+	Price float64 `bson:"price,omitempty" json:"price"`
 
-	Price2 string `bson:"price2,omitempty" json:"price2"`
+	Price2 float64 `bson:"price2,omitempty" json:"price2"`
 
 	//数量
 	Count int `bson:"count,omitempty" json:"count"`
@@ -106,6 +106,19 @@ type ProduceBillData struct {
 
 	//交货时间
 	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+
+	// todo
+	// 单位成品数
+	BatchSize int `bson:"batchSize,omitempty" json:"batchSize"`
+
+	// 确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	// 结算数量
+	SetCount int `bson:"setCount,omitempty" json:"setCount"`
+
+	// 结算金额
+	SetAmount float64 `bson:"setAmount,omitempty" json:"setAmount"`
 }
 
 type ProduceBill struct {

+ 7 - 5
boxcost/db/repo/repo.go

@@ -20,6 +20,7 @@ type RepoSession struct {
 const (
 	CollectionMaterial      = "material"
 	CollectionCraft         = "craft"
+	CollectionProcess       = "process"
 	CollectionSupplier      = "supplier"
 	CollectionSupplierPrice = "supplier-price"
 	CollectionPack          = "pack"
@@ -27,11 +28,12 @@ const (
 	CollectionBillPurchase  = "bill-purchase"
 	CollectionBillProduce   = "bill-produce"
 
-	CollectionSupplierMatprice   = "supplier-mats"
-	CollectionSupplierCraftprice = "supplier-crafts"
-	CollectionIncrement          = "increment"
-	CollectionSignature          = "signature"
-	CollectionUsers              = "users"
+	CollectionSupplierMatprice     = "supplier-mats"
+	CollectionSupplierCraftprice   = "supplier-crafts"
+	CollectionSupplierProcessprice = "supplier-process"
+	CollectionIncrement            = "increment"
+	CollectionSignature            = "signature"
+	CollectionUsers                = "users"
 )
 
 type Map map[string]interface{}