function cw_warehouse_reset_amount($division_id, $data)
{
    global $tables, $user_account, $current_area;
    $fields = array('avail', 'avail_ordered', 'avail_sold', 'avail_reserved');
    $search_data = array('manufacturers' => array($data['manufacturer_id'] => 1), 'category_id' => $data['category_id'], 'flat_search' => 1);
    if ($data['product_class']) {
        $search_data['features'] = array($data['product_class'] => array());
    }
    if ($data['supplier_customer_id']) {
        $search_data['suppliers'] = array($data['supplier_customer_id'] => 1);
    }
    list($products, $navigation) = cw_func_call('cw_product_search', array('data' => $search_data, 'user_account' => $user_account, 'current_area' => $current_area));
    if ($products) {
        foreach ($products as $product) {
            cw_warehouse_reset_all_amount($division_id, $product['product_id']);
        }
    }
}
        if (!$v['address_id']) {
            $v['address_id'] = cw_array2insert('customers_addresses', array('customer_id' => 0));
            db_query("update {$tables['warehouse_divisions']} set address_id='{$v['address_id']}' where division_id='{$k}'");
        }
        $v['address']['address_id'] = $v['address_id'];
        cw_array2insert('customers_addresses', $v['address'], true);
        //"address_id='$v[address_id]'");
    }
    cw_header_location("index.php?target={$target}");
}
if ($action == 'delete' && is_array($del)) {
    foreach ($del as $div_id => $val) {
        cw_call('cw_warehouse_delete_division', array($div_id));
    }
    cw_header_location("index.php?target={$target}");
}
if ($action == 'reset_amount' && $division_id) {
    cw_load('accounting', 'product');
    cw_warehouse_reset_amount($division_id, $reset[$division_id]);
    cw_header_location('index.php?target=' . $target);
}
if ($action == 'reset_all_amount' && $division_id) {
    cw_load('accounting');
    cw_warehouse_reset_all_amount($division_id);
    cw_header_location('index.php?target=' . $target);
}
list($profile_sections, $profile_fields, $additional_fields) = cw_profile_fields_get_sections('U', true, 'P');
$smarty->assign('profile_fields', $profile_fields);
$smarty->assign('divisions', cw_warehouse_get_divisions());
$location[] = array(cw_get_langvar_by_name('lbl_divisions'), 'index.php?target=' . $target);
$smarty->assign('main', 'divisions');