@ -12,6 +12,7 @@ import (
"lapp_-wy/web/middleware/glog"
"lapp_-wy/web/middleware/glog"
"lapp_-wy/web/models/response"
"lapp_-wy/web/models/response"
"math"
"math"
"strconv"
"strings"
"strings"
"time"
"time"
"xorm.io/core"
"xorm.io/core"
@ -75,7 +76,7 @@ type ChargeArrearageResponse struct {
Total int64 ` json:"total" `
Total int64 ` json:"total" `
TotalPage int ` json:"total_page" `
TotalPage int ` json:"total_page" `
CurrentPage int ` json:"current_page" `
CurrentPage int ` json:"current_page" `
User string ` json:"user" `
User string ` json:"user" `
}
}
type ExcelChargeWayData struct {
type ExcelChargeWayData struct {
@ -260,14 +261,14 @@ func (t *Chargetab) ChargeTotalByBuilding(buildingid string, beginyear string, e
}
}
type SumStruct struct {
type SumStruct struct {
Cid int ` json:"cid" `
Allocateyear int ` json:"allocateyear" `
ReceivableArea float64 ` json:"receivable_area" `
PaidInArea float64 ` json:"paid_in_area" `
ReceivableMoney float64 ` json:"receivable_money" `
PaidInMoney float64 ` json:"paid_in_money" `
CurrentPercent float64 ` json:"current_percent" `
ArrearagePercent float64 ` json:"arrearage_percent" `
Cid int ` json:"cid" `
Allocateyear int ` json:"allocateyear" `
ReceivableArea float64 ` json:"receivable_area" `
PaidInArea float64 ` json:"paid_in_area" `
ReceivableMoney float64 ` json:"receivable_money" `
PaidInMoney float64 ` json:"paid_in_money" `
CurrentPercent string ` json:"current_percent" `
ArrearagePercent string ` json:"arrearage_percent" `
}
}
type BuildingInfo struct {
type BuildingInfo struct {
@ -1764,7 +1765,7 @@ func (t *Chargetab) GetChargeStatisticData(cid, year int, selectType string, cha
engine := db . MasterEngine ( )
engine := db . MasterEngine ( )
var query * xorm . Session
var query * xorm . Session
var chargeAllocation Chargeallocationtab
var chargeAllocation Chargeallocationtab
if chargeType == 0 && buildingId == "" && start == "" && end == "" && year == 0 {
if chargeType == 0 && buildingId == "" && start == "" && end == "" && year == 0 {
query = engine . Table ( chargeAllocation . TableName ( ) ) . Where ( "cid = ?" , cid )
query = engine . Table ( chargeAllocation . TableName ( ) ) . Where ( "cid = ?" , cid )
} else {
} else {
@ -2109,40 +2110,79 @@ func (t *Chargetab) ChargeTotalStatisticData(year int, selectType string) ([]Sum
e := db . MasterEngine ( )
e := db . MasterEngine ( )
datalist := make ( [ ] SumStruct , 0 )
datalist := make ( [ ] SumStruct , 0 )
currentYear := time . Now ( ) . Year ( )
currentYear := time . Now ( ) . Year ( )
var startDate string
var endDate string
if selectType == "current" {
if year < currentYear {
year = currentYear
startDate := fmt . Sprintf ( "%d-01-01" , year )
endDate := fmt . Sprintf ( "%d-12-31" , year )
var count float64
var totalMoney float64
var err error
//计算实收金额
var charge Chargetab
totalMoney , err = e . Table ( t . TableName ( ) ) . Where ( "cid = ? and chargetime >= ? and chargetime <= ?" , t . Cid , startDate , endDate ) . Sum ( charge , "chargableexpense" )
if err != nil {
glog . InfoExtln ( "年缴费测试" , "err0 := " , err )
return nil , 0 , err
}
tempChargeLi := make ( [ ] Chargetab , 0 )
err = e . Table ( t . TableName ( ) ) . Where ( "cid = ? and chargetime >= ? and chargetime <= ? and chargestartdate < ?" , t . Cid , startDate , endDate , startDate ) . Asc ( "chargestartdate" ) . Limit ( 1 , 0 ) . Find ( & tempChargeLi )
if err != nil {
return nil , 0 , err
}
fmt . Println ( "tempChargeLi:" , tempChargeLi )
var arrearageYears int
if len ( tempChargeLi ) < 0 || tempChargeLi [ 0 ] . Chargestartdate == "" {
arrearageYears = 0
} else {
date := tempChargeLi [ 0 ] . Chargestartdate
dateYear , err := strconv . Atoi ( strings . Split ( date , "-" ) [ 0 ] )
if err != nil {
arrearageYears = 0
}
}
startDate = fmt . Sprintf ( "%d-01-01" , year )
endDate = fmt . Sprintf ( "%d-01-01" , 2099 )
arrearageYears = currentYear - dateYear
}
fmt . Println ( "arrearageYears:" , arrearageYears )
chargenrLi := make ( [ ] int , 0 )
err = e . Table ( t . TableName ( ) ) . Where ( "cid = ? and chargetime >= ? and chargetime <= ?" , t . Cid , startDate , endDate ) . Cols ( "chargenr" ) . Find ( & chargenrLi )
if err != nil {
return nil , 0 , err
}
var chargeallocation Chargeallocationtab
arrearageMoney , err := e . Table ( chargeallocation . TableName ( ) ) . Where ( "cid = ?" , t . Cid ) . In ( "chargenr" , chargenrLi ) . And ( "allocateyear < ?" , currentYear ) . Sum ( chargeallocation , "allocateexpense" )
if err != nil {
return nil , 0 , err
}
if selectType == "current" {
count = totalMoney - arrearageMoney
} else if selectType == "arrearage" {
} else if selectType == "arrearage" {
startDate = fmt . Sprintf ( "%d-01-01" , 2000 )
if year >= currentYear {
year = currentYear - 1
}
endDate = fmt . Sprintf ( "%d-01-01" , year + 1 )
count = arrearageMoney
} else {
} else {
startDate = fmt . Sprintf ( "%d-01-01" , year )
endDate = fmt . Sprintf ( "%d-01-01" , year + 1 )
count = totalMoney
}
}
//计算实收金额
ss := new ( SumStruct )
_ , err := e . Table ( "chargeallocationtab" ) . Select ( "sum(allocateexpense) as paid_in_money" ) . Where ( "cid = ? and allocateyear =? " , t . Cid , year ) . Get ( ss )
//计算实收缴费面积
//计算实收缴费面积
one := SumStruct { }
one := SumStruct { }
one . Cid = t . Cid
one . Cid = t . Cid
one . Allocateyear = year
one . Allocateyear = year
PaidInMoney := fmt . Sprintf ( "%0.0f" , ss . PaidInMoney )
PaidInMoney := fmt . Sprintf ( "%0.0f" , count )
one . PaidInMoney = utils . ValueToFloat ( PaidInMoney , 0.0 )
one . PaidInMoney = utils . ValueToFloat ( PaidInMoney , 0.0 )
info := new ( SumStruct )
_ , err = e . Table ( "chargetab" ) . Select ( "sum(propertytab.constructionarea) as paid_in_area" ) . Join ( "INNER" , "propertytab" , "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid" ) . Where ( "chargetab.cid = ? and chargetab.chargeenddate >= ? and chargetab.chargeenddate < ?" , t . Cid , startDate , endDate ) . Get ( info )
propertyidLi := make ( [ ] string , 0 )
err = e . Table ( t . TableName ( ) ) . Where ( "cid = ? and chargetime >= ? and chargetime <= ?" , t . Cid , startDate , endDate ) . Cols ( "propertyid" ) . Find ( & propertyidLi )
if err != nil {
return nil , 0 , err
}
propertyidMap := make ( map [ string ] interface { } , 0 )
for _ , propertyid := range propertyidLi {
propertyidMap [ propertyid ] = nil
}
disctincPropertyidLi := make ( [ ] string , 0 )
for propertyid , _ := range propertyidMap {
disctincPropertyidLi = append ( disctincPropertyidLi , propertyid )
}
var property Propertytab
area , err := e . Table ( property . TableName ( ) ) . In ( "propertyid" , disctincPropertyidLi ) . Sum ( property , "constructionarea" )
if err != nil {
if err != nil {
glog . InfoExtln ( "年缴费测试" , "err1 := " , err )
glog . InfoExtln ( "年缴费测试" , "err1 := " , err )
return nil , 0 , err
return nil , 0 , err
}
}
area := fmt . Sprintf ( "%0.2f" , info . PaidInArea )
//area := fmt.Sprintf("%0.2f", info.PaidInArea)
one . PaidInArea = utils . ValueToFloat ( area , 0.0 )
one . PaidInArea = utils . ValueToFloat ( area , 0.0 )
//计算应收金额和面积
//计算应收金额和面积
buildInfo := new ( BuildingInfo )
buildInfo := new ( BuildingInfo )
@ -2155,22 +2195,11 @@ func (t *Chargetab) ChargeTotalStatisticData(year int, selectType string) ([]Sum
one . ReceivableArea = utils . ValueToFloat ( ReceivableArea , 0.0 )
one . ReceivableArea = utils . ValueToFloat ( ReceivableArea , 0.0 )
money := fmt . Sprintf ( "%0.0f" , buildInfo . Constructionarea * buildInfo . Unitprice * 12 )
money := fmt . Sprintf ( "%0.0f" , buildInfo . Constructionarea * buildInfo . Unitprice * 12 )
one . ReceivableMoney = utils . ValueToFloat ( money , 0.0 )
one . ReceivableMoney = utils . ValueToFloat ( money , 0.0 )
if selectType == "current" {
one . CurrentPercent = 1
one . ArrearagePercent = 0
} else if selectType == "arrearage" {
one . CurrentPercent = 0
one . ArrearagePercent = 1
} else {
if year >= currentYear {
one . CurrentPercent = 1
one . ArrearagePercent = 0
} else {
one . CurrentPercent = 0
one . ArrearagePercent = 1
}
}
one . CurrentPercent = fmt . Sprintf ( "%.2f" , ( ( totalMoney - arrearageMoney ) / one . ReceivableMoney ) * 100 ) + "%"
one . ArrearagePercent = fmt . Sprintf ( "%.2f" , ( arrearageMoney / ( one . ReceivableMoney * float64 ( arrearageYears ) ) ) * 100 ) + "%"
glog . InfoExtln ( "年缴费测试" , "one := " , one )
glog . InfoExtln ( "年缴费测试" , "one := " , one )
datalist = append ( datalist , one )
datalist = append ( datalist , one )
sumMoney := 0.0
sumMoney := 0.0
for _ , v := range datalist {
for _ , v := range datalist {
@ -2178,4 +2207,4 @@ func (t *Chargetab) ChargeTotalStatisticData(year int, selectType string) ([]Sum
}
}
total := utils . ValueToInt ( sumMoney , 0 )
total := utils . ValueToInt ( sumMoney , 0 )
return datalist , total , nil
return datalist , total , nil
}
}