DacoTaco / BarcodeParserBuilder

BarcodeParserBuilder is a .Net ( standard 2.0 & 2.1 ) nuget package to help parse & build barcode strings
https://www.nuget.org/packages/BarcodeParserBuilder
GNU Lesser General Public License v2.1
11 stars 4 forks source link

Support GTIN Parsing #3

Closed warnwar closed 2 years ago

warnwar commented 2 years ago

I'm seeing a lot of GS1 barcodes that appear to have metadata within the GTIN. It would be really great to have this parsed out.

For example, Take a look at this raw barcode: 0100367457153032 Typically represented as (01)00367457153032 on packaging. 00367457153032 is the GTIN, but this can in turn be parsed as a UPC. Right now I'm handling this by running the GTIN back through the parser after stripping the leading zeroes, but this is a workaround. Like last time I'm after the inner NDC of 6745715303.

Separately, the parser also fails when someone sends GTIN-14 values in a GS1 barcode like this: 0110333332112101 Taking the GTIN of 10333332112101 and trying to parse it as a UPC fails because the first 1 digit appears to be included in the checksum.

There should be a way to apply all the UPC parsing logic to the GTIN (with a few modifications for GTIN-14).

DacoTaco commented 2 years ago

hm, maybe i need to retackle the code i did before somehow and have the product code also be a class with sub properties that each product code type can parse separately. this way both EAN/UPC & GTIN can contain the same logic. i was thinking of maybe having the same types as before (ean, gtin, msi, ppn, hibc, ... ) but also adding a subtype. the subtype for ean/gtin could be NDC or whatever and contain properties with the data you need. this would allow for some flexible code too

also, '10333332112101' is indeed a valid GTIN-14, but the code will reject this because of the following :

warnwar commented 2 years ago

If you need anything from me, just let me know. I have all kinds of example codes that show what I'm talking about. Also, thanks for getting back to me so fast. This library is currently parsing a lot of barcodes.

DacoTaco commented 2 years ago

oh, the library is already in production? sweet! thats very cool to know!

DacoTaco commented 2 years ago

@warnwar : check out the 0.0.6-alpha.0.1 that is currently on nuget. see if it is up to spec and does what you expect it to.

you will sadly have to do some refactoring, since the schema/value stuff has been moved from barcode level to product code level, where it actually belongs. I've also merged the product code parsing from gtin & ean into the same class type.

you will have to cast the GS1/EAN's ProductCode object into a GtinProductCode to access the gtin specific value's, but thats better than screwing with them on a barcode level imo.

I also tried to have the GtinProductCode available in the barcode object itself, bypassing the casting but it was impossible to do since i want the barcode object to be generic, which was giving me casting errors. if anyone has any ideas, im open to change it.

do you also have a full GS1 barcode, with NDC ProductCode, that i can use in a unit test? im currently using some mangled up version from the product code you gave me above, and some data from another test

keep me posted!

warnwar commented 2 years ago

This is looking pretty good. The parsing for GS1 is much better, so I won't have to send the 12-digit GTIN back into the parser. I used this as a test case for myself: 0100376329334011 Feel free to use that as a unit test if it's helpful. I'll probably be parsing thousands of barcodes like that one.

The other one (I'm still not sure I 100% understand if it's a proper GTIN-14) does not seem to parse out the inner NDC like I'm hoping. Here is my example: 0110304094903115 is the raw barcode, and my NDC should be 0409490311 These seem to be less common than the first one, but hopefully there is a way to support parsing them?

DacoTaco commented 2 years ago

hey, thanks for the feedback! looks like im on a good track in implementing GTIN/EAN/UPC parsing.

from what i discovered reading specs before is that GTIN product codes' first character is like a schema, in which 0 means its a backwards compatible code or something for example the 0 in 0376329334011 means its actually a GTIN-12 aka a UPC. 3 in UPC means NDC. i assumed an extra 0 to make a GTIN-14 means the same, not sure if that is correct.

i can only assume 10304094903115 has a schema number i don't implement correctly yet though. do you have any information on this? maybe your product owner/business analyst can help with this?

EDIT : the 1 might just be an indicator to show what kind of GTIN-14 it is? source : https://en.wikipedia.org/wiki/Global_Trade_Item_Number#Format_and_encodings

warnwar commented 2 years ago

Hah, I was just about to send you the following message, looks like you beat me to the wikipedia article:

I looked around to see if I could find any decent answer as to what that first digit is supposed to be when looking at a GTIN-14, and the best answer I have is from https://en.wikipedia.org/wiki/Global_Trade_Item_Number

Indicator digit, used for GTIN-14, "1" to "8" indicates a packaging level and "9" a variable measure item. Zero in this position is not considered an Indicator Digit, but rather a pad or fill zero. There is, however, no worldwide consensus on which number indicates which packaging level and no significance should be built into this number.

To me it sounds like the 1 digit has significance to someone, but it's impossible to tell exactly what it means.

DacoTaco commented 2 years ago

alright, ill implement it as following asap : GTIN-14 : cut off indicator number and save it as a property. continue parsing it like a GTIN-13 without the indicator GTIN-13 : check first 2 digits. if its a 0 or 02 -> parse as GTIN-12, otherwise parse it like any other GTIN product code GTIN-12/ UPC : check schema and parse it accordingly

with the refactor it's actually not that complicated to implement that

DacoTaco commented 2 years ago

@warnwar : i have made the changes and uploaded a new alpha to nuget. can you verify it detects the NDC correctly now?

DacoTaco commented 2 years ago

@warnwar : any updates?

warnwar commented 2 years ago

@DacoTaco Sorry! I was gone for a few days, so today was the first time I was able to test 0.0.6-alpha.0.3 and it looks really good. I am seeing the NDC pulled out of GTIN even when they are a GTIN-14 with an indicator value, so this looks really great. As far as I need, that version looks ready for me to use.

DacoTaco commented 2 years ago

@warnwar thanks for confirming and sorry to have bothered you! version 0.0.6 has been uploaded and is currently being processed on nuget.org thanks to help me improve the project !