bill-produce-excel.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. if !b.Content.IsPrint {
  117. drawLeft = 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("F%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. drawRight = func(rowIndex int, value string) error {
  132. right1Cell := fmt.Sprintf("G%d", rowIndex)
  133. err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("H%d", rowIndex))
  134. if err != nil {
  135. return err
  136. }
  137. err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
  138. if err != nil {
  139. return err
  140. }
  141. b.Excel.SetCellValue(b.SheetName, right1Cell, value)
  142. return nil
  143. }
  144. if b.Content.IsLam {
  145. drawLeft = func(rowIndex int, value string) error {
  146. //左边1
  147. left1Cell := fmt.Sprintf("A%d", rowIndex)
  148. err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
  149. if err != nil {
  150. return err
  151. }
  152. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
  153. if err != nil {
  154. return err
  155. }
  156. b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  157. return nil
  158. }
  159. drawRight = func(rowIndex int, value string) error {
  160. right1Cell := fmt.Sprintf("G%d", rowIndex)
  161. err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("I%d", rowIndex))
  162. if err != nil {
  163. return err
  164. }
  165. err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
  166. if err != nil {
  167. return err
  168. }
  169. b.Excel.SetCellValue(b.SheetName, right1Cell, value)
  170. return nil
  171. }
  172. }
  173. }
  174. //第一行
  175. drawLeft(b.Row, "类别:"+b.Content.Type)
  176. drawRight(b.Row, "单号:"+b.Content.SerialNumber)
  177. b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
  178. //第二行
  179. drawLeft(b.Row+1, "供应商名称:"+b.Content.Supplier)
  180. timeformat := b.Content.CreateTime.Local().Format("2006年01月02号 15:04:05")
  181. drawRight(b.Row+1, "下单时间:"+timeformat)
  182. b.Excel.SetRowHeight(b.SheetName, b.Row+1, 21)
  183. //第三行
  184. drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
  185. status := ""
  186. if b.Content.Status == "complete" {
  187. status = "已完成"
  188. }
  189. if b.Content.Status == "created" {
  190. status = "进行中"
  191. }
  192. drawRight(b.Row+2, "状态:"+status)
  193. b.Excel.SetRowHeight(b.SheetName, b.Row+2, 21)
  194. // 第四行
  195. drawLeft(b.Row+3, "包含工序:"+b.Content.CompProduceName)
  196. return nil
  197. }
  198. func (b *ProduceBillExcel) drawTableTitle() error {
  199. b.Row += 4
  200. var drawCol = func(prefix string, value string) error {
  201. left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  202. left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  203. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  204. if err != nil {
  205. return err
  206. }
  207. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  208. if err != nil {
  209. return err
  210. }
  211. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  212. }
  213. // var drawCol2 = func(prefix string, value1 string, value2 string) error {
  214. // left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  215. // left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  216. // err := b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  217. // if err != nil {
  218. // return err
  219. // }
  220. // b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  221. // b.Excel.SetCellValue(b.SheetName, left2Cell, value2)
  222. // return nil
  223. // }
  224. var drawCol3 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
  225. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  226. left2Cell := fmt.Sprintf("%s%d", prefix2, b.Row)
  227. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  228. if err != nil {
  229. return err
  230. }
  231. if err != nil {
  232. fmt.Println(err)
  233. return err
  234. }
  235. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  236. if err != nil {
  237. return err
  238. }
  239. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  240. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  241. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  242. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  243. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  244. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  245. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  246. return nil
  247. }
  248. unit := b.Content.Produces[0].Unit
  249. if b.Content.IsPrint {
  250. drawCol("A", "加工项目")
  251. drawCol("B", "规格")
  252. drawCol("C", "纸张")
  253. drawCol("D", "来纸尺寸")
  254. drawCol("E", "印刷尺寸")
  255. drawCol("F", "下单数量")
  256. drawCol("G", "单位")
  257. drawCol("H", "单价")
  258. drawCol("I", "预算金额")
  259. drawCol("J", "交货时间")
  260. drawCol("K", "备注")
  261. } else {
  262. if b.Content.IsLam {
  263. drawCol("A", "加工项目")
  264. drawCol("B", "规格")
  265. drawCol("C", "覆膜尺寸")
  266. drawCol("D", "下单数量")
  267. unit2 := b.Content.Produces[0].Unit2
  268. drawCol3("E", "F", "单价", unit, unit2)
  269. drawCol("G", "预算金额")
  270. drawCol("H", "交货时间")
  271. drawCol("I", "备注")
  272. } else {
  273. drawCol("A", "加工项目")
  274. drawCol("B", "规格")
  275. drawCol("C", "下单数量")
  276. drawCol("D", "单位")
  277. drawCol("E", "单价")
  278. drawCol("F", "预算金额")
  279. drawCol("G", "交货时间")
  280. drawCol("H", "备注")
  281. }
  282. }
  283. return nil
  284. }
  285. func (b *ProduceBillExcel) drawTableContent() error {
  286. b.Row += 2
  287. var DrawRow = func(rowIndex int, values ...string) {
  288. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"}
  289. if !b.Content.IsPrint {
  290. charas = []string{"A", "B", "C", "D", "E", "F", "G", "H"}
  291. if b.Content.IsLam {
  292. charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
  293. }
  294. }
  295. // }
  296. for i, c := range charas {
  297. v := ""
  298. if i < len(values) {
  299. v = values[i]
  300. }
  301. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  302. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  303. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  304. // var magN float64 = 1
  305. // lenv := len([]rune(v))
  306. // magN = math.Ceil(float64(lenv) / 10)
  307. // if lenv%10 > 5 {
  308. // magN = math.Ceil(float64(lenv) / 10)
  309. // } else {
  310. // n := math.Floor(float64(lenv) / 10)
  311. // if n > 0 {
  312. // magN = n
  313. // }
  314. // }
  315. // b.Excel.SetRowHeight(b.SheetName, rowIndex, 21*magN)
  316. b.Excel.SetRowHeight(b.SheetName, rowIndex, 46)
  317. }
  318. }
  319. produces := b.Content.Produces
  320. if len(produces) > 0 {
  321. for _, produce := range produces {
  322. realCount := ""
  323. price := produce.OrderPrice
  324. priceStr := fmt.Sprintf("%.3f", price)
  325. b.FormatToEmpty(&priceStr)
  326. // 预算金额
  327. budgetAmount := fmt.Sprintf("%.3f", produce.OrderPrice*float64(produce.OrderCount))
  328. b.FormatToEmpty(&budgetAmount)
  329. // 实际金额
  330. realPrice := ""
  331. // 实际完成数
  332. realCount = fmt.Sprintf("%d", produce.ConfirmCount)
  333. b.FormatToEmpty(&realCount)
  334. realPrice = fmt.Sprintf("%.3f", produce.OrderPrice*float64(produce.ConfirmCount))
  335. b.FormatToEmpty(&realPrice)
  336. deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
  337. if b.Content.IsPrint {
  338. 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)
  339. } else {
  340. // 覆膜
  341. if b.Content.IsLam {
  342. DrawRow(b.Row, produce.Name, produce.Norm, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, fmt.Sprintf("%.3f", produce.Price2), budgetAmount, deliveryTime, produce.Remark)
  343. } else {
  344. DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
  345. }
  346. }
  347. b.Row++
  348. }
  349. }
  350. return nil
  351. }
  352. func (b *ProduceBillExcel) drawTableFooter() error {
  353. border := []excelize.Border{
  354. {Type: "top", Style: 1, Color: "000000"},
  355. {Type: "left", Style: 1, Color: "000000"},
  356. {Type: "right", Style: 1, Color: "000000"},
  357. {Type: "bottom", Style: 1, Color: "000000"},
  358. }
  359. styleLeft, _ := b.Excel.NewStyle(&excelize.Style{
  360. Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center"},
  361. Border: border,
  362. })
  363. sendToStartCell := fmt.Sprintf("A%d", b.Row)
  364. sendToEndCell := fmt.Sprintf("H%d", b.Row)
  365. supplierStartCell := fmt.Sprintf("I%d", b.Row)
  366. supplierEndCell := fmt.Sprintf("K%d", b.Row)
  367. if !b.Content.IsPrint {
  368. sendToEndCell = fmt.Sprintf("E%d", b.Row)
  369. supplierStartCell = fmt.Sprintf("F%d", b.Row)
  370. supplierEndCell = fmt.Sprintf("H%d", b.Row)
  371. if b.Content.IsLam {
  372. sendToEndCell = fmt.Sprintf("F%d", b.Row)
  373. supplierStartCell = fmt.Sprintf("G%d", b.Row)
  374. supplierEndCell = fmt.Sprintf("I%d", b.Row)
  375. }
  376. }
  377. b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
  378. b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
  379. b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
  380. b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
  381. b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
  382. b.Excel.SetCellValue(b.SheetName, supplierStartCell, "供应商签字:")
  383. b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
  384. return nil
  385. }
  386. func (b *ProduceBillExcel) drawSupplierRemark() error {
  387. b.Row++
  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"},
  396. Border: border,
  397. })
  398. sendToStartCell := fmt.Sprintf("A%d", b.Row)
  399. sendToEndCell := fmt.Sprintf("K%d", b.Row)
  400. if !b.Content.IsPrint {
  401. sendToEndCell = fmt.Sprintf("H%d", b.Row)
  402. if b.Content.IsLam {
  403. sendToEndCell = fmt.Sprintf("I%d", b.Row)
  404. }
  405. }
  406. b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
  407. b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
  408. b.Excel.SetCellValue(b.SheetName, sendToStartCell, "供应商备注:"+b.Content.SupplierRemark)
  409. b.Excel.SetRowHeight(b.SheetName, b.Row, 32)
  410. return nil
  411. }
  412. func (b *ProduceBillExcel) drawTableSignature() error {
  413. b.Row += 2
  414. style1, _ := b.Excel.NewStyle(&excelize.Style{
  415. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  416. // Border: border,
  417. })
  418. // 制单人
  419. billUserCellS := fmt.Sprintf("A%d", b.Row+1)
  420. billUserCellE := fmt.Sprintf("B%d", b.Row+1)
  421. b.Excel.MergeCell(b.SheetName, billUserCellS, billUserCellE)
  422. b.Excel.SetCellValue(b.SheetName, billUserCellS, "制单人:"+b.Content.UserName)
  423. fontNum := "F"
  424. fontENum := "G"
  425. image1s := "H"
  426. image2s := "J"
  427. image1e := "I"
  428. image2e := "K"
  429. if !b.Content.IsPrint {
  430. fontNum = "E"
  431. fontENum = "E"
  432. image1s = "F"
  433. image2s = "H"
  434. image1e = "G"
  435. image2e = "H"
  436. if b.Content.IsLam {
  437. fontNum = "E"
  438. fontENum = "E"
  439. image1s = "F"
  440. image2s = "H"
  441. image1e = "G"
  442. image2e = "I"
  443. }
  444. }
  445. fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
  446. fontEndCell := fmt.Sprintf("%s%d", fontENum, b.Row+2)
  447. imageCell1 := fmt.Sprintf("%s%d", image1s, b.Row)
  448. imageEndCell1 := fmt.Sprintf("%s%d", image1e, b.Row+2)
  449. imageCell2 := fmt.Sprintf("%s%d", image2s, b.Row)
  450. imageEndCell2 := fmt.Sprintf("%s%d", image2e, b.Row+2)
  451. b.Excel.MergeCell(b.SheetName, fontCell, fontEndCell)
  452. b.Excel.SetCellStyle(b.SheetName, fontCell, fontCell, style1)
  453. b.Excel.SetCellValue(b.SheetName, fontCell, "审核签字:")
  454. // 签字图片1 I10-J12
  455. b.Excel.MergeCell(b.SheetName, imageCell1, imageEndCell1)
  456. b.Excel.SetCellStyle(b.SheetName, imageCell1, imageCell1, style1)
  457. b.Excel.SetCellValue(b.SheetName, imageCell1, "")
  458. // 签字图片2 K10-L12
  459. b.Excel.MergeCell(b.SheetName, imageCell2, imageEndCell2)
  460. b.Excel.SetCellStyle(b.SheetName, imageCell2, imageCell1, style1)
  461. b.Excel.SetCellValue(b.SheetName, imageCell2, "")
  462. // 状态为已审核时,签字
  463. if b.Content.Reviewed == 1 {
  464. imageCells := []string{imageCell1, imageCell2}
  465. if len(b.Signatures) > 0 {
  466. for k, sign := range b.Signatures {
  467. b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Path, sign.Format)
  468. }
  469. }
  470. }
  471. b.Excel.SetRowHeight(b.SheetName, b.Row, 21)
  472. return nil
  473. }
  474. func (b *ProduceBillExcel) Draws() {
  475. b.drawTitle()
  476. b.drawSubTitles()
  477. b.drawTableTitle()
  478. b.drawTableContent()
  479. b.drawTableFooter()
  480. if len(b.Content.SupplierRemark) > 1 {
  481. b.drawSupplierRemark()
  482. }
  483. b.drawTableSignature()
  484. }
  485. func NewProduceBill(f *excelize.File) *ProduceBillExcel {
  486. border := []excelize.Border{
  487. {Type: "top", Style: 1, Color: "000000"},
  488. {Type: "left", Style: 1, Color: "000000"},
  489. {Type: "right", Style: 1, Color: "000000"},
  490. {Type: "bottom", Style: 1, Color: "000000"},
  491. }
  492. styleLeft, _ := f.NewStyle(&excelize.Style{
  493. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  494. Border: border,
  495. })
  496. b := &ProduceBillExcel{
  497. Title: "中鱼互动加工单",
  498. SheetName: "Sheet1",
  499. Excel: f,
  500. Offset: 0,
  501. AlignCenterStyle: styleLeft,
  502. Signatures: make([]*model.Signature, 0),
  503. }
  504. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(1), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  505. return b
  506. }
  507. func (b *ProduceBillExcel) FormatToEmpty(str *string) {
  508. if *str == "0" || *str == "0.000" {
  509. *str = ""
  510. }
  511. }
  512. func (b *ProduceBillExcel) SetContent(content interface{}) {
  513. b.Content = content.(*model.ProduceBill)
  514. }
  515. func (b *ProduceBillExcel) SetTitle(title string) {
  516. b.Title = title
  517. }
  518. func (b *ProduceBillExcel) SetSheetName(name string) {
  519. b.SheetName = name
  520. }
  521. func (b *ProduceBillExcel) SetRow(row int) {
  522. b.Row = row
  523. }
  524. func (b *ProduceBillExcel) SetIsPdf(isPdf string) {
  525. b.IsPdf = isPdf
  526. }
  527. func (b *ProduceBillExcel) GetRow() int {
  528. return b.Row
  529. }
  530. func (b *ProduceBillExcel) SetSignatures(sign interface{}) {
  531. b.Signatures = sign.([]*model.Signature)
  532. }