2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_ITEM';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15 include($path_to_root . "/reporting/includes/tcpdf.php");
18 if ($SysPrefs->use_popup_windows)
19 $js .= get_js_open_window(900, 500);
20 if (user_use_date_picker())
21 $js .= get_js_date_picker();
23 if (isset($_GET['FixedAsset'])) {
24 $page_security = 'SA_ASSET';
25 $_SESSION['page_title'] = _($help_context = "Fixed Assets");
26 $_POST['mb_flag'] = 'F';
27 $_POST['fixed_asset'] = 1;
30 $_SESSION['page_title'] = _($help_context = "Items");
31 if (!get_post('fixed_asset'))
32 $_POST['fixed_asset'] = 0;
36 page($_SESSION['page_title'], @$_REQUEST['popup'], false, "", $js);
38 include_once($path_to_root . "/includes/date_functions.inc");
39 include_once($path_to_root . "/includes/ui.inc");
40 include_once($path_to_root . "/includes/data_checks.inc");
42 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
43 include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc");
45 $user_comp = user_company();
46 $new_item = get_post('stock_id')=='' || get_post('cancel') || get_post('clone');
47 //------------------------------------------------------------------------------------
48 function set_edit($stock_id)
50 $_POST = array_merge($_POST, get_item($stock_id));
52 $_POST['depreciation_rate'] = number_format2($_POST['depreciation_rate'], 1);
53 $_POST['depreciation_factor'] = number_format2($_POST['depreciation_factor'], 1);
54 $_POST['depreciation_start'] = sql2date($_POST['depreciation_start']);
55 $_POST['depreciation_date'] = sql2date($_POST['depreciation_date']);
56 $_POST['del_image'] = 0;
59 if (isset($_GET['stock_id']))
61 $_POST['stock_id'] = $_GET['stock_id'];
63 $stock_id = get_post('stock_id');
64 if (list_updated('stock_id')) {
65 $_POST['NewStockID'] = $stock_id = get_post('stock_id');
67 $Ajax->activate('details');
68 $Ajax->activate('controls');
71 if (get_post('cancel')) {
72 $_POST['NewStockID'] = $stock_id = $_POST['stock_id'] = '';
74 set_focus('stock_id');
75 $Ajax->activate('_page_body');
77 if (list_updated('category_id') || list_updated('mb_flag') || list_updated('fa_class_id') || list_updated('depreciation_method')) {
78 $Ajax->activate('details');
81 if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '')
83 $stock_id = $_POST['NewStockID'];
84 $result = $_FILES['pic']['error'];
85 $upload_file = 'Yes'; //Assume all is well to start off with
86 $filename = company_path().'/images';
87 if (!file_exists($filename))
91 $filename .= "/".item_img_name($stock_id).(substr(trim($_FILES['pic']['name']), strrpos($_FILES['pic']['name'], '.')));
93 if ($_FILES['pic']['error'] == UPLOAD_ERR_INI_SIZE) {
94 display_error(_('The file size is over the maximum allowed.'));
97 elseif ($_FILES['pic']['error'] > 0) {
98 display_error(_('Error uploading file.'));
102 //But check for the worst
103 if ((list($width, $height, $type, $attr) = getimagesize($_FILES['pic']['tmp_name'])) !== false)
108 if ($imagetype != IMAGETYPE_GIF && $imagetype != IMAGETYPE_JPEG && $imagetype != IMAGETYPE_PNG)
110 display_warning( _('Only graphics files can be uploaded'));
113 elseif (!in_array(strtoupper(substr(trim($_FILES['pic']['name']), strlen($_FILES['pic']['name']) - 3)), array('JPG','PNG','GIF')))
115 display_warning(_('Only graphics files are supported - a file extension of .jpg, .png or .gif is expected'));
118 elseif ( $_FILES['pic']['size'] > ($SysPrefs->max_image_size * 1024))
120 display_warning(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $SysPrefs->max_image_size);
123 elseif ( $_FILES['pic']['type'] == "text/plain" )
125 display_warning( _('Only graphics files can be uploaded'));
128 elseif (file_exists($filename))
130 $result = unlink($filename);
133 display_error(_('The existing image could not be removed'));
138 if ($upload_file == 'Yes')
140 $result = move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
141 if ($msg = check_image_file($filename)) {
147 $Ajax->activate('details');
148 /* EOF Add Image upload for New Item - by Ori */
151 if (get_post('fixed_asset')) {
152 check_db_has_fixed_asset_categories(_("There are no fixed asset categories defined in the system. At least one fixed asset category is required to add a fixed asset."));
153 check_db_has_fixed_asset_classes(_("There are no fixed asset classes defined in the system. At least one fixed asset class is required to add a fixed asset."));
155 check_db_has_stock_categories(_("There are no item categories defined in the system. At least one item category is required to add a item."));
157 check_db_has_item_tax_types(_("There are no item tax types defined in the system. At least one item tax type is required to add a item."));
159 function clear_data()
161 unset($_POST['long_description']);
162 unset($_POST['description']);
163 unset($_POST['category_id']);
164 unset($_POST['tax_type_id']);
165 unset($_POST['units']);
166 unset($_POST['mb_flag']);
167 unset($_POST['NewStockID']);
168 unset($_POST['dimension_id']);
169 unset($_POST['dimension2_id']);
170 unset($_POST['no_sale']);
171 unset($_POST['no_purchase']);
172 unset($_POST['depreciation_method']);
173 unset($_POST['depreciation_rate']);
174 unset($_POST['depreciation_factor']);
175 unset($_POST['depreciation_start']);
178 //------------------------------------------------------------------------------------
180 if (isset($_POST['addupdate']))
184 if ($upload_file == 'No')
186 if (strlen($_POST['description']) == 0)
189 display_error( _('The item name must be entered.'));
190 set_focus('description');
192 elseif (strlen($_POST['NewStockID']) == 0)
195 display_error( _('The item code cannot be empty'));
196 set_focus('NewStockID');
198 elseif (strstr($_POST['NewStockID'], " ") || strstr($_POST['NewStockID'],"'") ||
199 strstr($_POST['NewStockID'], "+") || strstr($_POST['NewStockID'], "\"") ||
200 strstr($_POST['NewStockID'], "&") || strstr($_POST['NewStockID'], "\t"))
203 display_error( _('The item code cannot contain any of the following characters - & + OR a space OR quotes'));
204 set_focus('NewStockID');
207 elseif ($new_item && db_num_rows(get_item_kit($_POST['NewStockID'])))
210 display_error( _("This item code is already assigned to stock item or sale kit."));
211 set_focus('NewStockID');
214 if (get_post('fixed_asset')) {
215 if ($_POST['depreciation_rate'] > 100) {
216 $_POST['depreciation_rate'] = 100;
218 elseif ($_POST['depreciation_rate'] < 0) {
219 $_POST['depreciation_rate'] = 0;
221 $move_row = get_fixed_asset_move($_POST['NewStockID'], ST_SUPPRECEIVE);
222 if ($move_row && isset($_POST['depreciation_start']) && strtotime($_POST['depreciation_start']) < strtotime($move_row['tran_date'])) {
223 display_warning(_('The depracation cannot start before the fixed asset purchase date'));
227 if ($input_error != 1)
229 if (check_value('del_image'))
231 $filename = company_path().'/images/'.item_img_name($_POST['NewStockID']).".jpg";
232 if (file_exists($filename))
237 { /*so its an existing one */
238 update_item($_POST['NewStockID'], $_POST['description'],
239 $_POST['long_description'], $_POST['category_id'],
240 $_POST['tax_type_id'], get_post('units'),
241 get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'],
242 $_POST['inventory_account'], $_POST['cogs_account'],
243 $_POST['adjustment_account'], $_POST['wip_account'],
244 $_POST['dimension_id'], $_POST['dimension2_id'],
245 check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
246 get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start', null),
247 get_post('fa_class_id'));
249 update_record_status($_POST['NewStockID'], $_POST['inactive'],
250 'stock_master', 'stock_id');
251 update_record_status($_POST['NewStockID'], $_POST['inactive'],
252 'item_codes', 'item_code');
253 set_focus('stock_id');
254 $Ajax->activate('stock_id'); // in case of status change
255 display_notification(_("Item has been updated."));
260 add_item($_POST['NewStockID'], $_POST['description'],
261 $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'],
262 $_POST['units'], get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'],
263 $_POST['inventory_account'], $_POST['cogs_account'],
264 $_POST['adjustment_account'], $_POST['wip_account'],
265 $_POST['dimension_id'], $_POST['dimension2_id'],
266 check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
267 get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start', null),
268 get_post('fa_class_id'));
270 display_notification(_("A new item has been added."));
271 $_POST['stock_id'] = $_POST['NewStockID'] =
272 $_POST['description'] = $_POST['long_description'] = '';
273 $_POST['no_sale'] = $_POST['editable'] = $_POST['no_purchase'] =0;
274 set_focus('NewStockID');
276 $Ajax->activate('_page_body');
280 if (get_post('clone')) {
281 set_edit($_POST['stock_id']); // restores data for disabled inputs too
282 unset($_POST['stock_id']);
284 unset($_POST['inactive']);
285 set_focus('NewStockID');
286 $Ajax->activate('_page_body');
289 //------------------------------------------------------------------------------------
291 function check_usage($stock_id, $dispmsg=true)
293 $msg = item_in_foreign_codes($stock_id);
296 if($dispmsg) display_error($msg);
302 //------------------------------------------------------------------------------------
304 if (isset($_POST['delete']) && strlen($_POST['delete']) > 1)
307 if (check_usage($_POST['NewStockID'])) {
309 $stock_id = $_POST['NewStockID'];
310 delete_item($stock_id);
311 $filename = company_path().'/images/'.item_img_name($stock_id).".jpg";
312 if (file_exists($filename))
314 display_notification(_("Selected item has been deleted."));
315 $_POST['stock_id'] = '';
317 set_focus('stock_id');
319 $Ajax->activate('_page_body');
323 function item_settings(&$stock_id, $new_item)
325 global $SysPrefs, $path_to_root, $page_nested, $depreciation_methods;
327 start_outer_table(TABLESTYLE2);
331 table_section_title(_("General Settings"));
333 //------------------------------------------------------------------------------------
338 if (!empty($SysPrefs->prefs['barcodes_on_stock']))
340 $post_label = '<button class="ajaxsubmit" type="submit" aspect=\'default\' name="generateBarcode" id="generateBarcode" value="Generate Barcode EAN8"> '._("Generate EAN-8 Barcode").' </button>';
341 if (isset($_POST['generateBarcode']))
343 $tmpCodeID=generateBarcode();
344 $_POST['NewStockID'] = $tmpCodeID;
347 text_row(_("Item Code:"), 'NewStockID', $tmpCodeID, 21, 20, null, "", $post_label);
348 $_POST['inactive'] = 0;
351 { // Must be modifying an existing item
352 if (get_post('NewStockID') != get_post('stock_id') || get_post('addupdate')) { // first item display
354 $_POST['NewStockID'] = $_POST['stock_id'];
355 set_edit($_POST['stock_id']);
357 label_row(_("Item Code:"),$_POST['NewStockID']);
358 hidden('NewStockID', $_POST['NewStockID']);
359 set_focus('description');
361 $fixed_asset = get_post('fixed_asset');
363 text_row(_("Name:"), 'description', null, 52, 200);
365 textarea_row(_('Description:'), 'long_description', null, 42, 3);
367 stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item, $fixed_asset);
369 if ($new_item && (list_updated('category_id') || !isset($_POST['sales_account']))) { // changed category for new item or first page view
371 $category_record = get_item_category($_POST['category_id']);
373 $_POST['tax_type_id'] = $category_record["dflt_tax_type"];
374 $_POST['units'] = $category_record["dflt_units"];
375 $_POST['mb_flag'] = $category_record["dflt_mb_flag"];
376 $_POST['inventory_account'] = $category_record["dflt_inventory_act"];
377 $_POST['cogs_account'] = $category_record["dflt_cogs_act"];
378 $_POST['sales_account'] = $category_record["dflt_sales_act"];
379 $_POST['adjustment_account'] = $category_record["dflt_adjustment_act"];
380 $_POST['wip_account'] = $category_record["dflt_wip_act"];
381 $_POST['dimension_id'] = $category_record["dflt_dim1"];
382 $_POST['dimension2_id'] = $category_record["dflt_dim2"];
383 $_POST['no_sale'] = $category_record["dflt_no_sale"];
384 $_POST['no_purchase'] = $category_record["dflt_no_purchase"];
385 $_POST['editable'] = 0;
388 $fresh_item = !isset($_POST['NewStockID']) || $new_item
389 || check_usage($_POST['stock_id'],false);
391 // show inactive item tax type in selector only if already set.
392 item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null, !$new_item && item_type_inactive(get_post('tax_type_id')));
394 if (!get_post('fixed_asset'))
395 stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item);
397 stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item);
400 if (!get_post('fixed_asset')) {
401 check_row(_("Editable description:"), 'editable');
402 check_row(_("Exclude from sales:"), 'no_sale');
403 check_row(_("Exclude from purchases:"), 'no_purchase');
406 if (get_post('fixed_asset')) {
407 table_section_title(_("Depreciation"));
409 fixed_asset_classes_list_row(_("Fixed Asset Class").':', 'fa_class_id', null, false, true);
411 array_selector_row(_("Depreciation Method").":", "depreciation_method", null, $depreciation_methods, array('select_submit'=> true));
413 if (!isset($_POST['depreciation_rate']) || (list_updated('fa_class_id') || list_updated('depreciation_method'))) {
414 $class_row = get_fixed_asset_class($_POST['fa_class_id']);
415 $_POST['depreciation_rate'] = get_post('depreciation_method') == 'N' ? ceil(100/$class_row['depreciation_rate'])
416 : $class_row['depreciation_rate'];
419 if ($_POST['depreciation_method'] == 'O')
421 hidden('depreciation_rate', 100);
422 label_row(_("Depreciation Rate").':', "100 %");
424 elseif ($_POST['depreciation_method'] == 'N')
426 small_amount_row(_("Depreciation Years").':', 'depreciation_rate', null, null, _('years'), 0);
428 elseif ($_POST['depreciation_method'] == 'D')
429 small_amount_row(_("Base Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
431 small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
433 if ($_POST['depreciation_method'] == 'D')
434 small_amount_row(_("Rate multiplier").':', 'depreciation_factor', null, null, '', 2);
436 // do not allow to change the depreciation start after this item has been depreciated
437 if ($new_item || $_POST['depreciation_start'] == $_POST['depreciation_date'])
438 date_row(_("Depreciation Start").':', 'depreciation_start', null, null, 1 - date('j'));
440 hidden('depreciation_start');
441 label_row(_("Depreciation Start").':', $_POST['depreciation_start']);
442 label_row(_("Last Depreciation").':', $_POST['depreciation_date']==$_POST['depreciation_start'] ? _("None") : $_POST['depreciation_date']);
444 hidden('depreciation_date');
448 $dim = get_company_pref('use_dimension');
451 table_section_title(_("Dimensions"));
453 dimensions_list_row(_("Dimension")." 1", 'dimension_id', null, true, " ", false, 1);
455 dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
458 hidden('dimension_id', 0);
460 hidden('dimension2_id', 0);
462 table_section_title(_("GL Accounts"));
464 gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
466 if (get_post('fixed_asset')) {
467 gl_all_accounts_list_row(_("Asset account:"), 'inventory_account', $_POST['inventory_account']);
468 gl_all_accounts_list_row(_("Depreciation cost account:"), 'cogs_account', $_POST['cogs_account']);
469 gl_all_accounts_list_row(_("Depreciation/Disposal account:"), 'adjustment_account', $_POST['adjustment_account']);
471 elseif (!is_service(get_post('mb_flag')))
473 gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
474 gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
475 gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
479 gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
480 hidden('inventory_account', $_POST['inventory_account']);
481 hidden('adjustment_account', $_POST['adjustment_account']);
485 if (is_manufactured(get_post('mb_flag')))
486 gl_all_accounts_list_row(_("WIP Account:"), 'wip_account', $_POST['wip_account']);
488 hidden('wip_account', $_POST['wip_account']);
490 table_section_title(_("Other"));
492 // Add image upload for New Item - by Joe
493 file_row(_("Image File (.jpg)") . ":", 'pic', 'pic');
494 // Add Image upload for New Item - by Joe
495 $stock_img_link = "";
496 $check_remove_image = false;
498 if (@$_POST['NewStockID'] && file_exists(company_path().'/images/'
499 .item_img_name($_POST['NewStockID']).".jpg"))
501 // 31/08/08 - rand() call is necessary here to avoid caching problems.
502 $stock_img_link .= "<img id='item_img' alt = '[".$_POST['NewStockID'].".jpg".
503 "]' src='".company_path().'/images/'.item_img_name($_POST['NewStockID']).
504 ".jpg?nocache=".rand()."'"." height='".$SysPrefs->pic_height."' border='0'>";
505 $check_remove_image = true;
509 $stock_img_link .= _("No image");
512 label_row(" ", $stock_img_link);
513 if ($check_remove_image)
514 check_row(_("Delete Image:"), 'del_image');
516 record_status_list_row(_("Item status:"), 'inactive');
517 if (get_post('fixed_asset')) {
518 table_section_title(_("Values"));
520 hidden('material_cost');
521 hidden('purchase_cost');
522 label_row(_("Initial Value").":", price_format($_POST['purchase_cost']), "", "align='right'");
523 label_row(_("Depreciations").":", price_format($_POST['purchase_cost'] - $_POST['material_cost']), "", "align='right'");
524 label_row(_("Current Value").':', price_format($_POST['material_cost']), "", "align='right'");
529 div_start('controls');
530 if (@$_REQUEST['popup']) hidden('popup', 1);
531 if (!isset($_POST['NewStockID']) || $new_item)
533 submit_center('addupdate', _("Insert New Item"), true, '', 'default');
537 submit_center_first('addupdate', _("Update Item"), '',
538 $page_nested ? true : 'default');
539 submit_return('select', get_post('stock_id'),
540 _("Select this items and return to document entry."));
541 submit('clone', _("Clone This Item"), true, '', true);
542 submit('delete', _("Delete This Item"), true, '', true);
543 submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
549 //--------------------------------------------------------------------------------------------
553 if (db_has_stock_items())
555 start_table(TABLESTYLE_NOBORDER);
557 stock_items_list_cells(_("Select an item:"), 'stock_id', null,
558 _('New item'), true, check_value('show_inactive'), false, array('fixed_asset' => get_post('fixed_asset')));
559 $new_item = get_post('stock_id')=='';
560 check_cells(_("Show inactive:"), 'show_inactive', null, true);
564 if (get_post('_show_inactive_update')) {
565 $Ajax->activate('stock_id');
566 set_focus('stock_id');
571 hidden('stock_id', get_post('stock_id'));
574 div_start('details');
576 $stock_id = get_post('stock_id');
578 unset($_POST['_tabs_sel']); // force settings tab for new customer
580 $tabs = (get_post('fixed_asset'))
582 'settings' => array(_('&General settings'), $stock_id),
583 'movement' => array(_('&Transactions'), $stock_id) )
585 'settings' => array(_('&General settings'), $stock_id),
586 'sales_pricing' => array(_('S&ales Pricing'), (user_check_access('SA_SALESPRICE') ? $stock_id : null)),
587 'purchase_pricing' => array(_('&Purchasing Pricing'), (user_check_access('SA_PURCHASEPRICING') ? $stock_id : null)),
588 'standard_cost' => array(_('Standard &Costs'), (user_check_access('SA_STANDARDCOST') ? $stock_id : null)),
589 'reorder_level' => array(_('&Reorder Levels'), (is_inventory_item($stock_id) &&
590 user_check_access('SA_REORDER') ? $stock_id : null)),
591 'movement' => array(_('&Transactions'), (user_check_access('SA_ITEMSTRANSVIEW') && is_inventory_item($stock_id) ?
593 'status' => array(_('&Status'), (user_check_access('SA_ITEMSSTATVIEW') ? $stock_id : null)),
596 tabbed_content_start('tabs', $tabs);
598 switch (get_post('_tabs_sel')) {
601 item_settings($stock_id, $new_item);
603 case 'sales_pricing':
604 $_GET['stock_id'] = $stock_id;
605 $_GET['page_level'] = 1;
606 include_once($path_to_root."/inventory/prices.php");
608 case 'purchase_pricing':
609 $_GET['stock_id'] = $stock_id;
610 $_GET['page_level'] = 1;
611 include_once($path_to_root."/inventory/purchasing_data.php");
613 case 'standard_cost':
614 $_GET['stock_id'] = $stock_id;
615 $_GET['page_level'] = 1;
616 include_once($path_to_root."/inventory/cost_update.php");
618 case 'reorder_level':
619 if (!is_inventory_item($stock_id))
621 $_GET['page_level'] = 1;
622 $_GET['stock_id'] = $stock_id;
623 include_once($path_to_root."/inventory/reorder_level.php");
626 if (!is_inventory_item($stock_id))
628 $_GET['stock_id'] = $stock_id;
629 include_once($path_to_root."/inventory/inquiry/stock_movements.php");
632 $_GET['stock_id'] = $stock_id;
633 include_once($path_to_root."/inventory/inquiry/stock_status.php");
638 tabbed_content_end();
642 hidden('fixed_asset', get_post('fixed_asset'));
644 if (get_post('fixed_asset'))
645 hidden('mb_flag', 'F');
649 //------------------------------------------------------------------------------------
651 end_page(@$_REQUEST['popup']);
653 function generateBarcode() {
656 while ($tmpBarcodeID == "") {
657 srand ((double) microtime( )*1000000);
658 $random_1 = rand(1,9);
659 $random_2 = rand(0,9);
660 $random_3 = rand(0,9);
661 $random_4 = rand(0,9);
662 $random_5 = rand(0,9);
663 $random_6 = rand(0,9);
664 $random_7 = rand(0,9);
665 //$random_8 = rand(0,9);
667 // http://stackoverflow.com/questions/1136642/ean-8-how-to-calculate-checksum-digit
668 $sum1 = $random_2 + $random_4 + $random_6;
669 $sum2 = 3 * ($random_1 + $random_3 + $random_5 + $random_7 );
670 $checksum_value = $sum1 + $sum2;
672 $checksum_digit = 10 - ($checksum_value % 10);
673 if ($checksum_digit == 10)
676 $random_8 = $checksum_digit;
678 $tmpBarcodeID = $random_1 . $random_2 . $random_3 . $random_4 . $random_5 . $random_6 . $random_7 . $random_8;
680 // LETS CHECK TO SEE IF THIS NUMBER HAS EVER BEEN USED
681 $query = "SELECT stock_id FROM ".TB_PREF."stock_master WHERE stock_id='" . $tmpBarcodeID . "'";
682 $arr_stock = db_fetch(db_query($query));
684 if ( !$arr_stock['stock_id'] ) {
685 return $tmpBarcodeID;