plan-summary-excel.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 if splan.State[stage.BillId] == "complete" {
  236. stageStatus = "已完成"
  237. } else {
  238. stageStatus = "订单已销毁"
  239. }
  240. }
  241. 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)
  242. if stage.SupplierInfo != nil {
  243. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  244. }
  245. b.Row++
  246. }
  247. for supplierName, cate := range cates {
  248. mergeStartRow := cate[0]
  249. mergeEndRow := cate[len(cate)-1]
  250. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  251. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  252. }
  253. endRow := b.Row - 1
  254. // 组件名字
  255. startACell := fmt.Sprintf("%s%d", "B", startRow)
  256. endACell := fmt.Sprintf("%s%d", "B", endRow)
  257. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  258. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  259. if err != nil {
  260. return err
  261. }
  262. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  263. }
  264. // 预算
  265. planBudgetPrice += perBudgetPrice
  266. // 实际金额
  267. planRealPrice += perRealPrice
  268. }
  269. }
  270. totalBudgetPrice += planBudgetPrice
  271. totalRealPrice += planRealPrice
  272. // plan
  273. planEndRow := b.Row
  274. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  275. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  276. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  277. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  278. if err != nil {
  279. return err
  280. }
  281. b.Excel.SetCellValue(b.SheetName, planStartACell, plan.Name)
  282. }
  283. // summaryEndRow := b.Row
  284. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  285. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  286. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  287. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  288. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  289. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  290. // b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  291. // // 生产预算汇总
  292. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  293. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  294. // b.FormatToEmpty(&totalOrderRealPrice)
  295. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  296. // // 生产实际汇总
  297. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  298. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  299. // b.FormatToEmpty(&totalRealPricef)
  300. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  301. return nil
  302. }
  303. func (b *PlanSummaryExcel) drawSupplierContent() error {
  304. b.Row += 2
  305. supplier := ""
  306. // summaryPlans
  307. // 预算金额汇总
  308. var totalBudgetPrice float64 = 0.00
  309. // 实际金额汇总
  310. var totalRealPrice float64 = 0.00
  311. for _, splan := range b.Content.Plans {
  312. planStartRow := b.Row
  313. plan := splan.Plan
  314. comps := plan.Pack.Components
  315. // 预算金额汇总
  316. var planBudgetPrice float64 = 0.00
  317. // 实际金额汇总
  318. var planRealPrice float64 = 0.00
  319. if len(comps) > 0 {
  320. for _, comp := range comps {
  321. var perBudgetPrice float64 = 0.00
  322. var perRealPrice float64 = 0.00
  323. if len(comp.Stages) > 0 {
  324. startRow := 0
  325. cates := map[string][]int{}
  326. for _, stage := range comp.Stages {
  327. if stage.SupplierInfo != nil {
  328. if b.Content.SupplierId == stage.SupplierInfo.Id {
  329. supplier = stage.SupplierInfo.Name
  330. // 材料
  331. if startRow == 0 {
  332. startRow = b.Row
  333. }
  334. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  335. b.FormatToEmpty(&matHeigth)
  336. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  337. b.FormatToEmpty(&matWidth)
  338. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  339. b.FormatToEmpty(&orderCount)
  340. // 实际数量
  341. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  342. b.FormatToEmpty(&realCount)
  343. // 单价
  344. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  345. b.FormatToEmpty(&price)
  346. // 预算金额
  347. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  348. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  349. b.FormatToEmpty(&budgetPrice)
  350. // 实际金额
  351. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  352. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  353. b.FormatToEmpty(&realPrice)
  354. unit := stage.Unit
  355. if stage.Unit == "吨" || stage.Unit == "平方米" {
  356. unit = "张"
  357. }
  358. supplierName := ""
  359. if stage.SupplierInfo != nil {
  360. supplierName = stage.SupplierInfo.Name
  361. }
  362. stageType := ""
  363. if stage.BillType > 0 {
  364. stage.Type = stage.BillType
  365. }
  366. if stage.Type == 1 {
  367. stageType = "材料采购"
  368. }
  369. if stage.Type == 2 {
  370. stageType = "工艺"
  371. }
  372. if stage.Type == 3 {
  373. stageType = "成品采购"
  374. }
  375. // 状态
  376. stageStatus := ""
  377. // if len(stage.BillId) < 1 {
  378. // stageStatus = "未生成订单"
  379. // }
  380. // if splan.State[stage.BillId] == "created" {
  381. // stageStatus = "进行中"
  382. // }
  383. // // 审核状态
  384. // if splan.Reviewed[stage.BillId] == 1 {
  385. // stageStatus = "已审核"
  386. // } else {
  387. // stageStatus = "未审核"
  388. // }
  389. // // 接单状态
  390. // if splan.IsAck[stage.BillId] {
  391. // stageStatus = "已接单"
  392. // } else {
  393. // stageStatus = "未接单"
  394. // }
  395. // // 完成状态
  396. // if splan.State[stage.BillId] == "complete" {
  397. // stageStatus = "已完成"
  398. // }
  399. if len(stage.BillId) < 1 {
  400. stageStatus = "未生成订单"
  401. } else {
  402. if splan.State[stage.BillId] == "created" {
  403. stageStatus = "进行中"
  404. // 审核状态
  405. if splan.Reviewed[stage.BillId] == 1 {
  406. stageStatus = "已审核"
  407. if splan.IsAck[stage.BillId] {
  408. stageStatus = "已接单"
  409. } else {
  410. stageStatus = "未接单"
  411. }
  412. } else {
  413. stageStatus = "未审核"
  414. }
  415. } else if splan.State[stage.BillId] == "complete" {
  416. stageStatus = "已完成"
  417. } else {
  418. stageStatus = "订单已销毁"
  419. }
  420. }
  421. 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)
  422. if stage.SupplierInfo != nil {
  423. cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  424. }
  425. b.Row++
  426. }
  427. }
  428. }
  429. // 合并同一供应商名
  430. for supplierName, cate := range cates {
  431. mergeStartRow := cate[0]
  432. mergeEndRow := cate[len(cate)-1]
  433. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  434. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  435. }
  436. if startRow != 0 {
  437. endRow := b.Row - 1
  438. // 组件名字
  439. startACell := fmt.Sprintf("%s%d", "B", startRow)
  440. endACell := fmt.Sprintf("%s%d", "B", endRow)
  441. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  442. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  443. if err != nil {
  444. return err
  445. }
  446. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  447. }
  448. }
  449. // 预算
  450. totalBudgetPrice += perBudgetPrice
  451. // 预算
  452. totalRealPrice += perRealPrice
  453. }
  454. }
  455. totalBudgetPrice += planBudgetPrice
  456. totalRealPrice += planRealPrice
  457. // plan
  458. // b.row +2 分割每个计划
  459. planEndRow := b.Row
  460. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  461. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  462. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  463. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  464. if err != nil {
  465. return err
  466. }
  467. b.Excel.SetCellValue(b.SheetName, planStartACell, plan.Name)
  468. }
  469. // summaryEndRow := b.Row
  470. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  471. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  472. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  473. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  474. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  475. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  476. // b.Excel.SetCellValue(b.SheetName, startACell, fmt.Sprintf("【%s】生产计划汇总金额", supplier))
  477. // // 生产预算汇总
  478. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  479. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  480. // b.FormatToEmpty(&totalOrderRealPrice)
  481. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  482. // // 生产实际汇总
  483. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  484. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  485. // b.FormatToEmpty(&totalRealPricef)
  486. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  487. // 供应商名字标题
  488. style, err := b.Excel.NewStyle(&excelize.Style{
  489. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  490. })
  491. if err != nil {
  492. return err
  493. }
  494. err = b.Excel.SetCellStyle(b.SheetName, "A1", "G1", style)
  495. if err != nil {
  496. return err
  497. }
  498. b.Excel.SetRowHeight(b.SheetName, 1, 32)
  499. b.Excel.SetCellValue(b.SheetName, "A1", fmt.Sprintf("【%s】-汇总表", supplier))
  500. return nil
  501. }
  502. func (b *PlanSummaryExcel) Draws() {
  503. b.drawTitle()
  504. b.drawTableTitle()
  505. if !b.Content.SupplierId.IsZero() {
  506. b.drawSupplierContent()
  507. } else {
  508. b.drawAllContent()
  509. }
  510. }
  511. func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
  512. border := []excelize.Border{
  513. {Type: "top", Style: 1, Color: "000000"},
  514. {Type: "left", Style: 1, Color: "000000"},
  515. {Type: "right", Style: 1, Color: "000000"},
  516. {Type: "bottom", Style: 1, Color: "000000"},
  517. }
  518. styleLeft, _ := f.NewStyle(&excelize.Style{
  519. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  520. Border: border,
  521. Font: &excelize.Font{Size: 10},
  522. })
  523. b := &PlanSummaryExcel{
  524. Title: "生产成本表",
  525. SheetName: "Sheet1",
  526. Excel: f,
  527. AlignCenterStyle: styleLeft,
  528. }
  529. f.SetColWidth(b.SheetName, "A", "D", 16)
  530. f.SetColWidth(b.SheetName, "E", "G", 12)
  531. f.SetColWidth(b.SheetName, "H", "H", 25)
  532. f.SetColWidth(b.SheetName, "I", "L", 16)
  533. f.SetColWidth(b.SheetName, "M", "M", 10)
  534. f.SetColWidth(b.SheetName, "N", "P", 16)
  535. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  536. return b
  537. }
  538. func (b *PlanSummaryExcel) FormatToEmpty(str *string) {
  539. if *str == "0" || *str == "0.000" {
  540. *str = ""
  541. }
  542. }