Add products with a product reference number

A product reference number is only assigned (and the central counter incremented) if the product has no product reference number attached.
Fixes #14
This commit is contained in:
Oliver Jakoubek 2023-03-24 09:00:44 +01:00
parent 0a14f56ddb
commit 4b2dda8301
2 changed files with 9 additions and 3 deletions

View file

@ -84,8 +84,10 @@ func (fs *FeragString) PrintOut() string {
// AddProductReference adds a Product Reference instance to the list // AddProductReference adds a Product Reference instance to the list
// of product references of the FeragString // of product references of the FeragString
func (fs *FeragString) AddProductReference(pr *ProductReference) error { func (fs *FeragString) AddProductReference(pr *ProductReference) error {
fs.ProductReferencesNr++ if pr.productReferenceNumber == 0 {
pr.SetProductReferenceNumber(fs.ProductReferencesNr) fs.ProductReferencesNr++
pr.SetProductReferenceNumber(fs.ProductReferencesNr)
}
if pr.productReferenceNumber == 1 && pr.productUsageType == 0 { if pr.productReferenceNumber == 1 && pr.productUsageType == 0 {
pr.SetProductUsageType(1) pr.SetProductUsageType(1)
} }

View file

@ -119,13 +119,17 @@ func (pr *ProductReference) SetProductName(productName string) {
} }
func (pr *ProductReference) ProductReferenceNumber() string { func (pr *ProductReference) ProductReferenceNumber() string {
return fmt.Sprintf("+41%02d", pr.productReferenceNumber) return fmt.Sprintf("+99141%03d", pr.productReferenceNumber)
} }
func (pr *ProductReference) SetProductReferenceNumber(productReferenceNumber int) { func (pr *ProductReference) SetProductReferenceNumber(productReferenceNumber int) {
pr.productReferenceNumber = productReferenceNumber pr.productReferenceNumber = productReferenceNumber
} }
func (pr *ProductReference) GetProductReferenceNumber() int {
return pr.productReferenceNumber
}
func NewProductReference() *ProductReference { func NewProductReference() *ProductReference {
pr := ProductReference{ pr := ProductReference{
FeragMessage: FeragMessage{"2450", "!"}, FeragMessage: FeragMessage{"2450", "!"},