animeic 2 years ago
parent
commit
de8abd3da2

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


+ 4 - 1
boxcost/api/api.go

@@ -6,6 +6,7 @@ import (
 	"box-cost/db/repo"
 	"context"
 	"fmt"
+	"net/http"
 
 	"github.com/gin-contrib/cors"
 	"github.com/gin-contrib/sessions"
@@ -48,7 +49,9 @@ func NewHttpService(app *conf.AppConf, dbMongo *db.MongoDB, redisClient *redis.C
 
 	store := cookie.NewStore([]byte("spu3d-server"))
 	engine.Use(sessions.Sessions("dcsession", store))
-	engine.Static("/public", "static")
+	// engine.Static("/public", "static")
+	// engine.Static("/signature", "static")
+	engine.StaticFS("/boxcost/public", http.Dir("signature"))
 	config := cors.DefaultConfig()
 	// config.AllowOrigins == []string{"http://google.com", "http://facebook.com"}
 	config.AllowAllOrigins = true

+ 2 - 5
boxcost/api/bill-process-excel.go

@@ -172,10 +172,7 @@ func (b *ProcessBillExcel) drawTableContent() error {
 	process := b.Content.Process
 	if len(process) > 0 {
 		for _, ps := range process {
-			// 不是订单工序
-			if !ps.IsBill {
-				continue
-			}
+
 			deliveryTime := ps.DeliveryTime.Local().Format("2006-01-02")
 			confirmCount := "-"
 			realAmount := "-"
@@ -292,7 +289,7 @@ func (b *ProcessBillExcel) drawTableSignature() error {
 		imageCells := []string{imageCell1, imageCell2}
 		if len(b.Signatures) > 0 {
 			for k, sign := range b.Signatures {
-				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Url, sign.Format)
+				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Path, sign.Format)
 
 			}
 		}

+ 1 - 1
boxcost/api/bill-produce-excel.go

@@ -293,7 +293,7 @@ func (b *ProduceBillExcel) drawTableSignature() error {
 		imageCells := []string{imageCell1, imageCell2}
 		if len(b.Signatures) > 0 {
 			for k, sign := range b.Signatures {
-				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Url, sign.Format)
+				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Path, sign.Format)
 
 			}
 		}

+ 1 - 13
boxcost/api/bill-purchase-excel.go

@@ -343,7 +343,7 @@ func (b *PurchaseBillExcel) drawTableSignature() error {
 		imageCells := []string{imageCell1, imageCell2}
 		if len(b.Signatures) > 0 {
 			for k, sign := range b.Signatures {
-				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Url, sign.Format)
+				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Path, sign.Format)
 
 			}
 		}
@@ -418,15 +418,3 @@ func (b *PurchaseBillExcel) SetSignatures(sign []*model.Signature) {
 	b.Signatures = sign
 
 }
-
-type IPurchBill interface {
-	PrintPurchType() string
-	Draws()
-	SetContent(*model.PurchaseBill)
-	SetTitle(string)
-	SetSignatures([]*model.Signature)
-}
-
-// func ExeclDraw(ipurch IPurchBill) {
-// 	ipurch.Draws()
-// }

+ 11 - 0
boxcost/api/iFace.go

@@ -0,0 +1,11 @@
+package api
+
+import "box-cost/db/model"
+
+type IPurchBill interface {
+	PrintPurchType() string
+	Draws()
+	SetContent(*model.PurchaseBill)
+	SetTitle(string)
+	SetSignatures([]*model.Signature)
+}

+ 98 - 16
boxcost/api/plan-cost-excel.go

@@ -18,6 +18,7 @@ type PlanCostExcel struct {
 	SheetName string
 
 	AlignCenterStyle int
+	Row              int
 
 	// Content *model.ProductPlan
 	Content *SupplierPlanCost
@@ -308,10 +309,12 @@ func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
 func (b *PlanCostExcel) drawAllContent() error {
 	row := b.Offset + 4
 	comps := b.Content.Pack.Components
+	var totalPlanPrice float32 = 0.00
 	var confirmTotalPlanPrice float64 = 0.00
 	if len(comps) > 0 {
 		for _, comp := range comps {
 			var totalConfirmRealPrice float64 = 0.00
+			var totalOrderRealPrice float32 = 0.00
 			if len(comp.Mats) > 0 {
 				startRow := row
 				for _, mat := range comp.Mats {
@@ -334,6 +337,7 @@ func (b *PlanCostExcel) drawAllContent() error {
 					orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
 					b.FormatToEmpty(&orderPrice)
 					orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
+					totalOrderRealPrice += mat.Supplier.OrderRealPrice
 					b.FormatToEmpty(&orderRealPrice)
 					// 实际金额
 					confirmPrice := mat.Supplier.OrderPrice * float64(mat.ConfirmCount)
@@ -369,6 +373,8 @@ func (b *PlanCostExcel) drawAllContent() error {
 
 							// 实际金额
 							confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
+
+							totalOrderRealPrice += craft.Supplier.OrderRealPrice
 							totalConfirmRealPrice += confirmCraftPrice
 							confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
 							b.FormatToEmpty(&confirmCraftRealPrice)
@@ -391,28 +397,104 @@ func (b *PlanCostExcel) drawAllContent() error {
 				}
 				b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
 			}
+
+			// 实际
+			confirmTotalPlanPrice += totalConfirmRealPrice
+
+			// 预算
+			totalPlanPrice += totalOrderRealPrice
 		}
+	}
+	if len(b.Content.Process) > 0 {
 		// 生产汇总金额
 		startACell := fmt.Sprintf("%s%d", "A", row)
-		endKCell := fmt.Sprintf("%s%d", "K", row)
-		LCell := fmt.Sprintf("%s%d", "L", row)
-		MCell := fmt.Sprintf("%s%d", "M", row)
-		b.Excel.MergeCell(b.SheetName, startACell, endKCell)
-		b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
+		endMCell := fmt.Sprintf("%s%d", "K", row)
+		b.Excel.MergeCell(b.SheetName, startACell, endMCell)
+		b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
+		b.Excel.SetCellValue(b.SheetName, startACell, "其他")
+		row++
+		// 工序 外箱 手工费 表头
+		var drawCol = func(startCell, endCell string, value string) error {
+			left1Cell := fmt.Sprintf("%s%d", startCell, row)
+			left2Cell := fmt.Sprintf("%s%d", endCell, row+1)
+
+			err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
+			if err != nil {
+				return err
+			}
+			err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
+			if err != nil {
+				return err
+			}
 
-		// 生产预算汇总
-		b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
-		planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice)
-		b.FormatToEmpty(&planTotalPrice)
-		b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
+			return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
+		}
+
+		drawCol("B", "C", "材料/工序")
+		drawCol("D", "D", "供应商名称")
+		drawCol("E", "G", "规格")
+		drawCol("H", "H", "单位")
+		drawCol("I", "I", "下单数量")
+		drawCol("J", "J", "实际数量")
+		drawCol("K", "K", "单价")
+		drawCol("L", "L", "预算金额")
+		drawCol("M", "M", "实际金额")
+		row++
+
+		var DrawRow = func(rowIndex int, values ...string) {
+			charas := []string{"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
+			for i, c := range charas {
+				v := ""
+				if i < len(values) {
+					v = values[i]
+				}
+				b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
+				val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
+				b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
+				b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
+			}
+		}
+
+		for _, ps := range b.Content.Process {
+			count := fmt.Sprintf("%d", ps.Count)
+			confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
+			price := fmt.Sprintf("%.2f", ps.Price)
+			b.FormatToEmpty(&price)
+			budgetAmountf := ps.Price * float64(ps.Count)
+			budgetAmount := fmt.Sprintf("%.2f", budgetAmountf)
+			b.FormatToEmpty(&budgetAmount)
+			realAmountf := ps.Price * float64(ps.ConfirmCount)
+			realAmount := fmt.Sprintf("%.2f", realAmountf)
+			b.FormatToEmpty(&realAmount)
+			confirmTotalPlanPrice += realAmountf
+			totalPlanPrice += float32(budgetAmountf)
+
+			DrawRow(row, ps.Name, ps.Supplier, ps.Norm, ps.Unit, count, confirmCount, price, budgetAmount, realAmount)
+			row++
+		}
 
-		// 生产实际汇总
-		b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
-		planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
-		b.FormatToEmpty(&planConfirmTotalPrice)
-		b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
 	}
+	// 生产汇总金额
+	startACell := fmt.Sprintf("%s%d", "A", row)
+	endKCell := fmt.Sprintf("%s%d", "K", row)
+	LCell := fmt.Sprintf("%s%d", "L", row)
+	MCell := fmt.Sprintf("%s%d", "M", row)
+	b.Excel.MergeCell(b.SheetName, startACell, endKCell)
+	b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
+	b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
+
+	// 生产预算汇总
+	b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
+	// planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice) //
+	planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice) //
+	b.FormatToEmpty(&planTotalPrice)
+	b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
+
+	// 生产实际汇总
+	b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
+	planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
+	b.FormatToEmpty(&planConfirmTotalPrice)
+	b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
 
 	return nil
 }

+ 0 - 9
boxcost/api/plan.go

@@ -74,15 +74,6 @@ func DownLoadPlanCost(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	planCostExcel.Content = supplierPlanCost
 	planCostExcel.Draws()
 
-	// // 另存为
-	// // _ = os.MkdirAll("excel", os.ModePerm)
-	// // filename1 := time.Now().Format("20060102150405") + ".xlsx"
-	// filename1 := "生产成本表.xlsx"
-	// err = f.SaveAs(filename1)
-	// if err != nil {
-	// 	return nil, err
-	// }
-
 	c.Header("Content-Type", "application/octet-stream")
 	c.Header("Content-Disposition", "attachment; filename="+"planCost.xlsx")
 	c.Header("Content-Transfer-Encoding", "binary")

+ 2 - 2
boxcost/api/process.go

@@ -18,7 +18,7 @@ func Process(r *GinRouter) {
 			return entity, nil
 		},
 		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
-			return &model.PriceCalc{}
+			return &model.Process{}
 		},
 
 		JWT: true,
@@ -26,6 +26,6 @@ func Process(r *GinRouter) {
 			process := entity.(*model.Process)
 			process.UpdateTime = time.Now()
 		},
-		SearchProject: []string{"name", "unit", "norm", "price", "type", "remark"},
+		SearchProject: []string{"name", "unit", "norm", "price", "category", "remark"},
 	})
 }

+ 7 - 2
boxcost/api/signature.go

@@ -140,7 +140,7 @@ func SignatureUpload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	// 保存图片
 	os.Mkdir("signature/", 0777)
-	pathFileName := fmt.Sprintf("signature/%s%s", randName(6), handle.Filename)
+	pathFileName := fmt.Sprintf("%s%s", randName(6), handle.Filename)
 	saveFile, err := os.OpenFile(pathFileName, os.O_WRONLY|os.O_CREATE, 0666)
 	if err != nil {
 		return nil, err
@@ -149,5 +149,10 @@ func SignatureUpload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	defer uploadFile.Close()
 	defer saveFile.Close()
 
-	return pathFileName, nil
+	// http://127.0.0.1:18088/boxcost/public/
+	out := map[string]string{
+		"url":  fmt.Sprintf("http://127.0.0.1:18088/boxcost/public/%s", pathFileName),
+		"path": fmt.Sprintf("signature/%s", pathFileName),
+	}
+	return out, nil
 }

+ 12 - 16
boxcost/db/model/process.go

@@ -8,19 +8,13 @@ import (
 
 // 工序管理 用于选择模板
 type Process struct {
-	Id   primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Name string             `bson:"name,omitempty" json:"name"`
-	Unit string             `bson:"unit,omitempty" json:"unit"`
-	Norm string             `bson:"norm,omitempty" json:"norm"`
-
-	Price float64 `bson:"price,omitempty" json:"price"`
-	// 分类 外箱 礼盒。。。
-	Type string `bson:"type,omitempty" json:"type"`
-
-	// 金额
-	Amount float64 `bson:"amount,omitempty" json:"amount"`
-
-	IsBill bool `bson:"isBill,omitempty" json:"isBill"`
+	Id    primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name  string             `bson:"name,omitempty" json:"name"`
+	Unit  string             `bson:"unit,omitempty" json:"unit"`
+	Norm  string             `bson:"norm,omitempty" json:"norm"`
+	Price float64            `bson:"price,omitempty" json:"price"`
+	// 分类
+	Category string `bson:"category,omitempty" json:"category"`
 
 	// 单个工艺备注
 	Remark     string    `bson:"remark,omitempty" json:"remark"`
@@ -31,7 +25,11 @@ type Process struct {
 // 算到采购单里面
 type ProcessBill struct {
 	//名字
-	Name string `bson:"name,omitempty" json:"name"`
+	Name     string `bson:"name,omitempty" json:"name"`
+	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+
+	//确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
 
 	//名字
 	Type string `bson:"type,omitempty" json:"type"`
@@ -44,11 +42,9 @@ type ProcessBill struct {
 	//单价
 	Price float64 `bson:"price,omitempty" json:"price"`
 	// 金额
-	Amount float64 `bson:"amount,omitempty" json:"amount"`
 	//备注
 	Remark string `bson:"remark,omitempty" json:"remark"`
 
-	IsBill bool `bson:"isBill,omitempty" json:"isBill"`
 	//交货时间
 	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
 }

+ 1 - 0
boxcost/db/model/signature.go

@@ -10,6 +10,7 @@ import (
 type Signature struct {
 	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
 	Url        string             `bson:"url,omitempty" json:"url"`
+	Path       string             `bson:"path,omitempty" json:"path"`
 	Format     string             `bson:"format,omitempty" json:"format"`
 	Sort       int                `bson:"sort,omitempty" json:"sort"`
 	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`