...
function clear_data()
{
unset($_POST['long_description']);
unset($_POST['description']);
unset($_POST['category_id']);
unset($_POST['tax_type_id']);
unset($_POST['units']);
unset($_POST['mb_flag']);
unset($_POST['NewStockID']);
unset($_POST['dimension_id']);
unset($_POST['dimension2_id']);
unset($_POST['no_sale']);
unset($_POST['no_purchase']);
unset($_POST['depreciation_method']);
unset($_POST['depreciation_rate']);
unset($_POST['depreciation_factor']);
unset($_POST['depreciation_start']);
unset($_POST['weight']);
unset($_POST['weight_uom']);
unset($_POST['volume']);
unset($_POST['volume_uom']);
}
//------------------------------------------------------------------------------------
if (isset($_POST['addupdate']))
{
$input_error = 0;
if ($upload_file == 'No')
$input_error = 1;
if (strlen($_POST['description']) == 0)
{
$input_error = 1;
display_error( _('The item name must be entered.'));
set_focus('description');
}
elseif (strlen($_POST['NewStockID']) == 0)
{
$input_error = 1;
display_error( _('The item code cannot be empty'));
set_focus('NewStockID');
}
elseif (strstr($_POST['NewStockID'], " ") || strstr($_POST['NewStockID'],"'") ||
strstr($_POST['NewStockID'], "+") || strstr($_POST['NewStockID'], "\"") ||
strstr($_POST['NewStockID'], "&") || strstr($_POST['NewStockID'], "\t"))
{
$input_error = 1;
display_error( _('The item code cannot contain any of the following characters - & + OR a space OR quotes'));
set_focus('NewStockID');
}
elseif ($new_item && db_num_rows(get_item_kit($_POST['NewStockID'])))
{
$input_error = 1;
display_error( _("This item code is already assigned to stock item or sale kit."));
set_focus('NewStockID');
}
if (get_post('fixed_asset')) {
if ($_POST['depreciation_rate'] > 100) {
$_POST['depreciation_rate'] = 100;
}
elseif ($_POST['depreciation_rate'] < 0) {
$_POST['depreciation_rate'] = 0;
}
$move_row = get_fixed_asset_move($_POST['NewStockID'], ST_SUPPRECEIVE);
if (isset($_POST['depreciation_start']) && strtotime($_POST['depreciation_start']) < strtotime($move_row['tran_date'])) {
display_warning(_('The depracation cannot start before the fixed asset purchase date'));
}
}
if ($input_error != 1)
{
if (check_value('del_image'))
{
$filename = company_path().'/images/'.item_img_name($_POST['NewStockID']).".jpg";
if (file_exists($filename))
unlink($filename);
}
if (!$new_item)
{ /*so its an existing one */
update_item($_POST['NewStockID'], $_POST['description'],
$_POST['long_description'], $_POST['category_id'],
$_POST['tax_type_id'], get_post('units'),
get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'],
$_POST['inventory_account'], $_POST['cogs_account'],
$_POST['adjustment_account'], $_POST['wip_account'],
$_POST['dimension_id'], $_POST['dimension2_id'],
check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start'),
get_post('fa_class_id'), input_num("weight"), get_post("weight_uom"), input_num("volume"), get_post("volume_uom"));
update_record_status($_POST['NewStockID'], $_POST['inactive'],
'stock_master', 'stock_id');
update_record_status($_POST['NewStockID'], $_POST['inactive'],
'item_codes', 'item_code');
set_focus('stock_id');
$Ajax->activate('stock_id'); // in case of status change
display_notification(_("Item has been updated."));
}
else
{ //it is a NEW part
add_item($_POST['NewStockID'], $_POST['description'],
$_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'],
$_POST['units'], get_post('fixed_asset') ? 'F' : get_post('mb_flag'), $_POST['sales_account'],
$_POST['inventory_account'], $_POST['cogs_account'],
$_POST['adjustment_account'], $_POST['wip_account'],
$_POST['dimension_id'], $_POST['dimension2_id'],
check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start'),
get_post('fa_class_id'), input_num("weight"), get_post("weight_uom"), input_num("volume"), get_post("volume_uom"));
display_notification(_("A new item has been added."));
$_POST['stock_id'] = $_POST['NewStockID'] =
$_POST['description'] = $_POST['long_description'] = '';
$_POST['no_sale'] = $_POST['editable'] = $_POST['no_purchase'] =0;
set_focus('NewStockID');
}
$Ajax->activate('_page_body');
}
}
if (get_post('clone')) {
unset($_POST['stock_id']);
$stock_id = '';
unset($_POST['inactive']);
set_focus('NewStockID');
$Ajax->activate('_page_body');
}
//------------------------------------------------------------------------------------
function check_usage($stock_id, $dispmsg=true)
{
$msg = item_in_foreign_codes($stock_id);
if ($msg != '') {
if($dispmsg) display_error($msg);
return false;
}
return true;
}
//------------------------------------------------------------------------------------
if (isset($_POST['delete']) && strlen($_POST['delete']) > 1)
{
if (check_usage($_POST['NewStockID'])) {
$stock_id = $_POST['NewStockID'];
delete_item($stock_id);
$filename = company_path().'/images/'.item_img_name($stock_id).".jpg";
if (file_exists($filename))
unlink($filename);
display_notification(_("Selected item has been deleted."));
$_POST['stock_id'] = '';
clear_data();
set_focus('stock_id');
$new_item = true;
$Ajax->activate('_page_body');
}
}
function item_settings(&$stock_id, $new_item)
{
global $SysPrefs, $path_to_root, $page_nested, $depreciation_methods;
start_outer_table(TABLESTYLE2);
table_section(1);
table_section_title(_("General Settings"));
//------------------------------------------------------------------------------------
if ($new_item)
{
$tmpCodeID=null;
$post_label = null;
if (!empty($SysPrefs->prefs['barcodes_on_stock']))
{
$post_label = '<button class="ajaxsubmit" type="submit" aspect=\'default\' name="generateBarcode" id="generateBarcode" value="Generate Barcode EAN8"> '._("Generate EAN-8 Barcode").' </button>';
if (isset($_POST['generateBarcode']))
{
$tmpCodeID=generateBarcode();
$_POST['NewStockID'] = $tmpCodeID;
}
}
text_row(_("Item Code:"), 'NewStockID', $tmpCodeID, 21, 20, null, "", $post_label);
$_POST['inactive'] = 0;
}
else
{ // Must be modifying an existing item
if (get_post('NewStockID') != get_post('stock_id') || get_post('addupdate')) { // first item display
$_POST['NewStockID'] = $_POST['stock_id'];
$myrow = get_item($_POST['NewStockID']);
$_POST['long_description'] = $myrow["long_description"];
$_POST['description'] = $myrow["description"];
$_POST['category_id'] = $myrow["category_id"];
$_POST['tax_type_id'] = $myrow["tax_type_id"];
$_POST['units'] = $myrow["units"];
$_POST['mb_flag'] = $myrow["mb_flag"];
$_POST['depreciation_method'] = $myrow['depreciation_method'];
$_POST['depreciation_rate'] = number_format2($myrow['depreciation_rate'], 1);
$_POST['depreciation_factor'] = number_format2($myrow['depreciation_factor'], 1);
$_POST['depreciation_start'] = sql2date($myrow['depreciation_start']);
$_POST['depreciation_date'] = sql2date($myrow['depreciation_date']);
$_POST['fa_class_id'] = $myrow['fa_class_id'];
$_POST['material_cost'] = $myrow['material_cost'];
$_POST['purchase_cost'] = $myrow['purchase_cost'];
$_POST['sales_account'] = $myrow['sales_account'];
$_POST['inventory_account'] = $myrow['inventory_account'];
$_POST['cogs_account'] = $myrow['cogs_account'];
$_POST['adjustment_account'] = $myrow['adjustment_account'];
$_POST['wip_account'] = $myrow['wip_account'];
$_POST['dimension_id'] = $myrow['dimension_id'];
$_POST['dimension2_id'] = $myrow['dimension2_id'];
$_POST['no_sale'] = $myrow['no_sale'];
$_POST['no_purchase'] = $myrow['no_purchase'];
$_POST['del_image'] = 0;
$_POST['inactive'] = $myrow["inactive"];
$_POST['editable'] = $myrow["editable"];
$_POST['weight'] = $myrow["weight"];
$_POST['weight_uom'] = $myrow["weight_uom"];
$_POST['volume'] = $myrow["volume"];
$_POST['volume_uom'] = $myrow["volume_uom"];
}
label_row(_("Item Code:"),$_POST['NewStockID']);
hidden('NewStockID', $_POST['NewStockID']);
set_focus('description');
}
$fixed_asset = get_post('fixed_asset');
text_row(_("Name:"), 'description', null, 52, 200);
textarea_row(_('Description:'), 'long_description', null, 42, 3);
stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item, $fixed_asset);
if ($new_item && (list_updated('category_id') || !isset($_POST['units']))) {
$category_record = get_item_category($_POST['category_id']);
$_POST['tax_type_id'] = $category_record["dflt_tax_type"];
$_POST['units'] = $category_record["dflt_units"];
$_POST['mb_flag'] = $category_record["dflt_mb_flag"];
$_POST['inventory_account'] = $category_record["dflt_inventory_act"];
$_POST['cogs_account'] = $category_record["dflt_cogs_act"];
$_POST['sales_account'] = $category_record["dflt_sales_act"];
$_POST['adjustment_account'] = $category_record["dflt_adjustment_act"];
$_POST['wip_account'] = $category_record["dflt_wip_act"];
$_POST['dimension_id'] = $category_record["dflt_dim1"];
$_POST['dimension2_id'] = $category_record["dflt_dim2"];
$_POST['no_sale'] = $category_record["dflt_no_sale"];
$_POST['no_purchase'] = $category_record["dflt_no_purchase"];
$_POST['editable'] = 0;
}
$fresh_item = !isset($_POST['NewStockID']) || $new_item
|| check_usage($_POST['stock_id'],false);
// show inactive item tax type in selector only if already set.
item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null, !$new_item && item_type_inactive(get_post('tax_type_id')));
if (!get_post('fixed_asset'))
stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item);
stock_units_list_row(_('Units of Measure:'), 'units', null, TRUE);
check_row(_("Editable description:"), 'editable');
if (get_post('fixed_asset'))
hidden('no_sale', 0);
else
check_row(_("Exclude from sales:"), 'no_sale');
check_row(_("Exclude from purchases:"), 'no_purchase');
$result = get_all_item_units();
while ($unit = db_fetch($result))
$units[$unit['abbr']] = $unit['name'];
amount_row(_("Weight:"), "weight", null, null, array_selector("weight_uom", null, $units, array('disabled' => false)));
amount_row(_("Volume:"), "volume", null, null, array_selector("volume_uom", null, $units, array('disabled' => false)));
...