complete structure revamp
This commit is contained in:
49
api/helpers.go
Normal file
49
api/helpers.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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 string) ReceiptPay {
|
||||
return ReceiptPay{
|
||||
Type: PayTypeCard,
|
||||
Sum: sum,
|
||||
Paysys: PaySystemParkingPos,
|
||||
Cardmask: cardmask,
|
||||
BankID: bankID,
|
||||
Rrn: rrnCode,
|
||||
AuthCode: authCode,
|
||||
}
|
||||
}
|
||||
|
||||
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) Receipt {
|
||||
return Receipt{
|
||||
Sum: CalculateReceiptSum(rows),
|
||||
Round: 0.00,
|
||||
Disc: 0,
|
||||
DiscType: 0,
|
||||
Rows: rows,
|
||||
Pays: pays,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user