-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcustomer_portal.cpp
290 lines (259 loc) · 9.02 KB
/
customer_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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include<bits/stdc++.h>
using namespace std;
#ifndef customer_portal_cpp
#define customer_portal_cpp
#include "customer.cpp"
#include "database.cpp"
#include "transaction.cpp"
int home_page_customer(Customer customer,Transaction &t);
Deliveryboy deliveryboys[5];
void premain()
{
deliveryboys[0].name="Ram";
deliveryboys[0].contact_number=9867856435;
deliveryboys[1].name="Mohan";
deliveryboys[1].contact_number=9672136435;
deliveryboys[2].name="Prabhu";
deliveryboys[2].contact_number=6867858985;
deliveryboys[3].name="Kashiram";
deliveryboys[3].contact_number=8867856421;
deliveryboys[4].name="Tagore";
deliveryboys[4].contact_number=6866656435;
}
void update_shop(Transaction &t)
{
Item temp;
for(ulli i=0;i<20;i++)
{
if(t.items[i].quantity>0)
{
string Shop_category(t.items[i].shop_category);
string path = "database/shop_items/" + Shop_category + ".ooad";
fstream file(path.c_str());
if(!file)cout<<"Not Found";
while (file.read((char *)&temp, sizeof(Item)))
{
if (t.items[i].item_ID==temp.item_ID)
{
temp.quantity-=t.items[i].quantity;
long pos = file.tellp();
file.seekp(pos - sizeof(Item));
file.write((char *)&temp, sizeof(Item));
}
} file.close();
}
}
}
Transaction process(ulli option, Customer customer,Transaction &t)
{
switch (option)
{
case 1:
{
Transaction t=customer.select_items(t);//retry='n';
cout<<t.total_price<<" "<<t.quantity<<endl;
return t;
}
case 2:
{
string email="";Transaction temp;
ulli i=0;
while(customer.email[i]!='\0')
email+=customer.email[i],i++;
string path="database/transaction_data/"+email+".ooad";
ifstream file(path.c_str());
while(file.read((char *)&temp,sizeof(Transaction)))
{
//Print the Transaction slip
for(int i=0;i<20;i++)
{if(temp.items[i].quantity>0)
cout<<temp.items[i].name<<"\t"<<temp.items[i].quantity<<endl;
}
}
file.close();
return t;
}
case 3:
{
cout << "> Name : " << customer.name << endl;
cout << "> Email : " << customer.email << endl;
cout << "> contact number : " << customer.contact_number << endl;
cout << "> Credit Balance : " << customer.credit_balance << endl;
cout << "> Wallet Balance : " << customer.wallet_balance << endl;
if(customer.defaulter)
cout<<"\n> You are a defaulter and can't shop until you clear your debts";
cout << endl;
cout << "> select any of the following options :\n";
cout << "> a) go to home page\n";
cout << "> b) logout\n";
cout << ">";
char option1;
cin >> option1;
switch (option1){
case 'a':
{
system("clear");
//home_page_customer(customer,t);
return t;
}
case 'b':
{
cout<<"\n> Thanks for using our application\n";
exit(0);
return t;
}
}
break;
}
case 4:
{ cout<<"> Items\tQuantity\n";
//cout<<t.total_price<<" "<<t.quantity<<endl;
for(int i=0;i<20;i++)
{if(t.items[i].quantity>0)
//cout<<"not greater than zero";
cout<<"> "<<t.items[i].name<<"\t"<<t.items[i].quantity<<"\t\t"<<endl;
}
cout<<"> Total Price-->"<<t.total_price<<endl;
return t;
}
case 5:
{
cout<<"> Total Price--> "<<t.total_price<<"\n";
//Do the checkout
//cout<<"Only Cash on Delivery Available!!\n";
//cout<<"Would you like to go back? (y/n)";bool goback;cin>>goback;
//if(goback=='y')return t;
cout<<"> Would you like to pay on COD or Pay Later (c/p)? ";
char payment;
cin>>payment;
if(payment=='c')
t.payment_status=1;
else if(payment=='p')
{
t.payment_status=0;
customer.credit_balance+=t.total_price;
}
else
exit(0);
cout<<"> Delivery Slots:"<<endl;
cout<<"> 1) 11:00 to 12:00"<<endl;
cout<<"> 2) 13:00 to 15:00"<<endl;
cout<<"> 3) 15:30 to 17:00"<<endl;
cout<<"> 4) 17:30 to 19:00"<<endl;
cout<<"> 5) 19:30 to 20:30"<<endl;
int option_selected,option_selected2;
cout<<"> Please input the delivery slot suitable for you\n";
cin>>option_selected;
cout<<endl;
cout<<"> Delivery Locations:"<<endl;
cout<<"> 1)Common garden,Faculty Quarters\n";
cout<<"> 2)Admin/Library Block\n";
cout<<"> 3)LHC\n";
cout<<"> 4)Dining Hall Building\n";
cout<<"> 5)Common area between Green and Blue Student Hostels\n";
cout<<"> Please input the delivery location suitable for you\n";
cin>>option_selected2;
int deiver_boy_number=Moderator::assign_delivery_boy();
string temp_name(customer.name);
string temp_email(customer.email);
string temp_deliveryboy_name(deliveryboys[deiver_boy_number].name);
string temp_number(Utilities::ulli_to_string(deliveryboys[deiver_boy_number].contact_number));
string temp_amount(Utilities::ulli_to_string(t.total_price));
// working here
string pay_load="python3 mail_trans.py "+temp_email+" \""+temp_name+"\" "+temp_amount+" "+temp_deliveryboy_name+" "+temp_number;
if(payment=='c')
pay_load=pay_load+" Cash on Delivery";
else
pay_load=pay_load+" Credit";
system(pay_load.c_str());
update_shop(t);
update_shop_transaction_details(customer.email,t);
//Afer completion of Transaction(do not if the transaction is terminated)
//cout<<t.total_price<<endl;
string email="";
if(t.total_price>0){
ulli i=0;
while(customer.email[i]!='\0')
email+=customer.email[i],i++;
string path="database/transaction_data/"+email+".ooad";
ofstream file(path.c_str(),std::ios::app);
file.seekp(0L,ios::end);
file.write((char *)&t,sizeof(t));
file.close();}
t.Initialise(email);
string path="database/customer_data/"+email+".ooad";
ofstream file(path.c_str());
file.write((char*)&customer,sizeof(Customer));
file.close();
cout<<"> Transaction Done Success";
exit(1);
return t;
}
case 6:
{
cout<<"\n> Thanks for using our application";
exit(0);
return t;
}
}
}
int home_page_customer(Customer customer,Transaction &t)
{
cout<<"\n> Welcome "<<customer.name<<" !\n";int x=1;
cout << "> Select any of the following options (Type the corresponding index to select a option):\n\n";
do{
cout << "> 1) Shop now or add more items to cart\n";
cout << "> 2) View Transaction History\n";
cout << "> 3) Profile\n";
cout << "> 4) View Cart\n";
cout << "> 5) Checkout\n";
cout<< "> 6) Logout\n";
cout << "\n> ";
ulli option; //contains the input option given by the user
cin >> option;
//system("clear");
t=process(option,customer,t);
}while(x==1);
return -1;
}
int customer_portal(string email)
{
Customer customer;
cout<<"> Enter your password :: ";
customer=get_customer(email);
string password;
password=Terminal::input_password();
if(!customer.login(password))
{
cout<<"\n> Invalid email password combinationn\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(customer.name);
string temp_number(customer.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;
}
}
return -1;
}
Transaction t;
t.Initialise(email);
return home_page_customer(customer,t);
}
#endif