<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=7898&amp;type=atom" />
	<updated>2018-12-24T09:24:15Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=7898</id>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33746#p33746" />
			<content type="html"><![CDATA[<p>CODE128 supports the entire ASCII set (Type B has lower and upper case as well) and would be useful if a mere character check is inculcated till a complete induction occurs. Also choice of Barcode Type may be included in the <strong>sys_prefs</strong> table. That would ofcourse preclude the use of multiple types of Barcodes in the same company.</p><p>The above test will fail if CODE128 or those other than the leading ones like EAN% and UPC% are checked since the foreach() traverses the array in order of the array elements. The earliest &quot;true&quot; when returned may not be right!</p><p>Whilst testing is in progress, a flag to suppress Barcode validation may be preferred.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2018-12-24T09:24:15Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33746#p33746</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33742#p33742" />
			<content type="html"><![CDATA[<p>We have now established a Barcode Checker for the following types: <br /></p><div class="codebox"><pre><code>EAN, EAN-8, EAN-13, GTIN-8, GTIN-12, GTIN-14, UPC, UPC-12 coupon code, JAN </code></pre></div><p>This will be committed in a while.<br />If we later find som further testing of barcode types we will add these as well.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2018-12-23T23:35:45Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33742#p33742</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33741#p33741" />
			<content type="html"><![CDATA[<p>We don&#039;t have a $type when calling is_valid_barcode.</p><p>I have been trying this:<br /></p><div class="codebox"><pre><code>function is_valid_barcode($code)
{
    $types = array(&quot;EAN2&quot;, &quot;EAN5&quot;, &quot;EAN8&quot;, &quot;EAN13&quot;, &quot;UPCA&quot;, &quot;UPCE&quot;, &quot;C39&quot;, &quot;C39+&quot;, &quot;C39E&quot;, &quot;C39E+&quot;, &quot;I25&quot;, 
        &quot;C128A&quot;, &quot;C128B&quot;, &quot;C128C&quot;, &quot;POSTNET&quot;, &quot;CODABAR&quot;);

    foreach ($types as $type)
    {
        if (substr($type, 0, 3) === &quot;EAN&quot; || substr($type, 0, 3) == &quot;UPC&quot;)
        {
            if (!preg_match(&quot;/^[0-9]+$/&quot;, $code))
                continue;
        }        
           $barcode = new TCPDFBarcode($code, $type);
        $chk = $barcode-&gt;getBarcodeArray();
        if ($chk !== false)
            return true;
    }
    return false;
}</code></pre></div><p>But if alphanumerical characters it is still testing. It shouldn&#039;t if EAN of UPC. Please try it.</p><p>Maybe I have overseen something, so please help.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2018-12-23T16:32:11Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33741#p33741</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33740#p33740" />
			<content type="html"><![CDATA[<p>The following should do the trick:<br /></p><div class="codebox"><pre><code>include $path_to_root.&quot;reporting/includes/barcode.php&quot;;

function is_valid_barcode($code, $type) {
    $barcode = new TCPDFBarcode($code, $type);
    $chk = $barcode-&gt;getBarcodeArray();
    return ($chk !== false);
}</code></pre></div><p>The possible barcode types that tcpdf supports in FA are:<br /></p><div class="codebox"><pre><code>$barcode[&#039;C39&#039;][&#039;name&#039;]     = &#039;CODE 39&#039;;
$barcode[&#039;C39+&#039;][&#039;name&#039;]    = &#039;CODE 39 with checksum&#039;;
$barcode[&#039;C39E&#039;][&#039;name&#039;]    = &#039;CODE 39 EXTENDED&#039;;
$barcode[&#039;C39E+&#039;][&#039;name&#039;]   = &#039;CODE 39 EXTENDED with checksum&#039;;
$barcode[&#039;I25&#039;][&#039;name&#039;]     = &#039;Interleaved 2 of 5&#039;;
$barcode[&#039;C128A&#039;][&#039;name&#039;]   = &#039;CODE 128 A&#039;;
$barcode[&#039;C128B&#039;][&#039;name&#039;]   = &#039;CODE 128 B&#039;;
$barcode[&#039;C128C&#039;][&#039;name&#039;]   = &#039;CODE 128 C&#039;;
$barcode[&#039;EAN2&#039;][&#039;name&#039;]    = &#039;2-Digits UPC-Based Extension&#039;;
$barcode[&#039;EAN5&#039;][&#039;name&#039;]    = &#039;5-Digits UPC-Based Extension&#039;;
$barcode[&#039;EAN8&#039;][&#039;name&#039;]    = &#039;EAN 8&#039;;
$barcode[&#039;EAN13&#039;][&#039;name&#039;]   = &#039;EAN 13&#039;;
$barcode[&#039;UPCA&#039;][&#039;name&#039;]    = &#039;UPC-A&#039;;
$barcode[&#039;UPCE&#039;][&#039;name&#039;]    = &#039;UPC-E&#039;;
$barcode[&#039;POSTNET&#039;][&#039;name&#039;] = &#039;POSTNET&#039;;
$barcode[&#039;CODABAR&#039;][&#039;name&#039;] = &#039;CODABAR&#039;;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2018-12-23T15:49:14Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33740#p33740</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33739#p33739" />
			<content type="html"><![CDATA[<p>No, I couldn&#039;t get it to work. So I will have to leave it as is.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2018-12-23T13:02:32Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33739#p33739</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33736#p33736" />
			<content type="html"><![CDATA[<p>Maybe we can use the class TCPDFBarcode in <strong>/reporting/includes/barcodes.php</strong> för testing of valid barcodes. I will give it a try.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2018-12-23T08:50:14Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33736#p33736</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33735#p33735" />
			<content type="html"><![CDATA[<p>Or this one. Taken from <a href="https://www.phpclasses.org/browse/file/52224.html">PHP Classes</a>.&nbsp; It is a class, but I extracted the function.<br /></p><div class="codebox"><pre><code>&lt;?php
/* Check length of barcode for validity via the checkdigit calculation
 * We split the barcode into it&#039;s constituent digits, offset them into the GTIN
 * calculation tuple (x1, x3, x1, x3, x1, etc, etc), multiply the digits and add
 * them together, then modulo them on 10, and you get the calculated check digit.
 * For more information see GS1 website: https://www.gs1.org/check-digit-calculator
 * @param string gtin
 * @return bool */
function Checkgtin($gtin) 
{
    /* Checks the length of the GTIN
     * @param string gtin
     * @return bool */
    // Check length is ok
    if (strlen($gtin) &lt; 8 || strlen($gtin) &gt; 14)
        return false;

    // Check whether is a number
    preg_match(&quot;/\d+/&quot;, $gtin, $m, PREG_OFFSET_CAPTURE, 0);
    if (empty($m))
        return false;

    // Define fixed variables
    $CheckDigitArray = [];
    $gtinMaths = [3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3];
    $modifier = 17 - (strlen($gtin) - 1);  // Gets the position to place first digit in array
    $gtinCheckDigit = substr($gtin, -1); // Get provided check digit
    $BarcodeArray = str_split($gtin);  // Split barcode at each digit into array
    $gtinLength = strlen($gtin);
    $tmpCheckDigit = 0;
    $tmpCheckSum = 0;
    $tmpMath = 0;

    // Run through and put digits into multiplication table
    for ($i = 0; $i &lt; ($gtinLength - 1); $i++) {
        $CheckDigitArray[$modifier + $i] = $BarcodeArray[$i];  // Add barcode digits to Multiplication Table
    }

    // Calculate &quot;Sum&quot; of barcode digits
    for ($i = $modifier; $i &lt; 17; $i++) {
        $tmpCheckSum += ($CheckDigitArray[$i] * $gtinMaths[$i]);
    }

    // Difference from Rounded-Up-To-Nearest-10 - Fianl Check Digit Calculation
    $tmpCheckDigit = (ceil($tmpCheckSum / 10) * 10) - $tmpCheckSum;

    // Check if last digit is same as calculated check digit
    if ($gtinCheckDigit == $tmpCheckDigit)
        return true;
    return false;
}
  
$gtin = &quot;00abcd&quot;;
if (Checkgtin($gtin))
    echo &quot;$gtin is ok&lt;br /&gt;&quot;;
else    
    echo &quot;$gtin is NOT ok&lt;br /&gt;&quot;;</code></pre></div><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2018-12-23T07:16:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33735#p33735</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33734#p33734" />
			<content type="html"><![CDATA[<p>I found this class for Barcode validation on github. Maybe we could extract a function or use the class for validation:</p><p><a href="https://github.com/imelgrat/barcode-validator/blob/master/src/barcode-validator.php">Barcode validator</a>.</p><p>I wonder if this could be used.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2018-12-23T07:11:38Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33734#p33734</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Numeric BarCode restriction / Valid Alphanumeric filter]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33733#p33733" />
			<content type="html"><![CDATA[<p>A recent <a href="https://github.com/FrontAccountingERP/FA/commit/78292081998dbf40c461bb44b2c2e0d228933bbf">commit</a> restricts BarCodes to be generated only if the <strong>stock_id</strong> is an integer.</p><p>This was done since the Barcode generation routine generated errors on malformed input as a stop-gap arrangement since the auto generation of Barcode <strong>stock_id</strong> was restricted to a random / sequential available number.</p><p>The file <strong>/reporting/includes/barcodes.php</strong> manages Barcode generation and is taken from the <a href="https://github.com/tecnickcom/TCPDF/blob/master/tcpdf_barcodes_1d.php">TCPDF Library</a>.</p><p>In the said library above, each type of barcode is properly generated with the appropriate methods listing the valid ASCII codes and size range / limits along with check-digit computations and verification where enabled.</p><p>The following links in reference are in order:<br />1. <a href="http://www.makebarcode.com/specs/speclist.html">Make BarCode</a><br />2. <a href="https://www.barcoderesource.com/code128_barcodefont.html">BarCode Resource</a><br />3. <a href="https://www.keyence.com/ss/products/auto_id/barcode_lecture/basic/code128/">Keyence</a></p><p>Clearly, the <strong>stock_id</strong> and <strong>item_code</strong> fields are VARCHAR in the FA DB and several BarCode formats support alphanumeric characters (CODE128, Codabar, etc) and some even symbols too.</p><p>Currently available libraries:<br />1. A Zend Library Validation of BarCode &quot;code&quot; input is also <a href="https://framework.zend.com/manual/2.0/en/modules/zend.validator.barcode.html">available</a>.<br />2. A JavaScript Validation of a few barcode formats are available <a href="https://stackoverflow.com/questions/13605340/how-to-validate-a-ean-gtin-barcode-in-javascript">here</a>.</p><p>The need now is to hammer out a function to validate the <strong>stock_id</strong> before allowing the generation of the barcode in pure PHP without external dependancies so that errors don&#039;t get generated while doing so during generation.</p><p>Any suggestions?</p><p>Blindly suppressing all errors during Barcode generation and leaving it blank when not possible to generate on for whatever reason is a simplistic but effective choice for many.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2018-12-23T03:33:36Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33733#p33733</id>
		</entry>
</feed>
