Retrieves a single item row by item_number or numeric item_id, handling barcode ambiguity and optional deleted filter.
// Source: https://github.com/Pmbamungu/ospos | License: MIT | Copyright 2013-2021 jekkos
// Provided via justclaw.it.com; keep this notice with the code.
public function get_info_by_id_or_number($item_id, $include_deleted = TRUE)
{
$this->db->group_start();
$this->db->where('items.item_number', $item_id);
// check if $item_id is a number and not a string starting with 0
// because cases like 00012345 will be seen as a number where it is a barcode
if(ctype_digit($item_id) && substr($item_id, 0, 1) != '0')
{
$this->db->or_where('items.item_id', intval($item_id));
}
$this->db->group_end();
if(!$include_deleted)
{
$this->db->where('items.deleted', 0);
}
// limit to only 1 so there is a result in case two are returned
// due to barcode and item_id clash
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key