plan-summary-excel.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. // !10.27 如果是固定价格
  360. realPrice := fmt.Sprintf("%.3f", stage.OrderPrice*float64(stage.ConfirmCount))
  361. if stage.IsFix == nil {
  362. _fix := false
  363. stage.IsFix = &_fix
  364. }
  365. if *stage.IsFix {
  366. realPrice = budgetPrice
  367. perRealPrice += stage.OrderPrice * float64(stage.OrderCount)
  368. } else {
  369. perRealPrice += stage.OrderPrice * float64(stage.ConfirmCount)
  370. }
  371. b.FormatToEmpty(&realPrice)
  372. unit := stage.Unit
  373. // if stage.Unit == "吨" || stage.Unit == "平方米" {
  374. // unit = "张"
  375. // }
  376. supplierName := ""
  377. if stage.SupplierInfo != nil {
  378. supplierName = stage.SupplierInfo.Name
  379. }
  380. stageType := ""
  381. if stage.BillType > 0 {
  382. stage.Type = stage.BillType
  383. }
  384. if stage.Type == 1 {
  385. stageType = "材料采购"
  386. }
  387. if stage.Type == 2 {
  388. stageType = "工艺"
  389. }
  390. if stage.Type == 3 {
  391. stageType = "成品采购"
  392. }
  393. // 状态
  394. stageStatus := ""
  395. if len(stage.BillId) < 1 {
  396. stageStatus = "未生成订单"
  397. } else {
  398. if splan.State[stage.BillId] == "created" {
  399. stageStatus = "进行中"
  400. // 审核状态
  401. if splan.Reviewed[stage.BillId] == 1 {
  402. stageStatus = "已审核"
  403. if splan.IsSend[stage.BillId] {
  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. } else if splan.State[stage.BillId] == "complete" {
  417. stageStatus = "已完成"
  418. } else {
  419. stageStatus = "未生成订单"
  420. }
  421. }
  422. if len(stage.BillId) == 24 {
  423. billFlag := fmt.Sprintf("%s_%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"), splan.SendTo[stage.BillId])
  424. cates[billFlag] = append(cates[billFlag], b.Row)
  425. }
  426. b.drawRow(b.Row, "", "", "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit),
  427. stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark, "")
  428. // if stage.SupplierInfo != nil {
  429. // cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
  430. // }
  431. b.Row++
  432. }
  433. }
  434. }
  435. for billFlag, cate := range cates {
  436. billInfo := strings.Split(billFlag, "_")
  437. if len(billInfo) == 3 {
  438. mergeStartRow := cate[0]
  439. mergeEndRow := cate[len(cate)-1]
  440. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("C%d", mergeStartRow), fmt.Sprintf("C%d", mergeEndRow))
  441. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("C%d", mergeEndRow), billInfo[0])
  442. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
  443. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), billInfo[1])
  444. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("T%d", mergeStartRow), fmt.Sprintf("T%d", mergeEndRow))
  445. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("T%d", mergeEndRow), billInfo[2])
  446. }
  447. }
  448. // 合并同一供应商名
  449. // for supplierName, cate := range cates {
  450. // mergeStartRow := cate[0]
  451. // mergeEndRow := cate[len(cate)-1]
  452. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("H%d", mergeStartRow), fmt.Sprintf("H%d", mergeEndRow))
  453. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("H%d", mergeEndRow), supplierName)
  454. // }
  455. if startRow != 0 {
  456. endRow := b.Row - 1
  457. // 组件名字
  458. startACell := fmt.Sprintf("%s%d", "B", startRow)
  459. endACell := fmt.Sprintf("%s%d", "B", endRow)
  460. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  461. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  462. if err != nil {
  463. return err
  464. }
  465. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  466. }
  467. }
  468. // 预算
  469. totalBudgetPrice += perBudgetPrice
  470. // 预算
  471. totalRealPrice += perRealPrice
  472. }
  473. }
  474. if !isContainSupplier {
  475. continue
  476. }
  477. totalBudgetPrice += planBudgetPrice
  478. totalRealPrice += planRealPrice
  479. // 产品名称
  480. planEndRow := b.Row
  481. planStartACell := fmt.Sprintf("%s%d", "A", planStartRow)
  482. planEndACell := fmt.Sprintf("%s%d", "A", planEndRow-1)
  483. b.Excel.MergeCell(b.SheetName, planStartACell, planEndACell)
  484. err := b.Excel.SetCellStyle(b.SheetName, planStartACell, planEndACell, b.AlignCenterStyle)
  485. if err != nil {
  486. return err
  487. }
  488. b.Excel.SetCellValue(b.SheetName, planStartACell, fmt.Sprintf("%s(%d)", plan.Name, plan.Total))
  489. }
  490. // summaryEndRow := b.Row
  491. // startACell := fmt.Sprintf("%s%d", "A", summaryEndRow)
  492. // endNell := fmt.Sprintf("%s%d", "N", summaryEndRow)
  493. // OCell := fmt.Sprintf("%s%d", "O", summaryEndRow)
  494. // PCell := fmt.Sprintf("%s%d", "P", summaryEndRow)
  495. // b.Excel.MergeCell(b.SheetName, startACell, endNell)
  496. // b.Excel.SetCellStyle(b.SheetName, startACell, endNell, b.AlignCenterStyle)
  497. // b.Excel.SetCellValue(b.SheetName, startACell, fmt.Sprintf("【%s】生产计划汇总金额", supplier))
  498. // // 生产预算汇总
  499. // b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  500. // totalOrderRealPrice := fmt.Sprintf("%.3f", totalBudgetPrice)
  501. // b.FormatToEmpty(&totalOrderRealPrice)
  502. // b.Excel.SetCellValue(b.SheetName, OCell, totalOrderRealPrice)
  503. // // 生产实际汇总
  504. // b.Excel.SetCellStyle(b.SheetName, PCell, PCell, b.AlignCenterStyle)
  505. // totalRealPricef := fmt.Sprintf("%.3f", totalRealPrice)
  506. // b.FormatToEmpty(&totalRealPricef)
  507. // b.Excel.SetCellValue(b.SheetName, PCell, totalRealPricef)
  508. // 供应商名字标题
  509. style, err := b.Excel.NewStyle(&excelize.Style{
  510. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  511. })
  512. if err != nil {
  513. return err
  514. }
  515. err = b.Excel.SetCellStyle(b.SheetName, "A1", "T1", style)
  516. if err != nil {
  517. return err
  518. }
  519. b.Excel.SetRowHeight(b.SheetName, 1, 32)
  520. b.Excel.SetCellValue(b.SheetName, "A1", fmt.Sprintf("【%s】-汇总表", supplier))
  521. return nil
  522. }
  523. func (b *PlanSummaryExcel) Draws() {
  524. b.drawTitle()
  525. b.drawTableTitle()
  526. if !b.Content.SupplierId.IsZero() {
  527. b.drawSupplierContent()
  528. } else {
  529. b.drawAllContent()
  530. }
  531. }
  532. func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
  533. border := []excelize.Border{
  534. {Type: "top", Style: 1, Color: "000000"},
  535. {Type: "left", Style: 1, Color: "000000"},
  536. {Type: "right", Style: 1, Color: "000000"},
  537. {Type: "bottom", Style: 1, Color: "000000"},
  538. }
  539. styleLeft, _ := f.NewStyle(&excelize.Style{
  540. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  541. Border: border,
  542. Font: &excelize.Font{Size: 10},
  543. })
  544. b := &PlanSummaryExcel{
  545. Title: "生产成本表",
  546. SheetName: "Sheet1",
  547. Excel: f,
  548. AlignCenterStyle: styleLeft,
  549. }
  550. f.SetColWidth(b.SheetName, "A", "D", 16)
  551. f.SetColWidth(b.SheetName, "E", "E", 12)
  552. f.SetColWidth(b.SheetName, "F", "F", 16)
  553. f.SetColWidth(b.SheetName, "G", "I", 12)
  554. f.SetColWidth(b.SheetName, "J", "J", 25)
  555. f.SetColWidth(b.SheetName, "K", "L", 16)
  556. f.SetColWidth(b.SheetName, "M", "P", 12)
  557. f.SetColWidth(b.SheetName, "Q", "R", 16)
  558. f.SetColWidth(b.SheetName, "S", "S", 20)
  559. f.SetColWidth(b.SheetName, "T", "T", 40)
  560. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  561. return b
  562. }
  563. func (b *PlanSummaryExcel) FormatToEmpty(str *string) {
  564. if *str == "0" || *str == "0.000" {
  565. *str = ""
  566. }
  567. }