/home/desid573/public_html/ims2/application/models
NameSizeModeActions
Admin.php117840644editdlrm
Analytic.php143550644editdlrm
Genmod.php97420644editdlrm
index.html1310644editdlrm
Item.php124840644editdlrm
Report.php9490644editdlrm
Transaction.php162620644editdlrm
Edit: /home/desid573/public_html/ims2/application/models/Item.php (12484B)
* @date 4th RabThaani, 1437AH (15th Jan, 2016) */ class Item extends CI_Model{ public function __construct(){ parent::__construct(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public function getAll($orderBy, $orderFormat, $start=0, $limit=''){ $this->db->limit($limit, $start); $this->db->order_by($orderBy, $orderFormat); $run_q = $this->db->get('items'); if($run_q->num_rows() > 0){ return $run_q->result(); } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ /** * * @param type $itemName * @param type $itemQuantity * @param type $itemPrice * @param type $itemDescription * @param type $itemCode * @return boolean */ public function add($itemName, $itemQuantity, $itemPrice, $itemDescription, $itemCode){ $data = ['name'=>$itemName, 'quantity'=>$itemQuantity, 'unitPrice'=>$itemPrice, 'description'=>$itemDescription, 'code'=>$itemCode]; //set the datetime based on the db driver in use $this->db->platform() == "sqlite3" ? $this->db->set('dateAdded', "datetime('now')", FALSE) : $this->db->set('dateAdded', "NOW()", FALSE); $this->db->insert('items', $data); if($this->db->insert_id()){ return $this->db->insert_id(); } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ /** * * @param type $value * @return boolean */ public function itemsearch($value){ $q = "SELECT * FROM items WHERE name LIKE '%".$this->db->escape_like_str($value)."%' || code LIKE '%".$this->db->escape_like_str($value)."%'"; $run_q = $this->db->query($q, [$value, $value]); if($run_q->num_rows() > 0){ return $run_q->result(); } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ /** * To add to the number of an item in stock * @param type $itemId * @param type $numberToadd * @return boolean */ public function incrementItem($itemId, $numberToadd){ $q = "UPDATE items SET quantity = quantity + ? WHERE id = ?"; $this->db->query($q, [$numberToadd, $itemId]); if($this->db->affected_rows() > 0){ return TRUE; } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ public function decrementItem($itemCode, $numberToRemove){ $q = "UPDATE items SET quantity = quantity - ? WHERE code = ?"; $this->db->query($q, [$numberToRemove, $itemCode]); if($this->db->affected_rows() > 0){ return TRUE; } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ public function newstock($itemId, $qty){ $q = "UPDATE items SET quantity = quantity + $qty WHERE id = ?"; $this->db->query($q, [$itemId]); if($this->db->affected_rows()){ return TRUE; } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ public function deficit($itemId, $qty){ $q = "UPDATE items SET quantity = quantity - $qty WHERE id = ?"; $this->db->query($q, [$itemId]); if($this->db->affected_rows()){ return TRUE; } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ /** * * @param type $itemId * @param type $itemName * @param type $itemDesc * @param type $itemPrice */ public function edit($itemId, $itemName, $itemDesc, $itemPrice){ $data = ['name'=>$itemName, 'unitPrice'=>$itemPrice, 'description'=>$itemDesc]; $this->db->where('id', $itemId); $this->db->update('items', $data); return TRUE; } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ public function getActiveItems($orderBy, $orderFormat){ $this->db->order_by($orderBy, $orderFormat); $this->db->where('quantity >=', 1); $run_q = $this->db->get('items'); if($run_q->num_rows() > 0){ return $run_q->result(); } else{ return FALSE; } } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ /** * array $where_clause * array $fields_to_fetch * * return array | FALSE */ public function getItemInfo($where_clause, $fields_to_fetch){ $this->db->select($fields_to_fetch); $this->db->where($where_clause); $run_q = $this->db->get('items'); return $run_q->num_rows() ? $run_q->row() : FALSE; } /* ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** ******************************************************************************************************************************** */ public function getItemsCumTotal(){ $this->db->select("SUM(unitPrice*quantity) as cumPrice"); $run_q = $this->db->get('items'); return $run_q->num_rows() ? $run_q->row()->cumPrice : FALSE; } }