From 46d6847f949440df9083a18c7e25c0a978fb47f0 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 26 Feb 2024 17:52:27 +0100 Subject: [PATCH 01/83] Create a window to manage ward Inventory --- bundle/language_en.properties | 17 + rsc/settings.properties.dist | 80 ---- .../gui/InventoryWardBrowser.java | 373 ++++++++++++++++++ .../isf/utils/jobjects/InventoryState.java | 36 ++ 4 files changed, 426 insertions(+), 80 deletions(-) delete mode 100644 rsc/settings.properties.dist create mode 100644 src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java create mode 100644 src/main/java/org/isf/utils/jobjects/InventoryState.java diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 89746f971b..8970b37525 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -305,6 +305,7 @@ angal.billbrowser.deletetheselectedbill.msg angal.billbrowser.editbill = Edit Bill angal.billbrowser.editbill.btn = Edit Bill angal.billbrowser.editbill.btn.key = E +angal.billbrowser.from = From angal.billbrowser.fullreportallbills.txt = Full Report (all bills) angal.billbrowser.inout.col = IN/OUT angal.billbrowser.lastpayment.col = Last Payment @@ -335,6 +336,7 @@ angal.billbrowser.shortreportonlybaddebt.txt angal.billbrowser.thebilldeleted.msg = The bill is deleted. angal.billbrowser.thebillisstillopen.msg = This bill is still open. angal.billbrowser.thismonth.txt = This Month +angal.billbrowser.to = To angal.billbrowser.today.btn = Today angal.billbrowser.today.btn.key = T angal.billbrowser.today.txt = Today @@ -662,6 +664,19 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. +angal.inventory.close = Close +angal.inventory.delete = Delete inventory +angal.inventory.managementwardtitle = Manage Ward Inventory +angal.inventory.new = New inventory +angal.inventory.referenceshow = Reference +angal.inventory.state = State +angal.inventory.state.canceled = Canceled +angal.inventory.state.inprogress = In progress +angal.inventory.state.validate = Validate +angal.inventory.update = Update inventory +angal.inventory.user = User +angal.inventory.view = View inventory +angal.inventory.ward = Ward angal.lab.blood.txt = Blood angal.lab.cfs.txt = CFS angal.lab.datapatient = Patient's Data @@ -1021,6 +1036,7 @@ angal.menu.btn.generaldata angal.menu.btn.groups = Groups angal.menu.btn.help = Help angal.menu.btn.hospital = Hospital +angal.menu.btn.inventory.ward = Ward Inventory angal.menu.btn.labbrowsing = Laboratory Browsing angal.menu.btn.laboratory = Laboratory angal.menu.btn.logfile = Logs @@ -1077,6 +1093,7 @@ angal.menu.generaldata angal.menu.groups = Groups angal.menu.help = Help angal.menu.hospital = Hospital +angal.menu.inventory.ward = Ward Inventory angal.menu.labbrowsing = LaboratoryBrowsing angal.menu.laboratory = Laboratory angal.menu.logfile = Logs diff --git a/rsc/settings.properties.dist b/rsc/settings.properties.dist deleted file mode 100644 index 3bded160dc..0000000000 --- a/rsc/settings.properties.dist +++ /dev/null @@ -1,80 +0,0 @@ -########################################### -# This file contains Open Hospital settings -########################################### -# external settings -MODE=OH_MODE -DEMODATA=off - -# experimental settings -APISERVER=off - -# internal settings, modules, directories -LANGUAGE=OH_LANGUAGE -SINGLEUSER=YES_OR_NO -DEBUG=no -DOC_DIR=OH_DOC_DIR -PATIENTPHOTOSTORAGE=PHOTO_DIR -INTERNALVIEWER=yes -SMSENABLED=no -VIDEOMODULEENABLED=yes -XMPPMODULEENABLED=no -PARAMSURL=https://conf.open-hospital.org/oh-conf.json - -# application settings -ENHANCEDSEARCH=no -INTERNALPHARMACIES=yes -LABEXTENDED=yes -LABMULTIPLEINSERT=yes -MATERNITYRESTARTINJUNE=no -MERGEFUNCTION=yes -OPDEXTENDED=yes -PATIENTEXTENDED=yes -PATIENTVACCINEEXTENDED=yes - -# GUI settings -MAINMENUALWAYSONTOP=no - -# accounting -ALLOWMULTIPLEOPENEDBILL=yes -ALLOWPRINTOPENEDBILL=yes -BILLSREPORT=BillsReport -BILLSREPORTMONTHLY=BillsReportMonthly -BILLSREPORTPENDING=BillsReportPending -PATIENTBILL=PatientBill -PATIENTBILLGROUPED=PatientBillGrouped -PATIENTBILLSTATEMENT=PatientBillStatement -RECEIPTPRINTER=yes - -# pharmacy -AUTOMATICLOT_IN=no -AUTOMATICLOT_OUT=no -AUTOMATICLOTWARD_TOWARD=no -LOTWITHCOST=yes -PHARMACEUTICALORDER=PharmaceuticalOrder -PHARMACEUTICALSTOCK=PharmaceuticalStock_ver4 -PHARMACEUTICALSTOCKLOT=PharmaceuticalStock_ver5 -PHARMACEUTICALAMC=PharmaceuticalAMC - -# dicom / imaging settings -DICOMMODULEENABLED=yes -DICOMTHUMBNAILS=yes - -# reports -ADMCHART=patient_adm_chart -DISCHART=patient_dis_chart -EXAMINATIONCHART=patient_examination -OPDCHART=patient_opd_chart -PATIENTSHEET=patient_clinical_sheet_ver3 -VISITSHEET=WardVisits - -# security -SESSIONTIMEOUT=5 -STRONGPASSWORD=yes -STRONGLENGTH=6 -USERSLISTLOGIN=no -PASSWORDTRIES=5 -PASSWORDLOCKTIME=60 -PASSWORDIDLE=365 - -# telemetry -TELEMETRYENABLED=yes diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java new file mode 100644 index 0000000000..3680d279d1 --- /dev/null +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -0,0 +1,373 @@ +package org.isf.medicalinventory.gui; + +import org.isf.utils.jobjects.InventoryState; +import org.isf.generaldata.MessageBundle; +import org.isf.utils.jobjects.ModalJFrame; + +import com.toedter.calendar.JDateChooser; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.GregorianCalendar; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import java.awt.Dimension; +import javax.swing.JFrame; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Insets; + +import javax.swing.JComboBox; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +public class InventoryWardBrowser extends ModalJFrame { + + private static final long serialVersionUID = 1L; + + private JDateChooser jCalendarTo; + private JDateChooser jCalendarFrom; + private GregorianCalendar dateFrom = new GregorianCalendar(); + private GregorianCalendar dateTo = new GregorianCalendar(); + private JLabel jLabelTo; + private JLabel jLabelFrom; + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton newButton; + private JButton updateButton; + private JButton deleteButton; + private JButton viewButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventory; + private String[] pColums = { MessageBundle.getMessage("angal.inventory.referenceshow"), + MessageBundle.getMessage("angal.inventory.ward"), MessageBundle.getMessage("angal.common.date.txt"), + MessageBundle.getMessage("angal.inventory.state"), MessageBundle.getMessage("angal.inventory.user") }; + private int[] pColumwidth = { 150, 150, 100, 100, 150 }; + private JComboBox stateComboBox; + private JLabel stateLabel; + + public InventoryWardBrowser() { + initComponents(); + } + + private void initComponents() { + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new Dimension(850, 550)); + setLocationRelativeTo(null); // center + setTitle(MessageBundle.getMessage("angal.inventory.managementwardtitle")); + + panelHeader = getPanelHeader(); + getContentPane().add(panelHeader, BorderLayout.NORTH); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + panelFooter = getPanelFooter(); + getContentPane().add(panelFooter, BorderLayout.SOUTH); + + ajustWidth(); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + dispose(); + } + }); + // pack(); + } + + private JPanel getPanelHeader() { + if (panelHeader == null) { + panelHeader = new JPanel(); + panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); + GridBagLayout gbl_panelHeader = new GridBagLayout(); + gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; + gbl_panelHeader.rowHeights = new int[] { 32, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; + panelHeader.setLayout(gbl_panelHeader); + GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); + gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); + gbc_jLabelFrom.gridx = 0; + gbc_jLabelFrom.gridy = 0; + panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); + GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); + gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarFrom.gridx = 1; + gbc_jCalendarFrom.gridy = 0; + panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); + GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); + gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); + gbc_jLabelTo.gridx = 2; + gbc_jLabelTo.gridy = 0; + panelHeader.add(getJLabelTo(), gbc_jLabelTo); + GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); + gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarTo.gridx = 3; + gbc_jCalendarTo.gridy = 0; + panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); + GridBagConstraints gbc_stateLabel = new GridBagConstraints(); + gbc_stateLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_stateLabel.insets = new Insets(0, 0, 0, 5); + gbc_stateLabel.gridx = 4; + gbc_stateLabel.gridy = 0; + panelHeader.add(getStateLabel(), gbc_stateLabel); + GridBagConstraints gbc_comboBox = new GridBagConstraints(); + gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_comboBox.gridx = 5; + gbc_comboBox.gridy = 0; + panelHeader.add(getComboBox(), gbc_comboBox); + } + return panelHeader; + } + + private JPanel getPanelContent() { + if (panelContent == null) { + panelContent = new JPanel(); + GridBagLayout gbl_panelContent = new GridBagLayout(); + gbl_panelContent.columnWidths = new int[] { 452, 0 }; + gbl_panelContent.rowHeights = new int[] { 402, 0 }; + gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + panelContent.setLayout(gbl_panelContent); + GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); + gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; + gbc_scrollPaneInventory.gridx = 0; + gbc_scrollPaneInventory.gridy = 0; + panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); + } + return panelContent; + } + + private JPanel getPanelFooter() { + if (panelFooter == null) { + panelFooter = new JPanel(); + panelFooter.add(getNewButton()); + panelFooter.add(getViewButton()); + panelFooter.add(getUpdateButton()); + panelFooter.add(getDeleteButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private JDateChooser getJCalendarFrom() { + if (jCalendarFrom == null) { + dateFrom.set(GregorianCalendar.HOUR_OF_DAY, 0); + dateFrom.set(GregorianCalendar.MINUTE, 0); + dateFrom.set(GregorianCalendar.SECOND, 0); + + jCalendarFrom = new JDateChooser(dateFrom.getTime()); // Calendar + jCalendarFrom.setDateFormatString("dd/MM/yy"); //$NON-NLS-1$ + jCalendarFrom.addPropertyChangeListener("date", new PropertyChangeListener() { //$NON-NLS-1$ + + public void propertyChange(PropertyChangeEvent evt) { + jCalendarFrom.setDate((Date) evt.getNewValue()); + dateFrom.setTime((Date) evt.getNewValue()); + dateFrom.set(GregorianCalendar.HOUR_OF_DAY, 0); + dateFrom.set(GregorianCalendar.MINUTE, 0); + dateFrom.set(GregorianCalendar.SECOND, 0); + jTableInventory.setModel(new InventoryBrowsingModel()); + } + }); + } + return jCalendarFrom; + } + + private JDateChooser getJCalendarTo() { + if (jCalendarTo == null) { + dateTo.set(GregorianCalendar.HOUR_OF_DAY, 23); + dateTo.set(GregorianCalendar.MINUTE, 59); + dateTo.set(GregorianCalendar.SECOND, 59); + jCalendarTo = new JDateChooser(dateTo.getTime()); // Calendar + jCalendarTo.setDateFormatString("dd/MM/yy"); //$NON-NLS-1$ + jCalendarTo.addPropertyChangeListener("date", new PropertyChangeListener() { //$NON-NLS-1$ + + public void propertyChange(PropertyChangeEvent evt) { + jCalendarTo.setDate((Date) evt.getNewValue()); + dateTo.setTime((Date) evt.getNewValue()); + dateTo.set(GregorianCalendar.HOUR_OF_DAY, 23); + dateTo.set(GregorianCalendar.MINUTE, 59); + dateTo.set(GregorianCalendar.SECOND, 59); + jTableInventory.setModel(new InventoryBrowsingModel()); + } + }); + } + return jCalendarTo; + } + + private JLabel getJLabelTo() { + if (jLabelTo == null) { + jLabelTo = new JLabel(); + jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelTo.setText(MessageBundle.getMessage("angal.billbrowser.to")); //$NON-NLS-1$ + } + return jLabelTo; + } + + private JLabel getJLabelFrom() { + if (jLabelFrom == null) { + jLabelFrom = new JLabel(); + jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelFrom.setText(MessageBundle.getMessage("angal.billbrowser.from")); //$NON-NLS-1$ + } + return jLabelFrom; + } + + private JButton getNewButton() { + newButton = new JButton(MessageBundle.getMessage("angal.inventory.new")); + newButton.setMnemonic(KeyEvent.VK_N); + return newButton; + } + + private JButton getViewButton() { + viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view")); + viewButton.setMnemonic(KeyEvent.VK_V); + return viewButton; + } + + private JButton getUpdateButton() { + updateButton = new JButton(MessageBundle.getMessage("angal.inventory.update")); + updateButton.setMnemonic(KeyEvent.VK_M); + return updateButton; + } + + private JButton getDeleteButton() { + deleteButton = new JButton(MessageBundle.getMessage("angal.inventory.delete")); + deleteButton.setMnemonic(KeyEvent.VK_D); + return deleteButton; + } + + private JButton getCloseButton() { + closeButton = new JButton(MessageBundle.getMessage("angal.inventory.close")); + closeButton.setMnemonic(KeyEvent.VK_C); + closeButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + return closeButton; + } + + /* + * private JButton getInitialStocksButton() { initialStocksButton = new + * JButton(MessageBundle.getMessage("angal.inventory.initialstocks")); + * initialStocksButton.setMnemonic(KeyEvent.VK_N); + * initialStocksButton.addActionListener(new ActionListener() { public void + * actionPerformed(ActionEvent e) { WardInitialStocks wardInitialStocks = new + * WardInitialStocks(); + * + * if (Param.bool("WITHMODALWINDOW")) { + * wardInitialStocks.showAsModal(InventoryWardBrowser.this); } else { + * wardInitialStocks.show(InventoryWardBrowser.this); } // } }); return + * initialStocksButton; } + */ + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + scrollPaneInventory.setViewportView(getJTableInventory()); + } + return scrollPaneInventory; + } + + private JTable getJTableInventory() { + if (jTableInventory == null) { + jTableInventory = new JTable(); + jTableInventory.setFillsViewportHeight(true); + jTableInventory.setModel(new InventoryBrowsingModel()); + } + return jTableInventory; + } + + class InventoryBrowsingModel extends DefaultTableModel { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public InventoryBrowsingModel() { + + } + + public Class getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return String.class; + } else if (c == 3) { + return String.class; + } else if (c == 4) { + return String.class; + } + return null; + } + + public String getColumnName(int c) { + return pColums[c]; + } + + public int getColumnCount() { + return pColums.length; + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + return false; + } + + } + + public String formatDateTime(GregorianCalendar time) { + SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy"); //$NON-NLS-1$ + return format.format(time.getTime()); + } + + private void ajustWidth() { + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); + } + } + + private JComboBox getComboBox() { + if (stateComboBox == null) { + stateComboBox = new JComboBox(); + stateComboBox.addItem(""); + for (InventoryState.State currentState : InventoryState.State.values()) { + stateComboBox.addItem(MessageBundle.getMessage(currentState.getLabel())); + } + } + return stateComboBox; + } + + private JLabel getStateLabel() { + if (stateLabel == null) { + stateLabel = new JLabel(MessageBundle.getMessage("angal.inventory.state")); + stateLabel.setHorizontalAlignment(SwingConstants.RIGHT); + } + return stateLabel; + } +} diff --git a/src/main/java/org/isf/utils/jobjects/InventoryState.java b/src/main/java/org/isf/utils/jobjects/InventoryState.java new file mode 100644 index 0000000000..19f062760f --- /dev/null +++ b/src/main/java/org/isf/utils/jobjects/InventoryState.java @@ -0,0 +1,36 @@ +package org.isf.utils.jobjects; + +public class InventoryState { + public InventoryState() { + } + + public enum State { + PROGRESS("1", "angal.inventory.state.inprogress"), + CANCELED("2", "angal.inventory.state.canceled"), + VALIDATE("3", "angal.inventory.state.validate"); + + String code; + String label; + + private State(String code, String label) { + this.code = code; + this.label = label; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + } +} From c75c27d62b63bdb5bca747a2d21300b31f6a716a Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 27 Feb 2024 11:52:34 +0100 Subject: [PATCH 02/83] fix reviewed change --- rsc/settings.properties.dist | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 rsc/settings.properties.dist diff --git a/rsc/settings.properties.dist b/rsc/settings.properties.dist new file mode 100644 index 0000000000..3bded160dc --- /dev/null +++ b/rsc/settings.properties.dist @@ -0,0 +1,80 @@ +########################################### +# This file contains Open Hospital settings +########################################### +# external settings +MODE=OH_MODE +DEMODATA=off + +# experimental settings +APISERVER=off + +# internal settings, modules, directories +LANGUAGE=OH_LANGUAGE +SINGLEUSER=YES_OR_NO +DEBUG=no +DOC_DIR=OH_DOC_DIR +PATIENTPHOTOSTORAGE=PHOTO_DIR +INTERNALVIEWER=yes +SMSENABLED=no +VIDEOMODULEENABLED=yes +XMPPMODULEENABLED=no +PARAMSURL=https://conf.open-hospital.org/oh-conf.json + +# application settings +ENHANCEDSEARCH=no +INTERNALPHARMACIES=yes +LABEXTENDED=yes +LABMULTIPLEINSERT=yes +MATERNITYRESTARTINJUNE=no +MERGEFUNCTION=yes +OPDEXTENDED=yes +PATIENTEXTENDED=yes +PATIENTVACCINEEXTENDED=yes + +# GUI settings +MAINMENUALWAYSONTOP=no + +# accounting +ALLOWMULTIPLEOPENEDBILL=yes +ALLOWPRINTOPENEDBILL=yes +BILLSREPORT=BillsReport +BILLSREPORTMONTHLY=BillsReportMonthly +BILLSREPORTPENDING=BillsReportPending +PATIENTBILL=PatientBill +PATIENTBILLGROUPED=PatientBillGrouped +PATIENTBILLSTATEMENT=PatientBillStatement +RECEIPTPRINTER=yes + +# pharmacy +AUTOMATICLOT_IN=no +AUTOMATICLOT_OUT=no +AUTOMATICLOTWARD_TOWARD=no +LOTWITHCOST=yes +PHARMACEUTICALORDER=PharmaceuticalOrder +PHARMACEUTICALSTOCK=PharmaceuticalStock_ver4 +PHARMACEUTICALSTOCKLOT=PharmaceuticalStock_ver5 +PHARMACEUTICALAMC=PharmaceuticalAMC + +# dicom / imaging settings +DICOMMODULEENABLED=yes +DICOMTHUMBNAILS=yes + +# reports +ADMCHART=patient_adm_chart +DISCHART=patient_dis_chart +EXAMINATIONCHART=patient_examination +OPDCHART=patient_opd_chart +PATIENTSHEET=patient_clinical_sheet_ver3 +VISITSHEET=WardVisits + +# security +SESSIONTIMEOUT=5 +STRONGPASSWORD=yes +STRONGLENGTH=6 +USERSLISTLOGIN=no +PASSWORDTRIES=5 +PASSWORDLOCKTIME=60 +PASSWORDIDLE=365 + +# telemetry +TELEMETRYENABLED=yes From e1dd299c933403f53e4167163f548894544ed533 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 27 Feb 2024 11:54:09 +0100 Subject: [PATCH 03/83] fix reviewed change --- .../medicalinventory/gui/InventoryWardBrowser.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 3680d279d1..cc6aa4e8bd 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -269,20 +269,6 @@ public void actionPerformed(ActionEvent e) { return closeButton; } - /* - * private JButton getInitialStocksButton() { initialStocksButton = new - * JButton(MessageBundle.getMessage("angal.inventory.initialstocks")); - * initialStocksButton.setMnemonic(KeyEvent.VK_N); - * initialStocksButton.addActionListener(new ActionListener() { public void - * actionPerformed(ActionEvent e) { WardInitialStocks wardInitialStocks = new - * WardInitialStocks(); - * - * if (Param.bool("WITHMODALWINDOW")) { - * wardInitialStocks.showAsModal(InventoryWardBrowser.this); } else { - * wardInitialStocks.show(InventoryWardBrowser.this); } // } }); return - * initialStocksButton; } - */ - private JScrollPane getScrollPaneInventory() { if (scrollPaneInventory == null) { scrollPaneInventory = new JScrollPane(); From 9e3d42bde3724d85fc971be8b0e8aab50e2e7758 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 27 Feb 2024 14:29:40 +0100 Subject: [PATCH 04/83] add the standard license header comment block --- .../gui/InventoryWardBrowser.java | 21 +++++++++++++++++++ .../isf/utils/jobjects/InventoryState.java | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index cc6aa4e8bd..83e6198257 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -1,3 +1,24 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.isf.medicalinventory.gui; import org.isf.utils.jobjects.InventoryState; diff --git a/src/main/java/org/isf/utils/jobjects/InventoryState.java b/src/main/java/org/isf/utils/jobjects/InventoryState.java index 19f062760f..ba7eda55ec 100644 --- a/src/main/java/org/isf/utils/jobjects/InventoryState.java +++ b/src/main/java/org/isf/utils/jobjects/InventoryState.java @@ -1,3 +1,24 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.isf.utils.jobjects; public class InventoryState { From 904ee1f3aa02c59d4bccd6297f1f8e7f4f37e834 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 27 Feb 2024 16:07:54 +0100 Subject: [PATCH 05/83] Fix order import --- .../gui/InventoryWardBrowser.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 83e6198257..af38a0e3b8 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -21,17 +21,11 @@ */ package org.isf.medicalinventory.gui; -import org.isf.utils.jobjects.InventoryState; -import org.isf.generaldata.MessageBundle; -import org.isf.utils.jobjects.ModalJFrame; - -import com.toedter.calendar.JDateChooser; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; - import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; @@ -42,19 +36,23 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; -import java.awt.Dimension; -import javax.swing.JFrame; -import java.awt.GridBagLayout; -import java.awt.GridBagConstraints; -import java.awt.Insets; +import org.isf.generaldata.MessageBundle; +import org.isf.utils.jobjects.InventoryState; +import org.isf.utils.jobjects.ModalJFrame; -import javax.swing.JComboBox; -import javax.swing.SwingConstants; -import javax.swing.border.EmptyBorder; +import com.toedter.calendar.JDateChooser; public class InventoryWardBrowser extends ModalJFrame { @@ -377,4 +375,4 @@ private JLabel getStateLabel() { } return stateLabel; } -} +} \ No newline at end of file From b2c1e5f7043fef7cf29c2a63048c053a63aee45b Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 27 Feb 2024 17:57:24 +0100 Subject: [PATCH 06/83] Fix all reviewed change --- bundle/language_en.properties | 31 +++--- .../gui/InventoryWardBrowser.java | 97 ++++++++----------- .../isf/utils/jobjects/InventoryState.java | 6 +- 3 files changed, 58 insertions(+), 76 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 8970b37525..4f715273bb 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -305,7 +305,6 @@ angal.billbrowser.deletetheselectedbill.msg angal.billbrowser.editbill = Edit Bill angal.billbrowser.editbill.btn = Edit Bill angal.billbrowser.editbill.btn.key = E -angal.billbrowser.from = From angal.billbrowser.fullreportallbills.txt = Full Report (all bills) angal.billbrowser.inout.col = IN/OUT angal.billbrowser.lastpayment.col = Last Payment @@ -664,19 +663,21 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. -angal.inventory.close = Close -angal.inventory.delete = Delete inventory +angal.inventory.close.btn = Close +angal.inventory.date.col = Date +angal.inventory.delete.btn = Delete inventory angal.inventory.managementwardtitle = Manage Ward Inventory -angal.inventory.new = New inventory -angal.inventory.referenceshow = Reference -angal.inventory.state = State -angal.inventory.state.canceled = Canceled -angal.inventory.state.inprogress = In progress -angal.inventory.state.validate = Validate -angal.inventory.update = Update inventory -angal.inventory.user = User -angal.inventory.view = View inventory -angal.inventory.ward = Ward +angal.inventory.new.btn = New inventory +angal.inventory.referenceshow.col = Reference +angal.inventory.state.col = State +angal.inventory.state.label = State +angal.inventory.state.canceled.txt = Canceled +angal.inventory.state.inprogress.txt = In progress +angal.inventory.state.validate.txt = Validate +angal.inventory.update.btn = Update inventory +angal.inventory.user.col = User +angal.inventory.view.btn = View inventory +angal.inventory.ward.col = Ward angal.lab.blood.txt = Blood angal.lab.cfs.txt = CFS angal.lab.datapatient = Patient's Data @@ -1036,7 +1037,7 @@ angal.menu.btn.generaldata angal.menu.btn.groups = Groups angal.menu.btn.help = Help angal.menu.btn.hospital = Hospital -angal.menu.btn.inventory.ward = Ward Inventory +angal.menu.btn.inventoryward = Ward Inventory angal.menu.btn.labbrowsing = Laboratory Browsing angal.menu.btn.laboratory = Laboratory angal.menu.btn.logfile = Logs @@ -1093,7 +1094,7 @@ angal.menu.generaldata angal.menu.groups = Groups angal.menu.help = Help angal.menu.hospital = Hospital -angal.menu.inventory.ward = Ward Inventory +angal.menu.inventoryward = Ward Inventory angal.menu.labbrowsing = LaboratoryBrowsing angal.menu.laboratory = Laboratory angal.menu.logfile = Logs diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index af38a0e3b8..13f4352d96 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -31,10 +31,9 @@ import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.GregorianCalendar; import javax.swing.JButton; @@ -49,19 +48,19 @@ import javax.swing.table.DefaultTableModel; import org.isf.generaldata.MessageBundle; +import org.isf.utils.jobjects.GoodDateChooser; import org.isf.utils.jobjects.InventoryState; import org.isf.utils.jobjects.ModalJFrame; - -import com.toedter.calendar.JDateChooser; +import org.isf.utils.time.TimeTools; public class InventoryWardBrowser extends ModalJFrame { private static final long serialVersionUID = 1L; - private JDateChooser jCalendarTo; - private JDateChooser jCalendarFrom; - private GregorianCalendar dateFrom = new GregorianCalendar(); - private GregorianCalendar dateTo = new GregorianCalendar(); + private GoodDateChooser jCalendarTo; + private GoodDateChooser jCalendarFrom; + private LocalDateTime dateFrom = TimeTools.getDateToday0(); + private LocalDateTime dateTo = TimeTools.getDateToday24(); private JLabel jLabelTo; private JLabel jLabelFrom; private JPanel panelHeader; @@ -74,9 +73,10 @@ public class InventoryWardBrowser extends ModalJFrame { private JButton viewButton; private JScrollPane scrollPaneInventory; private JTable jTableInventory; - private String[] pColums = { MessageBundle.getMessage("angal.inventory.referenceshow"), - MessageBundle.getMessage("angal.inventory.ward"), MessageBundle.getMessage("angal.common.date.txt"), - MessageBundle.getMessage("angal.inventory.state"), MessageBundle.getMessage("angal.inventory.user") }; + private String[] pColums = { MessageBundle.getMessage("angal.inventory.referenceshow.col"), + MessageBundle.getMessage("angal.inventory.ward.col"), MessageBundle.getMessage("angal.common.date.txt"), + MessageBundle.getMessage("angal.inventory.state.col"), + MessageBundle.getMessage("angal.inventory.user.col") }; private int[] pColumwidth = { 150, 150, 100, 100, 150 }; private JComboBox stateComboBox; private JLabel stateLabel; @@ -101,7 +101,9 @@ private void initComponents() { panelFooter = getPanelFooter(); getContentPane().add(panelFooter, BorderLayout.SOUTH); - ajustWidth(); + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); + } addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -190,47 +192,32 @@ private JPanel getPanelFooter() { return panelFooter; } - private JDateChooser getJCalendarFrom() { + private GoodDateChooser getJCalendarFrom() { if (jCalendarFrom == null) { - dateFrom.set(GregorianCalendar.HOUR_OF_DAY, 0); - dateFrom.set(GregorianCalendar.MINUTE, 0); - dateFrom.set(GregorianCalendar.SECOND, 0); - - jCalendarFrom = new JDateChooser(dateFrom.getTime()); // Calendar - jCalendarFrom.setDateFormatString("dd/MM/yy"); //$NON-NLS-1$ - jCalendarFrom.addPropertyChangeListener("date", new PropertyChangeListener() { //$NON-NLS-1$ - - public void propertyChange(PropertyChangeEvent evt) { - jCalendarFrom.setDate((Date) evt.getNewValue()); - dateFrom.setTime((Date) evt.getNewValue()); - dateFrom.set(GregorianCalendar.HOUR_OF_DAY, 0); - dateFrom.set(GregorianCalendar.MINUTE, 0); - dateFrom.set(GregorianCalendar.SECOND, 0); - jTableInventory.setModel(new InventoryBrowsingModel()); + jCalendarFrom = new GoodDateChooser(dateFrom.toLocalDate()); + jCalendarFrom.addDateChangeListener(dateChangeEvent -> { + LocalDate newDate = dateChangeEvent.getNewDate(); + if (newDate != null) { + dateFrom = newDate.atStartOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); } }); + jCalendarFrom.setEnabled(false); } return jCalendarFrom; } - private JDateChooser getJCalendarTo() { + private GoodDateChooser getJCalendarTo() { if (jCalendarTo == null) { - dateTo.set(GregorianCalendar.HOUR_OF_DAY, 23); - dateTo.set(GregorianCalendar.MINUTE, 59); - dateTo.set(GregorianCalendar.SECOND, 59); - jCalendarTo = new JDateChooser(dateTo.getTime()); // Calendar - jCalendarTo.setDateFormatString("dd/MM/yy"); //$NON-NLS-1$ - jCalendarTo.addPropertyChangeListener("date", new PropertyChangeListener() { //$NON-NLS-1$ - - public void propertyChange(PropertyChangeEvent evt) { - jCalendarTo.setDate((Date) evt.getNewValue()); - dateTo.setTime((Date) evt.getNewValue()); - dateTo.set(GregorianCalendar.HOUR_OF_DAY, 23); - dateTo.set(GregorianCalendar.MINUTE, 59); - dateTo.set(GregorianCalendar.SECOND, 59); - jTableInventory.setModel(new InventoryBrowsingModel()); + jCalendarTo = new GoodDateChooser(dateTo.toLocalDate(), false); + jCalendarTo.addDateChangeListener(dateChangeEvent -> { + LocalDate newDate = dateChangeEvent.getNewDate(); + if (newDate != null) { + dateTo = newDate.atStartOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); } }); + jCalendarTo.setEnabled(false); } return jCalendarTo; } @@ -239,7 +226,7 @@ private JLabel getJLabelTo() { if (jLabelTo == null) { jLabelTo = new JLabel(); jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelTo.setText(MessageBundle.getMessage("angal.billbrowser.to")); //$NON-NLS-1$ + jLabelTo.setText(MessageBundle.getMessage("angal.common.to.txt")); //$NON-NLS-1$ } return jLabelTo; } @@ -248,37 +235,37 @@ private JLabel getJLabelFrom() { if (jLabelFrom == null) { jLabelFrom = new JLabel(); jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelFrom.setText(MessageBundle.getMessage("angal.billbrowser.from")); //$NON-NLS-1$ + jLabelFrom.setText(MessageBundle.getMessage("angal.common.from.txt")); //$NON-NLS-1$ } return jLabelFrom; } private JButton getNewButton() { - newButton = new JButton(MessageBundle.getMessage("angal.inventory.new")); + newButton = new JButton(MessageBundle.getMessage("angal.inventory.new.btn")); newButton.setMnemonic(KeyEvent.VK_N); return newButton; } private JButton getViewButton() { - viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view")); + viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); viewButton.setMnemonic(KeyEvent.VK_V); return viewButton; } private JButton getUpdateButton() { - updateButton = new JButton(MessageBundle.getMessage("angal.inventory.update")); + updateButton = new JButton(MessageBundle.getMessage("angal.inventory.update.btn")); updateButton.setMnemonic(KeyEvent.VK_M); return updateButton; } private JButton getDeleteButton() { - deleteButton = new JButton(MessageBundle.getMessage("angal.inventory.delete")); + deleteButton = new JButton(MessageBundle.getMessage("angal.inventory.delete.btn")); deleteButton.setMnemonic(KeyEvent.VK_D); return deleteButton; } private JButton getCloseButton() { - closeButton = new JButton(MessageBundle.getMessage("angal.inventory.close")); + closeButton = new JButton(MessageBundle.getMessage("angal.inventory.close.btn")); closeButton.setMnemonic(KeyEvent.VK_C); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -351,12 +338,6 @@ public String formatDateTime(GregorianCalendar time) { return format.format(time.getTime()); } - private void ajustWidth() { - for (int i = 0; i < pColumwidth.length; i++) { - jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); - } - } - private JComboBox getComboBox() { if (stateComboBox == null) { stateComboBox = new JComboBox(); @@ -370,7 +351,7 @@ private JComboBox getComboBox() { private JLabel getStateLabel() { if (stateLabel == null) { - stateLabel = new JLabel(MessageBundle.getMessage("angal.inventory.state")); + stateLabel = new JLabel(MessageBundle.getMessage("angal.inventory.state.label")); stateLabel.setHorizontalAlignment(SwingConstants.RIGHT); } return stateLabel; diff --git a/src/main/java/org/isf/utils/jobjects/InventoryState.java b/src/main/java/org/isf/utils/jobjects/InventoryState.java index ba7eda55ec..f76c57d421 100644 --- a/src/main/java/org/isf/utils/jobjects/InventoryState.java +++ b/src/main/java/org/isf/utils/jobjects/InventoryState.java @@ -26,9 +26,9 @@ public InventoryState() { } public enum State { - PROGRESS("1", "angal.inventory.state.inprogress"), - CANCELED("2", "angal.inventory.state.canceled"), - VALIDATE("3", "angal.inventory.state.validate"); + PROGRESS("1", "angal.inventory.state.inprogress.txt"), + CANCELED("2", "angal.inventory.state.canceled.txt"), + VALIDATE("3", "angal.inventory.state.validate.txt"); String code; String label; From 95c389a4dc9c52ae52eeae37b7ca891799956887 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 28 Feb 2024 08:18:05 +0100 Subject: [PATCH 07/83] Change hardcode mnemonic to bundle message --- bundle/language_en.properties | 9 +++---- .../gui/InventoryWardBrowser.java | 27 +++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 4f715273bb..1682976d02 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -366,6 +366,7 @@ angal.common.codestar angal.common.count.label = Count: angal.common.datacouldnotbesaved.msg = The data could not be saved. angal.common.date.txt = Date +angal.common.date.col = Date angal.common.datefrom.label = Date From: angal.common.dateto.label = Date To: angal.common.days.txt = Days @@ -476,6 +477,7 @@ angal.common.user.col angal.common.userid = User angal.common.userid.label = User: angal.common.ward.txt = Ward +angal.common.ward.col = Ward angal.common.weight.txt = Weight angal.common.years.txt = Years angal.dicom.afileinthefolderistoobigpleasesetdicommaxsizeindicomproperties.fmt.msg = A file in the folder is too big. Please set 'dicom.max.size' in dicom.properties ({0}). @@ -663,21 +665,16 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. -angal.inventory.close.btn = Close -angal.inventory.date.col = Date -angal.inventory.delete.btn = Delete inventory angal.inventory.managementwardtitle = Manage Ward Inventory -angal.inventory.new.btn = New inventory angal.inventory.referenceshow.col = Reference angal.inventory.state.col = State angal.inventory.state.label = State angal.inventory.state.canceled.txt = Canceled angal.inventory.state.inprogress.txt = In progress angal.inventory.state.validate.txt = Validate -angal.inventory.update.btn = Update inventory angal.inventory.user.col = User angal.inventory.view.btn = View inventory -angal.inventory.ward.col = Ward +angal.inventory.view.btn.key = V angal.lab.blood.txt = Blood angal.lab.cfs.txt = CFS angal.lab.datapatient = Patient's Data diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 13f4352d96..6aa2af2acc 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -28,7 +28,6 @@ import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.text.SimpleDateFormat; @@ -74,9 +73,9 @@ public class InventoryWardBrowser extends ModalJFrame { private JScrollPane scrollPaneInventory; private JTable jTableInventory; private String[] pColums = { MessageBundle.getMessage("angal.inventory.referenceshow.col"), - MessageBundle.getMessage("angal.inventory.ward.col"), MessageBundle.getMessage("angal.common.date.txt"), + MessageBundle.getMessage("angal.common.ward.col"), MessageBundle.getMessage("angal.common.date.col"), MessageBundle.getMessage("angal.inventory.state.col"), - MessageBundle.getMessage("angal.inventory.user.col") }; + MessageBundle.getMessage("angal.common.user.col") }; private int[] pColumwidth = { 150, 150, 100, 100, 150 }; private JComboBox stateComboBox; private JLabel stateLabel; @@ -226,7 +225,7 @@ private JLabel getJLabelTo() { if (jLabelTo == null) { jLabelTo = new JLabel(); jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelTo.setText(MessageBundle.getMessage("angal.common.to.txt")); //$NON-NLS-1$ + jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); //$NON-NLS-1$ } return jLabelTo; } @@ -235,38 +234,38 @@ private JLabel getJLabelFrom() { if (jLabelFrom == null) { jLabelFrom = new JLabel(); jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelFrom.setText(MessageBundle.getMessage("angal.common.from.txt")); //$NON-NLS-1$ + jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); //$NON-NLS-1$ } return jLabelFrom; } private JButton getNewButton() { - newButton = new JButton(MessageBundle.getMessage("angal.inventory.new.btn")); - newButton.setMnemonic(KeyEvent.VK_N); + newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); + newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); return newButton; } private JButton getViewButton() { viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); - viewButton.setMnemonic(KeyEvent.VK_V); + viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); return viewButton; } private JButton getUpdateButton() { - updateButton = new JButton(MessageBundle.getMessage("angal.inventory.update.btn")); - updateButton.setMnemonic(KeyEvent.VK_M); + updateButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); + updateButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); return updateButton; } private JButton getDeleteButton() { - deleteButton = new JButton(MessageBundle.getMessage("angal.inventory.delete.btn")); - deleteButton.setMnemonic(KeyEvent.VK_D); + deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); + deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); return deleteButton; } private JButton getCloseButton() { - closeButton = new JButton(MessageBundle.getMessage("angal.inventory.close.btn")); - closeButton.setMnemonic(KeyEvent.VK_C); + closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); + closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); From 74fcc4a4c301411eb3572a31f2fd29204c7b3123 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 28 Feb 2024 08:23:12 +0100 Subject: [PATCH 08/83] remove unused methode --- bundle/language_en.properties | 1 - .../org/isf/medicalinventory/gui/InventoryWardBrowser.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 1682976d02..52342599c7 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -335,7 +335,6 @@ angal.billbrowser.shortreportonlybaddebt.txt angal.billbrowser.thebilldeleted.msg = The bill is deleted. angal.billbrowser.thebillisstillopen.msg = This bill is still open. angal.billbrowser.thismonth.txt = This Month -angal.billbrowser.to = To angal.billbrowser.today.btn = Today angal.billbrowser.today.btn.key = T angal.billbrowser.today.txt = Today diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 6aa2af2acc..173915f687 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -332,11 +332,6 @@ public boolean isCellEditable(int arg0, int arg1) { } - public String formatDateTime(GregorianCalendar time) { - SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy"); //$NON-NLS-1$ - return format.format(time.getTime()); - } - private JComboBox getComboBox() { if (stateComboBox == null) { stateComboBox = new JComboBox(); From 34a1c44f8c84137f1a599092efca14b712640d9f Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 28 Feb 2024 08:27:09 +0100 Subject: [PATCH 09/83] Uppercase all column headings --- .../medicalinventory/gui/InventoryWardBrowser.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 173915f687..c82d936f30 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -30,10 +30,8 @@ import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.GregorianCalendar; import javax.swing.JButton; import javax.swing.JComboBox; @@ -72,10 +70,13 @@ public class InventoryWardBrowser extends ModalJFrame { private JButton viewButton; private JScrollPane scrollPaneInventory; private JTable jTableInventory; - private String[] pColums = { MessageBundle.getMessage("angal.inventory.referenceshow.col"), - MessageBundle.getMessage("angal.common.ward.col"), MessageBundle.getMessage("angal.common.date.col"), - MessageBundle.getMessage("angal.inventory.state.col"), - MessageBundle.getMessage("angal.common.user.col") }; + private String[] pColums = { + MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), + MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), + MessageBundle.getMessage("angal.common.date.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.state.col").toUpperCase(), + MessageBundle.getMessage("angal.common.user.col").toUpperCase() + }; private int[] pColumwidth = { 150, 150, 100, 100, 150 }; private JComboBox stateComboBox; private JLabel stateLabel; From fa10582e497b2135b63252703b564c26d78f68da Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 15 Mar 2024 15:47:30 +0100 Subject: [PATCH 10/83] Apply review suggestion --- bundle/language_en.properties | 2 +- .../java/org/isf/medicalinventory/gui/InventoryWardBrowser.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 52342599c7..04d06024b4 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -664,7 +664,7 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. -angal.inventory.managementwardtitle = Manage Ward Inventory +angal.inventory.managementward.title = Manage Ward Inventory angal.inventory.referenceshow.col = Reference angal.inventory.state.col = State angal.inventory.state.label = State diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index c82d936f30..98ec264a09 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -90,7 +90,7 @@ private void initComponents() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setMinimumSize(new Dimension(850, 550)); setLocationRelativeTo(null); // center - setTitle(MessageBundle.getMessage("angal.inventory.managementwardtitle")); + setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); panelHeader = getPanelHeader(); getContentPane().add(panelHeader, BorderLayout.NORTH); From 1f960c00acfe3736d2fa2a0276683c683211a9da Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 19 Mar 2024 15:59:45 +0100 Subject: [PATCH 11/83] Create window to Add new ward Inventory --- bundle/language_en.properties | 13 + .../gui/InventoryWardBrowser.java | 10 +- .../gui/InventoryWardEdit.java | 505 ++++++++++++++++++ 3 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 04d06024b4..a636955e9e 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -664,14 +664,27 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. +angal.inventory.allproduct.radio = All products +angal.inventory.date.label = Inventory's date +angal.inventory.edit.title = Edit an inventory angal.inventory.managementward.title = Manage Ward Inventory +angal.inventory.medical.col = Medical +angal.inventory.productcode.text = Product's code +angal.inventory.realqty.col = Real quantity +angal.inventory.reference.label = Inventory's reference angal.inventory.referenceshow.col = Reference +angal.inventory.searchproduct.txt = Search a product +angal.inventory.selectward.label = Select ward +angal.inventory.specificproduct.radio = Specific product angal.inventory.state.col = State angal.inventory.state.label = State angal.inventory.state.canceled.txt = Canceled angal.inventory.state.inprogress.txt = In progress angal.inventory.state.validate.txt = Validate +angal.inventory.theorticalqty.col = Theoretical quantity angal.inventory.user.col = User +angal.inventory.validate.btn = Validate +angal.inventory.validate.btn.key = V angal.inventory.view.btn = View inventory angal.inventory.view.btn.key = V angal.lab.blood.txt = Blood diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 98ec264a09..c1389cec2c 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -45,12 +45,13 @@ import javax.swing.table.DefaultTableModel; import org.isf.generaldata.MessageBundle; +import org.isf.medicalinventory.gui.InventoryWardEdit.InventoryListener; import org.isf.utils.jobjects.GoodDateChooser; import org.isf.utils.jobjects.InventoryState; import org.isf.utils.jobjects.ModalJFrame; import org.isf.utils.time.TimeTools; -public class InventoryWardBrowser extends ModalJFrame { +public class InventoryWardBrowser extends ModalJFrame implements InventoryListener { private static final long serialVersionUID = 1L; @@ -243,6 +244,13 @@ private JLabel getJLabelFrom() { private JButton getNewButton() { newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); + newButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + } + }); return newButton; } diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java new file mode 100644 index 0000000000..1f717d7c4e --- /dev/null +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -0,0 +1,505 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.medicalinventory.gui; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.EventListener; +import java.util.GregorianCalendar; + +import javax.swing.ButtonGroup; +import javax.swing.DefaultCellEditor; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; +import javax.swing.event.EventListenerList; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.plaf.DimensionUIResource; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; + +import org.isf.generaldata.MessageBundle; +import org.isf.utils.jobjects.GoodDateChooser; +import org.isf.utils.jobjects.ModalJFrame; +import org.isf.utils.jobjects.TextPrompt; +import org.isf.utils.jobjects.TextPrompt.Show; +import org.isf.utils.time.TimeTools; + +public class InventoryWardEdit extends ModalJFrame { + + private static final long serialVersionUID = 1L; + + private static EventListenerList InventoryListeners = new EventListenerList(); + + public interface InventoryListener extends EventListener { + + } + + public static void addInventoryListener(InventoryListener l) { + InventoryListeners.add(InventoryListener.class, l); + } + + private GoodDateChooser jCalendarInventory; + private LocalDateTime dateInventory = TimeTools.getServerDateTime(); + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton saveButton; + private JButton cancelButton; + private JButton printButton; + private JButton validateButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventoryRow; + private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt"), + MessageBundle.getMessage("angal.inventory.medical.col"), + MessageBundle.getMessage("angal.inventory.theorticalqty.col"), + MessageBundle.getMessage("angal.inventory.realqty.col") + }; + private boolean[] columnEditable = { false, false, false, true }; + private JRadioButton specificRadio; + private JRadioButton allRadio; + private JTextField searchTextField; + private JLabel dateInventoryLabel; + private JTextField codeTextField; + private JLabel referenceLabel; + private JTextField referenceTextField; + private JTextField jTetFieldEditor; + private JLabel wardLabel; + private JComboBox wardComboBox; + private JLabel loaderLabel; + + public InventoryWardEdit() { + initComponents(); + cancelButton.setVisible(false); + disabledSomeComponents(); + } + + private void initComponents() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new DimensionUIResource(750, 580)); + setLocationRelativeTo(null); // center + setTitle(MessageBundle.getMessage("angal.inventory.edit.title")); + + panelHeader = getPanelHeader(); + getContentPane().add(panelHeader, BorderLayout.NORTH); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + panelFooter = getPanelFooter(); + getContentPane().add(panelFooter, BorderLayout.SOUTH); + } + + private JPanel getPanelHeader() { + if (panelHeader == null) { + panelHeader = new JPanel(); + panelHeader.setBorder(new EmptyBorder(0, 0, 5, 0)); + GridBagLayout gbl_panelHeader = new GridBagLayout(); + gbl_panelHeader.columnWidths = new int[] { 123, 206, 187, 195, 0, 0 }; + gbl_panelHeader.rowHeights = new int[] { 34, 36, 0, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; + panelHeader.setLayout(gbl_panelHeader); + GridBagConstraints gbc_wardLabel = new GridBagConstraints(); + gbc_wardLabel.anchor = GridBagConstraints.EAST; + gbc_wardLabel.insets = new Insets(0, 0, 5, 5); + gbc_wardLabel.gridx = 0; + gbc_wardLabel.gridy = 0; + panelHeader.add(getWardLabel(), gbc_wardLabel); + GridBagConstraints gbc_wardComboBox = new GridBagConstraints(); + gbc_wardComboBox.insets = new Insets(0, 0, 5, 5); + gbc_wardComboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_wardComboBox.gridx = 1; + gbc_wardComboBox.gridy = 0; + panelHeader.add(getWardComboBox(), gbc_wardComboBox); + GridBagConstraints gbc_loaderLabel = new GridBagConstraints(); + gbc_loaderLabel.insets = new Insets(0, 0, 5, 5); + gbc_loaderLabel.gridx = 2; + gbc_loaderLabel.gridy = 0; + panelHeader.add(getLoaderLabel(), gbc_loaderLabel); + GridBagConstraints gbc_dateInventoryLabel = new GridBagConstraints(); + gbc_dateInventoryLabel.insets = new Insets(0, 0, 5, 5); + gbc_dateInventoryLabel.gridx = 0; + gbc_dateInventoryLabel.gridy = 1; + panelHeader.add(getDateInventoryLabel(), gbc_dateInventoryLabel); + + GridBagConstraints gbc_jCalendarInventory = new GridBagConstraints(); + gbc_jCalendarInventory.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarInventory.insets = new Insets(0, 0, 5, 5); + gbc_jCalendarInventory.gridx = 1; + gbc_jCalendarInventory.gridy = 1; + panelHeader.add(getJCalendarFrom(), gbc_jCalendarInventory); + GridBagConstraints gbc_referenceLabel = new GridBagConstraints(); + gbc_referenceLabel.anchor = GridBagConstraints.EAST; + gbc_referenceLabel.insets = new Insets(0, 0, 5, 5); + gbc_referenceLabel.gridx = 2; + gbc_referenceLabel.gridy = 1; + panelHeader.add(getReferenceLabel(), gbc_referenceLabel); + GridBagConstraints gbc_referenceTextField = new GridBagConstraints(); + gbc_referenceTextField.insets = new Insets(0, 0, 5, 5); + gbc_referenceTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_referenceTextField.gridx = 3; + gbc_referenceTextField.gridy = 1; + panelHeader.add(getReferenceTextField(), gbc_referenceTextField); + GridBagConstraints gbc_specificRadio = new GridBagConstraints(); + gbc_specificRadio.anchor = GridBagConstraints.EAST; + gbc_specificRadio.insets = new Insets(0, 0, 0, 5); + gbc_specificRadio.gridx = 0; + gbc_specificRadio.gridy = 2; + panelHeader.add(getSpecificRadio(), gbc_specificRadio); + GridBagConstraints gbc_codeTextField = new GridBagConstraints(); + gbc_codeTextField.insets = new Insets(0, 0, 0, 5); + gbc_codeTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_codeTextField.gridx = 1; + gbc_codeTextField.gridy = 2; + panelHeader.add(getCodeTextField(), gbc_codeTextField); + GridBagConstraints gbc_allRadio = new GridBagConstraints(); + gbc_allRadio.anchor = GridBagConstraints.EAST; + gbc_allRadio.insets = new Insets(0, 0, 0, 5); + gbc_allRadio.gridx = 2; + gbc_allRadio.gridy = 2; + panelHeader.add(getAllRadio(), gbc_allRadio); + GridBagConstraints gbc_searchTextField = new GridBagConstraints(); + gbc_searchTextField.insets = new Insets(0, 0, 0, 5); + gbc_searchTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_searchTextField.gridx = 3; + gbc_searchTextField.gridy = 2; + panelHeader.add(getSearchTextField(), gbc_searchTextField); + ButtonGroup group = new ButtonGroup(); + group.add(specificRadio); + group.add(allRadio); + + } + return panelHeader; + } + + private JPanel getPanelContent() { + if (panelContent == null) { + panelContent = new JPanel(); + GridBagLayout gbl_panelContent = new GridBagLayout(); + gbl_panelContent.columnWidths = new int[] { 452, 0 }; + gbl_panelContent.rowHeights = new int[] { 402, 0 }; + gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + panelContent.setLayout(gbl_panelContent); + GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); + gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; + gbc_scrollPaneInventory.gridx = 0; + gbc_scrollPaneInventory.gridy = 0; + panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); + } + return panelContent; + } + + private JPanel getPanelFooter() { + if (panelFooter == null) { + panelFooter = new JPanel(); + panelFooter.add(getSaveButton()); + panelFooter.add(getValidateButton()); + panelFooter.add(getCancelButton()); + panelFooter.add(getPrintButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private GoodDateChooser getJCalendarFrom() { + if (jCalendarInventory == null) { + + jCalendarInventory = new GoodDateChooser(dateInventory.toLocalDate()); + jCalendarInventory.addDateChangeListener(dateChangeEvent -> { + LocalDate newDate = dateChangeEvent.getNewDate(); + if (newDate != null) { + dateInventory = newDate.atStartOfDay(); + jCalendarInventory.setDate(newDate); + } + }); + } + return jCalendarInventory; + } + + private JButton getSaveButton() { + saveButton = new JButton(MessageBundle.getMessage("angal.common.save")); + saveButton.setMnemonic(MessageBundle.getMnemonic("angal.common.save.btn.key")); + return saveButton; + } + + private JButton getValidateButton() { + + validateButton = new JButton(MessageBundle.getMessage("angal.inventory.validate.btn")); + validateButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.validate.btn.key")); + return validateButton; + } + + private JButton getCancelButton() { + cancelButton = new JButton(MessageBundle.getMessage("angal.common.cancel.btn")); + cancelButton.setMnemonic(MessageBundle.getMnemonic("angal.common.cancel.btn.key")); + return cancelButton; + } + + private JButton getPrintButton() { + printButton = new JButton(MessageBundle.getMessage("angal.common.print.btn")); + printButton.setMnemonic(MessageBundle.getMnemonic("angal.common.print.btn.key")); + return printButton; + } + + private JButton getCloseButton() { + closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); + closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); + closeButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + + }); + return closeButton; + } + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + scrollPaneInventory.setViewportView(getJTableInventoryRow()); + } + return scrollPaneInventory; + } + + private JTable getJTableInventoryRow() { + if (jTableInventoryRow == null) { + jTableInventoryRow = new JTable(); + jTetFieldEditor = new JTextField(); + jTableInventoryRow.setFillsViewportHeight(true); + jTableInventoryRow.setModel(new InventoryRowModel()); + jTableInventoryRow.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + + if (!e.getValueIsAdjusting()) { + jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), 3); + jTetFieldEditor.selectAll(); + } + + } + }); + DefaultCellEditor cellEditor = new DefaultCellEditor(jTetFieldEditor); + jTableInventoryRow.setDefaultEditor(Double.class, cellEditor); + } + return jTableInventoryRow; + } + + class InventoryRowModel extends DefaultTableModel { + + private static final long serialVersionUID = 1L; + + public Class getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return Double.class; + } else if (c == 3) { + return Double.class; + } + return null; + } + + public int getRowCount() { + return 0; + } + + public String getColumnName(int c) { + return pColums[c]; + } + + public int getColumnCount() { + return pColums.length; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnEditable[columnIndex]; + } + } + + public String formatDateTime(GregorianCalendar time) { + if (time == null) + return ""; + SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy"); //$NON-NLS-1$ + return format.format(time.getTime()); + } + + class DecimalFormatRenderer extends DefaultTableCellRenderer { + /** + * + */ + private static final long serialVersionUID = 1L; + private final DecimalFormat formatter = new DecimalFormat("#,##0.00"); //$NON-NLS-1$ + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + // First format the cell value as required + Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + value = formatter.format((Number) value); + // setHorizontalAlignment(columnAlignment[column]); + if (!columnEditable[column]) { + cell.setBackground(Color.LIGHT_GRAY); + } + + // And pass it on to parent class + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } + } + + private JRadioButton getSpecificRadio() { + if (specificRadio == null) { + specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); + } + return specificRadio; + } + + private JRadioButton getAllRadio() { + if (allRadio == null) { + allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); + } + return allRadio; + } + + private JTextField getSearchTextField() { + if (searchTextField == null) { + searchTextField = new JTextField(); + searchTextField.setColumns(10); + TextPrompt suggestion = new TextPrompt( + MessageBundle + .getMessage("angal.inventory.searchproduct.txt"), + searchTextField, Show.FOCUS_LOST); + { + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + } + searchTextField.setEnabled(false); + } + return searchTextField; + } + + private JLabel getDateInventoryLabel() { + if (dateInventoryLabel == null) { + dateInventoryLabel = new JLabel(MessageBundle.getMessage("angal.inventory.date.label")); + } + return dateInventoryLabel; + } + + private JTextField getCodeTextField() { + if (codeTextField == null) { + codeTextField = new JTextField(); + codeTextField.setEnabled(false); + codeTextField.setColumns(10); + TextPrompt suggestion = new TextPrompt( + MessageBundle + .getMessage("angal.inventory.productcode.text"), + codeTextField, Show.FOCUS_LOST); + { + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + } + } + return codeTextField; + } + + private JLabel getReferenceLabel() { + if (referenceLabel == null) { + referenceLabel = new JLabel(MessageBundle.getMessage("angal.inventory.reference.label")); + } + return referenceLabel; + } + + private JTextField getReferenceTextField() { + if (referenceTextField == null) { + referenceTextField = new JTextField(); + referenceTextField.setColumns(10); + + referenceTextField.setEnabled(false); + } + return referenceTextField; + } + + private JLabel getWardLabel() { + if (wardLabel == null) { + wardLabel = new JLabel(MessageBundle.getMessage("angal.inventory.selectward.label")); + } + return wardLabel; + } + + private JComboBox getWardComboBox() { + wardComboBox = new JComboBox<>(); + return wardComboBox; + } + + private void disabledSomeComponents() { + jCalendarInventory.setEnabled(false); + searchTextField.setEnabled(false); + specificRadio.setEnabled(false); + codeTextField.setEnabled(false); + allRadio.setEnabled(false); + referenceTextField.setEnabled(false); + jTableInventoryRow.setEnabled(false); + saveButton.setEnabled(false); + validateButton.setEnabled(false); + printButton.setEnabled(false); + } + + private JLabel getLoaderLabel() { + if (loaderLabel == null) { + Icon icon = new ImageIcon("rsc/icons/oh_loader.GIF"); + loaderLabel = new JLabel(""); + loaderLabel.setIcon(icon); + loaderLabel.setVisible(false); + } + return loaderLabel; + } +} From 32da113c51e07a8da42affa137aa635f87fa740b Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 20 Mar 2024 08:32:21 +0100 Subject: [PATCH 12/83] Apply review change --- .../isf/medicalinventory/gui/InventoryWardEdit.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 1f717d7c4e..e25b7f64aa 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -363,17 +363,8 @@ public boolean isCellEditable(int rowIndex, int columnIndex) { } } - public String formatDateTime(GregorianCalendar time) { - if (time == null) - return ""; - SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy"); //$NON-NLS-1$ - return format.format(time.getTime()); - } - class DecimalFormatRenderer extends DefaultTableCellRenderer { - /** - * - */ + private static final long serialVersionUID = 1L; private final DecimalFormat formatter = new DecimalFormat("#,##0.00"); //$NON-NLS-1$ From 19fcdc7f877e62beb618d1461be338998b375808 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 20 Mar 2024 09:29:11 +0100 Subject: [PATCH 13/83] Apply review change --- .../java/org/isf/medicalinventory/gui/InventoryWardEdit.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index e25b7f64aa..0c086c3c3f 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -31,11 +31,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; -import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.EventListener; -import java.util.GregorianCalendar; import javax.swing.ButtonGroup; import javax.swing.DefaultCellEditor; From 152ec20c444220b483463a0740eced6fbc67ad7c Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 2 Apr 2024 11:39:41 +0200 Subject: [PATCH 14/83] Add new inventory for all Medicals or for specific Medical --- bundle/language_en.properties | 12 + .../gui/InventoryWardBrowser.java | 28 + .../gui/InventoryWardEdit.java | 608 +++++++++++++++++- .../medicalinventory/gui/MedicalPicker.java | 339 ++++++++++ .../medicalinventory/gui/StockMedModel.java | 103 +++ .../isf/utils/jobjects/InventoryStatus.java | 26 + .../org/isf/utils/jobjects/InventoryType.java | 26 + 7 files changed, 1108 insertions(+), 34 deletions(-) create mode 100644 src/main/java/org/isf/medicalinventory/gui/MedicalPicker.java create mode 100644 src/main/java/org/isf/medicalinventory/gui/StockMedModel.java create mode 100644 src/main/java/org/isf/utils/jobjects/InventoryStatus.java create mode 100644 src/main/java/org/isf/utils/jobjects/InventoryType.java diff --git a/bundle/language_en.properties b/bundle/language_en.properties index a636955e9e..9acca5048c 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -665,14 +665,23 @@ angal.hospital.visitendhour.txt angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. angal.inventory.allproduct.radio = All products +angal.inventory.anotherinventoryonthiswardstillanotheroneisinprogress = Another inventory on this ward still another one is in progress angal.inventory.date.label = Inventory's date angal.inventory.edit.title = Edit an inventory +angal.inventory.error.msg = Error during some products's recording +angal.inventory.lotcode.col = Lot's code angal.inventory.managementward.title = Manage Ward Inventory angal.inventory.medical.col = Medical +angal.inventory.mustenterareference.msg = You must enter a reference. +angal.inventory.noproduct.msg = Product is not found. +angal.inventory.noproductfound.msg = No medical found +angal.inventory.notdateinfuture.msg = A date in the future is not allowed. angal.inventory.productcode.text = Product's code angal.inventory.realqty.col = Real quantity angal.inventory.reference.label = Inventory's reference +angal.inventory.referencealreadyused.msg = Reference is already used. angal.inventory.referenceshow.col = Reference +angal.inventory.savesucces.msg = Inventory saved. angal.inventory.searchproduct.txt = Search a product angal.inventory.selectward.label = Select ward angal.inventory.specificproduct.radio = Specific product @@ -687,6 +696,9 @@ angal.inventory.validate.btn angal.inventory.validate.btn.key = V angal.inventory.view.btn = View inventory angal.inventory.view.btn.key = V +angal.inventoryrow.cannotchangethepriceofproductwithoutlot.msg = You cannot update the unit price of a product without a lot. +angal.inventoryrow.doyoureallywanttodeletethisinventoryrow.msg = Do you really want to delete this inventory row? +angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg = Please select only one inventory row. angal.lab.blood.txt = Blood angal.lab.cfs.txt = CFS angal.lab.datapatient = Patient's Data diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index c1389cec2c..ddb4ef65f5 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -21,6 +21,7 @@ */ package org.isf.medicalinventory.gui; +import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridBagConstraints; @@ -32,6 +33,7 @@ import java.awt.event.WindowEvent; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; import javax.swing.JButton; import javax.swing.JComboBox; @@ -46,6 +48,7 @@ import org.isf.generaldata.MessageBundle; import org.isf.medicalinventory.gui.InventoryWardEdit.InventoryListener; +import org.isf.medicalinventory.model.MedicalInventory; import org.isf.utils.jobjects.GoodDateChooser; import org.isf.utils.jobjects.InventoryState; import org.isf.utils.jobjects.ModalJFrame; @@ -81,6 +84,7 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListen private int[] pColumwidth = { 150, 150, 100, 100, 150 }; private JComboBox stateComboBox; private JLabel stateLabel; + private List inventoryList; public InventoryWardBrowser() { initComponents(); @@ -359,4 +363,28 @@ private JLabel getStateLabel() { } return stateLabel; } + + @Override + public void InventoryInserted(AWTEvent e) { + if (inventoryList != null) { + inventoryList.clear(); + } + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryUpdated(AWTEvent e) { + if (inventoryList != null) { + inventoryList.clear(); + } + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryCancelled(AWTEvent e) { + if (inventoryList != null) { + inventoryList.clear(); + } + jTableInventory.setModel(new InventoryBrowsingModel()); + } } \ No newline at end of file diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 0c086c3c3f..8f2ceebcc9 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -21,6 +21,7 @@ */ package org.isf.medicalinventory.gui; +import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -30,10 +31,19 @@ import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; import java.util.EventListener; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import javax.swing.ButtonGroup; import javax.swing.DefaultCellEditor; @@ -41,27 +51,53 @@ import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.event.EventListenerList; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; import javax.swing.plaf.DimensionUIResource; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; import org.isf.generaldata.MessageBundle; +import org.isf.medicalinventory.manager.MedicalInventoryManager; +import org.isf.medicalinventory.manager.MedicalInventoryRowManager; +import org.isf.medicalinventory.model.MedicalInventory; +import org.isf.medicalinventory.model.MedicalInventoryRow; +import org.isf.medicals.manager.MedicalBrowsingManager; +import org.isf.medicals.model.Medical; +import org.isf.medicalstock.model.Lot; +import org.isf.medicalstockward.manager.MovWardBrowserManager; +import org.isf.medicalstockward.model.MedicalWard; +import org.isf.menu.manager.Context; +import org.isf.menu.manager.UserBrowsingManager; +import org.isf.utils.db.NormalizeString; +import org.isf.utils.exception.OHServiceException; +import org.isf.utils.exception.gui.OHServiceExceptionUtil; import org.isf.utils.jobjects.GoodDateChooser; +import org.isf.utils.jobjects.InventoryStatus; +import org.isf.utils.jobjects.InventoryType; +import org.isf.utils.jobjects.MessageDialog; import org.isf.utils.jobjects.ModalJFrame; import org.isf.utils.jobjects.TextPrompt; import org.isf.utils.jobjects.TextPrompt.Show; import org.isf.utils.time.TimeTools; +import org.isf.ward.manager.WardBrowserManager; +import org.isf.ward.model.Ward; public class InventoryWardEdit extends ModalJFrame { @@ -71,12 +107,27 @@ public class InventoryWardEdit extends ModalJFrame { public interface InventoryListener extends EventListener { + public void InventoryInserted(AWTEvent e); + + public void InventoryUpdated(AWTEvent e); + + public void InventoryCancelled(AWTEvent e); } public static void addInventoryListener(InventoryListener l) { InventoryListeners.add(InventoryListener.class, l); } + private void fireInventoryUpdated() { + AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { + private static final long serialVersionUID = 1L; + }; + + EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class); + for (int i = 0; i < listeners.length; i++) + ((InventoryListener) listeners[i]).InventoryUpdated(event); + } + private GoodDateChooser jCalendarInventory; private LocalDateTime dateInventory = TimeTools.getServerDateTime(); private JPanel panelHeader; @@ -89,30 +140,61 @@ public static void addInventoryListener(InventoryListener l) { private JButton validateButton; private JScrollPane scrollPaneInventory; private JTable jTableInventoryRow; + private List inventoryRowList; + private List inventoryRowSearchList; private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt"), MessageBundle.getMessage("angal.inventory.medical.col"), + MessageBundle.getMessage("angal.inventory.lotcode.col"), MessageBundle.getMessage("angal.inventory.theorticalqty.col"), MessageBundle.getMessage("angal.inventory.realqty.col") }; - private boolean[] columnEditable = { false, false, false, true }; + private int[] pColumwidth = { 100, 250, 125, 100 }; + private boolean[] columnEditable = { false, false, false, false, true }; + private MedicalInventory inventory = null; private JRadioButton specificRadio; private JRadioButton allRadio; private JTextField searchTextField; private JLabel dateInventoryLabel; private JTextField codeTextField; + private String code = null; + private String mode = null; + private String wardId = ""; private JLabel referenceLabel; private JTextField referenceTextField; private JTextField jTetFieldEditor; private JLabel wardLabel; - private JComboBox wardComboBox; + private JComboBox wardComboBox; + private Ward wardSelected; private JLabel loaderLabel; + private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); + private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext() + .getBean(MedicalInventoryManager.class); + private MedicalInventoryRowManager medicalInventoryRowManager = Context.getApplicationContext() + .getBean(MedicalInventoryRowManager.class); + private MedicalBrowsingManager medicalBrowsingManager = Context.getApplicationContext() + .getBean(MedicalBrowsingManager.class); + private MovWardBrowserManager movWardBrowserManager = Context.getApplicationContext() + .getBean(MovWardBrowserManager.class); public InventoryWardEdit() { + mode = "new"; initComponents(); cancelButton.setVisible(false); disabledSomeComponents(); } + public InventoryWardEdit(MedicalInventory inventory, String modee) { + this.inventory = inventory; + mode = modee; + initComponents(); + if (mode.equals("view")) { + validateButton.setVisible(false); + saveButton.setVisible(false); + cancelButton.setVisible(false); + wardComboBox.setEnabled(false); + } + } + private void initComponents() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setMinimumSize(new DimensionUIResource(750, 580)); @@ -245,7 +327,10 @@ private JPanel getPanelFooter() { private GoodDateChooser getJCalendarFrom() { if (jCalendarInventory == null) { - jCalendarInventory = new GoodDateChooser(dateInventory.toLocalDate()); + jCalendarInventory = new GoodDateChooser(LocalDate.now()); + if (inventory != null) { + jCalendarInventory.setDate(inventory.getInventoryDate().toLocalDate()); + } jCalendarInventory.addDateChangeListener(dateChangeEvent -> { LocalDate newDate = dateChangeEvent.getNewDate(); if (newDate != null) { @@ -260,6 +345,72 @@ private GoodDateChooser getJCalendarFrom() { private JButton getSaveButton() { saveButton = new JButton(MessageBundle.getMessage("angal.common.save")); saveButton.setMnemonic(MessageBundle.getMnemonic("angal.common.save.btn.key")); + saveButton.addActionListener(actionEvent -> { + String State = InventoryStatus.draft.toString(); + String user = UserBrowsingManager.getCurrentUser(); + int checkResults = 0; + if (inventoryRowSearchList == null || inventoryRowSearchList.size() < 1) { + MessageDialog.error(null, "angal.inventory.noproduct.msg"); + return; + } + LocalDateTime now = LocalDateTime.now(); + if (dateInventory.isAfter(now)) { + MessageDialog.error(null, "angal.inventory.notdateinfuture.msg"); + return; + } + + if ((inventory == null) && (mode.equals("new"))) { + String reference = referenceTextField.getText().trim(); + if (reference.equals("")) { + MessageDialog.error(null, "angal.inventory.mustenterareference.msg"); + return; + } + if (medicalInventoryManager.referenceExists(reference)) { + MessageDialog.error(null, "angal.inventory.referencealreadyused.msg"); + return; + } + inventory = new MedicalInventory(); + inventory.setInventoryReference(reference); + inventory.setInventoryDate(dateInventory); + inventory.setStatus(State); + inventory.setUser(user); + inventory.setInventoryType(InventoryType.main.toString()); + MedicalInventory meInventory; + try { + meInventory = medicalInventoryManager.newMedicalInventory(inventory); + if (meInventory != null) { + MedicalInventoryRow currentInventoryRow; + for (Iterator iterator = inventoryRowSearchList.iterator(); iterator + .hasNext();) { + MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); + medicalInventoryRow.setInventory(meInventory); + Lot lot = medicalInventoryRow.getLot(); + if (lot != null && lot.getCode().equals("")) { + medicalInventoryRow.setLot(null); + } + currentInventoryRow = medicalInventoryRowManager + .newMedicalInventoryRow(medicalInventoryRow); + if (currentInventoryRow == null) { + checkResults++; + } + } + if (checkResults == 0) { + // enable validation + mode = "update"; + MessageDialog.info(this, "angal.inventory.savesucces.msg"); + fireInventoryUpdated(); + closeButton.doClick(); + } else { + MessageDialog.error(null, "angal.inventory.error.msg"); + } + } else { + MessageDialog.error(null, "angal.inventory.error.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + }); return saveButton; } @@ -273,6 +424,28 @@ private JButton getValidateButton() { private JButton getCancelButton() { cancelButton = new JButton(MessageBundle.getMessage("angal.common.cancel.btn")); cancelButton.setMnemonic(MessageBundle.getMnemonic("angal.common.cancel.btn.key")); + cancelButton.addActionListener(actionEvent -> { + if (jTableInventoryRow.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); + return; + } + int selectedRow = jTableInventoryRow.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); + return; + } + MedicalInventoryRow selectedInventory = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRow, + -1); + int delete = MessageDialog.yesNo(null, "angal.inventoryrow.doyoureallywanttodeletethisinventoryrow.msg"); + if (delete == JOptionPane.YES_OPTION) { + if (selectedInventory.getInventory() == null) { + inventoryRowSearchList.remove(selectedRow); + } + } else { + return; + } + jTableInventoryRow.updateUI(); + }); return cancelButton; } @@ -312,16 +485,46 @@ private JTable getJTableInventoryRow() { @Override public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), 3); + jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), 5); jTetFieldEditor.selectAll(); } } }); + jTableInventoryRow.getModel().addTableModelListener(new TableModelListener() { + + @Override + public void tableChanged(TableModelEvent e) { + + if (e.getType() == TableModelEvent.UPDATE) { + int row = e.getFirstRow(); + int column = e.getColumn(); + TableModel model = (TableModel) e.getSource(); + Object data = model.getValueAt(row, column); + + if (column == 2) { + Object data2 = model.getValueAt(row, 3); + if (!data.toString().equals("") && data2.toString().equals("")) { + jTableInventoryRow.setSurrendersFocusOnKeystroke(true); + jTableInventoryRow.getEditorComponent().requestFocus(); + return; + } + } + + if (column == 3) { + Object data2 = model.getValueAt(row, 2); + if (!data.toString().equals("") && data2.toString().equals("")) { + jTableInventoryRow.setSurrendersFocusOnKeystroke(true); + jTableInventoryRow.getEditorComponent().requestFocus(); + return; + } + } + } + } + }); DefaultCellEditor cellEditor = new DefaultCellEditor(jTetFieldEditor); - jTableInventoryRow.setDefaultEditor(Double.class, cellEditor); + jTableInventoryRow.setDefaultEditor(Integer.class, cellEditor); } return jTableInventoryRow; } @@ -330,21 +533,45 @@ class InventoryRowModel extends DefaultTableModel { private static final long serialVersionUID = 1L; + public InventoryRowModel() { + if (allRadio.isSelected()) { + try { + inventoryRowList = loadNewInventoryTable(null); + } catch (OHServiceException e) { + inventoryRowList = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + } else if (specificRadio.isSelected() && code != null && !code.trim().equals("")) { + try { + inventoryRowList = loadNewInventoryTable(code); + } catch (OHServiceException e) { + inventoryRowList = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + } + + inventoryRowSearchList = inventoryRowList; + } + public Class getColumnClass(int c) { if (c == 0) { return String.class; } else if (c == 1) { return String.class; } else if (c == 2) { - return Double.class; + return String.class; } else if (c == 3) { return Double.class; + } else if (c == 4) { + return Double.class; } return null; } public int getRowCount() { - return 0; + if (inventoryRowSearchList == null) + return 0; + return inventoryRowSearchList.size(); } public String getColumnName(int c) { @@ -355,12 +582,72 @@ public int getColumnCount() { return pColums.length; } + public Object getValueAt(int r, int c) { + MedicalInventoryRow medInvtRow = inventoryRowSearchList.get(r); + + if (c == -1) { + return medInvtRow; + } else if (c == 0) { + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getProdCode(); + } else if (c == 1) { + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription();// date + } else if (c == 2) { + return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode();// date + } else if (c == 3) { + Double dblVal = medInvtRow.getTheoreticQty(); + return dblVal; + } else if (c == 4) { + Double dblValue = medInvtRow.getRealQty(); + return dblValue; + } + return null; + } + + @Override + public void setValueAt(Object value, int r, int c) { + if (r < inventoryRowSearchList.size()) {/// + MedicalInventoryRow invRow = inventoryRowSearchList.get(r); + if (c == 4) { + Double intValue = 0.0; + try { + intValue = Double.parseDouble(value.toString()); + } catch (NumberFormatException e) { + intValue = 0.0; + } + invRow.setRealqty(intValue); + inventoryRowSearchList.set(r, invRow); + validateButton.setEnabled(false); + } + } + } + @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return columnEditable[columnIndex]; } } + private List loadNewInventoryTable(String code) throws OHServiceException { + List inventoryRowsList = new ArrayList<>(); + List medicalWardList = new ArrayList<>(); + Medical medical = null; + if (code != null) { + medical = medicalBrowsingManager.getMedicalByMedicalCode(code); + if (medical != null) { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode()); + } else { + MessageDialog.error(null, MessageBundle.getMessage("angal.inventory.noproductfound.msg")); + } + } else { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); + } + medicalWardList.stream().forEach(medicalWard -> { + inventoryRowsList.add(new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, + medicalWard.getMedical(), medicalWard.getLot())); + }); + return inventoryRowsList; + } + class DecimalFormatRenderer extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; @@ -384,6 +671,28 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole private JRadioButton getSpecificRadio() { if (specificRadio == null) { specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); + if (inventory != null) { + specificRadio.setSelected(false); + } else { + specificRadio.setSelected(true); + } + specificRadio.addActionListener(actionEvent -> { + + if (specificRadio.isSelected()) { + codeTextField.setEnabled(true); + searchTextField.setEnabled(false); + searchTextField.setText(""); + codeTextField.setText(""); + if (inventoryRowList != null) { + inventoryRowList.clear(); + } + if (inventoryRowSearchList != null) { + inventoryRowSearchList.clear(); + } + jTableInventoryRow.updateUI(); + ajustWidth(); + } + }); } return specificRadio; } @@ -391,6 +700,29 @@ private JRadioButton getSpecificRadio() { private JRadioButton getAllRadio() { if (allRadio == null) { allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); + if (inventory != null) { + allRadio.setSelected(true); + } else { + allRadio.setSelected(false); + } + allRadio.addActionListener(actionEvent -> { + if (allRadio.isSelected()) { + codeTextField.setEnabled(false); + searchTextField.setText(""); + codeTextField.setText(""); + searchTextField.setEnabled(true); + if (inventoryRowList != null) { + inventoryRowList.clear(); + } + if (inventoryRowSearchList != null) { + inventoryRowSearchList.clear(); + } + jTableInventoryRow.setModel(new InventoryRowModel()); + jTableInventoryRow.updateUI(); + code = null; + ajustWidth(); + } + }); } return allRadio; } @@ -398,18 +730,40 @@ private JRadioButton getAllRadio() { private JTextField getSearchTextField() { if (searchTextField == null) { searchTextField = new JTextField(); - searchTextField.setColumns(10); - TextPrompt suggestion = new TextPrompt( - MessageBundle - .getMessage("angal.inventory.searchproduct.txt"), - searchTextField, Show.FOCUS_LOST); - { - suggestion.setForeground(Color.GRAY); - suggestion.setHorizontalAlignment(JLabel.CENTER); - suggestion.changeAlpha(0.5f); - suggestion.changeStyle(Font.BOLD + Font.ITALIC); - } + searchTextField.setColumns(16); + TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.search.txt"), searchTextField, + Show.FOCUS_LOST); + suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + searchTextField.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void insertUpdate(DocumentEvent e) { + filterInventoryRow(); + ajustWidth(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + filterInventoryRow(); + ajustWidth(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + filterInventoryRow(); + ajustWidth(); + } + }); searchTextField.setEnabled(false); + if (inventory != null) { + searchTextField.setEnabled(true); + } else { + searchTextField.setEnabled(false); + } } return searchTextField; } @@ -424,22 +778,154 @@ private JLabel getDateInventoryLabel() { private JTextField getCodeTextField() { if (codeTextField == null) { codeTextField = new JTextField(); - codeTextField.setEnabled(false); - codeTextField.setColumns(10); - TextPrompt suggestion = new TextPrompt( - MessageBundle - .getMessage("angal.inventory.productcode.text"), - codeTextField, Show.FOCUS_LOST); - { - suggestion.setForeground(Color.GRAY); - suggestion.setHorizontalAlignment(JLabel.CENTER); - suggestion.changeAlpha(0.5f); - suggestion.changeStyle(Font.BOLD + Font.ITALIC); + if (inventory != null) { + codeTextField.setEnabled(false); + } else { + codeTextField.setEnabled(true); } + codeTextField.setColumns(10); + TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.code.txt"), codeTextField, + Show.FOCUS_LOST); + suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + codeTextField.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + code = codeTextField.getText().trim(); + code = code.toLowerCase(); + try { + addInventoryRow(code); + } catch (OHServiceException e1) { + OHServiceExceptionUtil.showMessages(e1); + } + codeTextField.setText(""); + ajustWidth(); + } + } + }); } return codeTextField; } + private void filterInventoryRow() { + String s = searchTextField.getText(); + s.trim(); + inventoryRowSearchList = new ArrayList(); + for (MedicalInventoryRow invRow : inventoryRowList) { + if (!s.equals("")) { + String name = invRow.getSearchString(); + if (name.contains(s.toLowerCase())) + inventoryRowSearchList.add(invRow); + } else { + inventoryRowSearchList.add(invRow); + } + } + jTableInventoryRow.updateUI(); + searchTextField.requestFocus(); + } + + private void addInventoryRow(String code) throws OHServiceException { + List inventoryRowsList = new ArrayList(); + List medicalWardList = new ArrayList(); + Medical medical = null; + if (code != null) { + medical = medicalBrowsingManager.getMedicalByMedicalCode(code); + if (medical != null) { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode()); + } else { + medical = chooseMedical(code); + if (medical != null) { + boolean found = false; + if (inventoryRowSearchList != null) { + for (MedicalInventoryRow row : inventoryRowSearchList) { + if (row.getMedical().getCode().equals(medical.getCode())) { + found = true; + } + } + } + if (!found) { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode()); + } + } + } + } else { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); + } + if (mode.equals("new")) { + inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), + medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); + } else if (mode.equals("update")) { + if (medical != null) { + String medicalCode = medical.getProdCode(); + inventoryRowsList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()) + .stream() + .filter(medRow -> medRow.getMedical().getProdCode().equals(medicalCode)).toList(); + } + } + if (inventoryRowSearchList == null) { + inventoryRowSearchList = new ArrayList<>(); + } + for (MedicalInventoryRow inventoryRow : inventoryRowsList) { + inventoryRowSearchList.add(inventoryRow); + } + jTableInventoryRow.updateUI(); + } + + private Medical chooseMedical(String text) throws OHServiceException { + Map medicalMap; + List medicals = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false).stream() + .map(medicalWard -> medicalWard.getMedical()).toList(); + if (mode.equals("update")) { + medicals.clear(); + List inventoryRowListTemp = medicalInventoryRowManager + .getMedicalInventoryRowByInventoryId(inventory.getId()); + for (MedicalInventoryRow medicalInventoryRow : inventoryRowListTemp) { + medicals.add(medicalInventoryRow.getMedical()); + } + } + medicalMap = new HashMap(); + for (Medical med : medicals) { + String key = med.getProdCode().toLowerCase(); + key = med.getCode().toString().toLowerCase(); + medicalMap.put(key, med); + } + ArrayList medList = new ArrayList(); + for (Medical aMed : medicalMap.values()) { + if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { + medList.add(aMed); + } + } + Collections.sort(medList); + Medical med = null; + if (!medList.isEmpty()) { + MedicalPicker framas = new MedicalPicker(new StockMedModel(medList), medList); + framas.setSize(300, 400); + JDialog dialog = new JDialog(); + dialog.setLocationRelativeTo(null); + dialog.setSize(600, 350); + dialog.setLocationRelativeTo(null); + dialog.setModal(true); + dialog.setTitle(MessageBundle.getMessage("angal.medicalstock.multiplecharging.selectmedical.title")); + framas.setParentFrame(dialog); + dialog.setContentPane(framas); + dialog.setVisible(true); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + med = framas.getSelectedMedical(); + return med; + } + return null; + } + + private void ajustWidth() { + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); + } + } + private JLabel getReferenceLabel() { if (referenceLabel == null) { referenceLabel = new JLabel(MessageBundle.getMessage("angal.inventory.reference.label")); @@ -451,8 +937,10 @@ private JTextField getReferenceTextField() { if (referenceTextField == null) { referenceTextField = new JTextField(); referenceTextField.setColumns(10); - - referenceTextField.setEnabled(false); + if (inventory != null && !mode.equals("new")) { + referenceTextField.setText(inventory.getInventoryReference()); + referenceTextField.setEnabled(false); + } } return referenceTextField; } @@ -464,8 +952,48 @@ private JLabel getWardLabel() { return wardLabel; } - private JComboBox getWardComboBox() { - wardComboBox = new JComboBox<>(); + private JComboBox getWardComboBox() { + if (wardComboBox == null) { + wardComboBox = new JComboBox(); + List wardList; + try { + wardList = wardBrowserManager.getWards(); + } catch (OHServiceException e) { + wardList = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + for (Ward elem : wardList) { + wardComboBox.addItem(elem); + } + wardComboBox.setSelectedIndex(-1); + + wardComboBox.addItemListener(itemEvent -> { + + if (itemEvent.getStateChange() == ItemEvent.SELECTED) { + Object item = itemEvent.getItem(); + if (item instanceof Ward) { + wardSelected = (Ward) item; + wardId = wardSelected.getCode(); + List medicalWardInventory; + try { + medicalWardInventory = medicalInventoryManager + .getMedicalInventoryByStatusAndWard(InventoryType.ward.toString(), wardId); + } catch (OHServiceException e) { + medicalWardInventory = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + + if (medicalWardInventory != null) { + activedSomeComponents(); + } else { + MessageDialog.error(this, + "angal.inventory.anotherinventoryonthiswardstillanotheroneisinprogress"); + return; + } + } + } + }); + } return wardComboBox; } @@ -482,6 +1010,18 @@ private void disabledSomeComponents() { printButton.setEnabled(false); } + private void activedSomeComponents() { + jCalendarInventory.setEnabled(true); + searchTextField.setEnabled(true); + specificRadio.setEnabled(true); + codeTextField.setEnabled(true); + allRadio.setEnabled(true); + referenceTextField.setEnabled(true); + jTableInventoryRow.setEnabled(true); + wardComboBox.setEnabled(false); + saveButton.setEnabled(true); + } + private JLabel getLoaderLabel() { if (loaderLabel == null) { Icon icon = new ImageIcon("rsc/icons/oh_loader.GIF"); diff --git a/src/main/java/org/isf/medicalinventory/gui/MedicalPicker.java b/src/main/java/org/isf/medicalinventory/gui/MedicalPicker.java new file mode 100644 index 0000000000..271dbb4525 --- /dev/null +++ b/src/main/java/org/isf/medicalinventory/gui/MedicalPicker.java @@ -0,0 +1,339 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.medicalinventory.gui; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; + +import org.isf.generaldata.MessageBundle; +import org.isf.medicals.model.Medical; +import org.isf.utils.jobjects.OhDefaultCellRenderer; + +public class MedicalPicker extends JPanel { + + OhDefaultCellRenderer cellRenderer = new OhDefaultCellRenderer(); + private static final long serialVersionUID = 1L; + private Collection medicalMapValues = new ArrayList(); + private String searchCode; + private JButton jButtonSelect; + private JButton jButtonQuit; + private JLabel jLabelImage; + private JPanel jPanel1; + private JPanel jPanel2; + private JPanel jPanel3; + private JScrollPane jScrollPane1; + private JTable jTableData; + private JTextField jTextFieldFind; + private int selectedRow = -1; + private JDialog parentFrame; + + private int getSelectedRow() { + return selectedRow; + } + + public Medical getSelectedMedical() { + StockMedModel model = (StockMedModel) jTableData.getModel(); + return model.getMedicalAtRow(this.getSelectedRow()); + } + + private void setSelectedRow(int selectedRow) { + this.selectedRow = selectedRow; + } + + public JDialog getParentFrame() { + return parentFrame; + } + + public void setParentFrame(JDialog parentFrame) { + this.parentFrame = parentFrame; + } + + public MedicalPicker(StockMedModel model, List medicals) { + initComponents(model); + this.medicalMapValues = medicals; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + private void initComponents(TableModel model) { + + jPanel3 = new JPanel(); + jPanel1 = new JPanel(); + + jPanel3.setBackground(new Color(240, 240, 240)); + + jPanel1.setBackground(new Color(240, 240, 240)); + + setLayout(new BorderLayout(10, 10)); + add(jPanel1, BorderLayout.CENTER); + GridBagLayout gbl_jPanel1 = new GridBagLayout(); + gbl_jPanel1.columnWidths = new int[] { 575, 0 }; + gbl_jPanel1.rowHeights = new int[] { 268, 0 }; + gbl_jPanel1.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_jPanel1.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + jPanel1.setLayout(gbl_jPanel1); + jScrollPane1 = new JScrollPane(); + jTableData = new JTable(); + + jTableData.setDefaultRenderer(Object.class, cellRenderer); + jTableData.setDefaultRenderer(Double.class, cellRenderer); + jTableData.addMouseMotionListener(new MouseMotionListener() { + @Override + public void mouseMoved(MouseEvent e) { + JTable aTable = (JTable) e.getSource(); + int itsRow = aTable.rowAtPoint(e.getPoint()); + if (itsRow >= 0) { + cellRenderer.setHoveredRow(itsRow); + } else { + cellRenderer.setHoveredRow(-1); + } + aTable.repaint(); + } + + @Override + public void mouseDragged(MouseEvent e) { + } + }); + jTableData.addMouseListener(new MouseAdapter() { + @Override + public void mouseExited(MouseEvent e) { + cellRenderer.setHoveredRow(-1); + } + }); + + jTableData.setModel(model); + jTableData.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + jTableData.setShowVerticalLines(false); + jTableData.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent evt) { + jTableDataMouseClicked(evt); + } + + public void mousePressed(MouseEvent evt) { + if (evt.getClickCount() == 2) { + validateSelection(); + } + } + }); + + jTableData.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + validateSelection(); + } + super.keyPressed(e); + } + }); + + jScrollPane1.setViewportView(jTableData); + GridBagConstraints gbc_jScrollPane1 = new GridBagConstraints(); + gbc_jScrollPane1.insets = new Insets(0, 15, 0, 15); + gbc_jScrollPane1.fill = GridBagConstraints.BOTH; + gbc_jScrollPane1.gridx = 0; + gbc_jScrollPane1.gridy = 0; + jPanel1.add(jScrollPane1, gbc_jScrollPane1); + add(jPanel3, BorderLayout.NORTH); + GridBagLayout gbl_jPanel3 = new GridBagLayout(); + gbl_jPanel3.columnWidths = new int[] { 90, 237, 0 }; + gbl_jPanel3.rowHeights = new int[] { 50, 0 }; + gbl_jPanel3.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; + gbl_jPanel3.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; + jPanel3.setLayout(gbl_jPanel3); + + jLabelImage = new JLabel(); + + jLabelImage.setText(MessageBundle.getMessage("angal.common.search.txt")); + GridBagConstraints gbc_jLabelImage = new GridBagConstraints(); + gbc_jLabelImage.anchor = GridBagConstraints.WEST; + gbc_jLabelImage.insets = new Insets(0, 15, 0, 5); + gbc_jLabelImage.gridx = 0; + gbc_jLabelImage.gridy = 0; + jPanel3.add(jLabelImage, gbc_jLabelImage); + jTextFieldFind = new JTextField(); + jTextFieldFind.setText(searchCode); + GridBagConstraints gbc_jTextFieldFind = new GridBagConstraints(); + gbc_jTextFieldFind.insets = new Insets(0, 0, 0, 15); + gbc_jTextFieldFind.fill = GridBagConstraints.HORIZONTAL; + gbc_jTextFieldFind.gridx = 1; + gbc_jTextFieldFind.gridy = 0; + jPanel3.add(jTextFieldFind, gbc_jTextFieldFind); + jTextFieldFind.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void insertUpdate(DocumentEvent e) { + String text = jTextFieldFind.getText(); + ArrayList medList = new ArrayList(); + for (Medical aMed : medicalMapValues) { + medList.add(aMed); + } + StockMedModel model = new StockMedModel(medList); + jTableData.setModel(model); + TableColumn column; + for (int i = 0; i < 2; i++) { + column = jTableData.getColumnModel().getColumn(i); + if (i == 1) { + column.setPreferredWidth(375); + } else { + column.setPreferredWidth(100); + } + } + model.filter(text); + if (jTableData.getRowCount() > 0) { + jTableData.setRowSelectionInterval(0, 0); + } + jTableData.updateUI(); + + } + + @Override + public void removeUpdate(DocumentEvent e) { + String text = jTextFieldFind.getText(); + StockMedModel model = (StockMedModel) jTableData.getModel(); + model.filter(text); + if (jTableData.getRowCount() > 0) { + jTableData.setRowSelectionInterval(0, 0); + } + jTableData.updateUI(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + throw new UnsupportedOperationException("Not supported yet."); + } + + }); + + jTextFieldFind.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + validateSelection(); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + int selectedRow = jTableData.getSelectedRow(); + if (jTableData.getRowCount() > 0 && selectedRow >= 0) { + selectedRow++; + if (jTableData.getRowCount() > selectedRow) { + jTableData.setRowSelectionInterval(selectedRow, selectedRow); + jTableData.scrollRectToVisible(new Rectangle(jTableData.getCellRect(selectedRow, 0, true))); + } + } + } else if (e.getKeyCode() == KeyEvent.VK_UP) { + int selectedRow = jTableData.getSelectedRow(); + if (jTableData.getRowCount() > 0 && selectedRow > 0) { + selectedRow--; + jTableData.setRowSelectionInterval(selectedRow, selectedRow); + jTableData.scrollRectToVisible(new Rectangle(jTableData.getCellRect(selectedRow, 0, true))); + } + } + jTableData.updateUI(); + super.keyPressed(e); + } + }); + + jPanel2 = new JPanel(); + jButtonSelect = new JButton(); + jButtonQuit = new JButton(); + jPanel2.setBackground(new Color(240, 240, 240)); + jButtonSelect.setText(MessageBundle.getMessage("angal.common.select.btn")); + jButtonSelect.setMnemonic(MessageBundle.getMnemonic("angal.common.select.btn.key")); + jButtonSelect.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent evt) { + jButtonSelectMouseClicked(evt); + } + }); + jButtonSelect.addActionListener(actionEvent -> { + jButtonSelectActionPerformed(actionEvent); + }); + jButtonQuit.setText(MessageBundle.getMessage("angal.common.cancel.btn")); + jButtonQuit.setMnemonic(MessageBundle.getMnemonic("angal.common.cancel.btn.key")); + jButtonQuit.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent evt) { + jButtonQuitMouseClicked(evt); + } + }); + add(jPanel2, BorderLayout.SOUTH); + jPanel2.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5)); + jPanel2.add(jButtonSelect); + jPanel2.add(jButtonQuit); + + if (jTableData.getRowCount() > 0) { + jTableData.setRowSelectionInterval(0, 0); + } + + } + + private void jTableDataMouseClicked(MouseEvent evt) { + + } + + private void validateSelection() { + this.setSelectedRow(this.jTableData.getSelectedRow()); + this.setVisible(false); + this.getParentFrame().dispose(); + } + + private void jButtonSelectActionPerformed(ActionEvent evt) { + + } + + private void jButtonSelectMouseClicked(MouseEvent evt) { + this.setSelectedRow(this.jTableData.getSelectedRow()); + this.setVisible(false); + this.getParentFrame().dispose(); + } + + private void jButtonQuitMouseClicked(MouseEvent evt) { + this.setVisible(false); + this.getParentFrame().dispose(); + } +} \ No newline at end of file diff --git a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java new file mode 100644 index 0000000000..51a474564c --- /dev/null +++ b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java @@ -0,0 +1,103 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.medicalinventory.gui; + +import java.util.ArrayList; +import java.util.Iterator; + +import javax.swing.table.DefaultTableModel; + +import org.isf.generaldata.MessageBundle; +import org.isf.medicals.model.Medical; +import org.isf.utils.db.NormalizeString; + +public class StockMedModel extends DefaultTableModel { + + private static final long serialVersionUID = 1L; + private ArrayList medList; + private ArrayList initList = new ArrayList(); + + public StockMedModel(ArrayList meds) { + medList = meds; + initList.addAll(medList); + } + + public int getRowCount() { + if (medList == null) { + return 0; + } + return medList.size(); + } + + public String getColumnName(int c) { + if (c == 0) { + return MessageBundle.getMessage("angal.common.code.txt").toUpperCase(); + } + if (c == 1) { + return MessageBundle.getMessage("angal.common.description.txt").toUpperCase(); + } + return ""; + } + + public int getColumnCount() { + return 2; + } + + public Object getValueAt(int r, int c) { + Medical med = medList.get(r); + if (c == -1) { + return med; + } else if (c == 0) { + return med.getProdCode(); + } else if (c == 1) { + return med.getDescription(); + } + return null; + } + + public void filter(String searchValue) { + medList.clear(); + for (Iterator iterator = initList.iterator(); iterator.hasNext();) { + Medical med = (Medical) iterator.next(); + if (med.getProdCode().trim().equalsIgnoreCase(searchValue.trim())) { + medList.add(med); + } else if (NormalizeString.normalizeContains( + med.getProdCode().toLowerCase().trim() + med.getDescription().toLowerCase(), + searchValue.toLowerCase().trim())) { + medList.add(med); + } + } + } + + public Medical getMedicalAtRow(int row) { + if (medList.size() > row && row >= 0) { + return medList.get(row); + } + return null; + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/org/isf/utils/jobjects/InventoryStatus.java b/src/main/java/org/isf/utils/jobjects/InventoryStatus.java new file mode 100644 index 0000000000..1a81bf0e80 --- /dev/null +++ b/src/main/java/org/isf/utils/jobjects/InventoryStatus.java @@ -0,0 +1,26 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.jobjects; + +public enum InventoryStatus { + draft, validated, canceled; +} \ No newline at end of file diff --git a/src/main/java/org/isf/utils/jobjects/InventoryType.java b/src/main/java/org/isf/utils/jobjects/InventoryType.java new file mode 100644 index 0000000000..1244e4d5b7 --- /dev/null +++ b/src/main/java/org/isf/utils/jobjects/InventoryType.java @@ -0,0 +1,26 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.isf.utils.jobjects; + +public enum InventoryType { + main, ward +} \ No newline at end of file From 3ae95a26cf33bce9cdc9ddff82a68319028ec6aa Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 2 Apr 2024 17:05:11 +0200 Subject: [PATCH 15/83] apply review suggestion --- bundle/language_en.properties | 6 +- .../gui/InventoryWardEdit.java | 93 +++++++++++++++---- 2 files changed, 81 insertions(+), 18 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 9acca5048c..fe786afd24 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -665,7 +665,7 @@ angal.hospital.visitendhour.txt angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. angal.inventory.allproduct.radio = All products -angal.inventory.anotherinventoryonthiswardstillanotheroneisinprogress = Another inventory on this ward still another one is in progress +angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward = cannot create an other inventory with other in progress in this ward. angal.inventory.date.label = Inventory's date angal.inventory.edit.title = Edit an inventory angal.inventory.error.msg = Error during some products's recording @@ -690,7 +690,9 @@ angal.inventory.state.label angal.inventory.state.canceled.txt = Canceled angal.inventory.state.inprogress.txt = In progress angal.inventory.state.validate.txt = Validate -angal.inventory.theorticalqty.col = Theoretical quantity +angal.inventory.theorticalqty.col = Theoretical +angal.inventory.totalprice.col = Total price quantity +angal.inventory.unitprice.col = Unit price angal.inventory.user.col = User angal.inventory.validate.btn = Validate angal.inventory.validate.btn.key = V diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 8f2ceebcc9..021d3bb42b 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -21,6 +21,8 @@ */ package org.isf.medicalinventory.gui; +import static org.isf.utils.Constants.DATE_TIME_FORMATTER; + import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Color; @@ -34,6 +36,7 @@ import java.awt.event.ItemEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -80,6 +83,7 @@ import org.isf.medicalinventory.model.MedicalInventoryRow; import org.isf.medicals.manager.MedicalBrowsingManager; import org.isf.medicals.model.Medical; +import org.isf.medicalstock.manager.MovStockInsertingManager; import org.isf.medicalstock.model.Lot; import org.isf.medicalstockward.manager.MovWardBrowserManager; import org.isf.medicalstockward.model.MedicalWard; @@ -145,11 +149,14 @@ private void fireInventoryUpdated() { private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt"), MessageBundle.getMessage("angal.inventory.medical.col"), MessageBundle.getMessage("angal.inventory.lotcode.col"), + MessageBundle.getMessage("angal.medicalstock.duedate.col"), MessageBundle.getMessage("angal.inventory.theorticalqty.col"), - MessageBundle.getMessage("angal.inventory.realqty.col") + MessageBundle.getMessage("angal.inventory.realqty.col"), + MessageBundle.getMessage("angal.inventory.unitprice.col"), + MessageBundle.getMessage("angal.inventory.totalprice.col") }; - private int[] pColumwidth = { 100, 250, 125, 100 }; - private boolean[] columnEditable = { false, false, false, false, true }; + private int[] pColumwidth = { 100, 200, 100, 100, 100, 80, 80, 80 }; + private boolean[] columnEditable = { false, false, false, false, false, true, true, false }; private MedicalInventory inventory = null; private JRadioButton specificRadio; private JRadioButton allRadio; @@ -175,6 +182,8 @@ private void fireInventoryUpdated() { .getBean(MedicalBrowsingManager.class); private MovWardBrowserManager movWardBrowserManager = Context.getApplicationContext() .getBean(MovWardBrowserManager.class); + private MovStockInsertingManager movStockInsertingManager = Context.getApplicationContext() + .getBean(MovStockInsertingManager.class); public InventoryWardEdit() { mode = "new"; @@ -197,7 +206,7 @@ public InventoryWardEdit(MedicalInventory inventory, String modee) { private void initComponents() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setMinimumSize(new DimensionUIResource(750, 580)); + setMinimumSize(new DimensionUIResource(950, 580)); setLocationRelativeTo(null); // center setTitle(MessageBundle.getMessage("angal.inventory.edit.title")); @@ -214,7 +223,7 @@ private void initComponents() { private JPanel getPanelHeader() { if (panelHeader == null) { panelHeader = new JPanel(); - panelHeader.setBorder(new EmptyBorder(0, 0, 5, 0)); + panelHeader.setBorder(new EmptyBorder(5, 0, 5, 0)); GridBagLayout gbl_panelHeader = new GridBagLayout(); gbl_panelHeader.columnWidths = new int[] { 123, 206, 187, 195, 0, 0 }; gbl_panelHeader.rowHeights = new int[] { 34, 36, 0, 0 }; @@ -543,7 +552,7 @@ public InventoryRowModel() { } } else if (specificRadio.isSelected() && code != null && !code.trim().equals("")) { try { - inventoryRowList = loadNewInventoryTable(code); + inventoryRowList = loadNewInventoryTable(code.trim()); } catch (OHServiceException e) { inventoryRowList = new ArrayList<>(); OHServiceExceptionUtil.showMessages(e); @@ -561,9 +570,15 @@ public Class getColumnClass(int c) { } else if (c == 2) { return String.class; } else if (c == 3) { - return Double.class; + return String.class; } else if (c == 4) { return Double.class; + } else if (c == 5) { + return Double.class; + } else if (c == 6) { + return Double.class; + } else if (c == 7) { + return Double.class; } return null; } @@ -590,33 +605,79 @@ public Object getValueAt(int r, int c) { } else if (c == 0) { return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getProdCode(); } else if (c == 1) { - return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription();// date + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription(); } else if (c == 2) { - return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode();// date + return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode(); } else if (c == 3) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getDueDate() != null) { + return medInvtRow.getLot().getDueDate().format(DATE_TIME_FORMATTER); + } + } + return ""; + } else if (c == 4) { Double dblVal = medInvtRow.getTheoreticQty(); return dblVal; - } else if (c == 4) { + } else if (c == 5) { Double dblValue = medInvtRow.getRealQty(); return dblValue; + } else if (c == 6) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getCost() != null) { + return medInvtRow.getLot().getCost(); + } + } + return 0.0; + } else if (c == 7) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getCost() != null) { + return medInvtRow.getRealQty() * medInvtRow.getLot().getCost().doubleValue(); + } + } + return 0.0; } return null; } @Override public void setValueAt(Object value, int r, int c) { - if (r < inventoryRowSearchList.size()) {/// + if (r < inventoryRowSearchList.size()) { MedicalInventoryRow invRow = inventoryRowSearchList.get(r); - if (c == 4) { - Double intValue = 0.0; + if (c == 5) { + Integer intValue = 0; try { - intValue = Double.parseDouble(value.toString()); + intValue = Integer.parseInt(value.toString()); } catch (NumberFormatException e) { - intValue = 0.0; + intValue = 0; } + invRow.setRealqty(intValue); inventoryRowSearchList.set(r, invRow); - validateButton.setEnabled(false); + jTableInventoryRow.updateUI(); + } + if (c == 6) { + Double doubleValue = 0.0; + try { + doubleValue = Double.parseDouble(value.toString()); + } catch (NumberFormatException e) { + doubleValue = 0.0; + } + Lot lot = invRow.getLot(); + if (lot != null) { + if (lot.getCode().equals("")) { + MessageDialog.error(null, "angal.inventoryrow.cannotchangethepriceofproductwithoutlot.msg"); + } else { + lot.setCost(new BigDecimal(doubleValue)); + try { + Lot saveLot = movStockInsertingManager.updateLot(lot); + invRow.setLot(saveLot); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + } + inventoryRowSearchList.set(r, invRow); + jTableInventoryRow.updateUI(); } } } From 69e093b9fc21635fb2c82cfed50b2f42a35d1619 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 3 Apr 2024 10:05:20 +0200 Subject: [PATCH 16/83] Applying the suggested changes --- bundle/language_en.properties | 4 ++-- .../org/isf/medicalinventory/gui/InventoryWardEdit.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index fe786afd24..e9cbe17080 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -665,7 +665,7 @@ angal.hospital.visitendhour.txt angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. angal.inventory.allproduct.radio = All products -angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward = cannot create an other inventory with other in progress in this ward. +angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg = Cannot create another inventory with other in progress in this ward. angal.inventory.date.label = Inventory's date angal.inventory.edit.title = Edit an inventory angal.inventory.error.msg = Error during some products's recording @@ -691,7 +691,7 @@ angal.inventory.state.canceled.txt angal.inventory.state.inprogress.txt = In progress angal.inventory.state.validate.txt = Validate angal.inventory.theorticalqty.col = Theoretical -angal.inventory.totalprice.col = Total price quantity +angal.inventory.totalprice.col = Total price quantity angal.inventory.unitprice.col = Unit price angal.inventory.user.col = User angal.inventory.validate.btn = Validate diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 021d3bb42b..114e12a8c1 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -695,7 +695,7 @@ private List loadNewInventoryTable(String code) throws OHSe if (code != null) { medical = medicalBrowsingManager.getMedicalByMedicalCode(code); if (medical != null) { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode()); + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); } else { MessageDialog.error(null, MessageBundle.getMessage("angal.inventory.noproductfound.msg")); } @@ -896,7 +896,7 @@ private void addInventoryRow(String code) throws OHServiceException { if (code != null) { medical = medicalBrowsingManager.getMedicalByMedicalCode(code); if (medical != null) { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode()); + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); } else { medical = chooseMedical(code); if (medical != null) { @@ -909,7 +909,7 @@ private void addInventoryRow(String code) throws OHServiceException { } } if (!found) { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode()); + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); } } } @@ -1048,7 +1048,7 @@ private JComboBox getWardComboBox() { activedSomeComponents(); } else { MessageDialog.error(this, - "angal.inventory.anotherinventoryonthiswardstillanotheroneisinprogress"); + "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); return; } } From 710ef9be957d446771d03fc3a4ae32b66dc51e53 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 8 Apr 2024 15:49:42 +0100 Subject: [PATCH 17/83] Apply review suggestion --- .../java/org/isf/medicalinventory/gui/InventoryWardEdit.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 114e12a8c1..bf1ecc1d87 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -584,8 +584,9 @@ public Class getColumnClass(int c) { } public int getRowCount() { - if (inventoryRowSearchList == null) + if (inventoryRowSearchList == null) { return 0; + } return inventoryRowSearchList.size(); } From 3659c4fe99be620d7d55afeb30dc4a47940c6afa Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 9 Apr 2024 10:00:58 +0100 Subject: [PATCH 18/83] Apply suggestions from code review --- .../medicalinventory/gui/InventoryWardEdit.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index bf1ecc1d87..8e3c860772 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -146,14 +146,14 @@ private void fireInventoryUpdated() { private JTable jTableInventoryRow; private List inventoryRowList; private List inventoryRowSearchList; - private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt"), - MessageBundle.getMessage("angal.inventory.medical.col"), - MessageBundle.getMessage("angal.inventory.lotcode.col"), - MessageBundle.getMessage("angal.medicalstock.duedate.col"), - MessageBundle.getMessage("angal.inventory.theorticalqty.col"), - MessageBundle.getMessage("angal.inventory.realqty.col"), - MessageBundle.getMessage("angal.inventory.unitprice.col"), - MessageBundle.getMessage("angal.inventory.totalprice.col") + private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt").toUpperCase(), + MessageBundle.getMessage("angal.inventory.medical.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.lotcode.col").toUpperCase(), + MessageBundle.getMessage("angal.medicalstock.duedate.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.theorticalqty.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.realqty.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.unitprice.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.totalprice.col").toUpperCase() }; private int[] pColumwidth = { 100, 200, 100, 100, 100, 80, 80, 80 }; private boolean[] columnEditable = { false, false, false, false, false, true, true, false }; From ed30bc1f57e08052eded3848d36893c5df1d1f5b Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 12 Nov 2024 11:17:52 +0100 Subject: [PATCH 19/83] Update, Delete and validate inventory ward --- bundle/language_en.properties | 47 +- .../gui/InventoryWardBrowser.java | 384 ++++- .../gui/InventoryWardEdit.java | 1448 ++++++++++++----- .../isf/utils/jobjects/InventoryStatus.java | 2 +- 4 files changed, 1390 insertions(+), 491 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 77f1ae98ad..c7c547c4f8 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -665,24 +665,56 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. +angal.invetory.allmedicaladdedsuccessfully.msg = All medical are added successfully. angal.inventory.allproduct.radio = All products +angal.inventory.canceled = Canceled +angal.inventory.cancelednoteditable.msg = A canceled inventory can not be modified. angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg = Cannot create another inventory with other in progress in this ward. +angal.inventory.cannotsaveinventorywithoutproducts.msg = Cannot save inventory without products. +angal.inventory.chargetype.label = Charge Type: +angal.inventory.choosechargetypebeforevalidation.msg = Please choose the charge type and save the inventory before validation. +angal.inventory.choosedestinationbeforevalidation.msg = Please choose the destination and save the inventory before validation. +angal.inventory.choosedischargetypebeforevalidation.msg = Please choose the discharge type and save the inventory before validation. +angal.inventory.choosesupplierbeforevalidation.msg = Please choose the supplier and save the inventory before validation. +angal.inventory.clean.btn = Clean Table +angal.inventory.clean.btn.key = T angal.inventory.date.label = Inventory's date -angal.inventory.edit.title = Edit an inventory +angal.inventory.deletion.confirm.msg = Do you really want to delete this inventory? +angal.inventory.deletion.success.msg = The inventory has been successfully marked as deleted. +angal.inventory.deletion.error.msg = Deletion is only allowed for inventories with 'draft' or 'validated' status. +angal.inventory.destination.label = Destination: +angal.inventory.dischargetype.label = Discharge Type: +angal.inventory.done = Done +angal.inventory.doyoureallywanttocleanthistable.msg = Do you really want to clean this table? +angal.inventory.doyoureallywanttodeletethisinventoryrow.msg = Do you really want to delete this inventory row? +angal.inventory.doyouwanttoaddallnotyetlistedproducts.msg = Do you want to add all not yet listed products? +angal.inventory.doyouwanttocontinueediting.msg = Do you want to continue editing? +angal.inventory.doyouwanttosavethechanges.msg = Do you want to save the changes? +angal.inventory.draft = Draft +angal.inventory.editinventory.title = Edit inventory angal.inventory.error.msg = Error during some products's recording +angal.inventory.id.col = Id +angal.inventory.invalidquantity.msg = Invalid quantity. +angal.inventory.inventoryisalreadysaved.msg = This inventory is already saved. Please enter at least one inventory row before continue. +angal.inventory.inventorymustsavebeforevalidation.msg = Inventory must be saved before validation. angal.inventory.lotcode.col = Lot's code angal.inventory.managementward.title = Manage Ward Inventory angal.inventory.medical.col = Medical angal.inventory.mustenterareference.msg = You must enter a reference. +angal.inventory.nextarrow.btn = > +angal.inventory.newinventory.title = New inventory angal.inventory.noproduct.msg = Product is not found. angal.inventory.noproductfound.msg = No medical found angal.inventory.notdateinfuture.msg = A date in the future is not allowed. +angal.inventory.pleaseselectonlyoneinventory.msg = Please select only one inventory. +angal.inventory.pleaseselectinventory.msg = Please select inventory. +angal.inventory.previousarrow.btn = < angal.inventory.productcode.text = Product's code angal.inventory.realqty.col = Real quantity angal.inventory.reference.label = Inventory's reference angal.inventory.referencealreadyused.msg = Reference is already used. angal.inventory.referenceshow.col = Reference -angal.inventory.savesucces.msg = Inventory saved. +angal.inventory.savesuccess.msg = Inventory saved. angal.inventory.searchproduct.txt = Search a product angal.inventory.selectward.label = Select ward angal.inventory.specificproduct.radio = Specific product @@ -691,17 +723,22 @@ angal.inventory.state.label angal.inventory.state.canceled.txt = Canceled angal.inventory.state.inprogress.txt = In progress angal.inventory.state.validate.txt = Validate +angal.inventory.supplier.label = Supplier: angal.inventory.theorticalqty.col = Theoretical angal.inventory.totalprice.col = Total price quantity angal.inventory.unitprice.col = Unit price +angal.inventory.update.error.msg = Inventory not updated. +angal.inventory.update.success.msg = Inventory updated. +angal.inventory.updaterowerror.msg = Error during some products's update. angal.inventory.user.col = User angal.inventory.validate.btn = Validate angal.inventory.validate.btn.key = V +angal.inventory.validate.success.msg = The inventory has been successfully validated. +angal.inventory.validated = Validated angal.inventory.view.btn = View inventory angal.inventory.view.btn.key = V -angal.inventoryrow.cannotchangethepriceofproductwithoutlot.msg = You cannot update the unit price of a product without a lot. -angal.inventoryrow.doyoureallywanttodeletethisinventoryrow.msg = Do you really want to delete this inventory row? -angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg = Please select only one inventory row. +angal.inventory.viewinventory.title = View Inventory +angal.inventory.youhavealreadyaddedallproduct.msg = You have already added all the products. angal.lab.blood.txt = Blood angal.lab.cfs.txt = CFS angal.lab.datapatient = Patient's Data diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index ddb4ef65f5..f72bfdc032 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -1,6 +1,6 @@ /* * Open Hospital (www.open-hospital.org) - * Copyright © 2006-2023 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) * * Open Hospital is a free and open source software for healthcare data management. * @@ -21,38 +21,54 @@ */ package org.isf.medicalinventory.gui; +import static org.isf.utils.Constants.DATE_TIME_FORMATTER; + import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableModel; import org.isf.generaldata.MessageBundle; import org.isf.medicalinventory.gui.InventoryWardEdit.InventoryListener; +import org.isf.medicalinventory.manager.MedicalInventoryManager; import org.isf.medicalinventory.model.MedicalInventory; +import org.isf.menu.manager.Context; +import org.isf.utils.exception.OHServiceException; +import org.isf.utils.exception.gui.OHServiceExceptionUtil; import org.isf.utils.jobjects.GoodDateChooser; -import org.isf.utils.jobjects.InventoryState; +import org.isf.utils.jobjects.InventoryStatus; +import org.isf.utils.jobjects.InventoryType; +import org.isf.utils.jobjects.MessageDialog; import org.isf.utils.jobjects.ModalJFrame; import org.isf.utils.time.TimeTools; +import org.isf.ward.manager.WardBrowserManager; +import org.isf.ward.model.Ward; +import org.springframework.data.domain.Page; public class InventoryWardBrowser extends ModalJFrame implements InventoryListener { @@ -82,8 +98,17 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListen MessageBundle.getMessage("angal.common.user.col").toUpperCase() }; private int[] pColumwidth = { 150, 150, 100, 100, 150 }; - private JComboBox stateComboBox; - private JLabel stateLabel; + private JComboBox statusComboBox; + private JLabel statusLabel; + JButton next; + JButton previous; + JComboBox pagesCombo = new JComboBox(); + JLabel under = new JLabel("/ 0 Page"); + private static int PAGE_SIZE = 50; + private int startIndex = 0; + private int totalRows; + private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); + private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); private List inventoryList; public InventoryWardBrowser() { @@ -106,16 +131,57 @@ private void initComponents() { panelFooter = getPanelFooter(); getContentPane().add(panelFooter, BorderLayout.SOUTH); - for (int i = 0; i < pColumwidth.length; i++) { - jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); - } + ajustWidth(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); } }); - // pack(); + pagesCombo.setEditable(true); + previous.setEnabled(false); + next.setEnabled(false); + next.addActionListener(actionEvent -> { + if (!previous.isEnabled()) { + previous.setEnabled(true); + } + startIndex += PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if ((startIndex + PAGE_SIZE) > totalRows) { + next.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + }); + + previous.addActionListener(actionEvent -> { + if (!next.isEnabled()) { + next.setEnabled(true); + } + startIndex -= PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex < PAGE_SIZE) { + previous.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + }); + pagesCombo.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent itemEvent) { + int eventID = itemEvent.getStateChange(); + + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; + + next.setEnabled((startIndex + PAGE_SIZE) <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + + pagesCombo.setEnabled(true); + } + } + }); } private JPanel getPanelHeader() { @@ -157,7 +223,7 @@ private JPanel getPanelHeader() { gbc_stateLabel.insets = new Insets(0, 0, 0, 5); gbc_stateLabel.gridx = 4; gbc_stateLabel.gridy = 0; - panelHeader.add(getStateLabel(), gbc_stateLabel); + panelHeader.add(getStatusLabel(), gbc_stateLabel); GridBagConstraints gbc_comboBox = new GridBagConstraints(); gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; gbc_comboBox.gridx = 5; @@ -188,6 +254,16 @@ private JPanel getPanelContent() { private JPanel getPanelFooter() { if (panelFooter == null) { panelFooter = new JPanel(); + next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); + next.setMnemonic(KeyEvent.VK_RIGHT); + previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); + next.setMnemonic(KeyEvent.VK_LEFT); + + panelFooter.add(previous); + panelFooter.add(pagesCombo); + panelFooter.add(under); + panelFooter.add(next); + panelFooter.add(getNewButton()); panelFooter.add(getViewButton()); panelFooter.add(getUpdateButton()); @@ -198,40 +274,44 @@ private JPanel getPanelFooter() { } private GoodDateChooser getJCalendarFrom() { - if (jCalendarFrom == null) { - jCalendarFrom = new GoodDateChooser(dateFrom.toLocalDate()); - jCalendarFrom.addDateChangeListener(dateChangeEvent -> { - LocalDate newDate = dateChangeEvent.getNewDate(); - if (newDate != null) { - dateFrom = newDate.atStartOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - } - }); - jCalendarFrom.setEnabled(false); - } - return jCalendarFrom; + if (jCalendarFrom == null) { + jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarFrom.addDateChangeListener(event -> { + dateFrom = jCalendarFrom.getDateStartOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarFrom; } private GoodDateChooser getJCalendarTo() { - if (jCalendarTo == null) { - jCalendarTo = new GoodDateChooser(dateTo.toLocalDate(), false); - jCalendarTo.addDateChangeListener(dateChangeEvent -> { - LocalDate newDate = dateChangeEvent.getNewDate(); - if (newDate != null) { - dateTo = newDate.atStartOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - } - }); - jCalendarTo.setEnabled(false); - } - return jCalendarTo; + if (jCalendarTo == null) { + jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarTo.addDateChangeListener(event -> { + dateTo = jCalendarTo.getDateEndOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarTo; } private JLabel getJLabelTo() { if (jLabelTo == null) { jLabelTo = new JLabel(); jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); //$NON-NLS-1$ + jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); } return jLabelTo; } @@ -240,7 +320,7 @@ private JLabel getJLabelFrom() { if (jLabelFrom == null) { jLabelFrom = new JLabel(); jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); //$NON-NLS-1$ + jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); } return jLabelFrom; } @@ -248,42 +328,102 @@ private JLabel getJLabelFrom() { private JButton getNewButton() { newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); - newButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - } + newButton.addActionListener(actionEvent -> { + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); return newButton; } + private JButton getUpdateButton() { + updateButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); + updateButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); + updateButton.setEnabled(false); + updateButton.addActionListener(actionEvent -> { + MedicalInventory inventory; + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + inventory = inventoryList.get(selectedRow); + if (inventory.getStatus().equals(InventoryStatus.canceled.toString())) { + MessageDialog.error(this, "angal.inventory.cancelednoteditable.msg"); + return; + } + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "update"); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); + return updateButton; + } + private JButton getViewButton() { viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); + viewButton.setEnabled(false); + viewButton.addActionListener(actionEvent -> { + MedicalInventory inventory; + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + inventory = inventoryList.get(selectedRow); + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "view"); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); return viewButton; } - private JButton getUpdateButton() { - updateButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); - updateButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); - return updateButton; - } - private JButton getDeleteButton() { deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); + deleteButton.setEnabled(false); + deleteButton.addActionListener(actionEvent -> { + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + MedicalInventory inventory = inventoryList.get(selectedRow); + String currentStatus = inventory.getStatus(); + if (currentStatus.equalsIgnoreCase(InventoryStatus.validated.toString()) || currentStatus.equalsIgnoreCase(InventoryStatus.draft.toString())) { + int response = MessageDialog.yesNo(this, "angal.inventory.deletion.confirm.msg"); + if (response == JOptionPane.YES_OPTION) { + try { + medicalInventoryManager.deleteInventory(inventory); + MessageDialog.info(this, "angal.inventory.deletion.success.msg"); + jTableInventory.setModel(new InventoryBrowsingModel()); + } catch (OHServiceException e) { + MessageDialog.error(this, "angal.inventory.deletion.error.msg"); + } + } + } else { + MessageDialog.error(this, "angal.inventory.deletion.error.msg"); + } + }); return deleteButton; } private JButton getCloseButton() { closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - dispose(); - } - }); + closeButton.addActionListener(e -> dispose()); return closeButton; } @@ -300,6 +440,24 @@ private JTable getJTableInventory() { jTableInventory = new JTable(); jTableInventory.setFillsViewportHeight(true); jTableInventory.setModel(new InventoryBrowsingModel()); + jTableInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + if (e.getValueIsAdjusting()) { + int[] selectedRows = jTableInventory.getSelectedRows(); + if (selectedRows.length == 1) { + updateButton.setEnabled(true); + viewButton.setEnabled(true); + deleteButton.setEnabled(true); + } else { + updateButton.setEnabled(false); + viewButton.setEnabled(false); + deleteButton.setEnabled(false); + } + } + } + }); } return jTableInventory; } @@ -312,9 +470,29 @@ class InventoryBrowsingModel extends DefaultTableModel { private static final long serialVersionUID = 1L; public InventoryBrowsingModel() { - + inventoryList = new ArrayList<>(); + String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, state, type); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } } + public InventoryBrowsingModel(int startIndex, int pageSize) { + inventoryList = new ArrayList<>(); + String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, startIndex, + pageSize); + inventoryList = medInventorypage.getContent(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + public Class getColumnClass(int c) { if (c == 0) { return String.class; @@ -330,6 +508,13 @@ public Class getColumnClass(int c) { return null; } + public int getRowCount() { + if (inventoryList == null) { + return 0; + } + return inventoryList.size(); + } + public String getColumnName(int c) { return pColums[c]; } @@ -338,6 +523,31 @@ public int getColumnCount() { return pColums.length; } + public Object getValueAt(int r, int c) { + MedicalInventory medInvt = inventoryList.get(r); + + if (c == -1) { + return medInvt; + } else if (c == 0) { + return medInvt.getInventoryReference(); + } else if (c == 1) { + Ward ward = new Ward(); + try { + ward = wardBrowserManager.findWard(medInvt.getWard()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + return ward == null ? "" : ward.getDescription(); + } else if (c == 2) { + return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); + } else if (c == 3) { + return medInvt.getStatus(); + } else if (c == 4) { + return medInvt.getUser(); + } + return null; + } + @Override public boolean isCellEditable(int arg0, int arg1) { return false; @@ -345,46 +555,68 @@ public boolean isCellEditable(int arg0, int arg1) { } - private JComboBox getComboBox() { - if (stateComboBox == null) { - stateComboBox = new JComboBox(); - stateComboBox.addItem(""); - for (InventoryState.State currentState : InventoryState.State.values()) { - stateComboBox.addItem(MessageBundle.getMessage(currentState.getLabel())); + private JComboBox getComboBox() { + if (statusComboBox == null) { + statusComboBox = new JComboBox(); + statusComboBox.addItem(""); + for (InventoryStatus currentStatus : InventoryStatus.values()) { + statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); } + statusComboBox.addActionListener(actionEvent -> { + InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); + totalRows = inventoryBrowsingModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); } - return stateComboBox; + return statusComboBox; } - private JLabel getStateLabel() { - if (stateLabel == null) { - stateLabel = new JLabel(MessageBundle.getMessage("angal.inventory.state.label")); - stateLabel.setHorizontalAlignment(SwingConstants.RIGHT); + private JLabel getStatusLabel() { + if (statusLabel == null) { + statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.state.label")); + statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); } - return stateLabel; + return statusLabel; } + private void ajustWidth() { + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); + } + } + + public void initialiseCombo(int total_rows) { + int j = 0; + + pagesCombo.removeAllItems(); + for (int i = 0; i < total_rows / PAGE_SIZE; i++) { + j = i + 1; + pagesCombo.addItem(j); + } + if (j * PAGE_SIZE < total_rows) { + pagesCombo.addItem(j + 1); + under.setText("/" + (total_rows / PAGE_SIZE + 1 + " Pages")); + } else { + under.setText("/" + total_rows / PAGE_SIZE + " Pages"); + } + } + @Override public void InventoryInserted(AWTEvent e) { - if (inventoryList != null) { - inventoryList.clear(); - } jTableInventory.setModel(new InventoryBrowsingModel()); } @Override public void InventoryUpdated(AWTEvent e) { - if (inventoryList != null) { - inventoryList.clear(); - } jTableInventory.setModel(new InventoryBrowsingModel()); } @Override public void InventoryCancelled(AWTEvent e) { - if (inventoryList != null) { - inventoryList.clear(); - } jTableInventory.setModel(new InventoryBrowsingModel()); } } \ No newline at end of file diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 8e3c860772..8eef807ece 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -31,22 +31,20 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.math.BigDecimal; -import java.text.DecimalFormat; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.EventListener; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import javax.swing.ButtonGroup; import javax.swing.DefaultCellEditor; @@ -63,19 +61,16 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; +import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import javax.swing.event.EventListenerList; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; import javax.swing.plaf.DimensionUIResource; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; +import org.isf.generaldata.GeneralData; import org.isf.generaldata.MessageBundle; import org.isf.medicalinventory.manager.MedicalInventoryManager; import org.isf.medicalinventory.manager.MedicalInventoryRowManager; @@ -87,8 +82,12 @@ import org.isf.medicalstock.model.Lot; import org.isf.medicalstockward.manager.MovWardBrowserManager; import org.isf.medicalstockward.model.MedicalWard; +import org.isf.medstockmovtype.manager.MedicalDsrStockMovementTypeBrowserManager; +import org.isf.medstockmovtype.model.MovementType; import org.isf.menu.manager.Context; import org.isf.menu.manager.UserBrowsingManager; +import org.isf.supplier.manager.SupplierBrowserManager; +import org.isf.supplier.model.Supplier; import org.isf.utils.db.NormalizeString; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.gui.OHServiceExceptionUtil; @@ -128,8 +127,22 @@ private void fireInventoryUpdated() { }; EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class); - for (int i = 0; i < listeners.length; i++) + for (int i = 0; i < listeners.length; i++) { ((InventoryListener) listeners[i]).InventoryUpdated(event); + } + jTableInventoryRow.updateUI(); + } + + private void fireInventoryInserted() { + AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { + private static final long serialVersionUID = 1L; + }; + + EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class); + for (EventListener listener : listeners) { + ((InventoryListener) listener).InventoryInserted(event); + } + jTableInventoryRow.updateUI(); } private GoodDateChooser jCalendarInventory; @@ -139,14 +152,19 @@ private void fireInventoryUpdated() { private JPanel panelContent; private JButton closeButton; private JButton saveButton; - private JButton cancelButton; + private JButton resetButton; private JButton printButton; private JButton validateButton; + private JButton deleteButton; private JScrollPane scrollPaneInventory; private JTable jTableInventoryRow; - private List inventoryRowList; - private List inventoryRowSearchList; - private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt").toUpperCase(), + + private List inventoryRowList = new ArrayList<>(); + private List inventoryRowSearchList = new ArrayList<>(); + private List inventoryRowsToDelete = new ArrayList<>(); + private List inventoryRowListAdded = new ArrayList<>(); + private String[] pColums = { MessageBundle.getMessage("angal.inventory.id.col").toUpperCase(), + MessageBundle.getMessage("angal.common.code.txt").toUpperCase(), MessageBundle.getMessage("angal.inventory.medical.col").toUpperCase(), MessageBundle.getMessage("angal.inventory.lotcode.col").toUpperCase(), MessageBundle.getMessage("angal.medicalstock.duedate.col").toUpperCase(), @@ -155,24 +173,40 @@ private void fireInventoryUpdated() { MessageBundle.getMessage("angal.inventory.unitprice.col").toUpperCase(), MessageBundle.getMessage("angal.inventory.totalprice.col").toUpperCase() }; - private int[] pColumwidth = { 100, 200, 100, 100, 100, 80, 80, 80 }; - private boolean[] columnEditable = { false, false, false, false, false, true, true, false }; + private int[] pColumwidth = { 50, 50, 200, 100, 100, 100, 80, 80, 80 }; + private boolean[] columnEditable = { false, false, false, false, false, false, true, false, false }; + private boolean[] columnEditableView = { false, false, false, false, false, false, false, false, false }; + private boolean[] pColumnVisible = { false, true, true, !GeneralData.AUTOMATICLOT_IN, true, true, true, GeneralData.LOTWITHCOST, GeneralData.LOTWITHCOST }; private MedicalInventory inventory = null; private JRadioButton specificRadio; private JRadioButton allRadio; - private JTextField searchTextField; private JLabel dateInventoryLabel; private JTextField codeTextField; private String code = null; - private String mode = null; + private String mode; + private JLabel statusLabel; private String wardId = ""; private JLabel referenceLabel; private JTextField referenceTextField; - private JTextField jTetFieldEditor; + private JTextField jTextFieldEditor; private JLabel wardLabel; + private JLabel chargeLabel; + private JLabel dischargeLabel; + private JLabel supplierLabel; + private JLabel destinationLabel; private JComboBox wardComboBox; + private JComboBox chargeComboBox; + private JComboBox dischargeComboBox; + private JComboBox supplierComboBox; + private JComboBox destinationComboBox; private Ward wardSelected; private JLabel loaderLabel; + private boolean selectAll = false; + private String newReference = null; + private MovementType chargeType = null; + private MovementType dischargeType = null; + private Supplier supplier = null; + private Ward destination = null; private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext() .getBean(MedicalInventoryManager.class); @@ -184,11 +218,15 @@ private void fireInventoryUpdated() { .getBean(MovWardBrowserManager.class); private MovStockInsertingManager movStockInsertingManager = Context.getApplicationContext() .getBean(MovStockInsertingManager.class); + private MedicalDsrStockMovementTypeBrowserManager medStockMovTypeManager = Context.getApplicationContext() + .getBean(MedicalDsrStockMovementTypeBrowserManager.class); + private SupplierBrowserManager supplierBrowserManager = Context.getApplicationContext().getBean(SupplierBrowserManager.class); + public InventoryWardEdit() { mode = "new"; initComponents(); - cancelButton.setVisible(false); + resetButton.setVisible(false); disabledSomeComponents(); } @@ -196,19 +234,19 @@ public InventoryWardEdit(MedicalInventory inventory, String modee) { this.inventory = inventory; mode = modee; initComponents(); - if (mode.equals("view")) { - validateButton.setVisible(false); - saveButton.setVisible(false); - cancelButton.setVisible(false); - wardComboBox.setEnabled(false); - } } private void initComponents() { setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setMinimumSize(new DimensionUIResource(950, 580)); setLocationRelativeTo(null); // center - setTitle(MessageBundle.getMessage("angal.inventory.edit.title")); + if (mode.equals("update")) { + setTitle(MessageBundle.getMessage("angal.inventory.edit.title")); + } else if (mode.equals("view")) { + setTitle(MessageBundle.getMessage("angal.inventory.view.title")); + } else { + setTitle(MessageBundle.getMessage("angal.inventory.new.title")); + } panelHeader = getPanelHeader(); getContentPane().add(panelHeader, BorderLayout.NORTH); @@ -218,6 +256,48 @@ private void initComponents() { panelFooter = getPanelFooter(); getContentPane().add(panelFooter, BorderLayout.SOUTH); + + addWindowFocusListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + closeButton.doClick(); + } + }); + + if (mode.equals("view")) { + saveButton.setVisible(false); + deleteButton.setVisible(false); + columnEditable = columnEditableView; + codeTextField.setEditable(false); + resetButton.setVisible(false); + referenceTextField.setVisible(false); + jCalendarInventory.setEnabled(false); + specificRadio.setEnabled(false); + allRadio.setEnabled(false); + chargeComboBox.setEnabled(false); + dischargeComboBox.setEnabled(false); + supplierComboBox.setEnabled(false); + destinationComboBox.setEnabled(false); + wardComboBox.setEnabled(false); + validateButton.setVisible(false); + printButton.setVisible(true); + } else { + saveButton.setVisible(true); + deleteButton.setVisible(true); + codeTextField.setEditable(true); + resetButton.setVisible(true); + referenceTextField.setEditable(true); + jCalendarInventory.setEnabled(true); + specificRadio.setEnabled(true); + allRadio.setEnabled(true); + chargeComboBox.setEnabled(true); + dischargeComboBox.setEnabled(true); + supplierComboBox.setEnabled(true); + destinationComboBox.setEnabled(true); + wardComboBox.setEnabled(true); + validateButton.setVisible(true); + printButton.setVisible(false); + } } private JPanel getPanelHeader() { @@ -225,10 +305,10 @@ private JPanel getPanelHeader() { panelHeader = new JPanel(); panelHeader.setBorder(new EmptyBorder(5, 0, 5, 0)); GridBagLayout gbl_panelHeader = new GridBagLayout(); - gbl_panelHeader.columnWidths = new int[] { 123, 206, 187, 195, 0, 0 }; - gbl_panelHeader.rowHeights = new int[] { 34, 36, 0, 0 }; - gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; - gbl_panelHeader.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; + gbl_panelHeader.columnWidths = new int[] { 159, 191, 192, 218, 51, 0 }; + gbl_panelHeader.rowHeights = new int[] { 30, 30, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; panelHeader.setLayout(gbl_panelHeader); GridBagConstraints gbc_wardLabel = new GridBagConstraints(); gbc_wardLabel.anchor = GridBagConstraints.EAST; @@ -271,30 +351,79 @@ private JPanel getPanelHeader() { gbc_referenceTextField.gridx = 3; gbc_referenceTextField.gridy = 1; panelHeader.add(getReferenceTextField(), gbc_referenceTextField); + GridBagConstraints gbc_statusLabel = new GridBagConstraints(); + gbc_statusLabel.anchor = GridBagConstraints.CENTER; + gbc_statusLabel.insets = new Insets(0, 0, 5, 5); + gbc_statusLabel.gridx = 4; + gbc_statusLabel.gridy = 1; + gbc_statusLabel.gridheight = 3; + panelHeader.add(getStatusLabel(), gbc_statusLabel); + GridBagConstraints gbc_chargeLabel = new GridBagConstraints(); + gbc_chargeLabel.insets = new Insets(0, 0, 3, 3); + gbc_chargeLabel.gridx = 0; + gbc_chargeLabel.gridy = 2; + panelHeader.add(getChargeLabel(), gbc_chargeLabel); + GridBagConstraints gbc_chargeComboBox = new GridBagConstraints(); + gbc_chargeComboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_chargeComboBox.insets = new Insets(0, 0, 3, 3); + gbc_chargeComboBox.gridx = 1; + gbc_chargeComboBox.gridy = 2; + panelHeader.add(getChargeComboBox(), gbc_chargeComboBox); + GridBagConstraints gbc_supplierLabel = new GridBagConstraints(); + gbc_supplierLabel.anchor = GridBagConstraints.EAST; + gbc_supplierLabel.insets = new Insets(0, 0, 3, 3); + gbc_supplierLabel.gridx = 2; + gbc_supplierLabel.gridy = 2; + panelHeader.add(getSupplierLabel(), gbc_supplierLabel); + GridBagConstraints gbc_supplierComboBox = new GridBagConstraints(); + gbc_supplierComboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_supplierComboBox.insets = new Insets(0, 0, 3, 3); + gbc_supplierComboBox.gridx = 3; + gbc_supplierComboBox.gridy = 2; + panelHeader.add(getSupplierComboBox(), gbc_supplierComboBox); + + GridBagConstraints gbc_dischargeLabel = new GridBagConstraints(); + gbc_dischargeLabel.insets = new Insets(0, 0, 3, 3); + gbc_dischargeLabel.gridx = 0; + gbc_dischargeLabel.gridy = 3; + panelHeader.add(getDischargeLabel(), gbc_dischargeLabel); + GridBagConstraints gbc_dischargeComboBox = new GridBagConstraints(); + gbc_dischargeComboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_dischargeComboBox.insets = new Insets(0, 0, 3, 3); + gbc_dischargeComboBox.gridx = 1; + gbc_dischargeComboBox.gridy = 3; + panelHeader.add(getDischargeComboBox(), gbc_dischargeComboBox); + GridBagConstraints gbc_destinationLabel = new GridBagConstraints(); + gbc_destinationLabel.anchor = GridBagConstraints.EAST; + gbc_destinationLabel.insets = new Insets(0, 0, 3, 3); + gbc_destinationLabel.gridx = 2; + gbc_destinationLabel.gridy = 3; + panelHeader.add(getDestinationLabel(), gbc_destinationLabel); + GridBagConstraints gbc_destinationComboBox = new GridBagConstraints(); + gbc_destinationComboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_destinationComboBox.insets = new Insets(0, 0, 3, 3); + gbc_destinationComboBox.gridx = 3; + gbc_destinationComboBox.gridy = 3; + panelHeader.add(getDestinationComboBox(), gbc_destinationComboBox); + GridBagConstraints gbc_specificRadio = new GridBagConstraints(); gbc_specificRadio.anchor = GridBagConstraints.EAST; gbc_specificRadio.insets = new Insets(0, 0, 0, 5); gbc_specificRadio.gridx = 0; - gbc_specificRadio.gridy = 2; + gbc_specificRadio.gridy = 4; panelHeader.add(getSpecificRadio(), gbc_specificRadio); GridBagConstraints gbc_codeTextField = new GridBagConstraints(); gbc_codeTextField.insets = new Insets(0, 0, 0, 5); gbc_codeTextField.fill = GridBagConstraints.HORIZONTAL; gbc_codeTextField.gridx = 1; - gbc_codeTextField.gridy = 2; + gbc_codeTextField.gridy = 4; panelHeader.add(getCodeTextField(), gbc_codeTextField); GridBagConstraints gbc_allRadio = new GridBagConstraints(); gbc_allRadio.anchor = GridBagConstraints.EAST; gbc_allRadio.insets = new Insets(0, 0, 0, 5); gbc_allRadio.gridx = 2; - gbc_allRadio.gridy = 2; + gbc_allRadio.gridy = 4; panelHeader.add(getAllRadio(), gbc_allRadio); - GridBagConstraints gbc_searchTextField = new GridBagConstraints(); - gbc_searchTextField.insets = new Insets(0, 0, 0, 5); - gbc_searchTextField.fill = GridBagConstraints.HORIZONTAL; - gbc_searchTextField.gridx = 3; - gbc_searchTextField.gridy = 2; - panelHeader.add(getSearchTextField(), gbc_searchTextField); ButtonGroup group = new ButtonGroup(); group.add(specificRadio); group.add(allRadio); @@ -325,8 +454,9 @@ private JPanel getPanelFooter() { if (panelFooter == null) { panelFooter = new JPanel(); panelFooter.add(getSaveButton()); + panelFooter.add(getDeleteButton()); panelFooter.add(getValidateButton()); - panelFooter.add(getCancelButton()); + panelFooter.add(getCleanTableButton()); panelFooter.add(getPrintButton()); panelFooter.add(getCloseButton()); } @@ -336,88 +466,257 @@ private JPanel getPanelFooter() { private GoodDateChooser getJCalendarFrom() { if (jCalendarInventory == null) { - jCalendarInventory = new GoodDateChooser(LocalDate.now()); + jCalendarInventory = new GoodDateChooser(LocalDate.now(), false, false); if (inventory != null) { jCalendarInventory.setDate(inventory.getInventoryDate().toLocalDate()); + dateInventory = inventory.getInventoryDate(); } - jCalendarInventory.addDateChangeListener(dateChangeEvent -> { - LocalDate newDate = dateChangeEvent.getNewDate(); - if (newDate != null) { - dateInventory = newDate.atStartOfDay(); - jCalendarInventory.setDate(newDate); - } - }); + jCalendarInventory.addDateChangeListener(event -> dateInventory = jCalendarInventory.getDate().atStartOfDay()); } return jCalendarInventory; } private JButton getSaveButton() { - saveButton = new JButton(MessageBundle.getMessage("angal.common.save")); + saveButton = new JButton(MessageBundle.getMessage("angal.common.save.btn")); saveButton.setMnemonic(MessageBundle.getMnemonic("angal.common.save.btn.key")); saveButton.addActionListener(actionEvent -> { - String State = InventoryStatus.draft.toString(); + String state = InventoryStatus.draft.toString(); String user = UserBrowsingManager.getCurrentUser(); - int checkResults = 0; - if (inventoryRowSearchList == null || inventoryRowSearchList.size() < 1) { - MessageDialog.error(null, "angal.inventory.noproduct.msg"); - return; - } - LocalDateTime now = LocalDateTime.now(); - if (dateInventory.isAfter(now)) { - MessageDialog.error(null, "angal.inventory.notdateinfuture.msg"); + if (inventoryRowSearchList == null || inventoryRowSearchList.isEmpty()) { + MessageDialog.error(null, "angal.inventory.cannotsaveinventorywithoutproducts.msg"); return; } - - if ((inventory == null) && (mode.equals("new"))) { - String reference = referenceTextField.getText().trim(); - if (reference.equals("")) { - MessageDialog.error(null, "angal.inventory.mustenterareference.msg"); - return; - } - if (medicalInventoryManager.referenceExists(reference)) { - MessageDialog.error(null, "angal.inventory.referencealreadyused.msg"); - return; + try { + if (!inventoryRowsToDelete.isEmpty()) { + medicalInventoryRowManager.deleteMedicalInventoryRows(inventoryRowsToDelete); } - inventory = new MedicalInventory(); - inventory.setInventoryReference(reference); - inventory.setInventoryDate(dateInventory); - inventory.setStatus(State); - inventory.setUser(user); - inventory.setInventoryType(InventoryType.main.toString()); - MedicalInventory meInventory; - try { - meInventory = medicalInventoryManager.newMedicalInventory(inventory); - if (meInventory != null) { - MedicalInventoryRow currentInventoryRow; - for (Iterator iterator = inventoryRowSearchList.iterator(); iterator - .hasNext();) { - MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); - medicalInventoryRow.setInventory(meInventory); - Lot lot = medicalInventoryRow.getLot(); - if (lot != null && lot.getCode().equals("")) { - medicalInventoryRow.setLot(null); + chargeType = (MovementType) chargeComboBox.getSelectedItem(); + dischargeType = (MovementType) dischargeComboBox.getSelectedItem(); + supplier = (Supplier) supplierComboBox.getSelectedItem(); + destination = (Ward) destinationComboBox.getSelectedItem(); + if ((inventory == null) && (mode.equals("new"))) { + newReference = referenceTextField.getText().trim(); + boolean refExist; + refExist = medicalInventoryManager.referenceExists(newReference); + if (refExist) { + MessageDialog.error(null, "angal.inventory.referencealreadyused.msg"); + return; + } + inventory = new MedicalInventory(); + inventory.setInventoryReference(newReference); + inventory.setInventoryDate(dateInventory); + inventory.setStatus(state); + inventory.setUser(user); + inventory.setInventoryType(InventoryType.ward.toString()); + inventory.setChargeType(chargeType != null ? chargeType.getCode() : null); + inventory.setDischargeType(dischargeType != null ? dischargeType.getCode() : null); + inventory.setSupplier(supplier != null ? supplier.getSupId() : null); + inventory.setDestination(destination != null ? destination.getCode() : null); + inventory.setWard(wardSelected != null ? wardSelected.getCode() : null); + inventory = medicalInventoryManager.newMedicalInventory(inventory); + for (MedicalInventoryRow medicalInventoryRow : inventoryRowSearchList) { + medicalInventoryRow.setInventory(inventory); + Lot lot = medicalInventoryRow.getLot(); + String lotCode; + Medical medical = medicalInventoryRow.getMedical(); + if (lot != null) { + lotCode = lot.getCode(); + Lot lotExist; + lotExist = movStockInsertingManager.getLot(lotCode); + if (lotExist != null) { + Lot lotStore; + lotStore = movStockInsertingManager.updateLot(lot); + medicalInventoryRow.setLot(lotStore); + } else { + if (lot.getDueDate() != null) { + Lot lotStore; + lotStore = movStockInsertingManager.storeLot(lotCode, lot, medical); + medicalInventoryRow.setLot(lotStore); + medicalInventoryRow.setNewLot(true); + } else { + medicalInventoryRow.setLot(null); + } + } + } else { + medicalInventoryRow.setLot(null); + } + medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); + } + mode = "update"; + validateButton.setEnabled(true); + MessageDialog.info(this, "angal.inventory.savesuccess.msg"); + fireInventoryInserted(); + resetVariable(); + int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttocontinueediting.msg"); + if (info != JOptionPane.YES_OPTION) { + dispose(); + } + } else if ((inventory != null) && (mode.equals("update"))) { + String lastCharge = inventory.getChargeType(); + String lastDischarge = inventory.getDischargeType(); + Integer lastSupplier = inventory.getSupplier(); + String lastDestination = inventory.getDestination(); + String lastReference = inventory.getInventoryReference(); + newReference = referenceTextField.getText().trim(); + MedicalInventory existingInventory = medicalInventoryManager.getInventoryByReference(newReference); + if (existingInventory != null && !Objects.equals(existingInventory.getId(), inventory.getId())) { + MessageDialog.error(null, "angal.inventory.referencealreadyused.msg"); + return; + } + if (inventoryRowListAdded.isEmpty()) { + if ((destination != null && !destination.getCode().equals(lastDestination)) + || (chargeType != null && !chargeType.getCode().equals(lastCharge)) + || (dischargeType != null && !dischargeType.getCode().equals(lastDischarge)) + || (supplier != null && !supplier.getSupId().equals(lastSupplier)) || (destination == null && lastDestination != null) + || (chargeType == null && lastCharge != null) || (dischargeType == null && lastDischarge != null) + || (supplier == null && lastSupplier != null) || !lastReference.equals(newReference) + ) { + if (!inventory.getInventoryDate().equals(dateInventory)) { + inventory.setInventoryDate(dateInventory); + } + if (!inventory.getUser().equals(user)) { + inventory.setUser(user); + } + if (!lastReference.equals(newReference)) { + inventory.setInventoryReference(newReference); + } + MovementType charge = (MovementType) chargeComboBox.getSelectedItem(); + inventory.setChargeType(charge != null ? charge.getCode() : null); + + MovementType discharge = (MovementType) dischargeComboBox.getSelectedItem(); + inventory.setDischargeType(discharge != null ? discharge.getCode() : null); + + Supplier supplier1 = (Supplier) supplierComboBox.getSelectedItem(); + inventory.setSupplier(supplier1 != null ? supplier1.getSupId() : null); + + Ward destination = (Ward) destinationComboBox.getSelectedItem(); + inventory.setDestination(destination != null ? destination.getCode() : null); + + inventory = medicalInventoryManager.updateMedicalInventory(inventory); + if (inventory != null) { + MessageDialog.info(null, "angal.inventory.update.success.msg"); + resetVariable(); + fireInventoryUpdated(); + int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttocontinueediting.msg"); + if (info != JOptionPane.YES_OPTION) { + dispose(); + } + } else { + MessageDialog.error(null, "angal.inventory.update.error.msg"); + return; } - currentInventoryRow = medicalInventoryRowManager - .newMedicalInventoryRow(medicalInventoryRow); - if (currentInventoryRow == null) { - checkResults++; + } else { + if (!inventoryRowsToDelete.isEmpty()) { + MessageDialog.info(null, "angal.inventory.update.success.msg"); + resetVariable(); + fireInventoryUpdated(); + int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttocontinueediting.msg"); + if (info != JOptionPane.YES_OPTION) { + dispose(); + } + } else { + MessageDialog.info(null, "angal.inventory.inventoryisalreadysaved.msg"); + return; } } - if (checkResults == 0) { - // enable validation - mode = "update"; - MessageDialog.info(this, "angal.inventory.savesucces.msg"); - fireInventoryUpdated(); - closeButton.doClick(); + return; + } + if (!inventory.getInventoryDate().equals(dateInventory)) { + inventory.setInventoryDate(dateInventory); + } + if (!inventory.getUser().equals(user)) { + inventory.setUser(user); + } + if (!lastReference.equals(newReference)) { + inventory.setInventoryReference(newReference); + } + + MovementType charge = (MovementType) chargeComboBox.getSelectedItem(); + inventory.setChargeType(charge != null ? charge.getCode() : null); + + MovementType discharge = (MovementType) dischargeComboBox.getSelectedItem(); + inventory.setDischargeType(discharge != null ? discharge.getCode() : null); + + Supplier supplier1 = (Supplier) supplierComboBox.getSelectedItem(); + inventory.setSupplier(supplier1 != null ? supplier1.getSupId() : null); + + Ward destination = (Ward) destinationComboBox.getSelectedItem(); + inventory.setDestination(destination != null ? destination.getCode() : null); + + inventory = medicalInventoryManager.updateMedicalInventory(inventory); + + for (MedicalInventoryRow medicalInventoryRow : inventoryRowSearchList) { + Medical medical = medicalInventoryRow.getMedical(); + Lot lot = medicalInventoryRow.getLot(); + String lotCode; + medicalInventoryRow.setInventory(inventory); + int id = medicalInventoryRow.getId(); + if (id == 0) { + if (lot != null) { + lotCode = lot.getCode(); + boolean isExist; + Lot lotExist = movStockInsertingManager.getLot(lotCode); + isExist = (lotExist != null); + if (!isExist) { + if (lot.getDueDate() != null) { + Lot lotStore = movStockInsertingManager.storeLot(lotCode, lot, medical); + medicalInventoryRow.setLot(lotStore); + medicalInventoryRow.setNewLot(true); + } else { + Lot lotStore = movStockInsertingManager.updateLot(lot); + medicalInventoryRow.setLot(lotStore); + } + } else { + Lot lotStore = movStockInsertingManager.updateLot(lot); + medicalInventoryRow.setLot(lotStore); + } + } + medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); } else { - MessageDialog.error(null, "angal.inventory.error.msg"); + lot = medicalInventoryRow.getLot(); + double reatQty = medicalInventoryRow.getRealQty(); + medicalInventoryRow = medicalInventoryRowManager.getMedicalInventoryRowById(id); + medicalInventoryRow.setRealqty(reatQty); + + if (lot != null) { + lotCode = lot.getCode(); + Lot lotExist = movStockInsertingManager.getLot(lotCode); + if (lotExist != null) { + Lot lotStore; + lotExist.setDueDate(lot.getDueDate()); + lotExist.setPreparationDate(lot.getPreparationDate()); + lotExist.setCost(lot.getCost()); + lotStore = movStockInsertingManager.updateLot(lotExist); + medicalInventoryRow.setLot(lotStore); + } else { + if (lot.getDueDate() != null) { + Lot lotStore = movStockInsertingManager.storeLot(lotCode, lot, medical); + medicalInventoryRow.setLot(lotStore); + medicalInventoryRow.setNewLot(true); + } else { + medicalInventoryRow.setLot(null); + } + } + } else { + medicalInventoryRow.setLot(null); + } + if (medicalInventoryRow.getId() == 0) { + medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); + } else { + medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow); + } } - } else { - MessageDialog.error(null, "angal.inventory.error.msg"); } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); + MessageDialog.info(null, "angal.inventory.update.success.msg"); + resetVariable(); + fireInventoryUpdated(); + int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttocontinueediting.msg"); + if (info != JOptionPane.YES_OPTION) { + dispose(); + } } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); } }); return saveButton; @@ -427,35 +726,142 @@ private JButton getValidateButton() { validateButton = new JButton(MessageBundle.getMessage("angal.inventory.validate.btn")); validateButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.validate.btn.key")); + validateButton.setEnabled(inventory != null); + validateButton.addActionListener(actionEvent -> { + if (inventory == null) { + MessageDialog.error(null, "angal.inventory.inventorymustsavebeforevalidation.msg"); + return; + } + int reset = MessageDialog.yesNo(null, "angal.inventory.doyoureallywanttovalidatethisinventory.msg"); + if (reset == JOptionPane.YES_OPTION) { + String dischargeCode = inventory.getDischargeType(); + String chargeCode = inventory.getChargeType(); + Integer supplierId = inventory.getSupplier(); + String destinationCode = inventory.getDestination(); + if (chargeCode == null || chargeCode.isEmpty()) { + MessageDialog.error(null, "angal.inventory.choosechargetypebeforevalidation.msg"); + return; + } + if (dischargeCode == null || dischargeCode.isEmpty()) { + MessageDialog.error(null, "angal.inventory.choosedischargetypebeforevalidation.msg"); + return; + } + if (supplierId == null || supplierId == 0) { + MessageDialog.error(null, "angal.inventory.choosesupplierbeforevalidation.msg"); + return; + } + if (destinationCode == null || destinationCode.isEmpty()) { + MessageDialog.error(null, "angal.inventory.choosedestinationbeforevalidation.msg"); + return; + } + // validate inventory + int inventoryRowsSize = inventoryRowSearchList.size(); + try { + medicalInventoryManager.validateMedicalInventoryRow(inventory, inventoryRowSearchList); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + try { + jTableInventoryRow.setModel(new InventoryRowModel()); + adjustWidth(); + } catch (OHServiceException e1) { + OHServiceExceptionUtil.showMessages(e); + } + return; + } + String status = InventoryStatus.validated.toString(); + inventory.setStatus(status); + try { + inventory = medicalInventoryManager.updateMedicalInventory(inventory); + if (inventory != null) { + List invRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); + MessageDialog.info(null, "angal.inventory.validate.success.msg"); + if (invRows.size() > inventoryRowsSize) { + MessageDialog.error(null, "angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.msg"); + } + fireInventoryUpdated(); + statusLabel.setText(status.toUpperCase()); + statusLabel.setForeground(Color.BLUE); + } else { + MessageDialog.info(null, "angal.inventory.validate.error.msg"); + return; + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + return; + } + } + }); return validateButton; } - private JButton getCancelButton() { - cancelButton = new JButton(MessageBundle.getMessage("angal.common.cancel.btn")); - cancelButton.setMnemonic(MessageBundle.getMnemonic("angal.common.cancel.btn.key")); - cancelButton.addActionListener(actionEvent -> { - if (jTableInventoryRow.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); - return; + private JButton getCleanTableButton() { + resetButton = new JButton(MessageBundle.getMessage("angal.inventory.clean.btn")); + resetButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.clean.btn.key")); + resetButton.addActionListener(actionEvent -> { + int reset = MessageDialog.yesNo(null, "angal.inventory.doyoureallywanttocleanthistable.msg"); + if (reset == JOptionPane.YES_OPTION) { + if (inventory != null) { + for (MedicalInventoryRow invRow : inventoryRowSearchList) { + if (invRow.getId() != 0) { + inventoryRowsToDelete.add(invRow); + } + } + } + selectAll = false; + specificRadio.setSelected(true); + codeTextField.setEnabled(true); + inventoryRowSearchList.clear(); + DefaultTableModel model = (DefaultTableModel) jTableInventoryRow.getModel(); + model.setRowCount(0); + model.setColumnCount(0); + jTableInventoryRow.updateUI(); + adjustWidth(); } - int selectedRow = jTableInventoryRow.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); + }); + return resetButton; + } + + private JButton getDeleteButton() { + deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); + deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); + deleteButton.addActionListener(actionEvent -> { + int[] selectedRows = jTableInventoryRow.getSelectedRows(); + if (selectedRows.length == 0) { + MessageDialog.error(this, "angal.inventoryrow.pleaseselectatleastoneinventoryrow.msg"); return; } - MedicalInventoryRow selectedInventory = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRow, - -1); - int delete = MessageDialog.yesNo(null, "angal.inventoryrow.doyoureallywanttodeletethisinventoryrow.msg"); + int delete = MessageDialog.yesNo(null, "angal.inventory.doyoureallywanttodeletethisinventoryrow.msg"); if (delete == JOptionPane.YES_OPTION) { - if (selectedInventory.getInventory() == null) { - inventoryRowSearchList.remove(selectedRow); + if (selectedRows.length == inventoryRowSearchList.size()) { + resetButton.doClick(); + return; + } + DefaultTableModel model = (DefaultTableModel) jTableInventoryRow.getModel(); + if (inventory == null) { + for (int i = selectedRows.length - 1; i >= 0; i--) { + MedicalInventoryRow selectedInventoryRow = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRows[i], -1); + inventoryRowSearchList.remove(selectedInventoryRow); + model.fireTableDataChanged(); + jTableInventoryRow.setModel(model); + } + } else { + for (int i = selectedRows.length - 1; i >= 0; i--) { + MedicalInventoryRow inventoryRow = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRows[i], -1); + inventoryRowSearchList.remove(inventoryRow); + model.fireTableDataChanged(); + jTableInventoryRow.setModel(model); + if (inventoryRow.getId() != 0) { + inventoryRowsToDelete.add(inventoryRow); + } + } } + jTableInventoryRow.clearSelection(); + adjustWidth(); } else { return; } - jTableInventoryRow.updateUI(); }); - return cancelButton; + return deleteButton; } private JButton getPrintButton() { @@ -467,11 +873,46 @@ private JButton getPrintButton() { private JButton getCloseButton() { closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - dispose(); + closeButton.addActionListener(actionEvent -> { + String lastCharge = null; + String lastDischarge = null; + Integer lastSupplier = null; + String lastDestination = null; + String lastReference = null; + newReference = referenceTextField.getText().trim(); + LocalDateTime lastDate = dateInventory; + if (inventory != null) { + lastCharge = inventory.getChargeType(); + lastDischarge = inventory.getDischargeType(); + lastSupplier = inventory.getSupplier(); + lastDestination = inventory.getDestination(); + lastReference = inventory.getInventoryReference(); + lastDate = inventory.getInventoryDate(); } + if (!inventoryRowsToDelete.isEmpty() || (destination != null && !destination.getCode().equals(lastDestination)) + || (chargeType != null && !chargeType.getCode().equals(lastCharge)) + || (dischargeType != null && !dischargeType.getCode().equals(lastDischarge)) + || (supplier != null && !supplier.getSupId().equals(lastSupplier)) + || (destination == null && lastDestination != null) || (chargeType == null && lastCharge != null) + || (dischargeType == null && lastDischarge != null) || (supplier == null && lastSupplier != null) + || !Objects.equals(lastReference, newReference) || !lastDate.toLocalDate().equals(dateInventory.toLocalDate()) + ) { + int reset = MessageDialog.yesNoCancel(null, "angal.inventory.doyouwanttosavethechanges.msg"); + if (reset == JOptionPane.YES_OPTION) { + this.saveButton.doClick(); + } + if (reset == JOptionPane.NO_OPTION) { + resetVariable(); + dispose(); + } else { + resetVariable(); + return; + } + } else { + resetVariable(); + dispose(); + } }); return closeButton; } @@ -479,92 +920,99 @@ public void actionPerformed(ActionEvent e) { private JScrollPane getScrollPaneInventory() { if (scrollPaneInventory == null) { scrollPaneInventory = new JScrollPane(); - scrollPaneInventory.setViewportView(getJTableInventoryRow()); + try { + scrollPaneInventory.setViewportView(getJTableInventoryRow()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } } return scrollPaneInventory; } - private JTable getJTableInventoryRow() { + private JTable getJTableInventoryRow() throws OHServiceException { if (jTableInventoryRow == null) { jTableInventoryRow = new JTable(); - jTetFieldEditor = new JTextField(); + jTextFieldEditor = new JTextField(); jTableInventoryRow.setFillsViewportHeight(true); jTableInventoryRow.setModel(new InventoryRowModel()); + for (int i = 0; i < pColumnVisible.length; i++) { + jTableInventoryRow.getColumnModel().getColumn(i).setCellRenderer(new EnabledTableCellRenderer()); + jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(pColumwidth[i]); + if (i == 0 || !pColumnVisible[i]) { + jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(0); + jTableInventoryRow.getColumnModel().getColumn(i).setMaxWidth(0); + jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(0); + } + } + DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); + centerRenderer.setHorizontalAlignment(JLabel.CENTER); + jTableInventoryRow.getColumnModel().getColumn(3).setCellRenderer(centerRenderer); jTableInventoryRow.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), 5); - jTetFieldEditor.selectAll(); + if (e.getValueIsAdjusting()) { + jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), jTableInventoryRow.getSelectedColumn()); } - } }); - jTableInventoryRow.getModel().addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - - if (e.getType() == TableModelEvent.UPDATE) { - int row = e.getFirstRow(); - int column = e.getColumn(); - TableModel model = (TableModel) e.getSource(); - Object data = model.getValueAt(row, column); - - if (column == 2) { - Object data2 = model.getValueAt(row, 3); - if (!data.toString().equals("") && data2.toString().equals("")) { - jTableInventoryRow.setSurrendersFocusOnKeystroke(true); - jTableInventoryRow.getEditorComponent().requestFocus(); - return; - } - } - - if (column == 3) { - Object data2 = model.getValueAt(row, 2); - if (!data.toString().equals("") && data2.toString().equals("")) { - jTableInventoryRow.setSurrendersFocusOnKeystroke(true); - jTableInventoryRow.getEditorComponent().requestFocus(); - return; - } - } - } - } - }); - DefaultCellEditor cellEditor = new DefaultCellEditor(jTetFieldEditor); + DefaultCellEditor cellEditor = new DefaultCellEditor(jTextFieldEditor); jTableInventoryRow.setDefaultEditor(Integer.class, cellEditor); } return jTableInventoryRow; } + static class EnabledTableCellRenderer extends DefaultTableCellRenderer { + private static final long serialVersionUID = 1L; + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } + } + class InventoryRowModel extends DefaultTableModel { private static final long serialVersionUID = 1L; - public InventoryRowModel() { - if (allRadio.isSelected()) { - try { - inventoryRowList = loadNewInventoryTable(null); - } catch (OHServiceException e) { - inventoryRowList = new ArrayList<>(); - OHServiceExceptionUtil.showMessages(e); + public InventoryRowModel(boolean add) throws OHServiceException { + inventoryRowList = loadNewInventoryTable(null, inventory, add); + if (!inventoryRowList.isEmpty()) { + for (MedicalInventoryRow inventoryRow : inventoryRowList) { + addMedInRowInInventorySearchList(inventoryRow); } - } else if (specificRadio.isSelected() && code != null && !code.trim().equals("")) { - try { - inventoryRowList = loadNewInventoryTable(code.trim()); - } catch (OHServiceException e) { - inventoryRowList = new ArrayList<>(); - OHServiceExceptionUtil.showMessages(e); + selectAll = true; + MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg"); + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } + public InventoryRowModel() throws OHServiceException { + if (!inventoryRowSearchList.isEmpty()) { + inventoryRowSearchList.clear(); + } + if (inventory != null) { + inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); + } else { + if (allRadio.isSelected()) { + inventoryRowList = loadNewInventoryTable(null, inventory, false); + } + } + if (inventoryRowList != null && !inventoryRowList.isEmpty()) { + for (MedicalInventoryRow inventoryRow : inventoryRowList) { + addMedInRowInInventorySearchList(inventoryRow); + if (inventoryRow.getId() == 0) { + inventoryRowListAdded.add(inventoryRow); + } } } - - inventoryRowSearchList = inventoryRowList; } public Class getColumnClass(int c) { if (c == 0) { - return String.class; + return Integer.class; } else if (c == 1) { return String.class; } else if (c == 2) { @@ -572,13 +1020,15 @@ public Class getColumnClass(int c) { } else if (c == 3) { return String.class; } else if (c == 4) { - return Double.class; + return String.class; } else if (c == 5) { return Double.class; } else if (c == 6) { - return Double.class; + return Integer.class; } else if (c == 7) { return Double.class; + } else if (c == 8) { + return Double.class; } return null; } @@ -599,43 +1049,46 @@ public int getColumnCount() { } public Object getValueAt(int r, int c) { - MedicalInventoryRow medInvtRow = inventoryRowSearchList.get(r); - - if (c == -1) { - return medInvtRow; - } else if (c == 0) { - return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getProdCode(); - } else if (c == 1) { - return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription(); - } else if (c == 2) { - return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode(); - } else if (c == 3) { - if (medInvtRow.getLot() != null) { - if (medInvtRow.getLot().getDueDate() != null) { - return medInvtRow.getLot().getDueDate().format(DATE_TIME_FORMATTER); + if (r < inventoryRowSearchList.size()) { + MedicalInventoryRow medInvtRow = inventoryRowSearchList.get(r); + + if (c == -1) { + return medInvtRow; + } else if (c == 0) { + return medInvtRow.getId(); + } else if (c == 1) { + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getProdCode(); + } else if (c == 2) { + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription(); + } else if (c == 3) { + return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode(); + } else if (c == 4) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getDueDate() != null) { + return medInvtRow.getLot().getDueDate().format(DATE_TIME_FORMATTER); + } } - } - return ""; - } else if (c == 4) { - Double dblVal = medInvtRow.getTheoreticQty(); - return dblVal; - } else if (c == 5) { - Double dblValue = medInvtRow.getRealQty(); - return dblValue; - } else if (c == 6) { - if (medInvtRow.getLot() != null) { - if (medInvtRow.getLot().getCost() != null) { - return medInvtRow.getLot().getCost(); + return ""; + } else if (c == 5) { + return medInvtRow.getTheoreticQty(); + } else if (c == 6) { + double dblValue = medInvtRow.getRealQty(); + return (int) dblValue; + } else if (c == 7) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getCost() != null) { + return medInvtRow.getLot().getCost(); + } } - } - return 0.0; - } else if (c == 7) { - if (medInvtRow.getLot() != null) { - if (medInvtRow.getLot().getCost() != null) { - return medInvtRow.getRealQty() * medInvtRow.getLot().getCost().doubleValue(); + return 0.0; + } else if (c == 8) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getCost() != null) { + return medInvtRow.getRealQty() * medInvtRow.getLot().getCost().doubleValue(); + } } + return 0.0; } - return 0.0; } return null; } @@ -644,41 +1097,30 @@ public Object getValueAt(int r, int c) { public void setValueAt(Object value, int r, int c) { if (r < inventoryRowSearchList.size()) { MedicalInventoryRow invRow = inventoryRowSearchList.get(r); - if (c == 5) { - Integer intValue = 0; - try { - intValue = Integer.parseInt(value.toString()); - } catch (NumberFormatException e) { - intValue = 0; + if (c == 6) { + int intValue = 0; + if (value != null) { + try { + intValue = Integer.parseInt(value.toString()); + } catch (NumberFormatException e) { + return; + } + } + if (intValue < 0) { + MessageDialog.error(null, "angal.inventory.invalidquantity.msg"); + return; } invRow.setRealqty(intValue); - inventoryRowSearchList.set(r, invRow); - jTableInventoryRow.updateUI(); - } - if (c == 6) { - Double doubleValue = 0.0; - try { - doubleValue = Double.parseDouble(value.toString()); - } catch (NumberFormatException e) { - doubleValue = 0.0; - } - Lot lot = invRow.getLot(); - if (lot != null) { - if (lot.getCode().equals("")) { - MessageDialog.error(null, "angal.inventoryrow.cannotchangethepriceofproductwithoutlot.msg"); - } else { - lot.setCost(new BigDecimal(doubleValue)); - try { - Lot saveLot = movStockInsertingManager.updateLot(lot); - invRow.setLot(saveLot); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } + if (invRow.getLot() != null && invRow.getLot().getCost() != null) { + double total = invRow.getRealQty() * invRow.getLot().getCost().doubleValue(); + invRow.setTotal(total); } + inventoryRowListAdded.add(invRow); inventoryRowSearchList.set(r, invRow); - jTableInventoryRow.updateUI(); + SwingUtilities.invokeLater(() -> { + jTableInventoryRow.updateUI(); + }); } } } @@ -689,10 +1131,40 @@ public boolean isCellEditable(int rowIndex, int columnIndex) { } } - private List loadNewInventoryTable(String code) throws OHServiceException { + private List loadNewInventoryTable(String code, MedicalInventory inventory, boolean add) throws OHServiceException { + List inventoryRowsList; + if (inventory != null) { + int id = inventory.getId(); + inventoryRowsList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(id); + if (add) { + inventoryRowsList = getMedicalInventoryRows(code); + } + } else { + inventoryRowsList = getMedicalInventoryRows(code); + } + return inventoryRowsList; + } + + private void adjustWidth() { + for (int i = 0; i < jTableInventoryRow.getColumnModel().getColumnCount(); i++) { + jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(pColumwidth[i]); + if (i == 0 || !pColumnVisible[i]) { + jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(0); + jTableInventoryRow.getColumnModel().getColumn(i).setMaxWidth(0); + jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(0); + } + } + DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); + centerRenderer.setHorizontalAlignment(JLabel.CENTER); + jTableInventoryRow.getColumnModel().getColumn(3).setCellRenderer(centerRenderer); + } + + private List getMedicalInventoryRows(String code) throws OHServiceException { List inventoryRowsList = new ArrayList<>(); List medicalWardList = new ArrayList<>(); - Medical medical = null; + List lots; + Medical medical; + MedicalInventoryRow inventoryRowTemp; if (code != null) { medical = medicalBrowsingManager.getMedicalByMedicalCode(code); if (medical != null) { @@ -703,56 +1175,58 @@ private List loadNewInventoryTable(String code) throws OHSe } else { medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); } - medicalWardList.stream().forEach(medicalWard -> { - inventoryRowsList.add(new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, - medicalWard.getMedical(), medicalWard.getLot())); - }); + medicalWardList.forEach(medicalWard -> inventoryRowsList.add(new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, + medicalWard.getMedical(), medicalWard.getLot()))); + for (MedicalWard medicalWard : medicalWardList) { + lots = movStockInsertingManager.getLotByMedical(medicalWard.getMedical(), false); + double actualQty = medicalWard.getMedical().getInitialqty() + medicalWard.getMedical().getInqty() - medicalWard.getMedical().getOutqty(); + if (lots.isEmpty()) { + inventoryRowTemp = new MedicalInventoryRow(0, actualQty, actualQty, null, medicalWard.getMedical(), null); + if (!existInInventorySearchList(inventoryRowTemp)) { + inventoryRowsList.add(inventoryRowTemp); + } + } else { + for (Lot lot : lots) { + inventoryRowTemp = new MedicalInventoryRow(0, lot.getMainStoreQuantity(), lot.getMainStoreQuantity(), null, medicalWard.getMedical(), lot); + if (!existInInventorySearchList(inventoryRowTemp)) { + inventoryRowsList.add(inventoryRowTemp); + } + } + } + } return inventoryRowsList; } - class DecimalFormatRenderer extends DefaultTableCellRenderer { - - private static final long serialVersionUID = 1L; - private final DecimalFormat formatter = new DecimalFormat("#,##0.00"); //$NON-NLS-1$ - - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, - int row, int column) { - // First format the cell value as required - Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - value = formatter.format((Number) value); - // setHorizontalAlignment(columnAlignment[column]); - if (!columnEditable[column]) { - cell.setBackground(Color.LIGHT_GRAY); + private boolean existInInventorySearchList(MedicalInventoryRow inventoryRow) { + boolean found = false; + List invRows = inventoryRowSearchList.stream() + .filter(inventoryRow1 -> inventoryRow1.getMedical().getCode().equals(inventoryRow.getMedical().getCode())).toList(); + if (!invRows.isEmpty()) { + for (MedicalInventoryRow invR: invRows) { + if (inventoryRow.getLot() != null && invR.getLot() != null) { + if (inventoryRow.getLot().getCode().equals(invR.getLot().getCode())) { + found = true; + break; + } + } else { + if (invR.getLot() == null && inventoryRow.getLot() == null) { + found = true; + break; + } + } } - - // And pass it on to parent class - return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } + return found; } private JRadioButton getSpecificRadio() { if (specificRadio == null) { specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); - if (inventory != null) { - specificRadio.setSelected(false); - } else { - specificRadio.setSelected(true); - } specificRadio.addActionListener(actionEvent -> { - if (specificRadio.isSelected()) { codeTextField.setEnabled(true); - searchTextField.setEnabled(false); - searchTextField.setText(""); codeTextField.setText(""); - if (inventoryRowList != null) { - inventoryRowList.clear(); - } - if (inventoryRowSearchList != null) { - inventoryRowSearchList.clear(); - } - jTableInventoryRow.updateUI(); - ajustWidth(); + allRadio.setSelected(false); } }); } @@ -762,74 +1236,58 @@ private JRadioButton getSpecificRadio() { private JRadioButton getAllRadio() { if (allRadio == null) { allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); - if (inventory != null) { - allRadio.setSelected(true); - } else { - allRadio.setSelected(false); - } + allRadio.setSelected(inventory != null); + specificRadio.setSelected(inventory == null); allRadio.addActionListener(actionEvent -> { - if (allRadio.isSelected()) { - codeTextField.setEnabled(false); - searchTextField.setText(""); - codeTextField.setText(""); - searchTextField.setEnabled(true); - if (inventoryRowList != null) { - inventoryRowList.clear(); - } - if (inventoryRowSearchList != null) { - inventoryRowSearchList.clear(); + if (!selectAll) { + if (allRadio.isSelected()) { + codeTextField.setEnabled(false); + codeTextField.setText(""); + if (!inventoryRowSearchList.isEmpty()) { + int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttoaddallnotyetlistedproducts.msg"); + if (info == JOptionPane.YES_OPTION) { + try { + allRadio.setSelected(true); + jTableInventoryRow.setModel(new InventoryRowModel(true)); + } catch (OHServiceException e){ + OHServiceExceptionUtil.showMessages(e); + } + } else { + allRadio.setSelected(false); + specificRadio.setEnabled(true); + selectAll = false; + } + } else { + if (mode.equals("update")) { + try { + allRadio.setEnabled(true); + jTableInventoryRow.setModel(new InventoryRowModel(true)); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } else { + try { + jTableInventoryRow.setModel(new InventoryRowModel()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + } + if (inventory != null && !inventory.getStatus().equals(InventoryStatus.draft.toString())) { + inventory.setStatus(InventoryStatus.draft.toString()); + } + fireInventoryUpdated(); + code = null; + adjustWidth(); } - jTableInventoryRow.setModel(new InventoryRowModel()); - jTableInventoryRow.updateUI(); - code = null; - ajustWidth(); + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); } }); } return allRadio; } - private JTextField getSearchTextField() { - if (searchTextField == null) { - searchTextField = new JTextField(); - searchTextField.setColumns(16); - TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.search.txt"), searchTextField, - Show.FOCUS_LOST); - suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); - suggestion.setForeground(Color.GRAY); - suggestion.setHorizontalAlignment(JLabel.CENTER); - suggestion.changeAlpha(0.5f); - suggestion.changeStyle(Font.BOLD + Font.ITALIC); - searchTextField.getDocument().addDocumentListener(new DocumentListener() { - - @Override - public void insertUpdate(DocumentEvent e) { - filterInventoryRow(); - ajustWidth(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - filterInventoryRow(); - ajustWidth(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - filterInventoryRow(); - ajustWidth(); - } - }); - searchTextField.setEnabled(false); - if (inventory != null) { - searchTextField.setEnabled(true); - } else { - searchTextField.setEnabled(false); - } - } - return searchTextField; - } - private JLabel getDateInventoryLabel() { if (dateInventoryLabel == null) { dateInventoryLabel = new JLabel(MessageBundle.getMessage("angal.inventory.date.label")); @@ -840,14 +1298,9 @@ private JLabel getDateInventoryLabel() { private JTextField getCodeTextField() { if (codeTextField == null) { codeTextField = new JTextField(); - if (inventory != null) { - codeTextField.setEnabled(false); - } else { - codeTextField.setEnabled(true); - } + codeTextField.setEnabled(inventory == null); codeTextField.setColumns(10); - TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.code.txt"), codeTextField, - Show.FOCUS_LOST); + TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.code.txt"), codeTextField, Show.FOCUS_LOST); suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); suggestion.setForeground(Color.GRAY); suggestion.setHorizontalAlignment(JLabel.CENTER); @@ -864,8 +1317,10 @@ public void keyPressed(KeyEvent e) { } catch (OHServiceException e1) { OHServiceExceptionUtil.showMessages(e1); } + if (inventory != null && !inventory.getStatus().equals(InventoryStatus.draft.toString())) { + inventory.setStatus(InventoryStatus.draft.toString()); + } codeTextField.setText(""); - ajustWidth(); } } }); @@ -873,27 +1328,13 @@ public void keyPressed(KeyEvent e) { return codeTextField; } - private void filterInventoryRow() { - String s = searchTextField.getText(); - s.trim(); - inventoryRowSearchList = new ArrayList(); - for (MedicalInventoryRow invRow : inventoryRowList) { - if (!s.equals("")) { - String name = invRow.getSearchString(); - if (name.contains(s.toLowerCase())) - inventoryRowSearchList.add(invRow); - } else { - inventoryRowSearchList.add(invRow); - } - } - jTableInventoryRow.updateUI(); - searchTextField.requestFocus(); - } - private void addInventoryRow(String code) throws OHServiceException { - List inventoryRowsList = new ArrayList(); + List inventoryRowsList; List medicalWardList = new ArrayList(); - Medical medical = null; + Medical medical; + if (wardId.isEmpty()) { + wardId = ((Ward) Objects.requireNonNull(wardComboBox.getSelectedItem())).getCode(); + } if (code != null) { medical = medicalBrowsingManager.getMedicalByMedicalCode(code); if (medical != null) { @@ -917,52 +1358,34 @@ private void addInventoryRow(String code) throws OHServiceException { } else { medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); } - if (mode.equals("new")) { - inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), - medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); - } else if (mode.equals("update")) { - if (medical != null) { - String medicalCode = medical.getProdCode(); - inventoryRowsList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()) - .stream() - .filter(medRow -> medRow.getMedical().getProdCode().equals(medicalCode)).toList(); - } - } + inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), + medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); if (inventoryRowSearchList == null) { inventoryRowSearchList = new ArrayList<>(); } - for (MedicalInventoryRow inventoryRow : inventoryRowsList) { - inventoryRowSearchList.add(inventoryRow); - } + + inventoryRowsList.forEach(this::addMedInRowInInventorySearchList); jTableInventoryRow.updateUI(); } private Medical chooseMedical(String text) throws OHServiceException { Map medicalMap; - List medicals = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false).stream() - .map(medicalWard -> medicalWard.getMedical()).toList(); - if (mode.equals("update")) { - medicals.clear(); - List inventoryRowListTemp = medicalInventoryRowManager - .getMedicalInventoryRowByInventoryId(inventory.getId()); - for (MedicalInventoryRow medicalInventoryRow : inventoryRowListTemp) { - medicals.add(medicalInventoryRow.getMedical()); - } - } - medicalMap = new HashMap(); + List medicals = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false).stream().map(MedicalWard::getMedical).toList(); + + medicalMap = new HashMap<>(); for (Medical med : medicals) { - String key = med.getProdCode().toLowerCase(); + String key; key = med.getCode().toString().toLowerCase(); medicalMap.put(key, med); } - ArrayList medList = new ArrayList(); + ArrayList medList = new ArrayList<>(); for (Medical aMed : medicalMap.values()) { if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { medList.add(aMed); } } Collections.sort(medList); - Medical med = null; + Medical med; if (!medList.isEmpty()) { MedicalPicker framas = new MedicalPicker(new StockMedModel(medList), medList); framas.setSize(300, 400); @@ -982,11 +1405,6 @@ private Medical chooseMedical(String text) throws OHServiceException { return null; } - private void ajustWidth() { - for (int i = 0; i < pColumwidth.length; i++) { - jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); - } - } private JLabel getReferenceLabel() { if (referenceLabel == null) { @@ -1007,6 +1425,33 @@ private JTextField getReferenceTextField() { return referenceTextField; } + private JLabel getStatusLabel() { + if (statusLabel == null) { + if (inventory == null) { + String currentStatus = InventoryStatus.draft.toString().toUpperCase(); + statusLabel = new JLabel(currentStatus); + statusLabel.setForeground(Color.GRAY); + } else { + String currentStatus = inventory.getStatus().toUpperCase(); + statusLabel = new JLabel(currentStatus); + if (currentStatus.equalsIgnoreCase(InventoryStatus.draft.toString())) { + statusLabel.setForeground(Color.GRAY); + } + if (currentStatus.equalsIgnoreCase(InventoryStatus.validated.toString())) { + statusLabel.setForeground(Color.BLUE); + } + if (currentStatus.equalsIgnoreCase(InventoryStatus.canceled.toString())) { + statusLabel.setForeground(Color.RED); + } + if (currentStatus.equalsIgnoreCase(InventoryStatus.done.toString())) { + statusLabel.setForeground(Color.GREEN); + } + } + statusLabel.setFont(new Font(statusLabel.getFont().getName(), Font.BOLD, statusLabel.getFont().getSize() + 8)); + } + return statusLabel; + } + private JLabel getWardLabel() { if (wardLabel == null) { wardLabel = new JLabel(MessageBundle.getMessage("angal.inventory.selectward.label")); @@ -1014,9 +1459,37 @@ private JLabel getWardLabel() { return wardLabel; } + private JLabel getChargeLabel() { + if (chargeLabel == null) { + chargeLabel = new JLabel(MessageBundle.getMessage("angal.inventory.chargetype.label")); + } + return chargeLabel; + } + + private JLabel getDischargeLabel() { + if (dischargeLabel == null) { + dischargeLabel = new JLabel(MessageBundle.getMessage("angal.inventory.dischargetype.label")); + } + return dischargeLabel; + } + + private JLabel getSupplierLabel() { + if (supplierLabel == null) { + supplierLabel = new JLabel(MessageBundle.getMessage("angal.inventory.supplier.label")); + } + return supplierLabel; + } + + private JLabel getDestinationLabel() { + if (destinationLabel == null) { + destinationLabel = new JLabel(MessageBundle.getMessage("angal.inventory.destination.label")); + } + return destinationLabel; + } + private JComboBox getWardComboBox() { if (wardComboBox == null) { - wardComboBox = new JComboBox(); + wardComboBox = new JComboBox<>(); List wardList; try { wardList = wardBrowserManager.getWards(); @@ -1024,13 +1497,25 @@ private JComboBox getWardComboBox() { wardList = new ArrayList<>(); OHServiceExceptionUtil.showMessages(e); } - for (Ward elem : wardList) { - wardComboBox.addItem(elem); + if (!mode.equals("new")) { + String wardId = inventory.getWard(); + for (Ward ward : wardList) { + if (ward.getCode().equals(wardId)) { + wardComboBox.addItem(ward); + wardSelected = ward; + } + } + wardComboBox.setEnabled(false); + } else { + for (Ward elem : wardList) { + wardComboBox.addItem(elem); + } + wardComboBox.setSelectedIndex(-1); } - wardComboBox.setSelectedIndex(-1); wardComboBox.addItemListener(itemEvent -> { + if (itemEvent.getStateChange() == ItemEvent.SELECTED) { Object item = itemEvent.getItem(); if (item instanceof Ward) { @@ -1050,7 +1535,6 @@ private JComboBox getWardComboBox() { } else { MessageDialog.error(this, "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); - return; } } } @@ -1059,22 +1543,134 @@ private JComboBox getWardComboBox() { return wardComboBox; } + private JComboBox getChargeComboBox() { + MovementType movementSelected = null; + if (chargeComboBox == null) { + chargeComboBox = new JComboBox<>(); + try { + List movementTypes = medStockMovTypeManager.getMedicalDsrStockMovementType(); + chargeComboBox.addItem(null); + for (MovementType movementType: movementTypes) { + if (movementType.getType().equals("+")) { + chargeComboBox.addItem(movementType); + if (inventory != null && movementType.getCode().equals(inventory.getChargeType())) { + movementSelected = movementType; + } + } + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + if (inventory != null) { + chargeComboBox.setSelectedItem(movementSelected); + chargeType = movementSelected; + } + chargeComboBox.addActionListener(actionEvent -> { + chargeType = (MovementType) chargeComboBox.getSelectedItem(); + }); + } + return chargeComboBox; + } + + private JComboBox getDischargeComboBox() { + MovementType movementSelected = null; + if (dischargeComboBox == null) { + dischargeComboBox = new JComboBox<>(); + try { + List movementTypes = medStockMovTypeManager.getMedicalDsrStockMovementType(); + dischargeComboBox.addItem(null); + for (MovementType movementType: movementTypes) { + if (movementType.getType().equals("-")) { + dischargeComboBox.addItem(movementType); + if (inventory != null && movementType.getCode().equals(inventory.getDischargeType())) { + movementSelected = movementType; + } + } + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + if (inventory != null) { + dischargeComboBox.setSelectedItem(movementSelected); + dischargeType = movementSelected; + } + dischargeComboBox.addActionListener(actionEvent -> { + dischargeType = (MovementType) dischargeComboBox.getSelectedItem(); + }); + } + return dischargeComboBox; + } + + private JComboBox getSupplierComboBox() { + Supplier supplierSelected = null; + if (supplierComboBox == null) { + supplierComboBox = new JComboBox<>(); + try { + List suppliers = supplierBrowserManager.getList(); + supplierComboBox.addItem(null); + for (Supplier supplier1: suppliers) { + supplierComboBox.addItem(supplier1); + if (inventory != null && Objects.equals(supplier1.getSupId(), inventory.getSupplier())) { + supplierSelected = supplier1; + } + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + if (inventory != null) { + supplierComboBox.setSelectedItem(supplierSelected); + supplier = supplierSelected; + } + supplierComboBox.addActionListener(actionEvent -> { + supplier = (Supplier) supplierComboBox.getSelectedItem(); + }); + } + return supplierComboBox; + } + + private JComboBox getDestinationComboBox() { + Ward destinationSelected = null; + if (destinationComboBox == null) { + destinationComboBox = new JComboBox<>(); + try { + List wards = wardBrowserManager.getWards(); + destinationComboBox.addItem(null); + for (Ward ward: wards) { + destinationComboBox.addItem(ward); + if (inventory != null && ward.getCode().equals(inventory.getDestination())) { + destinationSelected = ward; + } + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + if (inventory != null) { + destinationComboBox.setSelectedItem(destinationSelected); + destination = destinationSelected; + } + destinationComboBox.addActionListener(actionEvent -> { + destination = (Ward) destinationComboBox.getSelectedItem(); + }); + } + return destinationComboBox; + } + private void disabledSomeComponents() { jCalendarInventory.setEnabled(false); - searchTextField.setEnabled(false); specificRadio.setEnabled(false); codeTextField.setEnabled(false); allRadio.setEnabled(false); referenceTextField.setEnabled(false); jTableInventoryRow.setEnabled(false); saveButton.setEnabled(false); - validateButton.setEnabled(false); - printButton.setEnabled(false); + chargeComboBox.setEnabled(false); + dischargeComboBox.setEnabled(false); + supplierComboBox.setEnabled(false); + destinationComboBox.setEnabled(false); } private void activedSomeComponents() { jCalendarInventory.setEnabled(true); - searchTextField.setEnabled(true); specificRadio.setEnabled(true); codeTextField.setEnabled(true); allRadio.setEnabled(true); @@ -1082,6 +1678,10 @@ private void activedSomeComponents() { jTableInventoryRow.setEnabled(true); wardComboBox.setEnabled(false); saveButton.setEnabled(true); + chargeComboBox.setEnabled(true); + dischargeComboBox.setEnabled(true); + supplierComboBox.setEnabled(true); + destinationComboBox.setEnabled(true); } private JLabel getLoaderLabel() { @@ -1093,4 +1693,34 @@ private JLabel getLoaderLabel() { } return loaderLabel; } + + private void addMedInRowInInventorySearchList(MedicalInventoryRow inventoryRow) { + int position = getPosition(inventoryRow); + if (position == -1) { + position = inventoryRowSearchList.size(); + inventoryRowSearchList.add(position, inventoryRow); + } else { + inventoryRowSearchList.add(position + 1, inventoryRow); + } + if (inventoryRow.getId() == 0) { + inventoryRowListAdded.add(inventoryRow); + } + } + + private int getPosition(MedicalInventoryRow inventoryRow) { + int position = -1; + int i = 0; + for (MedicalInventoryRow inventoryRow1 : inventoryRowSearchList) { + if (inventoryRow1.getMedical().getCode().equals(inventoryRow.getMedical().getCode())) { + position = i; + } + i++; + } + return position; + } + + private void resetVariable() { + inventoryRowsToDelete.clear(); + inventoryRowListAdded.clear(); + } } diff --git a/src/main/java/org/isf/utils/jobjects/InventoryStatus.java b/src/main/java/org/isf/utils/jobjects/InventoryStatus.java index 1a81bf0e80..118ed93479 100644 --- a/src/main/java/org/isf/utils/jobjects/InventoryStatus.java +++ b/src/main/java/org/isf/utils/jobjects/InventoryStatus.java @@ -22,5 +22,5 @@ package org.isf.utils.jobjects; public enum InventoryStatus { - draft, validated, canceled; + draft, validated, canceled, done; } \ No newline at end of file From adc7d6ad17bf7afa57a92a5279106f25473a3679 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Thu, 14 Nov 2024 09:30:09 +0100 Subject: [PATCH 20/83] Applying suggestion for change --- bundle/language_en.properties | 7 ++++--- .../org/isf/medicalinventory/gui/InventoryWardEdit.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index c7c547c4f8..e4bbe9ce29 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -665,7 +665,7 @@ angal.hospital.visitduration.txt angal.hospital.visitendhour.txt = Visit end hour angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. -angal.invetory.allmedicaladdedsuccessfully.msg = All medical are added successfully. +angal.invetory.allmedicaladdedsuccessfully.msg = All medicals are added successfully. angal.inventory.allproduct.radio = All products angal.inventory.canceled = Canceled angal.inventory.cancelednoteditable.msg = A canceled inventory can not be modified. @@ -691,11 +691,11 @@ angal.inventory.doyouwanttoaddallnotyetlistedproducts.msg angal.inventory.doyouwanttocontinueediting.msg = Do you want to continue editing? angal.inventory.doyouwanttosavethechanges.msg = Do you want to save the changes? angal.inventory.draft = Draft -angal.inventory.editinventory.title = Edit inventory +angal.inventory.edit.title = Edit Inventory angal.inventory.error.msg = Error during some products's recording angal.inventory.id.col = Id angal.inventory.invalidquantity.msg = Invalid quantity. -angal.inventory.inventoryisalreadysaved.msg = This inventory is already saved. Please enter at least one inventory row before continue. +angal.inventory.inventoryisalreadysaved.msg = This inventory is already saved. Please enter at least one inventory row before continuing. angal.inventory.inventorymustsavebeforevalidation.msg = Inventory must be saved before validation. angal.inventory.lotcode.col = Lot's code angal.inventory.managementward.title = Manage Ward Inventory @@ -706,6 +706,7 @@ angal.inventory.newinventory.title angal.inventory.noproduct.msg = Product is not found. angal.inventory.noproductfound.msg = No medical found angal.inventory.notdateinfuture.msg = A date in the future is not allowed. +angal.inventory.pleaseselectatleastoneinventoryrow.msg = Please select at least one inventory row. angal.inventory.pleaseselectonlyoneinventory.msg = Please select only one inventory. angal.inventory.pleaseselectinventory.msg = Please select inventory. angal.inventory.previousarrow.btn = < diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 8eef807ece..ddb7e76ef5 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -827,7 +827,7 @@ private JButton getDeleteButton() { deleteButton.addActionListener(actionEvent -> { int[] selectedRows = jTableInventoryRow.getSelectedRows(); if (selectedRows.length == 0) { - MessageDialog.error(this, "angal.inventoryrow.pleaseselectatleastoneinventoryrow.msg"); + MessageDialog.error(this, "angal.inventory.pleaseselectatleastoneinventoryrow.msg"); return; } int delete = MessageDialog.yesNo(null, "angal.inventory.doyoureallywanttodeletethisinventoryrow.msg"); From 612365d4229d854f1493208336bee17691da8678 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 15 Nov 2024 11:52:32 +0100 Subject: [PATCH 21/83] Applying suggestion to change --- bundle/language_en.properties | 6 +- .../gui/InventoryWardBrowser.java | 69 +++++++++---------- .../gui/InventoryWardEdit.java | 52 +++++--------- 3 files changed, 54 insertions(+), 73 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index e4bbe9ce29..60b5303403 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -702,10 +702,12 @@ angal.inventory.managementward.title angal.inventory.medical.col = Medical angal.inventory.mustenterareference.msg = You must enter a reference. angal.inventory.nextarrow.btn = > -angal.inventory.newinventory.title = New inventory +angal.inventory.new.title = New inventory angal.inventory.noproduct.msg = Product is not found. angal.inventory.noproductfound.msg = No medical found angal.inventory.notdateinfuture.msg = A date in the future is not allowed. +angal.inventory.page.text = Page +angal.inventory.pages.text = Pages angal.inventory.pleaseselectatleastoneinventoryrow.msg = Please select at least one inventory row. angal.inventory.pleaseselectonlyoneinventory.msg = Please select only one inventory. angal.inventory.pleaseselectinventory.msg = Please select inventory. @@ -738,7 +740,7 @@ angal.inventory.validate.success.msg angal.inventory.validated = Validated angal.inventory.view.btn = View inventory angal.inventory.view.btn.key = V -angal.inventory.viewinventory.title = View Inventory +angal.inventory.view.title = View Inventory angal.inventory.youhavealreadyaddedallproduct.msg = You have already added all the products. angal.lab.blood.txt = Blood angal.lab.cfs.txt = CFS diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index f72bfdc032..cfe24994fb 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -30,7 +30,6 @@ import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -49,8 +48,6 @@ import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import javax.swing.table.DefaultTableModel; import org.isf.generaldata.MessageBundle; @@ -102,10 +99,10 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListen private JLabel statusLabel; JButton next; JButton previous; - JComboBox pagesCombo = new JComboBox(); - JLabel under = new JLabel("/ 0 Page"); + JComboBox pagesCombo = new JComboBox<>(); + JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); private static int PAGE_SIZE = 50; - private int startIndex = 0; + private int startIndex; private int totalRows; private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); @@ -147,7 +144,7 @@ public void windowClosing(WindowEvent e) { } startIndex += PAGE_SIZE; jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if ((startIndex + PAGE_SIZE) > totalRows) { + if (startIndex + PAGE_SIZE > totalRows) { next.setEnabled(false); } pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); @@ -164,22 +161,19 @@ public void windowClosing(WindowEvent e) { } pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); - pagesCombo.addItemListener(new ItemListener() { + pagesCombo.addItemListener(itemEvent -> { + int eventID = itemEvent.getStateChange(); - public void itemStateChanged(ItemEvent itemEvent) { - int eventID = itemEvent.getStateChange(); + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; - if (eventID == ItemEvent.SELECTED) { - int page_number = (Integer) pagesCombo.getSelectedItem(); - startIndex = (page_number - 1) * PAGE_SIZE; - - next.setEnabled((startIndex + PAGE_SIZE) <= totalRows); - previous.setEnabled(page_number != 1); - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + next.setEnabled(startIndex + PAGE_SIZE <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - pagesCombo.setEnabled(true); - } + pagesCombo.setEnabled(true); } }); } @@ -440,21 +434,17 @@ private JTable getJTableInventory() { jTableInventory = new JTable(); jTableInventory.setFillsViewportHeight(true); jTableInventory.setModel(new InventoryBrowsingModel()); - jTableInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - - @Override - public void valueChanged(ListSelectionEvent e) { - if (e.getValueIsAdjusting()) { - int[] selectedRows = jTableInventory.getSelectedRows(); - if (selectedRows.length == 1) { - updateButton.setEnabled(true); - viewButton.setEnabled(true); - deleteButton.setEnabled(true); - } else { - updateButton.setEnabled(false); - viewButton.setEnabled(false); - deleteButton.setEnabled(false); - } + jTableInventory.getSelectionModel().addListSelectionListener(e -> { + if (e.getValueIsAdjusting()) { + int[] selectedRows = jTableInventory.getSelectedRows(); + if (selectedRows.length == 1) { + updateButton.setEnabled(true); + viewButton.setEnabled(true); + deleteButton.setEnabled(true); + } else { + updateButton.setEnabled(false); + viewButton.setEnabled(false); + deleteButton.setEnabled(false); } } }); @@ -493,6 +483,7 @@ public InventoryBrowsingModel(int startIndex, int pageSize) { } } + @Override public Class getColumnClass(int c) { if (c == 0) { return String.class; @@ -508,6 +499,7 @@ public Class getColumnClass(int c) { return null; } + @Override public int getRowCount() { if (inventoryList == null) { return 0; @@ -523,6 +515,7 @@ public int getColumnCount() { return pColums.length; } + @Override public Object getValueAt(int r, int c) { MedicalInventory medInvt = inventoryList.get(r); @@ -557,7 +550,7 @@ public boolean isCellEditable(int arg0, int arg1) { private JComboBox getComboBox() { if (statusComboBox == null) { - statusComboBox = new JComboBox(); + statusComboBox = new JComboBox<>(); statusComboBox.addItem(""); for (InventoryStatus currentStatus : InventoryStatus.values()) { statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); @@ -599,9 +592,9 @@ public void initialiseCombo(int total_rows) { } if (j * PAGE_SIZE < total_rows) { pagesCombo.addItem(j + 1); - under.setText("/" + (total_rows / PAGE_SIZE + 1 + " Pages")); + under.setText("/" + (total_rows / PAGE_SIZE + 1 + " " + MessageBundle.getMessage("angal.inventory.pages.text"))); } else { - under.setText("/" + total_rows / PAGE_SIZE + " Pages"); + under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); } } diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index ddb7e76ef5..658b9dcedf 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -61,6 +61,7 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; +import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; import javax.swing.event.EventListenerList; @@ -201,12 +202,12 @@ private void fireInventoryInserted() { private JComboBox destinationComboBox; private Ward wardSelected; private JLabel loaderLabel; - private boolean selectAll = false; - private String newReference = null; - private MovementType chargeType = null; - private MovementType dischargeType = null; - private Supplier supplier = null; - private Ward destination = null; + private boolean selectAll; + private String newReference; + private MovementType chargeType; + private MovementType dischargeType; + private Supplier supplier; + private Ward destination; private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext() .getBean(MedicalInventoryManager.class); @@ -494,7 +495,7 @@ private JButton getSaveButton() { dischargeType = (MovementType) dischargeComboBox.getSelectedItem(); supplier = (Supplier) supplierComboBox.getSelectedItem(); destination = (Ward) destinationComboBox.getSelectedItem(); - if ((inventory == null) && (mode.equals("new"))) { + if (inventory == null && mode.equals("new")) { newReference = referenceTextField.getText().trim(); boolean refExist; refExist = medicalInventoryManager.referenceExists(newReference); @@ -551,7 +552,7 @@ private JButton getSaveButton() { if (info != JOptionPane.YES_OPTION) { dispose(); } - } else if ((inventory != null) && (mode.equals("update"))) { + } else if (inventory != null && mode.equals("update")) { String lastCharge = inventory.getChargeType(); String lastDischarge = inventory.getDischargeType(); Integer lastSupplier = inventory.getSupplier(); @@ -783,11 +784,9 @@ private JButton getValidateButton() { statusLabel.setForeground(Color.BLUE); } else { MessageDialog.info(null, "angal.inventory.validate.error.msg"); - return; } } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); - return; } } }); @@ -857,8 +856,6 @@ private JButton getDeleteButton() { } jTableInventoryRow.clearSelection(); adjustWidth(); - } else { - return; } }); return deleteButton; @@ -907,7 +904,6 @@ private JButton getCloseButton() { dispose(); } else { resetVariable(); - return; } } else { resetVariable(); @@ -945,7 +941,7 @@ private JTable getJTableInventoryRow() throws OHServiceException { } } DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); - centerRenderer.setHorizontalAlignment(JLabel.CENTER); + centerRenderer.setHorizontalAlignment(SwingConstants.CENTER); jTableInventoryRow.getColumnModel().getColumn(3).setCellRenderer(centerRenderer); jTableInventoryRow.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @@ -1118,9 +1114,7 @@ public void setValueAt(Object value, int r, int c) { } inventoryRowListAdded.add(invRow); inventoryRowSearchList.set(r, invRow); - SwingUtilities.invokeLater(() -> { - jTableInventoryRow.updateUI(); - }); + SwingUtilities.invokeLater(() -> jTableInventoryRow.updateUI()); } } } @@ -1155,7 +1149,7 @@ private void adjustWidth() { } } DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); - centerRenderer.setHorizontalAlignment(JLabel.CENTER); + centerRenderer.setHorizontalAlignment(SwingConstants.CENTER); jTableInventoryRow.getColumnModel().getColumn(3).setCellRenderer(centerRenderer); } @@ -1179,7 +1173,7 @@ private List getMedicalInventoryRows(String code) throws OH medicalWard.getMedical(), medicalWard.getLot()))); for (MedicalWard medicalWard : medicalWardList) { lots = movStockInsertingManager.getLotByMedical(medicalWard.getMedical(), false); - double actualQty = medicalWard.getMedical().getInitialqty() + medicalWard.getMedical().getInqty() - medicalWard.getMedical().getOutqty(); + double actualQty = medicalWard.getMedical().getInqty() - medicalWard.getMedical().getOutqty(); if (lots.isEmpty()) { inventoryRowTemp = new MedicalInventoryRow(0, actualQty, actualQty, null, medicalWard.getMedical(), null); if (!existInInventorySearchList(inventoryRowTemp)) { @@ -1303,7 +1297,7 @@ private JTextField getCodeTextField() { TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.code.txt"), codeTextField, Show.FOCUS_LOST); suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); suggestion.setForeground(Color.GRAY); - suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.setHorizontalAlignment(SwingConstants.CENTER); suggestion.changeAlpha(0.5f); suggestion.changeStyle(Font.BOLD + Font.ITALIC); codeTextField.addKeyListener(new KeyAdapter() { @@ -1330,7 +1324,7 @@ public void keyPressed(KeyEvent e) { private void addInventoryRow(String code) throws OHServiceException { List inventoryRowsList; - List medicalWardList = new ArrayList(); + List medicalWardList = new ArrayList<>(); Medical medical; if (wardId.isEmpty()) { wardId = ((Ward) Objects.requireNonNull(wardComboBox.getSelectedItem())).getCode(); @@ -1565,9 +1559,7 @@ private JComboBox getChargeComboBox() { chargeComboBox.setSelectedItem(movementSelected); chargeType = movementSelected; } - chargeComboBox.addActionListener(actionEvent -> { - chargeType = (MovementType) chargeComboBox.getSelectedItem(); - }); + chargeComboBox.addActionListener(actionEvent -> chargeType = (MovementType) chargeComboBox.getSelectedItem()); } return chargeComboBox; } @@ -1594,9 +1586,7 @@ private JComboBox getDischargeComboBox() { dischargeComboBox.setSelectedItem(movementSelected); dischargeType = movementSelected; } - dischargeComboBox.addActionListener(actionEvent -> { - dischargeType = (MovementType) dischargeComboBox.getSelectedItem(); - }); + dischargeComboBox.addActionListener(actionEvent -> dischargeType = (MovementType) dischargeComboBox.getSelectedItem()); } return dischargeComboBox; } @@ -1621,9 +1611,7 @@ private JComboBox getSupplierComboBox() { supplierComboBox.setSelectedItem(supplierSelected); supplier = supplierSelected; } - supplierComboBox.addActionListener(actionEvent -> { - supplier = (Supplier) supplierComboBox.getSelectedItem(); - }); + supplierComboBox.addActionListener(actionEvent -> supplier = (Supplier) supplierComboBox.getSelectedItem()); } return supplierComboBox; } @@ -1648,9 +1636,7 @@ private JComboBox getDestinationComboBox() { destinationComboBox.setSelectedItem(destinationSelected); destination = destinationSelected; } - destinationComboBox.addActionListener(actionEvent -> { - destination = (Ward) destinationComboBox.getSelectedItem(); - }); + destinationComboBox.addActionListener(actionEvent -> destination = (Ward) destinationComboBox.getSelectedItem()); } return destinationComboBox; } From c29b77ea7dc49d38cbb627cd91061fc323691b85 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 15 Nov 2024 11:57:14 +0100 Subject: [PATCH 22/83] Applying suggestion to change --- .../java/org/isf/medicalinventory/gui/InventoryWardEdit.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 658b9dcedf..c302992876 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -1006,6 +1006,7 @@ public InventoryRowModel() throws OHServiceException { } } + @Override public Class getColumnClass(int c) { if (c == 0) { return Integer.class; @@ -1029,6 +1030,7 @@ public Class getColumnClass(int c) { return null; } + @Override public int getRowCount() { if (inventoryRowSearchList == null) { return 0; @@ -1036,14 +1038,17 @@ public int getRowCount() { return inventoryRowSearchList.size(); } + @Override public String getColumnName(int c) { return pColums[c]; } + @Override public int getColumnCount() { return pColums.length; } + @Override public Object getValueAt(int r, int c) { if (r < inventoryRowSearchList.size()) { MedicalInventoryRow medInvtRow = inventoryRowSearchList.get(r); From 8a01036786761ced3d1ae7cdb11c84cdff86bb97 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 15 Nov 2024 12:04:11 +0100 Subject: [PATCH 23/83] Applying suggestion to change --- .../isf/medicalinventory/gui/InventoryWardEdit.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index c302992876..93e866b5e1 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -26,7 +26,6 @@ import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -932,7 +931,7 @@ private JTable getJTableInventoryRow() throws OHServiceException { jTableInventoryRow.setFillsViewportHeight(true); jTableInventoryRow.setModel(new InventoryRowModel()); for (int i = 0; i < pColumnVisible.length; i++) { - jTableInventoryRow.getColumnModel().getColumn(i).setCellRenderer(new EnabledTableCellRenderer()); + jTableInventoryRow.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer()); jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(pColumwidth[i]); if (i == 0 || !pColumnVisible[i]) { jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(0); @@ -959,16 +958,6 @@ public void valueChanged(ListSelectionEvent e) { return jTableInventoryRow; } - static class EnabledTableCellRenderer extends DefaultTableCellRenderer { - private static final long serialVersionUID = 1L; - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, - int row, int column) { - return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - } - } - class InventoryRowModel extends DefaultTableModel { private static final long serialVersionUID = 1L; From 7548b139e9b2a886b4f90f2fcbbf8a1a3d41f3cd Mon Sep 17 00:00:00 2001 From: mwithi Date: Mon, 18 Nov 2024 17:41:31 +0100 Subject: [PATCH 24/83] Fix --- .../gui/InventoryWardEdit.java | 1986 +++++++++-------- 1 file changed, 998 insertions(+), 988 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 8e3c860772..c56d40651e 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -105,992 +105,1002 @@ public class InventoryWardEdit extends ModalJFrame { - private static final long serialVersionUID = 1L; - - private static EventListenerList InventoryListeners = new EventListenerList(); - - public interface InventoryListener extends EventListener { - - public void InventoryInserted(AWTEvent e); - - public void InventoryUpdated(AWTEvent e); - - public void InventoryCancelled(AWTEvent e); - } - - public static void addInventoryListener(InventoryListener l) { - InventoryListeners.add(InventoryListener.class, l); - } - - private void fireInventoryUpdated() { - AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { - private static final long serialVersionUID = 1L; - }; - - EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class); - for (int i = 0; i < listeners.length; i++) - ((InventoryListener) listeners[i]).InventoryUpdated(event); - } - - private GoodDateChooser jCalendarInventory; - private LocalDateTime dateInventory = TimeTools.getServerDateTime(); - private JPanel panelHeader; - private JPanel panelFooter; - private JPanel panelContent; - private JButton closeButton; - private JButton saveButton; - private JButton cancelButton; - private JButton printButton; - private JButton validateButton; - private JScrollPane scrollPaneInventory; - private JTable jTableInventoryRow; - private List inventoryRowList; - private List inventoryRowSearchList; - private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt").toUpperCase(), - MessageBundle.getMessage("angal.inventory.medical.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.lotcode.col").toUpperCase(), - MessageBundle.getMessage("angal.medicalstock.duedate.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.theorticalqty.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.realqty.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.unitprice.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.totalprice.col").toUpperCase() - }; - private int[] pColumwidth = { 100, 200, 100, 100, 100, 80, 80, 80 }; - private boolean[] columnEditable = { false, false, false, false, false, true, true, false }; - private MedicalInventory inventory = null; - private JRadioButton specificRadio; - private JRadioButton allRadio; - private JTextField searchTextField; - private JLabel dateInventoryLabel; - private JTextField codeTextField; - private String code = null; - private String mode = null; - private String wardId = ""; - private JLabel referenceLabel; - private JTextField referenceTextField; - private JTextField jTetFieldEditor; - private JLabel wardLabel; - private JComboBox wardComboBox; - private Ward wardSelected; - private JLabel loaderLabel; - private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); - private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext() - .getBean(MedicalInventoryManager.class); - private MedicalInventoryRowManager medicalInventoryRowManager = Context.getApplicationContext() - .getBean(MedicalInventoryRowManager.class); - private MedicalBrowsingManager medicalBrowsingManager = Context.getApplicationContext() - .getBean(MedicalBrowsingManager.class); - private MovWardBrowserManager movWardBrowserManager = Context.getApplicationContext() - .getBean(MovWardBrowserManager.class); - private MovStockInsertingManager movStockInsertingManager = Context.getApplicationContext() - .getBean(MovStockInsertingManager.class); - - public InventoryWardEdit() { - mode = "new"; - initComponents(); - cancelButton.setVisible(false); - disabledSomeComponents(); - } - - public InventoryWardEdit(MedicalInventory inventory, String modee) { - this.inventory = inventory; - mode = modee; - initComponents(); - if (mode.equals("view")) { - validateButton.setVisible(false); - saveButton.setVisible(false); - cancelButton.setVisible(false); - wardComboBox.setEnabled(false); - } - } - - private void initComponents() { - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setMinimumSize(new DimensionUIResource(950, 580)); - setLocationRelativeTo(null); // center - setTitle(MessageBundle.getMessage("angal.inventory.edit.title")); - - panelHeader = getPanelHeader(); - getContentPane().add(panelHeader, BorderLayout.NORTH); - - panelContent = getPanelContent(); - getContentPane().add(panelContent, BorderLayout.CENTER); - - panelFooter = getPanelFooter(); - getContentPane().add(panelFooter, BorderLayout.SOUTH); - } - - private JPanel getPanelHeader() { - if (panelHeader == null) { - panelHeader = new JPanel(); - panelHeader.setBorder(new EmptyBorder(5, 0, 5, 0)); - GridBagLayout gbl_panelHeader = new GridBagLayout(); - gbl_panelHeader.columnWidths = new int[] { 123, 206, 187, 195, 0, 0 }; - gbl_panelHeader.rowHeights = new int[] { 34, 36, 0, 0 }; - gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; - gbl_panelHeader.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; - panelHeader.setLayout(gbl_panelHeader); - GridBagConstraints gbc_wardLabel = new GridBagConstraints(); - gbc_wardLabel.anchor = GridBagConstraints.EAST; - gbc_wardLabel.insets = new Insets(0, 0, 5, 5); - gbc_wardLabel.gridx = 0; - gbc_wardLabel.gridy = 0; - panelHeader.add(getWardLabel(), gbc_wardLabel); - GridBagConstraints gbc_wardComboBox = new GridBagConstraints(); - gbc_wardComboBox.insets = new Insets(0, 0, 5, 5); - gbc_wardComboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_wardComboBox.gridx = 1; - gbc_wardComboBox.gridy = 0; - panelHeader.add(getWardComboBox(), gbc_wardComboBox); - GridBagConstraints gbc_loaderLabel = new GridBagConstraints(); - gbc_loaderLabel.insets = new Insets(0, 0, 5, 5); - gbc_loaderLabel.gridx = 2; - gbc_loaderLabel.gridy = 0; - panelHeader.add(getLoaderLabel(), gbc_loaderLabel); - GridBagConstraints gbc_dateInventoryLabel = new GridBagConstraints(); - gbc_dateInventoryLabel.insets = new Insets(0, 0, 5, 5); - gbc_dateInventoryLabel.gridx = 0; - gbc_dateInventoryLabel.gridy = 1; - panelHeader.add(getDateInventoryLabel(), gbc_dateInventoryLabel); - - GridBagConstraints gbc_jCalendarInventory = new GridBagConstraints(); - gbc_jCalendarInventory.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarInventory.insets = new Insets(0, 0, 5, 5); - gbc_jCalendarInventory.gridx = 1; - gbc_jCalendarInventory.gridy = 1; - panelHeader.add(getJCalendarFrom(), gbc_jCalendarInventory); - GridBagConstraints gbc_referenceLabel = new GridBagConstraints(); - gbc_referenceLabel.anchor = GridBagConstraints.EAST; - gbc_referenceLabel.insets = new Insets(0, 0, 5, 5); - gbc_referenceLabel.gridx = 2; - gbc_referenceLabel.gridy = 1; - panelHeader.add(getReferenceLabel(), gbc_referenceLabel); - GridBagConstraints gbc_referenceTextField = new GridBagConstraints(); - gbc_referenceTextField.insets = new Insets(0, 0, 5, 5); - gbc_referenceTextField.fill = GridBagConstraints.HORIZONTAL; - gbc_referenceTextField.gridx = 3; - gbc_referenceTextField.gridy = 1; - panelHeader.add(getReferenceTextField(), gbc_referenceTextField); - GridBagConstraints gbc_specificRadio = new GridBagConstraints(); - gbc_specificRadio.anchor = GridBagConstraints.EAST; - gbc_specificRadio.insets = new Insets(0, 0, 0, 5); - gbc_specificRadio.gridx = 0; - gbc_specificRadio.gridy = 2; - panelHeader.add(getSpecificRadio(), gbc_specificRadio); - GridBagConstraints gbc_codeTextField = new GridBagConstraints(); - gbc_codeTextField.insets = new Insets(0, 0, 0, 5); - gbc_codeTextField.fill = GridBagConstraints.HORIZONTAL; - gbc_codeTextField.gridx = 1; - gbc_codeTextField.gridy = 2; - panelHeader.add(getCodeTextField(), gbc_codeTextField); - GridBagConstraints gbc_allRadio = new GridBagConstraints(); - gbc_allRadio.anchor = GridBagConstraints.EAST; - gbc_allRadio.insets = new Insets(0, 0, 0, 5); - gbc_allRadio.gridx = 2; - gbc_allRadio.gridy = 2; - panelHeader.add(getAllRadio(), gbc_allRadio); - GridBagConstraints gbc_searchTextField = new GridBagConstraints(); - gbc_searchTextField.insets = new Insets(0, 0, 0, 5); - gbc_searchTextField.fill = GridBagConstraints.HORIZONTAL; - gbc_searchTextField.gridx = 3; - gbc_searchTextField.gridy = 2; - panelHeader.add(getSearchTextField(), gbc_searchTextField); - ButtonGroup group = new ButtonGroup(); - group.add(specificRadio); - group.add(allRadio); - - } - return panelHeader; - } - - private JPanel getPanelContent() { - if (panelContent == null) { - panelContent = new JPanel(); - GridBagLayout gbl_panelContent = new GridBagLayout(); - gbl_panelContent.columnWidths = new int[] { 452, 0 }; - gbl_panelContent.rowHeights = new int[] { 402, 0 }; - gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; - gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; - panelContent.setLayout(gbl_panelContent); - GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); - gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; - gbc_scrollPaneInventory.gridx = 0; - gbc_scrollPaneInventory.gridy = 0; - panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); - } - return panelContent; - } - - private JPanel getPanelFooter() { - if (panelFooter == null) { - panelFooter = new JPanel(); - panelFooter.add(getSaveButton()); - panelFooter.add(getValidateButton()); - panelFooter.add(getCancelButton()); - panelFooter.add(getPrintButton()); - panelFooter.add(getCloseButton()); - } - return panelFooter; - } - - private GoodDateChooser getJCalendarFrom() { - if (jCalendarInventory == null) { - - jCalendarInventory = new GoodDateChooser(LocalDate.now()); - if (inventory != null) { - jCalendarInventory.setDate(inventory.getInventoryDate().toLocalDate()); - } - jCalendarInventory.addDateChangeListener(dateChangeEvent -> { - LocalDate newDate = dateChangeEvent.getNewDate(); - if (newDate != null) { - dateInventory = newDate.atStartOfDay(); - jCalendarInventory.setDate(newDate); - } - }); - } - return jCalendarInventory; - } - - private JButton getSaveButton() { - saveButton = new JButton(MessageBundle.getMessage("angal.common.save")); - saveButton.setMnemonic(MessageBundle.getMnemonic("angal.common.save.btn.key")); - saveButton.addActionListener(actionEvent -> { - String State = InventoryStatus.draft.toString(); - String user = UserBrowsingManager.getCurrentUser(); - int checkResults = 0; - if (inventoryRowSearchList == null || inventoryRowSearchList.size() < 1) { - MessageDialog.error(null, "angal.inventory.noproduct.msg"); - return; - } - LocalDateTime now = LocalDateTime.now(); - if (dateInventory.isAfter(now)) { - MessageDialog.error(null, "angal.inventory.notdateinfuture.msg"); - return; - } - - if ((inventory == null) && (mode.equals("new"))) { - String reference = referenceTextField.getText().trim(); - if (reference.equals("")) { - MessageDialog.error(null, "angal.inventory.mustenterareference.msg"); - return; - } - if (medicalInventoryManager.referenceExists(reference)) { - MessageDialog.error(null, "angal.inventory.referencealreadyused.msg"); - return; - } - inventory = new MedicalInventory(); - inventory.setInventoryReference(reference); - inventory.setInventoryDate(dateInventory); - inventory.setStatus(State); - inventory.setUser(user); - inventory.setInventoryType(InventoryType.main.toString()); - MedicalInventory meInventory; - try { - meInventory = medicalInventoryManager.newMedicalInventory(inventory); - if (meInventory != null) { - MedicalInventoryRow currentInventoryRow; - for (Iterator iterator = inventoryRowSearchList.iterator(); iterator - .hasNext();) { - MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); - medicalInventoryRow.setInventory(meInventory); - Lot lot = medicalInventoryRow.getLot(); - if (lot != null && lot.getCode().equals("")) { - medicalInventoryRow.setLot(null); - } - currentInventoryRow = medicalInventoryRowManager - .newMedicalInventoryRow(medicalInventoryRow); - if (currentInventoryRow == null) { - checkResults++; - } - } - if (checkResults == 0) { - // enable validation - mode = "update"; - MessageDialog.info(this, "angal.inventory.savesucces.msg"); - fireInventoryUpdated(); - closeButton.doClick(); - } else { - MessageDialog.error(null, "angal.inventory.error.msg"); - } - } else { - MessageDialog.error(null, "angal.inventory.error.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - return saveButton; - } - - private JButton getValidateButton() { - - validateButton = new JButton(MessageBundle.getMessage("angal.inventory.validate.btn")); - validateButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.validate.btn.key")); - return validateButton; - } - - private JButton getCancelButton() { - cancelButton = new JButton(MessageBundle.getMessage("angal.common.cancel.btn")); - cancelButton.setMnemonic(MessageBundle.getMnemonic("angal.common.cancel.btn.key")); - cancelButton.addActionListener(actionEvent -> { - if (jTableInventoryRow.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); - return; - } - int selectedRow = jTableInventoryRow.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); - return; - } - MedicalInventoryRow selectedInventory = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRow, - -1); - int delete = MessageDialog.yesNo(null, "angal.inventoryrow.doyoureallywanttodeletethisinventoryrow.msg"); - if (delete == JOptionPane.YES_OPTION) { - if (selectedInventory.getInventory() == null) { - inventoryRowSearchList.remove(selectedRow); - } - } else { - return; - } - jTableInventoryRow.updateUI(); - }); - return cancelButton; - } - - private JButton getPrintButton() { - printButton = new JButton(MessageBundle.getMessage("angal.common.print.btn")); - printButton.setMnemonic(MessageBundle.getMnemonic("angal.common.print.btn.key")); - return printButton; - } - - private JButton getCloseButton() { - closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); - closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - dispose(); - } - - }); - return closeButton; - } - - private JScrollPane getScrollPaneInventory() { - if (scrollPaneInventory == null) { - scrollPaneInventory = new JScrollPane(); - scrollPaneInventory.setViewportView(getJTableInventoryRow()); - } - return scrollPaneInventory; - } - - private JTable getJTableInventoryRow() { - if (jTableInventoryRow == null) { - jTableInventoryRow = new JTable(); - jTetFieldEditor = new JTextField(); - jTableInventoryRow.setFillsViewportHeight(true); - jTableInventoryRow.setModel(new InventoryRowModel()); - jTableInventoryRow.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - - @Override - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), 5); - jTetFieldEditor.selectAll(); - } - - } - }); - jTableInventoryRow.getModel().addTableModelListener(new TableModelListener() { - - @Override - public void tableChanged(TableModelEvent e) { - - if (e.getType() == TableModelEvent.UPDATE) { - int row = e.getFirstRow(); - int column = e.getColumn(); - TableModel model = (TableModel) e.getSource(); - Object data = model.getValueAt(row, column); - - if (column == 2) { - Object data2 = model.getValueAt(row, 3); - if (!data.toString().equals("") && data2.toString().equals("")) { - jTableInventoryRow.setSurrendersFocusOnKeystroke(true); - jTableInventoryRow.getEditorComponent().requestFocus(); - return; - } - } - - if (column == 3) { - Object data2 = model.getValueAt(row, 2); - if (!data.toString().equals("") && data2.toString().equals("")) { - jTableInventoryRow.setSurrendersFocusOnKeystroke(true); - jTableInventoryRow.getEditorComponent().requestFocus(); - return; - } - } - } - } - }); - DefaultCellEditor cellEditor = new DefaultCellEditor(jTetFieldEditor); - jTableInventoryRow.setDefaultEditor(Integer.class, cellEditor); - } - return jTableInventoryRow; - } - - class InventoryRowModel extends DefaultTableModel { - - private static final long serialVersionUID = 1L; - - public InventoryRowModel() { - if (allRadio.isSelected()) { - try { - inventoryRowList = loadNewInventoryTable(null); - } catch (OHServiceException e) { - inventoryRowList = new ArrayList<>(); - OHServiceExceptionUtil.showMessages(e); - } - } else if (specificRadio.isSelected() && code != null && !code.trim().equals("")) { - try { - inventoryRowList = loadNewInventoryTable(code.trim()); - } catch (OHServiceException e) { - inventoryRowList = new ArrayList<>(); - OHServiceExceptionUtil.showMessages(e); - } - } - - inventoryRowSearchList = inventoryRowList; - } - - public Class getColumnClass(int c) { - if (c == 0) { - return String.class; - } else if (c == 1) { - return String.class; - } else if (c == 2) { - return String.class; - } else if (c == 3) { - return String.class; - } else if (c == 4) { - return Double.class; - } else if (c == 5) { - return Double.class; - } else if (c == 6) { - return Double.class; - } else if (c == 7) { - return Double.class; - } - return null; - } - - public int getRowCount() { - if (inventoryRowSearchList == null) { - return 0; - } - return inventoryRowSearchList.size(); - } - - public String getColumnName(int c) { - return pColums[c]; - } - - public int getColumnCount() { - return pColums.length; - } - - public Object getValueAt(int r, int c) { - MedicalInventoryRow medInvtRow = inventoryRowSearchList.get(r); - - if (c == -1) { - return medInvtRow; - } else if (c == 0) { - return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getProdCode(); - } else if (c == 1) { - return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription(); - } else if (c == 2) { - return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode(); - } else if (c == 3) { - if (medInvtRow.getLot() != null) { - if (medInvtRow.getLot().getDueDate() != null) { - return medInvtRow.getLot().getDueDate().format(DATE_TIME_FORMATTER); - } - } - return ""; - } else if (c == 4) { - Double dblVal = medInvtRow.getTheoreticQty(); - return dblVal; - } else if (c == 5) { - Double dblValue = medInvtRow.getRealQty(); - return dblValue; - } else if (c == 6) { - if (medInvtRow.getLot() != null) { - if (medInvtRow.getLot().getCost() != null) { - return medInvtRow.getLot().getCost(); - } - } - return 0.0; - } else if (c == 7) { - if (medInvtRow.getLot() != null) { - if (medInvtRow.getLot().getCost() != null) { - return medInvtRow.getRealQty() * medInvtRow.getLot().getCost().doubleValue(); - } - } - return 0.0; - } - return null; - } - - @Override - public void setValueAt(Object value, int r, int c) { - if (r < inventoryRowSearchList.size()) { - MedicalInventoryRow invRow = inventoryRowSearchList.get(r); - if (c == 5) { - Integer intValue = 0; - try { - intValue = Integer.parseInt(value.toString()); - } catch (NumberFormatException e) { - intValue = 0; - } - - invRow.setRealqty(intValue); - inventoryRowSearchList.set(r, invRow); - jTableInventoryRow.updateUI(); - } - if (c == 6) { - Double doubleValue = 0.0; - try { - doubleValue = Double.parseDouble(value.toString()); - } catch (NumberFormatException e) { - doubleValue = 0.0; - } - Lot lot = invRow.getLot(); - if (lot != null) { - if (lot.getCode().equals("")) { - MessageDialog.error(null, "angal.inventoryrow.cannotchangethepriceofproductwithoutlot.msg"); - } else { - lot.setCost(new BigDecimal(doubleValue)); - try { - Lot saveLot = movStockInsertingManager.updateLot(lot); - invRow.setLot(saveLot); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - } - inventoryRowSearchList.set(r, invRow); - jTableInventoryRow.updateUI(); - } - } - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return columnEditable[columnIndex]; - } - } - - private List loadNewInventoryTable(String code) throws OHServiceException { - List inventoryRowsList = new ArrayList<>(); - List medicalWardList = new ArrayList<>(); - Medical medical = null; - if (code != null) { - medical = medicalBrowsingManager.getMedicalByMedicalCode(code); - if (medical != null) { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); - } else { - MessageDialog.error(null, MessageBundle.getMessage("angal.inventory.noproductfound.msg")); - } - } else { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); - } - medicalWardList.stream().forEach(medicalWard -> { - inventoryRowsList.add(new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, - medicalWard.getMedical(), medicalWard.getLot())); - }); - return inventoryRowsList; - } - - class DecimalFormatRenderer extends DefaultTableCellRenderer { - - private static final long serialVersionUID = 1L; - private final DecimalFormat formatter = new DecimalFormat("#,##0.00"); //$NON-NLS-1$ - - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, - int row, int column) { - // First format the cell value as required - Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - value = formatter.format((Number) value); - // setHorizontalAlignment(columnAlignment[column]); - if (!columnEditable[column]) { - cell.setBackground(Color.LIGHT_GRAY); - } - - // And pass it on to parent class - return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - } - } - - private JRadioButton getSpecificRadio() { - if (specificRadio == null) { - specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); - if (inventory != null) { - specificRadio.setSelected(false); - } else { - specificRadio.setSelected(true); - } - specificRadio.addActionListener(actionEvent -> { - - if (specificRadio.isSelected()) { - codeTextField.setEnabled(true); - searchTextField.setEnabled(false); - searchTextField.setText(""); - codeTextField.setText(""); - if (inventoryRowList != null) { - inventoryRowList.clear(); - } - if (inventoryRowSearchList != null) { - inventoryRowSearchList.clear(); - } - jTableInventoryRow.updateUI(); - ajustWidth(); - } - }); - } - return specificRadio; - } - - private JRadioButton getAllRadio() { - if (allRadio == null) { - allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); - if (inventory != null) { - allRadio.setSelected(true); - } else { - allRadio.setSelected(false); - } - allRadio.addActionListener(actionEvent -> { - if (allRadio.isSelected()) { - codeTextField.setEnabled(false); - searchTextField.setText(""); - codeTextField.setText(""); - searchTextField.setEnabled(true); - if (inventoryRowList != null) { - inventoryRowList.clear(); - } - if (inventoryRowSearchList != null) { - inventoryRowSearchList.clear(); - } - jTableInventoryRow.setModel(new InventoryRowModel()); - jTableInventoryRow.updateUI(); - code = null; - ajustWidth(); - } - }); - } - return allRadio; - } - - private JTextField getSearchTextField() { - if (searchTextField == null) { - searchTextField = new JTextField(); - searchTextField.setColumns(16); - TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.search.txt"), searchTextField, - Show.FOCUS_LOST); - suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); - suggestion.setForeground(Color.GRAY); - suggestion.setHorizontalAlignment(JLabel.CENTER); - suggestion.changeAlpha(0.5f); - suggestion.changeStyle(Font.BOLD + Font.ITALIC); - searchTextField.getDocument().addDocumentListener(new DocumentListener() { - - @Override - public void insertUpdate(DocumentEvent e) { - filterInventoryRow(); - ajustWidth(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - filterInventoryRow(); - ajustWidth(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - filterInventoryRow(); - ajustWidth(); - } - }); - searchTextField.setEnabled(false); - if (inventory != null) { - searchTextField.setEnabled(true); - } else { - searchTextField.setEnabled(false); - } - } - return searchTextField; - } - - private JLabel getDateInventoryLabel() { - if (dateInventoryLabel == null) { - dateInventoryLabel = new JLabel(MessageBundle.getMessage("angal.inventory.date.label")); - } - return dateInventoryLabel; - } - - private JTextField getCodeTextField() { - if (codeTextField == null) { - codeTextField = new JTextField(); - if (inventory != null) { - codeTextField.setEnabled(false); - } else { - codeTextField.setEnabled(true); - } - codeTextField.setColumns(10); - TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.code.txt"), codeTextField, - Show.FOCUS_LOST); - suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); - suggestion.setForeground(Color.GRAY); - suggestion.setHorizontalAlignment(JLabel.CENTER); - suggestion.changeAlpha(0.5f); - suggestion.changeStyle(Font.BOLD + Font.ITALIC); - codeTextField.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - code = codeTextField.getText().trim(); - code = code.toLowerCase(); - try { - addInventoryRow(code); - } catch (OHServiceException e1) { - OHServiceExceptionUtil.showMessages(e1); - } - codeTextField.setText(""); - ajustWidth(); - } - } - }); - } - return codeTextField; - } - - private void filterInventoryRow() { - String s = searchTextField.getText(); - s.trim(); - inventoryRowSearchList = new ArrayList(); - for (MedicalInventoryRow invRow : inventoryRowList) { - if (!s.equals("")) { - String name = invRow.getSearchString(); - if (name.contains(s.toLowerCase())) - inventoryRowSearchList.add(invRow); - } else { - inventoryRowSearchList.add(invRow); - } - } - jTableInventoryRow.updateUI(); - searchTextField.requestFocus(); - } - - private void addInventoryRow(String code) throws OHServiceException { - List inventoryRowsList = new ArrayList(); - List medicalWardList = new ArrayList(); - Medical medical = null; - if (code != null) { - medical = medicalBrowsingManager.getMedicalByMedicalCode(code); - if (medical != null) { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); - } else { - medical = chooseMedical(code); - if (medical != null) { - boolean found = false; - if (inventoryRowSearchList != null) { - for (MedicalInventoryRow row : inventoryRowSearchList) { - if (row.getMedical().getCode().equals(medical.getCode())) { - found = true; - } - } - } - if (!found) { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); - } - } - } - } else { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); - } - if (mode.equals("new")) { - inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), - medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); - } else if (mode.equals("update")) { - if (medical != null) { - String medicalCode = medical.getProdCode(); - inventoryRowsList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()) - .stream() - .filter(medRow -> medRow.getMedical().getProdCode().equals(medicalCode)).toList(); - } - } - if (inventoryRowSearchList == null) { - inventoryRowSearchList = new ArrayList<>(); - } - for (MedicalInventoryRow inventoryRow : inventoryRowsList) { - inventoryRowSearchList.add(inventoryRow); - } - jTableInventoryRow.updateUI(); - } - - private Medical chooseMedical(String text) throws OHServiceException { - Map medicalMap; - List medicals = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false).stream() - .map(medicalWard -> medicalWard.getMedical()).toList(); - if (mode.equals("update")) { - medicals.clear(); - List inventoryRowListTemp = medicalInventoryRowManager - .getMedicalInventoryRowByInventoryId(inventory.getId()); - for (MedicalInventoryRow medicalInventoryRow : inventoryRowListTemp) { - medicals.add(medicalInventoryRow.getMedical()); - } - } - medicalMap = new HashMap(); - for (Medical med : medicals) { - String key = med.getProdCode().toLowerCase(); - key = med.getCode().toString().toLowerCase(); - medicalMap.put(key, med); - } - ArrayList medList = new ArrayList(); - for (Medical aMed : medicalMap.values()) { - if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { - medList.add(aMed); - } - } - Collections.sort(medList); - Medical med = null; - if (!medList.isEmpty()) { - MedicalPicker framas = new MedicalPicker(new StockMedModel(medList), medList); - framas.setSize(300, 400); - JDialog dialog = new JDialog(); - dialog.setLocationRelativeTo(null); - dialog.setSize(600, 350); - dialog.setLocationRelativeTo(null); - dialog.setModal(true); - dialog.setTitle(MessageBundle.getMessage("angal.medicalstock.multiplecharging.selectmedical.title")); - framas.setParentFrame(dialog); - dialog.setContentPane(framas); - dialog.setVisible(true); - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - med = framas.getSelectedMedical(); - return med; - } - return null; - } - - private void ajustWidth() { - for (int i = 0; i < pColumwidth.length; i++) { - jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); - } - } - - private JLabel getReferenceLabel() { - if (referenceLabel == null) { - referenceLabel = new JLabel(MessageBundle.getMessage("angal.inventory.reference.label")); - } - return referenceLabel; - } - - private JTextField getReferenceTextField() { - if (referenceTextField == null) { - referenceTextField = new JTextField(); - referenceTextField.setColumns(10); - if (inventory != null && !mode.equals("new")) { - referenceTextField.setText(inventory.getInventoryReference()); - referenceTextField.setEnabled(false); - } - } - return referenceTextField; - } - - private JLabel getWardLabel() { - if (wardLabel == null) { - wardLabel = new JLabel(MessageBundle.getMessage("angal.inventory.selectward.label")); - } - return wardLabel; - } - - private JComboBox getWardComboBox() { - if (wardComboBox == null) { - wardComboBox = new JComboBox(); - List wardList; - try { - wardList = wardBrowserManager.getWards(); - } catch (OHServiceException e) { - wardList = new ArrayList<>(); - OHServiceExceptionUtil.showMessages(e); - } - for (Ward elem : wardList) { - wardComboBox.addItem(elem); - } - wardComboBox.setSelectedIndex(-1); - - wardComboBox.addItemListener(itemEvent -> { - - if (itemEvent.getStateChange() == ItemEvent.SELECTED) { - Object item = itemEvent.getItem(); - if (item instanceof Ward) { - wardSelected = (Ward) item; - wardId = wardSelected.getCode(); - List medicalWardInventory; - try { - medicalWardInventory = medicalInventoryManager - .getMedicalInventoryByStatusAndWard(InventoryType.ward.toString(), wardId); - } catch (OHServiceException e) { - medicalWardInventory = new ArrayList<>(); - OHServiceExceptionUtil.showMessages(e); - } - - if (medicalWardInventory != null) { - activedSomeComponents(); - } else { - MessageDialog.error(this, - "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); - return; - } - } - } - }); - } - return wardComboBox; - } - - private void disabledSomeComponents() { - jCalendarInventory.setEnabled(false); - searchTextField.setEnabled(false); - specificRadio.setEnabled(false); - codeTextField.setEnabled(false); - allRadio.setEnabled(false); - referenceTextField.setEnabled(false); - jTableInventoryRow.setEnabled(false); - saveButton.setEnabled(false); - validateButton.setEnabled(false); - printButton.setEnabled(false); - } - - private void activedSomeComponents() { - jCalendarInventory.setEnabled(true); - searchTextField.setEnabled(true); - specificRadio.setEnabled(true); - codeTextField.setEnabled(true); - allRadio.setEnabled(true); - referenceTextField.setEnabled(true); - jTableInventoryRow.setEnabled(true); - wardComboBox.setEnabled(false); - saveButton.setEnabled(true); - } - - private JLabel getLoaderLabel() { - if (loaderLabel == null) { - Icon icon = new ImageIcon("rsc/icons/oh_loader.GIF"); - loaderLabel = new JLabel(""); - loaderLabel.setIcon(icon); - loaderLabel.setVisible(false); - } - return loaderLabel; - } + private static final long serialVersionUID = 1L; + + private static EventListenerList InventoryListeners = new EventListenerList(); + + public interface InventoryListener extends EventListener { + + public void InventoryInserted(AWTEvent e); + + public void InventoryUpdated(AWTEvent e); + + public void InventoryCancelled(AWTEvent e); + } + + public static void addInventoryListener(InventoryListener l) { + InventoryListeners.add(InventoryListener.class, l); + } + + private void fireInventoryUpdated() { + AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { + + private static final long serialVersionUID = 1L; + }; + + EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class); + for (int i = 0; i < listeners.length; i++) + ((InventoryListener) listeners[i]).InventoryUpdated(event); + } + + private GoodDateChooser jCalendarInventory; + private LocalDateTime dateInventory = TimeTools.getServerDateTime(); + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton saveButton; + private JButton cancelButton; + private JButton printButton; + private JButton validateButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventoryRow; + private List inventoryRowList; + private List inventoryRowSearchList; + private String[] pColums = { MessageBundle.getMessage("angal.common.code.txt").toUpperCase(), + MessageBundle.getMessage("angal.inventory.medical.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.lotcode.col").toUpperCase(), + MessageBundle.getMessage("angal.medicalstock.duedate.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.theorticalqty.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.realqty.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.unitprice.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.totalprice.col").toUpperCase() + }; + private int[] pColumwidth = { 100, 200, 100, 100, 100, 80, 80, 80 }; + private boolean[] columnEditable = { false, false, false, false, false, true, true, false }; + private MedicalInventory inventory = null; + private JRadioButton specificRadio; + private JRadioButton allRadio; + private JTextField searchTextField; + private JLabel dateInventoryLabel; + private JTextField codeTextField; + private String code = null; + private String mode = null; + private String wardId = ""; + private JLabel referenceLabel; + private JTextField referenceTextField; + private JTextField jTetFieldEditor; + private JLabel wardLabel; + private JComboBox wardComboBox; + private Ward wardSelected; + private JLabel loaderLabel; + private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); + private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext() + .getBean(MedicalInventoryManager.class); + private MedicalInventoryRowManager medicalInventoryRowManager = Context.getApplicationContext() + .getBean(MedicalInventoryRowManager.class); + private MedicalBrowsingManager medicalBrowsingManager = Context.getApplicationContext() + .getBean(MedicalBrowsingManager.class); + private MovWardBrowserManager movWardBrowserManager = Context.getApplicationContext() + .getBean(MovWardBrowserManager.class); + private MovStockInsertingManager movStockInsertingManager = Context.getApplicationContext() + .getBean(MovStockInsertingManager.class); + + public InventoryWardEdit() { + mode = "new"; + initComponents(); + cancelButton.setVisible(false); + disabledSomeComponents(); + } + + public InventoryWardEdit(MedicalInventory inventory, String modee) { + this.inventory = inventory; + mode = modee; + initComponents(); + if (mode.equals("view")) { + validateButton.setVisible(false); + saveButton.setVisible(false); + cancelButton.setVisible(false); + wardComboBox.setEnabled(false); + } + } + + private void initComponents() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new DimensionUIResource(950, 580)); + setLocationRelativeTo(null); // center + setTitle(MessageBundle.getMessage("angal.inventory.edit.title")); + + panelHeader = getPanelHeader(); + getContentPane().add(panelHeader, BorderLayout.NORTH); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + panelFooter = getPanelFooter(); + getContentPane().add(panelFooter, BorderLayout.SOUTH); + } + + private JPanel getPanelHeader() { + if (panelHeader == null) { + panelHeader = new JPanel(); + panelHeader.setBorder(new EmptyBorder(5, 0, 5, 0)); + GridBagLayout gbl_panelHeader = new GridBagLayout(); + gbl_panelHeader.columnWidths = new int[] { 123, 206, 187, 195, 0, 0 }; + gbl_panelHeader.rowHeights = new int[] { 34, 36, 0, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; + panelHeader.setLayout(gbl_panelHeader); + GridBagConstraints gbc_wardLabel = new GridBagConstraints(); + gbc_wardLabel.anchor = GridBagConstraints.EAST; + gbc_wardLabel.insets = new Insets(0, 0, 5, 5); + gbc_wardLabel.gridx = 0; + gbc_wardLabel.gridy = 0; + panelHeader.add(getWardLabel(), gbc_wardLabel); + GridBagConstraints gbc_wardComboBox = new GridBagConstraints(); + gbc_wardComboBox.insets = new Insets(0, 0, 5, 5); + gbc_wardComboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_wardComboBox.gridx = 1; + gbc_wardComboBox.gridy = 0; + panelHeader.add(getWardComboBox(), gbc_wardComboBox); + GridBagConstraints gbc_loaderLabel = new GridBagConstraints(); + gbc_loaderLabel.insets = new Insets(0, 0, 5, 5); + gbc_loaderLabel.gridx = 2; + gbc_loaderLabel.gridy = 0; + panelHeader.add(getLoaderLabel(), gbc_loaderLabel); + GridBagConstraints gbc_dateInventoryLabel = new GridBagConstraints(); + gbc_dateInventoryLabel.insets = new Insets(0, 0, 5, 5); + gbc_dateInventoryLabel.gridx = 0; + gbc_dateInventoryLabel.gridy = 1; + panelHeader.add(getDateInventoryLabel(), gbc_dateInventoryLabel); + + GridBagConstraints gbc_jCalendarInventory = new GridBagConstraints(); + gbc_jCalendarInventory.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarInventory.insets = new Insets(0, 0, 5, 5); + gbc_jCalendarInventory.gridx = 1; + gbc_jCalendarInventory.gridy = 1; + panelHeader.add(getJCalendarFrom(), gbc_jCalendarInventory); + GridBagConstraints gbc_referenceLabel = new GridBagConstraints(); + gbc_referenceLabel.anchor = GridBagConstraints.EAST; + gbc_referenceLabel.insets = new Insets(0, 0, 5, 5); + gbc_referenceLabel.gridx = 2; + gbc_referenceLabel.gridy = 1; + panelHeader.add(getReferenceLabel(), gbc_referenceLabel); + GridBagConstraints gbc_referenceTextField = new GridBagConstraints(); + gbc_referenceTextField.insets = new Insets(0, 0, 5, 5); + gbc_referenceTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_referenceTextField.gridx = 3; + gbc_referenceTextField.gridy = 1; + panelHeader.add(getReferenceTextField(), gbc_referenceTextField); + GridBagConstraints gbc_specificRadio = new GridBagConstraints(); + gbc_specificRadio.anchor = GridBagConstraints.EAST; + gbc_specificRadio.insets = new Insets(0, 0, 0, 5); + gbc_specificRadio.gridx = 0; + gbc_specificRadio.gridy = 2; + panelHeader.add(getSpecificRadio(), gbc_specificRadio); + GridBagConstraints gbc_codeTextField = new GridBagConstraints(); + gbc_codeTextField.insets = new Insets(0, 0, 0, 5); + gbc_codeTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_codeTextField.gridx = 1; + gbc_codeTextField.gridy = 2; + panelHeader.add(getCodeTextField(), gbc_codeTextField); + GridBagConstraints gbc_allRadio = new GridBagConstraints(); + gbc_allRadio.anchor = GridBagConstraints.EAST; + gbc_allRadio.insets = new Insets(0, 0, 0, 5); + gbc_allRadio.gridx = 2; + gbc_allRadio.gridy = 2; + panelHeader.add(getAllRadio(), gbc_allRadio); + GridBagConstraints gbc_searchTextField = new GridBagConstraints(); + gbc_searchTextField.insets = new Insets(0, 0, 0, 5); + gbc_searchTextField.fill = GridBagConstraints.HORIZONTAL; + gbc_searchTextField.gridx = 3; + gbc_searchTextField.gridy = 2; + panelHeader.add(getSearchTextField(), gbc_searchTextField); + ButtonGroup group = new ButtonGroup(); + group.add(specificRadio); + group.add(allRadio); + + } + return panelHeader; + } + + private JPanel getPanelContent() { + if (panelContent == null) { + panelContent = new JPanel(); + GridBagLayout gbl_panelContent = new GridBagLayout(); + gbl_panelContent.columnWidths = new int[] { 452, 0 }; + gbl_panelContent.rowHeights = new int[] { 402, 0 }; + gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + panelContent.setLayout(gbl_panelContent); + GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); + gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; + gbc_scrollPaneInventory.gridx = 0; + gbc_scrollPaneInventory.gridy = 0; + panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); + } + return panelContent; + } + + private JPanel getPanelFooter() { + if (panelFooter == null) { + panelFooter = new JPanel(); + panelFooter.add(getSaveButton()); + panelFooter.add(getValidateButton()); + panelFooter.add(getCancelButton()); + panelFooter.add(getPrintButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private GoodDateChooser getJCalendarFrom() { + if (jCalendarInventory == null) { + + jCalendarInventory = new GoodDateChooser(LocalDate.now()); + if (inventory != null) { + jCalendarInventory.setDate(inventory.getInventoryDate().toLocalDate()); + } + jCalendarInventory.addDateChangeListener(dateChangeEvent -> { + LocalDate newDate = dateChangeEvent.getNewDate(); + if (newDate != null) { + dateInventory = newDate.atStartOfDay(); + jCalendarInventory.setDate(newDate); + } + }); + } + return jCalendarInventory; + } + + private JButton getSaveButton() { + saveButton = new JButton(MessageBundle.getMessage("angal.common.save")); + saveButton.setMnemonic(MessageBundle.getMnemonic("angal.common.save.btn.key")); + saveButton.addActionListener(actionEvent -> { + String State = InventoryStatus.draft.toString(); + String user = UserBrowsingManager.getCurrentUser(); + int checkResults = 0; + if (inventoryRowSearchList == null || inventoryRowSearchList.size() < 1) { + MessageDialog.error(null, "angal.inventory.noproduct.msg"); + return; + } + LocalDateTime now = LocalDateTime.now(); + if (dateInventory.isAfter(now)) { + MessageDialog.error(null, "angal.inventory.notdateinfuture.msg"); + return; + } + + try { + if ((inventory == null) && (mode.equals("new"))) { + String reference = referenceTextField.getText().trim(); + if (reference.equals("")) { + MessageDialog.error(null, "angal.inventory.mustenterareference.msg"); + return; + } + + if (medicalInventoryManager.referenceExists(reference)) { + MessageDialog.error(null, "angal.inventory.referencealreadyused.msg"); + return; + } + + inventory = new MedicalInventory(); + inventory.setInventoryReference(reference); + inventory.setInventoryDate(dateInventory); + inventory.setStatus(State); + inventory.setUser(user); + inventory.setInventoryType(InventoryType.main.toString()); + MedicalInventory meInventory; + try { + meInventory = medicalInventoryManager.newMedicalInventory(inventory); + if (meInventory != null) { + MedicalInventoryRow currentInventoryRow; + for (Iterator iterator = inventoryRowSearchList.iterator(); iterator + .hasNext();) { + MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); + medicalInventoryRow.setInventory(meInventory); + Lot lot = medicalInventoryRow.getLot(); + if (lot != null && lot.getCode().equals("")) { + medicalInventoryRow.setLot(null); + } + currentInventoryRow = medicalInventoryRowManager + .newMedicalInventoryRow(medicalInventoryRow); + if (currentInventoryRow == null) { + checkResults++; + } + } + if (checkResults == 0) { + // enable validation + mode = "update"; + MessageDialog.info(this, "angal.inventory.savesucces.msg"); + fireInventoryUpdated(); + closeButton.doClick(); + } else { + MessageDialog.error(null, "angal.inventory.error.msg"); + } + } else { + MessageDialog.error(null, "angal.inventory.error.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + return; + } + }); + return saveButton; + } + + private JButton getValidateButton() { + + validateButton = new JButton(MessageBundle.getMessage("angal.inventory.validate.btn")); + validateButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.validate.btn.key")); + return validateButton; + } + + private JButton getCancelButton() { + cancelButton = new JButton(MessageBundle.getMessage("angal.common.cancel.btn")); + cancelButton.setMnemonic(MessageBundle.getMnemonic("angal.common.cancel.btn.key")); + cancelButton.addActionListener(actionEvent -> { + if (jTableInventoryRow.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); + return; + } + int selectedRow = jTableInventoryRow.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventoryrow.pleaseselectonlyoneinventoryrow.msg"); + return; + } + MedicalInventoryRow selectedInventory = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRow, + -1); + int delete = MessageDialog.yesNo(null, "angal.inventoryrow.doyoureallywanttodeletethisinventoryrow.msg"); + if (delete == JOptionPane.YES_OPTION) { + if (selectedInventory.getInventory() == null) { + inventoryRowSearchList.remove(selectedRow); + } + } else { + return; + } + jTableInventoryRow.updateUI(); + }); + return cancelButton; + } + + private JButton getPrintButton() { + printButton = new JButton(MessageBundle.getMessage("angal.common.print.btn")); + printButton.setMnemonic(MessageBundle.getMnemonic("angal.common.print.btn.key")); + return printButton; + } + + private JButton getCloseButton() { + closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); + closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); + closeButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + dispose(); + } + + }); + return closeButton; + } + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + scrollPaneInventory.setViewportView(getJTableInventoryRow()); + } + return scrollPaneInventory; + } + + private JTable getJTableInventoryRow() { + if (jTableInventoryRow == null) { + jTableInventoryRow = new JTable(); + jTetFieldEditor = new JTextField(); + jTableInventoryRow.setFillsViewportHeight(true); + jTableInventoryRow.setModel(new InventoryRowModel()); + jTableInventoryRow.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + jTableInventoryRow.editCellAt(jTableInventoryRow.getSelectedRow(), 5); + jTetFieldEditor.selectAll(); + } + + } + }); + jTableInventoryRow.getModel().addTableModelListener(new TableModelListener() { + + @Override + public void tableChanged(TableModelEvent e) { + + if (e.getType() == TableModelEvent.UPDATE) { + int row = e.getFirstRow(); + int column = e.getColumn(); + TableModel model = (TableModel) e.getSource(); + Object data = model.getValueAt(row, column); + + if (column == 2) { + Object data2 = model.getValueAt(row, 3); + if (!data.toString().equals("") && data2.toString().equals("")) { + jTableInventoryRow.setSurrendersFocusOnKeystroke(true); + jTableInventoryRow.getEditorComponent().requestFocus(); + return; + } + } + + if (column == 3) { + Object data2 = model.getValueAt(row, 2); + if (!data.toString().equals("") && data2.toString().equals("")) { + jTableInventoryRow.setSurrendersFocusOnKeystroke(true); + jTableInventoryRow.getEditorComponent().requestFocus(); + return; + } + } + } + } + }); + DefaultCellEditor cellEditor = new DefaultCellEditor(jTetFieldEditor); + jTableInventoryRow.setDefaultEditor(Integer.class, cellEditor); + } + return jTableInventoryRow; + } + + class InventoryRowModel extends DefaultTableModel { + + private static final long serialVersionUID = 1L; + + public InventoryRowModel() { + if (allRadio.isSelected()) { + try { + inventoryRowList = loadNewInventoryTable(null); + } catch (OHServiceException e) { + inventoryRowList = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + } else if (specificRadio.isSelected() && code != null && !code.trim().equals("")) { + try { + inventoryRowList = loadNewInventoryTable(code.trim()); + } catch (OHServiceException e) { + inventoryRowList = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + } + + inventoryRowSearchList = inventoryRowList; + } + + public Class< ? > getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return String.class; + } else if (c == 3) { + return String.class; + } else if (c == 4) { + return Double.class; + } else if (c == 5) { + return Double.class; + } else if (c == 6) { + return Double.class; + } else if (c == 7) { + return Double.class; + } + return null; + } + + public int getRowCount() { + if (inventoryRowSearchList == null) { + return 0; + } + return inventoryRowSearchList.size(); + } + + public String getColumnName(int c) { + return pColums[c]; + } + + public int getColumnCount() { + return pColums.length; + } + + public Object getValueAt(int r, int c) { + MedicalInventoryRow medInvtRow = inventoryRowSearchList.get(r); + + if (c == -1) { + return medInvtRow; + } else if (c == 0) { + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getProdCode(); + } else if (c == 1) { + return medInvtRow.getMedical() == null ? "" : medInvtRow.getMedical().getDescription(); + } else if (c == 2) { + return medInvtRow.getLot() == null ? "" : medInvtRow.getLot().getCode(); + } else if (c == 3) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getDueDate() != null) { + return medInvtRow.getLot().getDueDate().format(DATE_TIME_FORMATTER); + } + } + return ""; + } else if (c == 4) { + Double dblVal = medInvtRow.getTheoreticQty(); + return dblVal; + } else if (c == 5) { + Double dblValue = medInvtRow.getRealQty(); + return dblValue; + } else if (c == 6) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getCost() != null) { + return medInvtRow.getLot().getCost(); + } + } + return 0.0; + } else if (c == 7) { + if (medInvtRow.getLot() != null) { + if (medInvtRow.getLot().getCost() != null) { + return medInvtRow.getRealQty() * medInvtRow.getLot().getCost().doubleValue(); + } + } + return 0.0; + } + return null; + } + + @Override + public void setValueAt(Object value, int r, int c) { + if (r < inventoryRowSearchList.size()) { + MedicalInventoryRow invRow = inventoryRowSearchList.get(r); + if (c == 5) { + Integer intValue = 0; + try { + intValue = Integer.parseInt(value.toString()); + } catch (NumberFormatException e) { + intValue = 0; + } + + invRow.setRealqty(intValue); + inventoryRowSearchList.set(r, invRow); + jTableInventoryRow.updateUI(); + } + if (c == 6) { + Double doubleValue = 0.0; + try { + doubleValue = Double.parseDouble(value.toString()); + } catch (NumberFormatException e) { + doubleValue = 0.0; + } + Lot lot = invRow.getLot(); + if (lot != null) { + if (lot.getCode().equals("")) { + MessageDialog.error(null, "angal.inventoryrow.cannotchangethepriceofproductwithoutlot.msg"); + } else { + lot.setCost(new BigDecimal(doubleValue)); + try { + Lot saveLot = movStockInsertingManager.updateLot(lot); + invRow.setLot(saveLot); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + } + inventoryRowSearchList.set(r, invRow); + jTableInventoryRow.updateUI(); + } + } + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnEditable[columnIndex]; + } + } + + private List loadNewInventoryTable(String code) throws OHServiceException { + List inventoryRowsList = new ArrayList<>(); + List medicalWardList = new ArrayList<>(); + Medical medical = null; + if (code != null) { + medical = medicalBrowsingManager.getMedicalByMedicalCode(code); + if (medical != null) { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); + } else { + MessageDialog.error(null, MessageBundle.getMessage("angal.inventory.noproductfound.msg")); + } + } else { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); + } + medicalWardList.stream().forEach(medicalWard -> { + inventoryRowsList.add(new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, + medicalWard.getMedical(), medicalWard.getLot())); + }); + return inventoryRowsList; + } + + class DecimalFormatRenderer extends DefaultTableCellRenderer { + + private static final long serialVersionUID = 1L; + private final DecimalFormat formatter = new DecimalFormat("#,##0.00"); //$NON-NLS-1$ + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + // First format the cell value as required + Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + value = formatter.format((Number) value); + // setHorizontalAlignment(columnAlignment[column]); + if (!columnEditable[column]) { + cell.setBackground(Color.LIGHT_GRAY); + } + + // And pass it on to parent class + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } + } + + private JRadioButton getSpecificRadio() { + if (specificRadio == null) { + specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); + if (inventory != null) { + specificRadio.setSelected(false); + } else { + specificRadio.setSelected(true); + } + specificRadio.addActionListener(actionEvent -> { + + if (specificRadio.isSelected()) { + codeTextField.setEnabled(true); + searchTextField.setEnabled(false); + searchTextField.setText(""); + codeTextField.setText(""); + if (inventoryRowList != null) { + inventoryRowList.clear(); + } + if (inventoryRowSearchList != null) { + inventoryRowSearchList.clear(); + } + jTableInventoryRow.updateUI(); + ajustWidth(); + } + }); + } + return specificRadio; + } + + private JRadioButton getAllRadio() { + if (allRadio == null) { + allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); + if (inventory != null) { + allRadio.setSelected(true); + } else { + allRadio.setSelected(false); + } + allRadio.addActionListener(actionEvent -> { + if (allRadio.isSelected()) { + codeTextField.setEnabled(false); + searchTextField.setText(""); + codeTextField.setText(""); + searchTextField.setEnabled(true); + if (inventoryRowList != null) { + inventoryRowList.clear(); + } + if (inventoryRowSearchList != null) { + inventoryRowSearchList.clear(); + } + jTableInventoryRow.setModel(new InventoryRowModel()); + jTableInventoryRow.updateUI(); + code = null; + ajustWidth(); + } + }); + } + return allRadio; + } + + private JTextField getSearchTextField() { + if (searchTextField == null) { + searchTextField = new JTextField(); + searchTextField.setColumns(16); + TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.search.txt"), searchTextField, + Show.FOCUS_LOST); + suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + searchTextField.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void insertUpdate(DocumentEvent e) { + filterInventoryRow(); + ajustWidth(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + filterInventoryRow(); + ajustWidth(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + filterInventoryRow(); + ajustWidth(); + } + }); + searchTextField.setEnabled(false); + if (inventory != null) { + searchTextField.setEnabled(true); + } else { + searchTextField.setEnabled(false); + } + } + return searchTextField; + } + + private JLabel getDateInventoryLabel() { + if (dateInventoryLabel == null) { + dateInventoryLabel = new JLabel(MessageBundle.getMessage("angal.inventory.date.label")); + } + return dateInventoryLabel; + } + + private JTextField getCodeTextField() { + if (codeTextField == null) { + codeTextField = new JTextField(); + if (inventory != null) { + codeTextField.setEnabled(false); + } else { + codeTextField.setEnabled(true); + } + codeTextField.setColumns(10); + TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.common.code.txt"), codeTextField, + Show.FOCUS_LOST); + suggestion.setFont(new Font("Tahoma", Font.PLAIN, 12)); + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(JLabel.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + codeTextField.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + code = codeTextField.getText().trim(); + code = code.toLowerCase(); + try { + addInventoryRow(code); + } catch (OHServiceException e1) { + OHServiceExceptionUtil.showMessages(e1); + } + codeTextField.setText(""); + ajustWidth(); + } + } + }); + } + return codeTextField; + } + + private void filterInventoryRow() { + String s = searchTextField.getText(); + s.trim(); + inventoryRowSearchList = new ArrayList(); + for (MedicalInventoryRow invRow : inventoryRowList) { + if (!s.equals("")) { + String name = invRow.getSearchString(); + if (name.contains(s.toLowerCase())) + inventoryRowSearchList.add(invRow); + } else { + inventoryRowSearchList.add(invRow); + } + } + jTableInventoryRow.updateUI(); + searchTextField.requestFocus(); + } + + private void addInventoryRow(String code) throws OHServiceException { + List inventoryRowsList = new ArrayList(); + List medicalWardList = new ArrayList(); + Medical medical = null; + if (code != null) { + medical = medicalBrowsingManager.getMedicalByMedicalCode(code); + if (medical != null) { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); + } else { + medical = chooseMedical(code); + if (medical != null) { + boolean found = false; + if (inventoryRowSearchList != null) { + for (MedicalInventoryRow row : inventoryRowSearchList) { + if (row.getMedical().getCode().equals(medical.getCode())) { + found = true; + } + } + } + if (!found) { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false); + } + } + } + } else { + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); + } + if (mode.equals("new")) { + inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), + medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); + } else if (mode.equals("update")) { + if (medical != null) { + String medicalCode = medical.getProdCode(); + inventoryRowsList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()) + .stream() + .filter(medRow -> medRow.getMedical().getProdCode().equals(medicalCode)).toList(); + } + } + if (inventoryRowSearchList == null) { + inventoryRowSearchList = new ArrayList<>(); + } + for (MedicalInventoryRow inventoryRow : inventoryRowsList) { + inventoryRowSearchList.add(inventoryRow); + } + jTableInventoryRow.updateUI(); + } + + private Medical chooseMedical(String text) throws OHServiceException { + Map medicalMap; + List medicals = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false).stream() + .map(medicalWard -> medicalWard.getMedical()).toList(); + if (mode.equals("update")) { + medicals.clear(); + List inventoryRowListTemp = medicalInventoryRowManager + .getMedicalInventoryRowByInventoryId(inventory.getId()); + for (MedicalInventoryRow medicalInventoryRow : inventoryRowListTemp) { + medicals.add(medicalInventoryRow.getMedical()); + } + } + medicalMap = new HashMap(); + for (Medical med : medicals) { + String key = med.getProdCode().toLowerCase(); + key = med.getCode().toString().toLowerCase(); + medicalMap.put(key, med); + } + ArrayList medList = new ArrayList(); + for (Medical aMed : medicalMap.values()) { + if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { + medList.add(aMed); + } + } + Collections.sort(medList); + Medical med = null; + if (!medList.isEmpty()) { + MedicalPicker framas = new MedicalPicker(new StockMedModel(medList), medList); + framas.setSize(300, 400); + JDialog dialog = new JDialog(); + dialog.setLocationRelativeTo(null); + dialog.setSize(600, 350); + dialog.setLocationRelativeTo(null); + dialog.setModal(true); + dialog.setTitle(MessageBundle.getMessage("angal.medicalstock.multiplecharging.selectmedical.title")); + framas.setParentFrame(dialog); + dialog.setContentPane(framas); + dialog.setVisible(true); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + med = framas.getSelectedMedical(); + return med; + } + return null; + } + + private void ajustWidth() { + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventoryRow.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); + } + } + + private JLabel getReferenceLabel() { + if (referenceLabel == null) { + referenceLabel = new JLabel(MessageBundle.getMessage("angal.inventory.reference.label")); + } + return referenceLabel; + } + + private JTextField getReferenceTextField() { + if (referenceTextField == null) { + referenceTextField = new JTextField(); + referenceTextField.setColumns(10); + if (inventory != null && !mode.equals("new")) { + referenceTextField.setText(inventory.getInventoryReference()); + referenceTextField.setEnabled(false); + } + } + return referenceTextField; + } + + private JLabel getWardLabel() { + if (wardLabel == null) { + wardLabel = new JLabel(MessageBundle.getMessage("angal.inventory.selectward.label")); + } + return wardLabel; + } + + private JComboBox getWardComboBox() { + if (wardComboBox == null) { + wardComboBox = new JComboBox(); + List wardList; + try { + wardList = wardBrowserManager.getWards(); + } catch (OHServiceException e) { + wardList = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + for (Ward elem : wardList) { + wardComboBox.addItem(elem); + } + wardComboBox.setSelectedIndex(-1); + + wardComboBox.addItemListener(itemEvent -> { + + if (itemEvent.getStateChange() == ItemEvent.SELECTED) { + Object item = itemEvent.getItem(); + if (item instanceof Ward) { + wardSelected = (Ward) item; + wardId = wardSelected.getCode(); + List medicalWardInventory; + try { + medicalWardInventory = medicalInventoryManager + .getMedicalInventoryByStatusAndWard(InventoryType.ward.toString(), wardId); + } catch (OHServiceException e) { + medicalWardInventory = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + + if (medicalWardInventory != null) { + activedSomeComponents(); + } else { + MessageDialog.error(this, + "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); + return; + } + } + } + }); + } + return wardComboBox; + } + + private void disabledSomeComponents() { + jCalendarInventory.setEnabled(false); + searchTextField.setEnabled(false); + specificRadio.setEnabled(false); + codeTextField.setEnabled(false); + allRadio.setEnabled(false); + referenceTextField.setEnabled(false); + jTableInventoryRow.setEnabled(false); + saveButton.setEnabled(false); + validateButton.setEnabled(false); + printButton.setEnabled(false); + } + + private void activedSomeComponents() { + jCalendarInventory.setEnabled(true); + searchTextField.setEnabled(true); + specificRadio.setEnabled(true); + codeTextField.setEnabled(true); + allRadio.setEnabled(true); + referenceTextField.setEnabled(true); + jTableInventoryRow.setEnabled(true); + wardComboBox.setEnabled(false); + saveButton.setEnabled(true); + } + + private JLabel getLoaderLabel() { + if (loaderLabel == null) { + Icon icon = new ImageIcon("rsc/icons/oh_loader.GIF"); + loaderLabel = new JLabel(""); + loaderLabel.setIcon(icon); + loaderLabel.setVisible(false); + } + return loaderLabel; + } } From a5a8a9e057c42d426d963f1777c2f255c8d98a18 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 19 Nov 2024 17:54:21 +0100 Subject: [PATCH 25/83] Applying suggestion to change --- bundle/language_en.properties | 6 +- .../gui/InventoryWardBrowser.java | 20 +- .../gui/InventoryWardEdit.java | 403 ++++-------------- 3 files changed, 94 insertions(+), 335 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 60b5303403..090d6e9e8a 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -672,10 +672,7 @@ angal.inventory.cancelednoteditable.msg angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg = Cannot create another inventory with other in progress in this ward. angal.inventory.cannotsaveinventorywithoutproducts.msg = Cannot save inventory without products. angal.inventory.chargetype.label = Charge Type: -angal.inventory.choosechargetypebeforevalidation.msg = Please choose the charge type and save the inventory before validation. angal.inventory.choosedestinationbeforevalidation.msg = Please choose the destination and save the inventory before validation. -angal.inventory.choosedischargetypebeforevalidation.msg = Please choose the discharge type and save the inventory before validation. -angal.inventory.choosesupplierbeforevalidation.msg = Please choose the supplier and save the inventory before validation. angal.inventory.clean.btn = Clean Table angal.inventory.clean.btn.key = T angal.inventory.date.label = Inventory's date @@ -690,6 +687,7 @@ angal.inventory.doyoureallywanttodeletethisinventoryrow.msg angal.inventory.doyouwanttoaddallnotyetlistedproducts.msg = Do you want to add all not yet listed products? angal.inventory.doyouwanttocontinueediting.msg = Do you want to continue editing? angal.inventory.doyouwanttosavethechanges.msg = Do you want to save the changes? +angal.inventory.doyoureallywanttovalidatethisinventory.msg = Do you really want to validate this inventory? angal.inventory.draft = Draft angal.inventory.edit.title = Edit Inventory angal.inventory.error.msg = Error during some products's recording @@ -708,12 +706,14 @@ angal.inventory.noproductfound.msg angal.inventory.notdateinfuture.msg = A date in the future is not allowed. angal.inventory.page.text = Page angal.inventory.pages.text = Pages +angal.inventory.pleasefilloutreasonfield.msg = please fill out the reason field. angal.inventory.pleaseselectatleastoneinventoryrow.msg = Please select at least one inventory row. angal.inventory.pleaseselectonlyoneinventory.msg = Please select only one inventory. angal.inventory.pleaseselectinventory.msg = Please select inventory. angal.inventory.previousarrow.btn = < angal.inventory.productcode.text = Product's code angal.inventory.realqty.col = Real quantity +angal.inventory.reason.label = Reason angal.inventory.reference.label = Inventory's reference angal.inventory.referencealreadyused.msg = Reference is already used. angal.inventory.referenceshow.col = Reference diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index cfe24994fb..221cd01f8e 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -82,7 +82,7 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListen private JPanel panelContent; private JButton closeButton; private JButton newButton; - private JButton updateButton; + private JButton editButton; private JButton deleteButton; private JButton viewButton; private JScrollPane scrollPaneInventory; @@ -260,7 +260,7 @@ private JPanel getPanelFooter() { panelFooter.add(getNewButton()); panelFooter.add(getViewButton()); - panelFooter.add(getUpdateButton()); + panelFooter.add(getEditButton()); panelFooter.add(getDeleteButton()); panelFooter.add(getCloseButton()); } @@ -330,11 +330,11 @@ private JButton getNewButton() { return newButton; } - private JButton getUpdateButton() { - updateButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); - updateButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); - updateButton.setEnabled(false); - updateButton.addActionListener(actionEvent -> { + private JButton getEditButton() { + editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); + editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); + editButton.setEnabled(false); + editButton.addActionListener(actionEvent -> { MedicalInventory inventory; if (jTableInventory.getSelectedRowCount() > 1) { MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); @@ -354,7 +354,7 @@ private JButton getUpdateButton() { InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); - return updateButton; + return editButton; } private JButton getViewButton() { @@ -438,11 +438,11 @@ private JTable getJTableInventory() { if (e.getValueIsAdjusting()) { int[] selectedRows = jTableInventory.getSelectedRows(); if (selectedRows.length == 1) { - updateButton.setEnabled(true); + editButton.setEnabled(true); viewButton.setEnabled(true); deleteButton.setEnabled(true); } else { - updateButton.setEnabled(false); + editButton.setEnabled(false); viewButton.setEnabled(false); deleteButton.setEnabled(false); } diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 93e866b5e1..5fa931db90 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -78,16 +78,12 @@ import org.isf.medicalinventory.model.MedicalInventoryRow; import org.isf.medicals.manager.MedicalBrowsingManager; import org.isf.medicals.model.Medical; -import org.isf.medicalstock.manager.MovStockInsertingManager; import org.isf.medicalstock.model.Lot; import org.isf.medicalstockward.manager.MovWardBrowserManager; import org.isf.medicalstockward.model.MedicalWard; import org.isf.medstockmovtype.manager.MedicalDsrStockMovementTypeBrowserManager; -import org.isf.medstockmovtype.model.MovementType; import org.isf.menu.manager.Context; import org.isf.menu.manager.UserBrowsingManager; -import org.isf.supplier.manager.SupplierBrowserManager; -import org.isf.supplier.model.Supplier; import org.isf.utils.db.NormalizeString; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.gui.OHServiceExceptionUtil; @@ -190,23 +186,17 @@ private void fireInventoryInserted() { private JTextField referenceTextField; private JTextField jTextFieldEditor; private JLabel wardLabel; - private JLabel chargeLabel; - private JLabel dischargeLabel; - private JLabel supplierLabel; private JLabel destinationLabel; + private JLabel reasonLabel; private JComboBox wardComboBox; - private JComboBox chargeComboBox; - private JComboBox dischargeComboBox; - private JComboBox supplierComboBox; private JComboBox destinationComboBox; + private JTextField reasonTextField; private Ward wardSelected; private JLabel loaderLabel; private boolean selectAll; private String newReference; - private MovementType chargeType; - private MovementType dischargeType; - private Supplier supplier; private Ward destination; + private String reason; private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext() .getBean(MedicalInventoryManager.class); @@ -216,11 +206,8 @@ private void fireInventoryInserted() { .getBean(MedicalBrowsingManager.class); private MovWardBrowserManager movWardBrowserManager = Context.getApplicationContext() .getBean(MovWardBrowserManager.class); - private MovStockInsertingManager movStockInsertingManager = Context.getApplicationContext() - .getBean(MovStockInsertingManager.class); private MedicalDsrStockMovementTypeBrowserManager medStockMovTypeManager = Context.getApplicationContext() .getBean(MedicalDsrStockMovementTypeBrowserManager.class); - private SupplierBrowserManager supplierBrowserManager = Context.getApplicationContext().getBean(SupplierBrowserManager.class); public InventoryWardEdit() { @@ -274,9 +261,6 @@ public void windowClosing(WindowEvent e) { jCalendarInventory.setEnabled(false); specificRadio.setEnabled(false); allRadio.setEnabled(false); - chargeComboBox.setEnabled(false); - dischargeComboBox.setEnabled(false); - supplierComboBox.setEnabled(false); destinationComboBox.setEnabled(false); wardComboBox.setEnabled(false); validateButton.setVisible(false); @@ -290,9 +274,6 @@ public void windowClosing(WindowEvent e) { jCalendarInventory.setEnabled(true); specificRadio.setEnabled(true); allRadio.setEnabled(true); - chargeComboBox.setEnabled(true); - dischargeComboBox.setEnabled(true); - supplierComboBox.setEnabled(true); destinationComboBox.setEnabled(true); wardComboBox.setEnabled(true); validateButton.setVisible(true); @@ -358,54 +339,32 @@ private JPanel getPanelHeader() { gbc_statusLabel.gridy = 1; gbc_statusLabel.gridheight = 3; panelHeader.add(getStatusLabel(), gbc_statusLabel); - GridBagConstraints gbc_chargeLabel = new GridBagConstraints(); - gbc_chargeLabel.insets = new Insets(0, 0, 3, 3); - gbc_chargeLabel.gridx = 0; - gbc_chargeLabel.gridy = 2; - panelHeader.add(getChargeLabel(), gbc_chargeLabel); - GridBagConstraints gbc_chargeComboBox = new GridBagConstraints(); - gbc_chargeComboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_chargeComboBox.insets = new Insets(0, 0, 3, 3); - gbc_chargeComboBox.gridx = 1; - gbc_chargeComboBox.gridy = 2; - panelHeader.add(getChargeComboBox(), gbc_chargeComboBox); - GridBagConstraints gbc_supplierLabel = new GridBagConstraints(); - gbc_supplierLabel.anchor = GridBagConstraints.EAST; - gbc_supplierLabel.insets = new Insets(0, 0, 3, 3); - gbc_supplierLabel.gridx = 2; - gbc_supplierLabel.gridy = 2; - panelHeader.add(getSupplierLabel(), gbc_supplierLabel); - GridBagConstraints gbc_supplierComboBox = new GridBagConstraints(); - gbc_supplierComboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_supplierComboBox.insets = new Insets(0, 0, 3, 3); - gbc_supplierComboBox.gridx = 3; - gbc_supplierComboBox.gridy = 2; - panelHeader.add(getSupplierComboBox(), gbc_supplierComboBox); - - GridBagConstraints gbc_dischargeLabel = new GridBagConstraints(); - gbc_dischargeLabel.insets = new Insets(0, 0, 3, 3); - gbc_dischargeLabel.gridx = 0; - gbc_dischargeLabel.gridy = 3; - panelHeader.add(getDischargeLabel(), gbc_dischargeLabel); - GridBagConstraints gbc_dischargeComboBox = new GridBagConstraints(); - gbc_dischargeComboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_dischargeComboBox.insets = new Insets(0, 0, 3, 3); - gbc_dischargeComboBox.gridx = 1; - gbc_dischargeComboBox.gridy = 3; - panelHeader.add(getDischargeComboBox(), gbc_dischargeComboBox); GridBagConstraints gbc_destinationLabel = new GridBagConstraints(); gbc_destinationLabel.anchor = GridBagConstraints.EAST; gbc_destinationLabel.insets = new Insets(0, 0, 3, 3); - gbc_destinationLabel.gridx = 2; + gbc_destinationLabel.gridx = 0; gbc_destinationLabel.gridy = 3; panelHeader.add(getDestinationLabel(), gbc_destinationLabel); GridBagConstraints gbc_destinationComboBox = new GridBagConstraints(); gbc_destinationComboBox.fill = GridBagConstraints.HORIZONTAL; gbc_destinationComboBox.insets = new Insets(0, 0, 3, 3); - gbc_destinationComboBox.gridx = 3; + gbc_destinationComboBox.gridx = 1; gbc_destinationComboBox.gridy = 3; panelHeader.add(getDestinationComboBox(), gbc_destinationComboBox); + GridBagConstraints gbc_reasonLabel = new GridBagConstraints(); + gbc_reasonLabel.anchor = GridBagConstraints.EAST; + gbc_reasonLabel.insets = new Insets(0, 0, 3,3); + gbc_reasonLabel.gridx = 2; + gbc_reasonLabel.gridy = 3; + panelHeader.add(getReasonLabel(), gbc_reasonLabel); + GridBagConstraints gbc_reasonTexField = new GridBagConstraints(); + gbc_reasonTexField.insets = new Insets(0, 0, 5, 5); + gbc_reasonTexField.fill = GridBagConstraints.HORIZONTAL; + gbc_reasonTexField.gridx = 3; + gbc_reasonTexField.gridy = 3; + panelHeader.add(getReasonTextField(), gbc_reasonTexField); + GridBagConstraints gbc_specificRadio = new GridBagConstraints(); gbc_specificRadio.anchor = GridBagConstraints.EAST; gbc_specificRadio.insets = new Insets(0, 0, 0, 5); @@ -490,10 +449,8 @@ private JButton getSaveButton() { if (!inventoryRowsToDelete.isEmpty()) { medicalInventoryRowManager.deleteMedicalInventoryRows(inventoryRowsToDelete); } - chargeType = (MovementType) chargeComboBox.getSelectedItem(); - dischargeType = (MovementType) dischargeComboBox.getSelectedItem(); - supplier = (Supplier) supplierComboBox.getSelectedItem(); destination = (Ward) destinationComboBox.getSelectedItem(); + reason = reasonTextField.getText(); if (inventory == null && mode.equals("new")) { newReference = referenceTextField.getText().trim(); boolean refExist; @@ -508,38 +465,12 @@ private JButton getSaveButton() { inventory.setStatus(state); inventory.setUser(user); inventory.setInventoryType(InventoryType.ward.toString()); - inventory.setChargeType(chargeType != null ? chargeType.getCode() : null); - inventory.setDischargeType(dischargeType != null ? dischargeType.getCode() : null); - inventory.setSupplier(supplier != null ? supplier.getSupId() : null); inventory.setDestination(destination != null ? destination.getCode() : null); inventory.setWard(wardSelected != null ? wardSelected.getCode() : null); + inventory.setReason(reason); inventory = medicalInventoryManager.newMedicalInventory(inventory); for (MedicalInventoryRow medicalInventoryRow : inventoryRowSearchList) { medicalInventoryRow.setInventory(inventory); - Lot lot = medicalInventoryRow.getLot(); - String lotCode; - Medical medical = medicalInventoryRow.getMedical(); - if (lot != null) { - lotCode = lot.getCode(); - Lot lotExist; - lotExist = movStockInsertingManager.getLot(lotCode); - if (lotExist != null) { - Lot lotStore; - lotStore = movStockInsertingManager.updateLot(lot); - medicalInventoryRow.setLot(lotStore); - } else { - if (lot.getDueDate() != null) { - Lot lotStore; - lotStore = movStockInsertingManager.storeLot(lotCode, lot, medical); - medicalInventoryRow.setLot(lotStore); - medicalInventoryRow.setNewLot(true); - } else { - medicalInventoryRow.setLot(null); - } - } - } else { - medicalInventoryRow.setLot(null); - } medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); } mode = "update"; @@ -552,11 +483,9 @@ private JButton getSaveButton() { dispose(); } } else if (inventory != null && mode.equals("update")) { - String lastCharge = inventory.getChargeType(); - String lastDischarge = inventory.getDischargeType(); - Integer lastSupplier = inventory.getSupplier(); String lastDestination = inventory.getDestination(); String lastReference = inventory.getInventoryReference(); + String lastReason = inventory.getReason(); newReference = referenceTextField.getText().trim(); MedicalInventory existingInventory = medicalInventoryManager.getInventoryByReference(newReference); if (existingInventory != null && !Objects.equals(existingInventory.getId(), inventory.getId())) { @@ -565,11 +494,8 @@ private JButton getSaveButton() { } if (inventoryRowListAdded.isEmpty()) { if ((destination != null && !destination.getCode().equals(lastDestination)) - || (chargeType != null && !chargeType.getCode().equals(lastCharge)) - || (dischargeType != null && !dischargeType.getCode().equals(lastDischarge)) - || (supplier != null && !supplier.getSupId().equals(lastSupplier)) || (destination == null && lastDestination != null) - || (chargeType == null && lastCharge != null) || (dischargeType == null && lastDischarge != null) - || (supplier == null && lastSupplier != null) || !lastReference.equals(newReference) + || (destination == null && lastDestination != null) || !reason.equals(lastReason) + || !newReference.equals(lastReference) ) { if (!inventory.getInventoryDate().equals(dateInventory)) { inventory.setInventoryDate(dateInventory); @@ -577,17 +503,12 @@ private JButton getSaveButton() { if (!inventory.getUser().equals(user)) { inventory.setUser(user); } - if (!lastReference.equals(newReference)) { + if (!newReference.equals(lastReference)) { inventory.setInventoryReference(newReference); } - MovementType charge = (MovementType) chargeComboBox.getSelectedItem(); - inventory.setChargeType(charge != null ? charge.getCode() : null); - - MovementType discharge = (MovementType) dischargeComboBox.getSelectedItem(); - inventory.setDischargeType(discharge != null ? discharge.getCode() : null); - - Supplier supplier1 = (Supplier) supplierComboBox.getSelectedItem(); - inventory.setSupplier(supplier1 != null ? supplier1.getSupId() : null); + if (!reason.equals(lastReason)) { + inventory.setReason(reason); + } Ward destination = (Ward) destinationComboBox.getSelectedItem(); inventory.setDestination(destination != null ? destination.getCode() : null); @@ -631,80 +552,21 @@ private JButton getSaveButton() { inventory.setInventoryReference(newReference); } - MovementType charge = (MovementType) chargeComboBox.getSelectedItem(); - inventory.setChargeType(charge != null ? charge.getCode() : null); - - MovementType discharge = (MovementType) dischargeComboBox.getSelectedItem(); - inventory.setDischargeType(discharge != null ? discharge.getCode() : null); - - Supplier supplier1 = (Supplier) supplierComboBox.getSelectedItem(); - inventory.setSupplier(supplier1 != null ? supplier1.getSupId() : null); - Ward destination = (Ward) destinationComboBox.getSelectedItem(); inventory.setDestination(destination != null ? destination.getCode() : null); inventory = medicalInventoryManager.updateMedicalInventory(inventory); for (MedicalInventoryRow medicalInventoryRow : inventoryRowSearchList) { - Medical medical = medicalInventoryRow.getMedical(); - Lot lot = medicalInventoryRow.getLot(); - String lotCode; medicalInventoryRow.setInventory(inventory); int id = medicalInventoryRow.getId(); if (id == 0) { - if (lot != null) { - lotCode = lot.getCode(); - boolean isExist; - Lot lotExist = movStockInsertingManager.getLot(lotCode); - isExist = (lotExist != null); - if (!isExist) { - if (lot.getDueDate() != null) { - Lot lotStore = movStockInsertingManager.storeLot(lotCode, lot, medical); - medicalInventoryRow.setLot(lotStore); - medicalInventoryRow.setNewLot(true); - } else { - Lot lotStore = movStockInsertingManager.updateLot(lot); - medicalInventoryRow.setLot(lotStore); - } - } else { - Lot lotStore = movStockInsertingManager.updateLot(lot); - medicalInventoryRow.setLot(lotStore); - } - } medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); } else { - lot = medicalInventoryRow.getLot(); double reatQty = medicalInventoryRow.getRealQty(); medicalInventoryRow = medicalInventoryRowManager.getMedicalInventoryRowById(id); medicalInventoryRow.setRealqty(reatQty); - - if (lot != null) { - lotCode = lot.getCode(); - Lot lotExist = movStockInsertingManager.getLot(lotCode); - if (lotExist != null) { - Lot lotStore; - lotExist.setDueDate(lot.getDueDate()); - lotExist.setPreparationDate(lot.getPreparationDate()); - lotExist.setCost(lot.getCost()); - lotStore = movStockInsertingManager.updateLot(lotExist); - medicalInventoryRow.setLot(lotStore); - } else { - if (lot.getDueDate() != null) { - Lot lotStore = movStockInsertingManager.storeLot(lotCode, lot, medical); - medicalInventoryRow.setLot(lotStore); - medicalInventoryRow.setNewLot(true); - } else { - medicalInventoryRow.setLot(null); - } - } - } else { - medicalInventoryRow.setLot(null); - } - if (medicalInventoryRow.getId() == 0) { - medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); - } else { - medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow); - } + medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow); } } MessageDialog.info(null, "angal.inventory.update.success.msg"); @@ -734,30 +596,23 @@ private JButton getValidateButton() { } int reset = MessageDialog.yesNo(null, "angal.inventory.doyoureallywanttovalidatethisinventory.msg"); if (reset == JOptionPane.YES_OPTION) { - String dischargeCode = inventory.getDischargeType(); - String chargeCode = inventory.getChargeType(); - Integer supplierId = inventory.getSupplier(); String destinationCode = inventory.getDestination(); - if (chargeCode == null || chargeCode.isEmpty()) { - MessageDialog.error(null, "angal.inventory.choosechargetypebeforevalidation.msg"); - return; - } - if (dischargeCode == null || dischargeCode.isEmpty()) { - MessageDialog.error(null, "angal.inventory.choosedischargetypebeforevalidation.msg"); - return; - } - if (supplierId == null || supplierId == 0) { - MessageDialog.error(null, "angal.inventory.choosesupplierbeforevalidation.msg"); - return; - } if (destinationCode == null || destinationCode.isEmpty()) { MessageDialog.error(null, "angal.inventory.choosedestinationbeforevalidation.msg"); return; } + if (inventory.getReason() == null || inventory.getReason().isEmpty()) { + if (!reasonTextField.getText().isEmpty()) { + inventory.setReason(reasonTextField.getText()); + } else { + MessageDialog.error(null, "angal.inventory.pleasefilloutreasonfield.msg"); + return; + } + } // validate inventory int inventoryRowsSize = inventoryRowSearchList.size(); try { - medicalInventoryManager.validateMedicalInventoryRow(inventory, inventoryRowSearchList); + medicalInventoryManager.validateMedicalWardInventoryRow(inventory, inventoryRowSearchList); } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); try { @@ -870,29 +725,22 @@ private JButton getCloseButton() { closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); closeButton.addActionListener(actionEvent -> { - String lastCharge = null; - String lastDischarge = null; - Integer lastSupplier = null; String lastDestination = null; String lastReference = null; + String lastReason = null; + reason = reasonTextField.getText(); newReference = referenceTextField.getText().trim(); LocalDateTime lastDate = dateInventory; if (inventory != null) { - lastCharge = inventory.getChargeType(); - lastDischarge = inventory.getDischargeType(); - lastSupplier = inventory.getSupplier(); lastDestination = inventory.getDestination(); lastReference = inventory.getInventoryReference(); lastDate = inventory.getInventoryDate(); + lastReason = inventory.getReason(); } if (!inventoryRowsToDelete.isEmpty() || (destination != null && !destination.getCode().equals(lastDestination)) - || (chargeType != null && !chargeType.getCode().equals(lastCharge)) - || (dischargeType != null && !dischargeType.getCode().equals(lastDischarge)) - || (supplier != null && !supplier.getSupId().equals(lastSupplier)) - || (destination == null && lastDestination != null) || (chargeType == null && lastCharge != null) - || (dischargeType == null && lastDischarge != null) || (supplier == null && lastSupplier != null) - || !Objects.equals(lastReference, newReference) || !lastDate.toLocalDate().equals(dateInventory.toLocalDate()) + || (destination == null && lastDestination != null) || !newReference.equals(lastReference) + || !reason.equals(lastReason) || !lastDate.toLocalDate().equals(dateInventory.toLocalDate()) ) { int reset = MessageDialog.yesNoCancel(null, "angal.inventory.doyouwanttosavethechanges.msg"); if (reset == JOptionPane.YES_OPTION) { @@ -1163,23 +1011,11 @@ private List getMedicalInventoryRows(String code) throws OH } else { medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); } - medicalWardList.forEach(medicalWard -> inventoryRowsList.add(new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, - medicalWard.getMedical(), medicalWard.getLot()))); - for (MedicalWard medicalWard : medicalWardList) { - lots = movStockInsertingManager.getLotByMedical(medicalWard.getMedical(), false); - double actualQty = medicalWard.getMedical().getInqty() - medicalWard.getMedical().getOutqty(); - if (lots.isEmpty()) { - inventoryRowTemp = new MedicalInventoryRow(0, actualQty, actualQty, null, medicalWard.getMedical(), null); - if (!existInInventorySearchList(inventoryRowTemp)) { - inventoryRowsList.add(inventoryRowTemp); - } - } else { - for (Lot lot : lots) { - inventoryRowTemp = new MedicalInventoryRow(0, lot.getMainStoreQuantity(), lot.getMainStoreQuantity(), null, medicalWard.getMedical(), lot); - if (!existInInventorySearchList(inventoryRowTemp)) { - inventoryRowsList.add(inventoryRowTemp); - } - } + for (MedicalWard medicalWard: medicalWardList) { + inventoryRowTemp = new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, + medicalWard.getMedical(), medicalWard.getLot()); + if (!existInInventorySearchList(inventoryRowTemp)) { + inventoryRowsList.add(inventoryRowTemp); } } return inventoryRowsList; @@ -1231,6 +1067,9 @@ private JRadioButton getAllRadio() { if (allRadio.isSelected()) { codeTextField.setEnabled(false); codeTextField.setText(""); + if (wardId.isEmpty()) { + wardId = wardSelected.getCode(); + } if (!inventoryRowSearchList.isEmpty()) { int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttoaddallnotyetlistedproducts.msg"); if (info == JOptionPane.YES_OPTION) { @@ -1447,27 +1286,6 @@ private JLabel getWardLabel() { return wardLabel; } - private JLabel getChargeLabel() { - if (chargeLabel == null) { - chargeLabel = new JLabel(MessageBundle.getMessage("angal.inventory.chargetype.label")); - } - return chargeLabel; - } - - private JLabel getDischargeLabel() { - if (dischargeLabel == null) { - dischargeLabel = new JLabel(MessageBundle.getMessage("angal.inventory.dischargetype.label")); - } - return dischargeLabel; - } - - private JLabel getSupplierLabel() { - if (supplierLabel == null) { - supplierLabel = new JLabel(MessageBundle.getMessage("angal.inventory.supplier.label")); - } - return supplierLabel; - } - private JLabel getDestinationLabel() { if (destinationLabel == null) { destinationLabel = new JLabel(MessageBundle.getMessage("angal.inventory.destination.label")); @@ -1475,6 +1293,13 @@ private JLabel getDestinationLabel() { return destinationLabel; } + private JLabel getReasonLabel() { + if (reasonLabel == null) { + reasonLabel = new JLabel(MessageBundle.getMessage("angal.inventory.reason.label")); + } + return reasonLabel; + } + private JComboBox getWardComboBox() { if (wardComboBox == null) { wardComboBox = new JComboBox<>(); @@ -1509,16 +1334,20 @@ private JComboBox getWardComboBox() { if (item instanceof Ward) { wardSelected = (Ward) item; wardId = wardSelected.getCode(); - List medicalWardInventory; + List medicalWardInventoryDraft; + List medicalWardInventoryValidated; try { - medicalWardInventory = medicalInventoryManager - .getMedicalInventoryByStatusAndWard(InventoryType.ward.toString(), wardId); + medicalWardInventoryDraft = medicalInventoryManager + .getMedicalInventoryByStatusAndWard(InventoryStatus.draft.toString(), wardId); + medicalWardInventoryValidated = medicalInventoryManager + .getMedicalInventoryByStatusAndWard(InventoryStatus.validated.toString(), wardId); } catch (OHServiceException e) { - medicalWardInventory = new ArrayList<>(); + medicalWardInventoryDraft = new ArrayList<>(); + medicalWardInventoryValidated = new ArrayList<>(); OHServiceExceptionUtil.showMessages(e); } - if (medicalWardInventory != null) { + if (medicalWardInventoryDraft.isEmpty() && medicalWardInventoryValidated.isEmpty()) { activedSomeComponents(); } else { MessageDialog.error(this, @@ -1531,85 +1360,6 @@ private JComboBox getWardComboBox() { return wardComboBox; } - private JComboBox getChargeComboBox() { - MovementType movementSelected = null; - if (chargeComboBox == null) { - chargeComboBox = new JComboBox<>(); - try { - List movementTypes = medStockMovTypeManager.getMedicalDsrStockMovementType(); - chargeComboBox.addItem(null); - for (MovementType movementType: movementTypes) { - if (movementType.getType().equals("+")) { - chargeComboBox.addItem(movementType); - if (inventory != null && movementType.getCode().equals(inventory.getChargeType())) { - movementSelected = movementType; - } - } - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - if (inventory != null) { - chargeComboBox.setSelectedItem(movementSelected); - chargeType = movementSelected; - } - chargeComboBox.addActionListener(actionEvent -> chargeType = (MovementType) chargeComboBox.getSelectedItem()); - } - return chargeComboBox; - } - - private JComboBox getDischargeComboBox() { - MovementType movementSelected = null; - if (dischargeComboBox == null) { - dischargeComboBox = new JComboBox<>(); - try { - List movementTypes = medStockMovTypeManager.getMedicalDsrStockMovementType(); - dischargeComboBox.addItem(null); - for (MovementType movementType: movementTypes) { - if (movementType.getType().equals("-")) { - dischargeComboBox.addItem(movementType); - if (inventory != null && movementType.getCode().equals(inventory.getDischargeType())) { - movementSelected = movementType; - } - } - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - if (inventory != null) { - dischargeComboBox.setSelectedItem(movementSelected); - dischargeType = movementSelected; - } - dischargeComboBox.addActionListener(actionEvent -> dischargeType = (MovementType) dischargeComboBox.getSelectedItem()); - } - return dischargeComboBox; - } - - private JComboBox getSupplierComboBox() { - Supplier supplierSelected = null; - if (supplierComboBox == null) { - supplierComboBox = new JComboBox<>(); - try { - List suppliers = supplierBrowserManager.getList(); - supplierComboBox.addItem(null); - for (Supplier supplier1: suppliers) { - supplierComboBox.addItem(supplier1); - if (inventory != null && Objects.equals(supplier1.getSupId(), inventory.getSupplier())) { - supplierSelected = supplier1; - } - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - if (inventory != null) { - supplierComboBox.setSelectedItem(supplierSelected); - supplier = supplierSelected; - } - supplierComboBox.addActionListener(actionEvent -> supplier = (Supplier) supplierComboBox.getSelectedItem()); - } - return supplierComboBox; - } - private JComboBox getDestinationComboBox() { Ward destinationSelected = null; if (destinationComboBox == null) { @@ -1635,6 +1385,17 @@ private JComboBox getDestinationComboBox() { return destinationComboBox; } + private JTextField getReasonTextField() { + if (reasonTextField == null) { + reasonTextField = new JTextField(); + reasonTextField.setColumns(10); + if (inventory != null && !mode.equals("new")) { + reasonTextField.setText(inventory.getReason()); + } + } + return reasonTextField; + } + private void disabledSomeComponents() { jCalendarInventory.setEnabled(false); specificRadio.setEnabled(false); @@ -1643,10 +1404,9 @@ private void disabledSomeComponents() { referenceTextField.setEnabled(false); jTableInventoryRow.setEnabled(false); saveButton.setEnabled(false); - chargeComboBox.setEnabled(false); - dischargeComboBox.setEnabled(false); - supplierComboBox.setEnabled(false); destinationComboBox.setEnabled(false); + reasonTextField.setEnabled(false); + deleteButton.setEnabled(false); } private void activedSomeComponents() { @@ -1658,10 +1418,9 @@ private void activedSomeComponents() { jTableInventoryRow.setEnabled(true); wardComboBox.setEnabled(false); saveButton.setEnabled(true); - chargeComboBox.setEnabled(true); - dischargeComboBox.setEnabled(true); - supplierComboBox.setEnabled(true); destinationComboBox.setEnabled(true); + reasonTextField.setEnabled(true); + deleteButton.setEnabled(true); } private JLabel getLoaderLabel() { From c1c94fac0b4272c7235db70474f3f1f65e897a29 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 20 Nov 2024 11:46:00 +0100 Subject: [PATCH 26/83] Add new message bundle --- bundle/language_en.properties | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 9dd85439ed..b750b25082 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -706,6 +706,10 @@ angal.inventory.medical.col angal.inventory.mustenterareference.msg = You must enter a reference. angal.inventory.nextarrow.btn = > angal.inventory.new.title = New inventory +angal.inventory.newlotshavebeenaddedforsomemedicalward.fmt.msg = New lot(s) have been found by new movement(s) in ward store for: {0} +angal.inventory.newlotshavebeenaddedforsomemedical.detail.fmt.msg = {0} lot: {1} qty: {2} +angal.inventory.newmedicalshavebeenfoundward.fmt.msg = New medical(s) have been found by new movement(s) in ward store for: {0} +angal.inventory.newmedicalshavebeenfound.detail.fmt.msg = {0} lot: {1} qty: {2} angal.inventory.noproduct.msg = Product is not found. angal.inventory.noproductfound.msg = No medical found angal.inventory.notdateinfuture.msg = A date in the future is not allowed. @@ -733,6 +737,8 @@ angal.inventory.state.inprogress.txt angal.inventory.state.validate.txt = Validate angal.inventory.supplier.label = Supplier: angal.inventory.theorticalqty.col = Theoretical +angal.inventory.theoreticalqtyhavebeenupdatedforsomemedicalward.fmt.msg = Theoretical(s) quantity(ies) have been updated by new movement(s) in ward store for: {0} +angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.detail.fmt.msg = {0} lot: {1} qty: {2} -> {3} ({4}) angal.inventory.totalprice.col = Total price quantity angal.inventory.unitprice.col = Unit price angal.inventory.update.error.msg = Inventory not updated. From dff24b226e8f6f7a8123d8b9a448f2dc5a377d62 Mon Sep 17 00:00:00 2001 From: NKONGA Andy <59751611+JantBogard@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:51:29 +0100 Subject: [PATCH 27/83] Fix indentations issue --- .../gui/InventoryWardBrowser.java | 348 +++++++++--------- 1 file changed, 174 insertions(+), 174 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 221cd01f8e..2bf96ce8fe 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -135,47 +135,47 @@ public void windowClosing(WindowEvent e) { dispose(); } }); - pagesCombo.setEditable(true); - previous.setEnabled(false); + pagesCombo.setEditable(true); + previous.setEnabled(false); + next.setEnabled(false); + next.addActionListener(actionEvent -> { + if (!previous.isEnabled()) { + previous.setEnabled(true); + } + startIndex += PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex + PAGE_SIZE > totalRows) { next.setEnabled(false); - next.addActionListener(actionEvent -> { - if (!previous.isEnabled()) { - previous.setEnabled(true); - } - startIndex += PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex + PAGE_SIZE > totalRows) { - next.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - }); - - previous.addActionListener(actionEvent -> { - if (!next.isEnabled()) { - next.setEnabled(true); - } - startIndex -= PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex < PAGE_SIZE) { - previous.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - }); - pagesCombo.addItemListener(itemEvent -> { - int eventID = itemEvent.getStateChange(); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + }); - if (eventID == ItemEvent.SELECTED) { - int page_number = (Integer) pagesCombo.getSelectedItem(); - startIndex = (page_number - 1) * PAGE_SIZE; + previous.addActionListener(actionEvent -> { + if (!next.isEnabled()) { + next.setEnabled(true); + } + startIndex -= PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex < PAGE_SIZE) { + previous.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + }); + pagesCombo.addItemListener(itemEvent -> { + int eventID = itemEvent.getStateChange(); - next.setEnabled(startIndex + PAGE_SIZE <= totalRows); - previous.setEnabled(page_number != 1); - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; - pagesCombo.setEnabled(true); - } - }); + next.setEnabled(startIndex + PAGE_SIZE <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + + pagesCombo.setEnabled(true); + } + }); } private JPanel getPanelHeader() { @@ -248,15 +248,15 @@ private JPanel getPanelContent() { private JPanel getPanelFooter() { if (panelFooter == null) { panelFooter = new JPanel(); - next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); - next.setMnemonic(KeyEvent.VK_RIGHT); - previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); - next.setMnemonic(KeyEvent.VK_LEFT); + next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); + next.setMnemonic(KeyEvent.VK_RIGHT); + previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); + next.setMnemonic(KeyEvent.VK_LEFT); - panelFooter.add(previous); - panelFooter.add(pagesCombo); - panelFooter.add(under); - panelFooter.add(next); + panelFooter.add(previous); + panelFooter.add(pagesCombo); + panelFooter.add(under); + panelFooter.add(next); panelFooter.add(getNewButton()); panelFooter.add(getViewButton()); @@ -330,87 +330,87 @@ private JButton getNewButton() { return newButton; } - private JButton getEditButton() { - editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); - editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); - editButton.setEnabled(false); - editButton.addActionListener(actionEvent -> { - MedicalInventory inventory; - if (jTableInventory.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); - return; - } - int selectedRow = jTableInventory.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); - return; - } - inventory = inventoryList.get(selectedRow); - if (inventory.getStatus().equals(InventoryStatus.canceled.toString())) { - MessageDialog.error(this, "angal.inventory.cancelednoteditable.msg"); - return; - } - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "update"); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); - return editButton; - } + private JButton getEditButton() { + editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); + editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); + editButton.setEnabled(false); + editButton.addActionListener(actionEvent -> { + MedicalInventory inventory; + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + inventory = inventoryList.get(selectedRow); + if (inventory.getStatus().equals(InventoryStatus.canceled.toString())) { + MessageDialog.error(this, "angal.inventory.cancelednoteditable.msg"); + return; + } + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "update"); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); + return editButton; + } private JButton getViewButton() { viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); - viewButton.setEnabled(false); - viewButton.addActionListener(actionEvent -> { - MedicalInventory inventory; - if (jTableInventory.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); - return; - } - int selectedRow = jTableInventory.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); - return; - } - inventory = inventoryList.get(selectedRow); - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "view"); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); + viewButton.setEnabled(false); + viewButton.addActionListener(actionEvent -> { + MedicalInventory inventory; + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + inventory = inventoryList.get(selectedRow); + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "view"); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); return viewButton; } private JButton getDeleteButton() { deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); - deleteButton.setEnabled(false); - deleteButton.addActionListener(actionEvent -> { - if (jTableInventory.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); - return; - } - int selectedRow = jTableInventory.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); - return; - } - MedicalInventory inventory = inventoryList.get(selectedRow); - String currentStatus = inventory.getStatus(); - if (currentStatus.equalsIgnoreCase(InventoryStatus.validated.toString()) || currentStatus.equalsIgnoreCase(InventoryStatus.draft.toString())) { - int response = MessageDialog.yesNo(this, "angal.inventory.deletion.confirm.msg"); - if (response == JOptionPane.YES_OPTION) { - try { - medicalInventoryManager.deleteInventory(inventory); - MessageDialog.info(this, "angal.inventory.deletion.success.msg"); - jTableInventory.setModel(new InventoryBrowsingModel()); - } catch (OHServiceException e) { - MessageDialog.error(this, "angal.inventory.deletion.error.msg"); - } + deleteButton.setEnabled(false); + deleteButton.addActionListener(actionEvent -> { + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + MedicalInventory inventory = inventoryList.get(selectedRow); + String currentStatus = inventory.getStatus(); + if (currentStatus.equalsIgnoreCase(InventoryStatus.validated.toString()) || currentStatus.equalsIgnoreCase(InventoryStatus.draft.toString())) { + int response = MessageDialog.yesNo(this, "angal.inventory.deletion.confirm.msg"); + if (response == JOptionPane.YES_OPTION) { + try { + medicalInventoryManager.deleteInventory(inventory); + MessageDialog.info(this, "angal.inventory.deletion.success.msg"); + jTableInventory.setModel(new InventoryBrowsingModel()); + } catch (OHServiceException e) { + MessageDialog.error(this, "angal.inventory.deletion.error.msg"); } - } else { - MessageDialog.error(this, "angal.inventory.deletion.error.msg"); } - }); + } else { + MessageDialog.error(this, "angal.inventory.deletion.error.msg"); + } + }); return deleteButton; } @@ -434,20 +434,20 @@ private JTable getJTableInventory() { jTableInventory = new JTable(); jTableInventory.setFillsViewportHeight(true); jTableInventory.setModel(new InventoryBrowsingModel()); - jTableInventory.getSelectionModel().addListSelectionListener(e -> { - if (e.getValueIsAdjusting()) { - int[] selectedRows = jTableInventory.getSelectedRows(); - if (selectedRows.length == 1) { - editButton.setEnabled(true); - viewButton.setEnabled(true); - deleteButton.setEnabled(true); - } else { - editButton.setEnabled(false); - viewButton.setEnabled(false); - deleteButton.setEnabled(false); - } - } - }); + jTableInventory.getSelectionModel().addListSelectionListener(e -> { + if (e.getValueIsAdjusting()) { + int[] selectedRows = jTableInventory.getSelectedRows(); + if (selectedRows.length == 1) { + editButton.setEnabled(true); + viewButton.setEnabled(true); + deleteButton.setEnabled(true); + } else { + editButton.setEnabled(false); + viewButton.setEnabled(false); + deleteButton.setEnabled(false); + } + } + }); } return jTableInventory; } @@ -470,20 +470,20 @@ public InventoryBrowsingModel() { } } - public InventoryBrowsingModel(int startIndex, int pageSize) { - inventoryList = new ArrayList<>(); - String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, startIndex, - pageSize); - inventoryList = medInventorypage.getContent(); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } + public InventoryBrowsingModel(int startIndex, int pageSize) { + inventoryList = new ArrayList<>(); + String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, startIndex, + pageSize); + inventoryList = medInventorypage.getContent(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); } + } - @Override + @Override public Class getColumnClass(int c) { if (c == 0) { return String.class; @@ -499,13 +499,13 @@ public Class getColumnClass(int c) { return null; } - @Override - public int getRowCount() { - if (inventoryList == null) { - return 0; - } - return inventoryList.size(); + @Override + public int getRowCount() { + if (inventoryList == null) { + return 0; } + return inventoryList.size(); + } public String getColumnName(int c) { return pColums[c]; @@ -515,7 +515,7 @@ public int getColumnCount() { return pColums.length; } - @Override + @Override public Object getValueAt(int r, int c) { MedicalInventory medInvt = inventoryList.get(r); @@ -555,15 +555,15 @@ private JComboBox getComboBox() { for (InventoryStatus currentStatus : InventoryStatus.values()) { statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); } - statusComboBox.addActionListener(actionEvent -> { - InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); - totalRows = inventoryBrowsingModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); + statusComboBox.addActionListener(actionEvent -> { + InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); + totalRows = inventoryBrowsingModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); } return statusComboBox; } @@ -576,27 +576,27 @@ private JLabel getStatusLabel() { return statusLabel; } - private void ajustWidth() { - for (int i = 0; i < pColumwidth.length; i++) { - jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); - } + private void ajustWidth() { + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); } + } - public void initialiseCombo(int total_rows) { - int j = 0; + public void initialiseCombo(int total_rows) { + int j = 0; - pagesCombo.removeAllItems(); - for (int i = 0; i < total_rows / PAGE_SIZE; i++) { - j = i + 1; - pagesCombo.addItem(j); - } - if (j * PAGE_SIZE < total_rows) { - pagesCombo.addItem(j + 1); - under.setText("/" + (total_rows / PAGE_SIZE + 1 + " " + MessageBundle.getMessage("angal.inventory.pages.text"))); - } else { - under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); - } + pagesCombo.removeAllItems(); + for (int i = 0; i < total_rows / PAGE_SIZE; i++) { + j = i + 1; + pagesCombo.addItem(j); + } + if (j * PAGE_SIZE < total_rows) { + pagesCombo.addItem(j + 1); + under.setText("/" + (total_rows / PAGE_SIZE + 1 + " " + MessageBundle.getMessage("angal.inventory.pages.text"))); + } else { + under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); } + } @Override public void InventoryInserted(AWTEvent e) { @@ -612,4 +612,4 @@ public void InventoryUpdated(AWTEvent e) { public void InventoryCancelled(AWTEvent e) { jTableInventory.setModel(new InventoryBrowsingModel()); } -} \ No newline at end of file +} From 5a1b7e8f43ef8f83ab98dbbaf21aec3f0753d76c Mon Sep 17 00:00:00 2001 From: JantBogard Date: Thu, 21 Nov 2024 09:32:38 +0100 Subject: [PATCH 28/83] Fix bug occur when i update CORE --- .../org/isf/medicalinventory/gui/InventoryWardEdit.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 5fa931db90..2ca243458b 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -513,7 +513,7 @@ private JButton getSaveButton() { Ward destination = (Ward) destinationComboBox.getSelectedItem(); inventory.setDestination(destination != null ? destination.getCode() : null); - inventory = medicalInventoryManager.updateMedicalInventory(inventory); + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); if (inventory != null) { MessageDialog.info(null, "angal.inventory.update.success.msg"); resetVariable(); @@ -555,7 +555,7 @@ private JButton getSaveButton() { Ward destination = (Ward) destinationComboBox.getSelectedItem(); inventory.setDestination(destination != null ? destination.getCode() : null); - inventory = medicalInventoryManager.updateMedicalInventory(inventory); + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); for (MedicalInventoryRow medicalInventoryRow : inventoryRowSearchList) { medicalInventoryRow.setInventory(inventory); @@ -626,7 +626,7 @@ private JButton getValidateButton() { String status = InventoryStatus.validated.toString(); inventory.setStatus(status); try { - inventory = medicalInventoryManager.updateMedicalInventory(inventory); + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); if (inventory != null) { List invRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); MessageDialog.info(null, "angal.inventory.validate.success.msg"); From 59c64c6210c5a21436b961927e8e72846655932f Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 22 Nov 2024 15:23:12 +0100 Subject: [PATCH 29/83] Applying suggestion for change --- .../gui/InventoryWardBrowser.java | 6 ++--- .../gui/InventoryWardEdit.java | 25 +++++++----------- .../isf/utils/jobjects/InventoryStatus.java | 26 ------------------- .../org/isf/utils/jobjects/InventoryType.java | 26 ------------------- 4 files changed, 12 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/org/isf/utils/jobjects/InventoryStatus.java delete mode 100644 src/main/java/org/isf/utils/jobjects/InventoryType.java diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 2bf96ce8fe..33783852d7 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -53,13 +53,13 @@ import org.isf.generaldata.MessageBundle; import org.isf.medicalinventory.gui.InventoryWardEdit.InventoryListener; import org.isf.medicalinventory.manager.MedicalInventoryManager; +import org.isf.medicalinventory.model.InventoryStatus; +import org.isf.medicalinventory.model.InventoryType; import org.isf.medicalinventory.model.MedicalInventory; import org.isf.menu.manager.Context; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.gui.OHServiceExceptionUtil; import org.isf.utils.jobjects.GoodDateChooser; -import org.isf.utils.jobjects.InventoryStatus; -import org.isf.utils.jobjects.InventoryType; import org.isf.utils.jobjects.MessageDialog; import org.isf.utils.jobjects.ModalJFrame; import org.isf.utils.time.TimeTools; @@ -417,7 +417,7 @@ private JButton getDeleteButton() { private JButton getCloseButton() { closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(e -> dispose()); + closeButton.addActionListener(actionEvent -> dispose()); return closeButton; } diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 2ca243458b..e84b1be6a4 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -74,22 +74,20 @@ import org.isf.generaldata.MessageBundle; import org.isf.medicalinventory.manager.MedicalInventoryManager; import org.isf.medicalinventory.manager.MedicalInventoryRowManager; +import org.isf.medicalinventory.model.InventoryStatus; +import org.isf.medicalinventory.model.InventoryType; import org.isf.medicalinventory.model.MedicalInventory; import org.isf.medicalinventory.model.MedicalInventoryRow; import org.isf.medicals.manager.MedicalBrowsingManager; import org.isf.medicals.model.Medical; -import org.isf.medicalstock.model.Lot; import org.isf.medicalstockward.manager.MovWardBrowserManager; import org.isf.medicalstockward.model.MedicalWard; -import org.isf.medstockmovtype.manager.MedicalDsrStockMovementTypeBrowserManager; import org.isf.menu.manager.Context; import org.isf.menu.manager.UserBrowsingManager; import org.isf.utils.db.NormalizeString; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.gui.OHServiceExceptionUtil; import org.isf.utils.jobjects.GoodDateChooser; -import org.isf.utils.jobjects.InventoryStatus; -import org.isf.utils.jobjects.InventoryType; import org.isf.utils.jobjects.MessageDialog; import org.isf.utils.jobjects.ModalJFrame; import org.isf.utils.jobjects.TextPrompt; @@ -123,9 +121,9 @@ private void fireInventoryUpdated() { }; EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class); - for (int i = 0; i < listeners.length; i++) { - ((InventoryListener) listeners[i]).InventoryUpdated(event); - } + for (EventListener listener : listeners) { + ((InventoryListener) listener).InventoryUpdated(event); + } jTableInventoryRow.updateUI(); } @@ -206,8 +204,6 @@ private void fireInventoryInserted() { .getBean(MedicalBrowsingManager.class); private MovWardBrowserManager movWardBrowserManager = Context.getApplicationContext() .getBean(MovWardBrowserManager.class); - private MedicalDsrStockMovementTypeBrowserManager medStockMovTypeManager = Context.getApplicationContext() - .getBean(MedicalDsrStockMovementTypeBrowserManager.class); public InventoryWardEdit() { @@ -219,6 +215,7 @@ public InventoryWardEdit() { public InventoryWardEdit(MedicalInventory inventory, String modee) { this.inventory = inventory; + wardId = this.inventory.getWard(); mode = modee; initComponents(); } @@ -998,7 +995,6 @@ private void adjustWidth() { private List getMedicalInventoryRows(String code) throws OHServiceException { List inventoryRowsList = new ArrayList<>(); List medicalWardList = new ArrayList<>(); - List lots; Medical medical; MedicalInventoryRow inventoryRowTemp; if (code != null) { @@ -1009,7 +1005,7 @@ private List getMedicalInventoryRows(String code) throws OH MessageDialog.error(null, MessageBundle.getMessage("angal.inventory.noproductfound.msg")); } } else { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, false); } for (MedicalWard medicalWard: medicalWardList) { inventoryRowTemp = new MedicalInventoryRow(0, medicalWard.getQty(), medicalWard.getQty(), null, @@ -1067,9 +1063,6 @@ private JRadioButton getAllRadio() { if (allRadio.isSelected()) { codeTextField.setEnabled(false); codeTextField.setText(""); - if (wardId.isEmpty()) { - wardId = wardSelected.getCode(); - } if (!inventoryRowSearchList.isEmpty()) { int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttoaddallnotyetlistedproducts.msg"); if (info == JOptionPane.YES_OPTION) { @@ -1183,7 +1176,7 @@ private void addInventoryRow(String code) throws OHServiceException { } } } else { - medicalWardList = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false); + medicalWardList = movWardBrowserManager.getMedicalsWard(wardId, false); } inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); @@ -1197,7 +1190,7 @@ private void addInventoryRow(String code) throws OHServiceException { private Medical chooseMedical(String text) throws OHServiceException { Map medicalMap; - List medicals = movWardBrowserManager.getMedicalsWard(wardId.charAt(0), false).stream().map(MedicalWard::getMedical).toList(); + List medicals = movWardBrowserManager.getMedicalsWard(wardId, false).stream().map(MedicalWard::getMedical).toList(); medicalMap = new HashMap<>(); for (Medical med : medicals) { diff --git a/src/main/java/org/isf/utils/jobjects/InventoryStatus.java b/src/main/java/org/isf/utils/jobjects/InventoryStatus.java deleted file mode 100644 index 118ed93479..0000000000 --- a/src/main/java/org/isf/utils/jobjects/InventoryStatus.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Open Hospital (www.open-hospital.org) - * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) - * - * Open Hospital is a free and open source software for healthcare data management. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.isf.utils.jobjects; - -public enum InventoryStatus { - draft, validated, canceled, done; -} \ No newline at end of file diff --git a/src/main/java/org/isf/utils/jobjects/InventoryType.java b/src/main/java/org/isf/utils/jobjects/InventoryType.java deleted file mode 100644 index 1244e4d5b7..0000000000 --- a/src/main/java/org/isf/utils/jobjects/InventoryType.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Open Hospital (www.open-hospital.org) - * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) - * - * Open Hospital is a free and open source software for healthcare data management. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.isf.utils.jobjects; - -public enum InventoryType { - main, ward -} \ No newline at end of file From 0ca0998a6527eabbc315e87b206a79ee3c1dedf1 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 22 Nov 2024 15:39:40 +0100 Subject: [PATCH 30/83] Applying suggestion for change --- .../gui/InventoryWardBrowser.java | 372 +++++++++--------- 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 33783852d7..a80ea53551 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -135,47 +135,47 @@ public void windowClosing(WindowEvent e) { dispose(); } }); - pagesCombo.setEditable(true); - previous.setEnabled(false); - next.setEnabled(false); - next.addActionListener(actionEvent -> { - if (!previous.isEnabled()) { - previous.setEnabled(true); - } - startIndex += PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex + PAGE_SIZE > totalRows) { + pagesCombo.setEditable(true); + previous.setEnabled(false); next.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - }); + next.addActionListener(actionEvent -> { + if (!previous.isEnabled()) { + previous.setEnabled(true); + } + startIndex += PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex + PAGE_SIZE > totalRows) { + next.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + }); previous.addActionListener(actionEvent -> { - if (!next.isEnabled()) { - next.setEnabled(true); - } - startIndex -= PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex < PAGE_SIZE) { - previous.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - }); - pagesCombo.addItemListener(itemEvent -> { - int eventID = itemEvent.getStateChange(); - - if (eventID == ItemEvent.SELECTED) { - int page_number = (Integer) pagesCombo.getSelectedItem(); - startIndex = (page_number - 1) * PAGE_SIZE; - - next.setEnabled(startIndex + PAGE_SIZE <= totalRows); - previous.setEnabled(page_number != 1); - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - - pagesCombo.setEnabled(true); - } - }); + if (!next.isEnabled()) { + next.setEnabled(true); + } + startIndex -= PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex < PAGE_SIZE) { + previous.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + }); + pagesCombo.addItemListener(itemEvent -> { + int eventID = itemEvent.getStateChange(); + + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; + + next.setEnabled(startIndex + PAGE_SIZE <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + + pagesCombo.setEnabled(true); + } + }); } private JPanel getPanelHeader() { @@ -248,15 +248,15 @@ private JPanel getPanelContent() { private JPanel getPanelFooter() { if (panelFooter == null) { panelFooter = new JPanel(); - next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); - next.setMnemonic(KeyEvent.VK_RIGHT); - previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); - next.setMnemonic(KeyEvent.VK_LEFT); + next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); + next.setMnemonic(KeyEvent.VK_RIGHT); + previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); + next.setMnemonic(KeyEvent.VK_LEFT); panelFooter.add(previous); - panelFooter.add(pagesCombo); - panelFooter.add(under); - panelFooter.add(next); + panelFooter.add(pagesCombo); + panelFooter.add(under); + panelFooter.add(next); panelFooter.add(getNewButton()); panelFooter.add(getViewButton()); @@ -331,86 +331,86 @@ private JButton getNewButton() { } private JButton getEditButton() { - editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); - editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); - editButton.setEnabled(false); - editButton.addActionListener(actionEvent -> { - MedicalInventory inventory; - if (jTableInventory.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); - return; - } - int selectedRow = jTableInventory.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); - return; - } - inventory = inventoryList.get(selectedRow); - if (inventory.getStatus().equals(InventoryStatus.canceled.toString())) { - MessageDialog.error(this, "angal.inventory.cancelednoteditable.msg"); - return; - } - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "update"); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); - return editButton; + editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); + editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); + editButton.setEnabled(false); + editButton.addActionListener(actionEvent -> { + MedicalInventory inventory; + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + inventory = inventoryList.get(selectedRow); + if (inventory.getStatus().equals(InventoryStatus.canceled.toString())) { + MessageDialog.error(this, "angal.inventory.cancelednoteditable.msg"); + return; + } + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "update"); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); + return editButton; } private JButton getViewButton() { viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); - viewButton.setEnabled(false); - viewButton.addActionListener(actionEvent -> { - MedicalInventory inventory; - if (jTableInventory.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); - return; - } - int selectedRow = jTableInventory.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); - return; - } - inventory = inventoryList.get(selectedRow); - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "view"); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); + viewButton.setEnabled(false); + viewButton.addActionListener(actionEvent -> { + MedicalInventory inventory; + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + inventory = inventoryList.get(selectedRow); + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(inventory, "view"); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); return viewButton; } private JButton getDeleteButton() { deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); - deleteButton.setEnabled(false); - deleteButton.addActionListener(actionEvent -> { - if (jTableInventory.getSelectedRowCount() > 1) { - MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); - return; - } - int selectedRow = jTableInventory.getSelectedRow(); - if (selectedRow == -1) { - MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); - return; - } - MedicalInventory inventory = inventoryList.get(selectedRow); - String currentStatus = inventory.getStatus(); - if (currentStatus.equalsIgnoreCase(InventoryStatus.validated.toString()) || currentStatus.equalsIgnoreCase(InventoryStatus.draft.toString())) { - int response = MessageDialog.yesNo(this, "angal.inventory.deletion.confirm.msg"); - if (response == JOptionPane.YES_OPTION) { - try { - medicalInventoryManager.deleteInventory(inventory); - MessageDialog.info(this, "angal.inventory.deletion.success.msg"); - jTableInventory.setModel(new InventoryBrowsingModel()); - } catch (OHServiceException e) { - MessageDialog.error(this, "angal.inventory.deletion.error.msg"); + deleteButton.setEnabled(false); + deleteButton.addActionListener(actionEvent -> { + if (jTableInventory.getSelectedRowCount() > 1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + int selectedRow = jTableInventory.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectinventory.msg"); + return; + } + MedicalInventory inventory = inventoryList.get(selectedRow); + String currentStatus = inventory.getStatus(); + if (currentStatus.equalsIgnoreCase(InventoryStatus.validated.toString()) || currentStatus.equalsIgnoreCase(InventoryStatus.draft.toString())) { + int response = MessageDialog.yesNo(this, "angal.inventory.deletion.confirm.msg"); + if (response == JOptionPane.YES_OPTION) { + try { + medicalInventoryManager.deleteInventory(inventory); + MessageDialog.info(this, "angal.inventory.deletion.success.msg"); + jTableInventory.setModel(new InventoryBrowsingModel()); + } catch (OHServiceException e) { + MessageDialog.error(this, "angal.inventory.deletion.error.msg"); + } } + } else { + MessageDialog.error(this, "angal.inventory.deletion.error.msg"); } - } else { - MessageDialog.error(this, "angal.inventory.deletion.error.msg"); - } - }); + }); return deleteButton; } @@ -434,20 +434,20 @@ private JTable getJTableInventory() { jTableInventory = new JTable(); jTableInventory.setFillsViewportHeight(true); jTableInventory.setModel(new InventoryBrowsingModel()); - jTableInventory.getSelectionModel().addListSelectionListener(e -> { - if (e.getValueIsAdjusting()) { - int[] selectedRows = jTableInventory.getSelectedRows(); - if (selectedRows.length == 1) { - editButton.setEnabled(true); - viewButton.setEnabled(true); - deleteButton.setEnabled(true); - } else { - editButton.setEnabled(false); - viewButton.setEnabled(false); - deleteButton.setEnabled(false); - } - } - }); + jTableInventory.getSelectionModel().addListSelectionListener(e -> { + if (e.getValueIsAdjusting()) { + int[] selectedRows = jTableInventory.getSelectedRows(); + if (selectedRows.length == 1) { + editButton.setEnabled(true); + viewButton.setEnabled(true); + deleteButton.setEnabled(true); + } else { + editButton.setEnabled(false); + viewButton.setEnabled(false); + deleteButton.setEnabled(false); + } + } + }); } return jTableInventory; } @@ -470,42 +470,42 @@ public InventoryBrowsingModel() { } } - public InventoryBrowsingModel(int startIndex, int pageSize) { - inventoryList = new ArrayList<>(); - String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, startIndex, - pageSize); - inventoryList = medInventorypage.getContent(); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - @Override - public Class getColumnClass(int c) { - if (c == 0) { - return String.class; - } else if (c == 1) { - return String.class; - } else if (c == 2) { - return String.class; - } else if (c == 3) { - return String.class; - } else if (c == 4) { - return String.class; - } - return null; - } + public InventoryBrowsingModel(int startIndex, int pageSize) { + inventoryList = new ArrayList<>(); + String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, startIndex, + pageSize); + inventoryList = medInventorypage.getContent(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } - @Override - public int getRowCount() { - if (inventoryList == null) { - return 0; + @Override + public Class getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return String.class; + } else if (c == 3) { + return String.class; + } else if (c == 4) { + return String.class; + } + return null; } - return inventoryList.size(); - } + + @Override + public int getRowCount() { + if (inventoryList == null) { + return 0; + } + return inventoryList.size(); + } public String getColumnName(int c) { return pColums[c]; @@ -515,7 +515,7 @@ public int getColumnCount() { return pColums.length; } - @Override + @Override public Object getValueAt(int r, int c) { MedicalInventory medInvt = inventoryList.get(r); @@ -555,15 +555,15 @@ private JComboBox getComboBox() { for (InventoryStatus currentStatus : InventoryStatus.values()) { statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); } - statusComboBox.addActionListener(actionEvent -> { - InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); - totalRows = inventoryBrowsingModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); + statusComboBox.addActionListener(actionEvent -> { + InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); + totalRows = inventoryBrowsingModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); } return statusComboBox; } @@ -577,25 +577,25 @@ private JLabel getStatusLabel() { } private void ajustWidth() { - for (int i = 0; i < pColumwidth.length; i++) { - jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); - } + for (int i = 0; i < pColumwidth.length; i++) { + jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); + } } public void initialiseCombo(int total_rows) { - int j = 0; - - pagesCombo.removeAllItems(); - for (int i = 0; i < total_rows / PAGE_SIZE; i++) { - j = i + 1; - pagesCombo.addItem(j); - } - if (j * PAGE_SIZE < total_rows) { - pagesCombo.addItem(j + 1); - under.setText("/" + (total_rows / PAGE_SIZE + 1 + " " + MessageBundle.getMessage("angal.inventory.pages.text"))); - } else { - under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); - } + int j = 0; + + pagesCombo.removeAllItems(); + for (int i = 0; i < total_rows / PAGE_SIZE; i++) { + j = i + 1; + pagesCombo.addItem(j); + } + if (j * PAGE_SIZE < total_rows) { + pagesCombo.addItem(j + 1); + under.setText("/" + (total_rows / PAGE_SIZE + 1 + " " + MessageBundle.getMessage("angal.inventory.pages.text"))); + } else { + under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); + } } @Override From 00e3fa30c5e8d998b8ef5b447f6fdca9e490edad Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 22 Nov 2024 16:54:04 +0100 Subject: [PATCH 31/83] Applying suggestion for change --- bundle/language_en.properties | 10 +++++----- .../medicalinventory/gui/InventoryWardBrowser.java | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index a82e8bc059..d35a901a27 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -730,11 +730,11 @@ angal.inventory.savesuccess.msg angal.inventory.searchproduct.txt = Search a product angal.inventory.selectward.label = Select ward angal.inventory.specificproduct.radio = Specific product -angal.inventory.state.col = State -angal.inventory.state.label = State -angal.inventory.state.canceled.txt = Canceled -angal.inventory.state.inprogress.txt = In progress -angal.inventory.state.validate.txt = Validate +angal.inventory.status.col = Status +angal.inventory.status.label = Status +angal.inventory.status.canceled.txt = Canceled +angal.inventory.status.inprogress.txt = In progress +angal.inventory.status.validate.txt = Validate angal.inventory.supplier.label = Supplier: angal.inventory.theorticalqty.col = Theoretical angal.inventory.theoreticalqtyhavebeenupdatedforsomemedicalward.fmt.msg = Theoretical(s) quantity(ies) have been updated by new movement(s) in ward store for: {0} diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index a80ea53551..6ad5fb93c1 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -91,7 +91,7 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListen MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), MessageBundle.getMessage("angal.common.date.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.state.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), MessageBundle.getMessage("angal.common.user.col").toUpperCase() }; private int[] pColumwidth = { 150, 150, 100, 100, 150 }; @@ -461,10 +461,10 @@ class InventoryBrowsingModel extends DefaultTableModel { public InventoryBrowsingModel() { inventoryList = new ArrayList<>(); - String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; String type = InventoryType.ward.toString(); try { - inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, state, type); + inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } @@ -472,10 +472,10 @@ public InventoryBrowsingModel() { public InventoryBrowsingModel(int startIndex, int pageSize) { inventoryList = new ArrayList<>(); - String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; String type = InventoryType.ward.toString(); try { - Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, startIndex, + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, startIndex, pageSize); inventoryList = medInventorypage.getContent(); } catch (OHServiceException e) { @@ -570,7 +570,7 @@ private JComboBox getComboBox() { private JLabel getStatusLabel() { if (statusLabel == null) { - statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.state.label")); + statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); } return statusLabel; From 825d342275af84d9ed56b3a08ca2716541d159b3 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 09:26:38 +0100 Subject: [PATCH 32/83] Applying suggestion for change --- bundle/language_en.properties | 4 ++-- .../medicalinventory/gui/InventoryWardBrowser.java | 12 ++++++------ .../isf/medicalinventory/gui/InventoryWardEdit.java | 10 +++++----- .../org/isf/medicalinventory/gui/StockMedModel.java | 7 ++++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index d35a901a27..fd5e62c312 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -671,7 +671,7 @@ angal.hospital.visitendhour.txt angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. angal.invetory.allmedicaladdedsuccessfully.msg = All medicals are added successfully. -angal.inventory.allproduct.radio = All products +angal.inventory.allproduct.btn = All products angal.inventory.canceled = Canceled angal.inventory.cancelednoteditable.msg = A canceled inventory can not be modified. angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg = Cannot create another inventory with other in progress in this ward. @@ -729,7 +729,7 @@ angal.inventory.referenceshow.col angal.inventory.savesuccess.msg = Inventory saved. angal.inventory.searchproduct.txt = Search a product angal.inventory.selectward.label = Select ward -angal.inventory.specificproduct.radio = Specific product +angal.inventory.specificproduct.btn = Specific product angal.inventory.status.col = Status angal.inventory.status.label = Status angal.inventory.status.canceled.txt = Canceled diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 6ad5fb93c1..4ad441e8f5 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -212,12 +212,12 @@ private JPanel getPanelHeader() { gbc_jCalendarTo.gridx = 3; gbc_jCalendarTo.gridy = 0; panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); - GridBagConstraints gbc_stateLabel = new GridBagConstraints(); - gbc_stateLabel.fill = GridBagConstraints.HORIZONTAL; - gbc_stateLabel.insets = new Insets(0, 0, 0, 5); - gbc_stateLabel.gridx = 4; - gbc_stateLabel.gridy = 0; - panelHeader.add(getStatusLabel(), gbc_stateLabel); + GridBagConstraints gbc_statusLabel = new GridBagConstraints(); + gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_statusLabel.insets = new Insets(0, 0, 0, 5); + gbc_statusLabel.gridx = 4; + gbc_statusLabel.gridy = 0; + panelHeader.add(getStatusLabel(), gbc_statusLabel); GridBagConstraints gbc_comboBox = new GridBagConstraints(); gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; gbc_comboBox.gridx = 5; diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index e84b1be6a4..0f785824ec 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -1041,7 +1041,7 @@ private boolean existInInventorySearchList(MedicalInventoryRow inventoryRow) { private JRadioButton getSpecificRadio() { if (specificRadio == null) { - specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); + specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.btn")); specificRadio.addActionListener(actionEvent -> { if (specificRadio.isSelected()) { codeTextField.setEnabled(true); @@ -1055,7 +1055,7 @@ private JRadioButton getSpecificRadio() { private JRadioButton getAllRadio() { if (allRadio == null) { - allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); + allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.btn")); allRadio.setSelected(inventory != null); specificRadio.setSelected(inventory == null); allRadio.addActionListener(actionEvent -> { @@ -1198,7 +1198,7 @@ private Medical chooseMedical(String text) throws OHServiceException { key = med.getCode().toString().toLowerCase(); medicalMap.put(key, med); } - ArrayList medList = new ArrayList<>(); + List medList = new ArrayList<>(); for (Medical aMed : medicalMap.values()) { if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { medList.add(aMed); @@ -1341,7 +1341,7 @@ private JComboBox getWardComboBox() { } if (medicalWardInventoryDraft.isEmpty() && medicalWardInventoryValidated.isEmpty()) { - activedSomeComponents(); + activateSomeComponents(); } else { MessageDialog.error(this, "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); @@ -1402,7 +1402,7 @@ private void disabledSomeComponents() { deleteButton.setEnabled(false); } - private void activedSomeComponents() { + private void activateSomeComponents() { jCalendarInventory.setEnabled(true); specificRadio.setEnabled(true); codeTextField.setEnabled(true); diff --git a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java index 51a474564c..8f526e73e8 100644 --- a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java +++ b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import javax.swing.table.DefaultTableModel; @@ -33,10 +34,10 @@ public class StockMedModel extends DefaultTableModel { private static final long serialVersionUID = 1L; - private ArrayList medList; - private ArrayList initList = new ArrayList(); + private List medList; + private List initList = new ArrayList<>(); - public StockMedModel(ArrayList meds) { + public StockMedModel(List meds) { medList = meds; initList.addAll(medList); } From 99b20f8456ac3b1b4837bb955a0078fad2f8584e Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 10:15:02 +0100 Subject: [PATCH 33/83] Applying suggestion for change --- .../gui/InventoryWardBrowser.java | 847 +++++++++--------- 1 file changed, 424 insertions(+), 423 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 4ad441e8f5..fd58efbc97 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -69,268 +69,268 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListener { - private static final long serialVersionUID = 1L; - - private GoodDateChooser jCalendarTo; - private GoodDateChooser jCalendarFrom; - private LocalDateTime dateFrom = TimeTools.getDateToday0(); - private LocalDateTime dateTo = TimeTools.getDateToday24(); - private JLabel jLabelTo; - private JLabel jLabelFrom; - private JPanel panelHeader; - private JPanel panelFooter; - private JPanel panelContent; - private JButton closeButton; - private JButton newButton; - private JButton editButton; - private JButton deleteButton; - private JButton viewButton; - private JScrollPane scrollPaneInventory; - private JTable jTableInventory; - private String[] pColums = { - MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), - MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), - MessageBundle.getMessage("angal.common.date.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), - MessageBundle.getMessage("angal.common.user.col").toUpperCase() - }; - private int[] pColumwidth = { 150, 150, 100, 100, 150 }; - private JComboBox statusComboBox; - private JLabel statusLabel; - JButton next; - JButton previous; - JComboBox pagesCombo = new JComboBox<>(); - JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); - private static int PAGE_SIZE = 50; - private int startIndex; - private int totalRows; - private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); - private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); - private List inventoryList; - - public InventoryWardBrowser() { - initComponents(); - } - - private void initComponents() { - - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setMinimumSize(new Dimension(850, 550)); - setLocationRelativeTo(null); // center - setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); - - panelHeader = getPanelHeader(); - getContentPane().add(panelHeader, BorderLayout.NORTH); - - panelContent = getPanelContent(); - getContentPane().add(panelContent, BorderLayout.CENTER); - - panelFooter = getPanelFooter(); - getContentPane().add(panelFooter, BorderLayout.SOUTH); - - ajustWidth(); - - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - dispose(); - } - }); + private static final long serialVersionUID = 1L; + private static int PAGE_SIZE = 50; + JButton next; + JButton previous; + JComboBox pagesCombo = new JComboBox<>(); + JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); + private GoodDateChooser jCalendarTo; + private GoodDateChooser jCalendarFrom; + private LocalDateTime dateFrom = TimeTools.getDateToday0(); + private LocalDateTime dateTo = TimeTools.getDateToday24(); + private JLabel jLabelTo; + private JLabel jLabelFrom; + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton newButton; + private JButton editButton; + private JButton deleteButton; + private JButton viewButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventory; + private String[] pColums = { + MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), + MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), + MessageBundle.getMessage("angal.common.date.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), + MessageBundle.getMessage("angal.common.user.col").toUpperCase() + }; + private int[] pColumwidth = { 150, 150, 100, 100, 150 }; + private JComboBox statusComboBox; + private JLabel statusLabel; + private int startIndex; + private int totalRows; + private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); + private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); + private List inventoryList; + + public InventoryWardBrowser() { + initComponents(); + } + + private void initComponents() { + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new Dimension(850, 550)); + setLocationRelativeTo(null); // center + setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); + + panelHeader = getPanelHeader(); + getContentPane().add(panelHeader, BorderLayout.NORTH); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + panelFooter = getPanelFooter(); + getContentPane().add(panelFooter, BorderLayout.SOUTH); + + ajustWidth(); + + addWindowListener(new WindowAdapter() { + + public void windowClosing(WindowEvent e) { + dispose(); + } + }); pagesCombo.setEditable(true); previous.setEnabled(false); next.setEnabled(false); next.addActionListener(actionEvent -> { - if (!previous.isEnabled()) { - previous.setEnabled(true); - } - startIndex += PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex + PAGE_SIZE > totalRows) { - next.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + if (!previous.isEnabled()) { + previous.setEnabled(true); + } + startIndex += PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex + PAGE_SIZE > totalRows) { + next.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); - previous.addActionListener(actionEvent -> { - if (!next.isEnabled()) { - next.setEnabled(true); - } - startIndex -= PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex < PAGE_SIZE) { - previous.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + previous.addActionListener(actionEvent -> { + if (!next.isEnabled()) { + next.setEnabled(true); + } + startIndex -= PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex < PAGE_SIZE) { + previous.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); pagesCombo.addItemListener(itemEvent -> { - int eventID = itemEvent.getStateChange(); + int eventID = itemEvent.getStateChange(); - if (eventID == ItemEvent.SELECTED) { - int page_number = (Integer) pagesCombo.getSelectedItem(); - startIndex = (page_number - 1) * PAGE_SIZE; + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; - next.setEnabled(startIndex + PAGE_SIZE <= totalRows); - previous.setEnabled(page_number != 1); - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + next.setEnabled(startIndex + PAGE_SIZE <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - pagesCombo.setEnabled(true); - } + pagesCombo.setEnabled(true); + } }); - } - - private JPanel getPanelHeader() { - if (panelHeader == null) { - panelHeader = new JPanel(); - panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); - GridBagLayout gbl_panelHeader = new GridBagLayout(); - gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; - gbl_panelHeader.rowHeights = new int[] { 32, 0 }; - gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; - gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; - panelHeader.setLayout(gbl_panelHeader); - GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); - gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; - gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); - gbc_jLabelFrom.gridx = 0; - gbc_jLabelFrom.gridy = 0; - panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); - GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); - gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); - gbc_jCalendarFrom.gridx = 1; - gbc_jCalendarFrom.gridy = 0; - panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); - GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); - gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; - gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); - gbc_jLabelTo.gridx = 2; - gbc_jLabelTo.gridy = 0; - panelHeader.add(getJLabelTo(), gbc_jLabelTo); - GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); - gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); - gbc_jCalendarTo.gridx = 3; - gbc_jCalendarTo.gridy = 0; - panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); - GridBagConstraints gbc_statusLabel = new GridBagConstraints(); - gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL; - gbc_statusLabel.insets = new Insets(0, 0, 0, 5); - gbc_statusLabel.gridx = 4; - gbc_statusLabel.gridy = 0; - panelHeader.add(getStatusLabel(), gbc_statusLabel); - GridBagConstraints gbc_comboBox = new GridBagConstraints(); - gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_comboBox.gridx = 5; - gbc_comboBox.gridy = 0; - panelHeader.add(getComboBox(), gbc_comboBox); - } - return panelHeader; - } - - private JPanel getPanelContent() { - if (panelContent == null) { - panelContent = new JPanel(); - GridBagLayout gbl_panelContent = new GridBagLayout(); - gbl_panelContent.columnWidths = new int[] { 452, 0 }; - gbl_panelContent.rowHeights = new int[] { 402, 0 }; - gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; - gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; - panelContent.setLayout(gbl_panelContent); - GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); - gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; - gbc_scrollPaneInventory.gridx = 0; - gbc_scrollPaneInventory.gridy = 0; - panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); - } - return panelContent; - } - - private JPanel getPanelFooter() { - if (panelFooter == null) { - panelFooter = new JPanel(); - next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); - next.setMnemonic(KeyEvent.VK_RIGHT); - previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); - next.setMnemonic(KeyEvent.VK_LEFT); - - panelFooter.add(previous); - panelFooter.add(pagesCombo); - panelFooter.add(under); - panelFooter.add(next); - - panelFooter.add(getNewButton()); - panelFooter.add(getViewButton()); - panelFooter.add(getEditButton()); - panelFooter.add(getDeleteButton()); - panelFooter.add(getCloseButton()); - } - return panelFooter; - } - - private GoodDateChooser getJCalendarFrom() { - if (jCalendarFrom == null) { - jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); - jCalendarFrom.addDateChangeListener(event -> { - dateFrom = jCalendarFrom.getDateStartOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - totalRows = inventoryModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); - } - return jCalendarFrom; - } - - private GoodDateChooser getJCalendarTo() { - if (jCalendarTo == null) { - jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); - jCalendarTo.addDateChangeListener(event -> { - dateTo = jCalendarTo.getDateEndOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - totalRows = inventoryModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); - } - return jCalendarTo; - } - - private JLabel getJLabelTo() { - if (jLabelTo == null) { - jLabelTo = new JLabel(); - jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); - } - return jLabelTo; - } - - private JLabel getJLabelFrom() { - if (jLabelFrom == null) { - jLabelFrom = new JLabel(); - jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); - } - return jLabelFrom; - } - - private JButton getNewButton() { - newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); - newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); - newButton.addActionListener(actionEvent -> { - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); - return newButton; - } - - private JButton getEditButton() { + } + + private JPanel getPanelHeader() { + if (panelHeader == null) { + panelHeader = new JPanel(); + panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); + GridBagLayout gbl_panelHeader = new GridBagLayout(); + gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; + gbl_panelHeader.rowHeights = new int[] { 32, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; + panelHeader.setLayout(gbl_panelHeader); + GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); + gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); + gbc_jLabelFrom.gridx = 0; + gbc_jLabelFrom.gridy = 0; + panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); + GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); + gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarFrom.gridx = 1; + gbc_jCalendarFrom.gridy = 0; + panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); + GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); + gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); + gbc_jLabelTo.gridx = 2; + gbc_jLabelTo.gridy = 0; + panelHeader.add(getJLabelTo(), gbc_jLabelTo); + GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); + gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarTo.gridx = 3; + gbc_jCalendarTo.gridy = 0; + panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); + GridBagConstraints gbc_statusLabel = new GridBagConstraints(); + gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_statusLabel.insets = new Insets(0, 0, 0, 5); + gbc_statusLabel.gridx = 4; + gbc_statusLabel.gridy = 0; + panelHeader.add(getStatusLabel(), gbc_statusLabel); + GridBagConstraints gbc_comboBox = new GridBagConstraints(); + gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_comboBox.gridx = 5; + gbc_comboBox.gridy = 0; + panelHeader.add(getComboBox(), gbc_comboBox); + } + return panelHeader; + } + + private JPanel getPanelContent() { + if (panelContent == null) { + panelContent = new JPanel(); + GridBagLayout gbl_panelContent = new GridBagLayout(); + gbl_panelContent.columnWidths = new int[] { 452, 0 }; + gbl_panelContent.rowHeights = new int[] { 402, 0 }; + gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + panelContent.setLayout(gbl_panelContent); + GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); + gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; + gbc_scrollPaneInventory.gridx = 0; + gbc_scrollPaneInventory.gridy = 0; + panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); + } + return panelContent; + } + + private JPanel getPanelFooter() { + if (panelFooter == null) { + panelFooter = new JPanel(); + next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); + next.setMnemonic(KeyEvent.VK_RIGHT); + previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); + next.setMnemonic(KeyEvent.VK_LEFT); + + panelFooter.add(previous); + panelFooter.add(pagesCombo); + panelFooter.add(under); + panelFooter.add(next); + + panelFooter.add(getNewButton()); + panelFooter.add(getViewButton()); + panelFooter.add(getEditButton()); + panelFooter.add(getDeleteButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private GoodDateChooser getJCalendarFrom() { + if (jCalendarFrom == null) { + jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarFrom.addDateChangeListener(event -> { + dateFrom = jCalendarFrom.getDateStartOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarFrom; + } + + private GoodDateChooser getJCalendarTo() { + if (jCalendarTo == null) { + jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarTo.addDateChangeListener(event -> { + dateTo = jCalendarTo.getDateEndOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarTo; + } + + private JLabel getJLabelTo() { + if (jLabelTo == null) { + jLabelTo = new JLabel(); + jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); + } + return jLabelTo; + } + + private JLabel getJLabelFrom() { + if (jLabelFrom == null) { + jLabelFrom = new JLabel(); + jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); + } + return jLabelFrom; + } + + private JButton getNewButton() { + newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); + newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); + newButton.addActionListener(actionEvent -> { + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); + return newButton; + } + + private JButton getEditButton() { editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); editButton.setEnabled(false); @@ -355,11 +355,11 @@ private JButton getEditButton() { inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); return editButton; - } + } - private JButton getViewButton() { - viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); - viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); + private JButton getViewButton() { + viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); + viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); viewButton.setEnabled(false); viewButton.addActionListener(actionEvent -> { MedicalInventory inventory; @@ -377,12 +377,12 @@ private JButton getViewButton() { InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); - return viewButton; - } + return viewButton; + } - private JButton getDeleteButton() { - deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); - deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); + private JButton getDeleteButton() { + deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); + deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); deleteButton.setEnabled(false); deleteButton.addActionListener(actionEvent -> { if (jTableInventory.getSelectedRowCount() > 1) { @@ -411,30 +411,30 @@ private JButton getDeleteButton() { MessageDialog.error(this, "angal.inventory.deletion.error.msg"); } }); - return deleteButton; - } - - private JButton getCloseButton() { - closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); - closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(actionEvent -> dispose()); - return closeButton; - } - - private JScrollPane getScrollPaneInventory() { - if (scrollPaneInventory == null) { - scrollPaneInventory = new JScrollPane(); - scrollPaneInventory.setViewportView(getJTableInventory()); - } - return scrollPaneInventory; - } - - private JTable getJTableInventory() { - if (jTableInventory == null) { - jTableInventory = new JTable(); - jTableInventory.setFillsViewportHeight(true); - jTableInventory.setModel(new InventoryBrowsingModel()); - jTableInventory.getSelectionModel().addListSelectionListener(e -> { + return deleteButton; + } + + private JButton getCloseButton() { + closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); + closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); + closeButton.addActionListener(actionEvent -> dispose()); + return closeButton; + } + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + scrollPaneInventory.setViewportView(getJTableInventory()); + } + return scrollPaneInventory; + } + + private JTable getJTableInventory() { + if (jTableInventory == null) { + jTableInventory = new JTable(); + jTableInventory.setFillsViewportHeight(true); + jTableInventory.setModel(new InventoryBrowsingModel()); + jTableInventory.getSelectionModel().addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { int[] selectedRows = jTableInventory.getSelectedRows(); if (selectedRows.length == 1) { @@ -447,115 +447,19 @@ private JTable getJTableInventory() { deleteButton.setEnabled(false); } } - }); - } - return jTableInventory; - } - - class InventoryBrowsingModel extends DefaultTableModel { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public InventoryBrowsingModel() { - inventoryList = new ArrayList<>(); - String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - public InventoryBrowsingModel(int startIndex, int pageSize) { - inventoryList = new ArrayList<>(); - String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, startIndex, - pageSize); - inventoryList = medInventorypage.getContent(); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - @Override - public Class getColumnClass(int c) { - if (c == 0) { - return String.class; - } else if (c == 1) { - return String.class; - } else if (c == 2) { - return String.class; - } else if (c == 3) { - return String.class; - } else if (c == 4) { - return String.class; - } - return null; - } - - @Override - public int getRowCount() { - if (inventoryList == null) { - return 0; - } - return inventoryList.size(); + }); } - - public String getColumnName(int c) { - return pColums[c]; - } - - public int getColumnCount() { - return pColums.length; - } - - @Override - public Object getValueAt(int r, int c) { - MedicalInventory medInvt = inventoryList.get(r); - - if (c == -1) { - return medInvt; - } else if (c == 0) { - return medInvt.getInventoryReference(); - } else if (c == 1) { - Ward ward = new Ward(); - try { - ward = wardBrowserManager.findWard(medInvt.getWard()); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - return ward == null ? "" : ward.getDescription(); - } else if (c == 2) { - return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); - } else if (c == 3) { - return medInvt.getStatus(); - } else if (c == 4) { - return medInvt.getUser(); - } - return null; - } - - @Override - public boolean isCellEditable(int arg0, int arg1) { - return false; - } - - } - - private JComboBox getComboBox() { - if (statusComboBox == null) { - statusComboBox = new JComboBox<>(); - statusComboBox.addItem(""); - for (InventoryStatus currentStatus : InventoryStatus.values()) { - statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); - } - statusComboBox.addActionListener(actionEvent -> { + return jTableInventory; + } + + private JComboBox getComboBox() { + if (statusComboBox == null) { + statusComboBox = new JComboBox<>(); + statusComboBox.addItem(""); + for (InventoryStatus currentStatus : InventoryStatus.values()) { + statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); + } + statusComboBox.addActionListener(actionEvent -> { InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); totalRows = inventoryBrowsingModel.getRowCount(); startIndex = 0; @@ -563,26 +467,26 @@ private JComboBox getComboBox() { next.setEnabled(totalRows > PAGE_SIZE); jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); initialiseCombo(totalRows); - }); - } - return statusComboBox; - } - - private JLabel getStatusLabel() { - if (statusLabel == null) { - statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); - statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); - } - return statusLabel; - } - - private void ajustWidth() { + }); + } + return statusComboBox; + } + + private JLabel getStatusLabel() { + if (statusLabel == null) { + statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); + statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); + } + return statusLabel; + } + + private void ajustWidth() { for (int i = 0; i < pColumwidth.length; i++) { jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); } - } + } - public void initialiseCombo(int total_rows) { + public void initialiseCombo(int total_rows) { int j = 0; pagesCombo.removeAllItems(); @@ -596,20 +500,117 @@ public void initialiseCombo(int total_rows) { } else { under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); } - } - - @Override - public void InventoryInserted(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - @Override - public void InventoryUpdated(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - @Override - public void InventoryCancelled(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } + } + + @Override + public void InventoryInserted(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryUpdated(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryCancelled(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + class InventoryBrowsingModel extends DefaultTableModel { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public InventoryBrowsingModel() { + inventoryList = new ArrayList<>(); + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + + public InventoryBrowsingModel(int startIndex, int pageSize) { + inventoryList = new ArrayList<>(); + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, + startIndex, + pageSize); + inventoryList = medInventorypage.getContent(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + + @Override + public Class getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return String.class; + } else if (c == 3) { + return String.class; + } else if (c == 4) { + return String.class; + } + return null; + } + + @Override + public int getRowCount() { + if (inventoryList == null) { + return 0; + } + return inventoryList.size(); + } + + public String getColumnName(int c) { + return pColums[c]; + } + + public int getColumnCount() { + return pColums.length; + } + + @Override + public Object getValueAt(int r, int c) { + MedicalInventory medInvt = inventoryList.get(r); + + if (c == -1) { + return medInvt; + } else if (c == 0) { + return medInvt.getInventoryReference(); + } else if (c == 1) { + Ward ward = new Ward(); + try { + ward = wardBrowserManager.findWard(medInvt.getWard()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + return ward == null ? "" : ward.getDescription(); + } else if (c == 2) { + return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); + } else if (c == 3) { + return medInvt.getStatus(); + } else if (c == 4) { + return medInvt.getUser(); + } + return null; + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + return false; + } + + } } From 13908959157f40e1c79d508dced6bacef8e8b40e Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 10:23:24 +0100 Subject: [PATCH 34/83] Revert "Applying suggestion for change" --- bundle/language_en.properties | 4 +- .../gui/InventoryWardBrowser.java | 847 +++++++++--------- .../gui/InventoryWardEdit.java | 10 +- .../medicalinventory/gui/StockMedModel.java | 7 +- 4 files changed, 433 insertions(+), 435 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index fd5e62c312..d35a901a27 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -671,7 +671,7 @@ angal.hospital.visitendhour.txt angal.hospital.visitstarthour.txt = Visit start hour angal.lab.allnegative.txt = All negative. angal.invetory.allmedicaladdedsuccessfully.msg = All medicals are added successfully. -angal.inventory.allproduct.btn = All products +angal.inventory.allproduct.radio = All products angal.inventory.canceled = Canceled angal.inventory.cancelednoteditable.msg = A canceled inventory can not be modified. angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg = Cannot create another inventory with other in progress in this ward. @@ -729,7 +729,7 @@ angal.inventory.referenceshow.col angal.inventory.savesuccess.msg = Inventory saved. angal.inventory.searchproduct.txt = Search a product angal.inventory.selectward.label = Select ward -angal.inventory.specificproduct.btn = Specific product +angal.inventory.specificproduct.radio = Specific product angal.inventory.status.col = Status angal.inventory.status.label = Status angal.inventory.status.canceled.txt = Canceled diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index fd58efbc97..6ad5fb93c1 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -69,268 +69,268 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListener { - private static final long serialVersionUID = 1L; - private static int PAGE_SIZE = 50; - JButton next; - JButton previous; - JComboBox pagesCombo = new JComboBox<>(); - JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); - private GoodDateChooser jCalendarTo; - private GoodDateChooser jCalendarFrom; - private LocalDateTime dateFrom = TimeTools.getDateToday0(); - private LocalDateTime dateTo = TimeTools.getDateToday24(); - private JLabel jLabelTo; - private JLabel jLabelFrom; - private JPanel panelHeader; - private JPanel panelFooter; - private JPanel panelContent; - private JButton closeButton; - private JButton newButton; - private JButton editButton; - private JButton deleteButton; - private JButton viewButton; - private JScrollPane scrollPaneInventory; - private JTable jTableInventory; - private String[] pColums = { - MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), - MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), - MessageBundle.getMessage("angal.common.date.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), - MessageBundle.getMessage("angal.common.user.col").toUpperCase() - }; - private int[] pColumwidth = { 150, 150, 100, 100, 150 }; - private JComboBox statusComboBox; - private JLabel statusLabel; - private int startIndex; - private int totalRows; - private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); - private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); - private List inventoryList; - - public InventoryWardBrowser() { - initComponents(); - } - - private void initComponents() { - - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setMinimumSize(new Dimension(850, 550)); - setLocationRelativeTo(null); // center - setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); - - panelHeader = getPanelHeader(); - getContentPane().add(panelHeader, BorderLayout.NORTH); - - panelContent = getPanelContent(); - getContentPane().add(panelContent, BorderLayout.CENTER); - - panelFooter = getPanelFooter(); - getContentPane().add(panelFooter, BorderLayout.SOUTH); - - ajustWidth(); - - addWindowListener(new WindowAdapter() { - - public void windowClosing(WindowEvent e) { - dispose(); - } - }); + private static final long serialVersionUID = 1L; + + private GoodDateChooser jCalendarTo; + private GoodDateChooser jCalendarFrom; + private LocalDateTime dateFrom = TimeTools.getDateToday0(); + private LocalDateTime dateTo = TimeTools.getDateToday24(); + private JLabel jLabelTo; + private JLabel jLabelFrom; + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton newButton; + private JButton editButton; + private JButton deleteButton; + private JButton viewButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventory; + private String[] pColums = { + MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), + MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), + MessageBundle.getMessage("angal.common.date.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), + MessageBundle.getMessage("angal.common.user.col").toUpperCase() + }; + private int[] pColumwidth = { 150, 150, 100, 100, 150 }; + private JComboBox statusComboBox; + private JLabel statusLabel; + JButton next; + JButton previous; + JComboBox pagesCombo = new JComboBox<>(); + JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); + private static int PAGE_SIZE = 50; + private int startIndex; + private int totalRows; + private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); + private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); + private List inventoryList; + + public InventoryWardBrowser() { + initComponents(); + } + + private void initComponents() { + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new Dimension(850, 550)); + setLocationRelativeTo(null); // center + setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); + + panelHeader = getPanelHeader(); + getContentPane().add(panelHeader, BorderLayout.NORTH); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + panelFooter = getPanelFooter(); + getContentPane().add(panelFooter, BorderLayout.SOUTH); + + ajustWidth(); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + dispose(); + } + }); pagesCombo.setEditable(true); previous.setEnabled(false); next.setEnabled(false); next.addActionListener(actionEvent -> { - if (!previous.isEnabled()) { - previous.setEnabled(true); - } - startIndex += PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex + PAGE_SIZE > totalRows) { - next.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + if (!previous.isEnabled()) { + previous.setEnabled(true); + } + startIndex += PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex + PAGE_SIZE > totalRows) { + next.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); - previous.addActionListener(actionEvent -> { - if (!next.isEnabled()) { - next.setEnabled(true); - } - startIndex -= PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex < PAGE_SIZE) { - previous.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + previous.addActionListener(actionEvent -> { + if (!next.isEnabled()) { + next.setEnabled(true); + } + startIndex -= PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex < PAGE_SIZE) { + previous.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); pagesCombo.addItemListener(itemEvent -> { - int eventID = itemEvent.getStateChange(); + int eventID = itemEvent.getStateChange(); - if (eventID == ItemEvent.SELECTED) { - int page_number = (Integer) pagesCombo.getSelectedItem(); - startIndex = (page_number - 1) * PAGE_SIZE; + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; - next.setEnabled(startIndex + PAGE_SIZE <= totalRows); - previous.setEnabled(page_number != 1); - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + next.setEnabled(startIndex + PAGE_SIZE <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - pagesCombo.setEnabled(true); - } + pagesCombo.setEnabled(true); + } }); - } - - private JPanel getPanelHeader() { - if (panelHeader == null) { - panelHeader = new JPanel(); - panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); - GridBagLayout gbl_panelHeader = new GridBagLayout(); - gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; - gbl_panelHeader.rowHeights = new int[] { 32, 0 }; - gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; - gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; - panelHeader.setLayout(gbl_panelHeader); - GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); - gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; - gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); - gbc_jLabelFrom.gridx = 0; - gbc_jLabelFrom.gridy = 0; - panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); - GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); - gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); - gbc_jCalendarFrom.gridx = 1; - gbc_jCalendarFrom.gridy = 0; - panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); - GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); - gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; - gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); - gbc_jLabelTo.gridx = 2; - gbc_jLabelTo.gridy = 0; - panelHeader.add(getJLabelTo(), gbc_jLabelTo); - GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); - gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); - gbc_jCalendarTo.gridx = 3; - gbc_jCalendarTo.gridy = 0; - panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); - GridBagConstraints gbc_statusLabel = new GridBagConstraints(); - gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL; - gbc_statusLabel.insets = new Insets(0, 0, 0, 5); - gbc_statusLabel.gridx = 4; - gbc_statusLabel.gridy = 0; - panelHeader.add(getStatusLabel(), gbc_statusLabel); - GridBagConstraints gbc_comboBox = new GridBagConstraints(); - gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_comboBox.gridx = 5; - gbc_comboBox.gridy = 0; - panelHeader.add(getComboBox(), gbc_comboBox); - } - return panelHeader; - } - - private JPanel getPanelContent() { - if (panelContent == null) { - panelContent = new JPanel(); - GridBagLayout gbl_panelContent = new GridBagLayout(); - gbl_panelContent.columnWidths = new int[] { 452, 0 }; - gbl_panelContent.rowHeights = new int[] { 402, 0 }; - gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; - gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; - panelContent.setLayout(gbl_panelContent); - GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); - gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; - gbc_scrollPaneInventory.gridx = 0; - gbc_scrollPaneInventory.gridy = 0; - panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); - } - return panelContent; - } - - private JPanel getPanelFooter() { - if (panelFooter == null) { - panelFooter = new JPanel(); - next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); - next.setMnemonic(KeyEvent.VK_RIGHT); - previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); - next.setMnemonic(KeyEvent.VK_LEFT); - - panelFooter.add(previous); - panelFooter.add(pagesCombo); - panelFooter.add(under); - panelFooter.add(next); - - panelFooter.add(getNewButton()); - panelFooter.add(getViewButton()); - panelFooter.add(getEditButton()); - panelFooter.add(getDeleteButton()); - panelFooter.add(getCloseButton()); - } - return panelFooter; - } - - private GoodDateChooser getJCalendarFrom() { - if (jCalendarFrom == null) { - jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); - jCalendarFrom.addDateChangeListener(event -> { - dateFrom = jCalendarFrom.getDateStartOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - totalRows = inventoryModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); - } - return jCalendarFrom; - } - - private GoodDateChooser getJCalendarTo() { - if (jCalendarTo == null) { - jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); - jCalendarTo.addDateChangeListener(event -> { - dateTo = jCalendarTo.getDateEndOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - totalRows = inventoryModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); - } - return jCalendarTo; - } - - private JLabel getJLabelTo() { - if (jLabelTo == null) { - jLabelTo = new JLabel(); - jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); - } - return jLabelTo; - } - - private JLabel getJLabelFrom() { - if (jLabelFrom == null) { - jLabelFrom = new JLabel(); - jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); - } - return jLabelFrom; - } - - private JButton getNewButton() { - newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); - newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); - newButton.addActionListener(actionEvent -> { - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); - return newButton; - } - - private JButton getEditButton() { + } + + private JPanel getPanelHeader() { + if (panelHeader == null) { + panelHeader = new JPanel(); + panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); + GridBagLayout gbl_panelHeader = new GridBagLayout(); + gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; + gbl_panelHeader.rowHeights = new int[] { 32, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; + panelHeader.setLayout(gbl_panelHeader); + GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); + gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); + gbc_jLabelFrom.gridx = 0; + gbc_jLabelFrom.gridy = 0; + panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); + GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); + gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarFrom.gridx = 1; + gbc_jCalendarFrom.gridy = 0; + panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); + GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); + gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); + gbc_jLabelTo.gridx = 2; + gbc_jLabelTo.gridy = 0; + panelHeader.add(getJLabelTo(), gbc_jLabelTo); + GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); + gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarTo.gridx = 3; + gbc_jCalendarTo.gridy = 0; + panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); + GridBagConstraints gbc_stateLabel = new GridBagConstraints(); + gbc_stateLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_stateLabel.insets = new Insets(0, 0, 0, 5); + gbc_stateLabel.gridx = 4; + gbc_stateLabel.gridy = 0; + panelHeader.add(getStatusLabel(), gbc_stateLabel); + GridBagConstraints gbc_comboBox = new GridBagConstraints(); + gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_comboBox.gridx = 5; + gbc_comboBox.gridy = 0; + panelHeader.add(getComboBox(), gbc_comboBox); + } + return panelHeader; + } + + private JPanel getPanelContent() { + if (panelContent == null) { + panelContent = new JPanel(); + GridBagLayout gbl_panelContent = new GridBagLayout(); + gbl_panelContent.columnWidths = new int[] { 452, 0 }; + gbl_panelContent.rowHeights = new int[] { 402, 0 }; + gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + panelContent.setLayout(gbl_panelContent); + GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); + gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; + gbc_scrollPaneInventory.gridx = 0; + gbc_scrollPaneInventory.gridy = 0; + panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); + } + return panelContent; + } + + private JPanel getPanelFooter() { + if (panelFooter == null) { + panelFooter = new JPanel(); + next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); + next.setMnemonic(KeyEvent.VK_RIGHT); + previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); + next.setMnemonic(KeyEvent.VK_LEFT); + + panelFooter.add(previous); + panelFooter.add(pagesCombo); + panelFooter.add(under); + panelFooter.add(next); + + panelFooter.add(getNewButton()); + panelFooter.add(getViewButton()); + panelFooter.add(getEditButton()); + panelFooter.add(getDeleteButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private GoodDateChooser getJCalendarFrom() { + if (jCalendarFrom == null) { + jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarFrom.addDateChangeListener(event -> { + dateFrom = jCalendarFrom.getDateStartOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarFrom; + } + + private GoodDateChooser getJCalendarTo() { + if (jCalendarTo == null) { + jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarTo.addDateChangeListener(event -> { + dateTo = jCalendarTo.getDateEndOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarTo; + } + + private JLabel getJLabelTo() { + if (jLabelTo == null) { + jLabelTo = new JLabel(); + jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); + } + return jLabelTo; + } + + private JLabel getJLabelFrom() { + if (jLabelFrom == null) { + jLabelFrom = new JLabel(); + jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); + } + return jLabelFrom; + } + + private JButton getNewButton() { + newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); + newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); + newButton.addActionListener(actionEvent -> { + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); + return newButton; + } + + private JButton getEditButton() { editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); editButton.setEnabled(false); @@ -355,11 +355,11 @@ private JButton getEditButton() { inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); return editButton; - } + } - private JButton getViewButton() { - viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); - viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); + private JButton getViewButton() { + viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); + viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); viewButton.setEnabled(false); viewButton.addActionListener(actionEvent -> { MedicalInventory inventory; @@ -377,12 +377,12 @@ private JButton getViewButton() { InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); - return viewButton; - } + return viewButton; + } - private JButton getDeleteButton() { - deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); - deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); + private JButton getDeleteButton() { + deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); + deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); deleteButton.setEnabled(false); deleteButton.addActionListener(actionEvent -> { if (jTableInventory.getSelectedRowCount() > 1) { @@ -411,30 +411,30 @@ private JButton getDeleteButton() { MessageDialog.error(this, "angal.inventory.deletion.error.msg"); } }); - return deleteButton; - } - - private JButton getCloseButton() { - closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); - closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(actionEvent -> dispose()); - return closeButton; - } - - private JScrollPane getScrollPaneInventory() { - if (scrollPaneInventory == null) { - scrollPaneInventory = new JScrollPane(); - scrollPaneInventory.setViewportView(getJTableInventory()); - } - return scrollPaneInventory; - } - - private JTable getJTableInventory() { - if (jTableInventory == null) { - jTableInventory = new JTable(); - jTableInventory.setFillsViewportHeight(true); - jTableInventory.setModel(new InventoryBrowsingModel()); - jTableInventory.getSelectionModel().addListSelectionListener(e -> { + return deleteButton; + } + + private JButton getCloseButton() { + closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); + closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); + closeButton.addActionListener(actionEvent -> dispose()); + return closeButton; + } + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + scrollPaneInventory.setViewportView(getJTableInventory()); + } + return scrollPaneInventory; + } + + private JTable getJTableInventory() { + if (jTableInventory == null) { + jTableInventory = new JTable(); + jTableInventory.setFillsViewportHeight(true); + jTableInventory.setModel(new InventoryBrowsingModel()); + jTableInventory.getSelectionModel().addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { int[] selectedRows = jTableInventory.getSelectedRows(); if (selectedRows.length == 1) { @@ -447,19 +447,115 @@ private JTable getJTableInventory() { deleteButton.setEnabled(false); } } - }); + }); + } + return jTableInventory; + } + + class InventoryBrowsingModel extends DefaultTableModel { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public InventoryBrowsingModel() { + inventoryList = new ArrayList<>(); + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + + public InventoryBrowsingModel(int startIndex, int pageSize) { + inventoryList = new ArrayList<>(); + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, startIndex, + pageSize); + inventoryList = medInventorypage.getContent(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } } - return jTableInventory; - } - - private JComboBox getComboBox() { - if (statusComboBox == null) { - statusComboBox = new JComboBox<>(); - statusComboBox.addItem(""); - for (InventoryStatus currentStatus : InventoryStatus.values()) { - statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); - } - statusComboBox.addActionListener(actionEvent -> { + + @Override + public Class getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return String.class; + } else if (c == 3) { + return String.class; + } else if (c == 4) { + return String.class; + } + return null; + } + + @Override + public int getRowCount() { + if (inventoryList == null) { + return 0; + } + return inventoryList.size(); + } + + public String getColumnName(int c) { + return pColums[c]; + } + + public int getColumnCount() { + return pColums.length; + } + + @Override + public Object getValueAt(int r, int c) { + MedicalInventory medInvt = inventoryList.get(r); + + if (c == -1) { + return medInvt; + } else if (c == 0) { + return medInvt.getInventoryReference(); + } else if (c == 1) { + Ward ward = new Ward(); + try { + ward = wardBrowserManager.findWard(medInvt.getWard()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + return ward == null ? "" : ward.getDescription(); + } else if (c == 2) { + return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); + } else if (c == 3) { + return medInvt.getStatus(); + } else if (c == 4) { + return medInvt.getUser(); + } + return null; + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + return false; + } + + } + + private JComboBox getComboBox() { + if (statusComboBox == null) { + statusComboBox = new JComboBox<>(); + statusComboBox.addItem(""); + for (InventoryStatus currentStatus : InventoryStatus.values()) { + statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); + } + statusComboBox.addActionListener(actionEvent -> { InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); totalRows = inventoryBrowsingModel.getRowCount(); startIndex = 0; @@ -467,26 +563,26 @@ private JComboBox getComboBox() { next.setEnabled(totalRows > PAGE_SIZE); jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); initialiseCombo(totalRows); - }); - } - return statusComboBox; - } - - private JLabel getStatusLabel() { - if (statusLabel == null) { - statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); - statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); - } - return statusLabel; - } - - private void ajustWidth() { + }); + } + return statusComboBox; + } + + private JLabel getStatusLabel() { + if (statusLabel == null) { + statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); + statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); + } + return statusLabel; + } + + private void ajustWidth() { for (int i = 0; i < pColumwidth.length; i++) { jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); } - } + } - public void initialiseCombo(int total_rows) { + public void initialiseCombo(int total_rows) { int j = 0; pagesCombo.removeAllItems(); @@ -500,117 +596,20 @@ public void initialiseCombo(int total_rows) { } else { under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); } - } - - @Override - public void InventoryInserted(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - @Override - public void InventoryUpdated(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - @Override - public void InventoryCancelled(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - class InventoryBrowsingModel extends DefaultTableModel { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public InventoryBrowsingModel() { - inventoryList = new ArrayList<>(); - String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - public InventoryBrowsingModel(int startIndex, int pageSize) { - inventoryList = new ArrayList<>(); - String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, - startIndex, - pageSize); - inventoryList = medInventorypage.getContent(); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - @Override - public Class getColumnClass(int c) { - if (c == 0) { - return String.class; - } else if (c == 1) { - return String.class; - } else if (c == 2) { - return String.class; - } else if (c == 3) { - return String.class; - } else if (c == 4) { - return String.class; - } - return null; - } - - @Override - public int getRowCount() { - if (inventoryList == null) { - return 0; - } - return inventoryList.size(); - } - - public String getColumnName(int c) { - return pColums[c]; - } - - public int getColumnCount() { - return pColums.length; - } - - @Override - public Object getValueAt(int r, int c) { - MedicalInventory medInvt = inventoryList.get(r); - - if (c == -1) { - return medInvt; - } else if (c == 0) { - return medInvt.getInventoryReference(); - } else if (c == 1) { - Ward ward = new Ward(); - try { - ward = wardBrowserManager.findWard(medInvt.getWard()); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - return ward == null ? "" : ward.getDescription(); - } else if (c == 2) { - return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); - } else if (c == 3) { - return medInvt.getStatus(); - } else if (c == 4) { - return medInvt.getUser(); - } - return null; - } - - @Override - public boolean isCellEditable(int arg0, int arg1) { - return false; - } - - } + } + + @Override + public void InventoryInserted(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryUpdated(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryCancelled(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } } diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index 0f785824ec..e84b1be6a4 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -1041,7 +1041,7 @@ private boolean existInInventorySearchList(MedicalInventoryRow inventoryRow) { private JRadioButton getSpecificRadio() { if (specificRadio == null) { - specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.btn")); + specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); specificRadio.addActionListener(actionEvent -> { if (specificRadio.isSelected()) { codeTextField.setEnabled(true); @@ -1055,7 +1055,7 @@ private JRadioButton getSpecificRadio() { private JRadioButton getAllRadio() { if (allRadio == null) { - allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.btn")); + allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); allRadio.setSelected(inventory != null); specificRadio.setSelected(inventory == null); allRadio.addActionListener(actionEvent -> { @@ -1198,7 +1198,7 @@ private Medical chooseMedical(String text) throws OHServiceException { key = med.getCode().toString().toLowerCase(); medicalMap.put(key, med); } - List medList = new ArrayList<>(); + ArrayList medList = new ArrayList<>(); for (Medical aMed : medicalMap.values()) { if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { medList.add(aMed); @@ -1341,7 +1341,7 @@ private JComboBox getWardComboBox() { } if (medicalWardInventoryDraft.isEmpty() && medicalWardInventoryValidated.isEmpty()) { - activateSomeComponents(); + activedSomeComponents(); } else { MessageDialog.error(this, "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); @@ -1402,7 +1402,7 @@ private void disabledSomeComponents() { deleteButton.setEnabled(false); } - private void activateSomeComponents() { + private void activedSomeComponents() { jCalendarInventory.setEnabled(true); specificRadio.setEnabled(true); codeTextField.setEnabled(true); diff --git a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java index 8f526e73e8..51a474564c 100644 --- a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java +++ b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import javax.swing.table.DefaultTableModel; @@ -34,10 +33,10 @@ public class StockMedModel extends DefaultTableModel { private static final long serialVersionUID = 1L; - private List medList; - private List initList = new ArrayList<>(); + private ArrayList medList; + private ArrayList initList = new ArrayList(); - public StockMedModel(List meds) { + public StockMedModel(ArrayList meds) { medList = meds; initList.addAll(medList); } From 65d64e88209a2f723a8908e4f0780a830098736a Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 11:51:20 +0100 Subject: [PATCH 35/83] Fix format issues --- .../gui/InventoryWardBrowser.java | 847 +++++++++--------- 1 file changed, 424 insertions(+), 423 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 6ad5fb93c1..00f2abfceb 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -69,268 +69,268 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListener { - private static final long serialVersionUID = 1L; - - private GoodDateChooser jCalendarTo; - private GoodDateChooser jCalendarFrom; - private LocalDateTime dateFrom = TimeTools.getDateToday0(); - private LocalDateTime dateTo = TimeTools.getDateToday24(); - private JLabel jLabelTo; - private JLabel jLabelFrom; - private JPanel panelHeader; - private JPanel panelFooter; - private JPanel panelContent; - private JButton closeButton; - private JButton newButton; - private JButton editButton; - private JButton deleteButton; - private JButton viewButton; - private JScrollPane scrollPaneInventory; - private JTable jTableInventory; - private String[] pColums = { - MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), - MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), - MessageBundle.getMessage("angal.common.date.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), - MessageBundle.getMessage("angal.common.user.col").toUpperCase() - }; - private int[] pColumwidth = { 150, 150, 100, 100, 150 }; - private JComboBox statusComboBox; - private JLabel statusLabel; - JButton next; - JButton previous; - JComboBox pagesCombo = new JComboBox<>(); - JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); - private static int PAGE_SIZE = 50; - private int startIndex; - private int totalRows; - private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); - private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); - private List inventoryList; - - public InventoryWardBrowser() { - initComponents(); - } - - private void initComponents() { - - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setMinimumSize(new Dimension(850, 550)); - setLocationRelativeTo(null); // center - setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); - - panelHeader = getPanelHeader(); - getContentPane().add(panelHeader, BorderLayout.NORTH); - - panelContent = getPanelContent(); - getContentPane().add(panelContent, BorderLayout.CENTER); - - panelFooter = getPanelFooter(); - getContentPane().add(panelFooter, BorderLayout.SOUTH); - - ajustWidth(); - - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - dispose(); - } - }); + private static final long serialVersionUID = 1L; + private static int PAGE_SIZE = 50; + JButton next; + JButton previous; + JComboBox pagesCombo = new JComboBox<>(); + JLabel under = new JLabel("/ 0 " + MessageBundle.getMessage("angal.inventory.page.text")); + private GoodDateChooser jCalendarTo; + private GoodDateChooser jCalendarFrom; + private LocalDateTime dateFrom = TimeTools.getDateToday0(); + private LocalDateTime dateTo = TimeTools.getDateToday24(); + private JLabel jLabelTo; + private JLabel jLabelFrom; + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton newButton; + private JButton editButton; + private JButton deleteButton; + private JButton viewButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventory; + private String[] pColums = { + MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), + MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), + MessageBundle.getMessage("angal.common.date.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), + MessageBundle.getMessage("angal.common.user.col").toUpperCase() + }; + private int[] pColumwidth = { 150, 150, 100, 100, 150 }; + private JComboBox statusComboBox; + private JLabel statusLabel; + private int startIndex; + private int totalRows; + private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); + private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); + private List inventoryList; + + public InventoryWardBrowser() { + initComponents(); + } + + private void initComponents() { + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new Dimension(850, 550)); + setLocationRelativeTo(null); // center + setTitle(MessageBundle.getMessage("angal.inventory.managementward.title")); + + panelHeader = getPanelHeader(); + getContentPane().add(panelHeader, BorderLayout.NORTH); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + panelFooter = getPanelFooter(); + getContentPane().add(panelFooter, BorderLayout.SOUTH); + + ajustWidth(); + + addWindowListener(new WindowAdapter() { + + public void windowClosing(WindowEvent e) { + dispose(); + } + }); pagesCombo.setEditable(true); previous.setEnabled(false); next.setEnabled(false); next.addActionListener(actionEvent -> { - if (!previous.isEnabled()) { - previous.setEnabled(true); - } - startIndex += PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex + PAGE_SIZE > totalRows) { - next.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + if (!previous.isEnabled()) { + previous.setEnabled(true); + } + startIndex += PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex + PAGE_SIZE > totalRows) { + next.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); - previous.addActionListener(actionEvent -> { - if (!next.isEnabled()) { - next.setEnabled(true); - } - startIndex -= PAGE_SIZE; - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - if (startIndex < PAGE_SIZE) { - previous.setEnabled(false); - } - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + previous.addActionListener(actionEvent -> { + if (!next.isEnabled()) { + next.setEnabled(true); + } + startIndex -= PAGE_SIZE; + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + if (startIndex < PAGE_SIZE) { + previous.setEnabled(false); + } + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); }); pagesCombo.addItemListener(itemEvent -> { - int eventID = itemEvent.getStateChange(); + int eventID = itemEvent.getStateChange(); - if (eventID == ItemEvent.SELECTED) { - int page_number = (Integer) pagesCombo.getSelectedItem(); - startIndex = (page_number - 1) * PAGE_SIZE; + if (eventID == ItemEvent.SELECTED) { + int page_number = (Integer) pagesCombo.getSelectedItem(); + startIndex = (page_number - 1) * PAGE_SIZE; - next.setEnabled(startIndex + PAGE_SIZE <= totalRows); - previous.setEnabled(page_number != 1); - pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + next.setEnabled(startIndex + PAGE_SIZE <= totalRows); + previous.setEnabled(page_number != 1); + pagesCombo.setSelectedItem(startIndex / PAGE_SIZE + 1); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - pagesCombo.setEnabled(true); - } + pagesCombo.setEnabled(true); + } }); - } - - private JPanel getPanelHeader() { - if (panelHeader == null) { - panelHeader = new JPanel(); - panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); - GridBagLayout gbl_panelHeader = new GridBagLayout(); - gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; - gbl_panelHeader.rowHeights = new int[] { 32, 0 }; - gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; - gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; - panelHeader.setLayout(gbl_panelHeader); - GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); - gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; - gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); - gbc_jLabelFrom.gridx = 0; - gbc_jLabelFrom.gridy = 0; - panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); - GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); - gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); - gbc_jCalendarFrom.gridx = 1; - gbc_jCalendarFrom.gridy = 0; - panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); - GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); - gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; - gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); - gbc_jLabelTo.gridx = 2; - gbc_jLabelTo.gridy = 0; - panelHeader.add(getJLabelTo(), gbc_jLabelTo); - GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); - gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; - gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); - gbc_jCalendarTo.gridx = 3; - gbc_jCalendarTo.gridy = 0; - panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); - GridBagConstraints gbc_stateLabel = new GridBagConstraints(); - gbc_stateLabel.fill = GridBagConstraints.HORIZONTAL; - gbc_stateLabel.insets = new Insets(0, 0, 0, 5); - gbc_stateLabel.gridx = 4; - gbc_stateLabel.gridy = 0; - panelHeader.add(getStatusLabel(), gbc_stateLabel); - GridBagConstraints gbc_comboBox = new GridBagConstraints(); - gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; - gbc_comboBox.gridx = 5; - gbc_comboBox.gridy = 0; - panelHeader.add(getComboBox(), gbc_comboBox); - } - return panelHeader; - } - - private JPanel getPanelContent() { - if (panelContent == null) { - panelContent = new JPanel(); - GridBagLayout gbl_panelContent = new GridBagLayout(); - gbl_panelContent.columnWidths = new int[] { 452, 0 }; - gbl_panelContent.rowHeights = new int[] { 402, 0 }; - gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; - gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; - panelContent.setLayout(gbl_panelContent); - GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); - gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; - gbc_scrollPaneInventory.gridx = 0; - gbc_scrollPaneInventory.gridy = 0; - panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); - } - return panelContent; - } - - private JPanel getPanelFooter() { - if (panelFooter == null) { - panelFooter = new JPanel(); - next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); - next.setMnemonic(KeyEvent.VK_RIGHT); - previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); - next.setMnemonic(KeyEvent.VK_LEFT); - - panelFooter.add(previous); - panelFooter.add(pagesCombo); - panelFooter.add(under); - panelFooter.add(next); - - panelFooter.add(getNewButton()); - panelFooter.add(getViewButton()); - panelFooter.add(getEditButton()); - panelFooter.add(getDeleteButton()); - panelFooter.add(getCloseButton()); - } - return panelFooter; - } - - private GoodDateChooser getJCalendarFrom() { - if (jCalendarFrom == null) { - jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); - jCalendarFrom.addDateChangeListener(event -> { - dateFrom = jCalendarFrom.getDateStartOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - totalRows = inventoryModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); - } - return jCalendarFrom; - } - - private GoodDateChooser getJCalendarTo() { - if (jCalendarTo == null) { - jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); - jCalendarTo.addDateChangeListener(event -> { - dateTo = jCalendarTo.getDateEndOfDay(); - InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); - totalRows = inventoryModel.getRowCount(); - startIndex = 0; - previous.setEnabled(false); - next.setEnabled(totalRows > PAGE_SIZE); - jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); - initialiseCombo(totalRows); - }); - } - return jCalendarTo; - } - - private JLabel getJLabelTo() { - if (jLabelTo == null) { - jLabelTo = new JLabel(); - jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); - } - return jLabelTo; - } - - private JLabel getJLabelFrom() { - if (jLabelFrom == null) { - jLabelFrom = new JLabel(); - jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); - jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); - } - return jLabelFrom; - } - - private JButton getNewButton() { - newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); - newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); - newButton.addActionListener(actionEvent -> { - InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); - InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); - inventoryWardEdit.showAsModal(InventoryWardBrowser.this); - }); - return newButton; - } - - private JButton getEditButton() { + } + + private JPanel getPanelHeader() { + if (panelHeader == null) { + panelHeader = new JPanel(); + panelHeader.setBorder(new EmptyBorder(5, 0, 0, 5)); + GridBagLayout gbl_panelHeader = new GridBagLayout(); + gbl_panelHeader.columnWidths = new int[] { 65, 103, 69, 105, 77, 146, 0 }; + gbl_panelHeader.rowHeights = new int[] { 32, 0 }; + gbl_panelHeader.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_panelHeader.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; + panelHeader.setLayout(gbl_panelHeader); + GridBagConstraints gbc_jLabelFrom = new GridBagConstraints(); + gbc_jLabelFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelFrom.insets = new Insets(0, 0, 0, 5); + gbc_jLabelFrom.gridx = 0; + gbc_jLabelFrom.gridy = 0; + panelHeader.add(getJLabelFrom(), gbc_jLabelFrom); + GridBagConstraints gbc_jCalendarFrom = new GridBagConstraints(); + gbc_jCalendarFrom.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarFrom.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarFrom.gridx = 1; + gbc_jCalendarFrom.gridy = 0; + panelHeader.add(getJCalendarFrom(), gbc_jCalendarFrom); + GridBagConstraints gbc_jLabelTo = new GridBagConstraints(); + gbc_jLabelTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jLabelTo.insets = new Insets(0, 0, 0, 5); + gbc_jLabelTo.gridx = 2; + gbc_jLabelTo.gridy = 0; + panelHeader.add(getJLabelTo(), gbc_jLabelTo); + GridBagConstraints gbc_jCalendarTo = new GridBagConstraints(); + gbc_jCalendarTo.fill = GridBagConstraints.HORIZONTAL; + gbc_jCalendarTo.insets = new Insets(0, 0, 0, 5); + gbc_jCalendarTo.gridx = 3; + gbc_jCalendarTo.gridy = 0; + panelHeader.add(getJCalendarTo(), gbc_jCalendarTo); + GridBagConstraints gbc_stateLabel = new GridBagConstraints(); + gbc_stateLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_stateLabel.insets = new Insets(0, 0, 0, 5); + gbc_stateLabel.gridx = 4; + gbc_stateLabel.gridy = 0; + panelHeader.add(getStatusLabel(), gbc_stateLabel); + GridBagConstraints gbc_comboBox = new GridBagConstraints(); + gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; + gbc_comboBox.gridx = 5; + gbc_comboBox.gridy = 0; + panelHeader.add(getComboBox(), gbc_comboBox); + } + return panelHeader; + } + + private JPanel getPanelContent() { + if (panelContent == null) { + panelContent = new JPanel(); + GridBagLayout gbl_panelContent = new GridBagLayout(); + gbl_panelContent.columnWidths = new int[] { 452, 0 }; + gbl_panelContent.rowHeights = new int[] { 402, 0 }; + gbl_panelContent.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panelContent.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; + panelContent.setLayout(gbl_panelContent); + GridBagConstraints gbc_scrollPaneInventory = new GridBagConstraints(); + gbc_scrollPaneInventory.fill = GridBagConstraints.BOTH; + gbc_scrollPaneInventory.gridx = 0; + gbc_scrollPaneInventory.gridy = 0; + panelContent.add(getScrollPaneInventory(), gbc_scrollPaneInventory); + } + return panelContent; + } + + private JPanel getPanelFooter() { + if (panelFooter == null) { + panelFooter = new JPanel(); + next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn")); + next.setMnemonic(KeyEvent.VK_RIGHT); + previous = new JButton(MessageBundle.getMessage("angal.inventory.previousarrow.btn")); + next.setMnemonic(KeyEvent.VK_LEFT); + + panelFooter.add(previous); + panelFooter.add(pagesCombo); + panelFooter.add(under); + panelFooter.add(next); + + panelFooter.add(getNewButton()); + panelFooter.add(getViewButton()); + panelFooter.add(getEditButton()); + panelFooter.add(getDeleteButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private GoodDateChooser getJCalendarFrom() { + if (jCalendarFrom == null) { + jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarFrom.addDateChangeListener(event -> { + dateFrom = jCalendarFrom.getDateStartOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarFrom; + } + + private GoodDateChooser getJCalendarTo() { + if (jCalendarTo == null) { + jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false); + jCalendarTo.addDateChangeListener(event -> { + dateTo = jCalendarTo.getDateEndOfDay(); + InventoryBrowsingModel inventoryModel = new InventoryBrowsingModel(); + totalRows = inventoryModel.getRowCount(); + startIndex = 0; + previous.setEnabled(false); + next.setEnabled(totalRows > PAGE_SIZE); + jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); + initialiseCombo(totalRows); + }); + } + return jCalendarTo; + } + + private JLabel getJLabelTo() { + if (jLabelTo == null) { + jLabelTo = new JLabel(); + jLabelTo.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelTo.setText(MessageBundle.getMessage("angal.common.dateto.label")); + } + return jLabelTo; + } + + private JLabel getJLabelFrom() { + if (jLabelFrom == null) { + jLabelFrom = new JLabel(); + jLabelFrom.setHorizontalAlignment(SwingConstants.RIGHT); + jLabelFrom.setText(MessageBundle.getMessage("angal.common.datefrom.label")); + } + return jLabelFrom; + } + + private JButton getNewButton() { + newButton = new JButton(MessageBundle.getMessage("angal.common.new.btn")); + newButton.setMnemonic(MessageBundle.getMnemonic("angal.common.new.btn.key")); + newButton.addActionListener(actionEvent -> { + InventoryWardEdit inventoryWardEdit = new InventoryWardEdit(); + InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); + inventoryWardEdit.showAsModal(InventoryWardBrowser.this); + }); + return newButton; + } + + private JButton getEditButton() { editButton = new JButton(MessageBundle.getMessage("angal.common.update.btn")); editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.update.btn.key")); editButton.setEnabled(false); @@ -355,11 +355,11 @@ private JButton getEditButton() { inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); return editButton; - } + } - private JButton getViewButton() { - viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); - viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); + private JButton getViewButton() { + viewButton = new JButton(MessageBundle.getMessage("angal.inventory.view.btn")); + viewButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key")); viewButton.setEnabled(false); viewButton.addActionListener(actionEvent -> { MedicalInventory inventory; @@ -377,12 +377,12 @@ private JButton getViewButton() { InventoryWardEdit.addInventoryListener(InventoryWardBrowser.this); inventoryWardEdit.showAsModal(InventoryWardBrowser.this); }); - return viewButton; - } + return viewButton; + } - private JButton getDeleteButton() { - deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); - deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); + private JButton getDeleteButton() { + deleteButton = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); + deleteButton.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); deleteButton.setEnabled(false); deleteButton.addActionListener(actionEvent -> { if (jTableInventory.getSelectedRowCount() > 1) { @@ -411,30 +411,30 @@ private JButton getDeleteButton() { MessageDialog.error(this, "angal.inventory.deletion.error.msg"); } }); - return deleteButton; - } - - private JButton getCloseButton() { - closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); - closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); - closeButton.addActionListener(actionEvent -> dispose()); - return closeButton; - } - - private JScrollPane getScrollPaneInventory() { - if (scrollPaneInventory == null) { - scrollPaneInventory = new JScrollPane(); - scrollPaneInventory.setViewportView(getJTableInventory()); - } - return scrollPaneInventory; - } - - private JTable getJTableInventory() { - if (jTableInventory == null) { - jTableInventory = new JTable(); - jTableInventory.setFillsViewportHeight(true); - jTableInventory.setModel(new InventoryBrowsingModel()); - jTableInventory.getSelectionModel().addListSelectionListener(e -> { + return deleteButton; + } + + private JButton getCloseButton() { + closeButton = new JButton(MessageBundle.getMessage("angal.common.close.btn")); + closeButton.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); + closeButton.addActionListener(actionEvent -> dispose()); + return closeButton; + } + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + scrollPaneInventory.setViewportView(getJTableInventory()); + } + return scrollPaneInventory; + } + + private JTable getJTableInventory() { + if (jTableInventory == null) { + jTableInventory = new JTable(); + jTableInventory.setFillsViewportHeight(true); + jTableInventory.setModel(new InventoryBrowsingModel()); + jTableInventory.getSelectionModel().addListSelectionListener(e -> { if (e.getValueIsAdjusting()) { int[] selectedRows = jTableInventory.getSelectedRows(); if (selectedRows.length == 1) { @@ -447,115 +447,19 @@ private JTable getJTableInventory() { deleteButton.setEnabled(false); } } - }); - } - return jTableInventory; - } - - class InventoryBrowsingModel extends DefaultTableModel { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public InventoryBrowsingModel() { - inventoryList = new ArrayList<>(); - String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - public InventoryBrowsingModel(int startIndex, int pageSize) { - inventoryList = new ArrayList<>(); - String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; - String type = InventoryType.ward.toString(); - try { - Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, startIndex, - pageSize); - inventoryList = medInventorypage.getContent(); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - - @Override - public Class getColumnClass(int c) { - if (c == 0) { - return String.class; - } else if (c == 1) { - return String.class; - } else if (c == 2) { - return String.class; - } else if (c == 3) { - return String.class; - } else if (c == 4) { - return String.class; - } - return null; - } - - @Override - public int getRowCount() { - if (inventoryList == null) { - return 0; - } - return inventoryList.size(); + }); } - - public String getColumnName(int c) { - return pColums[c]; - } - - public int getColumnCount() { - return pColums.length; - } - - @Override - public Object getValueAt(int r, int c) { - MedicalInventory medInvt = inventoryList.get(r); - - if (c == -1) { - return medInvt; - } else if (c == 0) { - return medInvt.getInventoryReference(); - } else if (c == 1) { - Ward ward = new Ward(); - try { - ward = wardBrowserManager.findWard(medInvt.getWard()); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - return ward == null ? "" : ward.getDescription(); - } else if (c == 2) { - return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); - } else if (c == 3) { - return medInvt.getStatus(); - } else if (c == 4) { - return medInvt.getUser(); - } - return null; - } - - @Override - public boolean isCellEditable(int arg0, int arg1) { - return false; - } - - } - - private JComboBox getComboBox() { - if (statusComboBox == null) { - statusComboBox = new JComboBox<>(); - statusComboBox.addItem(""); - for (InventoryStatus currentStatus : InventoryStatus.values()) { - statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); - } - statusComboBox.addActionListener(actionEvent -> { + return jTableInventory; + } + + private JComboBox getComboBox() { + if (statusComboBox == null) { + statusComboBox = new JComboBox<>(); + statusComboBox.addItem(""); + for (InventoryStatus currentStatus : InventoryStatus.values()) { + statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus)); + } + statusComboBox.addActionListener(actionEvent -> { InventoryBrowsingModel inventoryBrowsingModel = new InventoryBrowsingModel(); totalRows = inventoryBrowsingModel.getRowCount(); startIndex = 0; @@ -563,26 +467,26 @@ private JComboBox getComboBox() { next.setEnabled(totalRows > PAGE_SIZE); jTableInventory.setModel(new InventoryBrowsingModel(startIndex, PAGE_SIZE)); initialiseCombo(totalRows); - }); - } - return statusComboBox; - } - - private JLabel getStatusLabel() { - if (statusLabel == null) { - statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); - statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); - } - return statusLabel; - } - - private void ajustWidth() { + }); + } + return statusComboBox; + } + + private JLabel getStatusLabel() { + if (statusLabel == null) { + statusLabel = new JLabel(MessageBundle.getMessage("angal.inventory.status.label")); + statusLabel.setHorizontalAlignment(SwingConstants.RIGHT); + } + return statusLabel; + } + + private void ajustWidth() { for (int i = 0; i < pColumwidth.length; i++) { jTableInventory.getColumnModel().getColumn(i).setMinWidth(pColumwidth[i]); } - } + } - public void initialiseCombo(int total_rows) { + public void initialiseCombo(int total_rows) { int j = 0; pagesCombo.removeAllItems(); @@ -596,20 +500,117 @@ public void initialiseCombo(int total_rows) { } else { under.setText("/" + total_rows / PAGE_SIZE + " " + MessageBundle.getMessage("angal.inventory.pages.text")); } - } - - @Override - public void InventoryInserted(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - @Override - public void InventoryUpdated(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } - - @Override - public void InventoryCancelled(AWTEvent e) { - jTableInventory.setModel(new InventoryBrowsingModel()); - } + } + + @Override + public void InventoryInserted(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryUpdated(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + @Override + public void InventoryCancelled(AWTEvent e) { + jTableInventory.setModel(new InventoryBrowsingModel()); + } + + class InventoryBrowsingModel extends DefaultTableModel { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public InventoryBrowsingModel() { + inventoryList = new ArrayList<>(); + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + inventoryList = medicalInventoryManager.getMedicalInventoryByParams(dateFrom, dateTo, status, type); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + + public InventoryBrowsingModel(int startIndex, int pageSize) { + inventoryList = new ArrayList<>(); + String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null; + String type = InventoryType.ward.toString(); + try { + Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, + startIndex, + pageSize); + inventoryList = medInventorypage.getContent(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + + @Override + public Class getColumnClass(int c) { + if (c == 0) { + return String.class; + } else if (c == 1) { + return String.class; + } else if (c == 2) { + return String.class; + } else if (c == 3) { + return String.class; + } else if (c == 4) { + return String.class; + } + return null; + } + + @Override + public int getRowCount() { + if (inventoryList == null) { + return 0; + } + return inventoryList.size(); + } + + public String getColumnName(int c) { + return pColums[c]; + } + + public int getColumnCount() { + return pColums.length; + } + + @Override + public Object getValueAt(int r, int c) { + MedicalInventory medInvt = inventoryList.get(r); + + if (c == -1) { + return medInvt; + } else if (c == 0) { + return medInvt.getInventoryReference(); + } else if (c == 1) { + Ward ward = new Ward(); + try { + ward = wardBrowserManager.findWard(medInvt.getWard()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + return ward == null ? "" : ward.getDescription(); + } else if (c == 2) { + return medInvt.getInventoryDate().format(DATE_TIME_FORMATTER); + } else if (c == 3) { + return medInvt.getStatus(); + } else if (c == 4) { + return medInvt.getUser(); + } + return null; + } + + @Override + public boolean isCellEditable(int arg0, int arg1) { + return false; + } + + } } From 2febb597b24125554090418dd8b80f26c53f3216 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 12:10:55 +0100 Subject: [PATCH 36/83] Applying suggestion to change --- .../isf/medicalinventory/gui/InventoryWardEdit.java | 10 +++++----- .../org/isf/medicalinventory/gui/StockMedModel.java | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java index e84b1be6a4..0f785824ec 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -1041,7 +1041,7 @@ private boolean existInInventorySearchList(MedicalInventoryRow inventoryRow) { private JRadioButton getSpecificRadio() { if (specificRadio == null) { - specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.radio")); + specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.btn")); specificRadio.addActionListener(actionEvent -> { if (specificRadio.isSelected()) { codeTextField.setEnabled(true); @@ -1055,7 +1055,7 @@ private JRadioButton getSpecificRadio() { private JRadioButton getAllRadio() { if (allRadio == null) { - allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.radio")); + allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.btn")); allRadio.setSelected(inventory != null); specificRadio.setSelected(inventory == null); allRadio.addActionListener(actionEvent -> { @@ -1198,7 +1198,7 @@ private Medical chooseMedical(String text) throws OHServiceException { key = med.getCode().toString().toLowerCase(); medicalMap.put(key, med); } - ArrayList medList = new ArrayList<>(); + List medList = new ArrayList<>(); for (Medical aMed : medicalMap.values()) { if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { medList.add(aMed); @@ -1341,7 +1341,7 @@ private JComboBox getWardComboBox() { } if (medicalWardInventoryDraft.isEmpty() && medicalWardInventoryValidated.isEmpty()) { - activedSomeComponents(); + activateSomeComponents(); } else { MessageDialog.error(this, "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); @@ -1402,7 +1402,7 @@ private void disabledSomeComponents() { deleteButton.setEnabled(false); } - private void activedSomeComponents() { + private void activateSomeComponents() { jCalendarInventory.setEnabled(true); specificRadio.setEnabled(true); codeTextField.setEnabled(true); diff --git a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java index 51a474564c..7db2656d1d 100644 --- a/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java +++ b/src/main/java/org/isf/medicalinventory/gui/StockMedModel.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import javax.swing.table.DefaultTableModel; @@ -33,10 +34,10 @@ public class StockMedModel extends DefaultTableModel { private static final long serialVersionUID = 1L; - private ArrayList medList; - private ArrayList initList = new ArrayList(); + private List medList; + private List initList = new ArrayList(); - public StockMedModel(ArrayList meds) { + public StockMedModel(List meds) { medList = meds; initList.addAll(medList); } From 959de16f30013525f0fb1812dcc242817d3d4dac Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 14:10:27 +0100 Subject: [PATCH 37/83] formating --- .../gui/InventoryWardBrowser.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index 00f2abfceb..75026b5e99 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java @@ -70,7 +70,7 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListener { private static final long serialVersionUID = 1L; - private static int PAGE_SIZE = 50; + private static final int PAGE_SIZE = 50; JButton next; JButton previous; JComboBox pagesCombo = new JComboBox<>(); @@ -91,20 +91,20 @@ public class InventoryWardBrowser extends ModalJFrame implements InventoryListen private JButton viewButton; private JScrollPane scrollPaneInventory; private JTable jTableInventory; - private String[] pColums = { - MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), - MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), - MessageBundle.getMessage("angal.common.date.col").toUpperCase(), - MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), - MessageBundle.getMessage("angal.common.user.col").toUpperCase() + private final String[] pColums = { + MessageBundle.getMessage("angal.inventory.referenceshow.col").toUpperCase(), + MessageBundle.getMessage("angal.common.ward.col").toUpperCase(), + MessageBundle.getMessage("angal.common.date.col").toUpperCase(), + MessageBundle.getMessage("angal.inventory.status.col").toUpperCase(), + MessageBundle.getMessage("angal.common.user.col").toUpperCase() }; - private int[] pColumwidth = { 150, 150, 100, 100, 150 }; + private final int[] pColumwidth = { 150, 150, 100, 100, 150 }; private JComboBox statusComboBox; private JLabel statusLabel; private int startIndex; private int totalRows; - private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); - private WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); + private final MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); + private final WardBrowserManager wardBrowserManager = Context.getApplicationContext().getBean(WardBrowserManager.class); private List inventoryList; public InventoryWardBrowser() { @@ -541,8 +541,8 @@ public InventoryBrowsingModel(int startIndex, int pageSize) { String type = InventoryType.ward.toString(); try { Page medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, - startIndex, - pageSize); + startIndex, + pageSize); inventoryList = medInventorypage.getContent(); } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); From 4f431822d438a7037c7059cf9cda11c69c471dcc Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 14:18:09 +0100 Subject: [PATCH 38/83] formating --- .../OpenHospital-code-style-configuration.xml | 2 +- .../gui/InventoryWardBrowser.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.ide-settings/idea/OpenHospital-code-style-configuration.xml b/.ide-settings/idea/OpenHospital-code-style-configuration.xml index 87a358cd6c..ba814defd5 100644 --- a/.ide-settings/idea/OpenHospital-code-style-configuration.xml +++ b/.ide-settings/idea/OpenHospital-code-style-configuration.xml @@ -73,7 +73,7 @@