public function new_sales_report(array $sales_report_data) { $sales_report_id_from_branch = $sales_report_data['id']; $branch_id = $sales_report_data['branch_id']; $main_id = $sales_report_data['main_id']; $settings_repo = new Settings_Repository($this->db); $branches_repo = new Branches_Repository($this->db); if ($settings_repo->get_settings()->app_id != $main_id) { return -2; // invalid main } else { if (!$branches_repo->branch_exists($branch_id)) { return -1; // invalid branch } else { if (!$this->sales_report_exists_via_sales_report_id_from_branch($sales_report_id_from_branch, $branch_id)) { $this->db->insert('sales_reports', array('branch_id' => $branch_id, 'sales_report_id_from_branch' => $sales_report_id_from_branch, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'))); $sales_report_id = $this->db->insert_id(); $users_repo = new Users_Repository($this->db); foreach ($sales_report_data['sales'] as $sale) { $this->db->insert('receipts', array('receipt_id_from_branch' => $sale['receipt_id'], 'sales_report_id_from_branch' => $sales_report_id_from_branch, 'created_at_from_branch' => $sale['created_at'], 'updated_at_from_branch' => $sale['updated_at'], 'sales_report_id' => $sales_report_id, 'user_id' => $users_repo->get_user_via_username($sale['username'])->id, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'))); $receipt_id = $this->db->insert_id(); foreach ($sale['items'] as $item) { $this->db->insert('receipt_items', array('item_id' => $item['item_id'], 'receipt_id' => $receipt_id, 'price' => $item['price'], 'quantity' => $item['quantity'])); } } return $sales_report_id; } else { return 0; // sales report exists } } } }
public function get_all_users_post() { $users_repo = new Users_Repository($this->base_model->get_db_instance()); $users = $users_repo->get_all_users(); $data = array(); foreach ($users as $user) { array_push($data, array('id' => $user->id, 'username' => $user->username, 'user_level_id' => $user->user_level_id, 'user_level' => $user->user_level, 'last_name' => $user->last_name, 'first_name' => $user->first_name, 'middle_name' => $user->middle_name, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at)); } echo json_encode($data); }
public function login_post() { $username = $this->input->post('username'); $password = $this->input->post('password'); $user_repo = new Users_Repository($this->base_model->get_db_instance()); if ($user_repo->user_exists_via_username_and_password($username, $password)) { $user = $user_repo->get_user_via_username($username); $data = array(); array_push($data, array('id' => $user->id, 'username' => $user->username, 'password' => $user->password, 'user_level_id' => $user->user_level_id, 'user_level' => $user->user_level, 'last_name' => $user->last_name, 'first_name' => $user->first_name, 'middle_name' => $user->middle_name, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at)); $settings_repo = new Settings_Repository($this->base_model->get_db_instance()); $this->session->set_userdata('auth', array('user_id' => $user->id, 'name' => $user->first_name . ' ' . $user->last_name, 'app_id' => $settings_repo->get_settings()->app_id)); echo json_encode($data); } else { echo 0; } }
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 write_user_data_to_file_post() { $user_ids = $this->input->post('userIds'); // [1, 2, 3] $branch_id = $this->input->post('branchId'); $file_path = $this->input->post('filePath'); $users_repo = new Users_Repository($this->base_model->get_db_instance()); $enc = new Encryption(); $file_size = file_put_contents($file_path, $enc->encrypt($users_repo->to_json($user_ids, $branch_id))); echo $file_size; }