作者 yangfu

分红明细修改

@@ -138,6 +138,37 @@ func (dao *DividendsEstimateDao) CountDividendsEstimateDividendsAmount(queryOpti @@ -138,6 +138,37 @@ func (dao *DividendsEstimateDao) CountDividendsEstimateDividendsAmount(queryOpti
138 return dividendsAmount, nil 138 return dividendsAmount, nil
139 } 139 }
140 140
  141 +// CountDividendsEstimate 统计当前分红预算单总数
  142 +func (dao *DividendsEstimateDao) DividendsEstimateStatistics(queryOptions map[string]interface{}, v interface{}) error {
  143 + tx := dao.transactionContext.PgTx
  144 + var dividendsEstimateModels []*models.DividendsEstimate
  145 + query := tx.Model(&dividendsEstimateModels)
  146 + query.ColumnExpr("sum(dividends_amount) total")
  147 + query.ColumnExpr(`sum((case when dividends_account_status =1 then dividends_amount else 0 end)) accounting `)
  148 + query.ColumnExpr(`sum((case when dividends_account_status =2 then dividends_amount else 0 end)) accounted `)
  149 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  150 + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
  151 + }
  152 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  153 + query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
  154 + }
  155 + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
  156 + query = query.Where(`dividends_user->>'userBaseId'='?'`, userBaseId)
  157 + }
  158 + if _, ok := queryOptions["beginTime"]; ok {
  159 + query.Where(fmt.Sprintf("created_at>='%s' and created_at<'%s'", (queryOptions["beginTime"].(time.Time)).Format(time.RFC3339), (queryOptions["endTime"].(time.Time)).Format(time.RFC3339)))
  160 + }
  161 + if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
  162 + query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
  163 + }
  164 + //query.AllWithDeleted()
  165 + query.Where("is_canceled is null")
  166 + if err := query.Select(v); err != nil {
  167 + return err
  168 + }
  169 + return nil
  170 +}
  171 +
141 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) { 172 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
142 if transactionContext == nil { 173 if transactionContext == nil {
143 return nil, fmt.Errorf("transactionContext参数不能为空") 174 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -402,34 +402,47 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st @@ -402,34 +402,47 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
402 402
403 queryOptions["cooperationContractNumbers"] = contractNumbers 403 queryOptions["cooperationContractNumbers"] = contractNumbers
404 404
  405 + var allDividendsEstimate = &CreditAccountStatisticsResponse{}
  406 + var annualDividendsEstimate = &CreditAccountStatisticsResponse{}
  407 + var quarterDividendsEstimate = &CreditAccountStatisticsResponse{}
405 var allDividends = &CreditAccountStatisticsResponse{} 408 var allDividends = &CreditAccountStatisticsResponse{}
406 var annualDividends = &CreditAccountStatisticsResponse{} 409 var annualDividends = &CreditAccountStatisticsResponse{}
407 var quarterDividends = &CreditAccountStatisticsResponse{} 410 var quarterDividends = &CreditAccountStatisticsResponse{}
408 411
  412 + dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
409 if len(contractNumbers) > 0 { 413 if len(contractNumbers) > 0 {
  414 + if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, allDividendsEstimate); err != nil {
  415 + return nil, err
  416 + }
410 if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil { 417 if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
411 return nil, err 418 return nil, err
412 } 419 }
413 - allDividends.Accounting = allDividends.Total - allDividends.Accounted 420 + allDividendsEstimate.Paid = allDividends.Paid
414 421
415 queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local) 422 queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)
416 queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0) 423 queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
  424 + if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, annualDividendsEstimate); err != nil {
  425 + return nil, err
  426 + }
417 if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil { 427 if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil {
418 return nil, err 428 return nil, err
419 } 429 }
420 - annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted 430 + annualDividendsEstimate.Paid = annualDividends.Paid
421 431
422 queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd() 432 queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd()
  433 + if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, quarterDividendsEstimate); err != nil {
  434 + return nil, err
  435 + }
423 if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil { 436 if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil {
424 return nil, err 437 return nil, err
425 } 438 }
426 - quarterDividends.Accounting = quarterDividends.Total - quarterDividends.Accounted 439 + quarterDividendsEstimate.Paid = quarterDividends.Paid
427 } 440 }
428 441
429 ret := map[string]interface{}{ 442 ret := map[string]interface{}{
430 - "allDividends": allDividends,  
431 - "annualDividends": annualDividends,  
432 - "quarterDividends": quarterDividends, 443 + "allDividends": allDividendsEstimate.Round(2),
  444 + "annualDividends": annualDividendsEstimate.Round(2),
  445 + "quarterDividends": quarterDividendsEstimate.Round(2),
433 } 446 }
434 return ret, nil 447 return ret, nil
435 } 448 }
@@ -454,7 +467,7 @@ func quarterBeginEnd() (time.Time, time.Time) { @@ -454,7 +467,7 @@ func quarterBeginEnd() (time.Time, time.Time) {
454 mEnd = 3 467 mEnd = 3
455 } 468 }
456 begin = time.Date(y, time.Month(mBegin), 1, 0, 0, 0, 0, time.Local) 469 begin = time.Date(y, time.Month(mBegin), 1, 0, 0, 0, 0, time.Local)
457 - end = time.Date(y, time.Month(mEnd), 1, 0, 0, 0, 0, time.Local) 470 + end = time.Date(y, time.Month(mEnd), 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
458 return begin, end 471 return begin, end
459 } 472 }
460 473
@@ -590,6 +603,15 @@ type CreditAccountStatisticsResponse struct { @@ -590,6 +603,15 @@ type CreditAccountStatisticsResponse struct {
590 Unpaid float64 `json:"unpaid"` 603 Unpaid float64 `json:"unpaid"`
591 } 604 }
592 605
  606 +func (credit *CreditAccountStatisticsResponse) Round(places int) *CreditAccountStatisticsResponse {
  607 + credit.Total = utils.Round(credit.Total, int32(places))
  608 + credit.Accounting = utils.Round(credit.Accounting, int32(places))
  609 + credit.Accounted = utils.Round(credit.Accounted, int32(places))
  610 + credit.Paid = utils.Round(credit.Paid, int32(places))
  611 + credit.Unpaid = utils.Round(credit.Unpaid, int32(places))
  612 + return credit
  613 +}
  614 +
593 //getRelevantContracts 获取相关人的合约 615 //getRelevantContracts 获取相关人的合约
594 func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(queryOptions map[string]interface{}) (interface{}, error) { 616 func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(queryOptions map[string]interface{}) (interface{}, error) {
595 var request = struct { 617 var request = struct {