Compare commits
2 Commits
c69d312335
...
a0ddf33d85
Author | SHA1 | Date | |
---|---|---|---|
a0ddf33d85 | |||
dc8329de35 |
125
admin_user.h
125
admin_user.h
@ -216,7 +216,7 @@ struct inventory item_control(struct inventory db,int index){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (choice != 0);
|
||||
} while (choice != 0&&choice != 2);
|
||||
struct inventory temp = read_db_invt();
|
||||
temp.row = (struct inventory_row *)realloc(temp.row, sizeof(struct inventory_row) * (temp.db.row_count + 1));
|
||||
temp.db.row_count += 1;
|
||||
@ -495,7 +495,7 @@ void list_tran(struct transaction db){
|
||||
|
||||
|
||||
void print_tran(struct transaction db, int cur, int end,struct Map* map){
|
||||
printf("%-5s%-15s%-10s%-10s%-10s%-10s%-10s\n","No.","Date","Time","Barcode","Price","Quantity","Total");
|
||||
printf("%-5s%-15s%-10s%-10s%-10s%-10s%-10s%-10s\n","No.","Date","Time","Barcode","ID","Price","Quantity","Total");
|
||||
for (int i = cur; i < end; i++)
|
||||
{
|
||||
if(map != NULL){
|
||||
@ -503,17 +503,17 @@ void print_tran(struct transaction db, int cur, int end,struct Map* map){
|
||||
//reconstuct date and time and print all transaction info out
|
||||
char date[11];
|
||||
char time[9];
|
||||
sprintf(date,"%04d-%02d-%02d",db.row[map[i].key].date.day,db.row[map[i].key].date.month,db.row[map[i].key].date.year);
|
||||
sprintf(date,"%02d-%02d-%04d",db.row[map[i].key].date.day,db.row[map[i].key].date.month,db.row[map[i].key].date.year);
|
||||
sprintf(time,"%02d:%02d:%02d",db.row[map[i].key].time.hour,db.row[map[i].key].time.minute,db.row[map[i].key].time.second);
|
||||
printf("%-5d%-15s%-10s%-10ld%-10.2lf%-10d%-10.2lf\n",i+9-cur,date,time,db.row[map[i].key].barcode,db.row[map[i].key].price,db.row[map[i].key].quantity,total);
|
||||
printf("%-5d%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[map[i].key].barcode,db.row[map[i].key].id,db.row[map[i].key].price,db.row[map[i].key].quantity,total);
|
||||
}else{
|
||||
double total = db.row[i].price * db.row[i].quantity;
|
||||
//reconstuct date and time and print all transaction info out
|
||||
char date[11];
|
||||
char time[9];
|
||||
sprintf(date,"%04d-%02d-%02d",db.row[i].date.day,db.row[i].date.month,db.row[i].date.year);
|
||||
sprintf(date,"%02d-%02d-%04d",db.row[i].date.day,db.row[i].date.month,db.row[i].date.year);
|
||||
sprintf(time,"%02d:%02d:%02d",db.row[i].time.hour,db.row[i].time.minute,db.row[i].time.second);
|
||||
printf("%-5d%-15s%-10s%-10ld%-10.2lf%-10d%-10.2lf\n",i+9-cur,date,time,db.row[i].barcode,db.row[i].price,db.row[i].quantity,total);
|
||||
printf("%-5d%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",i+9,date,time,db.row[i].barcode,db.row[i].id,db.row[i].price,db.row[i].quantity,total);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -524,76 +524,95 @@ struct transaction update_tran(struct transaction db,int index);
|
||||
struct transaction remove_tran(struct transaction db,int index);
|
||||
|
||||
struct transaction showTran(struct transaction db,int index){
|
||||
int choice;
|
||||
do{
|
||||
printf("Transaction detail\n");
|
||||
printf("Date:day %s\n",db.row[index].date.day);
|
||||
printf("Date:month %s\n",db.row[index].date.month);
|
||||
printf("Date:year %s\n",db.row[index].date.year);
|
||||
printf("Time:hour %s\n",db.row[index].time.hour);
|
||||
printf("Time:minute %s\n",db.row[index].time.minute);
|
||||
printf("Time:second %s\n",db.row[index].time.second);
|
||||
printf("Price: $%.1lf\n",db.row[index].price);
|
||||
printf("Quantity: %d\n",db.row[index].quantity);
|
||||
printf("ID: %d\n",db.row[index].id);
|
||||
printf("Barcode: %s\n",db.row[index].barcode);
|
||||
printf("Total: $%.1lf\n",db.row[index].price * db.row[index].quantity);
|
||||
double total = db.row[index].price * db.row[index].quantity;
|
||||
//reconstuct date and time and print all transaction info out
|
||||
char date[11];
|
||||
char time[9];
|
||||
sprintf(date,"%02d-%02d-%04d",db.row[index].date.day,db.row[index].date.month,db.row[index].date.year);
|
||||
sprintf(time,"%02d:%02d:%02d",db.row[index].time.hour,db.row[index].time.minute,db.row[index].time.second);
|
||||
printf("%-15s%-10s%-10s%-10s%-10s%-10s%-10s\n","Date","Time","Barcode","ID","Price","Quantity","Total");
|
||||
printf("%-15s%-10s%-10d%-10d%-10.2lf%-10d%-10.2lf\n",date,time,db.row[index].barcode,db.row[index].id,db.row[index].price,db.row[index].quantity,total);
|
||||
printf("1 edit transaction\n");
|
||||
printf("2 delete transaction\n");
|
||||
printf("3 exit\n");
|
||||
int choice;
|
||||
bool valid = true;
|
||||
do{
|
||||
printf("Please input your choice: ");
|
||||
fflush(stdin);
|
||||
scanf("%d",&choice);
|
||||
switch(choice){
|
||||
case 1:
|
||||
valid = true;
|
||||
db = update_tran(db,index);
|
||||
break;
|
||||
case 2:
|
||||
valid = true;
|
||||
db = remove_tran(db,index);
|
||||
break;
|
||||
case 3:
|
||||
valid = true;
|
||||
break;
|
||||
default:
|
||||
printf("Invalid input, try again\n");
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}while(!valid);
|
||||
}while(choice != 3);
|
||||
return db;
|
||||
}
|
||||
|
||||
//tran controls
|
||||
void add_tran(){
|
||||
char* temp;
|
||||
struct transaction_row* row = (struct transaction_row*)malloc(sizeof(struct transaction_row));
|
||||
temp = prompt_item("Please input date:day \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
char check;
|
||||
printf("Use current date time? (y/n): ");
|
||||
fflush(stdin);
|
||||
scanf("%c",&check);
|
||||
if(check == 'y'){
|
||||
row->date = get_date();
|
||||
row->time = get_time();
|
||||
}else{
|
||||
temp = prompt_item("Please input date:day \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->date.day = atoi(temp);
|
||||
temp = prompt_item("Please input date:month \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->date.month = atoi(temp);
|
||||
temp = prompt_item("Please input date:year \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->date.year = atoi(temp);
|
||||
temp = prompt_item("Please input time:hour \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->time.hour = atoi(temp);
|
||||
temp = prompt_item("Please input time:minute \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->time.minute = atoi(temp);
|
||||
temp = prompt_item("Please input time:second \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
}
|
||||
row->date.day = atoi(temp);
|
||||
temp = prompt_item("Please input date:month \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->date.month = atoi(temp);
|
||||
temp = prompt_item("Please input date:year \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->date.year = atoi(temp);
|
||||
temp = prompt_item("Please input time:hour \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->time.hour = atoi(temp);
|
||||
temp = prompt_item("Please input time:minute \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
return;
|
||||
}
|
||||
row->time.minute = atoi(temp);
|
||||
temp = prompt_item("Please input price \n>");
|
||||
if(temp == NULL){
|
||||
free(row);
|
||||
@ -633,37 +652,37 @@ void add_tran(){
|
||||
struct transaction update_tran(struct transaction db,int index){
|
||||
char temp[100];
|
||||
printf("Update transaction(empty value to not change the value)\n");
|
||||
printf("Please input the Date:day(original:%s)\n>",db.row[index].date.day);
|
||||
printf("Please input the Date:day(original:%d)\n>",db.row[index].date.day);
|
||||
fflush(stdin);
|
||||
scanf("%[^\n]", temp);//input until /n
|
||||
if(strcmp(temp,"") != 0){//check if temp is not empty
|
||||
db.row[index].date.day = atoi(temp);
|
||||
}//else preserve the original value
|
||||
printf("Please input the Date:month(original:%s)\n>",db.row[index].date.month);
|
||||
printf("Please input the Date:month(original:%d)\n>",db.row[index].date.month);
|
||||
fflush(stdin);
|
||||
scanf("%[^\n]", temp);
|
||||
if(strcmp(temp,"") != 0){
|
||||
db.row[index].date.month = atoi(temp);
|
||||
}
|
||||
printf("Please input the Date:year(original:%s)\n>",db.row[index].date.year);
|
||||
printf("Please input the Date:year(original:%d)\n>",db.row[index].date.year);
|
||||
fflush(stdin);
|
||||
scanf("%[^\n]", temp);
|
||||
if(strcmp(temp,"") != 0){
|
||||
db.row[index].date.year = atoi(temp);
|
||||
}
|
||||
printf("Please input the Time:hour(original:%s)\n>",db.row[index].time.hour);
|
||||
printf("Please input the Time:hour(original:%d)\n>",db.row[index].time.hour);
|
||||
fflush(stdin);
|
||||
scanf("%[^\n]", temp);
|
||||
if(strcmp(temp,"") != 0){
|
||||
db.row[index].time.hour = atoi(temp);
|
||||
}
|
||||
printf("Please input the Time:minute(original:%s)\n>",db.row[index].time.minute);
|
||||
printf("Please input the Time:minute(original:%d)\n>",db.row[index].time.minute);
|
||||
fflush(stdin);
|
||||
scanf("%[^\n]", temp);
|
||||
if(strcmp(temp,"") != 0){
|
||||
db.row[index].time.minute = atoi(temp);
|
||||
}
|
||||
printf("Please input the Time:second(original:%s)\n>",db.row[index].time.second);
|
||||
printf("Please input the Time:second(original:%d)\n>",db.row[index].time.second);
|
||||
fflush(stdin);
|
||||
scanf("%[^\n]", temp);
|
||||
if(strcmp(temp,"") != 0){
|
||||
|
@ -469,7 +469,7 @@ bool append_transaction_db(struct transaction_row* row){
|
||||
printf("Error in opening file\n");
|
||||
return false;
|
||||
}
|
||||
fprintf(fp,"%d-%02d-%02d\n",row->date.year,row->date.month,row->date.day);
|
||||
fprintf(fp,"%04d-%02d-%02d\n",row->date.year,row->date.month,row->date.day);
|
||||
fprintf(fp,"%02d:%02d:%02d\n",row->time.hour,row->time.minute,row->time.second);
|
||||
fprintf(fp,"%ld\n",row->id);
|
||||
fprintf(fp,"%.1f\n",row->price);
|
||||
|
@ -20,11 +20,11 @@ typedef struct Date{
|
||||
struct Date convert_to_date(char* date){
|
||||
struct Date d;
|
||||
char* token = strtok(date, "-");
|
||||
d.day = atoi(token);
|
||||
d.year = atoi(token);
|
||||
token = strtok(NULL, "-");
|
||||
d.month = atoi(token);
|
||||
token = strtok(NULL, "-");
|
||||
d.year = atoi(token);
|
||||
d.day = atoi(token);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user