X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fincludes%2Fdb%2Fitems_db.inc;h=78893071bb4a713e22de9b1efc18f194bcf4de2c;hb=5b8f4c4b4aa8cf996bc071f116bfce1273200fa2;hp=e336155254177289c0af78e8a2ac0448287beda6;hpb=a5242af68e65661edb7175412444dce536a7f311;p=fa-stable.git diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index e3361552..78893071 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -9,44 +9,63 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ -function update_item($stock_id, $description, $long_description, $category_id, $tax_type_id, - $sales_account, $inventory_account, $cogs_account, $adjustment_account, - $assembly_account, $dimension_id, $dimension2_id) +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, $editable, $no_purchase) { $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).", description=".db_escape($description).", - category_id='$category_id', - sales_account='$sales_account', - inventory_account='$inventory_account', - cogs_account='$cogs_account', - adjustment_account='$adjustment_account', - assembly_account='$assembly_account', - dimension_id=$dimension_id, - dimension2_id=$dimension2_id, - tax_type_id=$tax_type_id - WHERE stock_id='$stock_id'"; + category_id=".db_escape($category_id).", + sales_account=".db_escape($sales_account).", + inventory_account=".db_escape($inventory_account).", + cogs_account=".db_escape($cogs_account).", + adjustment_account=".db_escape($adjustment_account).", + 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).", + no_purchase=".db_escape($no_purchase).", + editable=".db_escape($editable); + + if ($units != '') + $sql .= ", units=".db_escape($units); + + if ($mb_flag != '') + $sql .= ", mb_flag=".db_escape($mb_flag); + + $sql .= " WHERE stock_id=".db_escape($stock_id); db_query($sql, "The item could not be updated"); update_item_code(-1, $stock_id, $stock_id, $description, $category_id, 1, 0); } -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) +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, $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) + adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale, editable) VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).", - '$category_id', $tax_type_id, '$units', '$mb_flag', - '$sales_account', '$inventory_account', '$cogs_account', - '$adjustment_account', '$assembly_account', $dimension_id, $dimension2_id)"; + ".db_escape($category_id).", ".db_escape($tax_type_id).", " + .db_escape($units).", ".db_escape($mb_flag).", + ".db_escape($sales_account).", ".db_escape($inventory_account) + .", ".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_purchase)."," + .db_escape($editable).")"; db_query($sql, "The item could not be added"); $sql = "INSERT INTO ".TB_PREF."loc_stock (loc_code, stock_id) - SELECT ".TB_PREF."locations.loc_code, '$stock_id' FROM ".TB_PREF."locations"; + SELECT ".TB_PREF."locations.loc_code, ".db_escape($stock_id) + ." FROM ".TB_PREF."locations"; db_query($sql, "The item locstock could not be added"); @@ -55,23 +74,23 @@ function add_item($stock_id, $description, $long_description, $category_id, $tax function delete_item($stock_id) { - $sql="DELETE FROM ".TB_PREF."stock_master WHERE stock_id='$stock_id'"; + $sql="DELETE FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id); db_query($sql, "could not delete stock item"); /*and cascade deletes in loc_stock */ - $sql ="DELETE FROM ".TB_PREF."loc_stock WHERE stock_id='$stock_id'"; + $sql ="DELETE FROM ".TB_PREF."loc_stock WHERE stock_id=".db_escape($stock_id); db_query($sql, "could not delete stock item loc stock"); /*and cascade deletes in purch_data */ - $sql ="DELETE FROM ".TB_PREF."purch_data WHERE stock_id='$stock_id'"; + $sql ="DELETE FROM ".TB_PREF."purch_data WHERE stock_id=".db_escape($stock_id); db_query($sql, "could not delete stock item purch data"); /*and cascade deletes in prices */ - $sql ="DELETE FROM ".TB_PREF."prices WHERE stock_id='$stock_id'"; + $sql ="DELETE FROM ".TB_PREF."prices WHERE stock_id=".db_escape($stock_id); db_query($sql, "could not delete stock item prices"); /*and cascade delete the bill of material if any */ - $sql = "DELETE FROM ".TB_PREF."bom WHERE parent='$stock_id'"; + $sql = "DELETE FROM ".TB_PREF."bom WHERE parent=".db_escape($stock_id); db_query($sql, "could not delete stock item bom"); delete_item_kit($stock_id); @@ -82,7 +101,7 @@ function get_item($stock_id) $sql = "SELECT ".TB_PREF."stock_master.*,".TB_PREF."item_tax_types.name AS tax_type_name FROM ".TB_PREF."stock_master,".TB_PREF."item_tax_types WHERE ".TB_PREF."item_tax_types.id=".TB_PREF."stock_master.tax_type_id - AND stock_id='$stock_id'"; + AND stock_id=".db_escape($stock_id); $result = db_query($sql,"an item could not be retreived"); return db_fetch($result); @@ -94,4 +113,50 @@ function get_items() return db_query($sql,"items could not be retreived"); } -?> \ No newline at end of file +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; +}