diff --git a/admin_user.h b/admin_user.h index 88bae76..54dd055 100644 --- a/admin_user.h +++ b/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; @@ -562,42 +562,57 @@ struct transaction showTran(struct transaction db,int index){ } }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); diff --git a/data_file_transaction.txt b/data_file_transaction.txt index ed97022..66c1e37 100644 --- a/data_file_transaction.txt +++ b/data_file_transaction.txt @@ -70,4 +70,4 @@ 32001 15.000000 10 -5155 \ No newline at end of file +5155 diff --git a/database.h b/database.h index f49d02f..c007aaf 100644 --- a/database.h +++ b/database.h @@ -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); diff --git a/dateNtime.h b/dateNtime.h index f7712b3..6476782 100644 --- a/dateNtime.h +++ b/dateNtime.h @@ -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; }