alexandra84

FINAL_FINAL_FINAL

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