bill-produce-excel.go 19 KB

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