plan-cost-excel.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. )
  6. // 生产成本表
  7. type PlanCostExcel struct {
  8. Offset int
  9. Row int
  10. Title string //标题
  11. Excel *excelize.File
  12. SheetName string
  13. AlignCenterStyle int
  14. // Content *model.ProductPlan
  15. Content *SupplierPlanCost
  16. }
  17. func (b *PlanCostExcel) drawTitle() error {
  18. // tileIndex := b.Offset + 1
  19. b.Row++
  20. startCell := fmt.Sprintf("A%d", b.Row)
  21. err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("M%d", b.Row))
  22. if err != nil {
  23. return err
  24. }
  25. style, err := b.Excel.NewStyle(&excelize.Style{
  26. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  27. Font: &excelize.Font{Bold: true, Size: 18}})
  28. if err != nil {
  29. return err
  30. }
  31. err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
  32. if err != nil {
  33. return err
  34. }
  35. b.Excel.SetRowHeight(b.SheetName, b.Row, 23)
  36. b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
  37. return nil
  38. }
  39. func (b *PlanCostExcel) drawTableTitle() error {
  40. // row := b.Offset + 2
  41. b.Row++
  42. //A采购项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
  43. // A产品名称
  44. var drawCol = func(prefix string, value string) error {
  45. left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
  46. left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
  47. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  48. if err != nil {
  49. return err
  50. }
  51. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  52. if err != nil {
  53. return err
  54. }
  55. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  56. }
  57. var drawCol2 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
  58. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  59. left2Cell := fmt.Sprintf("%s%d", prefix2, b.Row)
  60. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  61. if err != nil {
  62. return err
  63. }
  64. if err != nil {
  65. fmt.Println(err)
  66. return err
  67. }
  68. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  69. if err != nil {
  70. return err
  71. }
  72. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  73. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  74. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  75. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  76. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  77. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  78. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  79. return nil
  80. }
  81. var drawCol3 = func(prefix1 string, prefix2 string, prefix3 string, value1 string, value2 string, value3 string, value4 string) error {
  82. left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
  83. // left2Cell := fmt.Sprintf("%s%d", prefix2, row)
  84. left3Cell := fmt.Sprintf("%s%d", prefix3, b.Row)
  85. err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
  86. if err != nil {
  87. return err
  88. }
  89. if err != nil {
  90. fmt.Println(err)
  91. return err
  92. }
  93. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left3Cell, b.AlignCenterStyle)
  94. if err != nil {
  95. return err
  96. }
  97. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  98. val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
  99. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  100. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  101. val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
  102. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  103. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  104. val4Cel := fmt.Sprintf("%s%d", prefix3, b.Row+1)
  105. b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
  106. b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
  107. return nil
  108. }
  109. drawCol("A", "产品部件名称")
  110. drawCol2("B", "C", "材料/工序", "材料", "工序")
  111. drawCol("D", "供应商名称")
  112. drawCol3("E", "F", "G", "规格", "厚度(纸克)", "长", "宽")
  113. drawCol("H", "单位")
  114. drawCol("I", "下单数量")
  115. drawCol("J", "实际数量")
  116. drawCol("K", "单价")
  117. drawCol("L", "预算金额")
  118. drawCol("M", "实际金额")
  119. return nil
  120. }
  121. func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
  122. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
  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, 21)
  132. }
  133. }
  134. // func (b *PlanCostExcel) drawSupplierContent() error {
  135. // b.Row += 2
  136. // supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
  137. // if err != nil {
  138. // return err
  139. // }
  140. // comps := b.Content.Pack.Components
  141. // // 预算金额汇总
  142. // var totalOrderRealPrice float64 = 0.00
  143. // // 实际金额汇总
  144. // var totalRealPrice float64 = 0.00
  145. // if len(comps) > 0 {
  146. // for _, comp := range comps {
  147. // var perOrderRealPrice float64 = 0.00
  148. // var perRealPrice float64 = 0.00
  149. // if len(comp.Stages) > 0 {
  150. // startRow := 0
  151. // for _, mat := range comp.Mats {
  152. // if mat.Supplier.SupplierInfo != nil {
  153. // if supplierId == mat.Supplier.SupplierInfo.Id {
  154. // // 材料
  155. // if startRow == 0 {
  156. // startRow = row
  157. // }
  158. // supplierName := ""
  159. // if mat.Supplier.SupplierInfo != nil {
  160. // supplierName = mat.Supplier.SupplierInfo.Name
  161. // }
  162. // matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
  163. // b.FormatToEmpty(&matHeigth)
  164. // matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
  165. // b.FormatToEmpty(&matWidth)
  166. // orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
  167. // b.FormatToEmpty(&orderCount)
  168. // // 实际数量
  169. // confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
  170. // b.FormatToEmpty(&confirmCount)
  171. // // 单价
  172. // orderPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderPrice)
  173. // b.FormatToEmpty(&orderPrice)
  174. // // 预算金额
  175. // orderRealPrice := fmt.Sprintf("%.3f", mat.Supplier.OrderRealPrice)
  176. // perOrderRealPrice += mat.Supplier.OrderRealPrice
  177. // b.FormatToEmpty(&orderRealPrice)
  178. // // 实际金额
  179. // perRealPrice += mat.RealPrice
  180. // realPrice := fmt.Sprintf("%.3f", mat.RealPrice)
  181. // b.FormatToEmpty(&realPrice)
  182. // if mat.MatInfo.Unit == "吨" || mat.MatInfo.Unit == "平方米" {
  183. // mat.MatInfo.Unit = "张"
  184. // }
  185. // b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, realPrice)
  186. // row++
  187. // }
  188. // }
  189. // if len(mat.Crafts) > 0 {
  190. // // 实际数量、预算数量
  191. // // mergeStartRow := row
  192. // // mergeEndRow := row
  193. // cates := map[string]MergeRow{}
  194. // for _, craft := range mat.Crafts {
  195. // if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
  196. // // 工序
  197. // if supplierId == craft.Supplier.SupplierInfo.Id {
  198. // if startRow == 0 {
  199. // startRow = row
  200. // }
  201. // supplierName := ""
  202. // if craft.Supplier.SupplierInfo != nil {
  203. // supplierName = craft.Supplier.SupplierInfo.Name
  204. // }
  205. // orderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
  206. // b.FormatToEmpty(&orderCount)
  207. // carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
  208. // b.FormatToEmpty(&carftHeigth)
  209. // carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
  210. // b.FormatToEmpty(&carftWidth)
  211. // // 实际数量
  212. // confirmCount := fmt.Sprintf("%d", craft.ConfirmCount)
  213. // b.FormatToEmpty(&confirmCount)
  214. // price := fmt.Sprintf("%.3f", craft.Supplier.OrderPrice)
  215. // b.FormatToEmpty(&price)
  216. // // 预算金额
  217. // budgetAmount := ""
  218. // b.FormatToEmpty(&budgetAmount)
  219. // // 实际金额 在外层合并单元格
  220. // realAmount := ""
  221. // if craft.CraftInfo.Unit == "吨" || craft.CraftInfo.Unit == "平方米" {
  222. // craft.CraftInfo.Unit = "张"
  223. // }
  224. // b.drawRow(row, "", "", craft.CraftInfo.Name, supplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, orderCount, confirmCount, price, budgetAmount, realAmount)
  225. // // mergeEndRow = row
  226. // category := craft.CraftInfo.Category
  227. // cates[category] = MergeRow{
  228. // Rows: append(cates[category].Rows, row),
  229. // RealAmount: craft.RealPrice,
  230. // BudgetAmount: craft.Supplier.OrderRealPrice,
  231. // }
  232. // row++
  233. // }
  234. // }
  235. // }
  236. // fmt.Println(cates)
  237. // for _, cate := range cates {
  238. // mergeStartRow := cate.Rows[0]
  239. // mergeEndRow := cate.Rows[len(cate.Rows)-1]
  240. // orderRealPrice := cate.BudgetAmount
  241. // realPrice := cate.RealAmount
  242. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
  243. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), orderRealPrice)
  244. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
  245. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), realPrice)
  246. // perRealPrice += realPrice
  247. // perOrderRealPrice += orderRealPrice
  248. // }
  249. // // 多个工序 合并预算价格、实际价格
  250. // // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", mergeStartRow), fmt.Sprintf("L%d", mergeEndRow))
  251. // // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", mergeEndRow), mat.Crafts[0].Supplier.OrderRealPrice)
  252. // // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("M%d", mergeStartRow), fmt.Sprintf("M%d", mergeEndRow))
  253. // // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("M%d", mergeEndRow), mat.Crafts[0].RealPrice)
  254. // // perRealPrice += mat.Crafts[0].RealPrice
  255. // // perOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
  256. // }
  257. // }
  258. // if startRow != 0 {
  259. // endRow := row - 1
  260. // // 组件名字
  261. // startACell := fmt.Sprintf("%s%d", "A", startRow)
  262. // endACell := fmt.Sprintf("%s%d", "A", 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. // // 预算
  272. // totalOrderRealPrice += perOrderRealPrice
  273. // // 预算
  274. // totalRealPrice += perRealPrice
  275. // }
  276. // }
  277. // // 工序数据
  278. // if b.Content.Process != nil {
  279. // if len(b.Content.Process) > 0 {
  280. // isSupplier := false
  281. // for _, ps := range b.Content.Process {
  282. // if supplierId == ps.Supplier.SupplierInfo.Id {
  283. // isSupplier = true
  284. // break
  285. // }
  286. // }
  287. // if isSupplier {
  288. // // 生产汇总金额
  289. // startACell := fmt.Sprintf("%s%d", "A", row)
  290. // endMCell := fmt.Sprintf("%s%d", "K", row)
  291. // b.Excel.MergeCell(b.SheetName, startACell, endMCell)
  292. // b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
  293. // b.Excel.SetCellValue(b.SheetName, startACell, "额外工序")
  294. // row++
  295. // // 工序 外箱 手工费 表头
  296. // var drawCol = func(startCell, endCell string, value string) error {
  297. // left1Cell := fmt.Sprintf("%s%d", startCell, row)
  298. // left2Cell := fmt.Sprintf("%s%d", endCell, row)
  299. // err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  300. // if err != nil {
  301. // return err
  302. // }
  303. // err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  304. // if err != nil {
  305. // return err
  306. // }
  307. // return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  308. // }
  309. // drawCol("A", "A", "")
  310. // drawCol("B", "C", "材料/工序")
  311. // drawCol("D", "E", "供应商名称")
  312. // drawCol("F", "G", "规格")
  313. // drawCol("H", "H", "单位")
  314. // drawCol("I", "I", "下单数量")
  315. // drawCol("J", "J", "实际数量")
  316. // drawCol("K", "K", "单价")
  317. // drawCol("L", "L", "预算金额")
  318. // drawCol("M", "M", "实际金额")
  319. // row++
  320. // if len(b.Content.Process) > 0 {
  321. // for _, ps := range b.Content.Process {
  322. // orderCount := fmt.Sprintf("%.3f", ps.Supplier.OrderCount)
  323. // confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
  324. // price := fmt.Sprintf("%.3f", ps.Supplier.OrderPrice)
  325. // b.FormatToEmpty(&price)
  326. // totalOrderRealPrice += ps.Supplier.OrderRealPrice
  327. // totalRealPrice += ps.RealPrice
  328. // orderRealPrice := fmt.Sprintf("%.3f", ps.Supplier.OrderRealPrice)
  329. // b.FormatToEmpty(&orderRealPrice)
  330. // realPrice := fmt.Sprintf("%.3f", ps.RealPrice)
  331. // supplierName := ""
  332. // if ps.Supplier.SupplierInfo != nil {
  333. // supplierName = ps.Supplier.SupplierInfo.Name
  334. // }
  335. // b.drawRow(row, "", "", "", "", "", "", "", ps.ProcessInfo.Unit, orderCount, confirmCount, price, orderRealPrice, realPrice)
  336. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "B", row), fmt.Sprintf("%s%d", "C", row))
  337. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "B", row), ps.ProcessInfo.Name)
  338. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "D", row), fmt.Sprintf("%s%d", "E", row))
  339. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "D", row), supplierName)
  340. // b.Excel.MergeCell(b.SheetName, fmt.Sprintf("%s%d", "F", row), fmt.Sprintf("%s%d", "G", row))
  341. // b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", "F", row), ps.ProcessInfo.Norm)
  342. // row++
  343. // }
  344. // }
  345. // }
  346. // }
  347. // }
  348. // // 生产汇总金额
  349. // startACell := fmt.Sprintf("%s%d", "A", row)
  350. // endKCell := fmt.Sprintf("%s%d", "K", row)
  351. // LCell := fmt.Sprintf("%s%d", "L", row)
  352. // MCell := fmt.Sprintf("%s%d", "M", row)
  353. // b.Excel.MergeCell(b.SheetName, startACell, endKCell)
  354. // b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
  355. // b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  356. // // 生产预算汇总
  357. // b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
  358. // planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderRealPrice)
  359. // b.FormatToEmpty(&planOrderRealPrice)
  360. // b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
  361. // // 生产实际汇总
  362. // b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
  363. // planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
  364. // b.FormatToEmpty(&planRealPrice)
  365. // b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
  366. // return nil
  367. // }
  368. func (b *PlanCostExcel) drawAllContent() error {
  369. b.Row += 2
  370. comps := b.Content.Pack.Components
  371. // 预算金额汇总
  372. var totalOrderPrice float64 = 0.00
  373. // 实际金额汇总
  374. var totalRealPrice float64 = 0.00
  375. if len(comps) > 0 {
  376. for _, comp := range comps {
  377. var perOrderPrice float64 = 0.00
  378. var perRealPrice float64 = 0.00
  379. if len(comp.Stages) > 0 {
  380. startRow := b.Row
  381. for _, stage := range comp.Stages {
  382. // 材料
  383. supplierName := ""
  384. if stage.SupplierInfo != nil {
  385. supplierName = stage.SupplierInfo.Name
  386. }
  387. matHeigth := fmt.Sprintf("%d", stage.BatchSizeHeight)
  388. b.FormatToEmpty(&matHeigth)
  389. matWidth := fmt.Sprintf("%d", stage.BatchSizeWidth)
  390. b.FormatToEmpty(&matWidth)
  391. orderCount := fmt.Sprintf("%d", int(stage.OrderCount))
  392. b.FormatToEmpty(&orderCount)
  393. // 实际数量
  394. realCount := fmt.Sprintf("%d", stage.RealCount)
  395. b.FormatToEmpty(&realCount)
  396. // 单价
  397. price := fmt.Sprintf("%.3f", stage.Price)
  398. b.FormatToEmpty(&price)
  399. // 预算金额
  400. orderPrice := fmt.Sprintf("%.3f", stage.OrderPrice)
  401. perOrderPrice += stage.OrderPrice
  402. b.FormatToEmpty(&orderPrice)
  403. // 实际金额
  404. perRealPrice += stage.RealPrice
  405. realPrice := fmt.Sprintf("%.3f", stage.RealPrice)
  406. b.FormatToEmpty(&realPrice)
  407. if stage.Unit == "吨" || stage.Unit == "平方米" {
  408. stage.Unit = "张"
  409. }
  410. b.drawRow(b.Row, "", stage.Name, "", supplierName, stage.Norm, matHeigth, matWidth, stage.Unit, orderCount, realCount, price, orderPrice, realPrice)
  411. b.Row++
  412. }
  413. endRow := b.Row - 1
  414. // 组件名字
  415. startACell := fmt.Sprintf("%s%d", "A", startRow)
  416. endACell := fmt.Sprintf("%s%d", "A", endRow)
  417. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  418. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  419. if err != nil {
  420. return err
  421. }
  422. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  423. }
  424. // 预算
  425. totalOrderPrice += perOrderPrice
  426. // 实际金额
  427. totalRealPrice += perRealPrice
  428. }
  429. }
  430. startACell := fmt.Sprintf("%s%d", "A", b.Row)
  431. endKCell := fmt.Sprintf("%s%d", "K", b.Row)
  432. LCell := fmt.Sprintf("%s%d", "L", b.Row)
  433. MCell := fmt.Sprintf("%s%d", "M", b.Row)
  434. b.Excel.MergeCell(b.SheetName, startACell, endKCell)
  435. b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
  436. b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  437. // 生产预算汇总
  438. b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
  439. planOrderRealPrice := fmt.Sprintf("%.3f", totalOrderPrice)
  440. b.FormatToEmpty(&planOrderRealPrice)
  441. b.Excel.SetCellValue(b.SheetName, LCell, planOrderRealPrice)
  442. // 生产实际汇总
  443. b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
  444. planRealPrice := fmt.Sprintf("%.3f", totalRealPrice)
  445. b.FormatToEmpty(&planRealPrice)
  446. b.Excel.SetCellValue(b.SheetName, MCell, planRealPrice)
  447. return nil
  448. }
  449. func (b *PlanCostExcel) Draws() {
  450. b.drawTitle()
  451. b.drawTableTitle()
  452. // if b.Content.SupplierId != "" {
  453. // b.drawSupplierContent()
  454. // } else {
  455. // b.drawAllContent()
  456. // }
  457. b.drawAllContent()
  458. }
  459. func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
  460. border := []excelize.Border{
  461. {Type: "top", Style: 1, Color: "000000"},
  462. {Type: "left", Style: 1, Color: "000000"},
  463. {Type: "right", Style: 1, Color: "000000"},
  464. {Type: "bottom", Style: 1, Color: "000000"},
  465. }
  466. styleLeft, _ := f.NewStyle(&excelize.Style{
  467. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  468. Border: border,
  469. Font: &excelize.Font{Size: 10},
  470. })
  471. b := &PlanCostExcel{
  472. Title: "生产成本表",
  473. SheetName: "Sheet1",
  474. Excel: f,
  475. Offset: 0,
  476. AlignCenterStyle: styleLeft,
  477. }
  478. f.SetColWidth(b.SheetName, "A", "D", 12)
  479. f.SetColWidth(b.SheetName, "E", "M", 10)
  480. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  481. return b
  482. }
  483. func (b *PlanCostExcel) FormatToEmpty(str *string) {
  484. if *str == "0" || *str == "0.000" {
  485. *str = ""
  486. }
  487. }