plan-cost-excel.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. craftStartRow := row
  303. craftEndRow := row
  304. for _, craft := range mat.Crafts {
  305. craftSupplierName := ""
  306. if craft.Supplier.SupplierInfo != nil { // 外箱材料报错
  307. craftSupplierName = craft.Supplier.SupplierInfo.Name
  308. }
  309. carftOrderCount := fmt.Sprintf("%d", int(craft.Supplier.OrderCount))
  310. b.FormatToEmpty(&carftOrderCount)
  311. carftHeigth := fmt.Sprintf("%d", craft.BatchSizeHeight)
  312. b.FormatToEmpty(&carftHeigth)
  313. carftWidth := fmt.Sprintf("%d", craft.BatchSizeWidth)
  314. b.FormatToEmpty(&carftWidth)
  315. // 实际数量
  316. confirmCraftCount := fmt.Sprintf("%d", craft.ConfirmCount)
  317. b.FormatToEmpty(&confirmCraftCount)
  318. carftOrderPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderPrice)
  319. b.FormatToEmpty(&carftOrderPrice)
  320. carftOrderRealPrice := fmt.Sprintf("%.2f", craft.Supplier.OrderRealPrice)
  321. b.FormatToEmpty(&carftOrderRealPrice)
  322. // 实际金额
  323. confirmCraftPrice := craft.Supplier.OrderPrice * float64(craft.ConfirmCount)
  324. totalConfirmRealPrice += confirmCraftPrice
  325. confirmCraftRealPrice := fmt.Sprintf("%.2f", confirmCraftPrice)
  326. b.FormatToEmpty(&confirmCraftRealPrice)
  327. b.drawRow(row, "", "", craft.CraftInfo.Name, craftSupplierName, craft.CraftInfo.Norm, carftHeigth, carftWidth, craft.CraftInfo.Unit, carftOrderCount, confirmCraftCount, carftOrderPrice, carftOrderRealPrice, confirmCraftRealPrice)
  328. row++
  329. craftEndRow = row
  330. }
  331. // 多个工序 合并预算价格
  332. if len(mat.Crafts) > 1 {
  333. b.Excel.MergeCell(b.SheetName, fmt.Sprintf("L%d", craftStartRow), fmt.Sprintf("L%d", craftEndRow))
  334. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("L%d", craftStartRow), mat.Crafts[0].Supplier.OrderRealPrice)
  335. }
  336. // 只加一次合并的预算金额
  337. totalOrderRealPrice += mat.Crafts[0].Supplier.OrderRealPrice
  338. }
  339. }
  340. endRow := row - 1
  341. // 组件名字
  342. startACell := fmt.Sprintf("%s%d", "A", startRow)
  343. endACell := fmt.Sprintf("%s%d", "A", endRow)
  344. b.Excel.MergeCell(b.SheetName, startACell, endACell)
  345. err := b.Excel.SetCellStyle(b.SheetName, startACell, endACell, b.AlignCenterStyle)
  346. if err != nil {
  347. return err
  348. }
  349. b.Excel.SetCellValue(b.SheetName, startACell, comp.Name)
  350. }
  351. // 实际
  352. confirmTotalPlanPrice += totalConfirmRealPrice
  353. // 预算
  354. totalPlanPrice += totalOrderRealPrice
  355. }
  356. }
  357. // ??? 工序数据
  358. if b.Content.Process != nil {
  359. // 生产汇总金额
  360. startACell := fmt.Sprintf("%s%d", "A", row)
  361. endMCell := fmt.Sprintf("%s%d", "K", row)
  362. b.Excel.MergeCell(b.SheetName, startACell, endMCell)
  363. b.Excel.SetCellStyle(b.SheetName, startACell, endMCell, b.AlignCenterStyle)
  364. b.Excel.SetCellValue(b.SheetName, startACell, "其他")
  365. row++
  366. // 工序 外箱 手工费 表头
  367. var drawCol = func(startCell, endCell string, value string) error {
  368. left1Cell := fmt.Sprintf("%s%d", startCell, row)
  369. left2Cell := fmt.Sprintf("%s%d", endCell, row+1)
  370. err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
  371. if err != nil {
  372. return err
  373. }
  374. err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
  375. if err != nil {
  376. return err
  377. }
  378. return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
  379. }
  380. drawCol("B", "C", "材料/工序")
  381. drawCol("D", "D", "供应商名称")
  382. drawCol("E", "G", "规格")
  383. drawCol("H", "H", "单位")
  384. drawCol("I", "I", "下单数量")
  385. drawCol("J", "J", "实际数量")
  386. drawCol("K", "K", "单价")
  387. drawCol("L", "L", "预算金额")
  388. drawCol("M", "M", "实际金额")
  389. row++
  390. var DrawRow = func(rowIndex int, values ...string) {
  391. charas := []string{"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"}
  392. for i, c := range charas {
  393. v := ""
  394. if i < len(values) {
  395. v = values[i]
  396. }
  397. b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("%s%d", c, rowIndex), v)
  398. val2Cel := fmt.Sprintf("%s%d", c, rowIndex)
  399. b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
  400. b.Excel.SetRowHeight(b.SheetName, rowIndex, 21)
  401. }
  402. }
  403. ps := b.Content.Process
  404. count := fmt.Sprintf("%.2f", ps.Supplier.OrderCount)
  405. confirmCount := fmt.Sprintf("%d", ps.ConfirmCount)
  406. price := fmt.Sprintf("%.2f", ps.Supplier.OrderPrice)
  407. b.FormatToEmpty(&price)
  408. // budgetAmountf := ps.Supplier.OrderPrice * float64(ps.Supplier.OrderCount)
  409. budgetAmount := fmt.Sprintf("%.2f", ps.Supplier.OrderRealPrice)
  410. b.FormatToEmpty(&budgetAmount)
  411. // realAmountf := ps.Price * float64(ps.ConfirmCount)
  412. realAmountf := ps.Supplier.OrderPrice * float64(ps.ConfirmCount)
  413. realAmount := fmt.Sprintf("%.2f", realAmountf)
  414. b.FormatToEmpty(&realAmount)
  415. confirmTotalPlanPrice += realAmountf
  416. totalPlanPrice += float32(ps.Supplier.OrderRealPrice)
  417. DrawRow(row, ps.ProcessInfo.Name, ps.Supplier.SupplierInfo.Name, ps.ProcessInfo.Norm, ps.ProcessInfo.Unit, count, confirmCount, price, budgetAmount, realAmount)
  418. row++
  419. }
  420. // 生产汇总金额
  421. startACell := fmt.Sprintf("%s%d", "A", row)
  422. endKCell := fmt.Sprintf("%s%d", "K", row)
  423. LCell := fmt.Sprintf("%s%d", "L", row)
  424. MCell := fmt.Sprintf("%s%d", "M", row)
  425. b.Excel.MergeCell(b.SheetName, startACell, endKCell)
  426. b.Excel.SetCellStyle(b.SheetName, startACell, endKCell, b.AlignCenterStyle)
  427. b.Excel.SetCellValue(b.SheetName, startACell, "生产计划汇总金额")
  428. // 生产预算汇总
  429. b.Excel.SetCellStyle(b.SheetName, LCell, LCell, b.AlignCenterStyle)
  430. // planTotalPrice := fmt.Sprintf("%.2f", b.Content.TotalPrice) //
  431. planTotalPrice := fmt.Sprintf("%.2f", totalPlanPrice)
  432. b.FormatToEmpty(&planTotalPrice)
  433. b.Excel.SetCellValue(b.SheetName, LCell, planTotalPrice)
  434. // 生产实际汇总
  435. b.Excel.SetCellStyle(b.SheetName, MCell, MCell, b.AlignCenterStyle)
  436. planConfirmTotalPrice := fmt.Sprintf("%.2f", confirmTotalPlanPrice)
  437. b.FormatToEmpty(&planConfirmTotalPrice)
  438. b.Excel.SetCellValue(b.SheetName, MCell, planConfirmTotalPrice)
  439. return nil
  440. }
  441. func (b *PlanCostExcel) Draws() {
  442. b.drawTitle()
  443. b.drawTableTitle()
  444. if b.Content.SupplierId != "" {
  445. b.drawSupplierContent()
  446. } else {
  447. b.drawAllContent()
  448. }
  449. }
  450. func NewPlanCostExcel(f *excelize.File) *PlanCostExcel {
  451. border := []excelize.Border{
  452. {Type: "top", Style: 1, Color: "000000"},
  453. {Type: "left", Style: 1, Color: "000000"},
  454. {Type: "right", Style: 1, Color: "000000"},
  455. {Type: "bottom", Style: 1, Color: "000000"},
  456. }
  457. styleLeft, _ := f.NewStyle(&excelize.Style{
  458. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  459. Border: border,
  460. Font: &excelize.Font{Size: 10},
  461. })
  462. b := &PlanCostExcel{
  463. Title: "生产成本表",
  464. SheetName: "Sheet1",
  465. Excel: f,
  466. Offset: 0,
  467. AlignCenterStyle: styleLeft,
  468. }
  469. f.SetColWidth(b.SheetName, "A", "D", 12)
  470. f.SetColWidth(b.SheetName, "E", "M", 10)
  471. f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
  472. return b
  473. }
  474. func (b *PlanCostExcel) FormatToEmpty(str *string) {
  475. if *str == "0" || *str == "0.00" {
  476. *str = ""
  477. }
  478. }