plan-cost-excel.go 18 KB

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