public function test_update_item()
 {
     $data = array('id' => 3, 'name' => "Iphone", 'description' => "This is test data from Unit test update", 'price' => 3);
     $_POST = $data;
     $expected = TRUE;
     $Item_model = new Item_model();
     $list = $Item_model->update_item();
     $actual = $list['status'];
     $this->assertEquals($expected, $actual);
 }
Beispiel #2
0
 public function lists()
 {
     header("Access-Control-Allow-Origin: *");
     header("Content-Type: application/json; charset=UTF-8");
     $Item_model = new Item_model();
     $result = $Item_model->get_all_items();
     if ($result === FALSE) {
         print json_encode(array('status' => 'failed'));
     } else {
         print json_encode($result);
     }
 }
Beispiel #3
0
 public function saveItem($data)
 {
     $item = new Item_model();
     $item->productCode = $data['productCode'];
     $item->description = $data['itemName'];
     $item->itemTypeId = $data['itemTypeId'];
     $item->categoryId = $data['categoryId'];
     $item->suggestedSellingPrice = $data['price'];
     $item->active = 1;
     $query = $this->db->get_where('Item', array('productCode' => $data['productCode']));
     if ($query->num_rows() > 0) {
         throw new DuplicateRecordException('The product code ' . $data['productCode'] . ' already exists.');
     }
     return $item->insert();
 }
Beispiel #4
0
 /**
  * Saves Items ordering
  *
  * @return	String		Success or error message
  *
  */
 function save_ordering()
 {
     $order = $this->input->post('order');
     if ($order !== FALSE) {
         // Saves the new ordering
         $this->item_model->save_ordering($order);
         // Answer
         $this->success(lang('ionize_message_operation_ok'));
     } else {
         $this->error(lang('ionize_message_operation_nok'));
     }
 }
Beispiel #5
0
 /**
  * Insert a item record into the database
  *
  * @access public
  * @return void
  */
 public function lists_post()
 {
     $Item_model = new Item_model();
     if ($this->_detect_method() == 'post') {
         if (isset($_POST['id'])) {
             $lists = $Item_model->update_item();
         } else {
             $lists = $Item_model->insert_item();
         }
         if ($lists['status'] === FALSE) {
             $this->response(['status' => FALSE, 'message' => 'Could not save the item'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
             // INTERNAL_SERVER_ERROR (500) being the HTTP response code
         } else {
             $this->response(['status' => TRUE, 'id' => $lists['id']], REST_Controller::HTTP_CREATED);
             // CREATED (201) being the HTTP response code
         }
     } else {
         $this->response(['status' => FALSE, 'message' => 'Nothing Post'], REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
         // INTERNAL_SERVER_ERROR (500) being the HTTP response code
     }
 }
Beispiel #6
0
 public function history($i_id, $s_id)
 {
     $this->load->helper('html');
     $this->load->library('table');
     $this->load->model(array('price_model', 'item_model'));
     $item = new Item_model();
     $item->load($i_id);
     $prices = $this->price_model->get_history($i_id, $s_id);
     if (!$prices) {
         redirect('items/view/' . $i_id);
         die;
     }
     $RM = "RM ";
     $price_list = array();
     foreach ($prices as $p_id => $price) {
         $price_list[] = array(date_format(new DateTime($price->datetime), 'd/m/Y, h:i A'), $RM . number_format((double) $price->price, 2, '.', ''), $price->username, anchor('items/delete/' . $price->id, 'Delete Price'));
     }
     $this->load->view('history', array('item' => $item, 'price' => $price, 'price_list' => $price_list));
 }