plan-cost-excel.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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("M%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. return nil
  127. }
  128. func (b *PlanCostExcel) drawSupplierContent() error {
  129. supplierId, err := primitive.ObjectIDFromHex(b.Content.SupplierId)
  130. if err != nil {
  131. return err
  132. }
  133. row := b.Offset + 4
  134. comps := b.Content.Pack.Components
  135. var totalPlanPrice float32 = 0.00
  136. var confirmTotalPlanPrice float64 = 0.00
  137. if len(comps) > 0 {
  138. for _, comp := range comps {
  139. var totalOrderRealPrice float32 = 0.00
  140. var totalConfirmRealPrice float64 = 0.00
  141. if len(comp.Mats) > 0 {
  142. startRow := 0
  143. for _, mat := range comp.Mats {
  144. if mat.Supplier.SupplierInfo != nil {
  145. if supplierId == mat.Supplier.SupplierInfo.Id {
  146. // 材料
  147. if startRow == 0 {
  148. startRow = row
  149. }
  150. supplierName := mat.Supplier.SupplierInfo.Name
  151. matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
  152. b.FormatToEmpty(&matHeigth)
  153. matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
  154. b.FormatToEmpty(&matWidth)
  155. orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
  156. b.FormatToEmpty(&orderCount)
  157. // 实际数量
  158. confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
  159. b.FormatToEmpty(&confirmCount)
  160. // 单价
  161. orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
  162. b.FormatToEmpty(&orderPrice)
  163. totalOrderRealPrice += mat.Supplier.OrderRealPrice
  164. orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
  165. b.FormatToEmpty(&orderRealPrice)
  166. // 实际金额
  167. confirmPrice := mat.Supplier.OrderPrice * float64(mat.ConfirmCount)
  168. totalConfirmRealPrice += confirmPrice
  169. confirmRealPrice := fmt.Sprintf("%.2f", confirmPrice)
  170. b.FormatToEmpty(&confirmRealPrice)
  171. b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, confirmRealPrice)
  172. row++
  173. }
  174. }
  175. if len(mat.Crafts) > 0 {
  176. for _, craft := range mat.Crafts {
  177. if craft.Supplier.SupplierInfo != nil {
  178. // 工序
  179. if supplierId == craft.Supplier.SupplierInfo.Id {
  180. if startRow == 0 {
  181. startRow = row
  182. }
  183. craftSupplierName := craft.Supplier.SupplierInfo.Name
  184. carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
  185. b.FormatToEmpty(&carftOrderCount)
  186. carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
  187. b.FormatToEmpty(&carftHeigth)
  188. carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
  189. b.FormatToEmpty(&carftWidth)
  190. // 实际数量
  191. confirmCraftCount := fmt.Sprintf("%d", craft.ConfirmCount)
  192. b.FormatToEmpty(&confirmCraftCount)
  193. carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  194. b.FormatToEmpty(&carftOrderPrice)
  195. totalOrderRealPrice += craft.Supplier.OrderRealPrice
  196. carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  197. b.FormatToEmpty(&carftOrderRealPrice)
  198. // 实际金额
  199. confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
  200. totalConfirmRealPrice += confirmCraftPrice
  201. confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
  202. b.FormatToEmpty(&confirmCraftRealPrice)
  203. b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice)
  204. row++
  205. }
  206. }
  207. }
  208. }
  209. }
  210. if startRow != 0 {
  211. endRow := row - 1
  212. // 组件名字
  213. startACell := fmt.Sprintf("%s%d", "A", startRow)
  214. endACell := fmt.Sprintf("%s%d", "A", endRow)
  215. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  216. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  217. if err != nil {
  218. return err
  219. }
  220. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  221. fmt.Println("startACell:", startACell)
  222. fmt.Println("endACell:", endACell)
  223. fmt.Println("compName:", comp.Name)
  224. // // 供应商组件预算汇总
  225. // startLCell := fmt.Sprintf("%s%d", "N", startRow)
  226. // endLCell := fmt.Sprintf("%s%d", "N", endRow)
  227. // b.Excel.MergeCell(b.SheetName, startLCell, endLCell)
  228. // err = b.Excel.SetCellStyle(b.SheetName, startLCell, endLCell, b.AlignCenterStyle)
  229. // if err != nil {
  230. // return err
  231. // }
  232. // compTotalPrice := fmt.Sprintf("%.2f", totalOrderRealPrice)
  233. // b.FormatToEmpty(&compTotalPrice)
  234. // b.Excel.SetCellValue(b.SheetName, startLCell, compTotalPrice)
  235. // // 供应商组件实际汇总
  236. // startOCell := fmt.Sprintf("%s%d", "O", startRow)
  237. // endOCell := fmt.Sprintf("%s%d", "O", endRow)
  238. // b.Excel.MergeCell(b.SheetName, startOCell, endOCell)
  239. // err = b.Excel.SetCellStyle(b.SheetName, startOCell, endOCell, b.AlignCenterStyle)
  240. // if err != nil {
  241. // return err
  242. // }
  243. // compConfirmTotalPrice := fmt.Sprintf("%.2f", totalConfirmRealPrice)
  244. // b.FormatToEmpty(&compConfirmTotalPrice)
  245. // b.Excel.SetCellValue(b.SheetName, startLCell, compConfirmTotalPrice)
  246. }
  247. }
  248. totalPlanPrice += totalOrderRealPrice
  249. confirmTotalPlanPrice += totalConfirmRealPrice
  250. }
  251. // 生产汇总金额
  252. startACell := fmt.Sprintf("%s%d", "A", row)
  253. endKCell := fmt.Sprintf("%s%d", "K", row)
  254. LCell := fmt.Sprintf("%s%d", "L", row)
  255. MCell := fmt.Sprintf("%s%d", "M", row)
  256. b.Excel.MergeCell(b.SheetName, startACell, endKCell)
  257. b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
  258. b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  259. // 生产预算汇总
  260. b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
  261. planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice)
  262. b.FormatToEmpty(&planTotalPrice)
  263. b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
  264. // 生产实际汇总
  265. b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
  266. planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
  267. b.FormatToEmpty(&planConfirmTotalPrice)
  268. b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
  269. }
  270. return nil
  271. }
  272. func (b *PlanCostExcel) drawRow(rowIndex int, values ...string) {
  273. charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
  274. for i, c := range charas {
  275. v := ""
  276. if i < len(values) {
  277. v = values[i]
  278. }
  279. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  280. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  281. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  282. b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
  283. }
  284. }
  285. func (b *PlanCostExcel) drawAllContent() error {
  286. row := b.Offset + 4
  287. comps := b.Content.Pack.Components
  288. var confirmTotalPlanPrice float64 = 0.00
  289. if len(comps) > 0 {
  290. for _, comp := range comps {
  291. var totalConfirmRealPrice float64 = 0.00
  292. if len(comp.Mats) > 0 {
  293. startRow := row
  294. for _, mat := range comp.Mats {
  295. // 材料
  296. supplierName := ""
  297. if mat.Supplier.SupplierInfo != nil {
  298. supplierName = mat.Supplier.SupplierInfo.Name
  299. }
  300. matHeigth := fmt.Sprintf("%d", mat.BatchSizeHeight)
  301. b.FormatToEmpty(&matHeigth)
  302. matWidth := fmt.Sprintf("%d", mat.BatchSizeWidth)
  303. b.FormatToEmpty(&matWidth)
  304. orderCount := fmt.Sprintf("%d", int(mat.Supplier.OrderCount))
  305. b.FormatToEmpty(&orderCount)
  306. // orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
  307. // b.FormatToEmpty(&orderPrice)
  308. // orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
  309. // b.FormatToEmpty(&orderRealPrice)
  310. // b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, orderPrice, orderRealPrice, "")
  311. // 实际数量
  312. confirmCount := fmt.Sprintf("%d", mat.ConfirmCount)
  313. b.FormatToEmpty(&confirmCount)
  314. // 单价
  315. orderPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderPrice)
  316. b.FormatToEmpty(&orderPrice)
  317. // totalOrderRealPrice += mat.Supplier.OrderRealPrice
  318. orderRealPrice := fmt.Sprintf("%.2f", mat.Supplier.OrderRealPrice)
  319. b.FormatToEmpty(&orderRealPrice)
  320. // 实际金额
  321. confirmPrice := mat.Supplier.OrderPrice * float64(mat.ConfirmCount)
  322. totalConfirmRealPrice += confirmPrice
  323. confirmRealPrice := fmt.Sprintf("%.2f", confirmPrice)
  324. b.FormatToEmpty(&confirmRealPrice)
  325. b.drawRow(row, "", mat.MatInfo.Name, "", supplierName, mat.MatInfo.Norm, matHeigth, matWidth, mat.MatInfo.Unit, orderCount, confirmCount, orderPrice, orderRealPrice, confirmRealPrice)
  326. row++
  327. if len(mat.Crafts) > 0 {
  328. // 工序
  329. for _, craft := range mat.Crafts {
  330. craftSupplierName := ""
  331. if craft.Supplier.SupplierInfo != nil {
  332. craftSupplierName = craft.Supplier.SupplierInfo.Name
  333. }
  334. carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
  335. b.FormatToEmpty(&carftOrderCount)
  336. carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
  337. b.FormatToEmpty(&carftHeigth)
  338. carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
  339. b.FormatToEmpty(&carftWidth)
  340. // carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  341. // b.FormatToEmpty(&carftOrderPrice)
  342. // carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  343. // b.FormatToEmpty(&carftOrderRealPrice)
  344. // b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, carftOrderPrice, carftOrderRealPrice, "")
  345. // 实际数量
  346. confirmCraftCount := fmt.Sprintf("%d", craft.ConfirmCount)
  347. b.FormatToEmpty(&confirmCraftCount)
  348. carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  349. b.FormatToEmpty(&carftOrderPrice)
  350. // totalOrderRealPrice += craft.Supplier.OrderRealPrice
  351. carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  352. b.FormatToEmpty(&carftOrderRealPrice)
  353. // 实际金额
  354. confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
  355. totalConfirmRealPrice += confirmCraftPrice
  356. confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
  357. b.FormatToEmpty(&confirmCraftRealPrice)
  358. b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice)
  359. row++
  360. }
  361. }
  362. }
  363. endRow := row - 1
  364. // 组件名字
  365. startACell := fmt.Sprintf("%s%d", "A", startRow)
  366. endACell := fmt.Sprintf("%s%d", "A", endRow)
  367. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  368. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  369. if err != nil {
  370. return err
  371. }
  372. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  373. // // 组件汇总金额
  374. // startLCell := fmt.Sprintf("%s%d", "L", startRow)
  375. // endLCell := fmt.Sprintf("%s%d", "L", endRow)
  376. // b.Excel.MergeCell(b.SheetName, startLCell, endLCell)
  377. // err = b.Excel.SetCellStyle(b.SheetName, startLCell, endLCell, b.AlignCenterStyle)
  378. // if err != nil {
  379. // return err
  380. // }
  381. // compTotalPrice := fmt.Sprintf("%.2f", comp.TotalPrice)
  382. // b.FormatToEmpty(&compTotalPrice)
  383. // b.Excel.SetCellValue(b.SheetName, startLCell, compTotalPrice)
  384. // confirmTotalPlanPrice += totalConfirmRealPrice
  385. }
  386. }
  387. // 生产汇总金额
  388. startACell := fmt.Sprintf("%s%d", "A", row)
  389. endKCell := fmt.Sprintf("%s%d", "K", row)
  390. LCell := fmt.Sprintf("%s%d", "L", row)
  391. MCell := fmt.Sprintf("%s%d", "M", row)
  392. b.Excel.MergeCell(b.SheetName, startACell, endKCell)
  393. b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
  394. b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  395. // 生产预算汇总
  396. b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
  397. planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice)
  398. b.FormatToEmpty(&planTotalPrice)
  399. b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
  400. // 生产实际汇总
  401. b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
  402. planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
  403. b.FormatToEmpty(&planConfirmTotalPrice)
  404. b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
  405. }
  406. return nil
  407. }
  408. func (b *PlanCostExcel) Draws() {
  409. b.drawTitle()
  410. b.drawTableTitle()
  411. if b.Content.SupplierId != "" {
  412. b.drawSupplierContent()
  413. } else {
  414. b.drawAllContent()
  415. }
  416. }
  417. func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
  418. border := []excelize.Border{
  419. {Type: "top", Style: 1, Color: "000000"},
  420. {Type: "left", Style: 1, Color: "000000"},
  421. {Type: "right", Style: 1, Color: "000000"},
  422. {Type: "bottom", Style: 1, Color: "000000"},
  423. }
  424. styleLeft, _ := f.NewStyle(&excelize.Style{
  425. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  426. Border: border,
  427. Font: &excelize.Font{Size: 10},
  428. })
  429. b := &PlanCostExcel{
  430. Title: "生产成本表",
  431. SheetName: "Sheet1",
  432. Excel: f,
  433. Offset: 0,
  434. AlignCenterStyle: styleLeft,
  435. }
  436. f.SetColWidth(b.SheetName, "A", "D", 12)
  437. f.SetColWidth(b.SheetName, "E", "M", 10)
  438. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  439. return b
  440. }
  441. func (b *PlanCostExcel) FormatToEmpty(str *string) {
  442. if *str == "0" || *str == "0.00" {
  443. *str = ""
  444. }
  445. }