Optimized database indexes.
[fa-stable.git] / inventory / manage / items.php
index 59fc76713f3435ed915d3582c7ec91213570a86f..5e72e40592ee777d1e5add913c9b6b5089ea3895 100644 (file)
@@ -210,50 +210,8 @@ if (get_post('clone')) {
 
 function check_usage($stock_id, $dispmsg=true)
 {
-       $sqls=  array(
-       "SELECT COUNT(*) FROM "
-               .TB_PREF."stock_moves WHERE stock_id=".db_escape($stock_id) =>
-        _('Cannot delete this item because there are stock movements that refer to this item.'),
-       "SELECT COUNT(*) FROM "
-               .TB_PREF."bom WHERE component=".db_escape($stock_id)=>
-        _('Cannot delete this item record because there are bills of material that require this part as a component.'),
-       "SELECT COUNT(*) FROM "
-               .TB_PREF."sales_order_details WHERE stk_code=".db_escape($stock_id) =>
-        _('Cannot delete this item because there are existing purchase order items for it.'),
-       "SELECT COUNT(*) FROM "
-               .TB_PREF."purch_order_details WHERE item_code=".db_escape($stock_id)=>
-        _('Cannot delete this item because there are existing purchase order items for it.')
-       );
-
-       $msg = '';
-
-       foreach($sqls as $sql=>$err) {
-               $result = db_query($sql, "could not query stock usage");
-               $myrow = db_fetch_row($result);
-               if ($myrow[0] > 0) 
-               {
-                       $msg = $err; break;
-               }
-       }
-
-       if ($msg == '') {       
+       $msg = item_in_foreign_codes($stock_id);
 
-               $kits = get_where_used($stock_id);
-               $num_kits = db_num_rows($kits);
-               if ($num_kits) {
-                       $msg = _("This item cannot be deleted because some code aliases 
-                               or foreign codes was entered for it, or there are kits defined 
-                               using this item as component")
-                               .':<br>';
-
-                       while($num_kits--) {
-                               $kit = db_fetch($kits);
-                               $msg .= "'".$kit[0]."'";
-                               if ($num_kits) $msg .= ',';
-                       }
-
-               }
-       }
        if ($msg != '') {
                if($dispmsg) display_error($msg);
                return false;
@@ -348,7 +306,7 @@ text_row(_("Name:"), 'description', null, 52, 50);
 
 textarea_row(_('Description:'), 'long_description', null, 42, 3);
 
-stock_categories_list_row(_("Category:"), 'category_id', null, $new_item);
+stock_categories_list_row(_("Category:"), 'category_id', null, false, $new_item);
 
 if ($new_item && (list_updated('category_id') || !isset($_POST['units']))) {