X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fincludes%2Fdb%2Fitems_db.inc;h=60bac30061679dae94b8c90eb2a5b28d263fe265;hb=8e299fb1bbc9113b4efdcb6973239041129c47cf;hp=9b382287749a65f93ee2748da615566eaed1d29d;hpb=8ea6c4dd0d9b31b3456d012b0c94339b801bee0c;p=fa-stable.git diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index 9b382287..60bac300 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -12,7 +12,7 @@ function update_item($stock_id, $description, $long_description, $category_id, $tax_type_id, $units='', $mb_flag='', $sales_account, $inventory_account, $cogs_account, $adjustment_account, $assembly_account, $dimension_id, - $dimension2_id, $no_sale) + $dimension2_id, $no_sale, $editable, $no_purchase) { $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).", description=".db_escape($description).", @@ -24,8 +24,10 @@ function update_item($stock_id, $description, $long_description, $category_id, assembly_account=".db_escape($assembly_account).", dimension_id=".db_escape($dimension_id).", dimension2_id=".db_escape($dimension2_id).", - tax_type_id=".db_escape($tax_type_id)." - no_sale=".db_escape($no_sale); + tax_type_id=".db_escape($tax_type_id).", + no_sale=".db_escape($no_sale).", + no_purchase=".db_escape($no_purchase).", + editable=".db_escape($editable); if ($units != '') $sql .= ", units='$units'"; @@ -43,11 +45,11 @@ function update_item($stock_id, $description, $long_description, $category_id, function add_item($stock_id, $description, $long_description, $category_id, $tax_type_id, $units, $mb_flag, $sales_account, $inventory_account, $cogs_account, $adjustment_account, $assembly_account, $dimension_id, - $dimension2_id, $no_sale) + $dimension2_id, $no_sale, $editable, $no_purchase) { $sql = "INSERT INTO ".TB_PREF."stock_master (stock_id, description, long_description, category_id, tax_type_id, units, mb_flag, sales_account, inventory_account, cogs_account, - adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale) + adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale, editable) VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).", ".db_escape($category_id).", ".db_escape($tax_type_id).", " .db_escape($units).", ".db_escape($mb_flag).", @@ -55,7 +57,9 @@ function add_item($stock_id, $description, $long_description, $category_id, .", ".db_escape($cogs_account).",".db_escape($adjustment_account) .", ".db_escape($assembly_account).", " .db_escape($dimension_id).", ".db_escape($dimension2_id)."," - .db_escape($no_sale).")"; + .db_escape($no_sale)."," + .db_escape($no_purchase)."," + .db_escape($editable).")"; db_query($sql, "The item could not be added"); @@ -109,4 +113,51 @@ function get_items() return db_query($sql,"items could not be retreived"); } +function item_in_foreign_codes($stock_id) +{ + $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 == '') { + + $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") + .':
'; + + while($num_kits--) { + $kit = db_fetch($kits); + $msg .= "'".$kit[0]."'"; + if ($num_kits) $msg .= ','; + } + + } + } + return $msg; +} ?> \ No newline at end of file