plan-summary-excel.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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("T%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. drawCol("T", "送货地址")
  120. return nil
  121. }
  122. func (b *PlanSummaryExcel) drawRow(rowIndex int, values ...string) {
  123. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"}
  124. for i, c := range charas {
  125. v := ""
  126. if i < len(values) {
  127. v = values[i]
  128. }
  129. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  130. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  131. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  132. b.Excel.SetRowHeight(b.SheetName, rowIndex, 32)
  133. }
  134. }
  135. func (b *PlanSummaryExcel) drawAllContent() error {
  136. b.Row += 2
  137. // summaryPlans
  138. // 预算金额汇总
  139. var totalBudgetPrice float64 = 0.00
  140. // 实际金额汇总
  141. var totalRealPrice float64 = 0.00
  142. for _, splan := range b.Content.Plans {
  143. planStartRow := b.Row
  144. plan := splan.Plan
  145. comps := plan.Pack.Components
  146. // 预算金额汇总
  147. var planBudgetPrice float64 = 0.00
  148. // 实际金额汇总
  149. var planRealPrice float64 = 0.00
  150. if len(comps) > 0 {
  151. for _, comp := range comps {
  152. var perBudgetPrice float64 = 0.00
  153. var perRealPrice float64 = 0.00
  154. if len(comp.Stages) > 0 {
  155. startRow := b.Row
  156. cates := map[string][]int{}
  157. for _, stage := range comp.Stages {
  158. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  159. b.FormatToEmpty(&matHeigth)
  160. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  161. b.FormatToEmpty(&matWidth)
  162. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  163. b.FormatToEmpty(&orderCount)
  164. // 实际数量
  165. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  166. b.FormatToEmpty(&realCount)
  167. // 单价
  168. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  169. b.FormatToEmpty(&price)
  170. // 预算金额
  171. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  172. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  173. b.FormatToEmpty(&budgetPrice)
  174. // 实际金额
  175. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  176. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  177. b.FormatToEmpty(&realPrice)
  178. unit := stage.Unit
  179. if stage.Unit == "吨" || stage.Unit == "平方米" {
  180. unit = "张"
  181. }
  182. supplierName := ""
  183. if stage.SupplierInfo != nil {
  184. supplierName = stage.SupplierInfo.Name
  185. }
  186. stageType := ""
  187. if stage.BillType > 0 {
  188. stage.Type = stage.BillType
  189. }
  190. if stage.Type == 1 {
  191. stageType = "材料采购"
  192. }
  193. if stage.Type == 2 {
  194. stageType = "工艺"
  195. }
  196. if stage.Type == 3 {
  197. stageType = "成品采购"
  198. }
  199. // 状态
  200. stageStatus := ""
  201. if len(stage.BillId) < 1 {
  202. stageStatus = "未生成订单"
  203. } else {
  204. if splan.State[stage.BillId] == "created" {
  205. stageStatus = "进行中"
  206. // 审核状态
  207. if splan.Reviewed[stage.BillId] == 1 {
  208. stageStatus = "已审核"
  209. if splan.IsSend[stage.BillId] {
  210. stageStatus = "已发送"
  211. if splan.IsAck[stage.BillId] {
  212. stageStatus = "已接单"
  213. } else {
  214. stageStatus = "未接单"
  215. }
  216. } else {
  217. stageStatus = "未发送"
  218. }
  219. } else {
  220. stageStatus = "未审核"
  221. }
  222. } else if splan.State[stage.BillId] == "complete" {
  223. stageStatus = "已完成"
  224. } else {
  225. stageStatus = "未生成订单"
  226. }
  227. }
  228. // 订单存在时,订单号和下单时间// 合并相同的订单,记录row方便合并
  229. if len(stage.BillId) == 24 {
  230. billFlag := fmt.Sprintf("%s_%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"), splan.SendTo[stage.BillId])
  231. cates[billFlag] = append(cates[billFlag], b.Row)
  232. }
  233. b.drawRow(b.Row, "", "", "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm,
  234. matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark, "")
  235. // if stage.SupplierInfo != nil {
  236. // cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  237. // }
  238. b.Row++
  239. }
  240. for billFlag, cate := range cates {
  241. billInfo := strings.Split(billFlag, "_")
  242. if len(billInfo) == 3 {
  243. mergeStartRow := cate[0]
  244. mergeEndRow := cate[len(cate)-1]
  245. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("C%d", mergeStartRow), fmt.Sprintf("C%d", mergeEndRow))
  246. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("C%d", mergeEndRow), billInfo[0])
  247. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
  248. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), billInfo[1])
  249. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("T%d", mergeStartRow), fmt.Sprintf("T%d", mergeEndRow))
  250. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("T%d", mergeEndRow), billInfo[2])
  251. }
  252. }
  253. // for supplierName, cate := range cates {
  254. // mergeStartRow := cate[0]
  255. // mergeEndRow := cate[len(cate)-1]
  256. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  257. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  258. // }
  259. endRow := b.Row - 1
  260. // 组件名字
  261. startACell := fmt.Sprintf("%s%d", "B", startRow)
  262. endACell := fmt.Sprintf("%s%d", "B", endRow)
  263. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  264. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  265. if err != nil {
  266. return err
  267. }
  268. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  269. }
  270. // 预算
  271. planBudgetPrice += perBudgetPrice
  272. // 实际金额
  273. planRealPrice += perRealPrice
  274. }
  275. }
  276. totalBudgetPrice += planBudgetPrice
  277. totalRealPrice += planRealPrice
  278. // plan
  279. planEndRow := b.Row
  280. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  281. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  282. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  283. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  284. if err != nil {
  285. return err
  286. }
  287. b.Excel.SetCellValue(b.SheetName, planStartACell, fmt.Sprintf("%s(%d)", plan.Name, plan.Total))
  288. }
  289. // summaryEndRow := b.Row
  290. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  291. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  292. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  293. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  294. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  295. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  296. // b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  297. // // 生产预算汇总
  298. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  299. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  300. // b.FormatToEmpty(&totalOrderRealPrice)
  301. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  302. // // 生产实际汇总
  303. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  304. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  305. // b.FormatToEmpty(&totalRealPricef)
  306. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  307. return nil
  308. }
  309. func (b *PlanSummaryExcel) drawSupplierContent() error {
  310. b.Row += 2
  311. supplier := ""
  312. // summaryPlans
  313. // 预算金额汇总
  314. var totalBudgetPrice float64 = 0.00
  315. // 实际金额汇总
  316. var totalRealPrice float64 = 0.00
  317. for _, splan := range b.Content.Plans {
  318. planStartRow := b.Row
  319. isContainSupplier := false
  320. plan := splan.Plan
  321. comps := plan.Pack.Components
  322. // 预算金额汇总
  323. var planBudgetPrice float64 = 0.00
  324. // 实际金额汇总
  325. var planRealPrice float64 = 0.00
  326. if len(comps) > 0 {
  327. for _, comp := range comps {
  328. var perBudgetPrice float64 = 0.00
  329. var perRealPrice float64 = 0.00
  330. if len(comp.Stages) > 0 {
  331. startRow := 0
  332. cates := map[string][]int{}
  333. for _, stage := range comp.Stages {
  334. if stage.SupplierInfo != nil {
  335. if b.Content.SupplierId == stage.SupplierInfo.Id {
  336. supplier = stage.SupplierInfo.Name
  337. isContainSupplier = true
  338. // 材料
  339. if startRow == 0 {
  340. startRow = b.Row
  341. }
  342. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  343. b.FormatToEmpty(&matHeigth)
  344. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  345. b.FormatToEmpty(&matWidth)
  346. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  347. b.FormatToEmpty(&orderCount)
  348. // 实际数量
  349. realCount := fmt.Sprintf("%d", stage.ConfirmCount)
  350. b.FormatToEmpty(&realCount)
  351. // 单价
  352. price := fmt.Sprintf("%.3f", stage.OrderPrice)
  353. b.FormatToEmpty(&price)
  354. // 预算金额
  355. budgetPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.OrderCount))
  356. perBudgetPrice += stage.OrderPrice * float64(stage.OrderCount)
  357. b.FormatToEmpty(&budgetPrice)
  358. // 实际金额
  359. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  360. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  361. b.FormatToEmpty(&realPrice)
  362. unit := stage.Unit
  363. if stage.Unit == "吨" || stage.Unit == "平方米" {
  364. unit = "张"
  365. }
  366. supplierName := ""
  367. if stage.SupplierInfo != nil {
  368. supplierName = stage.SupplierInfo.Name
  369. }
  370. stageType := ""
  371. if stage.BillType > 0 {
  372. stage.Type = stage.BillType
  373. }
  374. if stage.Type == 1 {
  375. stageType = "材料采购"
  376. }
  377. if stage.Type == 2 {
  378. stageType = "工艺"
  379. }
  380. if stage.Type == 3 {
  381. stageType = "成品采购"
  382. }
  383. // 状态
  384. stageStatus := ""
  385. if len(stage.BillId) < 1 {
  386. stageStatus = "未生成订单"
  387. } else {
  388. if splan.State[stage.BillId] == "created" {
  389. stageStatus = "进行中"
  390. // 审核状态
  391. if splan.Reviewed[stage.BillId] == 1 {
  392. stageStatus = "已审核"
  393. if splan.IsSend[stage.BillId] {
  394. stageStatus = "已发送"
  395. if splan.IsAck[stage.BillId] {
  396. stageStatus = "已接单"
  397. } else {
  398. stageStatus = "未接单"
  399. }
  400. } else {
  401. stageStatus = "未发送"
  402. }
  403. } else {
  404. stageStatus = "未审核"
  405. }
  406. } else if splan.State[stage.BillId] == "complete" {
  407. stageStatus = "已完成"
  408. } else {
  409. stageStatus = "未生成订单"
  410. }
  411. }
  412. if len(stage.BillId) == 24 {
  413. billFlag := fmt.Sprintf("%s_%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"), splan.SendTo[stage.BillId])
  414. cates[billFlag] = append(cates[billFlag], b.Row)
  415. }
  416. b.drawRow(b.Row, "", "", "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit),
  417. stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark, "")
  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. for billFlag, cate := range cates {
  426. billInfo := strings.Split(billFlag, "_")
  427. if len(billInfo) == 3 {
  428. mergeStartRow := cate[0]
  429. mergeEndRow := cate[len(cate)-1]
  430. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("C%d", mergeStartRow), fmt.Sprintf("C%d", mergeEndRow))
  431. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("C%d", mergeEndRow), billInfo[0])
  432. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
  433. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), billInfo[1])
  434. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("T%d", mergeStartRow), fmt.Sprintf("T%d", mergeEndRow))
  435. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("T%d", mergeEndRow), billInfo[2])
  436. }
  437. }
  438. // 合并同一供应商名
  439. // for supplierName, cate := range cates {
  440. // mergeStartRow := cate[0]
  441. // mergeEndRow := cate[len(cate)-1]
  442. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  443. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  444. // }
  445. if startRow != 0 {
  446. endRow := b.Row - 1
  447. // 组件名字
  448. startACell := fmt.Sprintf("%s%d", "B", startRow)
  449. endACell := fmt.Sprintf("%s%d", "B", endRow)
  450. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  451. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  452. if err != nil {
  453. return err
  454. }
  455. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  456. }
  457. }
  458. // 预算
  459. totalBudgetPrice += perBudgetPrice
  460. // 预算
  461. totalRealPrice += perRealPrice
  462. }
  463. }
  464. if !isContainSupplier {
  465. continue
  466. }
  467. totalBudgetPrice += planBudgetPrice
  468. totalRealPrice += planRealPrice
  469. // 产品名称
  470. planEndRow := b.Row
  471. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  472. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  473. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  474. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  475. if err != nil {
  476. return err
  477. }
  478. b.Excel.SetCellValue(b.SheetName, planStartACell, fmt.Sprintf("%s(%d)", plan.Name, plan.Total))
  479. }
  480. // summaryEndRow := b.Row
  481. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  482. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  483. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  484. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  485. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  486. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  487. // b.Excel.SetCellValue(b.SheetName, startACell, fmt.Sprintf("【%s】生产计划汇总金额", supplier))
  488. // // 生产预算汇总
  489. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  490. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  491. // b.FormatToEmpty(&totalOrderRealPrice)
  492. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  493. // // 生产实际汇总
  494. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  495. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  496. // b.FormatToEmpty(&totalRealPricef)
  497. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  498. // 供应商名字标题
  499. style, err := b.Excel.NewStyle(&excelize.Style{
  500. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  501. })
  502. if err != nil {
  503. return err
  504. }
  505. err = b.Excel.SetCellStyle(b.SheetName, "A1", "T1", style)
  506. if err != nil {
  507. return err
  508. }
  509. b.Excel.SetRowHeight(b.SheetName, 1, 32)
  510. b.Excel.SetCellValue(b.SheetName, "A1", fmt.Sprintf("【%s】-汇总表", supplier))
  511. return nil
  512. }
  513. func (b *PlanSummaryExcel) Draws() {
  514. b.drawTitle()
  515. b.drawTableTitle()
  516. if !b.Content.SupplierId.IsZero() {
  517. b.drawSupplierContent()
  518. } else {
  519. b.drawAllContent()
  520. }
  521. }
  522. func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
  523. border := []excelize.Border{
  524. {Type: "top", Style: 1, Color: "000000"},
  525. {Type: "left", Style: 1, Color: "000000"},
  526. {Type: "right", Style: 1, Color: "000000"},
  527. {Type: "bottom", Style: 1, Color: "000000"},
  528. }
  529. styleLeft, _ := f.NewStyle(&excelize.Style{
  530. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  531. Border: border,
  532. Font: &excelize.Font{Size: 10},
  533. })
  534. b := &PlanSummaryExcel{
  535. Title: "生产成本表",
  536. SheetName: "Sheet1",
  537. Excel: f,
  538. AlignCenterStyle: styleLeft,
  539. }
  540. f.SetColWidth(b.SheetName, "A", "D", 16)
  541. f.SetColWidth(b.SheetName, "E", "E", 12)
  542. f.SetColWidth(b.SheetName, "F", "F", 16)
  543. f.SetColWidth(b.SheetName, "G", "I", 12)
  544. f.SetColWidth(b.SheetName, "J", "J", 25)
  545. f.SetColWidth(b.SheetName, "K", "L", 16)
  546. f.SetColWidth(b.SheetName, "M", "P", 12)
  547. f.SetColWidth(b.SheetName, "Q", "R", 16)
  548. f.SetColWidth(b.SheetName, "S", "S", 20)
  549. f.SetColWidth(b.SheetName, "T", "T", 40)
  550. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  551. return b
  552. }
  553. func (b *PlanSummaryExcel) FormatToEmpty(str *string) {
  554. if *str == "0" || *str == "0.000" {
  555. *str = ""
  556. }
  557. }