diff --git a/Interface.cpp b/Interface.cpp index f0950b1..92b1e36 100644 --- a/Interface.cpp +++ b/Interface.cpp @@ -1,5 +1,6 @@ #include "headers/Interface.h" + // I added it to pass spots, because the parking options need it to check where // is free parking_spots is declared in main, and if i declare it @@ -11,10 +12,14 @@ void interface(vector& spots) { cout << "\n[2]Log in as administrator"; cin >> selector; switch (selector) { - case 1: + case 1: { interface_member(spots); - case 2: + break; + } + case 2: { interface_admin(spots); + break; + } } } @@ -33,15 +38,16 @@ void interface_member(vector& spots) { } cout << "Logged in succesfully\n"; - cout << "select an option\n [1] Parking options\n[2]other"; + cout << "select an option\n [1] Parking options\n[2]monthy report"; int option; cin >> option; switch (option) { case 1: { park(c, spots); + break; } case 2: { - // other thing you want to add + c.gen_monthly(); break; } @@ -50,7 +56,47 @@ void interface_member(vector& spots) { } } -void interface_admin(vector& spots) {} +void interface_admin(vector& spots) { + cout << "Welcome to the admin interface. It is not completely ready yet.\n"; + cout << "[1] See monthly report of ALL parking spots\n"; + cout << "[2] See weekly report of ALL parking spots\n"; + cout << "[3] See monthly report of a specific parking spot\n"; + cout << "[4] See weekly report of a specific parking spot\n"; + cout << "[5] See current status of parking spots\n"; + cout << "option[1-5]:"; + int option; + cin >> option; + switch (option) { + case 1: { + reports_from_allparkspots(); + break; + } + case 2: { + reports_from_allparkspots(true); + break; + } + case 3: { + cout << "Which parking spot would you like a report on?ID:"; + int spotid; + cin >> spotid; + reports_from_parkspot(spotid); + break; + } + case 4: { + cout << "Which parking spot would you like a report on?ID:"; + int spotid; + cin >> spotid; + reports_from_parkspot(spotid, true); + break; + } + case 5: { + current_status_parkspots(spots); + } + + default: + break; + } +} // --------- individual things. diff --git a/Park_time.cpp b/Park_time.cpp index e6556ec..0da71ea 100644 --- a/Park_time.cpp +++ b/Park_time.cpp @@ -61,6 +61,7 @@ std::ostream& operator<<(std::ostream& os, const Park_time& pt) { std::time_t start_ = system_clock::to_time_t(pt.start); std::time_t end_ = system_clock::to_time_t(pt.end); os << "- - - - - - - - - - - - - - - - - - - -\n"; + os << "Customer # " << pt.customer_id << "at parking spot " << pt.spot_id << "\n"; os << "Clocked in :" << std::ctime(&start_); os << "clocked out : " << std::ctime(&end_); os << "duration : " << pt.duration << "\n"; diff --git a/Query.cpp b/Query.cpp index 29fb841..6bdbd2a 100644 --- a/Query.cpp +++ b/Query.cpp @@ -1,6 +1,5 @@ #include "headers/Query.h" - vector query_parktimes_for_customer(int cid) { /* This is needed to initialize the park_instances for the customer constructor @@ -25,10 +24,8 @@ vector query_parktimes_for_customer(int cid) { return park_times; } - //--------------------------------------------- customers - vector query_customer_with_name(string name) { /* We use this instead of plain customers because: @@ -70,29 +67,102 @@ Customer query_customer_with_id(int id) { Customer result{ id, name, password, Vehicle_type(vehicle), park_instances}; // DEBUG - // cout << "{" << result.id << "," <& parkspots){ - for (Park_spot& i : parkspots){ - if (i.id == id){ +Park_spot query_parkspot_with_id(int id, vector& parkspots) { + for (Park_spot& i : parkspots) { + if (i.id == id) { return i; } } } +void reports_from_parkspot(int spotid, bool weekly) { + std::time_t t = std::time(0); // get time now + std::tm* now = std::localtime(&t); + int s_since_epoch = ((now->tm_year - 70) * 365.2425 * 24 * 3600) + + (now->tm_mon * 30.436875 * 24 * 3600); + + if (weekly){ + s_since_epoch += ((now->tm_mday/ 7) * 24 * 3600); + } + + vector park_times; + SQLite::Statement query( + data::db, "SELECT * FROM Park_time WHERE spot_id = ? AND start > ?;"); + query.bind(1, spotid); + query.bind(2, s_since_epoch); + while (query.executeStep()) { + int id = query.getColumn(0); + int cid = query.getColumn(1); + int start = query.getColumn(3); + int duration = query.getColumn(5); + Park_time result{id, cid, spotid, start, duration}; + park_times.push_back(result); + } + query.reset(); + + for (auto i : park_times) { + cout << i; + } +} + + +void reports_from_allparkspots(bool weekly) { + std::time_t t = std::time(0); // get time now + std::tm* now = std::localtime(&t); + int s_since_epoch = ((now->tm_year - 70) * 365.2425 * 24 * 3600) + + (now->tm_mon * 30.436875 * 24 * 3600); + if (weekly){ + s_since_epoch += ((now->tm_mday/ 7) * 24 * 3600); + } + + vector park_times; + SQLite::Statement query( + data::db, "SELECT * FROM Park_time WHERE start > ?;"); + query.bind(1, s_since_epoch); + while (query.executeStep()) { + int id = query.getColumn(0); + int cid = query.getColumn(1); + int spotid = query.getColumn(2); + int start = query.getColumn(3); + int duration = query.getColumn(5); + Park_time result{id, cid, spotid, start, duration}; + park_times.push_back(result); + } + query.reset(); + + for (auto i : park_times) { + cout << i; + } +} + + + + +void current_status_parkspots(vector& spots){ + for(auto& i : spots){ + cout << "---------------------------\n"; + cout << "PS #" << i.id << "\n"; + cout << "Taken: " << ((i.taken) ? "true" : "false") << "\n"; + if (i.taken){ + cout << "Customer#" << i.parked_customer << " parked there\n"; + } + } +} // -------------- paroking spots - - // vector populate_spots(){ // vector spots; -// SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;"); +// SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > +// 0;"); // // query.bind(1, 2); // while (query.executeStep()) { // int id = query.getColumn(0); diff --git a/headers/Query.h b/headers/Query.h index 0e93231..703ebf1 100644 --- a/headers/Query.h +++ b/headers/Query.h @@ -59,5 +59,8 @@ vector populate_spots(); Park_spot query_parkspot_with_id(int id, vector& parkspots); +void reports_from_parkspot(int spotid, bool weekly=false); +void reports_from_allparkspots(bool weekly=false); -#endif // CUSTOMER_H \ No newline at end of file +void current_status_parkspots(vector& spots); +#endif // CUSTOMER_H diff --git a/test.db3 b/test.db3 index fe44461..4f0d862 100644 Binary files a/test.db3 and b/test.db3 differ