/************************************************** Component: Transaction Module: Deposit **************************************************/ /* include statements */ #include #include #include #include #include "constants.h" #include "database.h" #include "screen_output.h" #include "getch.h" #include "deposit.h" /* functions */ int tr_Deposit(char *cardNumber, int cashORcheck) { int exit_condition = 0; char temp[2] = " "; char ch; int i; int deposit_amount_100x = 0; double deposit_amount = 0.0; int number_of_accounts; char accountType[MAX_ACCOUNTS+1][MAX_ACCOUNT_TYPE_LENGTH+1]; char accountNumber[MAX_ACCOUNTS+1][MAX_ACCOUNT_NUMBER_LENGTH+1]; char sink_account_number[MAX_ACCOUNT_NUMBER_LENGTH+1]; char msg[MESSAGE_BUFFER_LENGTH]; // for receipts double availableBalanceR; double totalBalanceR; db_GetNumAccounts(cardNumber, &number_of_accounts); if (number_of_accounts <= 0) { io_DrawTopLine(); printf ("No accounts attached to this card\n"); printf ("Press any key to continue...\n"); io_DrawBottomLine(); getch(); return 1; } else if (number_of_accounts > MAX_ACCOUNTS) { number_of_accounts = MAX_ACCOUNTS; } for (i=0;i= 1 && atoi(temp) <= number_of_accounts) { /* an account was selected */ strcpy(sink_account_number, accountNumber[atoi(temp)-1]); deposit_amount_100x = tr_GetDepositAmount(); deposit_amount = (double)deposit_amount_100x / 100; if (deposit_amount_100x > 0) { // HANDLE THE DEPOSIT // Deposit to account with link number atoi(temp)-1, with temp[0]=ch if (cashORcheck == 0) { db_DepositCash(cardNumber, accountNumber[atoi(temp)-1], deposit_amount); } else { db_DepositCheque(cardNumber, accountNumber[atoi(temp)-1], deposit_amount); } // PRINT RECEIPT BEGIN io_DrawTopLine(); printf ("Deposit Receipt:\n"); printf ("Deposited $%10.2lf\n", deposit_amount); printf ("to account: %s\n", sink_account_number); db_GetAccountBalance(cardNumber, sink_account_number, &availableBalanceR, &totalBalanceR); printf ("Ending Balances for account: %s\n", sink_account_number); printf ("Total Balance: $%10.2lf\n", totalBalanceR); printf ("Available Balance: $%10.2lf\n", availableBalanceR); io_DrawBottomLine(); printf ("Press any key to continue...\n"); getch(); // END RECEIPT } } } else if (ch == 'c') exit_condition = 1; } while (exit_condition != 1); return 0; } long int tr_GetDepositAmount() { int exit_condition = 0; int D_position = 0; int warn_invalid_D = 0; int correct_value_entered = 0; char account_D[MDD+2]; // amount to deposit into the account char ch; char print1[MDD+1], print2[3]; // hold the split up dollar value int i,j; account_D[D_position] = '\0'; do { io_DrawTopLine(); printf ("Enter amount you are depositing:\n\n"); printf ("e - enter\n"); printf ("b - backspace\n"); printf ("c - cancel\n"); if (warn_invalid_D == 1) { printf ("Enter a valid deposit amount\n"); warn_invalid_D = 0; } io_DrawMidLine(); /* Split up string "ab" into two strings "a" and "b" b is of length 2, a is variable. Display as cash. */ j = 0; for (i=0;i<=(int)strlen(account_D);i++) { if ((int)strlen(account_D)-i > 2) { print1[i] = account_D[i]; } else { print1[i] = '\0'; print2[j] = account_D[i]; j++; } } printf ("$%10s.%2s\n", print1, print2); io_DrawBottomLine(); ch = getch(); if (isdigit(ch)) { account_D[D_position] = ch; D_position++; } else if (ch == 'c') { exit_condition = 1; } else if (ch == 'e') { if (atoi(account_D) > 0) { exit_condition = 1; correct_value_entered = 1; } else { /* deposit amount not valid */ D_position = 0; warn_invalid_D = 1; } } else if (ch == 'b') { if (D_position >= 1) { D_position--; } } if (D_position > MDD) { D_position = MDD; } account_D[D_position] = '\0'; } while (exit_condition != 1); if (correct_value_entered == 1) { return atoi(account_D); } else { return -1; } }