transaction bug fix;
transaction fix
This commit is contained in:
parent
dc8329de35
commit
a0ddf33d85
75
admin_user.h
75
admin_user.h
@ -216,7 +216,7 @@ struct inventory item_control(struct inventory db,int index){
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (choice != 0);
|
} while (choice != 0&&choice != 2);
|
||||||
struct inventory temp = read_db_invt();
|
struct inventory temp = read_db_invt();
|
||||||
temp.row = (struct inventory_row *)realloc(temp.row, sizeof(struct inventory_row) * (temp.db.row_count + 1));
|
temp.row = (struct inventory_row *)realloc(temp.row, sizeof(struct inventory_row) * (temp.db.row_count + 1));
|
||||||
temp.db.row_count += 1;
|
temp.db.row_count += 1;
|
||||||
@ -562,42 +562,57 @@ struct transaction showTran(struct transaction db,int index){
|
|||||||
}
|
}
|
||||||
}while(!valid);
|
}while(!valid);
|
||||||
}while(choice != 3);
|
}while(choice != 3);
|
||||||
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
//tran controls
|
//tran controls
|
||||||
void add_tran(){
|
void add_tran(){
|
||||||
char* temp;
|
char* temp;
|
||||||
struct transaction_row* row = (struct transaction_row*)malloc(sizeof(struct transaction_row));
|
struct transaction_row* row = (struct transaction_row*)malloc(sizeof(struct transaction_row));
|
||||||
temp = prompt_item("Please input date:day \n>");
|
char check;
|
||||||
if(temp == NULL){
|
printf("Use current date time? (y/n): ");
|
||||||
free(row);
|
fflush(stdin);
|
||||||
return;
|
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>");
|
temp = prompt_item("Please input price \n>");
|
||||||
if(temp == NULL){
|
if(temp == NULL){
|
||||||
free(row);
|
free(row);
|
||||||
|
@ -70,4 +70,4 @@
|
|||||||
32001
|
32001
|
||||||
15.000000
|
15.000000
|
||||||
10
|
10
|
||||||
5155
|
5155
|
||||||
|
@ -469,7 +469,7 @@ bool append_transaction_db(struct transaction_row* row){
|
|||||||
printf("Error in opening file\n");
|
printf("Error in opening file\n");
|
||||||
return false;
|
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,"%02d:%02d:%02d\n",row->time.hour,row->time.minute,row->time.second);
|
||||||
fprintf(fp,"%ld\n",row->id);
|
fprintf(fp,"%ld\n",row->id);
|
||||||
fprintf(fp,"%.1f\n",row->price);
|
fprintf(fp,"%.1f\n",row->price);
|
||||||
|
@ -20,11 +20,11 @@ typedef struct Date{
|
|||||||
struct Date convert_to_date(char* date){
|
struct Date convert_to_date(char* date){
|
||||||
struct Date d;
|
struct Date d;
|
||||||
char* token = strtok(date, "-");
|
char* token = strtok(date, "-");
|
||||||
d.day = atoi(token);
|
d.year = atoi(token);
|
||||||
token = strtok(NULL, "-");
|
token = strtok(NULL, "-");
|
||||||
d.month = atoi(token);
|
d.month = atoi(token);
|
||||||
token = strtok(NULL, "-");
|
token = strtok(NULL, "-");
|
||||||
d.year = atoi(token);
|
d.day = atoi(token);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user