plan-summary-excel.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. )
  6. // 生产成本表
  7. type PlanSummaryExcel struct {
  8. Row int
  9. Title string
  10. Excel *excelize.File
  11. SheetName string
  12. AlignCenterStyle int
  13. Content *SupplierPlanSummary
  14. }
  15. func (b *PlanSummaryExcel) drawTitle() error {
  16. b.Row++
  17. startCell := fmt.Sprintf("A%d", b.Row)
  18. err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("P%d", b.Row))
  19. if err != nil {
  20. return err
  21. }
  22. style, err := b.Excel.NewStyle(&excelize.Style{
  23. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  24. Font: &excelize.Font{Bold: true, Size: 18}})
  25. if err != nil {
  26. return err
  27. }
  28. err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
  29. if err != nil {
  30. return err
  31. }
  32. b.Excel.SetRowHeight(b.SheetName, b.Row, 23)
  33. b.Excel.SetCellValue(b.SheetName, startCell, "汇总表")
  34. return nil
  35. }
  36. func (b *PlanSummaryExcel) drawTableTitle() error {
  37. b.Row++
  38. var drawCol = func(prefix string, value string) error {
  39. left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  40. left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  41. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  42. if err != nil {
  43. return err
  44. }
  45. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  46. if err != nil {
  47. return err
  48. }
  49. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  50. }
  51. var drawCol2 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
  52. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  53. left2Cell := fmt.Sprintf("%s%d", prefix2, b.Row)
  54. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  55. if err != nil {
  56. return err
  57. }
  58. if err != nil {
  59. fmt.Println(err)
  60. return err
  61. }
  62. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  63. if err != nil {
  64. return err
  65. }
  66. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  67. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  68. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  69. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  70. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  71. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  72. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  73. return nil
  74. }
  75. var drawCol3 = func(prefix1 string, prefix2 string, prefix3 string, value1 string, value2 string, value3 string, value4 string) error {
  76. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  77. left3Cell := fmt.Sprintf("%s%d", prefix3, b.Row)
  78. err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
  79. if err != nil {
  80. return err
  81. }
  82. if err != nil {
  83. fmt.Println(err)
  84. return err
  85. }
  86. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left3Cell, b.AlignCenterStyle)
  87. if err != nil {
  88. return err
  89. }
  90. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  91. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  92. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  93. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  94. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  95. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  96. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  97. val4Cel := fmt.Sprintf("%s%d", prefix3, b.Row+1)
  98. b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
  99. b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
  100. return nil
  101. }
  102. drawCol("A", "产品名称")
  103. drawCol("B", "产品部件名称")
  104. drawCol2("C", "D", "类型/项目", "类型", "项目")
  105. drawCol("E", "下单数量")
  106. drawCol("F", "实际数量")
  107. drawCol("G", "状态") // 生成订单状态 审核状态 发送状态 完成状态
  108. drawCol("H", "供应商名称")
  109. drawCol("I", "单价")
  110. drawCol3("J", "K", "L", "规格", "厚度(纸克)", "长", "宽")
  111. drawCol("M", "单位")
  112. drawCol("N", "下单单价")
  113. drawCol("O", "预算金额")
  114. drawCol("P", "实际金额")
  115. return nil
  116. }
  117. func (b *PlanSummaryExcel) drawRow(rowIndex int, values ...string) {
  118. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
  119. for i, c := range charas {
  120. v := ""
  121. if i < len(values) {
  122. v = values[i]
  123. }
  124. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  125. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  126. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  127. b.Excel.SetRowHeight(b.SheetName, rowIndex, 32)
  128. }
  129. }
  130. func (b *PlanSummaryExcel) drawAllContent() error {
  131. b.Row += 2
  132. // summaryPlans
  133. // 预算金额汇总
  134. var totalBudgetPrice float64 = 0.00
  135. // 实际金额汇总
  136. var totalRealPrice float64 = 0.00
  137. for _, splan := range b.Content.Plans {
  138. planStartRow := b.Row
  139. plan := splan.Plan
  140. comps := plan.Pack.Components
  141. // 预算金额汇总
  142. var planBudgetPrice float64 = 0.00
  143. // 实际金额汇总
  144. var planRealPrice float64 = 0.00
  145. if len(comps) > 0 {
  146. for _, comp := range comps {
  147. var perBudgetPrice float64 = 0.00
  148. var perRealPrice float64 = 0.00
  149. if len(comp.Stages) > 0 {
  150. startRow := b.Row
  151. cates := map[string][]int{}
  152. for _, stage := range comp.Stages {
  153. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  154. b.FormatToEmpty(&matHeigth)
  155. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  156. b.FormatToEmpty(&matWidth)
  157. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  158. b.FormatToEmpty(&orderCount)
  159. // 实际数量
  160. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  161. b.FormatToEmpty(&realCount)
  162. // 单价
  163. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  164. b.FormatToEmpty(&price)
  165. // 预算金额
  166. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  167. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  168. b.FormatToEmpty(&budgetPrice)
  169. // 实际金额
  170. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  171. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  172. b.FormatToEmpty(&realPrice)
  173. unit := stage.Unit
  174. if stage.Unit == "吨" || stage.Unit == "平方米" {
  175. unit = "张"
  176. }
  177. supplierName := ""
  178. if stage.SupplierInfo != nil {
  179. supplierName = stage.SupplierInfo.Name
  180. }
  181. stageType := ""
  182. if stage.BillType > 0 {
  183. stage.Type = stage.BillType
  184. }
  185. if stage.Type == 1 {
  186. stageType = "材料采购"
  187. }
  188. if stage.Type == 2 {
  189. stageType = "工艺"
  190. }
  191. if stage.Type == 3 {
  192. stageType = "成品采购"
  193. }
  194. // !状态正确需要,按流程处理订单,未正确处理时不能进行下面的流程
  195. // 状态
  196. stageStatus := ""
  197. // if len(stage.BillId) < 1 {
  198. // stageStatus = "未生成订单"
  199. // }
  200. // if splan.State[stage.BillId] == "created" {
  201. // stageStatus = "进行中"
  202. // }
  203. // // 审核状态
  204. // if splan.Reviewed[stage.BillId] == 1 {
  205. // stageStatus = "已审核"
  206. // } else {
  207. // stageStatus = "未审核"
  208. // }
  209. // // 接单状态
  210. // if splan.IsAck[stage.BillId] {
  211. // stageStatus = "已接单"
  212. // } else {
  213. // stageStatus = "未接单"
  214. // }
  215. // // 完成状态
  216. // if splan.State[stage.BillId] == "complete" {
  217. // stageStatus = "已完成"
  218. // }
  219. if len(stage.BillId) < 1 {
  220. stageStatus = "未生成订单"
  221. } else {
  222. if splan.State[stage.BillId] == "created" {
  223. stageStatus = "进行中"
  224. // 审核状态
  225. if splan.Reviewed[stage.BillId] == 1 {
  226. stageStatus = "已审核"
  227. if splan.IsAck[stage.BillId] {
  228. stageStatus = "已接单"
  229. } else {
  230. stageStatus = "未接单"
  231. }
  232. } else {
  233. stageStatus = "未审核"
  234. }
  235. } else {
  236. stageStatus = "已完成"
  237. }
  238. }
  239. b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice)
  240. if stage.SupplierInfo != nil {
  241. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  242. }
  243. b.Row++
  244. }
  245. for supplierName, cate := range cates {
  246. mergeStartRow := cate[0]
  247. mergeEndRow := cate[len(cate)-1]
  248. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  249. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  250. }
  251. endRow := b.Row - 1
  252. // 组件名字
  253. startACell := fmt.Sprintf("%s%d", "B", startRow)
  254. endACell := fmt.Sprintf("%s%d", "B", endRow)
  255. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  256. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  257. if err != nil {
  258. return err
  259. }
  260. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  261. }
  262. // 预算
  263. planBudgetPrice += perBudgetPrice
  264. // 实际金额
  265. planRealPrice += perRealPrice
  266. }
  267. }
  268. totalBudgetPrice += planBudgetPrice
  269. totalRealPrice += planRealPrice
  270. // plan
  271. planEndRow := b.Row
  272. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  273. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  274. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  275. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  276. if err != nil {
  277. return err
  278. }
  279. b.Excel.SetCellValue(b.SheetName, planStartACell, plan.Name)
  280. }
  281. // summaryEndRow := b.Row
  282. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  283. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  284. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  285. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  286. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  287. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  288. // b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  289. // // 生产预算汇总
  290. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  291. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  292. // b.FormatToEmpty(&totalOrderRealPrice)
  293. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  294. // // 生产实际汇总
  295. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  296. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  297. // b.FormatToEmpty(&totalRealPricef)
  298. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  299. return nil
  300. }
  301. func (b *PlanSummaryExcel) drawSupplierContent() error {
  302. b.Row += 2
  303. supplier := ""
  304. // summaryPlans
  305. // 预算金额汇总
  306. var totalBudgetPrice float64 = 0.00
  307. // 实际金额汇总
  308. var totalRealPrice float64 = 0.00
  309. for _, splan := range b.Content.Plans {
  310. planStartRow := b.Row
  311. plan := splan.Plan
  312. comps := plan.Pack.Components
  313. // 预算金额汇总
  314. var planBudgetPrice float64 = 0.00
  315. // 实际金额汇总
  316. var planRealPrice float64 = 0.00
  317. if len(comps) > 0 {
  318. for _, comp := range comps {
  319. var perBudgetPrice float64 = 0.00
  320. var perRealPrice float64 = 0.00
  321. if len(comp.Stages) > 0 {
  322. startRow := 0
  323. cates := map[string][]int{}
  324. for _, stage := range comp.Stages {
  325. if stage.SupplierInfo != nil {
  326. if b.Content.SupplierId == stage.SupplierInfo.Id {
  327. supplier = stage.SupplierInfo.Name
  328. // 材料
  329. if startRow == 0 {
  330. startRow = b.Row
  331. }
  332. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  333. b.FormatToEmpty(&matHeigth)
  334. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  335. b.FormatToEmpty(&matWidth)
  336. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  337. b.FormatToEmpty(&orderCount)
  338. // 实际数量
  339. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  340. b.FormatToEmpty(&realCount)
  341. // 单价
  342. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  343. b.FormatToEmpty(&price)
  344. // 预算金额
  345. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  346. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  347. b.FormatToEmpty(&budgetPrice)
  348. // 实际金额
  349. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  350. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  351. b.FormatToEmpty(&realPrice)
  352. unit := stage.Unit
  353. if stage.Unit == "吨" || stage.Unit == "平方米" {
  354. unit = "张"
  355. }
  356. supplierName := ""
  357. if stage.SupplierInfo != nil {
  358. supplierName = stage.SupplierInfo.Name
  359. }
  360. stageType := ""
  361. if stage.BillType > 0 {
  362. stage.Type = stage.BillType
  363. }
  364. if stage.Type == 1 {
  365. stageType = "材料采购"
  366. }
  367. if stage.Type == 2 {
  368. stageType = "工艺"
  369. }
  370. if stage.Type == 3 {
  371. stageType = "成品采购"
  372. }
  373. // 状态
  374. stageStatus := ""
  375. // if len(stage.BillId) < 1 {
  376. // stageStatus = "未生成订单"
  377. // }
  378. // if splan.State[stage.BillId] == "created" {
  379. // stageStatus = "进行中"
  380. // }
  381. // // 审核状态
  382. // if splan.Reviewed[stage.BillId] == 1 {
  383. // stageStatus = "已审核"
  384. // } else {
  385. // stageStatus = "未审核"
  386. // }
  387. // // 接单状态
  388. // if splan.IsAck[stage.BillId] {
  389. // stageStatus = "已接单"
  390. // } else {
  391. // stageStatus = "未接单"
  392. // }
  393. // // 完成状态
  394. // if splan.State[stage.BillId] == "complete" {
  395. // stageStatus = "已完成"
  396. // }
  397. if len(stage.BillId) < 1 {
  398. stageStatus = "未生成订单"
  399. } else {
  400. if splan.State[stage.BillId] == "created" {
  401. stageStatus = "进行中"
  402. // 审核状态
  403. if splan.Reviewed[stage.BillId] == 1 {
  404. stageStatus = "已审核"
  405. if splan.IsAck[stage.BillId] {
  406. stageStatus = "已接单"
  407. } else {
  408. stageStatus = "未接单"
  409. }
  410. } else {
  411. stageStatus = "未审核"
  412. }
  413. } else {
  414. stageStatus = "已完成"
  415. }
  416. }
  417. b.drawRow(b.Row, "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice)
  418. if stage.SupplierInfo != nil {
  419. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  420. }
  421. b.Row++
  422. }
  423. }
  424. }
  425. // 合并同一供应商名
  426. for supplierName, cate := range cates {
  427. mergeStartRow := cate[0]
  428. mergeEndRow := cate[len(cate)-1]
  429. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  430. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  431. }
  432. if startRow != 0 {
  433. endRow := b.Row - 1
  434. // 组件名字
  435. startACell := fmt.Sprintf("%s%d", "B", startRow)
  436. endACell := fmt.Sprintf("%s%d", "B", endRow)
  437. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  438. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  439. if err != nil {
  440. return err
  441. }
  442. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  443. }
  444. }
  445. // 预算
  446. totalBudgetPrice += perBudgetPrice
  447. // 预算
  448. totalRealPrice += perRealPrice
  449. }
  450. }
  451. totalBudgetPrice += planBudgetPrice
  452. totalRealPrice += planRealPrice
  453. // plan
  454. // b.row +2 分割每个计划
  455. planEndRow := b.Row
  456. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  457. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  458. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  459. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  460. if err != nil {
  461. return err
  462. }
  463. b.Excel.SetCellValue(b.SheetName, planStartACell, plan.Name)
  464. }
  465. // summaryEndRow := b.Row
  466. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  467. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  468. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  469. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  470. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  471. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  472. // b.Excel.SetCellValue(b.SheetName, startACell, fmt.Sprintf("【%s】生产计划汇总金额", supplier))
  473. // // 生产预算汇总
  474. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  475. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  476. // b.FormatToEmpty(&totalOrderRealPrice)
  477. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  478. // // 生产实际汇总
  479. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  480. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  481. // b.FormatToEmpty(&totalRealPricef)
  482. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  483. // 供应商名字标题
  484. style, err := b.Excel.NewStyle(&excelize.Style{
  485. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  486. })
  487. if err != nil {
  488. return err
  489. }
  490. err = b.Excel.SetCellStyle(b.SheetName, "A1", "G1", style)
  491. if err != nil {
  492. return err
  493. }
  494. b.Excel.SetRowHeight(b.SheetName, 1, 32)
  495. b.Excel.SetCellValue(b.SheetName, "A1", fmt.Sprintf("【%s】-汇总表", supplier))
  496. return nil
  497. }
  498. func (b *PlanSummaryExcel) Draws() {
  499. b.drawTitle()
  500. b.drawTableTitle()
  501. if !b.Content.SupplierId.IsZero() {
  502. b.drawSupplierContent()
  503. } else {
  504. b.drawAllContent()
  505. }
  506. }
  507. func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
  508. border := []excelize.Border{
  509. {Type: "top", Style: 1, Color: "000000"},
  510. {Type: "left", Style: 1, Color: "000000"},
  511. {Type: "right", Style: 1, Color: "000000"},
  512. {Type: "bottom", Style: 1, Color: "000000"},
  513. }
  514. styleLeft, _ := f.NewStyle(&excelize.Style{
  515. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  516. Border: border,
  517. Font: &excelize.Font{Size: 10},
  518. })
  519. b := &PlanSummaryExcel{
  520. Title: "生产成本表",
  521. SheetName: "Sheet1",
  522. Excel: f,
  523. AlignCenterStyle: styleLeft,
  524. }
  525. f.SetColWidth(b.SheetName, "A", "D", 16)
  526. f.SetColWidth(b.SheetName, "E", "G", 12)
  527. f.SetColWidth(b.SheetName, "H", "H", 25)
  528. f.SetColWidth(b.SheetName, "I", "L", 16)
  529. f.SetColWidth(b.SheetName, "M", "M", 10)
  530. f.SetColWidth(b.SheetName, "N", "P", 16)
  531. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  532. return b
  533. }
  534. func (b *PlanSummaryExcel) FormatToEmpty(str *string) {
  535. if *str == "0" || *str == "0.000" {
  536. *str = ""
  537. }
  538. }