Advertisement
Guest User

toprint

a guest
Mar 26th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 71.86 KB | None | 0 0
  1. /**********************************************************************************************************************
  2. This is to certify that this project is my own work, based on my personal efforts in studying and applying the concepts
  3. learned. I have constructed the functions and their respective algorithms and corresponding code by myself. The program
  4. was run, tested, and debugged by my own efforts. I further certify that I have not copied in part or whole or otherwise
  5. plagiarized the work of other students and/or persons.
  6. Rivera, Miguel Fernando Cua, 11610794
  7. **********************************************************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <time.h>
  13. #define MAX_CART 100
  14. #define MAX_CATEG 10
  15.  
  16. typedef char string15[16];
  17. typedef char string20[21];
  18. typedef char string50[51];
  19. typedef char string8[9];
  20.  
  21. typedef struct {
  22. string20 first,middle,last;
  23. }nameType; //Structure for the user's name
  24.  
  25. typedef struct{
  26. nameType name;
  27. string50 address;
  28. }userInfoType; //Structure for user information
  29.  
  30. typedef struct{
  31. string8 code;
  32. int qty;
  33. }prodBoughtType; //Structure for the cart
  34.  
  35. typedef struct stockTag{
  36. string8 productcode;
  37. string15 supplier,
  38. product;
  39. int quantityavailable,
  40. quantitysold;
  41. float purchaseprice,
  42. unitsellingprice,
  43. discountrate;
  44. struct stockTag *pNext;
  45.  
  46. }z; //Product List structure
  47.  
  48. typedef struct stockTag stockType;
  49. typedef stockType * ptrStock;
  50.  
  51. typedef struct{
  52. string15 category;
  53. ptrStock pFirstStock;
  54. } categoryType;
  55.  
  56. typedef categoryType aStocks[10];
  57.  
  58. //typedef struct stockTag stockType;
  59. //typedef stockType * ptrStock; //Stocks Structure
  60.  
  61. typedef prodBoughtType arrBought[MAX_CART];
  62. struct userTag{
  63.  
  64. string15 username,
  65. password;
  66. userInfoType info;
  67. char type;
  68. float creditlimit,
  69. outstanding;
  70. arrBought cart;
  71. int nItems,
  72. nLocked,
  73. nLoggedin,
  74. nCheckedout;
  75. struct userTag *pNext;
  76. };
  77. typedef struct userTag userType;
  78. typedef userType * ptrUser; //User Information Structure
  79.  
  80. /*Function prodcode has 1 use:
  81.  
  82. 1. Generates a product code
  83.  
  84. @param i: index variable
  85. @param categoryinitial: holds first letter of category
  86. @param supplierinitial: holds first letter of supplier
  87. @param productinitial: holds first letter of product
  88. */
  89. stockType* prodcode (categoryType *pStock, aStocks *aCategories, int index)
  90. {
  91. int i;
  92.  
  93. char categoryinitial = aCategories[index]->category[0];
  94. char supplierinitial = aCategories[index]->pFirstStock->supplier[0];
  95. char productinitial = aCategories[index]->pFirstStock->product[0];
  96.  
  97. if (aCategories[index]->category==NULL)
  98. categoryinitial = 0;
  99. if (aCategories[index]->pFirstStock->supplier == NULL)
  100. supplierinitial = 0;
  101. if (aCategories[index]->pFirstStock->product == NULL)
  102. productinitial = 0;
  103.  
  104. aCategories[index]->pFirstStock->productcode[0] = categoryinitial;
  105. aCategories[index]->pFirstStock->productcode[1] = supplierinitial;
  106. aCategories[index]->pFirstStock->productcode[2] = productinitial;
  107.  
  108. for (i=3;i<8;i++)
  109. aCategories[index]->pFirstStock->productcode[i] = (rand() % 9) + '0';
  110.  
  111.  
  112. for (i=0;i<=2;i++){
  113.  
  114. if (aCategories[index]->pFirstStock->productcode[i] > 'a' && aCategories[index]->pFirstStock->productcode[i] < 'z')
  115. aCategories[index]->pFirstStock->productcode[i] -= 32;
  116. }
  117.  
  118. aCategories[index]->pFirstStock->productcode[8] = '\0';
  119.  
  120.  
  121. }
  122.  
  123. /*Function search has 1 use:
  124.  
  125. 1. Check if username exists
  126.  
  127. @param i: index variable
  128. @param pRun: variable that runs through linked list
  129.  
  130. */
  131. userType* search (userType* pFirst, string15 username)
  132. {
  133. ptrUser pRun;
  134.  
  135. pRun = pFirst;
  136.  
  137. while (pRun != NULL && strcmp(username, pRun->username)!=0)
  138. pRun = pRun->pNext;
  139.  
  140. return pRun;
  141. }
  142.  
  143. /*Function searchStock has 1 use:
  144.  
  145. 1. Check if stock exists
  146.  
  147. @param i: index variable
  148.  
  149. */
  150. categoryType * searchStock (categoryType *pFirst, string15 product, aStocks *aCategories, int currCateg)
  151. {
  152. categoryType * pTemp;
  153. int i;
  154.  
  155. pTemp->pFirstStock = aCategories[i]->pFirstStock;
  156. while (strcmp(pTemp->pFirstStock->product, product) != 0 && i < currCateg){
  157.  
  158. pTemp->pFirstStock = pTemp->pFirstStock->pNext;
  159.  
  160. if (pTemp->pFirstStock == NULL){
  161.  
  162. i++;
  163. pTemp = aCategories[i];
  164. }
  165. }
  166. return pTemp;
  167.  
  168. }
  169.  
  170. /*Function searchCategory has 1 use:
  171.  
  172. 1. Check if category exists
  173.  
  174. @param i: index variable
  175. @param pRun: variable that runs through linked list
  176.  
  177. */
  178. categoryType * searchCategory (string15 category, aStocks *aCategories, int currCateg)
  179. {
  180. categoryType * pRun;
  181. int i=0;
  182.  
  183. pRun->pFirstStock = aCategories[i]->pFirstStock;
  184. while (i < currCateg && strcmp(category, pRun->category)!=0){
  185. pRun->pFirstStock = pRun->pFirstStock->pNext;
  186.  
  187. if (pRun->pFirstStock == NULL){
  188. i++;
  189. pRun = aCategories[i];
  190. }
  191. }
  192.  
  193. return pRun;
  194.  
  195. }
  196.  
  197. /*Function searchSupplier has 1 use:
  198.  
  199. 1. Check if supplier exists
  200.  
  201. @param i: index variable
  202.  
  203. */
  204. categoryType * searchSupplier (string15 supplier, aStocks *aCategories, int currCateg)
  205. {
  206. int i = 0;
  207. categoryType* pRun;
  208. pRun->pFirstStock = aCategories[i]->pFirstStock;
  209. while (i < currCateg && strcmp(supplier, aCategories[i]->pFirstStock->supplier)!=0){
  210.  
  211. pRun->pFirstStock = pRun->pFirstStock->pNext;
  212. if (pRun->pFirstStock == NULL){
  213. i++;
  214. pRun->pFirstStock = aCategories[i]->pFirstStock;
  215. }
  216. }
  217. return pRun;
  218.  
  219. }
  220.  
  221. /*Function searchProductCode has 1 use:
  222.  
  223. 1. Check if product code exists
  224.  
  225. @param pRun: variable that runs through linked list
  226. @param i: index variable
  227.  
  228. */
  229. categoryType* searchProductCode (aStocks* aCategories, string8 productcode, int currCateg)
  230. {
  231. categoryType *pRun;
  232. int i = 0;
  233.  
  234. pRun->pFirstStock = aCategories[i]->pFirstStock;
  235. while (strcmp(pRun->pFirstStock->productcode, productcode)!=0 && i < currCateg){
  236.  
  237. pRun->pFirstStock = pRun->pFirstStock->pNext;
  238. if (pRun->pFirstStock == NULL){
  239.  
  240. i++;
  241. pRun->pFirstStock = aCategories[i]->pFirstStock;
  242. }
  243. }
  244.  
  245. return pRun;
  246.  
  247. }
  248.  
  249. /*Function InUnique has 1 use:
  250.  
  251. 1. Check if username is unique
  252.  
  253. @param pRun: variable that runs through linked list
  254.  
  255. */
  256. int IsUnique (userType *pUsers, string15 username)
  257. {
  258. ptrUser pRun;
  259.  
  260. pRun = pUsers;
  261.  
  262. while (pRun != NULL && strcmp(username, pRun->username)!=0)
  263. pRun = pRun->pNext;
  264.  
  265. if (pRun == NULL)
  266. return 1;
  267. else
  268. return 0;
  269.  
  270.  
  271. }
  272.  
  273. /*Function InUniqueStock has 1 use:
  274.  
  275. 1. Check if stock is unique
  276.  
  277. @param i: index variable
  278. @param pRun: variable that runs through linked list
  279.  
  280. */
  281. int IsUniqueStock (string15 product, aStocks *aCategories, int currCateg)
  282. {
  283. int i = 0;
  284. ptrStock pRun;
  285. pRun = aCategories[i]->pFirstStock;
  286. while (i <= currCateg && strcmp (product, pRun->product)!=0){
  287. pRun = pRun->pNext;
  288. if (pRun->pNext == NULL){
  289. i++;
  290. pRun = aCategories[i]->pFirstStock;
  291. }
  292. }
  293.  
  294. if (i > currCateg)
  295. return 1;
  296. else if (strcmp (product, aCategories[i]->pFirstStock->product)==0)
  297. return 0;
  298.  
  299. }
  300. /*Function AdminSaveInventory has 1 use:
  301.  
  302. 1. Save Inventory to Text File
  303.  
  304. @param i: index variable
  305. @param pText: file pointer
  306. @param strName: Name for file to be saved to
  307. @param pRun: variable that runs through linked list
  308.  
  309. */
  310. void AdminSaveInventory (aStocks *aCategories)
  311. {
  312. FILE * pText;
  313. string20 strName;
  314. categoryType* pRun;
  315. int i;
  316.  
  317. if (aCategories[i]->pFirstStock == NULL)
  318. printf("Nothing to save \n");
  319. else {
  320. printf("Enter file name");
  321. scanf("%s", strName);
  322. pRun = aCategories[i];
  323. pText = fopen(strName, "wt");
  324. if (pText != NULL){
  325. while (pRun != NULL){
  326. fprintf(pText, "%15s %8s %15s\n", pRun->category, pRun->pFirstStock->productcode,
  327. pRun->pFirstStock->product);
  328. //fprintf: file formated printing, for printing to a secondary memory
  329. fprintf(pText, "%d %.2f %15s \n", pRun->pFirstStock->quantityavailable,
  330. pRun->pFirstStock->purchaseprice, pRun->pFirstStock->supplier);
  331. fprintf(pText, "%.2f %.2f %d \n", pRun->pFirstStock->unitsellingprice,
  332. pRun->pFirstStock->discountrate, pRun->pFirstStock->quantitysold);
  333. pRun->pFirstStock = pRun->pFirstStock->pNext;
  334.  
  335. if (pRun->pFirstStock->pNext == NULL)
  336. pRun = aCategories[i++];
  337. }
  338. fclose(pText);
  339. }
  340. else
  341. printf("Error creating file \n");
  342. }
  343.  
  344. }
  345. /*Function AdminUpdateInventory has 1 use:
  346.  
  347. 1. Load from Text File
  348.  
  349. @param i: index variable
  350. @param pText: file pointer
  351. @param strName: Name for file to be saved to
  352. @param pRun: variable that runs through linked list
  353. @param category: temporary string input for category
  354. @param product: temporary string input for product
  355. @param supplier: temporary string input for supplier
  356. @param productcode: temporary string input for product code
  357. @param qtysold: temporary integer input for quantity sold
  358. @param qtyav: temporary integer input for quantity available
  359. @param pprice: temporary float input for purchase price
  360. @param usprice: temporary float input for unit selling price
  361. @param discount: temporary float input for discount
  362. @param cDump: character variable for dump
  363. @param pNew, pFirst, pRun: variables for cycling through linked list
  364.  
  365. */
  366. void AdminUpdateInventory (string20 strFile, aStocks* aCategories, int currCateg)
  367. {
  368. FILE * pFile;
  369. string15 category, product, supplier;
  370. string8 productcode;
  371. int qtysold, qtyav, i = 0;
  372. float pprice, usprice, discount;
  373. char cDump;
  374. categoryType* pNew, *pFirst, *pRun;
  375.  
  376. if ((pFile = fopen (strFile, "rt"))!= NULL){
  377.  
  378. while(fscanf(pFile, "%s%s%s%d%f%s%f%c%f%d", category, prodcode, product, &qtyav,
  379. &pprice, supplier, &usprice, &discount, &qtysold)==10){
  380.  
  381. //printf("%s %s\n", user, pass);
  382. //pRun = aCategories[i];
  383. //while (strcmp(pRun->pFirstStock->productcode, prodcode)!=0)
  384. // pRun->pFirstStock = pRun->pFirstStock->pNext;
  385.  
  386. //creation of the linked list
  387. pNew = malloc(sizeof(categoryType));
  388. strcpy(pNew->category, category);
  389. strcpy(pNew->pFirstStock->product, product);
  390. // always insert at head of list
  391. pNew->pFirstStock->pNext = pFirst->pFirstStock;
  392. pFirst->pFirstStock = pNew->pFirstStock;
  393. }
  394. fclose(pFile);
  395. }
  396. else printf("Error opening file \n");
  397.  
  398. }
  399.  
  400. void saveToTextFile (ptrUser pFirst)
  401. {
  402. FILE * pText;
  403. string20 strName;
  404.  
  405. if (pFirst == NULL)
  406. printf("Nothing to save");
  407. else{
  408. printf("Enter file name");
  409. scanf("%s", strName);
  410.  
  411. pText = fopen(strName, "wt");
  412. //syntax: fopen(file name [string], file mode[string][r, w, a])
  413. //r: reading, w: writing, a: append (edit)
  414. //fopen returns address where new or existing text file is
  415. //if the file exists, and using "w", it will overwrite everything
  416. if (pText != NULL){
  417. while (pFirst != NULL){
  418. fprintf(pText, "%s %s\n", pFirst->username, pFirst->password);
  419. //fprintf: file formated printing, for printing to a secondary memory
  420. pFirst = pFirst->pNext;
  421. }
  422. fclose(pText);
  423. }
  424. else
  425. printf("Error creating file \n");
  426.  
  427. }
  428.  
  429. }
  430.  
  431. void loadFromText (string20 strFile, ptrUser * pFirst)
  432. {
  433. FILE * pFile;
  434. string20 user, pass;
  435. ptrUser pNew;
  436.  
  437. if ((pFile = fopen (strFile, "rt"))!= NULL){
  438.  
  439. while(fscanf(pFile, "%s %s", user, pass)==2){
  440.  
  441. //fscanf(pFile, "%s%s", user, pass);
  442. printf("%s %s\n", user, pass);
  443.  
  444. //creation of the linked list
  445. pNew = malloc(sizeof(userType));
  446. strcpy(pNew->username, user);
  447. strcpy(pNew->password, pass);
  448. // always insert at head of list
  449. pNew->pNext = *pFirst;
  450. *pFirst = pNew;
  451. }
  452. fclose(pFile);
  453. }
  454. else printf("Error opening file \n");
  455.  
  456. }
  457.  
  458. /*Function AddStock has 1 use:
  459. 1. Add Stock
  460.  
  461. @param i: index variable
  462. @param strikes: determines whether the added stock exists
  463. @param exit: character variable that determines if do while loop will end
  464. @param cDump: character variable that holds dump
  465. @param tempinteger: temporary integer to be copied to stocks structure
  466. @param tempfloat: temporary float value to be copied to stocks structure
  467. @param comparecode, comparecategory, comparesupplier: temporary strings to be
  468. used to compare with existing
  469. */
  470. void AddStock (categoryType *pNewStock, categoryType *pStock, aStocks *aCategories, int currCateg)
  471. {
  472. int exit = 1, strikes = 0, tempinteger = 0, i=0;
  473. float tempfloat = 0;
  474. char cDump;
  475. string15 tempcategory, tempsupplier, tempproduct;
  476.  
  477. do {
  478.  
  479. printf("Input the Category: ");
  480. //fgets(tempcategory,16,stdin);
  481. fgets(tempcategory,16,stdin);
  482.  
  483. if (aCategories[currCateg] != NULL)
  484. if (searchCategory (tempcategory, aCategories, currCateg) != NULL)
  485. strikes++;
  486.  
  487. strcpy (aCategories[currCateg]->category, tempcategory);
  488.  
  489. printf("Input the Supplier: ");
  490. scanf("%s%c", tempsupplier, &cDump);
  491.  
  492. if (searchSupplier(aCategories[currCateg]->pFirstStock->supplier, aCategories, currCateg)!=NULL)
  493. strikes++;
  494.  
  495. strcpy (aCategories[currCateg]->pFirstStock->supplier, tempsupplier);
  496.  
  497. printf("Input the Product Name: ");
  498. scanf("%s%c", tempproduct, &cDump);
  499.  
  500. if (IsUniqueStock(aCategories[currCateg]->pFirstStock->product, aCategories, currCateg)==0)
  501. strikes++;
  502.  
  503. strcpy (aCategories[currCateg]->pFirstStock->product, tempproduct);
  504.  
  505. if (strikes > 4){
  506. printf("This product already exists. \n Use the Modify, Restock or Add New Stock with a different name \n");
  507. exit = 1;
  508. }
  509.  
  510. printf("Input the Quantity Available for this product: ");
  511. scanf("%d%c", &tempinteger, &cDump);
  512. aCategories[currCateg]->pFirstStock->quantityavailable = tempinteger;
  513. printf("Input the Purchase Price for this product: ");
  514. scanf("%f%c", &tempfloat, &cDump);
  515. aCategories[currCateg]->pFirstStock->quantityavailable = tempfloat;
  516. printf("Input the Unit Selling Price for this product: ");
  517. scanf("%f%c", &tempfloat, &cDump);
  518. aCategories[currCateg]->pFirstStock->quantityavailable = tempfloat;
  519. printf("Input the Discount Rate for this product: ");
  520. scanf("%f%c", &tempfloat, &cDump);
  521. aCategories[currCateg]->pFirstStock->quantityavailable = tempfloat;
  522. aCategories[currCateg]->pFirstStock->quantitysold = 0;
  523. prodcode (pNewStock, aCategories, currCateg);
  524. printf("Product Code of this Item: %s \n", aCategories[currCateg]->pFirstStock->productcode);
  525.  
  526. currCateg++;
  527.  
  528. printf("Press [1] to add new stock or [0] to return to manage stocks menu: ");
  529. scanf("%d%c", &exit, &cDump);
  530.  
  531. if(exit>1||exit<0)
  532. {
  533. printf("Invalid input. Returning to manage stocks menu");
  534. exit = 1;
  535. }
  536.  
  537.  
  538. }while(exit == 1);
  539.  
  540. }
  541.  
  542. /*Function AdminModifyStockMenu has 8 uses:
  543. 1. Modify Category
  544. 2. Modify Supplier
  545. 3. Modify Product
  546. 4. Modify Purchase Price
  547. 5. Modify Selling Price
  548. 6. Modify Discount
  549. 7. Finish Modifications of Product
  550. 8. Return to Administrator Menu
  551.  
  552. @param i: index variable
  553. @param exit: character variable that determines if do while loop will end
  554. @param cDump: character variable that holds dump
  555. @param comparecode, comparecategory, comparesupplier: temporary strings to be
  556. used to compare with existing
  557. */
  558. void AdminModifyStockMenu (categoryType *pStock, aStocks *aCategories, int currCateg)
  559. {
  560. int choice, exit, i=0;
  561. char cDump;
  562. string8 comparecode, comparecategory, comparesupplier;
  563.  
  564. ptrStock pRun;
  565.  
  566. do {
  567.  
  568. printf("Input product code of product to be modified \n");
  569. printf("Input: "); scanf("%s%c", comparecode, &cDump);
  570.  
  571.  
  572. while (strcmp(aCategories[i]->pFirstStock->productcode, comparecode)!=0 && i<currCateg)
  573. i++;
  574.  
  575. if (i>currCateg){
  576. printf("Product Code not found, please try again. \n");
  577. AdminModifyStockMenu (pStock, aCategories, currCateg);
  578. }
  579.  
  580.  
  581. printf("MODIFY STOCK INFO \n");
  582. printf("Product code: %s \n", aCategories[i]->pFirstStock->productcode);
  583. printf("[1] Modify Category \n");
  584. printf("[2] Modify Supplier \n");
  585. printf("[3] Modify Product \n");
  586. printf("[4] Modify Purchase Price \n");
  587. printf("[5] Modify Selling Price \n");
  588. printf("[6] Modify Discount \n");
  589. printf("[7] Finish Modifications of Product %s \n", aCategories[i]->pFirstStock->productcode);
  590. printf("[0] Return to Administrator Menu");
  591. printf("Input: ");
  592. scanf("%d%c", &choice, &cDump);
  593.  
  594. switch (choice){
  595. case 1: do{
  596.  
  597. printf("Input new category for this product: ");
  598. scanf("%s%c", comparecategory, &cDump);
  599.  
  600. if (searchCategory (comparecategory, aCategories, currCateg)== NULL){
  601. printf("Category not found. Creating a new one. \n");
  602. strcpy(aCategories[i]->category, comparecategory);
  603. printf("New category for this product is %s.\n", aCategories[i]->category);
  604. }
  605. printf("Modified category for this product is %s. \n", aCategories[i]->category);
  606. printf("[1] Modify Category \n");
  607. printf("[0] Return to Modify Stocks Info Menu \n");
  608. printf("Input: ");
  609. scanf("%d%c", &exit, &cDump);
  610.  
  611. if(exit>1||exit<0)
  612. {
  613. printf("Invalid input! returning you to main menu");
  614. exit = 0;
  615.  
  616. }
  617.  
  618. }while(exit==1);
  619.  
  620. break;
  621. case 2: do {
  622.  
  623. printf("Input new supplier for this product: ");
  624. scanf("%s%c", comparesupplier, &cDump);
  625.  
  626. if (searchSupplier (comparesupplier, aCategories, currCateg)==NULL){
  627. printf("Supplier not found. Creating a new one. \n");
  628. strcpy(aCategories[i]->pFirstStock->supplier, comparesupplier);
  629. printf("New supplier for this product is %s.\n", aCategories[i]->pFirstStock->supplier);
  630. }
  631. printf("Modified supplier for this product is %s. \n", aCategories[i]->pFirstStock->supplier);
  632. printf("[1] Modify Supplier \n");
  633. printf("[0] Return to Modify Stocks Info Menu: \n");
  634. printf("Input: ");
  635. scanf("%d%c", &exit, &cDump);
  636.  
  637.  
  638. if(exit>1||exit<0)
  639. {
  640. printf("Invalid input! returning you to main menu");
  641. exit = 0;
  642.  
  643. }
  644.  
  645. }while (exit== 1);
  646.  
  647. break;
  648. case 3: do {
  649.  
  650. printf("Input new product name for this item: ");
  651. scanf("%s%c", comparesupplier, &cDump);
  652.  
  653.  
  654. printf("Modified product name for this product is %s. \n", aCategories[i]->pFirstStock->product);
  655. printf("[1] Modify Product Name \n");
  656. printf("[0] Return to Modify Stocks Info Menu \n");
  657. printf("Input: ");
  658. scanf("%d%c", &exit, &cDump);
  659.  
  660.  
  661.  
  662. if(exit>1||exit<0)
  663. {
  664. printf("Invalid input! returning you to main menu");
  665. exit = 0;
  666.  
  667. }
  668.  
  669. }while (exit==1);
  670.  
  671. break;
  672. case 4: do {
  673.  
  674. printf("Input new purchase price for product: ");
  675. scanf("%f%c", &aCategories[i]->pFirstStock->purchaseprice, &cDump);
  676. printf("New purchase price: %.2f \n", pStock->pFirstStock->purchaseprice);
  677. printf("[1] Modify Purchase Price \n");
  678. printf("[0] Return to Modify Stocks Info Menu \n");
  679. printf("Input: ");
  680. scanf("%d%c", &exit, &cDump);
  681.  
  682. if(exit>1||exit<0)
  683. {
  684. printf("Invalid input! returning you to main menu");
  685. exit = 0;
  686.  
  687. }
  688.  
  689. }while (exit == 1);
  690.  
  691. break;
  692. case 5: do {
  693.  
  694. printf("Input new selling price: ");
  695. scanf("%f%c", aCategories[i]->pFirstStock->unitsellingprice, &cDump);
  696. printf("New selling price: %.2f \n", aCategories[i]->pFirstStock->unitsellingprice);
  697. printf("[1] Modify Selling Price \n");
  698. printf("[0] Return to Modify Stocks Info Menu \n");
  699. printf("Input: ");
  700. scanf("%d%c", &exit, &cDump);
  701.  
  702. if(exit>1||exit<0)
  703. {
  704. printf("Invalid input! returning you to main menu");
  705. exit = 0;
  706.  
  707. }
  708.  
  709. }while (exit==1);
  710.  
  711. break;
  712. case 6: do {
  713.  
  714. printf("Input new discount: ");
  715. scanf("%f%c", aCategories[i]->pFirstStock->discountrate, &cDump);
  716. printf("New discount for this product: %f % ", aCategories[i]->pFirstStock->discountrate);
  717. printf("[1] Modify Selling Price \n");
  718. printf("[0] Return to Modify Stocks Info Menu \n");
  719. printf("Input: ");
  720. scanf("%d%c", &exit, &cDump);
  721.  
  722. if(exit>1||exit<0)
  723. {
  724. printf("Invalid input! returning you to main menu");
  725. exit = 0;
  726.  
  727. }
  728.  
  729. }while (exit==1);
  730.  
  731. break;
  732. case 7: do {
  733. printf("Finishing Modification of Product.. \n");
  734. prodcode (pStock, aCategories, i);
  735. printf("Press [0] return to main menu");
  736. scanf("%d", &exit);
  737.  
  738. if(exit>1||exit<0)
  739. {
  740. printf("Invalid input! returning you to main menu");
  741. exit = 0;
  742.  
  743. }
  744.  
  745. }while (exit==1);
  746.  
  747. break;
  748. default:
  749. break;
  750. }
  751.  
  752. }while(choice > 0 && choice < 8 );
  753.  
  754. }
  755.  
  756. /*Function AdminPrepareDelivery has 1 use:
  757. 1. Prepare Delivery Receipt
  758.  
  759. @param i: index variable
  760. @param index: another index variable
  761. @param fileindex: another index variable for file pointer
  762. @param compareindex: index to be compared
  763. @param exit: character variable that determines if do while loop will end
  764. @param cDump: character variable that holds dump
  765. @param itemsubtotal: holds item subtotal for display
  766. @param totalprice: calculated by quantity * item price
  767. @param totaldiscount: total discounted amount
  768. @param billamout: total amount to be paid
  769. @param page: variable that controls how many entries appear
  770. @param pRun, pTrail, pTemp: variables that run through the linked list
  771. @param pRunFile: for file saving
  772. @param pText: file pointer
  773. @param strname: name of file
  774. @param foundproduct: name of product given product code
  775. */
  776. void AdminPrepareDelivery (userType *pUsers, userInfoType *pInfo, aStocks *aCategories)
  777. {
  778. int i = 0, index = 0, fileindex = 0, compareindex = 0;
  779. char exit, cDump;
  780. float itemsubtotal, totalprice, totaldiscount, billamount;
  781. ptrStock pRun, pTrail, pTemp;
  782. ptrUser pBought;
  783. categoryType * pRunFile;
  784. FILE * pText;
  785. string20 strName;
  786. string15 foundproduct;
  787.  
  788. do {
  789. if (pTrail == NULL)
  790. pRun = aCategories[index]->pFirstStock;
  791. if (pRun != NULL){
  792.  
  793. printf("User ID: %s \n", pUsers->username);
  794. printf("Customer Name: %s, %s, %s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  795. printf("Delivery Address: %s \n", (*pInfo).address);
  796. printf("Product Code Product Quantity Unit Price Total Price Discount Rate Item Subtotal \n");
  797.  
  798. pTemp = aCategories[index]->pFirstStock;
  799. while (strcmp (pUsers->cart[compareindex].code, pTemp->productcode)!=0){
  800.  
  801. if (strcmp (pUsers->cart[compareindex].code, pTemp->productcode)==0)
  802. strcpy (foundproduct, pTemp->product);
  803. pTemp = pTemp -> pNext;
  804. compareindex++;
  805. }
  806.  
  807. while (i <= pUsers->nItems && pRun->pNext != NULL){
  808.  
  809. totalprice = (pUsers->cart[i].qty)*(pRun->unitsellingprice);
  810. itemsubtotal = ((pRun->unitsellingprice) - (pRun->discountrate/100)) * (pUsers->cart[i].qty);
  811. totaldiscount += pRun->unitsellingprice - (pRun->unitsellingprice * (pRun->discountrate/100));
  812. billamount += itemsubtotal;
  813.  
  814. printf("%15s %15s %d %.2f %.2f %.2f %.2f \n", pUsers->cart[i].code, pRun->product, pUsers->cart[i].qty, pRun->unitsellingprice,totalprice, pRun->discountrate, itemsubtotal);
  815. i++;
  816. pRun = pRun->pNext;
  817. if (pRun->pNext == NULL){
  818.  
  819. index++;
  820. pRun = aCategories[index]->pFirstStock;
  821. }
  822. }
  823.  
  824. i = 0;
  825.  
  826. printf("Number of Items: %d \n", pUsers->nItems);
  827. printf("Total Discount: Php %d \n", totaldiscount);
  828. printf("Bill Amount: Php %.2f \n", billamount);
  829. printf("Total Outstanding: Php %.2f \n", pUsers->outstanding + billamount);
  830.  
  831. pTrail = pRun;
  832.  
  833. printf("Enter file name to save to");
  834. scanf("%s", strName);
  835. pRunFile = aCategories[fileindex];
  836. pText = fopen(strName, "wt");
  837. if (pText != NULL){
  838. while (pRunFile != NULL){
  839. fprintf(pText, "%15s %d \n", pUsers->username, pUsers->nItems);
  840. //fprintf: file formated printing, for printing to a secondary memory
  841. fprintf(pText, "%d %f %s \n", pUsers->cart[fileindex].qty, pUsers->cart[fileindex].code, pRun->supplier);
  842. fprintf(pText, "%f %f %d \n", pRun->unitsellingprice, pRun->discountrate, pRun->quantitysold);
  843. pRun = pRun->pNext;
  844. }
  845. fclose(pText);
  846. }
  847. else
  848. printf("Error creating file \n");
  849.  
  850.  
  851. printf("[B] Previous User \n");
  852. printf("[N] Next User \n");
  853. printf("[X] Return to Manage Stocks Menu \n");
  854. printf("Input: "); scanf("%c%c", &exit, &cDump);
  855.  
  856.  
  857. if (exit == 'b' || exit == 'B'){
  858. pRun = pTrail;
  859. if (pTrail == NULL)
  860. printf("No previous user. \n");
  861. }
  862.  
  863. if (exit == 'n' || exit == 'N'){
  864. pRun = pRun->pNext;
  865.  
  866. }
  867.  
  868. if (exit == 'x' || exit == 'X')
  869. printf("Exit function");
  870.  
  871. }
  872.  
  873. }while (exit == 'B' || exit == 'b'|| exit == 'n' || exit == 'N' && (exit != 'x' || exit != 'X'));
  874.  
  875.  
  876. }
  877. /*Function viewAllStocks has 1 use:
  878. 1. View all stocks
  879.  
  880. @param page: variable that controls how many entries appear
  881. @param pRun: variable that runs through the linked list
  882. */
  883. void viewAllStocks (categoryType *pStock, aStocks *aCategories, int currCateg)
  884. {
  885. categoryType *pRun;
  886. int page = 0;
  887.  
  888. printf("Viewing All Stocks \n");
  889. pRun = pStock;
  890. printf("Category Supplier Product Qty Available Purchase Price Selling Price Qty Sold Product Code \n");
  891. while (pRun != NULL && page < 20){
  892.  
  893. printf("%s %s %s %d %f %f %d %s \n",
  894. pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product, pRun->pFirstStock->quantityavailable, pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold, pRun->pFirstStock->productcode);
  895. pRun->pFirstStock = pRun->pFirstStock->pNext;
  896. page++;
  897. }
  898. page = 0;
  899. }
  900. /*Function viewByCategory has 1 use:
  901. 1. View stocks by category
  902.  
  903. @param TempCategory: string that temporary holds input category
  904. @param index: index variable
  905. @param choice: character variable which determines if the function ends or goes to next page
  906. @param cDump: character variable to serve as dump
  907. @param pRun: variable that runs through the linked list
  908. */
  909. void viewByCategory (categoryType *pStock, aStocks *aCategories, int currCateg)
  910. {
  911. string15 TempCategory;
  912. categoryType *pRun;
  913. char cDump;
  914. int index, page = 0;
  915.  
  916. printf("Input the category");
  917. printf("Input: ");scanf("%s%c",TempCategory, &cDump);
  918.  
  919. if (searchCategory (TempCategory, aCategories, currCateg)== NULL)
  920. printf("Category not found \n");
  921. else if (searchCategory (TempCategory, aCategories, currCateg)!= NULL){
  922. pRun = searchCategory(TempCategory, aCategories, currCateg);
  923. printf("Viewing Stocks by Category \n");
  924. printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
  925. while (pRun->pFirstStock != NULL){
  926.  
  927. printf("%15s %15s %15s %d %.2f %.2f %d %15s \n",
  928. pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product,pRun->pFirstStock->quantityavailable,
  929. pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold,
  930. pRun->pFirstStock->productcode);
  931. pRun->pFirstStock = pRun->pFirstStock->pNext;
  932.  
  933. }
  934. }
  935. }
  936. /*Function viewStockReorder has 1 use:
  937. 1. View stocks that have quantity = 0
  938.  
  939. @param page: variable that limits number of displayed entries
  940. @param i: index variable
  941. @param choice: character variable which determines if the function ends or goes to next page
  942. @param cDump: character variable to serve as dump
  943. @param pRun: variable that runs through the linked list
  944. */
  945. void viewStockReorder (categoryType* pStock, aStocks *aCategories, int currCateg)
  946. {
  947. int page = 0, i = 0;
  948. char choice = '\0', cDump;
  949. categoryType *pRun;
  950. printf("Viewing Stocks to Reorder \n");
  951. pRun = aCategories[i];
  952.  
  953. while (choice == '\0'){
  954.  
  955. while (pRun->pFirstStock != NULL && pRun->pFirstStock->quantityavailable == 0 && page <= 20){
  956.  
  957. printf("%15s %15s %15s %d %.2f %.2f %d %s",
  958. pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product, pRun->pFirstStock->quantityavailable,
  959. pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold, pRun->pFirstStock->productcode);
  960. pRun->pFirstStock = pRun->pFirstStock->pNext;
  961. page++;
  962. if (pRun->pFirstStock->pNext == NULL)
  963. pRun = aCategories[i++];
  964.  
  965. }
  966. printf("Press ENTER for next page or 0 to exit: ");
  967. scanf("%c%c", &choice, &cDump);
  968. }
  969. }
  970. /*Function restock has 1 use:
  971. 1. Restock product given a product code
  972.  
  973. @param addqty: quantity to add
  974. @param cDump: character variable to serve as dump
  975. @param TempProdCode: product code inputted to be compared
  976. @param pRun: variable that runs through the linked list
  977. */
  978. void restock (categoryType *pStock, aStocks *aCategories, int currCateg)
  979. {
  980. int addqty = 0;
  981. char cDump;
  982. categoryType *pRun;
  983. string8 TempProdCode;
  984.  
  985. printf("Restock \n");
  986. pRun = pStock;
  987. printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
  988. while (pRun != NULL){
  989. printf("%s %s %s %d %f %f %d %s",
  990. pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product, pRun->pFirstStock->quantityavailable, pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold, pRun->pFirstStock->productcode);
  991. pRun->pFirstStock = pRun->pFirstStock->pNext;
  992. }
  993. printf("Input the product code of the product that will be restocked: ");
  994. scanf("%s%c",TempProdCode, &cDump);
  995. pRun = pStock;
  996. while (pRun != NULL && strcmp(TempProdCode, pRun->pFirstStock->productcode)!=0){
  997. pRun->pFirstStock = pRun->pFirstStock->pNext;
  998. if (pRun == NULL){
  999. printf("Last input product code not found. Not restocked. Returning to Manage Stocks Menu \n");
  1000.  
  1001. }
  1002. if (pRun != NULL && strcmp(TempProdCode, pRun->pFirstStock->productcode)==0){
  1003. printf("Additional Quantity for this item: ");
  1004. scanf("%d%c", &addqty, &cDump);
  1005. pRun->pFirstStock->quantityavailable += addqty;
  1006. printf("This product has been restocked and has %d quantity available. \n", pRun->pFirstStock->quantityavailable);
  1007. }
  1008. }
  1009. }
  1010. /*Function AdminManageStocks has 8 uses:
  1011. 1. Add New Stock
  1012. 2. View All Stocks
  1013. 3. View Stocks by Category
  1014. 4. View Stocks to Reorder
  1015. 5. Modify Stock Info
  1016. 6. Restock
  1017. 7. Update Inventory from File
  1018. 8. Return to Administrator Menu
  1019.  
  1020. @param choice: variable for switch statement to navigate through menu
  1021. @param exit: variable to exit menu choice
  1022. @param page: variable that controls how many entries appear
  1023. @param cExit: like exit, but is a character
  1024. @param pRun: variable that runs through the linked list
  1025. */
  1026. void AdminManageStocks (userType *pUsers, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd, aStocks *aCategories, int currCateg)
  1027. {
  1028. int choice, exit, page = 0;
  1029. char cDump, cExit = '\0';
  1030. categoryType* pRun;
  1031. string20 strFile;
  1032.  
  1033. pStock = NULL;
  1034. pNewStock = NULL;
  1035. pEnd = NULL;
  1036.  
  1037. do {
  1038.  
  1039. printf("MANAGE STOCKS MENU \n");
  1040. printf("[1] Add New Stock \n");
  1041. printf("[2] View All Stocks \n");
  1042. printf("[3] View Stocks by Category \n");
  1043. printf("[4] View Stocks to Reorder \n");
  1044. printf("[5] Modify Stock Info \n");
  1045. printf("[6] Restock \n");
  1046. printf("[7] Save Inventory \n");
  1047. printf("[8] Update Inventory from File \n");
  1048. printf("[0] Return to Administrator Menu \n");
  1049. printf("Input: ");
  1050. scanf("%d%c", &choice, &cDump);
  1051.  
  1052. switch (choice){
  1053. case 1: do{
  1054. aCategories[currCateg]->pFirstStock = malloc(sizeof(categoryType));
  1055.  
  1056. AddStock(pNewStock, pStock, aCategories, currCateg);
  1057.  
  1058. aCategories[currCateg]->pFirstStock->pNext = NULL;
  1059.  
  1060. if (pStock == NULL) //if initially empty
  1061. pStock = pNewStock; //pNew is the first node
  1062.  
  1063. else //connect nodes to the list
  1064. pEnd->pFirstStock->pNext = pNewStock->pFirstStock;
  1065.  
  1066. pEnd = pNewStock;
  1067.  
  1068.  
  1069. }while(exit==0);
  1070.  
  1071. break;
  1072. case 2: do {
  1073.  
  1074. viewAllStocks (pStock, aCategories, currCateg);
  1075. printf("Press [N] return to main menu or ENTER to view next page. \n");
  1076. scanf("%c%c", &cExit, &cDump);
  1077. }while (cExit=='\0');
  1078.  
  1079. break;
  1080. case 3: do {
  1081.  
  1082. viewByCategory (pStock, aCategories, currCateg);
  1083. printf("Press [0] return to main menu");
  1084. scanf("%d%c", &exit, &cDump);
  1085. }while (exit==1);
  1086.  
  1087. break;
  1088. case 4: do {
  1089.  
  1090. viewStockReorder (pStock, aCategories, currCateg);
  1091. printf("Press [N] return to main menu or ENTER to view next page. \n");
  1092. scanf("%c%c", &cExit, &cDump);
  1093. }while (cExit=='\0');
  1094.  
  1095. break;
  1096. case 5: do {
  1097.  
  1098. viewAllStocks(pStock, aCategories, currCateg);
  1099. printf("Modify Stock Info \n");
  1100. AdminModifyStockMenu(pStock, aCategories, currCateg);
  1101. printf("Press [0] return to main menu");
  1102. scanf("%d%c", &exit, &cDump);
  1103. }while (exit==1);
  1104.  
  1105. break;
  1106. case 6: do {
  1107.  
  1108. restock(pStock, aCategories, currCateg);
  1109. printf("Press [0] return to main menu");
  1110. scanf("%d%c", &exit, &cDump);
  1111. }while (exit==1);
  1112.  
  1113. break;
  1114. case 7: do {
  1115. AdminSaveInventory (aCategories);
  1116. printf("Press [0] return to main menu");
  1117. scanf("%d", &exit);
  1118. }while (exit==1);
  1119.  
  1120. break;
  1121. case 8: do {
  1122. printf("Input filename: ");
  1123. scanf("%s%c", strFile, &cDump);
  1124. AdminUpdateInventory (strFile, aCategories, currCateg);
  1125. }while (exit == 1);
  1126. default: choice = 0;
  1127. break;
  1128. }
  1129.  
  1130. }while(choice > 0 && choice < 9 );
  1131.  
  1132.  
  1133. }
  1134.  
  1135. /*Function AdminManageAccounts has 5 uses:
  1136. 1. View Locked Accounts
  1137. 2. Unlock a specific account given the username
  1138. 3. Unlock all accounts that have the nLocked
  1139. 4. View accounts with outstanding balance
  1140. 5. Return to Administrator Menu
  1141.  
  1142. @param choice: variable for switch statement to navigate through menu
  1143. @param exit: variable to exit menu choice
  1144. @param yesorno: confirmation for unlock all locked accounts
  1145. @param CompareUser: variable that takes user input username, to be compared to existing
  1146. @param pLock: variable that holds the value of search
  1147. @param cDump: character variable for dump
  1148.  
  1149. */
  1150. void AdminManageAccounts (userType *pUsers, userInfoType *pInfo)
  1151. {
  1152. int choice = 0, exit;
  1153. char cDump, yesorno;
  1154. string15 CompareUser;
  1155. userType *pLock;
  1156. ptrUser pRun;
  1157.  
  1158. pRun = pUsers;
  1159.  
  1160. do {
  1161.  
  1162. printf("Welcome, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1163. printf("MANAGE ACCOUNTS MENU \n");
  1164. printf("[1] View Locked Accounts \n");
  1165. printf("[2] Unlock Specific Account \n");
  1166. printf("[3] Unlock All Locked Accounts \n");
  1167. printf("[4] View Accounts with Outstanding Balance \n");
  1168. printf("[0] Return to Administrator Menu \n");
  1169. printf("Input: ");
  1170. scanf("%d%c", &choice, &cDump);
  1171.  
  1172. switch (choice) {
  1173.  
  1174. case 1: do {
  1175.  
  1176. while (pRun != NULL && pRun->nLocked == 1){
  1177. pRun = pRun->pNext;
  1178. printf("Username: %s \n", pRun->username);
  1179. printf("Name: %s, %s ,%s",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1180. if (pRun->username == NULL)
  1181. printf("No account is locked. \n");
  1182. }
  1183.  
  1184. printf("[0] Return to Manage Accounts Menu \n");
  1185. printf("[1] View All Locked Accounts \n");
  1186. printf("Input: ");scanf("%d", &exit);
  1187.  
  1188. if(exit>1||exit<0)
  1189. {
  1190. printf("Invalid input. Returning to Manage Accounts Menu \n");
  1191. exit = 1;
  1192. }
  1193.  
  1194. } while(exit == 1);
  1195.  
  1196. pRun = NULL;
  1197.  
  1198.  
  1199. break;
  1200.  
  1201. case 2: do {
  1202.  
  1203. printf("Input username of locked account. \n");
  1204. printf("Input: ");scanf("%s%c", CompareUser, &cDump);
  1205.  
  1206. pLock = search (pUsers, CompareUser);
  1207.  
  1208. if (pLock != NULL)
  1209. pLock->nLocked = 0;
  1210.  
  1211.  
  1212. printf("[0] Return to Manage Accounts Menu \n");
  1213. printf("[1] Unlock Another Account\n");
  1214. printf("Input: ");scanf("%d", &exit);
  1215.  
  1216. if(exit>1||exit<0)
  1217. {
  1218. printf("Invalid input. Returning to Manage Accounts Menu \n");
  1219. exit = 1;
  1220. }
  1221.  
  1222. } while(exit == 1);
  1223.  
  1224. break;
  1225.  
  1226. case 3: do {
  1227.  
  1228. printf("Would you like to unlock all locked accounts? [Y]es | [N]o \n");
  1229. scanf("%c%c",&yesorno, &cDump);
  1230.  
  1231. if (yesorno == 'y' || yesorno == 'Y'){
  1232. while (pRun != NULL ){
  1233. if (pRun->nLocked == 1)
  1234. pRun->nLocked = 0;
  1235.  
  1236. pRun = pRun->pNext;
  1237. }
  1238. }
  1239.  
  1240. printf("[0] Return to Manage Accounts Menu \n");
  1241. printf("Input: ");scanf("%d%c", &exit, &cDump);
  1242.  
  1243. if(exit>1||exit<0)
  1244. {
  1245. printf("Invalid input. Returning to Manage Accounts Menu \n");
  1246. exit = 1;
  1247. }
  1248.  
  1249. } while(exit == 1);
  1250.  
  1251. break;
  1252. case 4: do {
  1253.  
  1254. printf("Diplaying Accounts with Outstanding Balance \n");
  1255. while (pRun != NULL){
  1256. if (pRun->outstanding>0){
  1257.  
  1258. printf("%s \n", pRun->username);
  1259. printf("%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1260. printf("%f \n", pRun->outstanding);
  1261. }
  1262. }
  1263.  
  1264. printf("[0] Return to Manage Accounts Menu \n");
  1265. printf("Input: ");scanf("%d", &exit);
  1266.  
  1267. if(exit>1||exit<0)
  1268. {
  1269. printf("Invalid input. Returning to Manage Accounts Menu \n");
  1270. exit = 1;
  1271. }
  1272.  
  1273. }while (exit == 1);
  1274. break;
  1275. default: printf("Returning to Administrator Menu.. \n");
  1276. break;
  1277. }
  1278.  
  1279. } while (choice > 0 && choice < 5);
  1280.  
  1281. }
  1282.  
  1283.  
  1284.  
  1285. /*Function signUp has 1 use:
  1286. 1. Allows user to create an account, either admin or shopper
  1287.  
  1288. @param unique: integer variable determines if username is unique
  1289. @param exit: variable to exit menu choice
  1290. @param cTempType: variable that hold user inputted user type
  1291. @param TempUsername: variable that takes user input username, to be pass to IsUnique
  1292. @param arrInputCode: variable that holds user input code
  1293. @param cDump: character variable for dump
  1294. @param arrCompareCode: temporary string that holds authorization code
  1295.  
  1296. */
  1297. void signUp (userType *pUser, userType *pUsers)
  1298. {
  1299. int unique = 0;
  1300. char cDump, cTempType = '\0';
  1301. char arrInputCode[9];
  1302. char arrCompareCode[9] = {'D','L','S','U','2','0','1','7'};
  1303. string15 TempUsername;
  1304.  
  1305.  
  1306. do{
  1307. printf("Enter username: ");
  1308. scanf("%s%c", (*pUser).username /*TempUsername*/,&cDump); //placing the information directly within the container. Username is inside pUser
  1309.  
  1310. if (IsUnique (pUsers, pUser->username) == 0){
  1311. printf("Username taken, please input a unique username. \n");
  1312. unique = 0;
  1313. }
  1314.  
  1315. else if (IsUnique (pUsers, pUser->username) == 1){
  1316.  
  1317. unique = 1;
  1318. printf("Username is unique, proceeding. \n");
  1319. }
  1320.  
  1321. }while (strlen((*pUser).username)<3 || strlen((*pUser).username)>15 || unique != 1);
  1322.  
  1323. do{
  1324. printf("Enter password: ");
  1325. scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
  1326. if (strlen((*pUser).password)<6){
  1327.  
  1328. printf("Password too short, please try again. \n");
  1329. printf("Enter password: ");
  1330. scanf("%s%c", (*pUser).password,&cDump);
  1331. }
  1332. if (strlen((*pUser).password)>15){
  1333.  
  1334. printf("Password too long, please try again. \n");
  1335. printf("Enter password: ");
  1336. scanf("%s%c", (*pUser).password,&cDump);
  1337. }
  1338.  
  1339. if (ValidPass(pUser)==1)
  1340. printf("Password is valid. \n");
  1341. else{
  1342. printf("Error, password must contain non-letter character.\n");
  1343. printf("Enter password: ");
  1344. scanf("%s%c", (*pUser).password,&cDump);
  1345. }
  1346.  
  1347.  
  1348. }while (strlen((*pUser).password)<6 || strlen((*pUser).password)>15);
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354. printf("Create [S]hopper or [A]dministrator account? \n");
  1355. printf("Input: ");
  1356. scanf("%c%c", &cTempType, &cDump);
  1357.  
  1358. if(cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
  1359. printf("Invalid input, please try again: \n");
  1360. while (cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
  1361. printf("Input: ");
  1362. scanf("%c%c",&cTempType, &cDump);
  1363. }
  1364. }
  1365.  
  1366.  
  1367. if (cTempType == 's' || cTempType == 'S'){
  1368.  
  1369. (*pUser).type = 'S';
  1370. printf("Account Type: Shopper \n");
  1371. (*pUser).creditlimit = 5000.00;
  1372. printf("Your current Credit Limit is Php 5000.00. \n");
  1373. (*pUser).outstanding = 0.00;
  1374. printf("Your current Outstanding Balance is Php 0.00. \n");
  1375.  
  1376. }
  1377.  
  1378. else if (cTempType == 'a' || cTempType == 'A'){
  1379.  
  1380.  
  1381. do {
  1382. printf("Input authorization code: ");
  1383. scanf("%s%c", arrInputCode,&cDump);
  1384.  
  1385. if (strcmp(arrInputCode,arrCompareCode)==0){
  1386.  
  1387. (*pUser).type = 'A';
  1388. //AdminChoice();
  1389. printf("Account Type: Admin \n");
  1390.  
  1391. }
  1392.  
  1393. else
  1394. printf("Invalid authorization code, try again. Please try again. \n");
  1395.  
  1396.  
  1397.  
  1398. }while (strcmp(arrInputCode,arrCompareCode)!=0);
  1399.  
  1400. }
  1401. }
  1402.  
  1403. /*Function modifyUserInfo has 4 uses:
  1404. 1. Allows user to edit their first name, middle name or last name
  1405. 2. Allows user to change their address
  1406. 3. Allows user to change their password
  1407. 4. Return to Shopper Menu
  1408.  
  1409. @param choice: variable to naviage through menu
  1410. @param exit: variable to exit menu choice
  1411. @param nChoice: variable to control
  1412. @param cDump: character variable for dump
  1413. @param arrComparepass: temporary string to compare input password with user's password
  1414.  
  1415. */
  1416. void modifyUserInfo (userType *pUser, userInfoType *pInfo)
  1417. {
  1418. int choice = 0, exit = 0, nChoice = 0;
  1419. char cDump;
  1420. char arrComparePass[16];
  1421.  
  1422. do {
  1423.  
  1424. printf("Hello, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1425. printf("What would you like to change? \n");
  1426. printf("[1] Change Name \n");
  1427. printf("[2] Change Address \n");
  1428. printf("[3] Change Password \n");
  1429. printf("[0] Return to Shopper Menu \n");
  1430. printf("Input: ");
  1431. scanf("%d%c", &choice, &cDump);
  1432.  
  1433. switch (choice) {
  1434.  
  1435. case 1: do {
  1436.  
  1437.  
  1438. while (nChoice > 3 || nChoice < 0){
  1439. printf("What would you like to change \n?");
  1440. printf("[1] First \n");
  1441. printf("[2] Middle \n");
  1442. printf("[3] Last \n");
  1443. printf("Input: "); scanf("%d", &nChoice);
  1444. if (nChoice < 0 || nChoice > 3)
  1445. printf("Invalid Input \n");
  1446. }
  1447.  
  1448. if (nChoice == 1){
  1449. printf("Change First Name: ");
  1450. fgets((*pInfo).name.first,21,stdin);
  1451. if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
  1452. (*pInfo).name.first[0] -= 32;
  1453. }
  1454.  
  1455. if (nChoice == 2){
  1456. printf("Change Middle Name: ");
  1457. fgets((*pInfo).name.middle,21,stdin);
  1458. if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
  1459. (*pInfo).name.middle[0] -= 32;
  1460. }
  1461.  
  1462. if (nChoice == 3){
  1463. printf("Change Last Name: ");
  1464. fgets((*pInfo).name.last,51,stdin);
  1465. if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
  1466. (*pInfo).name.last[0] -= 32;
  1467. }
  1468.  
  1469.  
  1470. printf("Your new name is: %s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1471. printf("[0] Return to Modify User Info Menu \n");
  1472. printf("[1] Reinput Name \n");
  1473. printf("Input: ");scanf("%d%c", &exit, &cDump);
  1474.  
  1475. if(exit>1||exit<0)
  1476. {
  1477. printf("Invalid input! returning you to main menu");
  1478. exit = 1;
  1479. }
  1480.  
  1481. } while(exit == 1);
  1482.  
  1483. break;
  1484.  
  1485. case 2: do {
  1486.  
  1487. printf("Input your new Address: ");
  1488. fgets((*pInfo).address,51,stdin);
  1489. (*pInfo).address[strlen((*pInfo).address)-1]='\0';
  1490. printf("Your new Address is: %s \n",(*pInfo).address);
  1491. printf("[0] Return to Modify User Info Menu \n");
  1492. printf("[1] Reinput Address\n");
  1493. printf("Input: ");scanf("%d%c", &exit, &cDump);
  1494. if(exit>1||exit<0)
  1495. {
  1496. printf("Invalid input! returning you to main menu");
  1497. exit = 1;
  1498. }
  1499.  
  1500. } while(exit == 1);
  1501.  
  1502. break;
  1503.  
  1504. case 3: do {
  1505.  
  1506. while (strcmp((*pUser).password, arrComparePass)!=0){
  1507. printf("Input your current password. \n");
  1508. scanf("%s%c",arrComparePass,&cDump);
  1509. if(strcmp((*pUser).password, arrComparePass)!=0){
  1510. printf("Password does not match, please try again. \n");
  1511. printf("Input: "); scanf("%s%c", arrComparePass,&cDump);
  1512. }
  1513. }
  1514.  
  1515. printf("Input your new Password: ");
  1516. scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
  1517. if (strlen((*pUser).password)<6){
  1518.  
  1519. printf("Password too short, please try again. \n");
  1520. printf("Enter password: ");
  1521. scanf("%s%c", (*pUser).password,&cDump);
  1522. }
  1523. if (strlen((*pUser).password)>15){
  1524.  
  1525. printf("Password too short, please try again. \n");
  1526. printf("Enter password: ");
  1527. scanf("%s%c", (*pUser).password,&cDump);
  1528. }
  1529.  
  1530. if (ValidPass(pUser)==1)
  1531. printf("Password is valid. \n");
  1532. else{
  1533. printf("Error, password must contain non-letter character.\n");
  1534. printf("Enter password: ");
  1535. scanf("%s%c", (*pUser).password,&cDump);
  1536. }
  1537.  
  1538. printf("Your new Password is %s. \n", (*pUser).password);
  1539.  
  1540. printf("[0] Return to Modify User Info Menu \n");
  1541. printf("[1] Reinput Address\n");
  1542. printf("Input: ");scanf("%d", &exit);
  1543.  
  1544. if(exit>1||exit<0)
  1545. {
  1546. printf("Invalid input! returning you to main menu");
  1547. exit = 1;
  1548. }
  1549.  
  1550. } while(exit == 1);
  1551.  
  1552. break;
  1553.  
  1554. default: choice = 0;
  1555.  
  1556. }
  1557.  
  1558. } while (choice == 1 || choice == 2 || choice == 3);
  1559.  
  1560. }
  1561.  
  1562. /*Function getUserInfo has 1 use:
  1563. 1. Allows user to input their user information
  1564.  
  1565. */
  1566. void getUserInfo (userInfoType *pInfo)
  1567. {
  1568.  
  1569. printf("Enter name: \n");
  1570. printf("First Name: ");
  1571. fgets((*pInfo).name.first,21,stdin);
  1572. if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
  1573. (*pInfo).name.first[0] -= 32;
  1574. printf("Middle Name: ");
  1575. fgets((*pInfo).name.middle,21,stdin);
  1576. if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
  1577. (*pInfo).name.middle[0] -= 32;
  1578. printf("Last Name: ");
  1579. fgets((*pInfo).name.last,51,stdin);
  1580. if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
  1581. (*pInfo).name.last[0] -= 32;
  1582.  
  1583. printf("%s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
  1584.  
  1585.  
  1586.  
  1587.  
  1588. printf("Enter address: ");
  1589. fgets((*pInfo).address,51,stdin);
  1590.  
  1591. (*pInfo).address[strlen((*pInfo).address)-1]='\0';
  1592. (*pInfo).name.first[strlen((*pInfo).name.first)-1]='\0';
  1593. (*pInfo).name.middle[strlen((*pInfo).name.middle)-1]='\0';
  1594. (*pInfo).name.last[strlen((*pInfo).name.last)-1]='\0';
  1595.  
  1596. }
  1597.  
  1598. /*Function ValidPass has 1 use:
  1599. 1. Allows user to sign in an exisiting account
  1600.  
  1601. @param i: index variable
  1602. @param valid: integer value that determines whether or not the password is valid
  1603. */
  1604. int ValidPass (userType *pUser)
  1605. {
  1606. int i, valid=0;
  1607.  
  1608. for(i=0;i<(strlen(pUser->password));i++){
  1609. if (pUser->password[i] < 'a' || pUser->password[i] >'z')
  1610. if (pUser->password[i] < 'A' || pUser->password[i] >'Z')
  1611. valid=1;
  1612. }
  1613. return valid;
  1614.  
  1615. }
  1616.  
  1617. /*Function displayAll has 1 use:
  1618. 1. Displays all users
  1619.  
  1620. */
  1621. void displayAll (userType *pUsers)
  1622. {
  1623. while (pUsers!=NULL){ //stop traversing when there is no more new address
  1624.  
  1625. printf("%s\n", pUsers->username);
  1626. pUsers = pUsers->pNext; //node traversal
  1627.  
  1628. }
  1629. }
  1630.  
  1631. /*Function signIn has 1 use:
  1632. 1. Allows user to sign in an exisiting account
  1633.  
  1634. @param i: index variable
  1635. @param loggedin: determine whether user is logged in or not
  1636. @param tries: number of tries before account is locked
  1637. @param exit: variable to do while statement
  1638. @param AccountType: integer variable to be passed into the linked list of user
  1639. @param arrTempuser: temporary string for username to be compared
  1640. @param arrTempPw: temporary string for password to be compared
  1641. @param arrInputCode: temporary string for authorization code
  1642. @param authcode: string that holds the authorization code
  1643. @param cDump: character variable for dump
  1644. @param pLogin: temporary pointer variable for username
  1645. @param pPassword: temporary pointer variable for password
  1646. */
  1647. int signIn (userType *pUsers, userInfoType *pInfo, userType *pNew, userType *pLast)
  1648. {
  1649. int loggedin=0, tries=3, exit = 0, AccountType = 0;
  1650. char arrTempUser[16], arrTempPW[16], arrInputCode[9], authcode[9]={'D','L','S','U','2','0','1','7'};
  1651. char cDump;
  1652. userType *pLogin, *pPassword;
  1653.  
  1654. do{
  1655.  
  1656.  
  1657. printf("Enter username: ");
  1658. scanf("%s", arrTempUser);fflush(stdin);
  1659.  
  1660. printf("Enter password: ");
  1661. scanf("%s", arrTempPW);fflush(stdin);
  1662.  
  1663. if(pUsers!=NULL)
  1664. {
  1665. pLogin = search(pUsers, arrTempUser);
  1666. pPassword = search(pUsers, pUsers->username);
  1667.  
  1668. if (pLogin == NULL){
  1669.  
  1670. printf("Not found address\n");
  1671. signIn (pUsers, pInfo, pNew, pLast);
  1672. }
  1673. }
  1674. else if (pUsers == NULL)
  1675. {
  1676.  
  1677. printf("Not found was null\n");
  1678. signIn (pUsers, pInfo, pNew, pLast);
  1679. }
  1680.  
  1681. if (pUsers->nLocked == 1)
  1682. printf("This account is locked, contact an administrator, returning to main menu. \n");
  1683.  
  1684.  
  1685. if (strcmp(pLogin->username, arrTempUser)==0){
  1686.  
  1687. if (strcmp(pPassword->password, arrTempPW)==0){
  1688.  
  1689.  
  1690. pUsers->nLoggedin = 1;
  1691. }
  1692. else{
  1693. while (strcmp(pPassword->password, arrTempPW)!=0 && pUsers->nLocked != 1){
  1694. printf("Incorrect password, please try again. %d tries remaining: \n", tries);
  1695. tries--;
  1696. scanf("%s%c", arrTempPW, &cDump);
  1697. if (tries == 0){
  1698. printf("This account has been locked. Contact Administrator. Returning to main menu. \n");
  1699. pUsers->nLocked = 1;
  1700. exit = 1;
  1701.  
  1702. }
  1703. }
  1704.  
  1705. }
  1706. }
  1707. else {
  1708.  
  1709. printf("Incorrect username or password, please try again. %d tries remaining: \n", tries);
  1710. printf("%s", arrTempUser);
  1711. printf("%d", strcmp(pLogin->username, arrTempUser));
  1712. tries--;
  1713. }
  1714.  
  1715. if (pUsers->type == 'A' && pUsers->nLocked == 0){
  1716.  
  1717. printf("Input authorization code: ");
  1718. scanf("%s%c", arrInputCode, &cDump);
  1719.  
  1720. if (strcmp(arrInputCode,authcode)==0){
  1721.  
  1722. AccountType = 2;
  1723. return AccountType;
  1724. pUsers->nLoggedin = 1;
  1725. }
  1726.  
  1727. else if (strcmp(arrInputCode,authcode)!=0) {
  1728.  
  1729. while (strcmp(arrInputCode,authcode)!=0){
  1730.  
  1731. printf("Incorrect code, please try again.\n");
  1732. printf("Input: "); scanf("%s%c", arrInputCode, &cDump);
  1733. }
  1734.  
  1735. }
  1736. }
  1737.  
  1738. else if (pUsers->type == 'S' && pUsers->nLocked == 0){
  1739.  
  1740. printf("Welcome, %s \n", (*pInfo).name.first);
  1741. //pUsers->loggedin = 1;
  1742. //modifyUserInfo (pUsers, pInfo);
  1743. AccountType = 1;
  1744. return AccountType;
  1745. pUsers->nLoggedin = 1;
  1746. }
  1747.  
  1748. }while (loggedin == 0 && tries > 0 && exit == 0 && pUsers->nLocked != 1);
  1749.  
  1750. }
  1751.  
  1752. /*Function freeAll has 1 use:
  1753. 1. Frees the linked list of users
  1754.  
  1755. @param i: index variable
  1756. @param pDel: node to be deleted
  1757. @param pTemp: temporary variable used to run throught linked list
  1758. */
  1759. void freeAll (ptrUser *pFirst)
  1760. {
  1761. userType *pDel;
  1762.  
  1763. while(*pFirst != NULL){
  1764. pDel = *pFirst;
  1765. *pFirst = (*pFirst)->pNext;
  1766. free(pDel);
  1767. }
  1768.  
  1769. }
  1770. /*Function freeAllStock has 1 use:
  1771. 1. Frees the linked list of stocks
  1772.  
  1773. @param i: index variable
  1774. @param pDel: node to be deleted
  1775. @param pTemp: temporary variable used to run throught linked list
  1776. */
  1777. void freeAllStock (categoryType **pFirst, aStocks *aCategories, int currCateg)
  1778. {
  1779. ptrStock pTemp, pDel;
  1780. int i;
  1781.  
  1782. for (i=0; i<currCateg; i++){
  1783. pTemp = aCategories[i]->pFirstStock;
  1784. while (aCategories[i]->pFirstStock != NULL){
  1785. pDel = pTemp;
  1786. pTemp = pTemp->pNext;
  1787. free(pDel);
  1788. }
  1789. }
  1790. }
  1791. /*Function ViewCart has 1 use:
  1792. 1. View all items added to user's cart
  1793.  
  1794. @param i: index variable
  1795. @param index: alternate index variable
  1796. @param arrayindex: index for array
  1797. @param itemsubtotal: total to be calculated in the function
  1798. @param pTemp: variable used to run throught linked list
  1799. */
  1800. void ViewCart (userType *pUsers, aStocks* aCategories, int currCateg)
  1801. {
  1802. categoryType * pTemp;
  1803. int i = 0, index = 0, arrayindex = 0;
  1804. float itemsubtotal;
  1805. if (pUsers->cart == NULL)
  1806. printf("Cart is empty \n");
  1807. pTemp = aCategories[i];
  1808. printf("Product Code Product Quantity Unit Price Total Price Discount Rate Item Subtotal \n");
  1809. while (i < pUsers->nItems){
  1810. while (strcmp(pTemp->pFirstStock->productcode, pUsers->cart[index].code)!=0){
  1811. pTemp->pFirstStock = pTemp->pFirstStock->pNext;
  1812. index++;
  1813. }
  1814.  
  1815. printf ("%15s %15s %d %f %f %f %f \n", pUsers->cart[i].code, pTemp->pFirstStock->product, pUsers->cart[i].qty,
  1816. pTemp->pFirstStock->unitsellingprice, pTemp->pFirstStock->discountrate, itemsubtotal);
  1817. i++;
  1818.  
  1819. if (pTemp->pFirstStock == NULL){
  1820.  
  1821. pTemp = aCategories[arrayindex];
  1822. arrayindex++;
  1823. }
  1824. }
  1825.  
  1826. }
  1827. /*Function AddtoCart has 1 use:
  1828. 1. Add a product to the cart given a product code
  1829.  
  1830. @param quantity: temp quantity to be placed in the linked list
  1831. @param i: index variable
  1832. @param index: alternate index variable
  1833. @param choice: to exit the loop
  1834. @param cChoice: to exit the loop, but uses a character
  1835. @param cDump: character variable that acts as a dump
  1836. @param tempcode: temporary string to compare
  1837. @param pRun: variable used to run throught linked list
  1838. */
  1839. void AddtoCart (userType *pUsers, aStocks* aCategories, int currCateg)
  1840. {
  1841. int quantity = 0, choice = 1, index, i = 0;
  1842. char cDump, cChoice = 'y';
  1843. string8 tempcode;
  1844. categoryType* pRun;
  1845.  
  1846. do {
  1847. printf("Input product code of item to add: ");
  1848. scanf("%s%c", tempcode, &cDump);
  1849.  
  1850. if (searchProductCode (aCategories, tempcode, currCateg) == NULL){
  1851. printf("Product not found, please try again. \n");
  1852. printf("[0] Exit \n");
  1853. printf("[1] Add to Cart");
  1854. scanf("%d",&choice);
  1855. }
  1856.  
  1857. else if (searchProductCode (aCategories, tempcode, currCateg) != NULL){
  1858. pRun = searchProductCode (aCategories, tempcode, currCateg);
  1859. while (strcmp(pRun->pFirstStock->productcode, tempcode) != 0){
  1860. pRun->pFirstStock = pRun->pFirstStock->pNext;
  1861. }
  1862. if (pRun->pFirstStock->quantityavailable == 0){
  1863. printf("Out of Stock \n");
  1864. }
  1865. printf("Input quantity: ");
  1866. scanf("%d", &quantity);
  1867.  
  1868. strcpy (pUsers->cart[i].code, tempcode);
  1869. pUsers->cart[i].qty = quantity;
  1870.  
  1871. printf("Would you like to add another item to the cart?");
  1872. scanf("%c%c", &cChoice, cDump);
  1873.  
  1874. if (cChoice != 'y' || cChoice != 'Y' || cChoice != 'N' || cChoice != 'n'){
  1875. printf("Invalid input, returning to shopper menu. \n");
  1876. choice = 0;
  1877. }
  1878. i++;
  1879. pUsers->nItems++;
  1880.  
  1881. }
  1882.  
  1883. }while (choice == 1 || cChoice == 'y' || cChoice == 'Y');
  1884.  
  1885.  
  1886. }
  1887. /*Function EditCart has 2 uses:
  1888. 1. Remove items from cart
  1889. 2. Update quantity
  1890.  
  1891. @param i: index variable
  1892. @param page: limits the number of entries shown so the items do not simply flash
  1893. @param cDump: character variable that acts as a dump
  1894. @param cExit: similar to exit, for option that requires a character input
  1895. @param tempcode: temporary storage for product code
  1896. */
  1897. void EditCart (userType *pUsers, aStocks* aCategories, int currCateg)
  1898. {
  1899. int exit = 0, choice, nExit = 1, i, newamount = 0;
  1900. char cDump;
  1901. string8 tempcode;
  1902. do {
  1903. switch (choice){
  1904. case 1:
  1905. do {
  1906. printf("Input product code of item to be removed: ");
  1907. scanf("%s%c",tempcode, &cDump);
  1908.  
  1909. if (pUsers->nItems == 0)
  1910. printf("No items in cart \n");
  1911.  
  1912. while (pUsers->cart[i].code != NULL && i < pUsers->nItems
  1913. && strcmp (tempcode, pUsers->cart[i].code)!=0) {
  1914. i++;
  1915. }
  1916.  
  1917. if (strcmp(tempcode, pUsers->cart[i].code) == 0){
  1918. pUsers->cart[i].qty = 0;
  1919. printf("Item removed. \n");
  1920. }
  1921. if (i>pUsers->nItems){
  1922. printf("Product code not found, returning to edit cart menu");
  1923. nExit = 0;
  1924. }
  1925.  
  1926.  
  1927. }while (nExit == 1);
  1928.  
  1929. break;
  1930.  
  1931. case 2: do {
  1932. printf("Input product code of item to update quantity: ");
  1933. scanf("%s%c",tempcode, &cDump);
  1934.  
  1935. if (pUsers->nItems == 0)
  1936. printf("No items in cart \n");
  1937.  
  1938. while (pUsers->cart[i].code != NULL && i < pUsers->nItems
  1939. && strcmp (tempcode, pUsers->cart[i].code)!=0) {
  1940. i++;
  1941. }
  1942.  
  1943. if (strcmp(tempcode, pUsers->cart[i].code) == 0){
  1944. printf("Input amount to update to: ");
  1945. scanf("%d%c",&newamount, cDump);
  1946. pUsers->cart[i].qty = newamount;
  1947. if (newamount == 0){
  1948. printf("New amount is zero, removing item. \n");
  1949. }
  1950. }
  1951. if (i>pUsers->nItems){
  1952. printf("Product code not found, returning to edit cart menu");
  1953. nExit = 0;
  1954. }
  1955.  
  1956. }while (nExit == 1);
  1957.  
  1958. break;
  1959.  
  1960. default: exit = 0;
  1961.  
  1962. break;
  1963. }
  1964.  
  1965. }while (exit == 1);
  1966. }
  1967. /*Function browseProducts has 1 use:
  1968. 1. Display products
  1969.  
  1970. @param i: index variable
  1971. @param page: limits the number of entries shown so the items do not simply flash
  1972. @param cDump: character variable that acts as a dump
  1973. @param cExit: similar to exit, for option that requires a character input
  1974. @param *pRun: variable that goes through the list to find what is needed
  1975. */
  1976. void browseProducts (aStocks *aCategories)
  1977. {
  1978. int i = 0, page = 0;
  1979. char cDump, cExit = '\0';
  1980. categoryType * pRun;
  1981. pRun = aCategories[i];
  1982. printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
  1983. do {
  1984. if (aCategories[i]->pFirstStock->quantityavailable >= 1){
  1985. printf("%15s%15s%8s%15s %d %d %.2f %.2f \n",
  1986. pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->productcode, pRun->pFirstStock->product,
  1987. pRun->pFirstStock->quantityavailable, pRun->pFirstStock->quantitysold, pRun->pFirstStock->unitsellingprice,
  1988. pRun->pFirstStock->discountrate);
  1989. }
  1990.  
  1991. if (pRun->pFirstStock->pNext == NULL){
  1992.  
  1993. i++;
  1994. pRun = aCategories[i];
  1995. }
  1996.  
  1997. page++;
  1998. }while (pRun->pFirstStock != NULL && page < 20);
  1999. }
  2000. /*Function browsebyCategory has 1 use:
  2001. 1. Display products by Category
  2002.  
  2003. @param i: index variable
  2004. @param index: another index variable
  2005. @param page: limits the number of entries shown so the items do not simply flash
  2006. @param cDump: character variable that acts as a dump
  2007. @param cExit: similar to exit, for option that requires a character input
  2008. @param TempCategory: temporary string to compare to existing ones
  2009. @param *pRun: variable that goes through the list to find what is needed
  2010. */
  2011. void browsebyCategory (aStocks *aCategories, int currCateg)
  2012. {
  2013. string15 TempCategory;
  2014. char cDump, cExit = '0';
  2015. int i = 0, index = 0, page = 0;
  2016. categoryType * pRun;
  2017.  
  2018. printf("Input the category");
  2019. printf("Input: ");scanf("%s%c",TempCategory, &cDump);
  2020.  
  2021. searchCategory (TempCategory, aCategories, currCateg);
  2022.  
  2023. if (searchCategory (TempCategory, aCategories, currCateg)==NULL)
  2024. printf("Category not found \n");
  2025.  
  2026. else if (searchCategory (TempCategory, aCategories, currCateg)!=NULL){
  2027. printf("Browsing Products by Category \n");
  2028. pRun = searchCategory (TempCategory, aCategories, currCateg);
  2029.  
  2030. printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
  2031. do {
  2032. printf("%15s %15s %8s %15s %d% d% .2f %.2f \n",pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->productcode, pRun->pFirstStock->product,
  2033. pRun->pFirstStock->quantityavailable, pRun->pFirstStock->quantitysold, pRun->pFirstStock->unitsellingprice,
  2034. pRun->pFirstStock->discountrate);
  2035.  
  2036. pRun->pFirstStock = pRun->pFirstStock->pNext;
  2037. page++;
  2038.  
  2039. if (pRun->pFirstStock->pNext == NULL){
  2040. index++;
  2041. pRun = aCategories[index];
  2042. }
  2043.  
  2044. if (page = 20){
  2045. printf("Press ENTER to go to next page or [0] to return to Shopper Menu \n");
  2046. printf("Input: "); scanf("%c%c", &cExit, &cDump);
  2047. }
  2048. }while (page <= 20 && index <= currCateg && cExit != '\0');
  2049. }
  2050.  
  2051. }
  2052. /*Function browseOnSale has 1 use:
  2053. 1. Display products on sale
  2054.  
  2055. @param i: index variable
  2056. @param page: limits the number of entries shown so the items do not simply flash
  2057. @param cDump: character variable that acts as a dump
  2058. @param cExit: similar to exit, for option that requires a character input
  2059. @param TempCategory: temporary string to compare to existing ones
  2060. @param *pRun: variable that goes through the list to find what is needed
  2061. */
  2062. void browseOnSale (aStocks *aCategories, int currCateg)
  2063. {
  2064. int i = 0, page = 0;
  2065. char cExit = '\0', cDump;
  2066. categoryType * pRun;
  2067. printf("Browsing Products on Sale \n");
  2068. pRun = aCategories[i];
  2069.  
  2070. printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
  2071.  
  2072. if (pRun->pFirstStock == NULL)
  2073. printf("Stocks is empty \n");
  2074.  
  2075. do{
  2076. if (pRun->pFirstStock->discountrate > 0){
  2077. printf("%15s %15s %8s %15s %d %d %f %f \n",
  2078. pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->productcode, pRun->pFirstStock->product,
  2079. pRun->pFirstStock->quantityavailable, pRun->pFirstStock->quantitysold, pRun->pFirstStock->unitsellingprice,
  2080. pRun->pFirstStock->discountrate);
  2081. }
  2082. page++;
  2083.  
  2084. if (pRun->pFirstStock->pNext == NULL){
  2085. i++;
  2086. pRun = aCategories[i];
  2087. }
  2088.  
  2089. if (page = 20){
  2090. printf("Press ENTER to go to next page or [0] to return to Shopper Menu \n");
  2091. printf("Input: "); scanf("%c%c", &cExit, &cDump);
  2092. if (cExit == '\0')
  2093. page = 0;
  2094. }
  2095.  
  2096. if (i > currCateg){
  2097. printf("End of List \n");
  2098. cExit = '0';
  2099. }
  2100. }
  2101. while (pRun->pFirstStock != NULL && cExit != '0');
  2102. }
  2103. /*Function checkOut has 1 use:
  2104. 1. Checkout user cart
  2105.  
  2106. @param i: index variable
  2107. @param index: alternate index variable
  2108. @param cChoice: for the switch case, but uses a character
  2109. @param cDump: character variable that acts as a dump
  2110. */
  2111. void checkOut (userType *pUsers, aStocks *aCategories, int currCateg)
  2112. {
  2113. int index = 0, i = 0;
  2114. char cDump, cChoice;
  2115. categoryType * pRun;
  2116. printf("Check Out \n");
  2117. printf("Are you sure you would like to check out? [Y]/[N] \n");
  2118. printf("Input: "); scanf("%s%c", cChoice, &cDump);
  2119. do {
  2120.  
  2121. if (cChoice == 'Y' || cChoice == 'y'){
  2122.  
  2123. for (i=0;i<pUsers->nItems;i++)
  2124. pUsers->cart[i].qty = 0;
  2125.  
  2126.  
  2127. printf("Check out successful \n");
  2128. printf("Adding to cart is now disabled for this account until items are delivered \n");
  2129. printf("Returning to Shopper Menu");
  2130. pUsers->nCheckedout == 1;
  2131.  
  2132. }
  2133.  
  2134. if (cChoice == 'N' || cChoice == 'n')
  2135. printf("Returning to Shopper Menu \n");
  2136.  
  2137. }while (cChoice == 'Y' || cChoice == 'y' || cChoice == 'n' || cChoice == 'N');
  2138. }
  2139. /*Function settleOutstanding has 1 use:
  2140. 1. Settle User Outstanding
  2141.  
  2142. @param settle: amount input by user to remove outstanding
  2143. @param cDump: character variable that acts as a dump
  2144. @param creditcardinfo: input by user
  2145. */
  2146. void settleOutstanding (userType *pUsers)
  2147. {
  2148. int exit = 1;
  2149. float settle = 0.0;
  2150. string15 creditcardinfo;
  2151. char cDump;
  2152. do {
  2153.  
  2154. printf("Your outstanding balance is: %.2f \n", pUsers->outstanding);
  2155. printf("Input credit card information \n");
  2156. printf("Input: "); scanf("%s%c", creditcardinfo, &cDump);
  2157. printf("Input amount to settle: "); scanf("%f", &settle);
  2158.  
  2159. if (settle <= pUsers->outstanding){
  2160. pUsers->outstanding -= settle;
  2161. printf("Your new outstanding is %f", pUsers->outstanding);
  2162. exit = 0;
  2163. }
  2164. if (settle > pUsers->outstanding){
  2165. printf("Error, input amount is greater than outstanding \n");
  2166. printf("Please input amount less or equal to outstanding \n");
  2167. printf("Returning to Shopper Menu \n");
  2168. exit = 0;
  2169. }
  2170.  
  2171. }while (exit == 0);
  2172. }
  2173. /*Function ShopperMenu has 9 uses:
  2174. 1. Modify User Info
  2175. 2. Browse All Products
  2176. 3. Browse Products by Category
  2177. 4. Browse Products on Sale
  2178. 5. Add to Cart
  2179. 6. View Cart
  2180. 7. Check Out
  2181. 8. Edit Cart Items
  2182. 9. Settle Outstanding Balance
  2183.  
  2184. @param choice: for the switch case, allows user to navigate throught menu
  2185. @param page: limits the number of entries shown so the items do not simply flash
  2186. @param cDump: character variable that acts as a dump
  2187. @param exit: an exit for the do while loop to go back to the main menu when after choosing an option
  2188. @param cExit: similar to exit, for option that requires a character input
  2189. @param TempCategory: temporary string to compare to existing ones
  2190. @param *pRun: variable that goes through the list to find what is needed
  2191. */
  2192. void ShopperMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock, aStocks* aCategories, int currCateg)
  2193. {
  2194. int choice = 0, page = 20;
  2195. char cDump, cExit = '\0';
  2196. int exit;
  2197. string15 TempCategory;
  2198. categoryType* pRun;
  2199.  
  2200. do {
  2201. printf("SHOPPER MENU \n");
  2202. printf("[1] Modify User Info \n");
  2203. printf("[2] Browse All Products \n");
  2204. printf("[3] Browse Products by Category \n");
  2205. printf("[4] Browse Products on Sale \n");
  2206. if (pUsers->outstanding > 0 && pUsers->nCheckedout != 1);
  2207. printf("[5] Add to Cart \n");
  2208. if (pUsers->nItems > 0)
  2209. printf("[6] View Cart \n");
  2210. printf("[7] Check Out \n");
  2211. printf("[8] Edit Cart Items \n");
  2212. if (pUsers->outstanding > 0)
  2213. printf("[9] Settle Outstanding Balance \n");
  2214. printf("[0] Return to Main Menu \n");
  2215. printf("Input: ");
  2216. scanf("%d%c", &choice, &cDump);
  2217.  
  2218. switch (choice){
  2219. case 1: do {
  2220. modifyUserInfo (pUsers, &pUsers->info);
  2221. printf("Press [0] to Return to Shopper Menu \n");
  2222. printf("Input: ");
  2223. scanf("%d%c", &exit, &cDump);
  2224. }while (exit==1);
  2225. //view locked
  2226. break;
  2227. case 2: do {
  2228.  
  2229. browseProducts (aCategories);
  2230. printf("Press [N] return to main menu or ENTER to view next page. \n");
  2231. scanf("%c%c", &cExit, &cDump);
  2232. }while (cExit=='\0');
  2233.  
  2234.  
  2235. break;
  2236. case 3: do {
  2237.  
  2238. browsebyCategory (aCategories, currCateg);
  2239. printf("Press [0] to Return to Shopper Menu \n");
  2240. printf("Input: ");
  2241. scanf("%d%c", &exit, &cDump);
  2242. }while (exit==1);
  2243.  
  2244. break;
  2245. case 4: do {
  2246.  
  2247. browseOnSale (aCategories, currCateg);
  2248. printf("Press [0] to Return to Shopper Menu \n");
  2249. printf("Input: ");
  2250. scanf("%d%c", &exit, &cDump);
  2251. }while (exit==1);
  2252.  
  2253. break;
  2254. case 5: if (pUsers->nCheckedout == 1){
  2255. printf("Error, items not yet cleared \n");
  2256. exit = 0;
  2257. }
  2258. else if (pUsers->nCheckedout != 1){
  2259. do {
  2260. AddtoCart (pUsers, aCategories, currCateg);
  2261. printf("Press [0] to Return to Shopper Menu \n");
  2262. printf("Input: ");
  2263. scanf("%d%c", &exit, &cDump);
  2264. }while (exit==1);
  2265. }
  2266. break;
  2267. case 6: do {
  2268.  
  2269. printf("Viewing Cart \n");
  2270. ViewCart (pUsers, aCategories, currCateg);
  2271. printf("Press [0] to Return to Shopper Menu \n");
  2272. printf("Input: ");
  2273. scanf("%d%c", &exit, &cDump);
  2274. }while (exit==1);
  2275.  
  2276. break;
  2277. case 7: do {
  2278.  
  2279. checkOut(pUsers, aCategories, currCateg);
  2280. printf("Press [0] to Return to Shopper Menu \n");
  2281. printf("Input: ");
  2282. scanf("%d%c", &exit, &cDump);
  2283. }while (exit==1);
  2284.  
  2285. break;
  2286. case 8: do {
  2287. EditCart (pUsers, aCategories, currCateg);
  2288. printf("Press [0] to Return to Shopper Menu \n");
  2289. printf("Input: ");
  2290. scanf("%d%c", &exit, &cDump);
  2291. }while (exit==1);
  2292.  
  2293. break;
  2294.  
  2295. case 9: do {
  2296. settleOutstanding(pUsers);
  2297. printf("Press [0] to Return to Shopper Menu \n");
  2298. printf("Input: ");
  2299. scanf("%d%c", &exit, &cDump);
  2300. }while (exit ==1);
  2301.  
  2302. break;
  2303.  
  2304. default: printf("Your account has been successfully logged out. \n");
  2305. pUsers->nLoggedin = 0;
  2306. choice = 0;
  2307. break;
  2308. }
  2309.  
  2310.  
  2311. }while (choice > 0 && choice < 9);
  2312.  
  2313. }
  2314.  
  2315. /*Function AdminMenu has 5 uses:
  2316. 1. Access manage accounts menu
  2317. 2. Access manage stocks menu
  2318. 3. Prepare Delivery Receipt for Shopper
  2319. 4. Shutdown the kiosk, end the program
  2320. 5. Log out the administrator, returning to the main menu
  2321.  
  2322. @param choice: for the switch case, allows user to navigate throught menu
  2323. @param cDump: character variable that acts as a dump
  2324. @param exit: an exit for the do while loop to go back to the main menu when after choosing an option
  2325. */
  2326. int AdminMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd, aStocks* aCategories, int currCateg)
  2327. {
  2328. int choice, exit = 1;
  2329. char cDump;
  2330.  
  2331. do {
  2332.  
  2333. printf("ADMINISTRATOR MENU \n");
  2334. printf("[1] Manage Accounts Menu \n");
  2335. printf("[2] Manage Stocks Menu \n");
  2336. printf("[3] Prepare Delivery Receipt \n");
  2337. printf("[4] Shutdown Kiosk \n");
  2338. printf("[5] Log Out \n");
  2339. printf("Input: ");
  2340. scanf("%d%c", &choice, &cDump);
  2341.  
  2342. switch (choice){
  2343. case 1: do {
  2344. AdminManageAccounts (pUsers, &pUsers->info);
  2345. printf("Press [0] to return to Administrator Menu: ");
  2346. scanf("%d", &exit);
  2347. }while (exit==1);
  2348. return 1;
  2349. break;
  2350. case 2: do {
  2351. AdminManageStocks (pUsers, pStock, pNewStock, pEnd, aCategories, currCateg);
  2352. printf("Press [0] to return to Administrator Menu: ");
  2353. scanf("%d", &exit);
  2354. }while (exit==1);
  2355. return 1;
  2356. break;
  2357. case 3: do {
  2358. AdminPrepareDelivery (pUsers, &pUsers->info, aCategories);
  2359. printf("Press [0] to return to Administrator Menu: ");
  2360. scanf("%d", &exit);
  2361. }while (exit==1);
  2362. return 1;
  2363. break;
  2364. case 4:
  2365. printf("Kiosk Shutdown. \n");
  2366. freeAll(&pUsers);
  2367. freeAllStock(&pStock, aCategories, currCateg);
  2368. choice = 0;
  2369. return 0;
  2370. break;
  2371.  
  2372. case 5:
  2373. pUsers->nLoggedin == 0;
  2374. printf("Your account has been successfully logged out. \n");
  2375. return 1;
  2376. break;
  2377.  
  2378. default: printf("Invalid Input. Returning to Main Menu. \n");
  2379. return 1;
  2380. break;
  2381.  
  2382. }
  2383.  
  2384. }while (choice > 0 && choice < 5 && choice != 4);
  2385. }
  2386.  
  2387. /*Function menu has 2 uses:
  2388. 1. Sign up new users
  2389. 2. Log in an existing user
  2390.  
  2391. @param choice: for the switch case, allows user to navigate throught menu
  2392. @param cDump: character variable that acts as a dump
  2393. @param exit: an exit for the do while loop to go back to the main menu when after choosing an option
  2394. */
  2395. void menu (userType *pUsers, userType *pNew, userType *pLast, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd, aStocks *aCategories, int currCateg)
  2396. {
  2397. int choice=0;
  2398. char cDump;
  2399. int exit;
  2400.  
  2401. pUsers = NULL;
  2402. pNew = NULL;
  2403. pLast = NULL;
  2404.  
  2405. ptrUser pRun, pTrail;
  2406.  
  2407. do {
  2408. printf("MAIN MENU \n");
  2409. printf("[1] Sign Up \n");
  2410. printf("[2] Log In \n");
  2411. //printf("[0] Shutdown Kiosk \n");
  2412. printf("Choice: ");
  2413. scanf("%d%c", &choice,&cDump);
  2414.  
  2415. if (choice > 2 || choice < 0){
  2416.  
  2417. printf("INVALID INPUT \n \n");
  2418. menu (pUsers, pNew, pLast, pStock, pNewStock, pEnd, aCategories, currCateg);
  2419. }
  2420.  
  2421. switch (choice){
  2422. case 1:
  2423. do{
  2424. pNew = malloc(sizeof(userType));
  2425.  
  2426. signUp(pNew, pUsers);
  2427. pNew -> pNext = NULL;
  2428.  
  2429. if (pUsers == NULL) //if list is empty
  2430. pUsers = pNew;
  2431.  
  2432. else if (strcmp(pUsers -> username, pNew -> username) > 0){ //conect as first node
  2433.  
  2434. pNew -> pNext = pUsers;
  2435. pUsers = pNew;
  2436.  
  2437. }
  2438.  
  2439. else { //modifying middle of list
  2440.  
  2441. pRun = pUsers;
  2442.  
  2443. while (pRun != NULL && strcmp(pRun -> username, pNew -> username) < 0){
  2444.  
  2445. pTrail = pRun;
  2446. pRun = pRun -> pNext;
  2447.  
  2448. }
  2449.  
  2450. pTrail -> pNext = pNew;
  2451. pNew -> pNext = pRun;
  2452. }
  2453.  
  2454. getUserInfo (&pUsers->info);
  2455.  
  2456. printf("Press [0] to create a new user or [1] to return to main menu: ");
  2457. scanf("%d%c", &exit, &cDump);
  2458.  
  2459. if(exit>1||exit<0)
  2460. {
  2461. printf("Invalid input! returning you to main menu");
  2462. exit = 1;
  2463.  
  2464. }
  2465.  
  2466. }while(exit==0);
  2467. break;
  2468.  
  2469. case 2:
  2470.  
  2471.  
  2472. if (signIn(pUsers, &pUsers->info , pNew, pLast)==1)
  2473. ShopperMenu (pUsers, pNew, pLast, &pUsers->info, pStock, aCategories, currCateg);
  2474. else if (signIn(pUsers, &pUsers->info , pNew, pLast)==2)
  2475. if (AdminMenu (pUsers, pNew, pLast, &pUsers->info, pStock, pNewStock, pEnd, aCategories, currCateg)==0)
  2476. choice = 0;
  2477. break;
  2478.  
  2479. default:freeAll(&pUsers);
  2480. freeAllStock(&pStock, aCategories, currCateg);
  2481. break;
  2482. }
  2483.  
  2484. }while (choice == 1||choice == 2);
  2485.  
  2486. freeAll(&pUsers);
  2487. freeAllStock(&pStock, aCategories, currCateg);
  2488.  
  2489. }
  2490.  
  2491. int main ()
  2492. {
  2493. categoryType *pFirst,
  2494. *pNewStock,
  2495. *pEnd;
  2496.  
  2497. userType *pUsers,
  2498. *pNew,
  2499. *pLast;
  2500. ptrUser pRun, pTrail;
  2501. aStocks aCategories;
  2502.  
  2503.  
  2504. int currCateg = 0;
  2505.  
  2506. menu (pUsers, pNew, pLast, pFirst, pNewStock, pEnd, &aCategories, currCateg);
  2507.  
  2508. return 0;
  2509. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement