- $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_moves WHERE stock_id='$stock_id'";
- $result = db_query($sql, "could not query stock moves");
- $myrow = db_fetch_row($result);
- if ($myrow[0] > 0)
- {
- display_error(_('Cannot delete this item because there are stock movements that refer to this item.'));
- return false;
+ $sqls= array(
+ "SELECT COUNT(*) FROM "
+ .TB_PREF."stock_moves WHERE stock_id='$stock_id'" =>
+ _('Cannot delete this item because there are stock movements that refer to this item.'),
+ "SELECT COUNT(*) FROM "
+ .TB_PREF."bom WHERE component='$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='$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='$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;
+ }