-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory-management.c
More file actions
269 lines (228 loc) · 6.31 KB
/
inventory-management.c
File metadata and controls
269 lines (228 loc) · 6.31 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Function declarations
void menu();
void transaction();
void buying();
void selling();
void searchdata();
void showDetails();
void profit_loss_data();
struct veg {
int SN;
char name[20];
float quantity;
float rate;
} v[100], temp[100];
// introduce a delay for loading animation
void delay(int mseconds) {
clock_t goal = mseconds + clock();
while (goal > clock());
}
// entry point of the program
void main() {
int loader; // counter for loading animation
// set console colors
system("COLOR 0A");
printf("Loading...");
// display a loading animation
for (loader = 1; loader < 20; loader++) {
delay(50); // introduce a delay for animation
printf(".");
}
// call the main menu function
menu();
}
// display the main manu
void menu() {
system("cls"); // Clear the console
printf("WELCOME TO INVENTORY MANAGEMENT SYSTEM\n");
printf("1. Transaction\n");
printf("2. View Details\n");
printf("3. Exit\n");
printf("Enter your choice: ");
char choice;
scanf(" %c", &choice);
switch (choice) {
case '1':
transaction();
break;
case '2':
showDetails();
break;
case '3':
printf("Exiting program. Goodbye!\n");
exit(0);
default:
printf("Invalid choice! Try again.\n");
getchar();
menu();
}
}
// display the transaction menu
void transaction() {
system("cls"); // clear the console
printf("TRANSACTION MENU\n");
printf("1. Buying\n");
printf("2. Selling\n");
printf("3. Back to Menu\n");
printf("Enter your choice: ");
char choice;
scanf(" %c", &choice);
switch (choice) {
case '1':
buying();
break;
case '2':
selling();
break;
case '3':
menu();
break;
default:
printf("Invalid choice! Try again.\n");
getchar();
transaction();
}
}
// handle buying transactions
void buying() {
system("cls"); // clear the console
FILE *fp = fopen("buyingdata.txt", "a"); /
if (fp == NULL) {
printf("Error opening file.\n");
return;
}
struct veg item;
// collect item details from the user
printf("Enter item name: ");
scanf("%s", item.name);
printf("Enter quantity: ");
scanf("%f", &item.quantity);
printf("Enter rate: ");
scanf("%f", &item.rate);
fprintf(fp, "%s %.2f %.2f\n", item.name, item.quantity, item.rate);
fclose(fp); // Close the file
printf("Item added successfully!\n");
transaction(); // return to the transaction
}
// handle selling transactions
void selling() {
system("cls");
FILE *fp = fopen("sellingdata.txt", "a");
if (fp == NULL) {
printf("Error opening file.\n");
return;
}
struct veg item;
printf("Enter item name: ");
scanf("%s", item.name);
printf("Enter quantity: ");
scanf("%f", &item.quantity);
printf("Enter rate: ");
scanf("%f", &item.rate);
fprintf(fp, "%s %.2f %.2f\n", item.name, item.quantity, item.rate);
fclose(fp);
printf("Item added successfully!\n");
transaction();
}
// display the details
void showDetails() {
system("cls");
printf("VIEW DETAILS MENU\n");
printf("1. Search Data\n");
printf("2. View Profit/Loss\n");
printf("3. Back to Menu\n");
printf("Enter your choice: ");
char choice;
scanf(" %c", &choice);
switch (choice) {
case '1':
searchdata();
break;
case '2':
profit_loss_data();
break;
case '3':
menu();
break;
default:
printf("Invalid choice! Try again.\n");
getchar();
showDetails();
}
}
// search for an item
void searchdata() {
system("cls");
printf("Enter the item name to search: ");
char itemName[20];
scanf("%s", itemName);
FILE *fp = fopen("buyingdata.txt", "r");
if (fp == NULL) {
printf("Error opening file.\n");
return;
}
struct veg item;
int found = 0;
while (fscanf(fp, "%s %f %f", item.name, &item.quantity, &item.rate) != EOF) {
if (strcmp(item.name, itemName) == 0) {
printf("Item found in buying records: %s, Quantity: %.2f, Rate: %.2f\n", item.name, item.quantity, item.rate);
found = 1;
}
}
fclose(fp);
fp = fopen("sellingdata.txt", "r");
if (fp == NULL) {
printf("Error opening file.\n");
return;
}
while (fscanf(fp, "%s %f %f", item.name, &item.quantity, &item.rate) != EOF) {
if (strcmp(item.name, itemName) == 0) {
printf("Item found in selling records: %s, Quantity: %.2f, Rate: %.2f\n", item.name, item.quantity, item.rate);
found = 1;
}
}
fclose(fp);
if (!found) {
printf("Item not found in records.\n");
}
printf("Press Enter to return to menu.\n");
getchar();
getchar();
showDetails();
}
// calculate and display profit or loss
void profit_loss_data() {
system("cls");
printf("PROFIT/LOSS DATA\n");
FILE *buyFile = fopen("buyingdata.txt", "r");
FILE *sellFile = fopen("sellingdata.txt", "r");
if (buyFile == NULL || sellFile == NULL) {
printf("Error opening files.\n");
return;
}
float buyingCost = 0, sellingRevenue = 0;
struct veg item;
while (fscanf(buyFile, "%s %f %f", item.name, &item.quantity, &item.rate) != EOF) {
buyingCost += item.quantity * item.rate;
}
fclose(buyFile);
while (fscanf(sellFile, "%s %f %f", item.name, &item.quantity, &item.rate) != EOF) {
sellingRevenue += item.quantity * item.rate;
}
fclose(sellFile);
printf("Total Buying Cost: %.2f\n", buyingCost);
printf("Total Selling Revenue: %.2f\n", sellingRevenue);
if (sellingRevenue > buyingCost) {
printf("Profit: %.2f\n", sellingRevenue - buyingCost);
} else {
printf("Loss: %.2f\n", buyingCost - sellingRevenue);
}
printf("Press Enter to return to menu.\n");
getchar();
getchar();
showDetails();
}