bill-produce-excel.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. package api
  2. import (
  3. "box-cost/db/model"
  4. "fmt"
  5. "github.com/xuri/excelize/v2"
  6. )
  7. type ProduceBillExcel struct {
  8. Offset int
  9. Row int
  10. Title string //标题
  11. Excel *excelize.File
  12. SheetName string
  13. AlignCenterStyle int
  14. Content *model.ProduceBill
  15. Signatures []*model.Signature
  16. IsPdf string
  17. }
  18. func (b *ProduceBillExcel) drawTitle() error {
  19. b.Row++
  20. // marginLeft := excelize.PageMarginLeft(0.15)
  21. // startCell := fmt.Sprintf("A%d", b.Row)
  22. // endCell := fmt.Sprintf("L%d", b.Row)
  23. // !isPrint
  24. // if !b.Content.IsPrint {
  25. // endCell = fmt.Sprintf("I%d", b.Row)
  26. // marginLeft = excelize.PageMarginLeft(0.4)
  27. // b.Excel.SetColWidth(b.SheetName, "A", "B", 16)
  28. // b.Excel.SetColWidth(b.SheetName, "C", "H", 10.5)
  29. // b.Excel.SetColWidth(b.SheetName, "I", "I", 16)
  30. // }
  31. // !!isPdf
  32. // if b.IsPdf == "true" {
  33. marginLeft := excelize.PageMarginLeft(0.18)
  34. startCell := fmt.Sprintf("A%d", b.Row)
  35. endCell := fmt.Sprintf("J%d", b.Row)
  36. b.Excel.SetColWidth(b.SheetName, "A", "A", 16)
  37. b.Excel.SetColWidth(b.SheetName, "B", "C", 14)
  38. b.Excel.SetColWidth(b.SheetName, "C", "H", 10)
  39. b.Excel.SetColWidth(b.SheetName, "I", "I", 12)
  40. b.Excel.SetColWidth(b.SheetName, "J", "J", 14)
  41. // !isPrint
  42. if !b.Content.IsPrint {
  43. endCell = fmt.Sprintf("G%d", b.Row)
  44. marginLeft = excelize.PageMarginLeft(0.6)
  45. b.Excel.SetColWidth(b.SheetName, "A", "B", 20)
  46. b.Excel.SetColWidth(b.SheetName, "C", "F", 12)
  47. b.Excel.SetColWidth(b.SheetName, "G", "G", 20)
  48. }
  49. // }
  50. b.Excel.SetPageMargins(b.SheetName, marginLeft)
  51. err := b.Excel.MergeCell(b.SheetName, startCell, endCell)
  52. if err != nil {
  53. return err
  54. }
  55. style, err := b.Excel.NewStyle(&excelize.Style{
  56. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  57. Font: &excelize.Font{Bold: true, Size: 18}})
  58. if err != nil {
  59. return err
  60. }
  61. err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
  62. if err != nil {
  63. return err
  64. }
  65. b.Excel.SetRowHeight(b.SheetName, b.Row, 23)
  66. b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
  67. return nil
  68. }
  69. func (b *ProduceBillExcel) drawSubTitles() error {
  70. b.Row++
  71. styleLeft, err := b.Excel.NewStyle(&excelize.Style{
  72. Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
  73. Font: &excelize.Font{Size: 11}})
  74. if err != nil {
  75. return err
  76. }
  77. styleRight, err := b.Excel.NewStyle(&excelize.Style{
  78. Alignment: &excelize.Alignment{Horizontal: "right", Vertical: "center"},
  79. Font: &excelize.Font{Size: 11}})
  80. if err != nil {
  81. return err
  82. }
  83. // var drawLeft = func(rowIndex int, value string) error {
  84. // //左边1
  85. // left1Cell := fmt.Sprintf("A%d", rowIndex)
  86. // err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
  87. // if err != nil {
  88. // return err
  89. // }
  90. // err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
  91. // if err != nil {
  92. // return err
  93. // }
  94. // b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  95. // return nil
  96. // }
  97. // var drawRight = func(rowIndex int, value string) error {
  98. // right1Cell := fmt.Sprintf("G%d", rowIndex)
  99. // err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("L%d", rowIndex))
  100. // if err != nil {
  101. // return err
  102. // }
  103. // err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
  104. // if err != nil {
  105. // return err
  106. // }
  107. // b.Excel.SetCellValue(b.SheetName, right1Cell, value)
  108. // return nil
  109. // }
  110. // !isPrint
  111. // if !b.Content.IsPrint {
  112. // drawLeft = func(rowIndex int, value string) error {
  113. // //左边1
  114. // left1Cell := fmt.Sprintf("A%d", rowIndex)
  115. // err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("E%d", rowIndex))
  116. // if err != nil {
  117. // return err
  118. // }
  119. // err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
  120. // if err != nil {
  121. // return err
  122. // }
  123. // b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  124. // return nil
  125. // }
  126. // drawRight = func(rowIndex int, value string) error {
  127. // right1Cell := fmt.Sprintf("F%d", rowIndex)
  128. // err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("I%d", rowIndex))
  129. // if err != nil {
  130. // return err
  131. // }
  132. // err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
  133. // if err != nil {
  134. // return err
  135. // }
  136. // b.Excel.SetCellValue(b.SheetName, right1Cell, value)
  137. // return nil
  138. // }
  139. // }
  140. // !!isPdf
  141. // if b.IsPdf == "true" {
  142. drawLeft := func(rowIndex int, value string) error {
  143. //左边1
  144. left1Cell := fmt.Sprintf("A%d", rowIndex)
  145. err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("G%d", rowIndex))
  146. if err != nil {
  147. return err
  148. }
  149. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
  150. if err != nil {
  151. return err
  152. }
  153. b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  154. return nil
  155. }
  156. drawRight := func(rowIndex int, value string) error {
  157. right1Cell := fmt.Sprintf("H%d", rowIndex)
  158. err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("J%d", rowIndex))
  159. if err != nil {
  160. return err
  161. }
  162. err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
  163. if err != nil {
  164. return err
  165. }
  166. b.Excel.SetCellValue(b.SheetName, right1Cell, value)
  167. return nil
  168. }
  169. // !isPrint
  170. if !b.Content.IsPrint {
  171. drawLeft = func(rowIndex int, value string) error {
  172. //左边1
  173. left1Cell := fmt.Sprintf("A%d", rowIndex)
  174. err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("E%d", rowIndex))
  175. if err != nil {
  176. return err
  177. }
  178. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
  179. if err != nil {
  180. return err
  181. }
  182. b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  183. return nil
  184. }
  185. drawRight = func(rowIndex int, value string) error {
  186. right1Cell := fmt.Sprintf("F%d", rowIndex)
  187. err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("G%d", rowIndex))
  188. if err != nil {
  189. return err
  190. }
  191. err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
  192. if err != nil {
  193. return err
  194. }
  195. b.Excel.SetCellValue(b.SheetName, right1Cell, value)
  196. return nil
  197. }
  198. }
  199. // }
  200. //第一行
  201. drawLeft(b.Row, "类别:"+b.Content.Type)
  202. drawRight(b.Row, "单号:"+b.Content.SerialNumber)
  203. b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
  204. //第二行
  205. drawLeft(b.Row+1, "供应商名称:"+b.Content.Supplier)
  206. timeformat := b.Content.CreateTime.Local().Format("2006年01月02号 15:04:05")
  207. drawRight(b.Row+1, "下单时间:"+timeformat)
  208. b.Excel.SetRowHeight(b.SheetName, b.Row+1, 21)
  209. //第三行
  210. drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
  211. status := ""
  212. if b.Content.Status == "complete" {
  213. status = "已完成"
  214. }
  215. if b.Content.Status == "created" {
  216. status = "进行中"
  217. }
  218. drawRight(b.Row+2, "状态:"+status)
  219. b.Excel.SetRowHeight(b.SheetName, b.Row+2, 21)
  220. return nil
  221. }
  222. func (b *ProduceBillExcel) drawTableTitle() error {
  223. b.Row += 3
  224. var drawCol = func(prefix string, value string) error {
  225. left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  226. left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  227. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  228. if err != nil {
  229. return err
  230. }
  231. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  232. if err != nil {
  233. return err
  234. }
  235. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  236. }
  237. var drawCol2 = func(prefix string, value1 string, value2 string) error {
  238. left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  239. left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  240. err := b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  241. if err != nil {
  242. return err
  243. }
  244. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  245. b.Excel.SetCellValue(b.SheetName, left2Cell, value2)
  246. return nil
  247. }
  248. if b.Content.IsPrint {
  249. drawCol("A", "加工项目")
  250. drawCol("B", "规格")
  251. drawCol("C", "纸张")
  252. drawCol("D", "来纸尺寸")
  253. drawCol("E", "印刷尺寸")
  254. drawCol("F", "下单数量")
  255. drawCol2("G", "单价", "元/张")
  256. drawCol("H", "预算金额")
  257. drawCol("I", "交货时间")
  258. drawCol("J", "备注")
  259. } else {
  260. drawCol("A", "加工项目")
  261. drawCol("B", "规格")
  262. drawCol("C", "下单数量")
  263. drawCol2("D", "单价", "元/张")
  264. drawCol("E", "预算金额")
  265. drawCol("F", "交货时间")
  266. drawCol("G", "备注")
  267. }
  268. // // !isPrint
  269. // if !b.Content.IsPrint {
  270. // // !!isPdf
  271. // if b.IsPdf == "true" {
  272. // drawCol("A", "加工项目")
  273. // drawCol("B", "规格")
  274. // drawCol("C", "下单数量")
  275. // drawCol2("D", "单价", "元/张")
  276. // drawCol("E", "预算金额")
  277. // drawCol("F", "交货时间")
  278. // drawCol("G", "备注")
  279. // } else {
  280. // drawCol("A", "加工项目")
  281. // drawCol("B", "规格")
  282. // drawCol("C", "下单数量")
  283. // drawCol("D", "完成数量")
  284. // drawCol2("E", "单价", "元/张")
  285. // drawCol("F", "预算金额")
  286. // drawCol("G", "实际金额")
  287. // drawCol("H", "交货时间")
  288. // drawCol("I", "备注")
  289. // }
  290. // } else {
  291. // // !!isPdf
  292. // if b.IsPdf == "true" {
  293. // drawCol("A", "加工项目")
  294. // drawCol("B", "规格")
  295. // drawCol("C", "纸张")
  296. // drawCol("D", "来纸尺寸")
  297. // drawCol("E", "印刷尺寸")
  298. // drawCol("F", "下单数量")
  299. // drawCol2("G", "单价", "元/张")
  300. // drawCol("H", "预算金额")
  301. // drawCol("I", "交货时间")
  302. // drawCol("J", "备注")
  303. // } else {
  304. // drawCol("A", "加工项目")
  305. // drawCol("B", "规格")
  306. // drawCol("C", "纸张")
  307. // drawCol("D", "来纸尺寸")
  308. // drawCol("E", "印刷尺寸")
  309. // drawCol("F", "下单数量")
  310. // drawCol("G", "完成数量")
  311. // drawCol2("H", "单价", "元/张")
  312. // drawCol("I", "预算金额")
  313. // drawCol("J", "实际金额")
  314. // drawCol("K", "交货时间")
  315. // drawCol("L", "备注")
  316. // }
  317. // }
  318. return nil
  319. }
  320. func (b *ProduceBillExcel) drawTableContent() error {
  321. b.Row += 2
  322. var DrawRow = func(rowIndex int, values ...string) {
  323. // charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}
  324. // // !isPrint
  325. // if !b.Content.IsPrint {
  326. // charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
  327. // }
  328. // !!isPdf
  329. // if b.IsPdf == "true" {
  330. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}
  331. // !isPrint
  332. if !b.Content.IsPrint {
  333. charas = []string{"A", "B", "C", "D", "E", "F", "G"}
  334. }
  335. // }
  336. for i, c := range charas {
  337. v := ""
  338. if i < len(values) {
  339. v = values[i]
  340. }
  341. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  342. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  343. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  344. b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
  345. }
  346. }
  347. produces := b.Content.Produces
  348. if len(produces) > 0 {
  349. for _, produce := range produces {
  350. realCount := ""
  351. price := produce.OrderPrice
  352. priceStr := fmt.Sprintf("%.3f", price)
  353. b.FormatToEmpty(&priceStr)
  354. // 预算金额
  355. budgetAmount := fmt.Sprintf("%.3f", produce.OrderPrice*float64(produce.OrderCount))
  356. b.FormatToEmpty(&budgetAmount)
  357. // 实际金额
  358. realPrice := ""
  359. // 实际完成数
  360. realCount = fmt.Sprintf("%d", produce.ConfirmCount)
  361. b.FormatToEmpty(&realCount)
  362. realPrice = fmt.Sprintf("%.3f", produce.OrderPrice*float64(produce.ConfirmCount))
  363. b.FormatToEmpty(&realPrice)
  364. deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
  365. if b.Content.IsPrint {
  366. DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
  367. } else {
  368. DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
  369. }
  370. // !isPrint
  371. // if !b.Content.IsPrint {
  372. // // !!isPdf
  373. // if b.IsPdf == "true" {
  374. // DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
  375. // } else {
  376. // DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, budgetAmount, realPrice, deliveryTime, produce.Remark)
  377. // }
  378. // } else {
  379. // // !!isPdf
  380. // if b.IsPdf == "true" {
  381. // DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, budgetAmount, deliveryTime, produce.Remark)
  382. // } else {
  383. // DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), realCount, priceStr, budgetAmount, realPrice, deliveryTime, produce.Remark)
  384. // }
  385. // }
  386. b.Row++
  387. }
  388. }
  389. return nil
  390. }
  391. func (b *ProduceBillExcel) drawTableFooter() error {
  392. border := []excelize.Border{
  393. {Type: "top", Style: 1, Color: "000000"},
  394. {Type: "left", Style: 1, Color: "000000"},
  395. {Type: "right", Style: 1, Color: "000000"},
  396. {Type: "bottom", Style: 1, Color: "000000"},
  397. }
  398. styleLeft, _ := b.Excel.NewStyle(&excelize.Style{
  399. Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
  400. Border: border,
  401. })
  402. sendToStartCell := fmt.Sprintf("A%d", b.Row)
  403. // sendToEndCell := fmt.Sprintf("G%d", b.Row)
  404. // supplierStartCell := fmt.Sprintf("H%d", b.Row)
  405. // supplierEndCell := fmt.Sprintf("L%d", b.Row)
  406. // // !isPrint
  407. // if !b.Content.IsPrint {
  408. // sendToEndCell = fmt.Sprintf("F%d", b.Row)
  409. // supplierStartCell = fmt.Sprintf("G%d", b.Row)
  410. // supplierEndCell = fmt.Sprintf("I%d", b.Row)
  411. // }
  412. // !!isPdf
  413. // if b.IsPdf == "true" {
  414. sendToEndCell := fmt.Sprintf("E%d", b.Row)
  415. supplierStartCell := fmt.Sprintf("F%d", b.Row)
  416. supplierEndCell := fmt.Sprintf("J%d", b.Row)
  417. // !isPrint
  418. if !b.Content.IsPrint {
  419. sendToEndCell = fmt.Sprintf("D%d", b.Row)
  420. supplierStartCell = fmt.Sprintf("E%d", b.Row)
  421. supplierEndCell = fmt.Sprintf("G%d", b.Row)
  422. }
  423. // }
  424. b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
  425. b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
  426. b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
  427. b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
  428. b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
  429. b.Excel.SetCellValue(b.SheetName, supplierStartCell, "供应商签字:")
  430. b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
  431. return nil
  432. }
  433. func (b *ProduceBillExcel) drawTableSignature() error {
  434. b.Row += 2
  435. style1, _ := b.Excel.NewStyle(&excelize.Style{
  436. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  437. // Border: border,
  438. })
  439. // 制单人
  440. billUserCellS := fmt.Sprintf("A%d", b.Row+1)
  441. billUserCellE := fmt.Sprintf("B%d", b.Row+1)
  442. b.Excel.MergeCell(b.SheetName, billUserCellS, billUserCellE)
  443. b.Excel.SetCellValue(b.SheetName, billUserCellS, "制单人:"+b.Content.UserName)
  444. // fontNum := "H"
  445. // image1s := "I"
  446. // image2s := "K"
  447. // image1e := "J"
  448. // image2e := "L"
  449. // // !isPrint
  450. // if !b.Content.IsPrint {
  451. // fontNum = "E"
  452. // image1s = "F"
  453. // image2s = "H"
  454. // image1e = "G"
  455. // image2e = "I"
  456. // }
  457. // !!isPdf
  458. // if b.IsPdf == "true" {
  459. fontNum := "F"
  460. image1s := "G"
  461. image2s := "I"
  462. image1e := "H"
  463. image2e := "J"
  464. if !b.Content.IsPrint {
  465. fontNum = "D"
  466. image1s = "E"
  467. image2s = "G"
  468. image1e = "F"
  469. image2e = "G"
  470. }
  471. // }
  472. fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
  473. fontEndCell := fmt.Sprintf("%s%d", fontNum, b.Row+2)
  474. imageCell1 := fmt.Sprintf("%s%d", image1s, b.Row)
  475. imageEndCell1 := fmt.Sprintf("%s%d", image1e, b.Row+2)
  476. imageCell2 := fmt.Sprintf("%s%d", image2s, b.Row)
  477. imageEndCell2 := fmt.Sprintf("%s%d", image2e, b.Row+2)
  478. b.Excel.MergeCell(b.SheetName, fontCell, fontEndCell)
  479. b.Excel.SetCellStyle(b.SheetName, fontCell, fontCell, style1)
  480. b.Excel.SetCellValue(b.SheetName, fontCell, "审核签字:")
  481. // 签字图片1 I10-J12
  482. b.Excel.MergeCell(b.SheetName, imageCell1, imageEndCell1)
  483. b.Excel.SetCellStyle(b.SheetName, imageCell1, imageCell1, style1)
  484. b.Excel.SetCellValue(b.SheetName, imageCell1, "")
  485. // 签字图片2 K10-L12
  486. b.Excel.MergeCell(b.SheetName, imageCell2, imageEndCell2)
  487. b.Excel.SetCellStyle(b.SheetName, imageCell2, imageCell1, style1)
  488. b.Excel.SetCellValue(b.SheetName, imageCell2, "")
  489. // 状态为已审核时,签字
  490. if b.Content.Reviewed == 1 {
  491. imageCells := []string{imageCell1, imageCell2}
  492. if len(b.Signatures) > 0 {
  493. for k, sign := range b.Signatures {
  494. b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Path, sign.Format)
  495. }
  496. }
  497. }
  498. b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
  499. return nil
  500. }
  501. func (b *ProduceBillExcel) Draws() {
  502. b.drawTitle()
  503. b.drawSubTitles()
  504. b.drawTableTitle()
  505. b.drawTableContent()
  506. b.drawTableFooter()
  507. b.drawTableSignature()
  508. }
  509. func NewProduceBill(f *excelize.File) *ProduceBillExcel {
  510. border := []excelize.Border{
  511. {Type: "top", Style: 1, Color: "000000"},
  512. {Type: "left", Style: 1, Color: "000000"},
  513. {Type: "right", Style: 1, Color: "000000"},
  514. {Type: "bottom", Style: 1, Color: "000000"},
  515. }
  516. styleLeft, _ := f.NewStyle(&excelize.Style{
  517. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  518. Border: border,
  519. })
  520. b := &ProduceBillExcel{
  521. Title: "中鱼互动加工单",
  522. SheetName: "Sheet1",
  523. Excel: f,
  524. Offset: 0,
  525. AlignCenterStyle: styleLeft,
  526. Signatures: make([]*model.Signature, 0),
  527. }
  528. // f.SetColWidth(b.SheetName, "A", "A", 12)
  529. // f.SetColWidth(b.SheetName, "B", "K", 9.5)
  530. // // f.SetColWidth(b.SheetName, "I", "J", 8)
  531. // f.SetColWidth(b.SheetName, "L", "L", 10)
  532. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  533. return b
  534. }
  535. func (b *ProduceBillExcel) FormatToEmpty(str *string) {
  536. if *str == "0" || *str == "0.000" {
  537. *str = ""
  538. }
  539. }
  540. func (b *ProduceBillExcel) SetContent(content interface{}) {
  541. b.Content = content.(*model.ProduceBill)
  542. }
  543. func (b *ProduceBillExcel) SetTitle(title string) {
  544. b.Title = title
  545. }
  546. func (b *ProduceBillExcel) SetRow(row int) {
  547. b.Row = row
  548. }
  549. func (b *ProduceBillExcel) SetIsPdf(isPdf string) {
  550. b.IsPdf = isPdf
  551. }
  552. func (b *ProduceBillExcel) GetRow() int {
  553. return b.Row
  554. }
  555. func (b *ProduceBillExcel) SetSignatures(sign interface{}) {
  556. b.Signatures = sign.([]*model.Signature)
  557. }