bill-produce-excel.go 18 KB

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