plan-summary-excel.go 20 KB

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