finance.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package admin
  2. import (
  3. "fmt"
  4. "server/dao"
  5. "server/model/common/request"
  6. )
  7. type FinanceService struct{}
  8. func (fs *FinanceService) QueryDailyExpensesList(info request.SearchDailyFee) (list interface{}, total int64, err error) {
  9. limit := info.PageInfo.PageSize
  10. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  11. dailyExpenses, total, err := dao.QueryDailyExpensesList(limit, offset, info.Genre, info.Name, info.Time, info.YearTime)
  12. for i, expenses := range dailyExpenses {
  13. feeDetails, err := dao.QueryDailyFeeDetails(int(expenses.ID))
  14. if err != nil {
  15. return nil, 0, err
  16. }
  17. dailyExpenses[i].DailyFeeDetails = feeDetails
  18. }
  19. return dailyExpenses, total, err
  20. }
  21. func (fs *FinanceService) QueryDailyExpenses(id int) (dao.DailyExpenses, error) {
  22. expenses, err := dao.QueryDailyExpenses(id)
  23. if err != nil {
  24. return dao.DailyExpenses{}, err
  25. }
  26. details, err := dao.QueryDailyFeeDetails(int(expenses.ID))
  27. if err != nil {
  28. return dao.DailyExpenses{}, err
  29. }
  30. expenses.DailyFeeDetails = details
  31. return expenses, err
  32. }
  33. func (fs *FinanceService) QueryExpensesGenre() ([]dao.ExpensesGenre, error) {
  34. return dao.QueryExpensesGenre()
  35. }
  36. func (fs *FinanceService) QueryBorrowingList(info request.SearchNameTime) (list interface{}, total int64, err error) {
  37. limit := info.PageInfo.PageSize
  38. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  39. borrowing, total, err := dao.QueryBorrowingList(limit, offset, info.Name, info.Time, info.YearTime)
  40. return borrowing, total, err
  41. }
  42. func (fs *FinanceService) QueryBorrowing(id int) (dao.Borrowing, error) {
  43. return dao.QueryBorrowing(id)
  44. }
  45. func (fs *FinanceService) QueryDailyFileList(info request.SearchIdNameGenre) (list interface{}, total int64, err error) {
  46. limit := info.PageInfo.PageSize
  47. offset := info.PageInfo.PageSize * (info.PageInfo.Page - 1)
  48. dailyFiles, total, err := dao.QueryDailyFileList(limit, offset, info.Id, info.Genre, info.Name)
  49. return dailyFiles, total, err
  50. }
  51. func (fs *FinanceService) QueryProjectFinance(code string) (dao.Project, error) {
  52. project, err := dao.QueryProjectByCode(code)
  53. if err != nil {
  54. return dao.Project{}, err
  55. }
  56. collection, collectionTotal, err := dao.QueryCollectionList(8, 0, code, "")
  57. if err != nil {
  58. return dao.Project{}, err
  59. }
  60. reimbursements, reimbursementTotal, err := dao.QueryReimbursementList(8, 0, code, "", "")
  61. if err != nil {
  62. return dao.Project{}, err
  63. }
  64. for i, reimbursement := range reimbursements {
  65. details, err := dao.QueryFeeDetails(int(reimbursement.ID))
  66. if err != nil {
  67. return dao.Project{}, err
  68. }
  69. reimbursements[i].FeeDetails = details
  70. }
  71. workingHours, workingHoursTotal, err := dao.QueryWorkingHoursList(8, 0, 0, code, "", "")
  72. if err != nil {
  73. return dao.Project{}, err
  74. }
  75. project.Collection = collection
  76. project.Reimbursement = reimbursements
  77. project.WorkingHours = workingHours
  78. project.ReimbursementTotal = reimbursementTotal
  79. project.CollectionTotal = collectionTotal
  80. project.WorkingHoursTotal = workingHoursTotal
  81. return project, err
  82. }
  83. func (fs *FinanceService) CreateDailyExpenses(expenses dao.DailyExpenses) error {
  84. return expenses.CreateDailyExpenses()
  85. }
  86. func (fs *FinanceService) CreateExpensesGenre(genre dao.ExpensesGenre) error {
  87. return genre.CreateExpensesGenre()
  88. }
  89. func (fs *FinanceService) CreateBorrowing(borrowing dao.Borrowing) error {
  90. return borrowing.CreateBorrowing()
  91. }
  92. func (fs *FinanceService) CreateDailyFile(file dao.DailyFile) error {
  93. return file.CreateDailyFile()
  94. }
  95. func (fs *FinanceService) UpdateDailyExpenses(expenses dao.DailyExpenses) error {
  96. return expenses.UpdateDailyExpenses()
  97. }
  98. func (fs *FinanceService) UpdateExpensesGenre(genre dao.ExpensesGenre) error {
  99. return genre.UpdateExpensesGenre()
  100. }
  101. func (fs *FinanceService) UpdateBorrowing(borrowing dao.Borrowing) error {
  102. return borrowing.UpdateBorrowing()
  103. }
  104. func (fs *FinanceService) DeleteDailyExpenses(expenses dao.DailyExpenses) error {
  105. return expenses.DeleteDailyExpenses()
  106. }
  107. func (fs *FinanceService) DeleteExpensesGenre(genre dao.ExpensesGenre) error {
  108. expenses, _ := dao.QueryExpensesByGenre(int(genre.ID))
  109. if len(expenses) > 0 {
  110. return fmt.Errorf("费用类型正在被使用")
  111. }
  112. return genre.DeleteExpensesGenre()
  113. }
  114. func (fs *FinanceService) DeleteBorrowing(borrowing dao.Borrowing) error {
  115. return borrowing.DeleteBorrowing()
  116. }
  117. func (fs *FinanceService) DeleteDailyFile(file dao.DailyFile) error {
  118. return file.DeleteDailyFile()
  119. }