X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fincludes%2Fdb%2Fitems_db.inc;h=07fde0d172768d1872dc80aead3876a361edcb7c;hb=2bcdab793e406bb5a44d2c4e079ec7cc2a1aa857;hp=b9b87b13fa21304d0b5eeda7bf17a57fb601d874;hpb=7622ac6f58b8173c16e238be48d3bb43296b438a;p=fa-stable.git diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index b9b87b13..07fde0d1 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -11,7 +11,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, + $cogs_account, $adjustment_account, $wip_account, $dimension_id, $dimension2_id, $no_sale, $editable, $no_purchase, $depreciation_method = 'D', $depreciation_rate=100, $depreciation_factor=1, $depreciation_start=null, $fa_class_id=null) @@ -23,7 +23,7 @@ function update_item($stock_id, $description, $long_description, $category_id, inventory_account=".db_escape($inventory_account).", cogs_account=".db_escape($cogs_account).", adjustment_account=".db_escape($adjustment_account).", - assembly_account=".db_escape($assembly_account).", + wip_account=".db_escape($wip_account).", dimension_id=".db_escape($dimension_id).", dimension2_id=".db_escape($dimension2_id).", tax_type_id=".db_escape($tax_type_id).", @@ -41,7 +41,7 @@ function update_item($stock_id, $description, $long_description, $category_id, if ($mb_flag != '') $sql .= ", mb_flag=".db_escape($mb_flag); - if ($depreciation_start != '') { + if (isset($depreciation_start)) { $sql .= ", depreciation_start='".date2sql($depreciation_start)."'" .", depreciation_date='".date2sql($depreciation_start)."'"; } @@ -55,28 +55,29 @@ 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, + $cogs_account, $adjustment_account, $wip_account, $dimension_id, $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, 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).", + adjustment_account, wip_account, dimension_id, dimension2_id, no_sale, no_purchase, editable, + depreciation_method, depreciation_rate, depreciation_factor" + .(isset($depreciation_start) ? ", 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).", ".db_escape($sales_account).", ".db_escape($inventory_account) .", ".db_escape($cogs_account).",".db_escape($adjustment_account) - .", ".db_escape($assembly_account).", " + .", ".db_escape($wip_account).", " .db_escape($dimension_id).", ".db_escape($dimension2_id)."," .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_escape($depreciation_method).",".db_escape($depreciation_rate).",".db_escape($depreciation_factor) + .(isset($depreciation_start) ? ",'".date2sql($depreciation_start)."','".date2sql($depreciation_start)."',".db_escape($fa_class_id) : "") + .")"; db_query($sql, "The item could not be added"); @@ -122,7 +123,7 @@ function get_item($stock_id) AND stock_id=".db_escape($stock_id); $result = db_query($sql,"an item could not be retreived"); - return db_fetch($result); + return db_fetch_assoc($result); } function get_items($fixed_asset = 0) @@ -142,7 +143,7 @@ function item_in_foreign_codes($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.'), + _('Cannot delete this item because there are existing sales 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.') @@ -158,7 +159,7 @@ function item_in_foreign_codes($stock_id) $msg = $err; break; } } - if ($msg == '') { + if ($msg == '') { $kits = get_where_used($stock_id); $num_kits = db_num_rows($kits); @@ -178,3 +179,52 @@ function item_in_foreign_codes($stock_id) } return $msg; } + +function get_items_search($description, $type) +{ + global $SysPrefs; + + $sql = "SELECT COUNT(i.item_code) AS kit, i.item_code, i.description, c.description category + FROM ".TB_PREF."stock_master s, ".TB_PREF."item_codes i + LEFT JOIN ".TB_PREF."stock_category c ON i.category_id=c.category_id + WHERE i.stock_id=s.stock_id + AND !i.inactive AND !s.inactive + AND ( i.item_code LIKE " . db_escape("%" . $description. "%") . " OR + i.description LIKE " . db_escape("%" . get_post("description"). "%") . " OR + c.description LIKE " . db_escape("%" . get_post("description"). "%") . ") "; + + switch ($type) { + case "sales": + $sql .= " AND !s.no_sale AND mb_flag <> 'F'"; + break; + case "manufactured": + $sql .= " AND mb_flag = 'M'"; + break; + case "purchasable": + $sql .= " AND NOT no_purchase AND mb_flag <> 'F' AND i.item_code=i.stock_id"; + break; + case "costable": + $sql .= " AND mb_flag <> 'D' AND mb_flag <> 'F' AND i.item_code=i.stock_id"; + break; + case "component": + $parent = $_GET['parent']; + $sql .= " AND i.item_code=i.stock_id AND i.stock_id <> '$parent' AND mb_flag <> 'F' "; + break; + case "kits": + $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag <> 'F'"; + break; + case "all": + $sql .= " AND mb_flag <> 'F' AND i.item_code=i.stock_id"; + break; + } + + if (isset($SysPrefs->max_rows_in_search)) + $limit = $SysPrefs->max_rows_in_search; + else + $limit = 10; + + $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0,".(int)($limit); + + return db_query($sql, "Failed in retreiving item list."); +} +