|
@@ -3,6 +3,7 @@ package api
|
|
|
import (
|
|
|
"box-cost/db/model"
|
|
|
"fmt"
|
|
|
+ "strconv"
|
|
|
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
)
|
|
@@ -18,13 +19,17 @@ type ProduceBillExcel struct {
|
|
|
|
|
|
AlignCenterStyle int
|
|
|
|
|
|
- Content *model.ProduceBill
|
|
|
+ Content *model.ProduceBill
|
|
|
+ Signatures []*model.Signature
|
|
|
}
|
|
|
|
|
|
func (b *ProduceBillExcel) drawTitle() error {
|
|
|
+ // 设置外边距
|
|
|
+ marginLeft := excelize.PageMarginLeft(0.15)
|
|
|
+ b.Excel.SetPageMargins(b.SheetName, marginLeft)
|
|
|
tileIndex := b.Offset + 1
|
|
|
startCell := fmt.Sprintf("A%d", tileIndex)
|
|
|
- err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("I%d", tileIndex))
|
|
|
+ err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("L%d", tileIndex))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -78,7 +83,7 @@ func (b *ProduceBillExcel) drawSubTitles() error {
|
|
|
|
|
|
var drawRight = func(rowIndex int, value string) error {
|
|
|
right1Cell := fmt.Sprintf("F%d", rowIndex)
|
|
|
- err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("I%d", rowIndex))
|
|
|
+ err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("L%d", rowIndex))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -155,9 +160,13 @@ func (b *ProduceBillExcel) drawTableTitle() error {
|
|
|
drawCol("D", "来纸尺寸")
|
|
|
drawCol("E", "印刷尺寸")
|
|
|
drawCol("F", "数量")
|
|
|
- drawCol("H", "交货时间")
|
|
|
- drawCol("I", "备注")
|
|
|
- drawCol2("G", "单价", "元/张")
|
|
|
+ drawCol("G", "完成数量")
|
|
|
+ drawCol2("H", "单价", "元/张")
|
|
|
+ drawCol("I", "预算金额")
|
|
|
+ drawCol("J", "实际金额")
|
|
|
+ drawCol("K", "交货时间")
|
|
|
+ drawCol("L", "备注")
|
|
|
+
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -165,7 +174,7 @@ func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
row := b.Offset + 7
|
|
|
|
|
|
var DrawRow = func(rowIndex int, values ...string) {
|
|
|
- charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
|
|
|
+ charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
|
|
|
for i, c := range charas {
|
|
|
v := ""
|
|
|
if i < len(values) {
|
|
@@ -182,8 +191,30 @@ func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
produces := b.Content.Produces
|
|
|
if len(produces) > 0 {
|
|
|
for _, produce := range produces {
|
|
|
+
|
|
|
+ confirmCount := "-"
|
|
|
+ realAmount := "-"
|
|
|
+ price, err := strconv.ParseFloat(produce.Price, 64)
|
|
|
+ if err != nil {
|
|
|
+ price = 0.00
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预算金额
|
|
|
+ budgetAmount := fmt.Sprintf("%.2f", float64(produce.Count)*price)
|
|
|
+ b.FormatToEmpty(&budgetAmount)
|
|
|
+
|
|
|
+ if b.Content.Status == "complete" {
|
|
|
+ // 实际完成数
|
|
|
+ confirmCount = fmt.Sprintf("%d", b.Content.ConfirmCount)
|
|
|
+ b.FormatToEmpty(&confirmCount)
|
|
|
+
|
|
|
+ // 实际金额
|
|
|
+ realAmount = fmt.Sprintf("%.2f", float64(b.Content.ConfirmCount)*price)
|
|
|
+ b.FormatToEmpty(&realAmount)
|
|
|
+ }
|
|
|
+
|
|
|
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), produce.Price, deliveryTime, produce.Remark)
|
|
|
+ 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)
|
|
|
row++
|
|
|
}
|
|
|
}
|
|
@@ -192,7 +223,7 @@ func (b *ProduceBillExcel) drawTableContent() error {
|
|
|
}
|
|
|
|
|
|
func (b *ProduceBillExcel) drawTableFooter() error {
|
|
|
- row := b.Offset + 10
|
|
|
+ row := b.Offset + 8
|
|
|
|
|
|
left1Cell := fmt.Sprintf("A%d", row)
|
|
|
|
|
@@ -218,8 +249,8 @@ func (b *ProduceBillExcel) drawTableFooter() error {
|
|
|
b.Excel.SetCellValue(b.SheetName, addCel, b.Content.SendTo)
|
|
|
|
|
|
sureCel := fmt.Sprintf("F%d", row)
|
|
|
- b.Excel.MergeCell(b.SheetName, sureCel, fmt.Sprintf("I%d", row))
|
|
|
- b.Excel.SetCellStyle(b.SheetName, sureCel, fmt.Sprintf("I%d", row), styleLeft)
|
|
|
+ b.Excel.MergeCell(b.SheetName, sureCel, fmt.Sprintf("L%d", row))
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, sureCel, fmt.Sprintf("L%d", row), styleLeft)
|
|
|
b.Excel.SetCellValue(b.SheetName, sureCel, "供应商签字:")
|
|
|
|
|
|
b.Excel.SetRowHeight(b.SheetName, row, 21)
|
|
@@ -227,12 +258,54 @@ func (b *ProduceBillExcel) drawTableFooter() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func (b *ProduceBillExcel) drawTableSignature() error {
|
|
|
+ row := b.Offset + 11
|
|
|
+
|
|
|
+ style1, _ := b.Excel.NewStyle(&excelize.Style{
|
|
|
+ Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
|
|
|
+ // Border: border,
|
|
|
+ })
|
|
|
+
|
|
|
+ fontCell := fmt.Sprintf("H%d", row)
|
|
|
+ imageCell1 := fmt.Sprintf("I%d", row)
|
|
|
+ imageCell2 := fmt.Sprintf("K%d", row)
|
|
|
+ b.Excel.MergeCell(b.SheetName, fontCell, fmt.Sprintf("H%d", row+2))
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, fontCell, fontCell, style1)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, fontCell, "领导签字:")
|
|
|
+
|
|
|
+ // 签字图片1 I10-J12
|
|
|
+ b.Excel.MergeCell(b.SheetName, imageCell1, fmt.Sprintf("J%d", row+2))
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, imageCell1, imageCell1, style1)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, imageCell1, "")
|
|
|
+
|
|
|
+ // 签字图片2 K10-L12
|
|
|
+ b.Excel.MergeCell(b.SheetName, imageCell2, fmt.Sprintf("L%d", row+2))
|
|
|
+ b.Excel.SetCellStyle(b.SheetName, imageCell2, imageCell1, style1)
|
|
|
+ b.Excel.SetCellValue(b.SheetName, imageCell2, "")
|
|
|
+
|
|
|
+ // 状态为已审核时,签字
|
|
|
+ if b.Content.Reviewed == 1 {
|
|
|
+ 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.SetRowHeight(b.SheetName, row, 21)
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func (b *ProduceBillExcel) Draws() {
|
|
|
b.drawTitle()
|
|
|
b.drawSubTitles()
|
|
|
b.drawTableTitle()
|
|
|
b.drawTableContent()
|
|
|
b.drawTableFooter()
|
|
|
+ b.drawTableSignature()
|
|
|
}
|
|
|
|
|
|
func NewProduceBill(f *excelize.File) *ProduceBillExcel {
|
|
@@ -255,13 +328,26 @@ func NewProduceBill(f *excelize.File) *ProduceBillExcel {
|
|
|
Excel: f,
|
|
|
Offset: 0,
|
|
|
AlignCenterStyle: styleLeft,
|
|
|
+ Signatures: make([]*model.Signature, 0),
|
|
|
}
|
|
|
|
|
|
- f.SetColWidth(b.SheetName, "A", "A", 17)
|
|
|
- f.SetColWidth(b.SheetName, "B", "B", 13)
|
|
|
- f.SetColWidth(b.SheetName, "C", "G", 9.5)
|
|
|
- f.SetColWidth(b.SheetName, "H", "I", 12)
|
|
|
+ // f.SetColWidth(b.SheetName, "A", "A", 17)
|
|
|
+ // f.SetColWidth(b.SheetName, "B", "B", 13)
|
|
|
+ // f.SetColWidth(b.SheetName, "C", "G", 9.5)
|
|
|
+ // f.SetColWidth(b.SheetName, "H", "I", 12)
|
|
|
+
|
|
|
+ f.SetColWidth(b.SheetName, "A", "A", 12)
|
|
|
+ f.SetColWidth(b.SheetName, "B", "K", 9.5)
|
|
|
+ // f.SetColWidth(b.SheetName, "I", "J", 8)
|
|
|
+ f.SetColWidth(b.SheetName, "L", "L", 10)
|
|
|
f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
|
|
|
|
|
|
return b
|
|
|
}
|
|
|
+
|
|
|
+func (b *ProduceBillExcel) FormatToEmpty(str *string) {
|
|
|
+ if *str == "0" || *str == "0.00" {
|
|
|
+ *str = ""
|
|
|
+ }
|
|
|
+
|
|
|
+}
|