Example #1
0
 public function get_item_post()
 {
     $items_repo = new Items_Repository($this->base_model->get_db_instance());
     $item = $items_repo->get_item($this->input->post('itemId'));
     $data = array();
     array_push($data, array('id' => $item->id, 'description' => $item->description, 'quantity' => $item->quantity, 'price' => $item->price, 'created_at' => $item->created_at, 'updated_at' => $item->updated_at));
     echo json_encode($data);
 }
Example #2
0
 public function new_delivery($branch_id, array $items)
 {
     $this->db->insert('deliveries', array('branch_id' => $branch_id, 'status' => Delivery_Status::Failed, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')));
     $delivery_id = $this->db->insert_id();
     $items_repo = new Items_Repository($this->db);
     foreach ($items as $item) {
         $this->db->insert('delivered_items', array('delivery_id' => $delivery_id, 'item_id' => $item['itemId'], 'quantity' => $item['quantity'], 'price' => $items_repo->get_item($item['itemId'])->price));
     }
     return $delivery_id;
 }
 public function get_all_uncleared_items_from_this_branch_post()
 {
     $branch_id = $this->input->post('branchId');
     $uncleared_items_repo = new Uncleared_Items_Repository($this->base_model->get_db_instance());
     $uncleared_items = $uncleared_items_repo->get_all_items_via_branch_id($branch_id);
     $data = array();
     foreach ($uncleared_items as $uncleared_item) {
         $items_repo = new Items_Repository($this->base_model->get_db_instance());
         $item = $items_repo->get_item($uncleared_item->item_id);
         array_push($data, array('id' => $uncleared_item->id, 'item_id' => $uncleared_item->item_id, 'description' => $item->description, 'branch_id' => $uncleared_item->branch_id, 'quantity' => $uncleared_item->quantity, 'created_at' => $uncleared_item->created_at, 'updated_at' => $uncleared_item->updated_at));
     }
     echo json_encode($data);
 }
 public function save_transaction_post()
 {
     /** 
      * 	[$items description]
      * 	@var   [json]
      *	@example
      *	[
      *		{"itemId": 1, "price": 100, "quantity": 2},
      *		{"itemId": 2, "price": 100, "quantity": 4}
      *	]
      */
     $items = $this->input->post('items');
     $session_data = $this->session->userdata('branch_auth');
     $user_id = $session_data['user_id'];
     $items_repo = new Items_Repository($this->base_model->get_db_instance());
     foreach ($items as $item) {
         $item_info = $items_repo->get_item($item['itemId']);
         $items_repo->update_item(new Item($item_info->id, $item_info->description, $item_info->quantity - $item['quantity'], $item_info->price, null, null));
     }
     $receipts_repo = new Receipts_Repository($this->base_model->get_db_instance());
     $receipts_repo->new_receipt($user_id, $items);
     echo json_encode($items);
 }
Example #5
0
 public function get_all_items_from_this_receipt_post()
 {
     $receipts_repo = new Receipts_Repository($this->base_model->get_db_instance());
     $receipt_items = $receipts_repo->get_all_items_from_receipt($this->input->post('receiptId'));
     $data = array();
     foreach ($receipt_items as $receipt_item) {
         $items_repo = new Items_Repository($this->base_model->get_db_instance());
         $item = $items_repo->get_item($receipt_item->item_id);
         array_push($data, array('id' => $receipt_item->id, 'item_id' => $receipt_item->item_id, 'description' => $item->description, 'receipt_id' => $receipt_item->receipt_id, 'price' => $receipt_item->price, 'quantity' => $receipt_item->quantity));
     }
     echo json_encode($data);
 }
 public function get_items_with_insufficient_quantity_post()
 {
     $num_of_branches = $this->input->post('numOfBranches');
     $items = $this->input->post('items');
     // [ {itemId: 401, quantity: 20}, {itemId: 402, quantity: 10} ]
     $data = array();
     $items_repo = new Items_Repository($this->base_model->get_db_instance());
     foreach ($items as $item) {
         $item_info = $items_repo->get_item($item['itemId']);
         if ($item_info->quantity < $item['quantity'] * $num_of_branches) {
             array_push($data, array('id' => $item['itemId'], 'requested_quantity' => $item['quantity'] * $num_of_branches, 'available_quantity' => $item_info->quantity));
         }
     }
     echo json_encode($data);
 }
 public function get_all_items_from_this_delivery_post()
 {
     $deliveries_repo = new Deliveries_Repository($this->base_model->get_db_instance());
     $delivered_items = $deliveries_repo->get_all_items_from_delivery($this->input->post('deliveryId'));
     $data = array();
     foreach ($delivered_items as $delivered_item) {
         $items_repo = new Items_Repository($this->base_model->get_db_instance());
         $item = $items_repo->get_item($delivered_item->item_id);
         array_push($data, array('id' => $delivered_item->id, 'delivery_id' => $delivered_item->delivery_id, 'item_id' => $delivered_item->item_id, 'description' => $item->description, 'quantity' => $delivered_item->quantity));
     }
     echo json_encode($data);
 }