#include "headers/Customer.h" // constructors Customer::Customer(string name_, string password_, Vehicle_type vehicle_) : name{name_}, vehicle{vehicle_}, password{hash_password(password_)} { id = auto_increment_db() + 1; save_db(); } Customer::Customer(int id_, string name_, string password_, Vehicle_type vehicle_, vector instances) : id{id_}, name{name_}, password{password_}, vehicle{vehicle_}, park_instances{instances} {} // clock in/out methods // ==================================================================================== /* Create a p_time object with start=now and adds to vector */ void Customer::clock_in(int s_id) { Park_time pt{id, s_id}; park_instances.push_back(pt); } // edit last p_time object so end=now void Customer::clock_out(int s_id) { park_instances[park_instances.size() - 1].clock_out(id, s_id); } bool Customer::parked() { if (!park_instances.size()){ return false; } if ((park_instances[park_instances.size() - 1].duration)) { // if duration of the last parktime == 0, meaning // that the customer has not clocked out return false; } else { return true; } } int Customer::parked_at(){ return park_instances[park_instances.size() - 1].spot_id; } // report gen void Customer::gen_monthly() { cout << "NAME: " << name << "\n"; cout << "-------------------------------------------------\n"; for (auto& i : park_instances) { // TODO: need some logic to only include from this month. scratch that, // need to remove gen monthly cout << i; } cout << "-------------------------------------------------\n\n"; } //================================================================================================ // functions that interact with the database void Customer::save_db() { string statement{"insert into Customer values (, '', '', );"}; // after ( = 28) statement.insert(38, to_string(int(vehicle))); statement.insert(36, password); statement.insert(32, name); statement.insert(29, to_string(id)); SQLite::Transaction transaction(data::db); data::db.exec(statement); transaction.commit(); } void Customer::update_db() { string statement = "UPDATE Customer SET name = '', card_code = '' where id = '';"; statement.insert(58, to_string(id)); statement.insert(44, password); statement.insert(28, name); data::db.exec(statement); } void Customer::delete_db() { string statement = "delete from Customer where id= ;"; statement.insert(statement.length() - 2, to_string(id)); SQLite::Transaction transaction(data::db); data::db.exec(statement); transaction.commit(); } int Customer::auto_increment_db() { SQLite::Statement max_id(data::db, "select max(id) from Customer;"); int id = 0; max_id.executeStep(); id = max_id.getColumn(0); max_id.reset(); return id; }