44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package vo
|
|
|
|
import (
|
|
"electricity_bill_calc/model"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
type StateForm struct {
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
type ConsumptionDisplay struct {
|
|
AmountStr string `json:"amount"`
|
|
FeeStr string `json:"fee"`
|
|
PriceStr string `json:"price"`
|
|
ProportionStr string `json:"proportion"`
|
|
}
|
|
|
|
func (cd *ConsumptionDisplay) Amount(a decimal.Decimal) *ConsumptionDisplay {
|
|
cd.AmountStr = a.StringFixedBank(4)
|
|
return cd
|
|
}
|
|
|
|
func (cd *ConsumptionDisplay) Fee(f decimal.Decimal) *ConsumptionDisplay {
|
|
cd.FeeStr = f.StringFixedBank(4)
|
|
return cd
|
|
}
|
|
|
|
func (cd *ConsumptionDisplay) Price(p decimal.Decimal) *ConsumptionDisplay {
|
|
cd.PriceStr = p.StringFixedBank(8)
|
|
return cd
|
|
}
|
|
|
|
func (cd *ConsumptionDisplay) Proportion(p decimal.Decimal) *ConsumptionDisplay {
|
|
cd.ProportionStr = p.StringFixedBank(8)
|
|
return cd
|
|
}
|
|
|
|
func (cd *ConsumptionDisplay) FromConsumptionUnit(cu *model.ConsumptionUnit) ConsumptionDisplay {
|
|
cd.Amount(cu.Amount).Fee(cu.Fee).Price(cu.Price).Proportion(cu.Proportion)
|
|
return *cd
|
|
}
|