plan-cost-excel.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. package api
  2. import (
  3. "fmt"
  4. "github.com/xuri/excelize/v2"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. )
  7. // 生产成本表
  8. type PlanCostExcel struct {
  9. Offset 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. startCell := fmt.Sprintf("A%d", tileIndex)
  20. err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("L%d", tileIndex))
  21. if err != nil {
  22. return err
  23. }
  24. style, err := b.Excel.NewStyle(&excelize.Style{
  25. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  26. Font: &excelize.Font{Bold: true, Size: 18}})
  27. if err != nil {
  28. return err
  29. }
  30. err = b.Excel.SetCellStyle(b.SheetName, startCell, startCell, style)
  31. if err != nil {
  32. return err
  33. }
  34. b.Excel.SetRowHeight(b.SheetName, tileIndex, 23)
  35. b.Excel.SetCellValue(b.SheetName, startCell, b.Title)
  36. return nil
  37. }
  38. func (b *PlanCostExcel) drawTableTitle() error {
  39. row := b.Offset + 2
  40. //A采购项目 B规格(克) 尺寸C-D 数量E 单价F-G 交货时间H 备注I
  41. // A产品名称
  42. var drawCol = func(prefix string, value string) error {
  43. left1Cell := fmt.Sprintf("%s%d", prefix, row)
  44. left2Cell := fmt.Sprintf("%s%d", prefix, row+1)
  45. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  46. if err != nil {
  47. return err
  48. }
  49. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  50. if err != nil {
  51. return err
  52. }
  53. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  54. }
  55. // var drawCol1 = func(prefix string, value1 string, value2 string) error {
  56. // topCell := fmt.Sprintf("%s%d", prefix, row)
  57. // bottomCell := fmt.Sprintf("%s%d", prefix, row+1)
  58. // b.Excel.SetCellStyle(b.SheetName, topCell, topCell, b.AlignCenterStyle)
  59. // b.Excel.SetCellValue(b.SheetName, topCell, value1)
  60. // b.Excel.SetCellStyle(b.SheetName, bottomCell, bottomCell, b.AlignCenterStyle)
  61. // b.Excel.SetCellValue(b.SheetName, bottomCell, value2)
  62. // return nil
  63. // }
  64. var drawCol2 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
  65. left1Cell := fmt.Sprintf("%s%d", prefix1, row)
  66. left2Cell := fmt.Sprintf("%s%d", prefix2, row)
  67. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  68. if err != nil {
  69. return err
  70. }
  71. if err != nil {
  72. fmt.Println(err)
  73. return err
  74. }
  75. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  76. if err != nil {
  77. return err
  78. }
  79. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  80. val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
  81. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  82. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  83. val3Cel := fmt.Sprintf("%s%d", prefix2, row+1)
  84. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  85. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  86. return nil
  87. }
  88. var drawCol3 = func(prefix1 string, prefix2 string, prefix3 string, value1 string, value2 string, value3 string, value4 string) error {
  89. left1Cell := fmt.Sprintf("%s%d", prefix1, row)
  90. // left2Cell := fmt.Sprintf("%s%d", prefix2, row)
  91. left3Cell := fmt.Sprintf("%s%d", prefix3, row)
  92. err := b.Excel.MergeCell(b.SheetName, left1Cell, left3Cell)
  93. if err != nil {
  94. return err
  95. }
  96. if err != nil {
  97. fmt.Println(err)
  98. return err
  99. }
  100. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left3Cell, b.AlignCenterStyle)
  101. if err != nil {
  102. return err
  103. }
  104. b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
  105. val2Cel := fmt.Sprintf("%s%d", prefix1, row+1)
  106. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  107. b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
  108. val3Cel := fmt.Sprintf("%s%d", prefix2, row+1)
  109. b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
  110. b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
  111. val4Cel := fmt.Sprintf("%s%d", prefix3, row+1)
  112. b.Excel.SetCellStyle(b.SheetName, val4Cel, val4Cel, b.AlignCenterStyle)
  113. b.Excel.SetCellValue(b.SheetName, val4Cel, value4)
  114. return nil
  115. }
  116. drawCol("A", "产品配料名称")
  117. drawCol2("B", "C", "材料/工序", "材料", "工序")
  118. drawCol("D", "供应商名称")
  119. drawCol3("E", "F", "G", "规格", "厚度(纸克)", "长", "宽")
  120. drawCol("H", "单位")
  121. drawCol("I", "下单数量")
  122. drawCol("J", "实际数量")
  123. drawCol("K", "单价")
  124. drawCol("L", "预算金额")
  125. drawCol("M", "实际金额")
  126. drawCol("N", "预算汇总")
  127. drawCol("O", "实际汇总")
  128. return nil
  129. }
  130. func (b *PlanCostExcel) drawSupplierContent() error {
  131. supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
  132. if err != nil {
  133. return err
  134. }
  135. row := b.Offset + 4
  136. comps := b.Content.Pack.Components
  137. var totalPlanPrice float32 = 0.00
  138. var confirmTotalPlanPrice float64 = 0.00
  139. if len(comps) > 0 {
  140. for _, comp := range comps {
  141. var totalOrderRealPrice float32 = 0.00
  142. var totalConfirmRealPrice float64 = 0.00
  143. if len(comp.Mats) > 0 {
  144. startRow := 0
  145. for _, mat := range comp.Mats {
  146. if mat.Supplier.SupplierInfo != nil {
  147. if supplierId == mat.Supplier.SupplierInfo.Id {
  148. // 材料
  149. if startRow == 0 {
  150. startRow = row
  151. }
  152. supplierName := mat.Supplier.SupplierInfo.Name
  153. matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
  154. b.FormatToEmpty(&matHeigth)
  155. matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
  156. b.FormatToEmpty(&matWidth)
  157. orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
  158. b.FormatToEmpty(&orderCount)
  159. // 实际数量
  160. confirmCount := fmt.Sprintf("%d", mat.MatInfo.ConfirmCount)
  161. b.FormatToEmpty(&confirmCount)
  162. // 单价
  163. orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
  164. b.FormatToEmpty(&orderPrice)
  165. totalOrderRealPrice += mat.Supplier.OrderRealPrice
  166. orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
  167. b.FormatToEmpty(&orderRealPrice)
  168. // 实际金额
  169. confirmPrice := mat.Supplier.OrderPrice * float64(mat.MatInfo.ConfirmCount)
  170. totalConfirmRealPrice += confirmPrice
  171. confirmRealPrice := fmt.Sprintf("%.2f", confirmPrice)
  172. b.FormatToEmpty(&confirmRealPrice)
  173. b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, confirmRealPrice, "", "")
  174. row++
  175. }
  176. }
  177. if len(mat.Crafts) > 0 {
  178. for _, craft := range mat.Crafts {
  179. if craft.Supplier.SupplierInfo != nil {
  180. // 工序
  181. if supplierId == craft.Supplier.SupplierInfo.Id {
  182. if startRow == 0 {
  183. startRow = row
  184. }
  185. craftSupplierName := craft.Supplier.SupplierInfo.Name
  186. carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
  187. b.FormatToEmpty(&carftOrderCount)
  188. carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
  189. b.FormatToEmpty(&carftHeigth)
  190. carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
  191. b.FormatToEmpty(&carftWidth)
  192. // 实际数量
  193. confirmCraftCount := fmt.Sprintf("%d", craft.CraftInfo.ConfirmCount)
  194. b.FormatToEmpty(&confirmCraftCount)
  195. carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  196. b.FormatToEmpty(&carftOrderPrice)
  197. totalOrderRealPrice += craft.Supplier.OrderRealPrice
  198. carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  199. b.FormatToEmpty(&carftOrderRealPrice)
  200. // 实际金额
  201. confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.CraftInfo.ConfirmCount)
  202. totalConfirmRealPrice += confirmCraftPrice
  203. confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
  204. b.FormatToEmpty(&confirmCraftRealPrice)
  205. b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice, "", "")
  206. row++
  207. }
  208. }
  209. }
  210. }
  211. }
  212. if startRow != 0 {
  213. endRow := row - 1
  214. // 组件名字
  215. startACell := fmt.Sprintf("%s%d", "A", startRow)
  216. endACell := fmt.Sprintf("%s%d", "A", endRow)
  217. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  218. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  219. if err != nil {
  220. return err
  221. }
  222. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  223. fmt.Println("startACell:", startACell)
  224. fmt.Println("endACell:", endACell)
  225. fmt.Println("compName:", comp.Name)
  226. // 供应商组件预算汇总
  227. startLCell := fmt.Sprintf("%s%d", "N", startRow)
  228. endLCell := fmt.Sprintf("%s%d", "N", endRow)
  229. b.Excel.MergeCell(b.SheetName, startLCell, endLCell)
  230. err = b.Excel.SetCellStyle(b.SheetName, startLCell, endLCell, b.AlignCenterStyle)
  231. if err != nil {
  232. return err
  233. }
  234. compTotalPrice := fmt.Sprintf("%.2f", totalOrderRealPrice)
  235. b.FormatToEmpty(&compTotalPrice)
  236. b.Excel.SetCellValue(b.SheetName, startLCell, compTotalPrice)
  237. // 供应商组件实际汇总
  238. startOCell := fmt.Sprintf("%s%d", "O", startRow)
  239. endOCell := fmt.Sprintf("%s%d", "O", endRow)
  240. b.Excel.MergeCell(b.SheetName, startOCell, endOCell)
  241. err = b.Excel.SetCellStyle(b.SheetName, startOCell, endOCell, b.AlignCenterStyle)
  242. if err != nil {
  243. return err
  244. }
  245. compConfirmTotalPrice := fmt.Sprintf("%.2f", totalConfirmRealPrice)
  246. b.FormatToEmpty(&compConfirmTotalPrice)
  247. b.Excel.SetCellValue(b.SheetName, startLCell, compConfirmTotalPrice)
  248. }
  249. }
  250. totalPlanPrice += totalOrderRealPrice
  251. confirmTotalPlanPrice += totalConfirmRealPrice
  252. }
  253. // 生产汇总金额
  254. startACell := fmt.Sprintf("%s%d", "A", row)
  255. endMCell := fmt.Sprintf("%s%d", "M", row)
  256. NCell := fmt.Sprintf("%s%d", "N", row)
  257. OCell := fmt.Sprintf("%s%d", "O", row)
  258. b.Excel.MergeCell(b.SheetName, startACell, endMCell)
  259. b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
  260. b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  261. // 生产预算汇总
  262. b.Excel.SetCellStyle(b.SheetName, NCell, NCell, b.AlignCenterStyle)
  263. planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice)
  264. b.FormatToEmpty(&planTotalPrice)
  265. b.Excel.SetCellValue(b.SheetName, NCell, planTotalPrice)
  266. // 生产实际汇总
  267. b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  268. planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
  269. b.FormatToEmpty(&planConfirmTotalPrice)
  270. b.Excel.SetCellValue(b.SheetName, OCell, planConfirmTotalPrice)
  271. }
  272. return nil
  273. }
  274. func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
  275. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O"}
  276. for i, c := range charas {
  277. v := ""
  278. if i < len(values) {
  279. v = values[i]
  280. }
  281. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  282. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  283. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  284. b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
  285. }
  286. }
  287. func (b *PlanCostExcel) drawAllContent() error {
  288. row := b.Offset + 4
  289. comps := b.Content.Pack.Components
  290. var confirmTotalPlanPrice float64 = 0.00
  291. if len(comps) > 0 {
  292. for _, comp := range comps {
  293. var totalConfirmRealPrice float64 = 0.00
  294. if len(comp.Mats) > 0 {
  295. startRow := row
  296. for _, mat := range comp.Mats {
  297. // 材料
  298. supplierName := ""
  299. if mat.Supplier.SupplierInfo != nil {
  300. supplierName = mat.Supplier.SupplierInfo.Name
  301. }
  302. matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
  303. b.FormatToEmpty(&matHeigth)
  304. matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
  305. b.FormatToEmpty(&matWidth)
  306. orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
  307. b.FormatToEmpty(&orderCount)
  308. // orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
  309. // b.FormatToEmpty(&orderPrice)
  310. // orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
  311. // b.FormatToEmpty(&orderRealPrice)
  312. // b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, orderPrice, orderRealPrice, "")
  313. // 实际数量
  314. confirmCount := fmt.Sprintf("%d", mat.MatInfo.ConfirmCount)
  315. b.FormatToEmpty(&confirmCount)
  316. // 单价
  317. orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
  318. b.FormatToEmpty(&orderPrice)
  319. // totalOrderRealPrice += mat.Supplier.OrderRealPrice
  320. orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
  321. b.FormatToEmpty(&orderRealPrice)
  322. // 实际金额
  323. confirmPrice := mat.Supplier.OrderPrice * float64(mat.MatInfo.ConfirmCount)
  324. totalConfirmRealPrice += confirmPrice
  325. confirmRealPrice := fmt.Sprintf("%.2f", confirmPrice)
  326. b.FormatToEmpty(&confirmRealPrice)
  327. b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, confirmRealPrice, "", "")
  328. row++
  329. if len(mat.Crafts) > 0 {
  330. // 工序
  331. for _, craft := range mat.Crafts {
  332. craftSupplierName := ""
  333. if craft.Supplier.SupplierInfo != nil {
  334. craftSupplierName = craft.Supplier.SupplierInfo.Name
  335. }
  336. carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
  337. b.FormatToEmpty(&carftOrderCount)
  338. carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
  339. b.FormatToEmpty(&carftHeigth)
  340. carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
  341. b.FormatToEmpty(&carftWidth)
  342. // carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  343. // b.FormatToEmpty(&carftOrderPrice)
  344. // carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  345. // b.FormatToEmpty(&carftOrderRealPrice)
  346. // b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, carftOrderPrice, carftOrderRealPrice, "")
  347. // 实际数量
  348. confirmCraftCount := fmt.Sprintf("%d", craft.CraftInfo.ConfirmCount)
  349. b.FormatToEmpty(&confirmCraftCount)
  350. carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  351. b.FormatToEmpty(&carftOrderPrice)
  352. // totalOrderRealPrice += craft.Supplier.OrderRealPrice
  353. carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  354. b.FormatToEmpty(&carftOrderRealPrice)
  355. // 实际金额
  356. confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.CraftInfo.ConfirmCount)
  357. totalConfirmRealPrice += confirmCraftPrice
  358. confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
  359. b.FormatToEmpty(&confirmCraftRealPrice)
  360. b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice, "", "")
  361. row++
  362. }
  363. }
  364. }
  365. endRow := row - 1
  366. // 组件名字
  367. startACell := fmt.Sprintf("%s%d", "A", startRow)
  368. endACell := fmt.Sprintf("%s%d", "A", endRow)
  369. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  370. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  371. if err != nil {
  372. return err
  373. }
  374. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  375. // 组件汇总金额
  376. startLCell := fmt.Sprintf("%s%d", "L", startRow)
  377. endLCell := fmt.Sprintf("%s%d", "L", endRow)
  378. b.Excel.MergeCell(b.SheetName, startLCell, endLCell)
  379. err = b.Excel.SetCellStyle(b.SheetName, startLCell, endLCell, b.AlignCenterStyle)
  380. if err != nil {
  381. return err
  382. }
  383. compTotalPrice := fmt.Sprintf("%.2f", comp.TotalPrice)
  384. b.FormatToEmpty(&compTotalPrice)
  385. b.Excel.SetCellValue(b.SheetName, startLCell, compTotalPrice)
  386. confirmTotalPlanPrice += totalConfirmRealPrice
  387. }
  388. }
  389. // 生产汇总金额
  390. startACell := fmt.Sprintf("%s%d", "A", row)
  391. endMCell := fmt.Sprintf("%s%d", "M", row)
  392. NCell := fmt.Sprintf("%s%d", "L", row)
  393. OCell := fmt.Sprintf("%s%d", "O", row)
  394. b.Excel.MergeCell(b.SheetName, startACell, endMCell)
  395. b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
  396. b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  397. // 生产预算汇总
  398. b.Excel.SetCellStyle(b.SheetName, NCell, NCell, b.AlignCenterStyle)
  399. planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice)
  400. b.FormatToEmpty(&planTotalPrice)
  401. b.Excel.SetCellValue(b.SheetName, NCell, planTotalPrice)
  402. // 生产实际汇总
  403. b.Excel.SetCellStyle(b.SheetName, OCell, OCell, b.AlignCenterStyle)
  404. planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
  405. b.FormatToEmpty(&planConfirmTotalPrice)
  406. b.Excel.SetCellValue(b.SheetName, OCell, planConfirmTotalPrice)
  407. }
  408. return nil
  409. }
  410. func (b *PlanCostExcel) Draws() {
  411. b.drawTitle()
  412. b.drawTableTitle()
  413. if b.Content.SupplierId != "" {
  414. b.drawSupplierContent()
  415. } else {
  416. b.drawAllContent()
  417. }
  418. }
  419. func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
  420. border := []excelize.Border{
  421. {Type: "top", Style: 1, Color: "000000"},
  422. {Type: "left", Style: 1, Color: "000000"},
  423. {Type: "right", Style: 1, Color: "000000"},
  424. {Type: "bottom", Style: 1, Color: "000000"},
  425. }
  426. styleLeft, _ := f.NewStyle(&excelize.Style{
  427. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  428. Border: border,
  429. Font: &excelize.Font{Size: 10},
  430. })
  431. b := &PlanCostExcel{
  432. Title: "生产成本表",
  433. SheetName: "Sheet1",
  434. Excel: f,
  435. Offset: 0,
  436. AlignCenterStyle: styleLeft,
  437. }
  438. f.SetColWidth(b.SheetName, "A", "D", 12)
  439. f.SetColWidth(b.SheetName, "E", "O", 10)
  440. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  441. return b
  442. }
  443. func (b *PlanCostExcel) FormatToEmpty(str *string) {
  444. if *str == "0" || *str == "0.00" {
  445. *str = ""
  446. }
  447. }