X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fincludes%2Fdb%2Fitems_db.inc;h=b9b87b13fa21304d0b5eeda7bf17a57fb601d874;hb=07737913eea4abbc7a8604a286852facb2134540;hp=b0553726158e0319b1be4ba2dc1f6e1072a13ecb;hpb=ebc600101ceab69c06eac4b1bd4d1782af45de05;p=fa-stable.git diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index b0553726..b9b87b13 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -12,7 +12,9 @@ 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, + $depreciation_method = 'D', $depreciation_rate=100, $depreciation_factor=1, + $depreciation_start=null, $fa_class_id=null) { $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).", description=".db_escape($description).", @@ -25,13 +27,24 @@ function update_item($stock_id, $description, $long_description, $category_id, 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_sale=".db_escape($no_sale).", + no_purchase=".db_escape($no_purchase).", + editable=".db_escape($editable).", + depreciation_method=".db_escape($depreciation_method).", + depreciation_rate=".db_escape($depreciation_rate).", + depreciation_factor=".db_escape($depreciation_factor).", + fa_class_id=".db_escape($fa_class_id); if ($units != '') - $sql .= ", units='$units'"; + $sql .= ", units=".db_escape($units); if ($mb_flag != '') - $sql .= ", mb_flag='$mb_flag'"; + $sql .= ", mb_flag=".db_escape($mb_flag); + + if ($depreciation_start != '') { + $sql .= ", depreciation_start='".date2sql($depreciation_start)."'" + .", depreciation_date='".date2sql($depreciation_start)."'"; + } $sql .= " WHERE stock_id=".db_escape($stock_id); @@ -43,11 +56,14 @@ 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, + $depreciation_method='D', $depreciation_rate=100, $depreciation_factor=1, $depreciation_start=null, + $fa_class_id=null) { $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, no_purchase, editable, + depreciation_method, depreciation_rate, depreciation_factor, depreciation_start, depreciation_date, fa_class_id) 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,12 +71,17 @@ 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_escape($depreciation_method).",".db_escape($depreciation_rate).",".db_escape($depreciation_factor).",'" + .date2sql($depreciation_start)."','".date2sql($depreciation_start)."'," + .db_escape($fa_class_id).")"; 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, ".db_escape($stock_id) + SELECT loc_code, ".db_escape($stock_id) ." FROM ".TB_PREF."locations"; db_query($sql, "The item locstock could not be added"); @@ -94,19 +115,66 @@ function delete_item($stock_id) 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 + $sql = "SELECT item.*, taxtype.name AS tax_type_name + FROM ".TB_PREF."stock_master item," + .TB_PREF."item_tax_types taxtype + WHERE taxtype.id=item.tax_type_id AND stock_id=".db_escape($stock_id); $result = db_query($sql,"an item could not be retreived"); return db_fetch($result); } -function get_items() +function get_items($fixed_asset = 0) { - $sql = "SELECT * FROM ".TB_PREF."stock_master"; + $sql = "SELECT * FROM ".TB_PREF."stock_master WHERE fixed_asset=".db_escape($fixed_asset); 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; +}