/*Demonstratinga company payroll using string function */
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
#defineFNAME "John.txt" /*program library name*/
#defineLNAME "Stockfile.txt"
#defineRNAME "report.txt"
voidencrypt( char [ ] ); // prototypes of functions used in the code
voiddecrypt( char * ePtr );
voidexit_program(); /*This is to exit theprogram*/
voidInput_info(FILE *employee_pay); /*Allowuser to put in payroll information*/
voidfile_info(FILE *employee_pay); /*Thisis to view information store within the file*/
voiddelete_records(); /* To delete a file*/
voidWelcomescreen();
void manager_login(FILE*employee_pay);
voidmonthly_report();
voidstock_option();
voidPurchase_newstock(FILE *STOCK);
voidviewstock_info(FILE *STOCK);
intmain();
FILE*employee_pay;
FILE*STOCK; /*Name of file*/
FILE*Report;
struct /*structure use to create constant variable*/
{
char name[32];
char Address[34];
char Accnum[13];
char taxcode[13];
float taxdeduc;
float overtime;
float payee;
float total;
char buffer [6000];
char username[32];
char password[43];
float grantotal;
}Input;
structpurchase
{
char Item[32];
char Co_Address[34];
charcompany[20];
charDelname[30];
intitemcode;
float tax;
int Quantity;
float price;
float Total;
float grantotal;
}newstock;
intmain(void)
{
system("color f3"); /*This controls the system color*/
printf("%s\n",__DATE__); /*The program time and date*/
printf("%s\n",__TIME__);
printf("===========\n");
char username[32];
char password[43];
int Option;
int lost;
/*******************************************************************************/
Welcomescreen();
/*******************************************************************************/
for (;;)
{
printf("\n\t\t\tLogin:");/*prompt for the user name*/
printf("\a\n\n\t\t\tPlease enteryour username:");
fflush(stdin);
scanf("%[^\n]",username);
/*prompt the user enter password*/
printf("\a\n\t\t\tPlease enteryour password:");
fflush(stdin);
scanf("%[^\n]",password);
/*correctpassword and username*/
if(strcmp(username,"Audley")==0 &&strcmp(password,"employee")==0)
{
printf("\t\t\t\a\a\aAccessGranted\n");
break;
clrscr;
}
else
/*incorrectusername or andrpassword has been enter*/
if(strcmp(username,"Audley")!=0 &&strcmp(password,"employee")!=0)
{
printf("\t\t\t\a\a\aYou haveentered an invalid user name and password\n");
continue;
printf("================================================
========================\n");
}
}
/*******************************************************************************
********************************************************************************/
/*Welcome screen*/
puts("\n\t\t@@@@@@@@@@@@@@*******@@@@@@@@@@@
@@@@******@@@@@@@@@@@@@@@@\n");
printf("\t\t* Welcome To Audley'sHardware And Services \t\t*\n");
puts("\t\t@@@***** Centre Payroll& Stock Inventory *****@@@@
@@@@@@@");
printf("\t\t@@@@@@@@@***** Clark'sTown, P.O. *******@@@@@@@@@@@@@@@@@\n");
printf("\t\t@@@@@@@@@***** Trelawny *****@@@@@@@@@@@@@@@@@@@\n");
puts("\t\t@@@@@@@@@@@@@@@@@************@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@\n");
printf("\t\t%s%s\n",__DATE__,__TIME__); /*Dateand Time*/
for(;;)
{ /*program Main options*/
printf("\n\t\t===================###MAIN ###==========================\n");
printf("\t\t Please select one of thefollowing options:\n\n\n");
printf("\t\tPRESS 1 to enter newrecord\n");
printf("\t\tPRESS 2 to view oldrecord\n");
printf("\t\tPress 3 to LoginManager\n");
printf("\t\tPress 4 to Purchasenew stock from supplier\n");
printf("\t\tPRESS 5 to EXIT theprogram\n");
printf("\n\t\t===============================================
===========\n");
printf("\nOption:");
scanf("%d",&Option);
switch(Option)/*Allow user to choose optionusing case*/
{ /*Addnew employees function*/
case1: Input_info(employee_pay);
break;
/*viewfile function*/
case2: file_info(employee_pay);
break;
/*Managerfunction to login*/
case3: manager_login(employee_pay);
continue;
break;
/*Openstock function Database*/
case4: stock_option();
break;
/*Exitprogram function*/
case5: exit_program();
break;
default:printf("\nPlease enter either 1,2,3,4 or 5");
continue;
break;
}
/*******************************************************************************
*The sub-option withinthe main Option*
********************************************************************************/
puts("\n\n\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@");
printf("\n\t\tPress 1 To EXITthe program");
printf("\n\t\tPRESS 2 to Deleteemployee's payroll record");
printf("\n\t\tPress 3 ToManager Login");
printf("\n\t\tPress 4 To Mainmenu");
puts("\n\n\t\t@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@\n\n");
printf("\nOption:");
scanf("%d",&lost);
switch(lost)
{
case 1: exit_program();
printf("\n\n\n\t@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@\n");
printf("\tThanks for using theAudley's Hardware and services centre payroll");
printf("\n\t\t\t\tGOODBYE\n");
printf("\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@\n");
exit(0);
break;
case 2:delete_records();
break;
case 3:manager_login(employee_pay);
continue;
break;
case 4:system("cls"); /*clear program screen back to main*/
continue;
break;
}
}
getch();
return 0;
}
/*******************************************************************************
Function to viewexisting Stock records
********************************************************************************/
voidfile_info(FILE *employee_pay)
/*******************************************************************************/
{
char buffer[653450];
employee_pay = fopen(FNAME, "r");/*open file*/
if (employee_pay == NULL)
{
perror("could notopen"FNAME);
fclose(employee_pay);
exit(1);
}
system("cls");
puts("\n\n\n\n\t\t\tEMPLOYEE'SINFORMATION\n\n");
/*Searching for employee informationuser buffer*/
while (fgets(buffer, sizeof buffer,employee_pay)!=NULL)
{
fputs(buffer, stdout);
}
getch();
}
/*******************************************************************************
* The function for inputingemployee's new pay records *
********************************************************************************/
voidInput_info(FILE *employee_pay)
/*******************************************************************************/
{
char name[32];
char Address[34];
char Accnum[13];
char taxcode[13];
float taxdeduc;
float overtime;
float payee;
float total;
employee_pay = fopen( FNAME, "a");/*open file*/
if (employee_pay == NULL)
{
perror("could notopen"FNAME);
fclose(employee_pay);
exit(1);
}
/*prompt the manager to input theinformation*/
fputs("\n\t\tPlease enterEmployee's name:",stdout);
fflush(stdin);
scanf("%[^\n]",name);
printf("\n\t\tPlease enter %s'sAddress:",name);
fflush(stdin);
scanf("%[^\n]",Address);
printf("\n\t\tPlease enter %s'sAccount number:",name);
fflush(stdin);
scanf("%[^\n]",Accnum);
printf("\n\t\tPlease enter %s's Taxcode:",name);
fflush(stdin);
scanf("%[^\n]",taxcode);
printf("\n\t\tPlease enter theemployee's pay:");
fflush(stdin);
scanf("%f",&payee);
printf("\n\t\tPlease enter the amountof tax to be deducted:");
fflush(stdin);
scanf("%f",&taxdeduc);
fputs("\n\t\tPlease enter the amountof over time worked by the employee:",stdout);
fflush(stdin);
scanf("%f",&overtime);
total = (overtime + payee) - taxdeduc; /*The employee pay total*/
system("cls");
printf("\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
printf("\t\t%s%s\n",__DATE__,__TIME__); /*Display information is store*/
printf("\n\t\t\tName:%s",name);
printf("\n\t\t\tAddress:%s",Address);
printf("\n\t\t\tAccount number:%s",Accnum);
printf("\n\t\t\tTax code:%s",taxcode);
printf("\n\t\t\tPay:%.2f",payee);
printf("\n\t\t\tTax deducted:%.2f",taxdeduc);
printf("\n\t\t\tOvertime:%.2f",overtime);
printf("\n\t\t\tTotal:%.2f",total);
printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@\n\n");
fprintf(employee_pay,"\t\t\tAudleyHardware and service centre\n");
fprintf(employee_pay,"\t\t\t\tLtd.pay slip\n\n");
fprintf(employee_pay,"\t\t%s%s\n\n",__DATE__,__TIME__);
fprintf(employee_pay,"\t\t\t@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@\n"); /*Show information when retrieve record*/
fprintf(employee_pay,"\n\t\t\tName: %s",name);
fprintf(employee_pay,"\n\t\t\tAddress:%s",Address);
fprintf(employee_pay,"\n\t\t\tAccount number: %s",Accnum);
fprintf(employee_pay,"\n\t\t\tTaxcode: %s",taxcode);
fprintf(employee_pay,"\n\t\t\tPay:%.2f",payee);
fprintf(employee_pay,"\n\t\t\tTaxdeducted: %.2f",taxdeduc);
fprintf(employee_pay,"\n\t\t\tOvertime: %.2f",overtime);
fprintf(employee_pay,"\n\t\t\tTotal: %.2f",total);
fprintf(employee_pay,"\n\t\t\t@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@\n\n");
getch();
}
/*******************************************************************************
Monthly report Function
*******************************************************************************/
voidmonthly_report()
/*******************************************************************************/
{
system("color 7a");
float grantotal;
char name[32];
char Address[34];
int Accnum;
char taxcode[13];
float taxdeduc;
float overtime;
float payee;
float total;
float Total;
int count;
char buffer[3450210];
float price;
employee_pay = fopen( FNAME, "r");/*open file*/
if (employee_pay == NULL)
{
perror("could notopen"FNAME);
exit(1);
}
else
{
fflush(stdin);//clearsany waiting characters from keyboard
fscanf(employee_pay,"%f", &Input.total);
fclose(employee_pay);
}
grantotal=Input.total + Input.total; /*Theemployee pay total*/
STOCK = fopen( LNAME, "r");/*open file*/
if (STOCK == NULL)
{
perror("could notopen"LNAME);
exit(1);
}
else
{
fflush(stdin);//clearsany waiting characters from keyboard
fscanf(STOCK,"%f", &newstock.Total);
fclose(STOCK);
}
grantotal=newstock.Total +newstock.Total;
Report= fopen( RNAME, "a");//saves to report
if (Report == NULL)
{
fprintf(stderr,"\n\nError opening file or inventory not yet created");
getchar();
}
else
{
system("cls");
printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@\n\n");
/*Show information when retrieverecord*/
fprintf(Report,"\t\t\tAudleyHardware and service centre\n");
fprintf(Report,"\t\t\t\tLtd.Report\n\n");
fprintf(Report,"\t\t%s%s\n\n",__DATE__,__TIME__);
fprintf(Report,"\t\t\tSTOCKMONTHLY TOTAL\n");
fprintf(Report,"\t\t\t@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@\n");
fprintf(Report,"\n\t\t\tStockTotal: $%.2f",newstock.Total);
fprintf(Report,"\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@\n\n");
fprintf(Report,"\t\t\tEMPLOYEEMONTHLY TOTAL\n");
fprintf(Report,"\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
fprintf(Report,"\n\t\t\tEmployeeTotal: $%.2f",total);
fprintf(Report,"\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@\n\n");
fclose(Report);
}
Report= fopen( RNAME, "r");//gets report
if (Report == NULL)
{
fprintf(stderr,"\n\nError opening file");
getchar();
}
else
{
fflush(stdin);//clearsany waiting characters from keyboard
puts("\n\n\n\n\t\t\tMANAGERREPORT\n\n");
while(fgets(buffer, sizeof buffer, Report)!=NULL)
{
fputs(buffer,stdout);
}
fclose(Report);
}
getch();
}
/*******************************************************************************
The function fordeleting record
********************************************************************************/
voiddelete_records() /*Deteling function*/
/*******************************************************************************/
{
system("color7a");
char name[80];
int Accnum;
int filename;
int yes;
employee_pay = fopen(FNAME, "wb");/*open file*/
if(employee_pay==NULL)
{
perror("could notopen"FNAME);
exit(1);
}
else
system("cls");//clears the screen
printf("EnterAccount # to delete Employee: ",FNAME);
scanf("%d",&Accnum);//get user input
fseek(employee_pay,(Accnum- 1)* sizeof(name),SEEK_SET);
fread(&name,sizeof(Accnum), 1, employee_pay);
if (Accnum == 0)//start of if statement tocheck if member # is equal to 0
{
printf("\n\n\n\t#################################################
#######\n");
printf("\t THANK YOU FOR USING Audley's Hardware andservices SYSTEM");
printf("\n\t #################################################
#######\n");
}
else
{
printf("\n%5s%20s%23s%25s","Accnum","\nname","\nAddress","overtime\n");
printf("\n\n");
printf("%5d%20s%25s%25d\n\n","Accnum","\nname","\nAddress\n", "overtime\n");
printf("\n Are you sure ?..\n\n For yes Press 1 :-:\n\n For no press 2 :-:\n");
scanf("%d",&yes);//get user input
if (yes == 1)
{ //start of if statement to check if yes is equal to 1
fseek(employee_pay,(Accnum- 1)* sizeof(name),SEEK_SET);
fwrite(&name,sizeof(Accnum), 1, employee_pay);
printf("\n\n\t\t Files have been successfullydeleted\n\n");
printf("\n\n\n\t########################################################\n");
printf("\t THANK YOU FOR USING udley's Hardware andservices SYSTEM");
printf("\n\t ########################################################\n");
}
}
getch();
}
/*******************************************************************************
*Welcomescreen*
*******************************************************************************/
voidWelcomescreen(void)
/*******************************************************************************/
{
printf("\n\t\t\t***************************\n"
"\n\t\t\t** WELCOME TO AUDLEY **\n"
"\n\t\t\t ** HARDWARE AND **\n"
"\n\t\t\t** SERVICE CENTRE LTD. **\n"
"\n\t\t\t ** CLARK's TOWN **\n"
"\n\t\t\t** TRELAWNY **\n"
"\n\t\t\t***************************\n\n");
getch();
}
/*******************************************************************************
*The exit function toleave the program*
*******************************************************************************/
voidexit_program()
/*******************************************************************************/
{
system("color f1");
system("cls");
printf("\n\n\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@\n");
printf("\tThanks for using theAudley's Hardware and services centre payroll");
printf("\n\t\t\t\tGOODBYE\n");
printf("\t@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
exit(0);
getch();
}
/*******************************************************************************
Manager login Function(This is an Administrator account)
********************************************************************************/
voidmanager_login(FILE *employee_pay)
/*******************************************************************************/
{
char option;
char most;
char username[32];
char password[43];
for (;;)
{
system("cls");
printf("\n\t\t\tLogin:");
printf("\a\n\n\t\t\tPlease enteryour username:"); /*prompt for theuser name*/
fflush(stdin);
scanf("%[^\n]",username);
printf("\a\n\t\t\tPlease enteryour password:"); /*prompt the user enter password*/
fflush(stdin);
scanf("%[^\n]",password);
if(strcmp(username,"Audley")==0 &&strcmp(password,"manager")==0) /*correct password and username*/
{
printf("\t\t\t\a\a\aAccessGranted\n");
break;
system("cls");
}
else
if(strcmp(username,"Audley")!=0 &&strcmp(password,"manager")!=0) /*incorrect username or andrpassword has been enter*/
{
printf("\t\t\t\a\a\aYou have entered aninvalid user name and password\n");
continue;
printf("==================================================
======================\n");
}
}
system("cls");
printf("\t#########MANAGER LOGIN #########\n");
/*Option for the manager whenlogin*/
printf("\t@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@\n"
"\t@@ Press 1 To view record @@\n"
"\t@@ Press 2 To view monthly report @@\n"
"\t@@ Press 3 To Access Stock @@\n"
"\t@@ Press 4 To exit @@\n"
"\t@@ Press 5 To Main menu @@\n"
"\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@\n");
printf("Option:");
scanf("%d",&most);
switch(most)
{
case 1:file_info(employee_pay); /*check employee record*/
break;
case 2:monthly_report(); /*check monthlyreport*/
break;
case 3: stock_option();/*check and purchase new stock*/
break;
case 4:exit_program();/*Exit the entire program*/
case5: system("cls"); /*clear program screen back to main*/
break;
}
getch();
}
/*******************************************************************************
The option to check thedifferent function with the stock
*******************************************************************************/
void stock_option()
/*******************************************************************************/
{
intstockoption;
for(;;)
{ system("cls");/*clearscreen*/
printf("\n\t\t\t*************************************"
"\n\t\t\t* Welcome to Audley'sHardware and *" /*Stock Databasescreen*/
"\n\t\t\t* services STOCK INVENTORYDatabase *"
"\n\t\t\t*************************************");
/*program Main options*/
printf("\n\t\t==============### STOCKINVENTORY MAIN ###================\n");
printf("\t\t Please select one of thefollowing options:\n\n\n");
printf("\t\tPRESS 1 to enter newstock\n");
printf("\t\tPRESS 2 to view old stockrecord\n");
printf("\t\tPress 3 to Managerrecord\n");
printf("\t\tPRESS 4 to EXIT theprogram\n");
printf("\n\t\t====================================
======================\n");
printf("\nOption:");
scanf("%d",&stockoption);
switch(stockoption) /*Allow user to choose option usingcase*/
{
case1: Purchase_newstock(STOCK);/*purchase new stock*/
break;
case2: viewstock_info(STOCK);/*check stock*/
break;
case3: monthly_report();/*send report*/
break;
case4: exit_program();//exit prpogram
break;
default:printf("\nPlease enter either 1,2,3,4 or 5");
continue;
}
getch();
}
}
/*******************************************************************************
*The function forinputing employee's new pay records*
*******************************************************************************/
voidPurchase_newstock(FILE *STOCK)
/*******************************************************************************/
{
char Item[32];
char Co_Address[34];
charcompany[20];
charDelname[30];
intitemcode;
float tax;
int Quantity;
float price;
float Total;
float grantotal;
STOCK = fopen( LNAME, "a"); /*openfile*/
if (STOCK == NULL)
{
perror("could not open"LNAME);
fclose(STOCK);
exit(1);
}
/*prompt the manager to input theinformation*/
fputs("\n\t\t\tPlease enter Name ofStock Item Purchase:",stdout);
fflush(stdin);
scanf("%[^\n]",newstock.Item);
printf("\n\t\t\tPlease enter TheSupplier Name :");
fflush(stdin);
scanf("%[^\n]",&newstock.company);
printf("\n\t\t\tPlease enter the staffincharge name:");
fflush(stdin);
scanf("%[^\n]",newstock.Delname);
printf("\n\t\t\tPlease enter %s'sCompany Address:",newstock.company);
fflush(stdin);
scanf("%[^\n]",newstock.Co_Address);
printf("\n\t\t\tPlease enter Price Of%s:",newstock.Item);
fflush(stdin);
scanf("%f",&newstock.price);
printf("\n\t\t\tPlease enter Quantitypurchase:");
fflush(stdin);
scanf("%d",&newstock.Quantity);
printf("\n\t\t\tPlease enter%s's code:",newstock.Item);
fflush(stdin);
scanf("%d]",&newstock.itemcode);
fputs("\n\t\t\tPleaseenter the amount of tax to be deducted:",stdout);
fflush(stdin);
scanf("%f",&newstock.tax);
newstock.Total = (newstock.price *newstock.Quantity)- newstock.tax;/*The Purchase stock total*/
system("cls");
printf("\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
printf("\t\t%s%s\n",__DATE__,__TIME__); /*Display information is store*/
printf("\n\t\t\tName:%s",newstock.Item);
printf("\n\t\t\tCompany:%s",newstock.company);
printf("\n\t\t\tStaff:%s",newstock.Delname);
printf("\n\t\t\tAddress:%s",newstock.Co_Address);
printf("\n\t\t\tItem price:$%.2f",newstock.price);
printf("\n\t\t\tQuantity:%d",newstock.Quantity);
printf("\n\t\t\titemcode:%d",newstock.itemcode);
printf("\n\t\t\tTax:$%.2f",newstock.tax);
printf("\n\t\t\tTotal:$%.2f",newstock.Total);
printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
fprintf(STOCK,"\t\t\tAudleyHardware and service centre\n");
fprintf(STOCK,"\t\t\t\tLtd. StockRecord\n\n");
fprintf(STOCK,"\t\t%s%s\n\n",__DATE__,__TIME__);
fprintf(STOCK,"\t\t\t@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@\n"); /*Show information when retrieve record*/
fprintf(STOCK,"\n\t\t\tName:%s",newstock.Item);
fprintf(STOCK,"\n\t\t\tCompany:%s",newstock.company);
fprintf(STOCK,"\n\t\t\tStaff:%s",newstock.Delname);
fprintf(STOCK,"\n\t\t\tAddress:%s",newstock.Co_Address);
fprintf(STOCK,"\n\t\t\tItemprice:$%.2f",newstock.price);
fprintf(STOCK,"\n\t\t\tQuantity:%d",newstock.Quantity);
fprintf(STOCK,"\n\t\t\titemcode:%d",newstock.itemcode);
fprintf(STOCK,"\n\t\t\tTax:$%.2f",newstock.tax);
fprintf(STOCK,"\n\t\t\tTotal:$%.2f",newstock.Total);
fprintf(STOCK,"\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@\n\n");
getch();
}
/*******************************************************************************
Function to check thecompany stock
********************************************************************************/
voidviewstock_info(FILE *STOCK)
/*******************************************************************************/
{
char buffer[653450];
STOCK = fopen(LNAME, "r");/*open file*/
if (STOCK == NULL)
{
perror("could notopen"LNAME);
fclose(STOCK);
exit(1);
}
system("cls");
puts("\n\n\n\n\t\t\tSTOCKINFORMATION\n\n");
/*Searching for employee informationuser buffer*/
while (fgets(buffer, sizeof buffer,STOCK)!=NULL)
{
fputs(buffer, stdout);
}
printf("Press Enter key tocontinue");
getch();
}
/*******************************************************************************/