Documentation
¶
Index ¶
- Constants
- type Charge
- type ChargeQualifier
- type Charges
- func (c Charges) Add(toadd Charges) Charges
- func (c Charges) AddCharge(toadd Charge) Charges
- func (c Charges) GetAllByType(ctype string) map[ChargeQualifier]Charge
- func (c Charges) GetAllCharges() map[ChargeQualifier]Charge
- func (c Charges) GetByChargeQualifier(qualifier ChargeQualifier) (Charge, bool)
- func (c Charges) GetByChargeQualifierForced(qualifier ChargeQualifier) Charge
- func (c Charges) GetByType(ctype string) (Charge, bool)
- func (c Charges) GetByTypeForced(ctype string) Charge
- func (c Charges) HasChargeQualifier(qualifier ChargeQualifier) bool
- func (c Charges) HasType(ctype string) bool
- func (c Charges) Items() []Charge
- func (c Charges) Mul(qty int) Charges
- type Price
- func (p Price) Add(add Price) (Price, error)
- func (p Price) Amount() *big.Float
- func (p Price) Clone() Price
- func (p Price) Currency() string
- func (p Price) Discounted(percent float64) Price
- func (p Price) Divided(qty int) Price
- func (p Price) Equal(cmp Price) bool
- func (p Price) FloatAmount() float64
- func (p Price) ForceAdd(add Price) Price
- func (p Price) GetPayable() Price
- func (p Price) GetPayableByRoundingMode(mode string, precision int) Price
- func (p Price) Inverse() Price
- func (p Price) IsGreaterThen(cmp Price) bool
- func (p Price) IsGreaterThenValue(amount big.Float) bool
- func (p Price) IsLessThen(cmp Price) bool
- func (p Price) IsLessThenValue(amount big.Float) bool
- func (p Price) IsNegative() bool
- func (p Price) IsPayable() bool
- func (p Price) IsPositive() bool
- func (p Price) IsZero() bool
- func (p Price) LikelyEqual(cmp Price) bool
- func (p Price) MarshalBinary() (data []byte, err error)
- func (p Price) MarshalJSON() (data []byte, err error)
- func (p Price) Multiply(qty int) Price
- func (p Price) SplitInPayables(count int) ([]Price, error)
- func (p Price) Sub(sub Price) (Price, error)
- func (p Price) TaxFromGross(percent big.Float) Price
- func (p Price) TaxFromNet(percent big.Float) Price
- func (p Price) Taxed(percent big.Float) Price
- func (p *Price) UnmarshalBinary(data []byte) error
Constants ¶
const ( //ChargeTypeGiftCard used as a charge type for gift cards ChargeTypeGiftCard = "giftcard" //ChargeTypeMain used as default for a Charge ChargeTypeMain = "main" //RoundingModeFloor - use if you want to cut (round down) RoundingModeFloor = "floor" //RoundingModeCeil - use if you want to round up always RoundingModeCeil = "ceil" //RoundingModeHalfUp - default for GetPayable() RoundingModeHalfUp = "halfup" //RoundingModeHalfDown - in cases where you want to round down on .5 RoundingModeHalfDown = "halfdown" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Charge ¶
type Charge struct { //Price that is paid, can be in a certain currency Price Price //Value of the "Price" in another (base) currency Value Price //Type of the charge - can be ChargeTypeMain or something else. Used to differentiate between different charges of a single thing Type string // Reference contains further information to distinguish charges of the same type Reference string }
Charge is a Amount of a certain Type. Charge is used as value object
type ChargeQualifier ¶
type ChargeQualifier struct { // Type represents charge type Type string // Reference contains further information to distinguish charges of the same type Reference string }
ChargeQualifier distinguishes charges by type and reference
type Charges ¶
type Charges struct {
// contains filtered or unexported fields
}
Charges - Represents the Charges the product need to be paid with
func NewCharges ¶
NewCharges creates a new Charges object
func (Charges) GetAllByType ¶
func (c Charges) GetAllByType(ctype string) map[ChargeQualifier]Charge
GetAllByType returns all charges of type
func (Charges) GetAllCharges ¶
func (c Charges) GetAllCharges() map[ChargeQualifier]Charge
GetAllCharges - returns all charges
func (Charges) GetByChargeQualifier ¶
func (c Charges) GetByChargeQualifier(qualifier ChargeQualifier) (Charge, bool)
GetByChargeQualifier returns a charge of given qualifier. If it was not found a Zero amount is returned and the second return value is false
func (Charges) GetByChargeQualifierForced ¶
func (c Charges) GetByChargeQualifierForced(qualifier ChargeQualifier) Charge
GetByChargeQualifierForced returns a charge of given qualifier. If it was not found a Zero amount is returned. This method might be useful to call in View (template) directly.
func (Charges) GetByType ¶
GetByType - returns a charge of given type. If it was not found a Zero amount is returned and the second return value is false sums up charges by a certain type if there are multiple
func (Charges) GetByTypeForced ¶
GetByTypeForced - returns a charge of given type. If it was not found a Zero amount is returned. This method might be useful to call in View (template) directly where you need one return value sums up charges by a certain type if there are multiple
func (Charges) HasChargeQualifier ¶
func (c Charges) HasChargeQualifier(qualifier ChargeQualifier) bool
HasChargeQualifier - returns a true if any charges include a charge with given type and concrete key values provided by additional
type Price ¶
type Price struct {
// contains filtered or unexported fields
}
Price is a Type that represents a Amount - it is immutable DevHint: We use Amount and Charge as Value - so we do not pass pointers. (According to Go Wiki's code review comments page suggests passing by value when structs are small and likely to stay that way)
func NewFromBigFloat ¶
NewFromBigFloat - factory method
func NewFromFloat ¶
NewFromFloat - factory method
func NewFromInt ¶
NewFromInt use to set money by smallest payable unit - e.g. to set 2.45 EUR you should use NewFromInt(245,100)
func (Price) Discounted ¶
Discounted - returns new price reduced by given percent
func (Price) FloatAmount ¶
FloatAmount gets the current amount as float
func (Price) ForceAdd ¶
ForceAdd - tries to Adds the given price to the current price - will not return errors
func (Price) GetPayable ¶
GetPayable - rounds the price with the precision required by the currency in a price that can actually be paid e.g. an internal amount of 1,23344 will get rounded to 1,23
func (Price) GetPayableByRoundingMode ¶
GetPayableByRoundingMode - a flexible rounding method where you can pass rounding mode and precision 1.115 > 1.12 (RoundingModeHalfUp) / 1.11 (RoundingModeFloor) -1.115 > -1.11 (RoundingModeHalfUp) / -1.12 (RoundingModeFloor)
func (Price) IsGreaterThen ¶
IsGreaterThen - compares the prices
func (Price) IsGreaterThenValue ¶
IsGreaterThenValue compares the price with a given amount value (assuming same currency)
func (Price) IsLessThen ¶
IsLessThen - compares the prices
func (Price) IsLessThenValue ¶
IsLessThenValue compares the price with a given amount value (assuming same currency)
func (Price) IsNegative ¶
IsNegative - returns true if the price represents a negative value
func (Price) IsPositive ¶
IsPositive - returns true if the price represents a positive value
func (Price) LikelyEqual ¶
LikelyEqual - compares the prices with some tolerance
func (Price) MarshalBinary ¶
MarshalBinary - implements interface required by gob
func (Price) MarshalJSON ¶
MarshalJSON - implements interface required by json marshal
func (Price) SplitInPayables ¶
SplitInPayables - returns "count" payable prices (each rounded) that in sum matches the given price
- Given a price of 12.456 (Payable 12,46) - Splitted in 6 will mean: 6 * 2.076
- but having them payable requires rounding them each (e.g. 2.07) which would mean we have 0.03 difference (=12,45-6*2.07)
- so that the sum is as close as possible to the original value in this case the correct return will be:
- 2.07 + 2.07+2.08 +2.08 +2.08 +2.08
func (Price) TaxFromGross ¶
TaxFromGross - returns new price representing the taxamount (assuming the current price is gross 100+percent)
func (Price) TaxFromNet ¶
TaxFromNet - returns new price representing the taxamount (assuming the current price is net 100%)
func (*Price) UnmarshalBinary ¶
UnmarshalBinary - implements interface required by gob. UnmarshalBinary - modifies the receiver so it must take a pointer receiver!