Advertisement
alexandra84

WaterWorkFINAL

Nov 2nd, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.41 KB | None | 0 0
  1. import com.sun.org.apache.bcel.internal.generic.Select;
  2.  
  3. import java.text.DateFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.Scanner;
  8. import java.io.BufferedWriter;
  9. import java.io.FileWriter;
  10. import java.io.IOException;
  11.  
  12. @SuppressWarnings("Duplicates") //JUST TO AVOID DUPLICATE CONTENT MARKING - REMOVE THIS BEFORE HAND IN
  13.  
  14. public class waterwork {
  15.  
  16. private static int menuItem = 0;
  17. private static boolean exit = false;
  18. private static boolean quit = false;
  19. private static int MaxCostumerID;
  20. private static int costumerID;
  21. private static double diff;
  22. private static double receivedamount;
  23.  
  24. public static void main(String[] args) {
  25.  
  26. //We start running a loop that will only exit if the user presses 0 - Otherwise the program will continue to run
  27. while (!exit) {
  28. do {
  29. System.out.println("***************** UPTOWN WATERWORK SYSTEM ****************");
  30. System.out.println("Welcome. Please choose your role in the company. Press:");
  31. System.out.println("1: for Admin");
  32. System.out.println("2: for Employee");
  33. System.out.println("0: to Quit the program");
  34. System.out.print("Choose your role: ");
  35. menuItem = validateIntInput(); // CHECKS IF THE INPUT IS INDEED AN VALID INT TYPE
  36. System.out.println(" ");
  37. System.out.println("**********************************************************");
  38. System.out.println(" ");
  39. } while (menuItem != 1 && menuItem != 2 && menuItem != 0); // WILL KEEP RUNNING UNTIL INPUT IS 1, 2 or 0
  40. if (menuItem == 1) {
  41. adminLogIn(); // KØRER ADMIN DELEN AF PROGRAMMET
  42. } else if (menuItem == 2) {
  43. employeeLogIn(); // KØRER EMPLOYEE DELEN AF PROGRAMMET
  44. } else {
  45. exit = true; // AFSLUTTER PROGRAMMET
  46. }
  47. }
  48. }
  49.  
  50. private static void adminLogIn() {
  51. Scanner scanner = new Scanner(System.in);
  52.  
  53. String username = "Admin"; // OUR HARDCODED ADMIN USERNAME - SHOULD IDEALLY NOT BE LIKE THIS BUT TIME...
  54. String password = "Admin123"; // OUR HARDCODED PASSWORD USERNAME - SHOULD IDEALLY NOT BE LIKE THIS BUT TIME...
  55.  
  56. System.out.println("********************** ADMIN LOGIN ***********************");
  57. System.out.println(" ");
  58.  
  59. for (int i = 0; i < 3; i++) {
  60. System.out.println("Please enter your username:");
  61. String usernameInput = scanner.next(); // LET'S THE USER TYPE IN A USERNAME
  62.  
  63. System.out.println("Please confirm your password:");
  64. String passwordInput = scanner.next(); // LET'S THE USER TYPE IN A PASSWORD
  65.  
  66. if (username.equals(usernameInput) && password.equals(passwordInput)) // IF USERNAME & PASSWORD IS CORRECT, ACCESS IS GRANTED.
  67. {
  68. System.out.println("You're logged in");
  69. adminInterface();
  70. break;
  71. } else { // ALLOWS THE USER TWO MORE TRIES TO GET IT RIGHT
  72. if (i < 2) {
  73. System.out.println("Log-in invalid. You have " + (2 - i) + " tries left");
  74. } else {
  75. System.out.println("You have no more tries left"); // IF USERNAME OR PASSWORD WAS WRONG, ACCESS IS NOT GRANTED.
  76. }
  77. }
  78. }
  79. System.out.println(" ");
  80. }
  81.  
  82. private static void adminInterface() {
  83. String employees;
  84. String username;
  85. String password;
  86. int menuItem;
  87.  
  88. boolean quit = false; // IS NEEDED AS THE BOOLEAN OUTSIDE OF THIS METHOD CAN'T BE ACCESSED
  89. do {
  90. System.out.println(" ");
  91. System.out.println("********************** ADMIN INTERFACE *********************");
  92. System.out.println(" ");
  93. System.out.println("1: Add Employee");
  94. System.out.println("2: Delete Employee:");
  95. System.out.println("0. Go back to Log In Screen");
  96. System.out.print("Choose menu number: ");
  97. menuItem = validateIntInput(); // CHECKS IF THE INPUT IS INDEED AN VALID INT TYPE
  98. System.out.println(" ");
  99. System.out.println("**********************************************************");
  100. System.out.println(" ");
  101.  
  102. Scanner name = new Scanner(System.in);
  103. Scanner password1 = new Scanner(System.in);
  104.  
  105. switch (menuItem) {
  106. case 1:
  107. System.out.println("Enter employees name");
  108. employees = name.next();
  109. System.out.println("Enter a Password");
  110. password = password1.next();
  111. DB.insertSQL("INSERT INTO tblLogin (fldUsername , fldPassword) VALUES ('" + employees + "' , '" + password + "')");
  112. //CODE THAT WILL ADD EMPLOYEE FROM DATABASE
  113. break;
  114.  
  115. case 2:
  116. System.out.println("Enter the username of the employee you want to delete");
  117. username = name.next();
  118. System.out.println("user: '" + username + "' will now be deleted");
  119. boolean ok = false;
  120. ok = DB.deleteSQL("DELETE FROM tblLogin WHERE fldUsername = '" + username + "'");
  121. if (ok) {
  122. System.out.println("The employee is now deleted from the system");
  123. } else {
  124. System.out.println("Error. Please try again - User might not have been in the system.");
  125. }
  126. //CODE THAT WILL DELETE EMPLOYEE FROM DATABASE
  127. break;
  128.  
  129. case 0:
  130. quit = true; // BREAKS THE LOOP WHICH LEADS US BACK ONE-STEP IN THE MENU
  131. System.out.println("Going back!");
  132. break;
  133.  
  134. default: // INVALID INPUTS RECEIVES THIS MESSAGE
  135. System.out.println("Invalid choice. Try again:");
  136. }
  137. } while (!quit);
  138. }
  139.  
  140. private static void employeeLogIn() {
  141. Scanner scanner = new Scanner(System.in);
  142.  
  143. System.out.println("********************* EMPLOYEE LOGIN *********************");
  144.  
  145. for (int i = 0; i < 3; i++) {
  146.  
  147. System.out.println("Please enter your username:");
  148. String usernameInput = scanner.next();
  149.  
  150. DB.selectSQL("SELECT fldUsername from tblLogin WHERE fldUsername='" + usernameInput + "'");
  151. String dbUsername = DB.getData();
  152. //System.out.println(dbUsername);// FOR US TO CHECK THE Username
  153.  
  154. DB.selectSQL("SELECT fldPassword FROM tblLogin WHERE fldUsername ='" + dbUsername + "'");
  155. String dbPassword = DB.getData();
  156. //System.out.println(dbPassword);// FOR US TO CHECK THE PASSWORD
  157.  
  158. if (usernameInput.equals(dbUsername)) {
  159. for (int j = 0; j < 3; j++) {
  160. System.out.println("Please enter your password:");
  161. String passwordInput = scanner.next();
  162.  
  163. if (passwordInput.equals(dbPassword)) {
  164. System.out.println("You're logged in");
  165. employeeInterface();
  166. break;
  167. } else {
  168. if (i < 2) {
  169. System.out.println("Log-in invalid. You have " + (2 - j) + " tries left");
  170. } else {
  171. System.out.println("You have no more tries left"); // IF USERNAME OR PASSWORD WAS WRONG, ACCESS IS NOT GRANTED.
  172. }
  173. }
  174. }
  175. } else { // ALLOWS THE USER TWO MORE TRIES TO GET IT RIGHT
  176. if (i < 2) {
  177. System.out.println("Log-in invalid. You have " + (2 - i) + " tries left");
  178. } else {
  179. System.out.println("You have no more tries left"); // IF USERNAME OR PASSWORD WAS WRONG, ACCESS IS NOT GRANTED.
  180. }
  181. }
  182. }
  183. System.out.println(" ");
  184. }
  185.  
  186. private static void employeeInterface() {
  187. boolean quit = false; // IS NEEDED AS THE BOOLEAN OUTSIDE OF THIS METHOD CAN'T BE ACCESSED
  188. do {
  189. System.out.println(" ");
  190. System.out.println("********************** EMPLOYEE MENU *********************");
  191. System.out.println(" ");
  192. System.out.println("1: Manage customers");
  193. System.out.println("2: Pull Statistics");
  194. System.out.println("0. Go back to Log In Screen");
  195. System.out.print("Choose menu number: ");
  196. menuItem = validateIntInput(); // CHECKS IF THE INPUT IS INDEED AN VALID INT TYPE
  197. System.out.println(" ");
  198. System.out.println("**********************************************************");
  199. System.out.println(" ");
  200. switch (menuItem) {
  201. case 1:
  202. employeeMenuManageCustomerBilling(); // HANDLES CUSTOMER BILLING MODULE
  203. break;
  204. case 2:
  205. employeeMenuExtractStatistics(); // HANDLES STATISTICS
  206. break;
  207. case 0:
  208. quit = true; // BREAKS THE LOOP WHICH LEADS US BACK ONE-STEP IN THE MENU
  209. System.out.println("Going back!");
  210. break;
  211. default: // INVALID INPUTS RECEIVES THIS MESSAGE
  212. System.out.println("Invalid choice. Try again:");
  213. }
  214. } while (!quit);
  215. }
  216.  
  217. private static void employeeMenuManageCustomerBilling() {
  218. boolean quit = false; // IS NEEDED AS THE BOOLEAN OUTSIDE OF THIS METHOD CAN'T BE ACCESSED
  219. do {
  220. System.out.println("********************** BILLING MENU **********************");
  221. System.out.println(" ");
  222. System.out.println("Where do you want to navigate?");
  223. System.out.println(" ");
  224. System.out.println("1: Billing Settings");
  225. System.out.println("2: Enter Water Measurements");
  226. System.out.println("3: Create Giro Cards");
  227. System.out.println("4: Register Cash Payment");
  228. System.out.println("5: Create Missed Payment Reminder");
  229. System.out.println("6: Shut Off Water Supply");
  230. System.out.println("7: Customer Management");
  231. System.out.println("8: Import csv.file");
  232. System.out.println("9: Check daily payment");
  233. System.out.println("10: Accumulated Tax Overview");
  234. System.out.println("0. Navigate back one step");
  235. System.out.print("Choose menu number: ");
  236. menuItem = validateIntInput();
  237. System.out.println(" ");
  238. System.out.println("**********************************************************");
  239. System.out.println(" ");
  240. switch (menuItem) {
  241. case 1:
  242. billingSettings();
  243. break;
  244. case 2:
  245. waterMeasurementInput();
  246. break;
  247. case 3:
  248. createGiroCardFiles();
  249. break;
  250. case 4:
  251. registerCashPayment();
  252. break;
  253. case 5:
  254. createMissingPaymentReminder();
  255. break;
  256. case 6:
  257. shutOffWaterSupply();
  258. break;
  259. case 7:
  260. customerManagement();
  261. break;
  262. case 8:
  263. importCsvFile();
  264. break;
  265. case 9:
  266. dailyPaymentOverview();
  267. break;
  268. case 10:
  269. accumulatedTaxOverview();
  270. break;
  271. case 0:
  272. quit = true;
  273. System.out.println("Going back one step!");
  274. break;
  275. default:
  276. System.out.println("Invalid choice. Try again: ");
  277. }
  278. } while (!quit);
  279. }
  280.  
  281.  
  282. private static void employeeMenuExtractStatistics() {
  283. boolean quit = false; // IS NEEDED AS THE BOOLEAN OUTSIDE OF THIS METHOD CAN'T BE ACCESSED
  284. do {
  285. System.out.println("********************* STATISTICS MENU ********************");
  286. System.out.println(" ");
  287. System.out.println("Where do you want to navigate?");
  288. System.out.println(" ");
  289. System.out.println("1: Extract statistic 1");
  290. System.out.println("2: Extract statistic 2");
  291. System.out.println("3: Extract statistic 3");
  292. System.out.println("0. Go back one step");
  293. System.out.print("Choose menu number: ");
  294. menuItem = validateIntInput();
  295. System.out.println(" ");
  296. System.out.println("**********************************************************");
  297. System.out.println(" ");
  298. switch (menuItem) {
  299. case 1:
  300. extractStatisticOne();
  301. break;
  302. case 2:
  303. extractStatisticTwo();
  304. break;
  305. case 3:
  306. extractStatisticThree();
  307. break;
  308. case 0:
  309. // Quit program
  310. quit = true;
  311. System.out.println("Going back one step!");
  312. break;
  313. default:
  314. System.out.println("Invalid choice. Try again: ");
  315. }
  316. } while (!quit);
  317. }
  318.  
  319. private static void billingSettings() {
  320. boolean quit = false;
  321. int settingID = 0;
  322.  
  323. Scanner input = new Scanner(System.in);
  324.  
  325.  
  326. System.out.println("Billing Settings");
  327. System.out.println("Would you like to make changes in billing settings?");
  328.  
  329. //Select and display billing data from sql payment table
  330. DB.selectSQL("SELECT * FROM tblSettings");
  331.  
  332.  
  333. do {
  334.  
  335. int menuItem; //This will save your menu choice
  336.  
  337. System.out.println("/////////////////////////////////////////");
  338. System.out.println("Press '1' for: Yes");
  339. System.out.println("Press '2' for No");
  340. System.out.print("Enter your choice here: ");
  341. menuItem = validateIntInput(); //Keep this to validate menu
  342. System.out.println("/////////////////////////////////////////");
  343.  
  344. switch (menuItem) {
  345. case 1:
  346.  
  347. do {
  348.  
  349. System.out.println("/////////////////////////////////////////");
  350. System.out.print("Please choose which setting would you like to change:");
  351. System.out.println();
  352. System.out.println("Press '1' for: Manual Fee Rate Industrial");
  353. System.out.println("Press '2' for: Manual Fee Rate Private");
  354. System.out.println("Press '3' for: Manual Fee Rate Agricultural");
  355. System.out.println("Press '4' for: Water Tax Rate Industrial");
  356. System.out.println("Press '5' for: Water Tax Rate Agricultural");
  357. System.out.println("Press '6' for: Water Tax Rate Private");
  358. System.out.println("Press '7' for: Drainage Tax Rate Private");
  359. System.out.println("Press '8' for: Drainage Tax Rate Agricultural");
  360. System.out.println("Press '9' for: Drainage Tax Rate Industrial");
  361. System.out.println("Press '10' for: Basic Water Price");
  362. System.out.println("Press '11' for: Go back to main menu");
  363.  
  364.  
  365. menuItem = validateIntInput(); //Keep this to validate menu
  366. System.out.println("/////////////////////////////////////////");
  367.  
  368. switch (menuItem) {
  369. case 1:
  370. System.out.println("Please input the new value:");
  371. double manualFeeRateIndustrial = input.nextDouble();
  372. //Update data in Manual Fee Rate Industrial field
  373. DB.updateSQL("UPDATE tblSettings SET fldManualFeeRateIndustrial=" + manualFeeRateIndustrial + "");
  374. System.out.println("Manual Fee Rate Industrial has been changed to " + manualFeeRateIndustrial);
  375. break;
  376.  
  377. case 2:
  378. System.out.println("Please input the new value:");//Enter the code that needs to run if 1 was the option choosed.
  379. double manualFeeRatePrivate = input.nextDouble();
  380. //Update data in Manual Fee Rate Private field
  381. DB.updateSQL("UPDATE tblSettings SET fldManualFeeRatePrivate= " + manualFeeRatePrivate + "");
  382. break;
  383.  
  384. case 3:
  385. System.out.println("Please input the new value:");
  386. double manualFeeRateAgriculture = input.nextDouble();
  387. //Update data in Manual Fee Rate Agriculture field
  388. DB.updateSQL("UPDATE tblSettings SET fldManualFeeRateAgriculture= " + manualFeeRateAgriculture + "");
  389. break;
  390.  
  391. case 4:
  392. System.out.println("Please input the new value:");
  393. double waterTaxRateIndustrial = input.nextDouble();
  394. //Update data in Water Tax Rate Industrial field
  395. DB.updateSQL("UPDATE tblSettings SET fldWaterTaxRateIndustrial= " + waterTaxRateIndustrial + "");
  396. break;
  397.  
  398. case 5:
  399. System.out.println("Please input the new value:");
  400. double waterTaxRateAgriculture = input.nextDouble();
  401. //Update data in Water Tax Rate Agriculture field
  402. DB.updateSQL("UPDATE tblSettings SET fldWaterTaxRateAgriculture= " + waterTaxRateAgriculture + "");
  403. break;
  404.  
  405. case 6:
  406. System.out.println("Please input the new value:");
  407. double waterTaxRatePrivate = input.nextDouble();
  408. //Update data in Water Tax Rate Private field
  409. DB.updateSQL("UPDATE tblSettings SET fldWaterTaxRatePrivate= " + waterTaxRatePrivate + "");
  410. break;
  411.  
  412. case 7:
  413. System.out.println("Please input the new value:");
  414. double drainageTaxRateAgriculture = input.nextDouble();
  415. //Update data in Drainage Tax Rate Agriculture field
  416. DB.updateSQL("UPDATE tblSettings SET fldDrainageTaxRateAgriculture= " + drainageTaxRateAgriculture + "");
  417. break;
  418.  
  419. case 8:
  420. System.out.println("Please input the new value:");
  421. double drainageTaxRatePrivate = input.nextDouble();
  422. //Update data in Drainage Tax Rate Private field
  423. DB.updateSQL("UPDATE tblSettings SET fldDrainageTaxRatePrivate= " + drainageTaxRatePrivate + "");
  424. break;
  425.  
  426. case 9:
  427. System.out.println("Please input the new value:");
  428. double drainageTaxRateIndustrial = input.nextDouble();
  429. //Update data in Drainage Tax Rate Industrial field
  430. DB.updateSQL("UPDATE tblSettings SET fldDrainageTaxRateIndustrial= " + drainageTaxRateIndustrial + "");
  431. break;
  432.  
  433. case 10:
  434. System.out.println("Please input the new value:");
  435. double basicWaterPrice = input.nextDouble();
  436. //Update data in Basic Water Price field
  437. DB.updateSQL("UPDATE tblSettings SET fldBasicWaterPrice= " + basicWaterPrice + "");
  438. break;
  439.  
  440. case 11:
  441. quit = true; //This will make the loop stop after running the program - Used when user want to go back
  442. break;
  443. default:
  444. System.out.println("Invalid choice. Try again: ");
  445. }
  446.  
  447. } while (!quit);
  448. break;
  449.  
  450. case 2:
  451. //Enter the code that needs to run if 2 was the option choosed.
  452. quit = true; //This will make the loop stop after running the program - Used when user want to go back
  453. break;
  454. default:
  455. System.out.println("Invalid choice. Try again: ");
  456. }
  457.  
  458. } while (!quit);
  459. }
  460.  
  461. private static void waterMeasurementInput() {
  462. //boolean quit = false; //This will make the loop run until you want it to quit
  463. int menuItem; //This will save your menu choice
  464.  
  465. do {
  466. System.out.println("/////////////////////////////////////////");
  467. System.out.println("Do you want to input a new water meter level? ");
  468. System.out.println("Press '1' for: Yes"); //Change these depending on the number of chioces
  469. System.out.println("Press '2' for No"); //Change these depending on the number of chioces
  470. System.out.print("Enter your choice here: ");
  471. menuItem = validateIntInput(); //Keep this to validate menu
  472. System.out.println("/////////////////////////////////////////");
  473. switch (menuItem) {
  474. case 1:
  475.  
  476. double newWaterMeterLevel = 0;
  477. boolean done = false;
  478.  
  479.  
  480. //CostumerID input
  481. while (!done) {
  482. Scanner in = new Scanner(System.in);
  483. getMaxID();
  484.  
  485. System.out.println("Input costumer ID:");
  486. if (in.hasNextInt()) {
  487. costumerID = in.nextInt();
  488.  
  489. if (costumerID > 0 && costumerID < MaxCostumerID) {
  490. DB.selectSQL("select fldCustomerName from tblCustomer where fldCustomerID = '" + costumerID + "'");
  491. String customerName = DB.getData();
  492. System.out.println(customerName);
  493. String StopValue = DB.getData();
  494. done = true;
  495. } else {
  496. System.out.println("Invalid input");
  497. }
  498. } else {
  499. System.out.println("Invalid input");
  500. }
  501. }
  502. done = false;
  503. ////////////////////////////////////
  504.  
  505. //Input Waterlevel
  506. while (!done) {
  507. Scanner in = new Scanner(System.in);
  508.  
  509. System.out.println("input new water meter level: ");
  510. if (in.hasNextDouble()) {
  511. newWaterMeterLevel = in.nextDouble();
  512.  
  513. if (newWaterMeterLevel > 0) {
  514.  
  515. done = true;
  516. } else {
  517. System.out.println("Invalid input");
  518. }
  519. } else {
  520. System.out.println("Invalid input");
  521. }
  522. }
  523. //Update fldWaterRadingThisTime
  524. DB.updateSQL("UPDATE tblWaterMeter SET fldWaterReadingThisTime = '" + newWaterMeterLevel + "' WHERE fldCustomerID = '" + costumerID + "';");
  525.  
  526. System.out.printf("CostumerID: %d \nNew water meter level: %.2f\n", costumerID, newWaterMeterLevel);
  527.  
  528. //Update fldAmountPaid
  529. DB.updateSQL("UPDATE tblPayment SET fldAmountPaid=0 WHERE fldWaterMeterID='" + FindWaterMeterID() + "'");
  530. break;
  531. case 2:
  532. //Enter the code that needs to run if 2 was the option choosed.
  533. quit = true; //This will make the loop stop after running the program - Used when user want to go back
  534. break;
  535. default:
  536. System.out.println("Invalid choice. Try again: ");
  537. }
  538. } while (!quit);
  539. }
  540.  
  541. private static void createGiroCardFiles() {
  542.  
  543. boolean quit = false; // IS NEEDED AS THE BOOLEAN OUTSIDE OF THIS METHOD CAN'T BE ACCESSED
  544.  
  545. DB.selectSQL("SELECT COUNT(fldCustomerID) FROM tblWaterMeter WHERE fldWaterReadingThisTime>0");
  546. String dbNumberOfCustomers = DB.getData();
  547. //String stopValue3 = DB.getData();
  548. int numberOfCustomers = Integer.parseInt(dbNumberOfCustomers);
  549. //System.out.println(numberOfCustomers);
  550.  
  551. DB.selectSQL("SELECT fldBasicWaterPrice FROM tblSettings");
  552. String dbBasicWaterPrice = DB.getData();
  553. //String stopValue4 = DB.getData();
  554. double basicWaterPrice = Double.parseDouble(dbBasicWaterPrice);
  555. //System.out.println(basicWaterPrice);
  556.  
  557. DB.selectSQL("SELECT fldWaterTaxRatePrivate FROM tblSettings");
  558. String dbWaterTaxPrivate = DB.getData();
  559. //String stopValue5 = DB.getData();
  560. double waterTaxPrivate = Double.parseDouble(dbWaterTaxPrivate);
  561. //System.out.println(waterTaxPrivate);
  562.  
  563. DB.selectSQL("SELECT fldWaterTaxRateAgriculture FROM tblSettings");
  564. String dbWaterTaxAgriculture = DB.getData();
  565. //String stopValue6 = DB.getData();
  566. double waterTaxAgriculture = Double.parseDouble(dbWaterTaxAgriculture);
  567. //System.out.println(waterTaxAgriculture);
  568.  
  569. DB.selectSQL("SELECT fldWaterTaxRateIndustrial FROM tblSettings");
  570. String dbWaterTaxIndustrial = DB.getData();
  571. //String stopValue7 = DB.getData();
  572. double waterTaxIndustrial = Double.parseDouble(dbWaterTaxIndustrial);
  573. //System.out.println(waterTaxIndustrial);
  574.  
  575. DB.selectSQL("SELECT fldDrainageTaxRatePrivate FROM tblSettings");
  576. String dbDrainageTaxPrivate = DB.getData();
  577. //String stopValue8 = DB.getData();
  578. double drainageTaxPrivate = Double.parseDouble(dbDrainageTaxPrivate);
  579. //System.out.println(drainageTaxPrivate);
  580.  
  581. DB.selectSQL("SELECT fldDrainageTaxRateAgriculture FROM tblSettings");
  582. String dbDrainageTaxAgriculture = DB.getData();
  583. //String stopValue9 = DB.getData();
  584. double drainageTaxAgriculture = Double.parseDouble(dbDrainageTaxAgriculture);
  585. //System.out.println(drainageTaxAgriculture);
  586.  
  587. DB.selectSQL("SELECT fldDrainageTaxRateIndustrial FROM tblSettings");
  588. String dbDrainageTaxIndustrial = DB.getData();
  589. //String stopValue10 = DB.getData();
  590. double drainageTaxIndustrial = Double.parseDouble(dbDrainageTaxIndustrial);
  591. //System.out.println(drainageTaxIndustrial);
  592.  
  593. DB.selectSQL("SELECT fldManualFeeRatePrivate FROM tblSettings");
  594. String dbManualWaterReadingFeePrivate = DB.getData();
  595. //String stopValue11 = DB.getData();
  596. double manualWaterReadingFeePrivate = Double.parseDouble(dbManualWaterReadingFeePrivate);
  597. //System.out.println(manualWaterReadingFeePrivate);
  598.  
  599. DB.selectSQL("SELECT fldManualFeeRateAgriculture FROM tblSettings");
  600. String dbManualWaterReadingFeeAgriculture = DB.getData();
  601. //String stopValue12 = DB.getData();
  602. double manualWaterReadingFeeAgriculture = Double.parseDouble(dbManualWaterReadingFeeAgriculture);
  603. //System.out.println(dbManualWaterReadingFeeAgriculture);
  604.  
  605. DB.selectSQL("SELECT fldManualFeeRateIndustrial FROM tblSettings");
  606. String dbManualWaterReadingFeeIndustrial = DB.getData();
  607. //String stopValue13 = DB.getData();
  608. double manualWaterReadingFeeIndustrial = Double.parseDouble(dbManualWaterReadingFeeIndustrial);
  609. //System.out.println(manualWaterReadingFeeIndustrial);
  610.  
  611. double amountDue = 0; //IS ONLY INITIALIZED - VALUE WILL CHANGE IN THE LOOP
  612.  
  613. do {
  614.  
  615. System.out.println(" ");
  616. System.out.println("****************** CREATE GIRO CARDS *********************");
  617. System.out.println(" ");
  618. System.out.println("Press '1' for: Yes");
  619. System.out.println("Press '2' for No");
  620. System.out.print("Enter your choice here: ");
  621. menuItem = validateIntInput();
  622. System.out.println(" ");
  623. System.out.println("**********************************************************");
  624. System.out.println(" ");
  625. switch (menuItem) {
  626. case 1:
  627. for (int i = 0; i < numberOfCustomers; i++) {
  628. //System.out.println(numberOfCustomers + i); //6
  629. DB.selectSQL("SELECT fldCustomerID FROM tblWaterMeter WHERE fldWaterReadingThisTime>0");
  630. String dbCustomerID = DB.getData();
  631. //String stopValue14 = DB.getData();
  632. int customerID = Integer.parseInt(dbCustomerID);
  633. //System.out.println(customerID); //1
  634.  
  635. DB.selectSQL("SELECT fldSegment FROM tblCustomer WHERE fldCustomerID=" + customerID );
  636. String dbCustomerSegment = DB.getData();
  637. //String stopValue15 = DB.getData();
  638. int customerSegment = Integer.parseInt(dbCustomerSegment);
  639. //System.out.println(customerSegment); //1
  640.  
  641. DB.selectSQL("SELECT fldManuelFee FROM tblWaterMeter WHERE fldCustomerID=" + customerID);
  642. String dbManuelWaterReading = DB.getData();
  643. //String stopValue16 = DB.getData();
  644. int manualWaterReading = Integer.parseInt(dbManuelWaterReading);
  645. //System.out.println(manualWaterReading); //0
  646.  
  647. DB.selectSQL("SELECT fldWaterReadingLastTime FROM tblWaterMeter WHERE fldCustomerID=" + customerID );
  648. String dbWaterReadingLastTime = DB.getData();
  649. //String stopValue17 = DB.getData();
  650. double waterReadingLastTime = Double.parseDouble(dbWaterReadingLastTime);
  651. //System.out.println(waterReadingLastTime); //4569.0
  652.  
  653. DB.selectSQL("SELECT fldWaterReadingThisTime FROM tblWaterMeter WHERE fldCustomerID=" + customerID);
  654. String dbWaterReadingThisTime = DB.getData();
  655. String stopValue18 = DB.getData();
  656. double waterReadingThisTime = Double.parseDouble(dbWaterReadingThisTime);
  657. //System.out.println(waterReadingThisTime); //5000.0
  658.  
  659. double waterUsage = waterReadingThisTime - waterReadingLastTime;
  660. //System.out.println(waterUsage); //431.0
  661.  
  662. DB.selectSQL("SELECT fldPaymentID from tblPayment WHERE fldWaterMeterID = (SELECT fldCustomerID from tblCustomer WHERE fldCustomerID = " + customerID);
  663. String dbPaymentIDString = DB.getData();
  664. String dbPaymentIDString1 = DB.getData();
  665. int paymentID = Integer.parseInt(dbPaymentIDString);
  666. //System.out.println(paymentID); //1
  667.  
  668. boolean ok = false;
  669. ok = DB.updateSQL("UPDATE tblWaterMeter SET fldWaterUsageDifference='" + waterUsage + "' WHERE fldWaterMeterID = (SELECT fldWaterMeterID FROM tblWaterMeter WHERE fldWaterMeterID ='" + paymentID + "'");
  670. System.out.println(ok);
  671.  
  672. if (customerSegment == 1 && manualWaterReading == 0) { //PRICE WILL CHANGE DEPENDING ON SEGMENT AND IF THEY'VE CHECKED THE WATER METER THEMSELVES
  673. amountDue = waterUsage * basicWaterPrice * waterTaxPrivate + waterUsage * basicWaterPrice * drainageTaxPrivate;
  674. //System.out.println("if else 1");
  675. } else if (customerSegment == 2 && manualWaterReading == 0) {
  676. amountDue = waterUsage * basicWaterPrice * waterTaxAgriculture + waterUsage * basicWaterPrice * drainageTaxAgriculture;
  677. //System.out.println("if else 2");
  678. } else if (customerSegment == 3 && manualWaterReading == 0) {
  679. amountDue = waterUsage * basicWaterPrice * waterTaxIndustrial + waterUsage * basicWaterPrice * drainageTaxIndustrial;
  680. //System.out.println("if else 3");
  681. } else if (customerSegment == 1 && manualWaterReading == 1) {
  682. amountDue = waterUsage * basicWaterPrice * waterTaxPrivate + waterUsage * basicWaterPrice * drainageTaxPrivate + manualWaterReadingFeePrivate;
  683. //System.out.println("if else 4");
  684. } else if (customerSegment == 2 && manualWaterReading == 1) {
  685. amountDue = waterUsage * basicWaterPrice * waterTaxAgriculture + waterUsage * basicWaterPrice * drainageTaxAgriculture + manualWaterReadingFeeAgriculture;
  686. //System.out.println("if else 1");
  687. } else if (customerSegment == 3 && manualWaterReading == 1) {
  688. amountDue = waterUsage * basicWaterPrice * waterTaxIndustrial + waterUsage * basicWaterPrice * drainageTaxIndustrial + manualWaterReadingFeeIndustrial;
  689. //System.out.println("if else 1");
  690. } else {
  691. System.out.println("Error");
  692. }
  693.  
  694. //THIS WILL UPDATE THE AMOUNT DUE FOR EACH CUSTOMER IN THE LOOP
  695. boolean ok2 = false;
  696. ok2 = DB.updateSQL("UPDATE tblPayment SET fldAmountDue='" + amountDue + "' WHERE fldPaymentID ='" + paymentID + "'");
  697. System.out.println(ok2); //true
  698.  
  699. double basicWaterPriceAmount = waterUsage * basicWaterPrice;
  700. //System.out.println(basicWaterPriceAmount); //1293.0
  701. double waterTaxAmountPrivate = waterUsage * waterTaxPrivate;
  702. //System.out.println(waterTaxAmountPrivate); //129.299999998
  703. double waterTaxAmountAgriculture = waterUsage * waterTaxAgriculture;
  704. //System.out.println(waterTaxAmountAgriculture); // 150.85
  705. double waterTaxAmountIndustrial = waterUsage * waterTaxIndustrial;
  706. //System.out.println(waterTaxAmountIndustrial); //172.4
  707. double drainageTaxAmountPrivate = waterUsage * drainageTaxPrivate;
  708. //System.out.println(drainageTaxAmountPrivate);//172.4
  709. double drainageTaxAmountAgriculture = waterUsage * drainageTaxAgriculture;
  710. //System.out.println(drainageTaxAmountAgriculture); //193.9500000000002
  711. double drainageTaxAmountIndustrial = waterUsage * drainageTaxIndustrial;
  712. //System.out.println(drainageTaxAmountIndustrial); //215.5
  713.  
  714. String filename = Integer.toString(customerID);
  715. //System.out.println(filename); //1
  716.  
  717. DB.selectSQL("SELECT fldCustomerName FROM tblCustomer WHERE fldCustomerID='" + customerID + "'");
  718. String customerName = DB.getData();
  719. //String stopValue21 = DB.getData();
  720. //System.out.println(customerName); // Bob Hansen
  721.  
  722. DB.selectSQL("SELECT fldAddress FROM tblCustomer WHERE fldCustomerID='" + customerID + "'");
  723. String address = DB.getData();
  724. String address2 = DB.getData();
  725. //String stopValue22 = DB.getData();
  726. //System.out.println(address); // Havneborg 1
  727.  
  728. String waterReadingLastTimeString = Double.toString(waterReadingLastTime);
  729. String waterReadingThisTimeString = Double.toString(waterReadingThisTime);
  730. String waterUsageString = Double.toString(waterUsage);
  731. String basicWaterPriceAmountString = Double.toString(basicWaterPriceAmount);
  732. String waterTaxAmountPrivateString = Double.toString(waterTaxAmountPrivate);
  733. String waterTaxAmountAgricultureString = Double.toString(waterTaxAmountAgriculture);
  734. String waterTaxAmountIndustrialString = Double.toString(waterTaxAmountIndustrial);
  735. String drainageTaxAmountPrivateString = Double.toString(drainageTaxAmountPrivate);
  736. String drainageTaxAmountAgricultureString = Double.toString(drainageTaxAmountAgriculture);
  737. String drainageTaxAmountIndustrialString = Double.toString(drainageTaxAmountIndustrial);
  738. String amountDueString = Double.toString(amountDue);
  739. String manuelReadingFeePrivateString = Double.toString(manualWaterReadingFeePrivate);
  740. String manuelReadingFeeAgricultureString = Double.toString(manualWaterReadingFeeAgriculture);
  741. String manuelReadingFeeIndustrialString = Double.toString(manualWaterReadingFeeIndustrial);
  742. String accountNumber = "Reg nr: 4578 - Account Number: 0004578988"; //IDEALLY THIS WOULD HAVE BEEN A SETTING SO IT COULD HAVE BEEN CHANGED LATER ON - TIME THOUGH.
  743.  
  744. // ADDS A DEADLINE 14 DAYS FROM TODAY
  745. int deadlineDifferenceFromTodaysDate = 14;
  746. Calendar cal = Calendar.getInstance();
  747. cal.add(Calendar.DAY_OF_YEAR, deadlineDifferenceFromTodaysDate);
  748. Date date = cal.getTime();
  749. DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
  750. String deadlineDate = df.format(date);
  751.  
  752. // ADDS TODAY's DATE
  753. Calendar cal1 = Calendar.getInstance();
  754. Date datesDate = cal1.getTime();
  755. DateFormat datesDateFormat = new SimpleDateFormat("dd/MM/yyyy");
  756. String todaysDate = datesDateFormat.format(datesDate);
  757.  
  758. final String FILELOCATION = "F:\\waterwork giro cards\\" + filename + ".doc"; //This is where we store giro-card files
  759. try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILELOCATION))) {
  760.  
  761. bw.write("\t" + customerName + "\n");
  762. bw.write("\t" + address + "\n");
  763. bw.write("\t" + todaysDate + "\n");
  764. bw.newLine();
  765. bw.newLine();
  766. bw.write("Consumption\n");
  767. bw.write("Water reading last time: " + waterReadingLastTimeString + " m3\n");
  768. bw.write("Water reading this time: " + waterReadingThisTimeString + " m3\n");
  769. bw.write("Water used in m3: " + waterUsageString + " m3\n");
  770. bw.newLine();
  771. bw.write("Price breakdown\n");
  772. if (customerSegment == 1 && manualWaterReading == 0) {
  773. bw.write("Base Water Price Total: " + basicWaterPriceAmountString + ",- incl. VAT\n");
  774. bw.write("Water Tax Total: " + waterTaxAmountPrivateString + ",- incl. VAT\n");
  775. bw.write("Drainage Tax Total: " + drainageTaxAmountPrivateString + ",- incl. VAT\n");
  776. bw.newLine();
  777. bw.write("Total Amount Due: " + amountDueString + ",- incl. VAT\n");
  778. } else if (customerSegment == 2 && manualWaterReading == 0) {
  779. bw.write("Base Water Price Total: " + basicWaterPriceAmountString + ",- incl. VAT\n");
  780. bw.write("Water Tax Total: " + waterTaxAmountAgricultureString + ",- incl. VAT\n");
  781. bw.write("Drainage Tax Total: " + drainageTaxAmountAgricultureString + ",- incl. VAT\n");
  782. bw.newLine();
  783. bw.write("Total Amount Due: " + amountDueString + ",- incl. VAT\n");
  784. } else if (customerSegment == 3 && manualWaterReading == 0) {
  785. bw.write("Base Water Price Total: " + basicWaterPriceAmountString + ",- incl. VAT\n");
  786. bw.write("Water Tax Total: " + waterTaxAmountIndustrialString + ",- incl. VAT\n");
  787. bw.write("Drainage Tax Total: " + drainageTaxAmountIndustrialString + ",- incl. VAT\n");
  788. bw.newLine();
  789. bw.write("Total Amount Due: " + amountDueString + ",- incl. VAT\n");
  790. } else if (customerSegment == 1 && manualWaterReading == 1) {
  791. bw.write("Base Water Price Total: " + basicWaterPriceAmountString + ",- incl. VAT\n");
  792. bw.write("Water Tax Total: " + waterTaxAmountPrivateString + ",- incl. VAT\n");
  793. bw.write("Drainage Tax Total: " + drainageTaxAmountPrivateString + ",- incl. VAT\n");
  794. bw.write("Manual Reading Fee: " + manuelReadingFeePrivateString + ",- incl. VAT\n");
  795. bw.newLine();
  796. bw.write("Total Amount Due: " + amountDueString + ",- incl. VAT\n");
  797. } else if (customerSegment == 2 && manualWaterReading == 1) {
  798. bw.write("Base Water Price Total: " + basicWaterPriceAmountString + ",- incl. VAT\n");
  799. bw.write("Water Tax Total: " + waterTaxAmountAgricultureString + ",- incl. VAT\n");
  800. bw.write("Drainage Tax Total: " + drainageTaxAmountAgricultureString + ",- incl. VAT\n");
  801. bw.write("Manual Reading Fee: " + manuelReadingFeeAgricultureString + ",- incl. VAT\n");
  802. bw.newLine();
  803. bw.write("Total Amount Due: " + amountDueString + ",- incl. VAT\n");
  804. } else if (customerSegment == 3 && manualWaterReading == 1) {
  805. bw.write("Base Water Price Total: " + basicWaterPriceAmountString + ",- incl. VAT\n");
  806. bw.write("Water Tax Total: " + waterTaxAmountIndustrialString + ",- incl. VAT\n");
  807. bw.write("Drainage Tax Total: " + drainageTaxAmountIndustrialString + ",- incl. VAT\n");
  808. bw.write("Manual Reading Fee: " + manuelReadingFeeIndustrialString + ",- incl. VAT\n");
  809. bw.newLine();
  810. bw.write("Total Amount Due: " + amountDueString + ",- incl. VAT\n");
  811. }
  812. bw.newLine();
  813. bw.write("Payment is due before the: " + deadlineDate + "\n");
  814. bw.write("Please use this Payment ID when transferring the money: " + dbPaymentIDString + "\n");
  815. bw.write("Account number: " + accountNumber + "\n");
  816. bw.newLine();
  817. bw.write("Uptown WaterWork - Waterwork Road 1, 6400 Sønderborg - CVR: 12345678");
  818.  
  819. /** TEST **/
  820. //System.out.println("Giro Card for CustomerID: " + customerID + " was saved correctly"); // This lets the employee see that it was successful.
  821. //System.out.println("WaterReadingThisTime: " + waterReadingThisTimeString);
  822. //System.out.println("CustomerID: " + customerID);
  823. //System.out.println("AmountDue: " + amountDueString);
  824. //System.out.println("PaymentID: " + paymentID);
  825. //System.out.println(basicWaterPriceAmountString);
  826. //System.out.println(waterTaxAmountPrivateString);
  827. //System.out.println(drainageTaxAmountPrivateString);
  828.  
  829. boolean ok3 = false;
  830. ok3 = DB.updateSQL("UPDATE tblWaterMeter SET fldWaterReadingLastTime='" + waterReadingThisTimeString + "' WHERE fldCustomerID ='" + customerID + "'");
  831. System.out.println(ok3);
  832. boolean ok4 = false;
  833. ok4 = DB.updateSQL("UPDATE tblWaterMeter SET fldWaterReadingThisTime = 0 WHERE fldCustomerID ='" + customerID + "'");
  834. System.out.println(ok4);
  835. } catch (IOException e) { //This is an error message (debugging safety) that will give a notice if something fails.
  836.  
  837. e.printStackTrace();
  838.  
  839. }
  840. }
  841. System.out.println("All Giro-cards have been created.");
  842. quit = true; //Stops the loop - Task finished
  843. break;
  844. case 2:
  845. quit = true; //Goes back to previous menu.
  846. break;
  847. default:
  848. System.out.println("Invalid choice. Try again: ");
  849. }
  850. } while (!quit);
  851. }
  852.  
  853. private static void registerCashPayment() {
  854.  
  855. do {
  856. //boolean quit = false; //This will make the loop run until you want it to quit
  857. int menuItem; //This will save your menu choice
  858.  
  859. System.out.println("/////////////////////////////////////////");
  860. System.out.println("Do you want to input a Manual payment? ");
  861. System.out.println("Press '1' for: Yes"); //Change these depending on the number of chioces
  862. System.out.println("Press '2' for No"); //Change these depending on the number of chioces
  863. System.out.print("Enter your choice here: ");
  864. menuItem = validateIntInput(); //Keep this to validate menu
  865. System.out.println("/////////////////////////////////////////");
  866. switch (menuItem) {
  867. case 1:
  868. boolean IDDone = false;
  869.  
  870.  
  871. while (!IDDone)
  872. if (CostumerIDtjeck()) {
  873. DB.selectSQL("select fldCustomerName from tblCustomer where fldCustomerID = '"+costumerID+"'");
  874. String customerName = DB.getData();
  875. System.out.println(customerName);
  876. String StopValue = DB.getData();
  877. System.out.println("CostumerID: " + costumerID);
  878. IDDone = true;
  879. } else {
  880. System.out.println("Invalid input\n");
  881. }
  882.  
  883. int diffInt = paymentjeck();
  884. if (diffInt == 0) {
  885. System.out.println("The amount due is now payed");
  886. DB.updateSQL("UPDATE tblPayment SET fldAmountDue=0, fldPaymentType='Cash',fldAmountPaid='"+ receivedamount+"' WHERE fldWaterMeterID='"+FindWaterMeterID()+"'");
  887.  
  888.  
  889. }
  890. if (diffInt == 1) {
  891. System.out.println("The costumer payed to much");
  892. double payBack = Math.abs(diff);
  893. System.out.println("The costumer should have " + payBack + " kr. back");
  894. DB.updateSQL("UPDATE tblPayment SET fldAmountDue=0, fldPaymentType='Cash', fldAmountPaid='"+findOldAmount() +"' WHERE fldWaterMeterID='"+FindWaterMeterID()+"'");
  895.  
  896. }
  897. if (diffInt == 2)
  898. {
  899. System.out.println("The costumer didn't pay enough");
  900. System.out.println("New amount due: "+ diff );
  901. DB.updateSQL("UPDATE tblPayment SET fldAmountDue='"+diff+"', fldAmountPaid='"+receivedamount +"',fldPaymentType='Cash' WHERE fldWaterMeterID='"+FindWaterMeterID()+"'");
  902. }
  903. System.out.println("input payment date: (YYYY-MM-DD");
  904. Scanner in = new Scanner(System.in);
  905. String date = in.next();
  906. DB.updateSQL("UPDATE tblPayment SET fldPaymentDate ='"+date+"' WHERE fldWaterMeterID='"+FindWaterMeterID()+"'");
  907. break;
  908. case 2:
  909. //Enter the code that needs to run if 2 was the option choosed.
  910. quit = true; //This will make the loop stop after running the program - Used when user want to go back
  911. break;
  912. default:
  913. System.out.println("Invalid choice. Try again: ");
  914. }
  915. } while (!quit);
  916. }
  917.  
  918. private static void createMissingPaymentReminder() {
  919. boolean quit = false; // IS NEEDED AS THE BOOLEAN OUTSIDE OF THIS METHOD CAN'T BE ACCESSED
  920.  
  921. DB.selectSQL("SELECT COUNT(fldwaterMeterID) FROM tblPayment WHERE fldAmountDue > 0"); //Will create a reminder for everyone who has an amount due
  922. String dbAmountOfCustomers = DB.getData();
  923. int amountOfCustomers = Integer.parseInt(dbAmountOfCustomers);
  924.  
  925. do {
  926. System.out.println(" ");
  927. System.out.println("****************** CREATE Reminders **********************");
  928. System.out.println(" ");
  929. System.out.println("Press '1' for: Yes");
  930. System.out.println("Press '2' for No");
  931. System.out.print("Enter your choice here: ");
  932. menuItem = validateIntInput();
  933. System.out.println(" ");
  934. System.out.println("**********************************************************");
  935. System.out.println(" ");
  936. switch (menuItem) {
  937. case 1:
  938. for (int i = 0; i < amountOfCustomers; i++) {
  939.  
  940. System.out.println(amountOfCustomers); //6
  941. DB.selectSQL("SELECT fldWaterMeterID FROM tblPayment WHERE fldAmountDue>0");
  942. String dbCustomerID = DB.getData();
  943. String stopValue14 = DB.getData();
  944. int customerID = Integer.parseInt(dbCustomerID);
  945. System.out.println(customerID);
  946.  
  947. DB.selectSQL("SELECT fldPaymentID from tblPayment WHERE fldWaterMeterID = (SELECT fldCustomerID from tblCustomer WHERE fldCustomerID = '" + customerID + "')");
  948. String dbPaymentIDString = DB.getData();
  949. //String dbPaymentIDString1 = DB.getData();
  950. int paymentID = Integer.parseInt(dbPaymentIDString);
  951. System.out.println(paymentID);
  952.  
  953. DB.selectSQL("SELECT fldAmountDue from tblPayment WHERE fldWaterMeterID = (SELECT fldCustomerID from tblCustomer WHERE fldCustomerID = '" + customerID + "')");
  954. String dbAmountDueString = DB.getData();
  955. double amountDue = Double.parseDouble(dbAmountDueString);
  956. System.out.println(amountDue);
  957.  
  958. DB.selectSQL("SELECT fldCustomerName FROM tblCustomer WHERE fldCustomerID='" + customerID + "'");
  959. String customerName = DB.getData();
  960. System.out.println(customerName);
  961.  
  962. String filename = Integer.toString(customerID);
  963.  
  964. DB.selectSQL("SELECT fldAddress FROM tblCustomer WHERE fldCustomerID='" + customerID + "'");
  965. String address = DB.getData();
  966. System.out.println(address);
  967.  
  968. String accountNumber = "Reg nr: 4578 - Account Number: 0004578988"; //IDEALLY THIS WOULD HAVE BEEN A SETTING SO IT COULD HAVE BEEN CHANGED LATER ON - TIME THOUGH...
  969. String paymentIDString = Integer.toString(paymentID);
  970. String amountDueString = Double.toString(amountDue);
  971.  
  972. // ADDS TODAY's DATE
  973. Calendar cal1 = Calendar.getInstance();
  974. Date datesDate = cal1.getTime();
  975. DateFormat datesDateFormat = new SimpleDateFormat("dd/MM/yyyy");
  976. String todaysDate = datesDateFormat.format(datesDate);
  977.  
  978. final String FILELOCATION = "F:\\waterwork reminders\\" + filename + "reminder.doc"; //This is where we store giro-card files
  979. try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILELOCATION))) {
  980.  
  981. bw.write("\t" + customerName + "\n");
  982. bw.write("\t" + address + "\n");
  983. bw.write("\t" + todaysDate + "\n");
  984. bw.newLine();
  985. bw.newLine();
  986. bw.write("Total Amount Overdue: " + amountDueString + ",- incl. VAT\n");
  987. bw.write("Please use this Payment ID when transferring the money: " + dbPaymentIDString + "\n");
  988. bw.write("Account number: " + accountNumber + "\n");
  989. bw.newLine();
  990. bw.write("Please pay within 7 days or you'll receive another reminder. At the third reminder we'll shut off the water supply to your address.\n");
  991. bw.newLine();
  992. bw.write("Uptown WaterWork - Waterwork Road 1, 6400 Sønderborg - CVR: 12345678");
  993.  
  994.  
  995. System.out.println("Giro Card for CustomerID: " + customerID + " was saved correctly"); // This lets the employee see that it was successful.
  996.  
  997. } catch (IOException e) { //This is an error message (debugging safety) that will give a notice if something fails.
  998.  
  999. e.printStackTrace();
  1000.  
  1001. }
  1002. DB.selectSQL("SELECT fldReminders FROM tblPayment WHERE fldWaterMeterID=(SELECT fldCustomerID FROM tblWaterMeter WHERE fldCustomerID = '" + customerID + "')");
  1003. String dbNumberOfReminders = DB.getData();
  1004. String stopValue = DB.getData();
  1005. int numberOfReminders = Integer.parseInt(dbNumberOfReminders);
  1006. numberOfReminders++;
  1007.  
  1008. boolean ok = false;
  1009. ok = DB.updateSQL("UPDATE tblPayment SET fldReminders = '" + numberOfReminders + "'");
  1010. System.out.println(ok);
  1011. }
  1012. System.out.println("All reminders have been created.");
  1013. quit = true; //Stops the loop - Task finished
  1014. break;
  1015. case 2:
  1016. quit = true; //Goes back to previous menu.
  1017. break;
  1018. default:
  1019. System.out.println("Invalid choice. Try again: ");
  1020. }
  1021. } while (!quit);
  1022. }
  1023.  
  1024. private static void shutOffWaterSupply() {
  1025. System.out.println("Shut Off Water Supply");
  1026. }
  1027.  
  1028. private static void customerManagement() {
  1029. Scanner input = new Scanner(System.in);
  1030. String customerName;
  1031.  
  1032.  
  1033. String customerNewName = "";
  1034. String customerOldName;
  1035. String oldAddress;
  1036. String newAddress;
  1037. String oldMoveInDate;
  1038. String newMoveInDate;
  1039. String oldSegment;
  1040. String newSegment;
  1041. int oldNoOfWaterMeters;
  1042. int newNoOfWaterMeters;
  1043. int oldZipcode;
  1044. int newZipcode;
  1045. String moveInDate;
  1046. String zipcode;
  1047. String address;
  1048. String segment;
  1049. String waterMeter;
  1050. String moveOutDate;
  1051. String customerID;
  1052. boolean quit = false;
  1053.  
  1054.  
  1055. do {
  1056.  
  1057. int menuItem; //This will save your menu choice
  1058.  
  1059.  
  1060. System.out.println("/////////////////////////////////////////");
  1061. System.out.println("Press '1' for: Adding new customer"); //Change these depending on the number of choices
  1062. System.out.println("Press '2' for: Deleting customer"); //Change these depending on the number of choices
  1063. System.out.println("Press '3' for: Update customer");
  1064. System.out.println("Press '4' for: Returning to the main menu"); //
  1065. System.out.print("Enter your choice here: ");
  1066. menuItem = validateIntInput(); //Keep this to validate menu
  1067. System.out.println("/////////////////////////////////////////");
  1068. switch (menuItem) {
  1069. case 1: //
  1070.  
  1071.  
  1072. System.out.println("Enter the customer name:");
  1073. customerName = input.next();
  1074.  
  1075. System.out.println("Enter the address:");
  1076. input.nextLine();
  1077. address = input.nextLine();
  1078.  
  1079.  
  1080. System.out.println("Enter the zipcode:");
  1081. zipcode = input.next();
  1082.  
  1083. System.out.println("Enter the move in date:");
  1084. moveInDate = input.next();
  1085.  
  1086. System.out.println("Enter the move out date");
  1087. moveOutDate = input.next();
  1088.  
  1089. System.out.println("Enter the segment:");
  1090. segment = input.next();
  1091.  
  1092. System.out.println("Enter the number of water meters:");
  1093. waterMeter = input.next();
  1094.  
  1095.  
  1096. //Inserting new data into the customer table
  1097.  
  1098. DB.insertSQL("INSERT INTO tblCustomer (fldCustomerName, fldAddress, fldZipcode, fldMoveInDate, fldSegment, fldNumberOfWaterMeters, fldMoveOutDate) VALUES('" + customerName + "', '" + address + "', '" + zipcode + "', '" + moveInDate + "', '" + segment + "', '" + waterMeter + "', '" + moveOutDate + "')");
  1099. System.out.println(customerName + " " + address + " " + zipcode + " " + moveInDate + " " + segment + " " + waterMeter + " " + moveOutDate);
  1100. break;
  1101.  
  1102.  
  1103. case 2:
  1104.  
  1105. DB.selectSQL("SELECT fldCustomerName FROM tblCustomer");
  1106. do {
  1107. String data = DB.getDisplayData();
  1108. if (data.equals(DB.NOMOREDATA)) {
  1109. break;
  1110. } else
  1111. System.out.print(data);
  1112. }
  1113. while (true);
  1114.  
  1115. System.out.println("You can enter the customer name here you want to delete from the system:");
  1116. customerName = input.next();
  1117.  
  1118. //Delete data
  1119. DB.deleteSQL("DELETE from tblCustomer where fldCustomerName='" + customerName + "';");
  1120. System.out.println(customerName + " is removed from the list");
  1121.  
  1122. break;
  1123.  
  1124. case 3:
  1125.  
  1126. System.out.println("You can update information about customers here:");
  1127.  
  1128. DB.selectSQL("SELECT fldCustomerName FROM tblCustomer");
  1129. do {
  1130. String data = DB.getDisplayData();
  1131. if (data.equals(DB.NOMOREDATA)) {
  1132. break;
  1133. } else
  1134. System.out.print(data);
  1135. }
  1136. while (true);
  1137.  
  1138. do {
  1139.  
  1140. System.out.println("/////////////////////////////////////////");
  1141. System.out.print("Please choose which information would you like to update:");
  1142. System.out.println();
  1143. System.out.println("Press '1' for: Customer Name");
  1144. System.out.println("Press '2' for: Address");
  1145. System.out.println("Press '3' for: Zipcode");
  1146. System.out.println("Press '4' for: Move in date");
  1147. System.out.println("Press '5' for: Segment");
  1148. System.out.println("Press '6' for: Number of Water meters");
  1149. System.out.println("Press '7' for: Go back to main menu");
  1150.  
  1151.  
  1152. menuItem = validateIntInput(); //Keep this to validate menu
  1153. System.out.println("/////////////////////////////////////////");
  1154.  
  1155. switch (menuItem) {
  1156. case 1:
  1157. System.out.println("Please input the customer name what you want to change:");//Enter the code that needs to run if 1 was the option choosed.
  1158. //input = input.reset();
  1159. input.nextLine();
  1160. customerOldName = input.nextLine();
  1161. System.out.println(customerOldName);
  1162. DB.selectSQL("SELECT fldCustomerName, fldCustomerID FROM tblCustomer WHERE fldCustomerName='" + customerOldName + "';");//
  1163. do {
  1164. String data = DB.getDisplayData();
  1165. if (data.equals(DB.NOMOREDATA)) {
  1166. break;
  1167. } else
  1168. System.out.print(data);
  1169. }
  1170. while (true);
  1171. System.out.println("Insert Customer ID");
  1172. customerID = input.next();
  1173. System.out.println("Insert New Name");
  1174. input.nextLine();
  1175. customerNewName = input.nextLine();
  1176.  
  1177. //Update data in Customer Name field
  1178. if (customerNewName.length() > 0) {
  1179. DB.updateSQL("UPDATE tblCustomer SET fldCustomerName='" + customerNewName + "' WHERE fldCustomerID='" + customerID + "'");
  1180. System.out.println("Customer number " + customerID + " has his name changed to " + customerNewName);
  1181. }
  1182. break;
  1183.  
  1184. case 2:
  1185. System.out.println("Please input the old address which you want to change:");
  1186. oldAddress = input.nextLine();
  1187.  
  1188. System.out.println(oldAddress);
  1189. DB.selectSQL("SELECT fldAddress, fldCustomerID FROM tblCustomer WHERE fldAddress='" + oldAddress + "';");//
  1190. do {
  1191. String data = DB.getDisplayData();
  1192. if (data.equals(DB.NOMOREDATA)) {
  1193. break;
  1194. } else
  1195. System.out.print(data);
  1196. }
  1197. while (true);
  1198.  
  1199. System.out.println("Insert Customer ID");
  1200. customerID = input.next();
  1201.  
  1202. System.out.println("Please input the new address:");
  1203. input.nextLine();
  1204. newAddress = input.nextLine();
  1205.  
  1206. //Update data in Address field
  1207. DB.updateSQL("UPDATE tblCustomer SET fldAddress='" + newAddress + "' WHERE fldCustomerID='" + customerID + "'");
  1208. System.out.println("Customer number " + customerID + " has his name changed to " + newAddress);
  1209. break;
  1210.  
  1211. case 3://
  1212. System.out.println("Please input the old zipcode which you want to change:");
  1213. oldZipcode = input.nextInt();
  1214.  
  1215. System.out.println(oldZipcode);
  1216. DB.selectSQL("SELECT fldZipcode, fldCustomerID FROM tblCustomer WHERE fldZipcode='" + oldZipcode + "';");//
  1217. do {
  1218. String data = DB.getDisplayData();
  1219. if (data.equals(DB.NOMOREDATA)) {
  1220. break;
  1221. } else
  1222. System.out.print(data);
  1223. }
  1224. while (true);
  1225.  
  1226. System.out.println("Insert Customer ID");
  1227. customerID = input.next();
  1228.  
  1229. System.out.println("Please input the new zipcode:");
  1230. input.nextLine();
  1231. newZipcode = input.nextInt();
  1232.  
  1233. //Update data in Address field
  1234. DB.updateSQL("UPDATE tblCustomer SET fldZipcode='" + newZipcode + "' WHERE fldCustomerID='" + customerID + "'");
  1235. System.out.println("Customer number " + customerID + " has his name changed to " + newZipcode);
  1236. break;
  1237.  
  1238.  
  1239. case 4:
  1240. System.out.println("Please input the old move in date which you want to change:");
  1241. oldMoveInDate = input.next();
  1242.  
  1243. System.out.println(oldMoveInDate);
  1244. DB.selectSQL("SELECT fldMoveInDate, fldCustomerID FROM tblCustomer WHERE fldMoveInDate='" + oldMoveInDate + "';");//
  1245. do {
  1246. String data = DB.getDisplayData();
  1247. if (data.equals(DB.NOMOREDATA)) {
  1248. break;
  1249. } else
  1250. System.out.print(data);
  1251. }
  1252. while (true);
  1253.  
  1254. System.out.println("Insert Customer ID");
  1255. customerID = input.next();
  1256.  
  1257. System.out.println("Please input the new date of move in:");
  1258. input.nextLine();
  1259. newMoveInDate = input.next();
  1260.  
  1261. //Update data in Address field
  1262. DB.updateSQL("UPDATE tblCustomer SET fldMoveInDate='" + newMoveInDate + "' WHERE fldCustomerID='" + customerID + "'");
  1263. System.out.println("Customer number " + customerID + " has his name changed to " + newMoveInDate);
  1264. System.out.println();
  1265. break;
  1266.  
  1267.  
  1268. case 5:
  1269. System.out.println("Please input the old segment type which you want to change:");
  1270. oldSegment = input.next();
  1271.  
  1272. System.out.println(oldSegment);
  1273. DB.selectSQL("SELECT fldSegment, fldCustomerID FROM tblCustomer WHERE fldSegment='" + oldSegment + "';");//
  1274. do {
  1275. String data = DB.getDisplayData();
  1276. if (data.equals(DB.NOMOREDATA)) {
  1277. break;
  1278. } else
  1279. System.out.print(data);
  1280. }
  1281. while (true);
  1282.  
  1283. System.out.println("Insert Customer ID");
  1284. customerID = input.next();
  1285.  
  1286. System.out.println("Please input the new segment type:");
  1287. input.nextLine();
  1288. newSegment = input.next();
  1289.  
  1290. //Update data in Address field
  1291. DB.updateSQL("UPDATE tblCustomer SET fldSegment='" + newSegment + "' WHERE fldCustomerID='" + customerID + "'");
  1292. System.out.println("Customer number " + customerID + " has his name changed to " + newSegment);
  1293. System.out.println();
  1294. break;
  1295.  
  1296. case 6:
  1297. System.out.println("Please input the number of water meters which you want to change:");
  1298. oldNoOfWaterMeters = input.nextInt();
  1299.  
  1300. System.out.println(oldNoOfWaterMeters);
  1301. DB.selectSQL("SELECT fldNumberOfWaterMeters, fldCustomerID FROM tblCustomer WHERE fldNumberOfWaterMeters='" + oldNoOfWaterMeters + "';");//
  1302. do {
  1303. String data = DB.getDisplayData();
  1304. if (data.equals(DB.NOMOREDATA)) {
  1305. break;
  1306. } else
  1307. System.out.print(data);
  1308. }
  1309. while (true);
  1310.  
  1311. System.out.println("Insert Customer ID");
  1312. customerID = input.next();
  1313.  
  1314. System.out.println("Please input the new number of water meters:");
  1315. input.nextLine();
  1316. newNoOfWaterMeters = input.nextInt();
  1317.  
  1318. //Update data in Address field
  1319. DB.updateSQL("UPDATE tblCustomer SET fldNoOfWaterMeters='" + newNoOfWaterMeters + "' WHERE fldCustomerID='" + customerID + "'");
  1320. System.out.println("Customer number " + customerID + " has his name changed to " + newNoOfWaterMeters);
  1321. System.out.println();
  1322. break;
  1323.  
  1324. case 7:
  1325. quit = true; //This will make the loop stop after running the program - Used when user want to go back
  1326. break;
  1327. default:
  1328. System.out.println("Invalid choice. Try again: ");
  1329. }
  1330.  
  1331. } while (!quit);
  1332. break;
  1333.  
  1334. case 4:
  1335. quit = true; //This will make the loop stop after running the program - Used when user want to go back
  1336. break;
  1337. default:
  1338. System.out.println("Invalid choice. Try again: ");
  1339. }
  1340. } while (!quit);
  1341. }
  1342.  
  1343. private static void importCsvFile() {
  1344. System.out.println("Import .csv File");
  1345. }
  1346.  
  1347. private static void dailyPaymentOverview() {
  1348. System.out.println("Daily Payment Overview");
  1349. }
  1350.  
  1351. private static void accumulatedTaxOverview() {
  1352. System.out.println("Accumulated Tax Overview");
  1353. }
  1354.  
  1355. private static void extractStatisticOne() {
  1356. System.out.println("Extract statistic 1");
  1357.  
  1358.  
  1359. DB.selectSQL("SELECT * from tblCustomer where fldSegment=1 (select avg(fldWaterReadingLastTime) from tblWaterMeter)");
  1360.  
  1361. do {
  1362. String data = DB.getDisplayData();
  1363. if (data.equals(DB.NOMOREDATA)) {
  1364. break;
  1365. } else
  1366. System.out.print(data);
  1367. }
  1368. while (true);
  1369. System.out.println("***********************************");
  1370.  
  1371. DB.selectSQL("SELECT * from tblCustomer where fldSegment=2 (select (fldWaterReadingLastTime) from tblWaterMeter)");
  1372.  
  1373. do {
  1374. String data = DB.getDisplayData();
  1375. if (data.equals(DB.NOMOREDATA)) {
  1376. break;
  1377. } else
  1378. System.out.print(data);
  1379. }
  1380. while (true);
  1381. System.out.println("***********************************");
  1382.  
  1383.  
  1384. DB.selectSQL("SELECT * from tblCustomer where fldSegment=1 (select avg(fldWaterReadingThisTime) from tblWaterMeter)");
  1385.  
  1386. do {
  1387. String data = DB.getDisplayData();
  1388. if (data.equals(DB.NOMOREDATA)) {
  1389. break;
  1390. } else
  1391. System.out.print(data);
  1392. }
  1393. while (true);
  1394. System.out.println("***********************************");
  1395.  
  1396. DB.selectSQL("SELECT * from tblCustomer where fldSegment=2 (select avg(fldWaterReadingThisTime) from tblWaterMeter)");
  1397.  
  1398. do {
  1399. String data = DB.getDisplayData();
  1400. if (data.equals(DB.NOMOREDATA)) {
  1401. break;
  1402. } else
  1403. System.out.print(data);
  1404. }
  1405. while (true);
  1406. System.out.println("***********************************");
  1407.  
  1408. DB.selectSQL("SELECT * from tblCustomer where fldSegment=3 (select avg(fldWaterReadingThisTime) from tblWaterMeter)");
  1409.  
  1410. do {
  1411. String data = DB.getDisplayData();
  1412. if (data.equals(DB.NOMOREDATA)) {
  1413. break;
  1414. } else
  1415. System.out.print(data);
  1416. }
  1417. while (true);
  1418. System.out.println("***********************************");
  1419.  
  1420. DB.selectSQL("SELECT * from tblCustomer where fldSegment=2 (select avg(fldWaterReadingLastTime) from tblWaterMeter)");
  1421.  
  1422. do {
  1423. String data = DB.getDisplayData();
  1424. if (data.equals(DB.NOMOREDATA)) {
  1425. break;
  1426. } else
  1427. System.out.print(data);
  1428. }
  1429. while (true);
  1430. System.out.println("***********************************");
  1431. }
  1432.  
  1433.  
  1434. private static void extractStatisticTwo() {
  1435. System.out.println("Extract statistic 2");
  1436. }
  1437.  
  1438. private static void extractStatisticThree() {
  1439. System.out.println("Extract statistic 3");
  1440. }
  1441.  
  1442. private static int validateIntInput() {
  1443. // VALIDATES IF THE INPUT IS AN INT
  1444. Scanner input = new Scanner(System.in);
  1445. while (true) {
  1446. try {
  1447. int a = input.nextInt();
  1448. if (a == 0) {
  1449. return 0;
  1450. } else {
  1451. return a;
  1452. }
  1453. } catch (java.util.InputMismatchException e) {
  1454. System.out.println("You didn't enter a number - Try again: ");
  1455. input.nextLine();
  1456. }
  1457. }
  1458. }
  1459.  
  1460. private static int getMaxID() {
  1461. DB.selectSQL("select Max(fldCustomerID) from tblWaterMeter");
  1462. String MaxCostumer = DB.getData();
  1463. MaxCostumerID = Integer.parseInt(MaxCostumer);
  1464. String stopValue = DB.getData();
  1465. return MaxCostumerID;
  1466. }
  1467.  
  1468. private static int FindWaterMeterID() {
  1469. DB.selectSQL("select fldWaterMeterID from tblWaterMeter where fldCustomerID = '" + costumerID + "'");
  1470. String costumer = DB.getData();
  1471. costumerID = Integer.parseInt(costumer);
  1472. String stopValue = DB.getData();
  1473. return costumerID;
  1474. }
  1475.  
  1476. private static double findOldAmount() {
  1477. DB.selectSQL("select fldAmountDue from tblPayment where fldWaterMeterID = '" + FindWaterMeterID() + "'");
  1478. double dueamount;
  1479. String amount = DB.getData();
  1480. dueamount = Double.parseDouble(amount);
  1481. String stopValue = DB.getData();
  1482. return dueamount;
  1483. }
  1484.  
  1485. private static boolean CostumerIDtjeck() {
  1486. boolean tjeck = false;
  1487. Scanner in = new Scanner(System.in);
  1488. //int maxcostumerID = //max coustumer ID ud fra SQL
  1489. getMaxID();
  1490. System.out.println("Input customer ID:");
  1491. if (in.hasNextInt()) {
  1492. costumerID = in.nextInt();
  1493.  
  1494. if (costumerID > 0 && costumerID < MaxCostumerID) {
  1495. tjeck = true;
  1496. }
  1497.  
  1498. }
  1499. return tjeck;
  1500. }
  1501.  
  1502. private static int paymentjeck() {
  1503.  
  1504.  
  1505. System.out.printf("Amount due: %.2f\n", findOldAmount());
  1506. System.out.println("input received amount: ");
  1507.  
  1508. Scanner in = new Scanner(System.in);
  1509.  
  1510. receivedamount = in.nextDouble();
  1511.  
  1512. diff = findOldAmount() - receivedamount;
  1513. if (diff < 0) {
  1514. return 1;//the costumer payed to much
  1515. }
  1516. if (diff > 0) {
  1517. return 2;//the costumer didn't pay enough
  1518. }
  1519. return 0;
  1520. }
  1521.  
  1522. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement