Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This source code is written in Linux
- some syntax will not be recognized
- by Windows compiler. If you faced a
- problem, please review and fix the code
- yourself.
- SESSIONS VARIABLES
- - temporary and will be cleared after the session is over
- TRANSACTIONS VARIABLES
- - record sessions data
- */
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #ifdef linux
- #define CLS_NAME "clear"
- #else
- #define CLS_NAME "cls"
- #endif
- // GLOBAL VARIABLES DECLARATIONS
- /*
- itemQuantity[][0] = Item Qty in inventory
- itemQuantity[][1] = Item Qty in a session
- itemQuantity[][2] = Item Qty in all transactions
- item_Price_Profit[][0] = Item Price
- item_Price_Profit[][1] = Item Profit
- */
- int totalItem=13,itemQuantity[][3]={8,0,0,9,0,0,11,0,0,0,0,0,20,0,0,22,0,0,16,0,0,18,0,0,9,0,0,7,0,0,5,0,0,12,0,0,0,0,0},sessionQuantity,sessionNumber=1,hiddenItemQuantity[]={},itemId;
- float item_Price_Profit[][2]={1,0.5,2,0.2,3,0.2,4,0.2,5,0.5,6,0.8,7,0.5,8,0.2,9,0.2,10,0.2,11,0.5,12,0.8,13,0.9},sesionTotalPrice,transactionTotalProfit=0,transactionTotalPrice=0,sessionPayment;
- char itemName[][30]={"STABILO PENCIL 2B","STABILO PEN 0.5","STABILO ERASER","STABILO RULER","STABILO TEST PAD","STABILO BOOK","STABILO SCISSORS","STABILO SHARPENER","STABILO GLUE","STABILO CHALK","STABILO MARKER PEN","OXFORD DICTIONARY","STABILO HIGHLIGHTER"},dummy;
- // FUNCTIONS PROTOTYPES
- void showTime();void menuSelection(int);void newTransaction();void allTransactions();void addItem();void reviewCart();void removeItem();void sessionReceipt();void gotoMenu();void calcQuantity(int);void allStocks();void addStock();void addStockItem();void editStockItem();void hideStockItem();void getItemId(int);void getItemQty();void getNewItemProfit(int);void getAuth();
- // DISPLAY MENU
- main(){
- int choice;
- system(CLS_NAME);
- showTime();
- printf("Assalamualaikum\n\nMAIN MENU :\n\n 1 - New Transaction\n 2 - All Transactions\n 3 - Stocks\n\nPlease select an option : ");
- scanf("%d",&choice);
- if(choice>0&&choice<4) menuSelection(choice);
- else main();
- }
- void showTime(){
- time_t mytime;
- mytime = time(NULL);
- printf("%38s",ctime(&mytime));
- }
- // MENU SELECTION
- void menuSelection(int choice){
- if(choice!=6) system(CLS_NAME);
- switch(choice){
- case 1 : sesionTotalPrice = 0;
- newTransaction();break;
- case 2 : allTransactions();break;
- case 3 : //getAuth(); break;
- allStocks(); break;
- case 4 : addStock();break;
- case 5 : addStockItem();break;
- case 6 : getItemId(3);
- editStockItem();break;
- case 7 : getItemId(4);
- hideStockItem();break;
- case 8 : main();break;
- default : main();break;
- }
- }
- // SHOWS ITEMS LIST
- void newTransaction(){
- int i;
- system(CLS_NAME); //system("cls");
- printf("INVENTORY SESSION NO : %3d\n",sessionNumber);
- printf(" TOTAL PRICE : RM %6.2f\n\n",sesionTotalPrice);
- printf("ID Item Qty Price\n");
- printf("-------------------------------------------\n");
- for (i=0;i<totalItem;i++){
- if (itemQuantity[i][0]==-1) ;
- else if (itemQuantity[i][0]==0) printf("%-2d %-27sOUT OF STOCK\n",i,itemName[i]);
- else printf("%-2d %-28s%3d %6.2f\n",i,itemName[i],itemQuantity[i][0],item_Price_Profit[i][0]);
- }
- printf("-------------------------------------------\n");
- printf("-1 VIEW CART\n99 CHECK OUT\n");
- addItem();
- }
- /*GET ITEM ID :
- 1=TO BE ADDED TO CART,
- 2=TO BE REMOVED FROM CART,
- 3=TO BE EDITED,
- 4=TO BE REMOVED,*/
- void getItemId(int i){
- switch(i){
- case 1 : printf("\nPlease enter Item ID to add to cart : ");break;
- case 2 : printf("\nPlease enter Item ID to hide from cart : ");break;
- case 3 : printf("ID of item to be edited : ");break;
- case 4 : printf("ID of item to be hide/unhide : ");break;
- case 5 : printf("ID of item to be restocked : ");break;
- }
- scanf("%d",&itemId);
- if(i==3 && itemId>=totalItem) {
- printf("Item does not exist. Create? Y to confirm : ");
- fflush(stdin);
- scanf("%s",&dummy);
- if(toupper(dummy)!='Y') allStocks();
- itemId = totalItem++;
- }
- }
- void getItemQty(){
- printf("Please enter Item Quantity : ");
- scanf("%d",&sessionQuantity);
- }
- // GET ITEM ID & QTY FROM USER TO BE ADDED TO SESSIONS VARIABLES
- void addItem(){
- getItemId(1);
- if (itemId==-1) reviewCart();
- if (itemId==99) sessionReceipt();
- if (itemId>=totalItem) newTransaction();
- if (itemQuantity[itemId][0]==0||itemQuantity[itemId][0]==-1) {
- printf("--UNAVAILABLE--\n");
- sleep(1);
- newTransaction();
- }
- if (itemQuantity[itemId][0]==1) {
- itemQuantity[itemId][0] --;
- itemQuantity[itemId][1] ++;
- itemQuantity[itemId][2] ++;
- sesionTotalPrice += item_Price_Profit[itemId][0];
- newTransaction();
- }
- getItemQty();
- if (sessionQuantity<0){
- printf("--INVALID--\n");
- sleep(1);
- newTransaction();
- }
- if (sessionQuantity>itemQuantity[itemId][0]){
- printf("--INSUFFICIENT--\n");
- sleep(1);
- newTransaction();
- }
- calcQuantity(1);
- newTransaction();
- }
- // DISPLAY DATA STORED IN SESSIONS VARIABLES
- void reviewCart(){
- int i;
- system(CLS_NAME); //system("cls");
- printf("INVENTORY SESSION NO : %3d\n",sessionNumber);
- printf(" TOTAL PRICE : RM %6.2f\n\n",sesionTotalPrice);
- printf("ID Item Price Amount\n");
- printf("-------------------------------------------\n");
- for (i=0;i<totalItem;i++){
- if (itemQuantity[i][1]!=0)
- printf("%-2d %2dx%-24s %5.2f %6.2f\n",i,itemQuantity[i][1],itemName[i],item_Price_Profit[i][0],item_Price_Profit[i][0]*itemQuantity[i][1]);
- }
- printf(" ------\n");
- printf("SUB TOTAL %6.2f\n",sesionTotalPrice);
- printf("-------------------------------------------\n");
- printf("-1 BROWSE INVENTORY\n99 CHECK OUT\n");
- removeItem();
- }
- // GET ITEM ID & QTY FROM USER TO BE hide FROM SESSIONS VEARIABLES
- void removeItem(){
- getItemId(2);
- if (itemId==-1) newTransaction();
- if (itemId==99) sessionReceipt();
- if (itemId>=totalItem) removeItem();
- if (itemQuantity[itemId][1]==1) {
- itemQuantity[itemId][0] ++;
- itemQuantity[itemId][1] --;
- itemQuantity[itemId][2] --;
- sesionTotalPrice -= item_Price_Profit[itemId][0];
- reviewCart();
- }
- if (itemQuantity[itemId][1]==0||itemQuantity[itemId][0]==-1) {
- printf("--ITEM INEXISTENT--\n");
- sleep(1);
- reviewCart();
- }
- getItemQty();
- if (sessionQuantity<0){
- printf("--INVALID--\n");
- sleep(1);
- reviewCart();
- }
- if (sessionQuantity>itemQuantity[itemId][1]){
- printf("--INSUFFICIENT--\n");
- sleep(1);
- reviewCart();
- }
- calcQuantity(-1);
- reviewCart();
- }
- // DISPLAY SESSION RECEIPT - ONE TIME ONLY
- void sessionReceipt(){
- int i;
- system(CLS_NAME); //system("cls");
- showTime();
- printf("Receipt number : %d\n",sessionNumber);
- printf("-------------------------------------\n");
- printf("Item\t\tQty Price Amount\n");
- for (i=0;i<totalItem;i++){
- if (itemQuantity[i][1]!=0)
- printf("%d\t\t%3d %5.2f %6.2f\n%s\n",i,itemQuantity[i][1],item_Price_Profit[i][0],item_Price_Profit[i][0]*itemQuantity[i][1],itemName[i]);
- if(sessionPayment!=0) itemQuantity[i][1]=0;
- }
- printf("\n ---------\n");
- printf("SUB TOTAL %6.2f",sesionTotalPrice);
- printf("\n ---------\n\n");
- if(sessionPayment==0){
- printf("CASH : ");
- scanf("%f",&sessionPayment);
- sessionReceipt();
- }else printf("CASH : %.2f\n",sessionPayment);
- printf("CHANGE : %.2f\n",sessionPayment-sesionTotalPrice);
- printf("\n\n-------------------------------------\n");
- printf("---------THANK YOU FOR COMING--------\n");
- printf("-------------------------------------\n");
- transactionTotalPrice += sesionTotalPrice;
- sessionNumber++;
- sessionPayment=0;
- gotoMenu();
- }
- // DISPLAY TOTAL TRANSACTIONS
- void allTransactions(){
- int i;
- system(CLS_NAME); //system("cls");
- printf("ALL TRANCTIONS\n\n");
- printf("ID Item Price Profit\n");
- printf("---------------------------------------------\n");
- for (i=0;i<totalItem;i++){
- if (itemQuantity[i][2]!=0)
- printf("%-2d %2dx%-24s %6.2f %6.2f\n",i,itemQuantity[i][2],itemName[i],item_Price_Profit[i][0]*itemQuantity[i][2],item_Price_Profit[i][1]*itemQuantity[i][2]);
- transactionTotalProfit += item_Price_Profit[i][1]*itemQuantity[i][2];
- }
- printf(" ------ ------\n");
- printf("TOTAL %6.2f %6.2f\n",transactionTotalPrice,transactionTotalProfit);
- printf(" ------ ------\n");
- printf("TOTAL TRANSACTIONS %6d\n",sessionNumber-1);
- printf("---------------------------------------------\n");
- transactionTotalProfit = 0;
- gotoMenu();
- }
- // PAUSE PROGRAM AND CONTINUE WITH dummy KEY ENTRY
- void gotoMenu(){
- printf("\n\nPress Enter to continue...");
- fflush(stdin);
- dummy = getchar();
- while (getchar() != '\n');
- main();
- }
- // CALCULATE QUANTITY IN SESSIONS AND TRANSACTIONS
- void calcQuantity(int i){
- itemQuantity[itemId][1] += (i*sessionQuantity);
- itemQuantity[itemId][2] += (i*sessionQuantity);
- itemQuantity[itemId][0] -= (i*sessionQuantity);
- sesionTotalPrice += (i*sessionQuantity*item_Price_Profit[itemId][0]);
- }
- void allStocks(){
- int i,choice;
- system(CLS_NAME);
- printf("INVENTORY\n");
- printf("ID Item Qty Price Profit\n");
- printf("+----------------------------------------------------+\n");
- for (i=0;i<totalItem;i++){
- if(itemQuantity[i][0]==-1) printf("|%-2d %-31sITEM HAS BEEN HID|\n",i,itemName[i]);
- else printf("|%-2d %-28s%3d %5.2f %6.2f|\n",i,itemName[i],itemQuantity[i][0],item_Price_Profit[i][0],item_Price_Profit[i][1]);
- }
- printf("+----------------------------------------------------+\n");
- printf("MENU :\n\n 1 - Add Stock\n 2 - Add Item\n 3 - Edit Item\n 4 - hide/Unhide Item\n 5 - Main Menu\n\nPlease select an option : ");
- scanf("%d",&choice);
- choice += 3;
- if(choice>3&&choice<9) menuSelection(choice);
- else allStocks();
- }
- void addStock(){
- getItemId(5);
- if(itemQuantity[itemId][0]==-1){
- printf("UNHIDE ITEM BEFORE ADD STOCK\n");
- sleep(1);
- allStocks();
- }
- getItemQty();
- itemQuantity[itemId][0] += sessionQuantity;
- allStocks();
- }
- // Currently problematic
- void addStockItem(){
- system(CLS_NAME);
- printf("New Item\n\n");
- printf("New Item Name : ");
- fflush(stdin);
- scanf(" %[^\n]s",&*itemName[totalItem]);
- //itemName[totalItem][30] = strupr(itemName[totalItem]);
- fflush(stdin);
- printf("New Item Price : ");
- scanf("%f",&item_Price_Profit[totalItem][0]);
- getNewItemProfit(totalItem);
- printf("New Item Qty : ");
- scanf("%d",&itemQuantity[totalItem][0]);
- itemQuantity[totalItem][1]=0;
- itemQuantity[totalItem][2]=0;
- ++totalItem;
- allStocks();
- }
- void getNewItemProfit(int i){
- printf("New Item Profit : ");
- scanf("%f",&item_Price_Profit[i][1]);
- while(item_Price_Profit[i][1]>item_Price_Profit[i][0]/2){
- printf("Profit more than half of item's price. Please reduce!\n New Item Profit : ");
- scanf("%f",&item_Price_Profit[i][1]);
- }
- }
- // Currently problematic
- void editStockItem(){
- int i;
- system(CLS_NAME);
- printf("Name : %s\n",itemName[itemId]);
- printf("Price : %.2f\n",item_Price_Profit[itemId][0]);
- printf("Profit : %.2f\n",item_Price_Profit[itemId][1]);
- printf("Qty : %d\n",itemQuantity[itemId][0]);
- printf("\nEdit \n\n 1 - Name\n 2 - Price\n 3 - Profit\n 4 - Quantity\n 5 - Back to Stocks\n\nPlease select what to edit: ");
- scanf("%d",&i);
- switch(i){
- case 1 : printf("New Item Name : ");
- fflush(stdin);
- scanf(" %[^\n]s",&*itemName[itemId]);break;
- case 2 : printf("New Item Price : ");
- scanf("%f",&item_Price_Profit[itemId][0]);break;
- case 3 : getNewItemProfit(itemId);break;
- case 4 : printf("New Item Qty : ");
- scanf("%d",&itemQuantity[itemId][0]);break;
- case 5 : allStocks();break;
- default : break;
- }
- editStockItem();
- }
- void hideStockItem(){
- if(itemQuantity[itemId][0]!=-1) {
- hiddenItemQuantity[itemId]=itemQuantity[itemId][0];
- itemQuantity[itemId][0]=-1;
- }
- else itemQuantity[itemId][0]=hiddenItemQuantity[itemId];
- allStocks();
- }
- void getAuth(){
- int i;
- char user[][10]={"manager","134562"},authdummy[10]={};
- system(CLS_NAME);
- printf("USER : ");
- scanf("%s",&*authdummy);
- for(i=0;i<10;i++){
- if(authdummy[i]!=user[0][i]){
- printf("ONLY A MANAGER CAN VIEW THIS PAGE\n");
- sleep(1);
- main();
- }
- }
- printf("PASS : ");
- for(i=0;i<6;i++){
- fflush(stdin);
- // authdummy[i] = getch();
- fflush(stdin);
- if(authdummy[i]=='\n') break;
- printf("*");
- }
- for(i=0;i<6;i++){
- if(authdummy[i]!=user[1][i]){
- printf("\nWRONG PASSWORD\n");
- sleep(1);
- main();
- }
- }
- allStocks();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement