fork download
  1. package controller;
  2.  
  3. import Entities.*;
  4. import com.jfoenix.controls.JFXButton;
  5. import com.jfoenix.controls.JFXComboBox;
  6. import com.jfoenix.controls.JFXTextField;
  7. import constant.Language;
  8. import constant.RoleType;
  9. import handler.SceneHandler;
  10. import javafx.event.ActionEvent;
  11. import javafx.fxml.FXML;
  12. import javafx.fxml.FXMLLoader;
  13. import javafx.fxml.Initializable;
  14. import javafx.scene.Parent;
  15. import javafx.scene.Scene;
  16. import javafx.scene.control.DatePicker;
  17. import javafx.scene.control.Label;
  18. import javafx.stage.Stage;
  19. import message.InfoMessage;
  20. import security.InterfaceLanguage;
  21. import security.UserSession;
  22. import utility.ConnectionUtil;
  23. import utility.DateUtil;
  24.  
  25. import java.io.IOException;
  26. import java.net.URL;
  27. import java.text.ParseException;
  28. import java.text.SimpleDateFormat;
  29. import java.time.LocalDate;
  30. import java.time.LocalDateTime;
  31. import java.time.LocalTime;
  32. import java.time.Year;
  33. import java.util.Date;
  34. import java.util.List;
  35. import java.util.ResourceBundle;
  36.  
  37. public class CloseContract implements Initializable {
  38.  
  39.  
  40. @FXML
  41. private JFXComboBox currentFuelCombo;
  42. @FXML
  43. private JFXTextField openContractField;
  44. @FXML
  45. private JFXTextField customerNameField;
  46. @FXML
  47. private JFXTextField customerSsnField;
  48. @FXML
  49. private JFXTextField carModelField;
  50. @FXML
  51. private JFXTextField carPlateNumberField;
  52. @FXML
  53. private JFXTextField startMileageField;
  54. @FXML
  55. private JFXTextField allowedMileageField;
  56. @FXML
  57. private JFXTextField startFuelField;
  58. @FXML
  59. private JFXTextField startHourField;
  60. @FXML
  61. private JFXTextField yearField;
  62. @FXML
  63. private JFXTextField priceDayField;
  64. @FXML
  65. private DatePicker startDatePicker;
  66. @FXML
  67. private DatePicker endDatePicker;
  68. @FXML
  69. private JFXTextField taxTypeField;
  70. @FXML
  71. private JFXTextField finalTaxField;
  72. @FXML
  73. private JFXTextField priceField;
  74. @FXML
  75. public JFXTextField finalPriceField;
  76. @FXML
  77. public JFXTextField remainingField;
  78. @FXML
  79. private JFXTextField notesField;
  80. @FXML
  81. private JFXTextField closeMileageField;
  82. @FXML
  83. private Label closeTotalDurationLabel;
  84. @FXML
  85. public JFXButton addPaymentBtn;
  86. @FXML
  87. public JFXButton closeContractBtn;
  88. @FXML
  89. private Label mileageDifferenceLabel;
  90. @FXML
  91. public Label totalPayment;
  92. @FXML
  93. private JFXTextField totalDurationField;
  94. @FXML
  95. private JFXButton unClosedContractBtn;
  96. @FXML
  97. private JFXButton viewPaymentBtn;
  98. @FXML
  99. private JFXButton carExchangeBtn;
  100. @FXML
  101. private JFXButton saveEditBtn;
  102. @FXML
  103. private JFXButton editBtn;
  104. @FXML
  105. private JFXTextField delayPriceField;
  106. @FXML
  107. private JFXButton addDelayCostBtn;
  108.  
  109.  
  110. public OpenContract selected;
  111. DisplayAllOpenedContract c;
  112.  
  113. static double finalTax;
  114. static double price;
  115. static double finalPrice;
  116. static double remaining;
  117. static double v;
  118. static double diffHours;
  119. static long differenceDays;
  120.  
  121. public static Car car1;
  122.  
  123. static long durationWithoutDelay;
  124.  
  125. static double extraCredit;
  126.  
  127. private static Date startDateForRemainingMethod;
  128. private static Date endDateForRemainingMethod;
  129. private static Date currentDateForRemainingMethod;
  130.  
  131. private static java.util.Date d1=null;
  132. private static java.util.Date d2=null;
  133.  
  134. public static double remainForPayment;
  135.  
  136.  
  137.  
  138.  
  139. @Override
  140. public void initialize(URL location, ResourceBundle resources) {
  141.  
  142. editBtn.setDisable(false);
  143.  
  144. startDatePicker.setDisable(true);
  145. endDatePicker.setDisable(true);
  146.  
  147. if(!ConnectionUtil.getEntityManager().getTransaction().isActive()){
  148. ConnectionUtil.getEntityManager().getTransaction().begin();
  149. }
  150.  
  151. currentFuelCombo.getItems().clear();
  152. currentFuelCombo.getItems().addAll("0","25","50","75","100");
  153.  
  154. selected=c.selectedOpenedContract;
  155.  
  156. openContractField.setText(selected.getOpenContractId().toString());
  157. customerNameField.setText(selected.getCustomerContract().getFirstName() + " " + selected.getCustomerContract().getLastName());
  158. customerSsnField.setText(selected.getCustomerContract().getSsn());
  159. carModelField.setText(selected.getCar().getCarColor().getColorName() + " " + selected.getCar().getModel().getCarModel().getModelName() + " " + selected.getCar().getModel().getSubModelType());
  160. carPlateNumberField.setText(selected.getCar().getPlateNumber());
  161. startMileageField.setText(String.valueOf(selected.getCurrentMileage()));
  162. allowedMileageField.setText(String.valueOf(selected.getAllowedMileage()));
  163. startFuelField.setText(String.valueOf(selected.getCurrentFuel()));
  164. startHourField.setText(String.valueOf(selected.getStartHour()));
  165. yearField.setText(String.valueOf(selected.getYear()));
  166. priceDayField.setText(String.valueOf(selected.getPricePerDay()));
  167. startDatePicker.setValue(LocalDate.parse(selected.getStartDate().toString()));
  168. endDatePicker.setValue(LocalDate.parse(selected.getExpectedEndDate().toString()));
  169. taxTypeField.setText(String.valueOf(selected.getTax().getTaxValue()));
  170. notesField.setText(selected.getNotes());
  171. // totalDurationField.setText(String.valueOf(selected.getTotalDuration()));
  172.  
  173. setTotalPayment();
  174. setRemaining();
  175.  
  176. closeMileageField.textProperty().addListener((ov, oldText, newText) -> {
  177. mileageDifferenceMethod();
  178. });
  179.  
  180.  
  181. if (!remainingField.getText().isEmpty() && Double.parseDouble(remainingField.getText()) > 0 ){
  182. unClosedContractBtn.setDisable(false);
  183. }
  184.  
  185. }
  186.  
  187. @FXML
  188. public void addCost(ActionEvent event) {
  189. if (delayPriceField == null) {
  190. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  191. new InfoMessage("Empty Field", "please add A cost for Dialy price ").show();
  192. } else {
  193. new InfoMessage("حقل فارغ", "الرجاء إدخال السعر اليومي").show();
  194. }
  195. } else {
  196. finalPrice = Double.parseDouble(finalPriceField.getText()) + Double.parseDouble(delayPriceField.getText());
  197. finalTax = finalPrice * Double.parseDouble(taxTypeField.getText());
  198. price = finalPrice - finalTax;
  199. remaining = finalPrice - Double.parseDouble(totalPayment.getText());
  200. priceField.setText(String.valueOf(price));
  201. finalTaxField.setText(String.valueOf(finalTax));
  202. remainingField.setText(String.valueOf(remaining));
  203. finalPriceField.setText(String.valueOf(finalPrice));
  204. }
  205. }
  206.  
  207. public void setFieldsOnEdit(){
  208.  
  209. Long durationafterEdition = (java.sql.Date.valueOf(selected.getExpectedEndDate()).getTime() - java.sql.Date.valueOf(selected.getStartDate()).getTime()) / (60 * 60 * 24 * 1000);
  210.  
  211. if (durationafterEdition == 0) {
  212. durationafterEdition = 1L;
  213. }
  214.  
  215. double priDay = Double.parseDouble(priceDayField.getText());
  216. double taxx = Double.parseDouble(taxTypeField.getText());
  217.  
  218. double pri = (durationafterEdition * priDay) - ((durationafterEdition * priDay) * taxx);
  219. double finPri = pri + ((durationafterEdition * priDay) * taxx);
  220. double remain = finPri - v;
  221.  
  222. totalDurationField.setText(String.valueOf(durationafterEdition));
  223. priceField.setText(String.valueOf(pri));
  224. finalTaxField.setText(String.valueOf(((durationafterEdition * priDay) * taxx)));
  225. finalPriceField.setText(String.valueOf(finPri));
  226. remainingField.setText(String.valueOf(remain));
  227. }
  228.  
  229.  
  230. @FXML
  231. public void saveEdit(ActionEvent event) {
  232. if(!ConnectionUtil.getEntityManager().getTransaction().isActive()){
  233. ConnectionUtil.getEntityManager().getTransaction().begin();
  234. }
  235. saveEditBtn.setVisible(false);
  236. editBtn.setVisible(true);
  237.  
  238. startDatePicker.setDisable(true);
  239. endDatePicker.setDisable(true);
  240.  
  241. Tax tax;
  242. tax = ConnectionUtil.getEntityManager().createQuery("select t from Tax t where t.taxValue = :v ", Tax.class).setParameter("v", Double.parseDouble(taxTypeField.getText())).getSingleResult();
  243.  
  244. setFieldsOnEdit();
  245.  
  246. selected.setPrice(Double.parseDouble(priceField.getText()));
  247. selected.setTotalPrice(Double.parseDouble(finalPriceField.getText()));
  248. selected.setTaxAmount(Double.parseDouble(finalTaxField.getText()));
  249. selected.setRemainingAmount(Double.parseDouble(remainingField.getText()));
  250. selected.setTotalDuration(Integer.parseInt(totalDurationField.getText()));
  251. selected.setStartDate(startDatePicker.getValue());
  252. selected.setExpectedEndDate(endDatePicker.getValue());
  253. selected.setAllowedMileage(Double.parseDouble(allowedMileageField.getText()));
  254. selected.setCurrentFuel(Integer.parseInt(startFuelField.getText()));
  255. selected.setTax(tax);
  256. selected.setNotes(notesField.getText());
  257. selected.setPricePerDay(Double.parseDouble(priceDayField.getText()));
  258. ConnectionUtil.getEntityManager().merge(selected);
  259.  
  260. Actions actions = new Actions();
  261. actions.setActionDate(LocalDate.now().toString() + " " + LocalTime.now().toString());
  262.  
  263. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  264. actions.setActionInfo("Contract Is Closed");
  265. } else {
  266. actions.setActionInfo("تم اغلاق عقد");
  267. }
  268. actions.setActionUser(UserSession.getInstance().getUsername());
  269. ConnectionUtil.getEntityManager().persist(actions);
  270. // ConnectionUtil.getEntityManager().refresh(selected);
  271. if(!ConnectionUtil.getEntityManager().getTransaction().isActive()){
  272. ConnectionUtil.getEntityManager().getTransaction().begin();
  273. }
  274. ConnectionUtil.getEntityManager().getTransaction().commit();
  275.  
  276. startDatePicker.setEditable(false);
  277. endDatePicker.setEditable(false);
  278. allowedMileageField.setEditable(false);
  279. startFuelField.setEditable(false);
  280. taxTypeField.setEditable(false);
  281. notesField.setEditable(false);
  282. priceDayField.setEditable(false);
  283.  
  284. setFieldsOnEdit();
  285. if (Double.parseDouble(remainingField.getText())> 0){
  286. addPaymentBtn.setDisable(false);
  287. }
  288. }
  289.  
  290. @FXML
  291. public void edit(ActionEvent event){
  292. editBtn.setVisible(false);
  293. saveEditBtn.setVisible(true);
  294.  
  295. startDatePicker.setEditable(true);
  296. endDatePicker.setEditable(true);
  297. allowedMileageField.setEditable(true);
  298. startFuelField.setEditable(true);
  299. taxTypeField.setEditable(true);
  300. notesField.setEditable(true);
  301. priceDayField.setEditable(true);
  302.  
  303. startDatePicker.setDisable(false);
  304. endDatePicker.setDisable(false);
  305. }
  306.  
  307.  
  308.  
  309. public void mileageDifferenceMethod() {
  310. mileageDifferenceLabel.setText("");
  311. double mileageDiff=Double.parseDouble(closeMileageField.getText()) - selected.getCurrentMileage();
  312. mileageDifferenceLabel.setText(String.valueOf(mileageDiff));
  313. }
  314.  
  315.  
  316. @FXML
  317. public void addPayments(ActionEvent event) throws IOException {
  318. remainForPayment = Double.parseDouble(remainingField.getText());
  319. FXMLLoader fxmlLoader;
  320. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  321. fxmlLoader=new FXMLLoader(getClass().getResource("/views/EN/AddPayment.fxml"));
  322.  
  323. } else {
  324. fxmlLoader=new FXMLLoader(getClass().getResource("/views/AR/AddPayment.fxml"));
  325.  
  326. }
  327. Parent root1=(Parent) fxmlLoader.load();
  328. Stage stage=new Stage();
  329.  
  330. stage.setScene(new Scene(root1));
  331.  
  332. AddPaymentController addProductControllerController=fxmlLoader.getController();
  333.  
  334. fxmlLoader.setController(addProductControllerController);
  335.  
  336. stage.showAndWait();
  337.  
  338. setTotalPayment();
  339.  
  340. if (delayPriceField.isVisible()){
  341. remainingField.setText(String.valueOf(Double.parseDouble(finalPriceField.getText()) - Double.parseDouble(totalPayment.getText())));
  342. if (Double.parseDouble(remainingField.getText()) <= 0 ){
  343. // closeContractBtn.setDisable(false);
  344. }
  345. }
  346. else {
  347. setRemaining();
  348. }
  349. }
  350.  
  351. @FXML
  352. public void viewPayments(ActionEvent event) {
  353. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  354. new SceneHandler("/views/EN/ViewPayments.fxml").Go();
  355. } else {
  356. new SceneHandler("/views/AR/ViewPayments.fxml").Go();
  357. }
  358. }
  359.  
  360.  
  361. public void setTotalPayment() {
  362. v=(Double) ConnectionUtil.getEntityManager().createQuery("select sum(paymentValue) from PaymentHistory where contractPayment.openContractId = :v ").setParameter("v", selected.getOpenContractId()).getSingleResult();
  363. totalPayment.setText(String.valueOf(v));
  364. }
  365.  
  366.  
  367. public void setRemaining()
  368. {
  369. if (!remainingField.getText().isEmpty() && (Double.parseDouble(remainingField.getText()) == 0 || Double.parseDouble(remainingField.getText()) < 0 ) ) {
  370. addPaymentBtn.setDisable(true);
  371. closeContractBtn.setDisable(false);
  372. }
  373. else {
  374. currentDateForRemainingMethod = java.sql.Date.valueOf(DateUtil.getDate());
  375. endDateForRemainingMethod = java.sql.Date.valueOf(selected.getExpectedEndDate());
  376. startDateForRemainingMethod = java.sql.Date.valueOf(selected.getStartDate());
  377.  
  378. durationWithoutDelay = (endDateForRemainingMethod.getTime() - startDateForRemainingMethod.getTime()) / (60 * 60 * 24 * 1000);
  379. differenceDays = (currentDateForRemainingMethod.getTime() - endDateForRemainingMethod.getTime()) / (60 * 60 * 24 * 1000);
  380.  
  381. SimpleDateFormat format=new SimpleDateFormat("HH:mm");
  382. try {
  383. d1=format.parse(selected.getExpectedEndHour());
  384. d2=format.parse(DateUtil.getCurrentHour());
  385.  
  386. //in milliseconds
  387. long diff=d2.getTime() - d1.getTime();
  388. diffHours=(diff / (60 * 60 * 1000) % 24);
  389. // double diffMin = ((diff / (60 * 1000) % 60));
  390. // System.out.println(diffHours);
  391.  
  392. } catch (ParseException e) {
  393. throw new RuntimeException(e);
  394. }
  395.  
  396.  
  397. if (differenceDays == 0) {
  398. differenceDays = 1;
  399. }
  400.  
  401. if ((currentDateForRemainingMethod.getTime()/ (60 * 60 * 24 * 1000)) > (endDateForRemainingMethod.getTime()/ (60 * 60 * 24 * 1000))) {
  402. ifCurrentDateBiggerThanEndDate();
  403.  
  404. }
  405. else if ((currentDateForRemainingMethod.getTime()/ (60 * 60 * 24 * 1000)) == (endDateForRemainingMethod.getTime()/ (60 * 60 * 24 * 1000))) {
  406. ifCurrentDateEqualEndDate();
  407. }
  408. else {
  409. ifCurrentDateLessThanEndDate();
  410. }
  411. }
  412.  
  413. if (!remainingField.getText().isEmpty() && (Double.parseDouble(remainingField.getText()) == 0 || Double.parseDouble(remainingField.getText()) < 0 ) ) {
  414. addPaymentBtn.setDisable(true);
  415. closeContractBtn.setDisable(false);
  416. }
  417. }
  418.  
  419. @FXML
  420. public void addToBlackList(ActionEvent event) {
  421.  
  422.  
  423. Customer customerr;
  424. customerr= ConnectionUtil.getEntityManager().createQuery("select c from Customer c where c.customerId= :v", Customer.class).setParameter("v", selected.getCustomerContract().getCustomerId()).getSingleResult();
  425. customerr.setBlocked(true);
  426.  
  427. ConnectionUtil.getEntityManager().merge(customerr);
  428. Actions actions = new Actions();
  429. actions.setActionDate(LocalDate.now().toString() + " " + LocalTime.now().toString());
  430. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  431. actions.setActionInfo("Customer Has Been Added To BlackList");
  432. } else {
  433. actions.setActionInfo("تمت إضافة العميل إلى القائمة السوداء");
  434. }
  435. actions.setActionUser(UserSession.getInstance().getUsername());
  436. ConnectionUtil.getEntityManager().persist(actions);
  437. if(!ConnectionUtil.getEntityManager().getTransaction().isActive()){
  438. ConnectionUtil.getEntityManager().getTransaction().begin();
  439. }
  440. ConnectionUtil.getEntityManager().getTransaction().commit();
  441. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  442. new InfoMessage("Done", "Customer added to blacklist ").show();
  443. } else {
  444. new InfoMessage("تمت العملية بنجاح", "تمت إضافة العميل إلى القائمة السوداء").show();
  445. }
  446.  
  447.  
  448. }
  449.  
  450.  
  451. @FXML
  452. public void closeContract(ActionEvent event) {
  453. // rearranged by yousef
  454. if (currentFuelCombo.getSelectionModel().getSelectedItem() == null || closeMileageField.getText().isEmpty()) {
  455. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  456. new InfoMessage("warning", "please insert current mileage and current fuel").show();
  457.  
  458. } else {
  459. new InfoMessage("تحذير", "الرجاء إدخال المسافة المقطوعة الحالية و كمية الوقود الحالية").show();
  460. }
  461.  
  462. } else {
  463.  
  464. if (Double.parseDouble(remainingField.getText()) > 0) {
  465.  
  466. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  467. new InfoMessage("Rejected Operation", "please check remaining and get payment from customer").show();
  468.  
  469. } else {
  470. new InfoMessage("تم رفض العملية", "يرجى التحقق من البلغ المتبقي وتحصيل المبلغ المتبقي من العميل").show();
  471. }
  472.  
  473. }
  474. else if (Double.parseDouble(remainingField.getText()) <= 0) {
  475.  
  476.  
  477. Long dur= (java.sql.Date.valueOf(DateUtil.getDate()).getTime() - java.sql.Date.valueOf(selected.getStartDate()).getTime()) / (60 * 60 * 24 * 1000);
  478.  
  479. if (dur == 0) {
  480. dur = 1L;
  481. }
  482.  
  483. double priDay = Double.parseDouble(priceDayField.getText());
  484. double taxx = Double.parseDouble(taxTypeField.getText());
  485.  
  486. double pri = (dur * priDay) - ((dur * priDay) * taxx);
  487. double finPri = pri + ((dur * priDay) * taxx);
  488. double remain = finPri - v;
  489.  
  490. SimpleDateFormat format=new SimpleDateFormat("HH:mm");
  491.  
  492. try {
  493. java.util.Date d11=null;
  494. java.util.Date d22=null;
  495.  
  496. d11=format.parse(selected.getExpectedEndHour());
  497. d22=format.parse(DateUtil.getCurrentHour());
  498.  
  499. //in milliseconds
  500. long diff=d2.getTime() - d1.getTime();
  501. diffHours=(diff / (60 * 60 * 1000) % 24);
  502. // double diffMin = ((diff / (60 * 1000) % 60));
  503. // System.out.println(diffHours);
  504.  
  505. } catch (ParseException e) {
  506. throw new RuntimeException(e);
  507. }
  508.  
  509. if ((diffHours >= 2)&&(diffHours < 6)) {
  510. double ext = Double.parseDouble(priceDayField.getText())/2;
  511. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  512. new InfoMessage("warning", "there is delay in end hour.... extra cost has been added tot total "+" : "+ext).show();
  513. } else {
  514. new InfoMessage("تحذير", "هناك تأخير في ساعة الاستلام .... تمت اضافة تكلفة التاخير الى المجموع الكلي و التي قيمتها : "+ext).show();
  515. }
  516.  
  517.  
  518. totalDurationField.setText(String.valueOf(dur));
  519. priceField.setText(String.valueOf(pri));
  520. finalTaxField.setText(String.valueOf(((dur * priDay) * taxx)));
  521. finalPriceField.setText(String.valueOf(finPri + ext));
  522. remainingField.setText(String.valueOf(remain));
  523. }
  524. else if (diffHours >= 6) {
  525. double extraOneDay = Double.parseDouble(priceDayField.getText());
  526. totalDurationField.setText(String.valueOf(dur + 1 ));
  527. priceField.setText(String.valueOf((pri + (extraOneDay)) - (extraOneDay * taxx) ));
  528. finalTaxField.setText(String.valueOf((((dur+1) * priDay) * taxx) ));
  529. finalPriceField.setText(String.valueOf(finPri + extraOneDay));
  530. remainingField.setText(String.valueOf(remain + extraOneDay));
  531.  
  532. }
  533. else {
  534. totalDurationField.setText(String.valueOf(dur));
  535. priceField.setText(String.valueOf(pri));
  536. finalTaxField.setText(String.valueOf(((dur * priDay) * taxx)));
  537. finalPriceField.setText(String.valueOf(finPri));
  538. remainingField.setText(String.valueOf(remain));
  539. }
  540.  
  541.  
  542. ClosedContract closedContract = new ClosedContract();
  543. Car car;
  544. CarStatus carStatus;
  545. List<Customer> customer;
  546.  
  547. selected.setContractState("Closed");
  548. selected.setPrice(Double.parseDouble(priceField.getText()));
  549. selected.setTaxAmount(Double.parseDouble(finalTaxField.getText()));
  550. selected.setRemainingAmount(Double.parseDouble(remainingField.getText()));
  551. selected.setTotalPrice(Double.parseDouble(finalPriceField.getText()));
  552. selected.setTotalDuration(Integer.parseInt(totalDurationField.getText()));
  553.  
  554. customer = ConnectionUtil.getEntityManager().createQuery("select c from Customer c where c.customerId=:v", Customer.class).setParameter("v", selected.getCustomerContract().getCustomerId()).getResultList();
  555.  
  556. if (Double.parseDouble(remainingField.getText()) == 0){
  557. customer.get(0).setCurrentCredit(0.0);
  558. }else if(Double.parseDouble(remainingField.getText()) < 0){
  559. customer.get(0).setCurrentCredit(-1 * Double.parseDouble(remainingField.getText()));
  560. }
  561.  
  562. closedContract.setCarId(selected.getCar().getCarId());
  563. closedContract.setContractYear(Year.now());
  564. closedContract.setCurrentFuel(Integer.parseInt(currentFuelCombo.getSelectionModel().getSelectedItem().toString()));
  565. closedContract.setCurrentMileage(Double.parseDouble(closeMileageField.getText()));
  566. closedContract.setCustomerId(selected.getCustomerContract().getCustomerId());
  567. closedContract.setEndDate(java.sql.Date.valueOf(LocalDate.now()));
  568. closedContract.setRecievedEmployeeId(UserSession.getInstance().getUserId());
  569. closedContract.setTotalDuration(Integer.parseInt(totalDurationField.getText()));
  570. closedContract.setContractNumber(selected.getOpenContractId());
  571. closedContract.setClosedHour(DateUtil.getCurrentHour());
  572. closedContract.setOpenContract(selected);
  573. closedContract.setStatus("Closed");
  574.  
  575. if (!ConnectionUtil.getEntityManager().getTransaction().isActive()) {
  576. ConnectionUtil.getEntityManager().getTransaction().begin();
  577. }
  578.  
  579. carStatus = ConnectionUtil.getEntityManager().createQuery("select c from CarStatus c where c.carStatusName= :sStatus", CarStatus.class).setParameter("sStatus", "Available").getSingleResult();
  580. car = ConnectionUtil.getEntityManager().createQuery("select c from Car c where c.carId=:v", Car.class).setParameter("v", selected.getCar().getCarId()).getSingleResult();
  581. car.setCarStatus(carStatus);
  582. car.setCarMileage(Double.parseDouble(closeMileageField.getText()));
  583.  
  584. car.setCurrentLoction(UserSession.getInstance().getBranch());
  585.  
  586. selected.setClosedContract(closedContract);
  587. closedContract.setOpenContract(selected);
  588.  
  589. ConnectionUtil.getEntityManager().persist(closedContract);
  590. ConnectionUtil.getEntityManager().merge(car);
  591. ConnectionUtil.getEntityManager().merge(customer.get(0));
  592. ConnectionUtil.getEntityManager().merge(selected);
  593.  
  594. Actions actions = new Actions();
  595. actions.setActionDate(LocalDate.now().toString() + " " + LocalTime.now().toString());
  596. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  597. actions.setActionInfo("Contract Closed Successfully");
  598. } else {
  599. actions.setActionInfo("تم إغلاق العقد بنجاح");
  600. }
  601.  
  602. actions.setActionUser(UserSession.getInstance().getUsername());
  603. ConnectionUtil.getEntityManager().persist(actions);
  604. if(!ConnectionUtil.getEntityManager().getTransaction().isActive()){
  605. ConnectionUtil.getEntityManager().getTransaction().begin();
  606. }
  607. ConnectionUtil.getEntityManager().getTransaction().commit();
  608. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  609. new InfoMessage("Success", "Contract Closed Successfully").show();
  610. } else {
  611. new InfoMessage("تمت العملية بنجاح", "تم إغلاق العقد بنجاح").show();
  612. }
  613.  
  614. Stage stage = (Stage) closeContractBtn.getScene().getWindow();
  615. stage.close();
  616.  
  617. if (Double.parseDouble(remainingField.getText()) < 0) {
  618. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  619. new InfoMessage("Note", "customer has credit from this contract " + "CREDIT VALUE :" + (-1 * Double.parseDouble(remainingField.getText()))).show();
  620.  
  621. } else {
  622. new InfoMessage("ملاحظة", "العميل لديه رصيد من هذا العقد " + "القيمة : " + (-1 * Double.parseDouble(remainingField.getText()))).show();
  623. }
  624. }
  625. }
  626.  
  627. }
  628. }
  629.  
  630.  
  631. @FXML
  632. public void carExchange(ActionEvent event) throws IOException {
  633.  
  634. if ((closeMileageField.getText().isEmpty() || currentFuelCombo.getSelectionModel().getSelectedItem().toString().length()==0) ) {
  635. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  636.  
  637. new InfoMessage("warning", "please enter current mileage and fuel").show();
  638. } else {
  639. new InfoMessage("تحذير", "يرجى إدخال المسافة المقطوعة الحالية و كمية الوقود").show();
  640. }
  641.  
  642. }
  643. else {
  644. FXMLLoader fxmlLoader;
  645. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  646. fxmlLoader = new FXMLLoader(getClass().getResource("/views/EN/CarExchange.fxml"));
  647. }else{
  648. fxmlLoader = new FXMLLoader(getClass().getResource("/views/AR/CarExchange.fxml"));
  649. }
  650. Parent root1 = (Parent) fxmlLoader.load();
  651. Stage stage = new Stage();
  652. stage.setScene(new Scene(root1));
  653. CarExchangeController exchangeController = fxmlLoader.getController();
  654. fxmlLoader.setController(exchangeController);
  655. stage.showAndWait();
  656.  
  657. if ((car1 != null) && ((java.sql.Date.valueOf(LocalDate.now()).getTime()) < java.sql.Date.valueOf(endDatePicker.getValue()).getTime()) && (Double.parseDouble(remainingField.getText()) <= 0)) {
  658.  
  659. forCarExchangeIfNewCarExist_andCurrentDateLessTHanEndDate();
  660.  
  661. setCloseContract_UpdateOpenContract_UpdateCar_UpdateCustomer();
  662.  
  663. viewRent_WithCurrentCustomer_InfoAndCredit();
  664.  
  665. Stage stv = (Stage) closeContractBtn.getScene().getWindow();
  666. stv.close();
  667. } else {
  668. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  669. new InfoMessage("warning", "Balance Due take remaining and open new Contract").show();
  670. } else {
  671. new InfoMessage("تحذير", "يوجد مبلغ متبقي قم بتحصيله من العميل و اغلق العقد ثم قم بفتح عقد جديد").show();
  672. }
  673. }
  674. }
  675. }
  676.  
  677.  
  678.  
  679. @FXML
  680. public void unCloseContractWithoutCarExchange(ActionEvent event) {
  681. if (currentFuelCombo.getSelectionModel().getSelectedItem() == null || closeMileageField.getText().isEmpty()){
  682. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  683. new InfoMessage("warning","please insert current fuel and current mileage").show();
  684. } else {
  685. new InfoMessage("تحذير", "يرجى إدخال المسافة المقطوعة الحالية و كمية الوقود").show();
  686. }
  687.  
  688. }
  689. else
  690. {
  691. if (Double.parseDouble(remainingField.getText()) > 0) {
  692.  
  693. Car car;
  694. Long dur= (java.sql.Date.valueOf(DateUtil.getDate()).getTime() - java.sql.Date.valueOf(selected.getStartDate()).getTime()) / (60 * 60 * 24 * 1000);
  695.  
  696. if (dur == 0) {
  697. dur = 1L;
  698. }
  699.  
  700. double priDay = Double.parseDouble(priceDayField.getText());
  701. double taxx = Double.parseDouble(taxTypeField.getText());
  702.  
  703. double pri = (dur * priDay) - ((dur * priDay) * taxx);
  704. double finPri = pri + ((dur * priDay) * taxx);
  705. double remain = selected.getRemainingAmount() + ( finPri - (v-selected.getDownPayment()));
  706.  
  707. SimpleDateFormat format=new SimpleDateFormat("HH:mm");
  708.  
  709. try {
  710. java.util.Date d11=null;
  711. java.util.Date d22=null;
  712.  
  713. d11=format.parse(selected.getExpectedEndHour());
  714. d22=format.parse(DateUtil.getCurrentHour());
  715.  
  716. //in milliseconds
  717. long diff=d2.getTime() - d1.getTime();
  718. diffHours=(diff / (60 * 60 * 1000) % 24);
  719. // double diffMin = ((diff / (60 * 1000) % 60));
  720. // System.out.println(diffHours);
  721.  
  722. } catch (ParseException e) {
  723. throw new RuntimeException(e);
  724. }
  725.  
  726. if ((diffHours >= 2)&&(diffHours < 6)) {
  727. double ext = Double.parseDouble(priceDayField.getText())/2;
  728. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  729. new InfoMessage("warning", "there is delay in end hour.... extra cost has been added tot total "+" : "+ext).show();
  730. } else {
  731. new InfoMessage("تحذير", "هناك تأخير في ساعة الاستلام .... تمت اضافة تكلفة التاخير الى المجموع الكلي و التي قيمتها : "+ext).show();
  732. }
  733.  
  734.  
  735. totalDurationField.setText(String.valueOf(dur));
  736. priceField.setText(String.valueOf(pri));
  737. finalTaxField.setText(String.valueOf(((dur * priDay) * taxx)));
  738. finalPriceField.setText(String.valueOf(finPri + + ext));
  739. remainingField.setText(String.valueOf(remain));
  740. }
  741. else if (diffHours >= 6) {
  742. double extraOneDay = Double.parseDouble(priceDayField.getText());
  743. totalDurationField.setText(String.valueOf(dur + 1 ));
  744. priceField.setText(String.valueOf((pri + (extraOneDay)) - (extraOneDay * taxx) ));
  745. finalTaxField.setText(String.valueOf((((dur+1) * priDay) * taxx) ));
  746. finalPriceField.setText(String.valueOf(finPri + extraOneDay));
  747. remainingField.setText(String.valueOf(remain + extraOneDay));
  748.  
  749. }
  750. else {
  751. totalDurationField.setText(String.valueOf(dur));
  752. priceField.setText(String.valueOf(pri));
  753. finalTaxField.setText(String.valueOf(((dur * priDay) * taxx)));
  754. finalPriceField.setText(String.valueOf(finPri));
  755. remainingField.setText(String.valueOf(remain));
  756. }
  757.  
  758. CarStatus carStatus = ConnectionUtil.getEntityManager().createQuery("select c from CarStatus c where c.carStatusName = :v",CarStatus.class).setParameter("v","Available").getSingleResult();
  759.  
  760. car = ConnectionUtil.getEntityManager().createQuery("select c from Car c where c.carId = :v",Car.class).setParameter("v",selected.getCar().getCarId()).getSingleResult();
  761. car.setCurrentLoction(UserSession.getInstance().getBranch());
  762. car.setCarMileage(Double.parseDouble(closeMileageField.getText()));
  763. car.setCarStatus(carStatus);
  764.  
  765. selected.setPrice(Double.parseDouble(priceField.getText()));
  766. selected.setTotalPrice(Double.parseDouble(finalPriceField.getText()));
  767. selected.setTaxAmount(Double.parseDouble(finalTaxField.getText()));
  768. selected.setRemainingAmount(Double.parseDouble(remainingField.getText()));
  769. selected.setTotalDuration(dur.intValue());
  770. selected.setStartDate(startDatePicker.getValue());
  771. selected.setExpectedEndDate(LocalDate.parse(DateUtil.getDate()));
  772. selected.setAllowedMileage(Double.parseDouble(allowedMileageField.getText()));
  773. selected.setCurrentFuel(Integer.parseInt(startFuelField.getText()));
  774. selected.setNotes(notesField.getText());
  775. selected.setPricePerDay(Double.parseDouble(priceDayField.getText()));
  776.  
  777. UnClosedContract unClosedContract = new UnClosedContract();
  778.  
  779. selected.setContractState("Unclosed");
  780. unClosedContract.setOpenContract(selected);
  781. unClosedContract.setActualEndDate(new Date());
  782.  
  783. unClosedContract.setUnclosedCurrentMileage(Double.parseDouble(closeMileageField.getText()));
  784. unClosedContract.setUnclosedCurrentFuel(Integer.parseInt(currentFuelCombo.getSelectionModel().getSelectedItem().toString()));
  785. unClosedContract.setUnclosedYear(LocalDateTime.now().getYear());
  786. unClosedContract.setOpenContract(selected);
  787. unClosedContract.setStatus("Unclosed");
  788. selected.setUnclosedOpenContract(unClosedContract);
  789.  
  790. ConnectionUtil.getEntityManager().merge(selected);
  791. ConnectionUtil.getEntityManager().merge(car);
  792. ConnectionUtil.getEntityManager().persist(unClosedContract);
  793.  
  794. }
  795.  
  796. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  797. new InfoMessage("done","Contract has been added to Unclosed Contract").show();
  798.  
  799. } else {
  800. new InfoMessage("تمت العملية بنجاح","تم تحويل العقد الى العقود المغلقة على الذمم").show();
  801. }
  802.  
  803. Stage stv = (Stage) closeContractBtn.getScene().getWindow();
  804. stv.close();
  805. }
  806. }
  807.  
  808. public void ifCurrentDateBiggerThanEndDate() {
  809.  
  810. SimpleDateFormat format=new SimpleDateFormat("HH:mm");
  811. try {
  812. d1=format.parse(selected.getStartHour());
  813. d2=format.parse(DateUtil.getCurrentHour());
  814.  
  815. //in milliseconds
  816. long diff=d2.getTime() - d1.getTime();
  817. diffHours=(diff / (60 * 60 * 1000) % 24);
  818. // double diffMin = ((diff / (60 * 1000) % 60));
  819. // System.out.println(diffHours);
  820.  
  821. } catch (ParseException e) {
  822. throw new RuntimeException(e);
  823. }
  824.  
  825.  
  826. carExchangeBtn.setDisable(true);
  827. if ((diffHours >= 2)&&(diffHours < 6)) {
  828. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  829. new InfoMessage("warning", "there is delay in end hour....you can set new cost to final price").show();
  830. } else {
  831. new InfoMessage("تحذير", "هناك تأخير في ساعة الاستلام .... يمكنك اضافة تكلفة التاخير الى المجموع الكلي ").show();
  832. }
  833. delayPriceField.setVisible(true);
  834. addDelayCostBtn.setVisible(true);
  835.  
  836.  
  837. price = (selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText()))) - (selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  838. // price = (durationWithoutDelay + differenceDays) * Double.parseDouble(priceDayField.getText());
  839. finalTax =(selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  840. finalPrice = price + finalTax;
  841. if (delayPriceField.getText().isEmpty()){
  842. remaining = selected.getRemainingAmount() + (differenceDays *Double.parseDouble(priceDayField.getText())) - (Double.parseDouble(totalPayment.getText())- selected.getDownPayment());
  843. }else {
  844. remaining = Double.parseDouble(delayPriceField.getText()) + selected.getRemainingAmount() + (differenceDays * Double.parseDouble(priceDayField.getText())) - (Double.parseDouble(totalPayment.getText()) - selected.getDownPayment());
  845. }
  846. priceField.setText(String.valueOf(price));
  847. finalTaxField.setText(String.valueOf(finalTax));
  848. finalPriceField.setText(String.valueOf(finalPrice));
  849. remainingField.setText(String.valueOf(remaining));
  850. totalDurationField.setText(String.valueOf(durationWithoutDelay + differenceDays));
  851.  
  852.  
  853. }
  854. else if (diffHours >= 6) {
  855. price = (selected.getPrice() + ((differenceDays +1) *Double.parseDouble(priceDayField.getText()))) - (selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  856. finalTax =(selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  857. finalPrice = price + finalTax;
  858. if (delayPriceField.getText().isEmpty()){
  859. remaining = selected.getRemainingAmount() + ((differenceDays+1) *Double.parseDouble(priceDayField.getText())) - (Double.parseDouble(totalPayment.getText())- selected.getDownPayment());
  860. }else {
  861. remaining = Double.parseDouble(delayPriceField.getText()) + selected.getRemainingAmount() + ((differenceDays+1) * Double.parseDouble(priceDayField.getText())) - (Double.parseDouble(totalPayment.getText()) - selected.getDownPayment());
  862. }
  863. priceField.setText(String.valueOf(price));
  864. finalTaxField.setText(String.valueOf(finalTax));
  865. finalPriceField.setText(String.valueOf(finalPrice));
  866. remainingField.setText(String.valueOf(remaining));
  867. totalDurationField.setText(String.valueOf(durationWithoutDelay + differenceDays + 1));
  868. }
  869. else {
  870. price = (selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText()))) - (selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  871. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  872. new InfoMessage("warning", "there is delay in end date ....final price and remaining updated ").show();
  873. } else {
  874. new InfoMessage("تحذير", "هناك تأخير في تاريخ الانتهاء .... تم تحديث السعر النهائي والسعر المتبقي ").show();
  875. }
  876. finalTax = (selected.getPrice() + (differenceDays *Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  877. finalPrice = price + finalTax;
  878. remaining = selected.getRemainingAmount() + ((differenceDays+1) * Double.parseDouble(priceDayField.getText())) - (Double.parseDouble(totalPayment.getText()) - selected.getDownPayment());
  879.  
  880.  
  881. priceField.setText(String.valueOf(price));
  882. finalTaxField.setText(String.valueOf(finalTax));
  883. finalPriceField.setText(String.valueOf(finalPrice));
  884. remainingField.setText(String.valueOf(remaining));
  885. totalDurationField.setText(String.valueOf(durationWithoutDelay + differenceDays));
  886. }
  887. }
  888.  
  889.  
  890. public void ifCurrentDateEqualEndDate(){
  891. carExchangeBtn.setDisable(true);
  892. if ((diffHours >= 2)&&(diffHours < 6)) {
  893. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  894. new InfoMessage("warning", "there is delay in end hour....you can set new cost to final price").show();
  895. } else {
  896. new InfoMessage("تحذير", "هناك تأخير في ساعة الاستلام .... يمكنك اضافة تكلفة التاخير الى المجموع الكلي ").show();
  897. }
  898. delayPriceField.setVisible(true);
  899. addDelayCostBtn.setVisible(true);
  900.  
  901. price = selected.getPrice() ;
  902. finalTax = price * Double.parseDouble(taxTypeField.getText());
  903. finalPrice = price + finalTax;
  904. if (delayPriceField.getText().isEmpty()){
  905. remaining =selected.getRemainingAmount();
  906. }else{
  907. remaining =selected.getRemainingAmount()+Double.parseDouble(delayPriceField.getText()) - (Double.parseDouble(totalPayment.getText())-selected.getDownPayment()) ;
  908. }
  909.  
  910.  
  911. priceField.setText(String.valueOf(price));
  912. finalTaxField.setText(String.valueOf(finalTax));
  913. finalPriceField.setText(String.valueOf(finalPrice));
  914. remainingField.setText(String.valueOf(remaining));
  915. totalDurationField.setText(String.valueOf(durationWithoutDelay));
  916. }
  917. else if (diffHours >= 6) {
  918.  
  919. price = (selected.getPrice() + (Double.parseDouble(priceDayField.getText()))) - (selected.getPrice() + (Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  920. finalTax = (selected.getPrice() + (Double.parseDouble(priceDayField.getText())) *Double.parseDouble(taxTypeField.getText()));
  921. finalPrice = price + finalTax;
  922. remaining = selected.getRemainingAmount() +(Double.parseDouble(priceDayField.getText())) -(Double.parseDouble(totalPayment.getText())-selected.getDownPayment()) ;
  923.  
  924. priceField.setText(String.valueOf(price));
  925. finalTaxField.setText(String.valueOf(finalTax));
  926. finalPriceField.setText(String.valueOf(finalPrice));
  927. remainingField.setText(String.valueOf(remaining));
  928. totalDurationField.setText(String.valueOf(durationWithoutDelay +1));
  929. }
  930. }
  931.  
  932. public void ifCurrentDateLessThanEndDate(){
  933. carExchangeBtn.setDisable(false);
  934. if ((diffHours >= 2)&&(diffHours < 6)) {
  935. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  936. new InfoMessage("warning", "there is delay in end hour....you can set new cost to final price").show();
  937. } else {
  938. new InfoMessage("تحذير", "هناك تأخير في ساعة الاستلام .... يمكنك اضافة تكلفة التاخير الى المجموع الكلي ").show();
  939. }
  940. delayPriceField.setVisible(true);
  941. addDelayCostBtn.setVisible(true);
  942.  
  943.  
  944. price = ((durationWithoutDelay) * Double.parseDouble(priceDayField.getText())) - (((durationWithoutDelay) * Double.parseDouble(priceDayField.getText())) * Double.parseDouble(taxTypeField.getText()));
  945. finalTax = (((durationWithoutDelay) * Double.parseDouble(priceDayField.getText())) * Double.parseDouble(taxTypeField.getText()));
  946. finalPrice = (price + finalTax);
  947.  
  948. if (delayPriceField.getText().isEmpty()){
  949. remaining = finalPrice- Double.parseDouble(totalPayment.getText()) ;
  950. }
  951. else if (!delayPriceField.getText().isEmpty() ){
  952. remaining = finalPrice+Double.parseDouble(delayPriceField.getText())- Double.parseDouble(totalPayment.getText()) ;
  953. }
  954.  
  955. priceField.setText(String.valueOf(price));
  956. finalTaxField.setText(String.valueOf(finalTax));
  957. finalPriceField.setText(String.valueOf(finalPrice));
  958. remainingField.setText(String.valueOf(remaining));
  959. totalDurationField.setText(String.valueOf(durationWithoutDelay));
  960. }
  961. else if (diffHours >= 6) {
  962. price = ((durationWithoutDelay + 1) * Double.parseDouble(priceDayField.getText())) - (((durationWithoutDelay+1) * Double.parseDouble(priceDayField.getText())) * Double.parseDouble(taxTypeField.getText()));
  963. finalTax = (((durationWithoutDelay+1) * Double.parseDouble(priceDayField.getText())) * Double.parseDouble(taxTypeField.getText()));
  964. finalPrice = (price + finalTax);
  965. remaining = selected.getRemainingAmount() - (finalPrice - (Double.parseDouble(totalPayment.getText()) - selected.getDownPayment()));
  966.  
  967. priceField.setText(String.valueOf(price));
  968. finalTaxField.setText(String.valueOf(finalTax));
  969. finalPriceField.setText(String.valueOf(finalPrice));
  970. remainingField.setText(String.valueOf(remaining));
  971. totalDurationField.setText(String.valueOf(durationWithoutDelay + 1));
  972.  
  973. }
  974.  
  975. }
  976.  
  977.  
  978.  
  979. public void forCarExchangeIfNewCarExist_andCurrentDateLessTHanEndDate(){
  980. currentDateForRemainingMethod = new Date();
  981. endDateForRemainingMethod = java.sql.Date.valueOf(selected.getExpectedEndDate());
  982. startDateForRemainingMethod = java.sql.Date.valueOf(selected.getStartDate());
  983.  
  984. durationWithoutDelay = (endDateForRemainingMethod.getTime() - startDateForRemainingMethod.getTime()) / (60 * 60 * 24 * 1000);
  985.  
  986. // its not the same of the upper function its specialize for this method
  987. differenceDays = (currentDateForRemainingMethod.getTime() - startDateForRemainingMethod.getTime()) / (60 * 60 * 24 * 1000);
  988.  
  989. SimpleDateFormat format=new SimpleDateFormat("HH:mm");
  990. try {
  991. d1=format.parse(selected.getStartHour());
  992. d2=format.parse(DateUtil.getCurrentHour());
  993.  
  994. //in milliseconds
  995. long diff=d2.getTime() - d1.getTime();
  996. diffHours=(diff / (60 * 60 * 1000) % 24);
  997. // double diffMin = ((diff / (60 * 1000) % 60));
  998. // System.out.println(diffHours);
  999.  
  1000. } catch (ParseException e) {
  1001. throw new RuntimeException(e);
  1002. }
  1003.  
  1004. if ((diffHours >= 2)&&(diffHours < 6)) {
  1005. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  1006. new InfoMessage("warning", "there is delay in end hour....you can set new cost to final price").show();
  1007. } else {
  1008. new InfoMessage("تحذير", "هناك تأخير في ساعة الاستلام .... يمكنك اضافة تكلفة التاخير الى المجموع الكلي ").show();
  1009. }
  1010. delayPriceField.setVisible(true);
  1011. addDelayCostBtn.setVisible(true);
  1012. price = ( differenceDays * Double.parseDouble(priceDayField.getText())) - (( differenceDays * Double.parseDouble(priceDayField.getText()))*Double.parseDouble(taxTypeField.getText()));
  1013. finalTax = (( differenceDays * Double.parseDouble(priceDayField.getText()))*Double.parseDouble(taxTypeField.getText()));;
  1014. finalPrice = price + finalTax ;
  1015. remaining =selected.getRemainingAmount() -( finalPrice - (Double.parseDouble(totalPayment.getText())- selected.getDownPayment()));
  1016.  
  1017. priceField.setText(String.valueOf(price));
  1018. finalTaxField.setText(String.valueOf(finalTax));
  1019. remainingField.setText(String.valueOf(remaining));
  1020. finalPriceField.setText(String.valueOf(finalPrice));
  1021. totalDurationField.setText(String.valueOf( differenceDays));
  1022.  
  1023. }else if (diffHours >= 6) {
  1024. price = ( (differenceDays+1) * Double.parseDouble(priceDayField.getText())) - (( differenceDays * Double.parseDouble(priceDayField.getText()))*Double.parseDouble(taxTypeField.getText()));
  1025. finalTax = (( differenceDays * Double.parseDouble(priceDayField.getText()))*Double.parseDouble(taxTypeField.getText()));;
  1026. finalPrice = price + finalTax ;
  1027. remaining =selected.getRemainingAmount() -( finalPrice - (Double.parseDouble(totalPayment.getText())- selected.getDownPayment()));
  1028.  
  1029. priceField.setText(String.valueOf(price));
  1030. finalTaxField.setText(String.valueOf(finalTax));
  1031. remainingField.setText(String.valueOf(remaining));
  1032. finalPriceField.setText(String.valueOf(finalPrice));
  1033. totalDurationField.setText(String.valueOf( differenceDays+1));
  1034.  
  1035. }
  1036. else {
  1037. price = ( differenceDays * Double.parseDouble(priceDayField.getText())) - (( differenceDays * Double.parseDouble(priceDayField.getText()))*Double.parseDouble(taxTypeField.getText()));
  1038. finalTax = (( differenceDays * Double.parseDouble(priceDayField.getText()))*Double.parseDouble(taxTypeField.getText()));;
  1039. finalPrice = price + finalTax ;
  1040. remaining =selected.getRemainingAmount() -( finalPrice - (Double.parseDouble(totalPayment.getText())- selected.getDownPayment()));
  1041.  
  1042. priceField.setText(String.valueOf(price));
  1043. finalTaxField.setText(String.valueOf(finalTax));
  1044. remainingField.setText(String.valueOf(remaining));
  1045. finalPriceField.setText(String.valueOf(finalPrice));
  1046. totalDurationField.setText(String.valueOf( differenceDays));
  1047. }
  1048.  
  1049. if(Double.parseDouble(remainingField.getText()) < 0 ){
  1050. extraCredit = -1 * Double.parseDouble(remainingField.getText());
  1051. }
  1052. else if (Double.parseDouble(remainingField.getText()) == 0) {
  1053. extraCredit = Double.parseDouble(totalPayment.getText()) - finalPrice ;
  1054. }
  1055. }
  1056.  
  1057.  
  1058. public void setCloseContract_UpdateOpenContract_UpdateCar_UpdateCustomer(){
  1059.  
  1060. ClosedContract closedContract = new ClosedContract();
  1061. Car car;
  1062. CarStatus carStatus;
  1063. CarStatus carStatus1;
  1064. List<Customer> customer;
  1065.  
  1066. selected.setContractState("Closed");
  1067. selected.setPrice(Double.parseDouble(priceField.getText()));
  1068. selected.setTaxAmount(Double.parseDouble(finalTaxField.getText()));
  1069. selected.setRemainingAmount(remaining);
  1070. selected.setTotalPrice(Double.parseDouble(finalPriceField.getText()));
  1071. selected.setTotalDuration(Integer.parseInt(totalDurationField.getText()));
  1072. selected.setExpectedEndDate(LocalDate.parse(DateUtil.getDate()));
  1073. selected.setExpectedEndHour(DateUtil.getCurrentHour());
  1074.  
  1075. customer = ConnectionUtil.getEntityManager().createQuery("select c from Customer c where c.customerId=:v", Customer.class).setParameter("v", selected.getCustomerContract().getCustomerId()).getResultList();
  1076. customer.get(0).setCurrentCredit(extraCredit);
  1077.  
  1078. closedContract.setCarId(selected.getCar().getCarId());
  1079. closedContract.setContractYear(Year.now());
  1080. closedContract.setCurrentFuel(Integer.parseInt(currentFuelCombo.getSelectionModel().getSelectedItem().toString()));
  1081. closedContract.setCurrentMileage(Double.parseDouble(closeMileageField.getText()));
  1082. closedContract.setCustomerId(selected.getCustomerContract().getCustomerId());
  1083. closedContract.setEndDate(java.sql.Date.valueOf(LocalDate.now()));
  1084. closedContract.setRecievedEmployeeId(UserSession.getInstance().getUserId());
  1085. closedContract.setTotalDuration(Integer.parseInt(totalDurationField.getText()));
  1086. closedContract.setContractNumber(selected.getOpenContractId());
  1087. closedContract.setClosedHour(DateUtil.getCurrentHour());
  1088. closedContract.setOpenContract(selected);
  1089. closedContract.setStatus("Closed");
  1090.  
  1091. carStatus = ConnectionUtil.getEntityManager().createQuery("select c from CarStatus c where c.carStatusName='Available'", CarStatus.class).getSingleResult();
  1092. carStatus1 = ConnectionUtil.getEntityManager().createQuery("select c from CarStatus c where c.carStatusName='Rented'", CarStatus.class).getSingleResult();
  1093.  
  1094. car = ConnectionUtil.getEntityManager().createQuery("select c from Car c where c.carId=:v", Car.class).setParameter("v", selected.getCar().getCarId()).getSingleResult();
  1095. car.setCarStatus(carStatus);
  1096. car.setCurrentLoction(UserSession.getInstance().getBranch());
  1097.  
  1098. car1.setCarStatus(carStatus1);
  1099. car1.setCurrentLoction(UserSession.getInstance().getBranch());
  1100.  
  1101. selected.setClosedContract(closedContract);
  1102. closedContract.setOpenContract(selected);
  1103.  
  1104. ConnectionUtil.getEntityManager().persist(closedContract);
  1105. ConnectionUtil.getEntityManager().merge(car);
  1106. ConnectionUtil.getEntityManager().merge(car1);
  1107. ConnectionUtil.getEntityManager().merge(customer.get(0));
  1108. ConnectionUtil.getEntityManager().merge(selected);
  1109. if(!ConnectionUtil.getEntityManager().getTransaction().isActive()){
  1110. ConnectionUtil.getEntityManager().getTransaction().begin();
  1111. }
  1112. ConnectionUtil.getEntityManager().getTransaction().commit();
  1113. }
  1114.  
  1115.  
  1116. private void viewRent_WithCurrentCustomer_InfoAndCredit() throws IOException {
  1117. FXMLLoader fxmlLoaderr;
  1118. if (InterfaceLanguage.getInstance().getLanguage() == Language.ENGLISH) {
  1119. fxmlLoaderr = new FXMLLoader(getClass().getResource("/views/EN/Rent.fxml"));
  1120. }
  1121. else
  1122. {
  1123. fxmlLoaderr = new FXMLLoader(getClass().getResource("/views/AR/Rent.fxml"));
  1124. }
  1125. Parent root2 = (Parent) fxmlLoaderr.load();
  1126. Stage stagee = new Stage();
  1127. stagee.setScene(new Scene(root2));
  1128. RentController addProductRentController = fxmlLoaderr.getController();
  1129.  
  1130. addProductRentController.customerRadio.setDisable(true);
  1131. addProductRentController.customerSearch.setText(selected.getCustomerContract().getFirstName()+"" +selected.getCustomerContract().getMiddleName()+" "+selected.getCustomerContract().getLastName());
  1132. addProductRentController.customerSearch.setDisable(true);
  1133. addProductRentController.customerScroll.setDisable(true);
  1134.  
  1135. addProductRentController.carSearch.setDisable(true);
  1136. addProductRentController.carRadio.setDisable(true);
  1137. addProductRentController.carScroll.setDisable(true);
  1138.  
  1139. addProductRentController.addSecondDriverButton.setVisible(true);
  1140.  
  1141.  
  1142. addProductRentController.selectedCar = car1;
  1143. addProductRentController.selectedCustomer = selected.getCustomerContract();
  1144.  
  1145. addProductRentController.carSearch.setText(selected.getCar().getCarColor().getColorName()+" "+selected.getCar().getModel().getCarModel().getModelName()+" "+selected.getCar().getModel().getSubModelType());
  1146.  
  1147. addProductRentController.modelLabel.setText(addProductRentController.selectedCar.getModel().getCarModel().getModelName());
  1148. addProductRentController.subModelLabel.setText(addProductRentController.selectedCar.getModel().getSubModelType());
  1149. addProductRentController.plateLabel.setText(addProductRentController.selectedCar.getPlateNumber());
  1150. addProductRentController.driverNameLabel.setText(addProductRentController.selectedCustomer.getFirstName() + " "+ addProductRentController.selectedCustomer.getMiddleName() + " "+ addProductRentController.selectedCustomer.getLastName());
  1151. addProductRentController.currentCreditLabel.setText("" + addProductRentController.selectedCustomer.getCurrentCredit());
  1152. addProductRentController.expirationLabel.setText("" + addProductRentController.selectedCustomer.getLicenseExpirationDate());
  1153. addProductRentController.customerPhoneNumberLabel.setText("" + addProductRentController.selectedCustomer.getPhoneNumber());
  1154. addProductRentController.halfPane.setDisable(false);
  1155.  
  1156. fxmlLoaderr.setController(addProductRentController);
  1157. stagee.show();
  1158. }
  1159.  
  1160. }
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:37: error: class CloseContract is public, should be declared in a file named CloseContract.java
public class CloseContract implements Initializable {
       ^
Main.java:4: error: package com.jfoenix.controls does not exist
import com.jfoenix.controls.JFXButton;
                           ^
Main.java:5: error: package com.jfoenix.controls does not exist
import com.jfoenix.controls.JFXComboBox;
                           ^
Main.java:6: error: package com.jfoenix.controls does not exist
import com.jfoenix.controls.JFXTextField;
                           ^
Main.java:7: error: package constant does not exist
import constant.Language;
               ^
Main.java:8: error: package constant does not exist
import constant.RoleType;
               ^
Main.java:9: error: package handler does not exist
import handler.SceneHandler;
              ^
Main.java:10: error: package javafx.event does not exist
import javafx.event.ActionEvent;
                   ^
Main.java:11: error: package javafx.fxml does not exist
import javafx.fxml.FXML;
                  ^
Main.java:12: error: package javafx.fxml does not exist
import javafx.fxml.FXMLLoader;
                  ^
Main.java:13: error: package javafx.fxml does not exist
import javafx.fxml.Initializable;
                  ^
Main.java:14: error: package javafx.scene does not exist
import javafx.scene.Parent;
                   ^
Main.java:15: error: package javafx.scene does not exist
import javafx.scene.Scene;
                   ^
Main.java:16: error: package javafx.scene.control does not exist
import javafx.scene.control.DatePicker;
                           ^
Main.java:17: error: package javafx.scene.control does not exist
import javafx.scene.control.Label;
                           ^
Main.java:18: error: package javafx.stage does not exist
import javafx.stage.Stage;
                   ^
Main.java:19: error: package message does not exist
import message.InfoMessage;
              ^
Main.java:20: error: package security does not exist
import security.InterfaceLanguage;
               ^
Main.java:21: error: package security does not exist
import security.UserSession;
               ^
Main.java:22: error: package utility does not exist
import utility.ConnectionUtil;
              ^
Main.java:23: error: package utility does not exist
import utility.DateUtil;
              ^
Main.java:37: error: cannot find symbol
public class CloseContract implements Initializable {
                                      ^
  symbol: class Initializable
Main.java:41: error: cannot find symbol
    private JFXComboBox currentFuelCombo;
            ^
  symbol:   class JFXComboBox
  location: class CloseContract
Main.java:43: error: cannot find symbol
    private JFXTextField openContractField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:45: error: cannot find symbol
    private JFXTextField customerNameField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:47: error: cannot find symbol
    private JFXTextField customerSsnField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:49: error: cannot find symbol
    private JFXTextField carModelField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:51: error: cannot find symbol
    private JFXTextField carPlateNumberField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:53: error: cannot find symbol
    private JFXTextField startMileageField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:55: error: cannot find symbol
    private JFXTextField allowedMileageField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:57: error: cannot find symbol
    private JFXTextField startFuelField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:59: error: cannot find symbol
    private JFXTextField startHourField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:61: error: cannot find symbol
    private JFXTextField yearField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:63: error: cannot find symbol
    private JFXTextField priceDayField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:65: error: cannot find symbol
    private DatePicker startDatePicker;
            ^
  symbol:   class DatePicker
  location: class CloseContract
Main.java:67: error: cannot find symbol
    private DatePicker endDatePicker;
            ^
  symbol:   class DatePicker
  location: class CloseContract
Main.java:69: error: cannot find symbol
    private JFXTextField taxTypeField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:71: error: cannot find symbol
    private JFXTextField finalTaxField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:73: error: cannot find symbol
    private JFXTextField priceField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:75: error: cannot find symbol
    public JFXTextField finalPriceField;
           ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:77: error: cannot find symbol
    public JFXTextField remainingField;
           ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:79: error: cannot find symbol
    private JFXTextField notesField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:81: error: cannot find symbol
    private JFXTextField closeMileageField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:83: error: cannot find symbol
    private Label closeTotalDurationLabel;
            ^
  symbol:   class Label
  location: class CloseContract
Main.java:85: error: cannot find symbol
    public JFXButton addPaymentBtn;
           ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:87: error: cannot find symbol
    public JFXButton closeContractBtn;
           ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:89: error: cannot find symbol
    private Label mileageDifferenceLabel;
            ^
  symbol:   class Label
  location: class CloseContract
Main.java:91: error: cannot find symbol
    public Label totalPayment;
           ^
  symbol:   class Label
  location: class CloseContract
Main.java:93: error: cannot find symbol
    private JFXTextField totalDurationField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:95: error: cannot find symbol
    private JFXButton unClosedContractBtn;
            ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:97: error: cannot find symbol
    private JFXButton viewPaymentBtn;
            ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:99: error: cannot find symbol
    private JFXButton carExchangeBtn;
            ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:101: error: cannot find symbol
    private JFXButton saveEditBtn;
            ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:103: error: cannot find symbol
    private JFXButton editBtn;
            ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:105: error: cannot find symbol
    private JFXTextField delayPriceField;
            ^
  symbol:   class JFXTextField
  location: class CloseContract
Main.java:107: error: cannot find symbol
    private JFXButton addDelayCostBtn;
            ^
  symbol:   class JFXButton
  location: class CloseContract
Main.java:110: error: cannot find symbol
    public OpenContract selected;
           ^
  symbol:   class OpenContract
  location: class CloseContract
Main.java:111: error: cannot find symbol
    DisplayAllOpenedContract c;
    ^
  symbol:   class DisplayAllOpenedContract
  location: class CloseContract
Main.java:121: error: cannot find symbol
    public static Car car1;
                  ^
  symbol:   class Car
  location: class CloseContract
Main.java:188: error: cannot find symbol
    public void addCost(ActionEvent event) {
                        ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:231: error: cannot find symbol
    public void saveEdit(ActionEvent event) {
                         ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:291: error: cannot find symbol
    public void edit(ActionEvent event){
                     ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:317: error: cannot find symbol
    public void addPayments(ActionEvent event) throws IOException {
                            ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:352: error: cannot find symbol
    public void viewPayments(ActionEvent event) {
                             ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:420: error: cannot find symbol
    public void addToBlackList(ActionEvent event) {
                               ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:452: error: cannot find symbol
    public void closeContract(ActionEvent event) {
                              ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:632: error: cannot find symbol
    public void carExchange(ActionEvent event) throws IOException {
                            ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:680: error: cannot find symbol
    public void unCloseContractWithoutCarExchange(ActionEvent event) {
                                                  ^
  symbol:   class ActionEvent
  location: class CloseContract
Main.java:3: error: package Entities does not exist
import Entities.*;
^
Main.java:40: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:42: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:44: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:46: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:48: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:50: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:52: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:54: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:56: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:58: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:60: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:62: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:64: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:66: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:68: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:70: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:72: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:74: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:76: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:78: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:80: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:82: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:84: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:86: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:88: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:90: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:92: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:94: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:96: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:98: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
Main.java:100: error: cannot find symbol
    @FXML
     ^
  symbol:   class FXML
  location: class CloseContract
100 errors
stdout
Standard output is empty