X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fmanage%2Fitems.php;h=06f27ea75fc98849f3e78626b70f3a14bf2de473;hb=0388050f6d4c6c7c9a9db06d2f31aa8879da69a8;hp=8ed29d2cb0bdaf7f484d86a3c7d8618f3c4fde71;hpb=4a69b00fd33fac15b82e68ef3e6a5cdae8bd6088;p=fa-stable.git diff --git a/inventory/manage/items.php b/inventory/manage/items.php index 8ed29d2c..06f27ea7 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -316,8 +316,18 @@ function item_settings(&$stock_id, $new_item) //------------------------------------------------------------------------------------ if ($new_item) { - text_row(_("Item Code:"), 'NewStockID', null, 21, 20); - + $tmpCodeID=null; + $post_label = null; + if (!empty($SysPrefs->prefs['barcodes_on_stock'])) + { + $post_label = ''; + if (isset($_POST['generateBarcode'])) + { + $tmpCodeID=generateBarcode(); + $_POST['NewStockID'] = $tmpCodeID; + } + } + text_row(_("Item Code:"), 'NewStockID', $tmpCodeID, 21, 20, null, "", $post_label); $_POST['inactive'] = 0; } else @@ -652,3 +662,41 @@ end_form(); //------------------------------------------------------------------------------------ end_page(); + +function generateBarcode() { + $tmpBarcodeID = ""; + $tmpCountTrys = 0; + while ($tmpBarcodeID == "") { + srand ((double) microtime( )*1000000); + $random_1 = rand(1,9); + $random_2 = rand(0,9); + $random_3 = rand(0,9); + $random_4 = rand(0,9); + $random_5 = rand(0,9); + $random_6 = rand(0,9); + $random_7 = rand(0,9); + //$random_8 = rand(0,9); + + // http://stackoverflow.com/questions/1136642/ean-8-how-to-calculate-checksum-digit + $sum1 = $random_2 + $random_4 + $random_6; + $sum2 = 3 * ($random_1 + $random_3 + $random_5 + $random_7 ); + $checksum_value = $sum1 + $sum2; + + $checksum_digit = 10 - ($checksum_value % 10); + if ($checksum_digit == 10) + $checksum_digit = 0; + + $random_8 = $checksum_digit; + + $tmpBarcodeID = $random_1 . $random_2 . $random_3 . $random_4 . $random_5 . $random_6 . $random_7 . $random_8; + + // LETS CHECK TO SEE IF THIS NUMBER HAS EVER BEEN USED + $query = "SELECT stock_id FROM ".TB_PREF."stock_master WHERE stock_id='" . $tmpBarcodeID . "'"; + $arr_stock = db_fetch(db_query($query)); + + if ( !$arr_stock['stock_id'] ) { + return $tmpBarcodeID; + } + $tmpBarcodeID = ""; + } +}