作者 yangfu

分红明细修改

... ... @@ -138,6 +138,37 @@ func (dao *DividendsEstimateDao) CountDividendsEstimateDividendsAmount(queryOpti
return dividendsAmount, nil
}
// CountDividendsEstimate 统计当前分红预算单总数
func (dao *DividendsEstimateDao) DividendsEstimateStatistics(queryOptions map[string]interface{}, v interface{}) error {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
query.ColumnExpr("sum(dividends_amount) total")
query.ColumnExpr(`sum((case when dividends_account_status =1 then dividends_amount else 0 end)) accounting `)
query.ColumnExpr(`sum((case when dividends_account_status =2 then dividends_amount else 0 end)) accounted `)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query = query.Where(`dividends_user->>'userBaseId'='?'`, userBaseId)
}
if _, ok := queryOptions["beginTime"]; ok {
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)))
}
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
}
//query.AllWithDeleted()
query.Where("is_canceled is null")
if err := query.Select(v); err != nil {
return err
}
return nil
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -402,34 +402,47 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
queryOptions["cooperationContractNumbers"] = contractNumbers
var allDividendsEstimate = &CreditAccountStatisticsResponse{}
var annualDividendsEstimate = &CreditAccountStatisticsResponse{}
var quarterDividendsEstimate = &CreditAccountStatisticsResponse{}
var allDividends = &CreditAccountStatisticsResponse{}
var annualDividends = &CreditAccountStatisticsResponse{}
var quarterDividends = &CreditAccountStatisticsResponse{}
dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
if len(contractNumbers) > 0 {
if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, allDividendsEstimate); err != nil {
return nil, err
}
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
return nil, err
}
allDividends.Accounting = allDividends.Total - allDividends.Accounted
allDividendsEstimate.Paid = allDividends.Paid
queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)
queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, annualDividendsEstimate); err != nil {
return nil, err
}
if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil {
return nil, err
}
annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted
annualDividendsEstimate.Paid = annualDividends.Paid
queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd()
if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, quarterDividendsEstimate); err != nil {
return nil, err
}
if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil {
return nil, err
}
quarterDividends.Accounting = quarterDividends.Total - quarterDividends.Accounted
quarterDividendsEstimate.Paid = quarterDividends.Paid
}
ret := map[string]interface{}{
"allDividends": allDividends,
"annualDividends": annualDividends,
"quarterDividends": quarterDividends,
"allDividends": allDividendsEstimate.Round(2),
"annualDividends": annualDividendsEstimate.Round(2),
"quarterDividends": quarterDividendsEstimate.Round(2),
}
return ret, nil
}
... ... @@ -454,7 +467,7 @@ func quarterBeginEnd() (time.Time, time.Time) {
mEnd = 3
}
begin = time.Date(y, time.Month(mBegin), 1, 0, 0, 0, 0, time.Local)
end = time.Date(y, time.Month(mEnd), 1, 0, 0, 0, 0, time.Local)
end = time.Date(y, time.Month(mEnd), 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
return begin, end
}
... ... @@ -590,6 +603,15 @@ type CreditAccountStatisticsResponse struct {
Unpaid float64 `json:"unpaid"`
}
func (credit *CreditAccountStatisticsResponse) Round(places int) *CreditAccountStatisticsResponse {
credit.Total = utils.Round(credit.Total, int32(places))
credit.Accounting = utils.Round(credit.Accounting, int32(places))
credit.Accounted = utils.Round(credit.Accounted, int32(places))
credit.Paid = utils.Round(credit.Paid, int32(places))
credit.Unpaid = utils.Round(credit.Unpaid, int32(places))
return credit
}
//getRelevantContracts 获取相关人的合约
func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(queryOptions map[string]interface{}) (interface{}, error) {
var request = struct {
... ...