-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshopkeeper_portal.cpp
187 lines (162 loc) · 5.18 KB
/
shopkeeper_portal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifndef shopkeeper_portal_cpp
#define shopkeeper_portal_cpp
#include<bits/stdc++.h>
using namespace std;
#include "database.cpp"
#include "shopkeeper.cpp"
#include "shop.cpp"
ulli number_of_items=0;
int home_page_shpkpr(Shopkeeper);
void display_transaction_details(char* name){
string name1(name);
Shop_trans trans;
string path="database/transaction_data/"+name1+".ooad";
ifstream file(path.c_str());
cout<<"email\t\tname\t\tquantity"<<endl;
while(file.read((char*)&trans,sizeof(Shop_trans))){
cout<<trans.email<<"\t"<<trans.name<<"\t"<<trans.quantity<<endl;
}
}
int process(ulli option, Shopkeeper shopkeeper)
{
switch (option)
{
case 1:
{
cout << "> Name : " << shopkeeper.name << endl;
cout<<"> shop name : "<<shopkeeper.shop_name<<endl;
cout << "> Email : " << shopkeeper.email << endl;
cout << "> contact number : " << shopkeeper.contact_number << endl;
cout << "> Account Number : " << shopkeeper.account_name << endl;
cout << "> IFSC code : " << shopkeeper.IFSC_code << endl;
cout << "> Pending amount : " << shopkeeper.pending_amount << endl;
cout <<"> Account Number : " << shopkeeper.account_name << endl;
cout <<"> Press 'a' to return to home page or press 'e' to exit :: ";
char option1;
cin >> option1;
switch (option1){
case 'a':
{
system("clear");
return home_page_shpkpr(shopkeeper);
}
case 'e':
{
return -1;
}
default:
cout<<"> pressed key not recognised";
return -1;
}
break;
}
case 2:
{
if(number_of_items==0)
cout<<"> No items to display\n";
else
display_shop_details(shopkeeper.shop_category);
return home_page_shpkpr(shopkeeper);
}
case 3:
{
Shop shop;
cout<<"> Shop_Category -> "<<shopkeeper.shop_category<<" shop"<<endl;
shop.add_items(shopkeeper.shop_category,number_of_items+1);
cout<<"> item added sucessfully\n";
number_of_items++;
string temp_id(Utilities::ulli_to_string(shopkeeper.shop_id));
string path="database/shop_data/"+temp_id+".num";
ofstream file(path.c_str());
file<<number_of_items;
file.close();
return home_page_shpkpr(shopkeeper);
break;
}
case 4:
{
display_shop_details(shopkeeper.shop_category);
cout << "> Enter the ID of the item whose record is to be updated : ";
ulli num;
cin >> num;
Item item = get_item(shopkeeper.shop_category, num);
string name(shopkeeper.shop_category);
update_item_record(item, name);
return home_page_shpkpr(shopkeeper);
}
case 5:
{
display_transaction_details(shopkeeper.shop_category);
return home_page_shpkpr(shopkeeper);
}
case 6:
{
return -1;
}
default:
{
return -1;
}
}
return -1;
}
int home_page_shpkpr(Shopkeeper shopkeeper)
{
string id=Utilities::ulli_to_string(shopkeeper.shop_id);
string path="database/shop_data/"+id+".num";
fstream file(path.c_str());
file>>number_of_items;
file.close();
cout << "> Select any of the following options (Type the corresponding index to select a option):\n";
cout << "> 1) profile\n";
cout << "> 2) view items in the shop\n";
cout << "> 3) add items to shop\n";
cout << "> 4) update item record\n";
cout << "> 5) transaction history\n";
cout << "> 6) Logout\n";
cout << "\n> ";
ulli option; //contains the input option given by the user
cin >> option;
system("clear");
return process(option,shopkeeper);
}
int shopkeeper_portal(string email)
{
Shopkeeper shopkeeper(get_number_of_shops());
shopkeeper=get_shopkeeper(email);
cout<<"> Enter your password :: ";
string password=Terminal::input_password();
if(password.length()==0)
return -1;
if(!shopkeeper.login(password))
{
cout<<"> invalid email password combination\n";
cout<<"> Do you want to login with OTP? (y/n)";
char ch;
cin>>ch;
if(ch!='y')
return -1;
if(ch=='y')
{
cout<<"> Sending OTP on your mail and mobile\n";
string temp_name(shopkeeper.name);
string temp_number(shopkeeper.contact_number);
string otp=Network::OTP_password(temp_name,temp_number,email);
if(otp.length()==0)
return -1;
string entered_otp;
cout<<"> Enter the OTP :: ";
char waste;
scanf("%c",&waste);
getline(cin,entered_otp);
if(strcmp(entered_otp.c_str(),otp.c_str())!=0)
{
cout<<"> Invalid OTP";
return -1;
}
}
}
cout << "\n> Welcome " << shopkeeper.name << " !\n";
return home_page_shpkpr(shopkeeper);
}
#endif