From 4b2dda8301729d97f7512505631e43478812448d Mon Sep 17 00:00:00 2001 From: Oliver Jakoubek Date: Fri, 24 Mar 2023 09:00:44 +0100 Subject: [PATCH] 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 --- ferag.go | 6 ++++-- product_reference.go | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ferag.go b/ferag.go index a4ce7be..75563fe 100644 --- a/ferag.go +++ b/ferag.go @@ -84,8 +84,10 @@ func (fs *FeragString) PrintOut() string { // AddProductReference adds a Product Reference instance to the list // of product references of the FeragString func (fs *FeragString) AddProductReference(pr *ProductReference) error { - fs.ProductReferencesNr++ - pr.SetProductReferenceNumber(fs.ProductReferencesNr) + if pr.productReferenceNumber == 0 { + fs.ProductReferencesNr++ + pr.SetProductReferenceNumber(fs.ProductReferencesNr) + } if pr.productReferenceNumber == 1 && pr.productUsageType == 0 { pr.SetProductUsageType(1) } diff --git a/product_reference.go b/product_reference.go index 8e53de2..ddd8d0f 100644 --- a/product_reference.go +++ b/product_reference.go @@ -119,13 +119,17 @@ func (pr *ProductReference) SetProductName(productName 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) { pr.productReferenceNumber = productReferenceNumber } +func (pr *ProductReference) GetProductReferenceNumber() int { + return pr.productReferenceNumber +} + func NewProductReference() *ProductReference { pr := ProductReference{ FeragMessage: FeragMessage{"2450", "!"},