private function get_all_sales_report()
 {
     $sales_reports_repo = new Sales_Reports_Repository($this->base_model->get_db_instance());
     $receipts_repo = new Receipts_Repository($this->base_model->get_db_instance());
     $data = array();
     foreach ($sales_reports_repo->get_all_sales_reports() as $sales_report) {
         $total_amount = 0;
         foreach ($receipts_repo->get_all_receipts_via_sales_report_id($sales_report->id) as $receipt) {
             foreach ($receipts_repo->get_all_items_from_receipt($receipt->id) as $receipt_item) {
                 $total_amount += $receipt_item->price;
             }
         }
         array_push($data, array('id' => $sales_report->id, 'total_amount' => $total_amount, 'created_at' => $sales_report->created_at, 'updated_at' => $sales_report->updated_at));
     }
     echo json_encode($data);
 }
 public function to_export_sales_report_json($sales_report_id)
 {
     $receipts_repo = new Receipts_Repository($this->db);
     $settings_repo = new Settings_Repository($this->db);
     $users_repo = new Users_Repository($this->db);
     $receipts = $receipts_repo->get_all_receipts_via_sales_report_id($sales_report_id);
     $sales = array();
     foreach ($receipts as $receipt) {
         $items = array();
         $receipt_items = $receipts_repo->get_all_items_from_receipt($receipt->id);
         foreach ($receipt_items as $receipt_item) {
             array_push($items, array('item_id' => $receipt_item->item_id, 'price' => $receipt_item->price, 'quantity' => $receipt_item->quantity));
         }
         array_push($sales, array('receipt_id' => $receipt->id, 'username' => $users_repo->get_user_via_id($receipt->user_id)->username, 'created_at' => $receipt->created_at, 'updated_at' => $receipt->updated_at, 'items' => $items));
     }
     $data = array('transaction' => Transaction_Type::Export_Sales_Report, 'id' => $sales_report_id, 'main_id' => $settings_repo->get_settings()->main_id, 'branch_id' => $settings_repo->get_settings()->app_id, 'sales' => $sales);
     return 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);
 }
Beispiel #4
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);
 }