Files
go-vchasno-kassa/api/helpers.go

53 lines
1.1 KiB
Go

package api
func NewReceiptRow(name string, cnt int, price float64, taxgrp string) ReceiptRow {
return ReceiptRow{
Name: name,
Cnt: cnt,
Price: price,
Taxgrp: taxgrp,
}
}
func NewReceiptPayCash(sum float64, comment string) ReceiptPay {
return ReceiptPay{
Type: PayTypeCash,
Sum: sum,
Comment: comment,
}
}
func NewReceiptPayCard(sum float64, cardmask, bankID, rrnCode, authCode, terminalID, bankName string) ReceiptPay {
return ReceiptPay{
Type: PayTypeCard,
Sum: sum,
Paysys: PaySystemParkingPos,
Cardmask: cardmask,
BankID: bankID,
Rrn: rrnCode,
AuthCode: authCode,
TermID: terminalID,
BankName: bankName,
}
}
func CalculateReceiptSum(rows []ReceiptRow) float64 {
sum := 0.0
for _, row := range rows {
sum += (row.Price - row.Disc) * float64(row.Cnt)
}
return sum
}
func NewReceipt(rows []ReceiptRow, pays []ReceiptPay, commentUp string) Receipt {
return Receipt{
Sum: CalculateReceiptSum(rows),
Round: 0.00,
CommentUp: commentUp,
Disc: 0,
DiscType: 0,
Rows: rows,
Pays: pays,
}
}