Skip to content

Commit

Permalink
Merge pull request #2106 from mwithi/OP-1304
Browse files Browse the repository at this point in the history
OP-1304 Small changes
  • Loading branch information
mwithi authored Dec 19, 2024
2 parents 6dcec23 + efbad2b commit 53dac51
Showing 1 changed file with 68 additions and 75 deletions.
143 changes: 68 additions & 75 deletions src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,18 @@ private JButton getSelectedButton() {
radioGroup.add(getAllRadioButton());
radioGroup.add(getMedicalWithNonZeroQuantityRadioButton());
radioGroup.add(getMedicalWithMovementRadioButton());

// Map actions to buttons
initializeActions();
// Convertir la HashMap en TreeMap pour trier les clés

// Convert HashMap to TreeMap to sort keys
Map<AbstractButton, Runnable> sortedActionMap = new TreeMap<>(Comparator.comparing(AbstractButton::getText));
sortedActionMap.putAll(actions);

// Add ActionListener to each button
sortedActionMap.forEach((key, value) -> {
rightPanel.add(key);
});
sortedActionMap.forEach((key, value) -> {
rightPanel.add(key);
});

JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
Expand Down Expand Up @@ -798,7 +800,6 @@ private JButton getDeleteButton() {
}
}
jTableInventoryRow.clearSelection();
adjustWidth();
} else {
return;
}
Expand Down Expand Up @@ -848,7 +849,7 @@ private JButton getLotButton() {
code = lot.getCode();
if (selectedInventoryRow.getLot() == null) {
List<MedicalInventoryRow> invRows = inventoryRowSearchList.stream()
.filter(inv -> inv.getLot() != null && inv.getLot().getCode().equals(code)).collect(Collectors.toList());
.filter(inv -> inv.getLot() != null && inv.getLot().getCode().equals(code)).collect(Collectors.toList());
if (invRows.isEmpty() || code.equals("")) {
selectedInventoryRow.setNewLot(true);
selectedInventoryRow.setLot(lot);
Expand All @@ -864,7 +865,7 @@ private JButton getLotButton() {
}
} else {
List<MedicalInventoryRow> invRows = inventoryRowSearchList.stream()
.filter(inv -> inv.getMedical().getCode().equals(selectedInventoryRow.getMedical().getCode())).collect(Collectors.toList());
.filter(inv -> inv.getMedical().getCode().equals(selectedInventoryRow.getMedical().getCode())).collect(Collectors.toList());
invRows = invRows.stream().filter(inv -> inv.getLot() != null && inv.getLot().getCode().equals(code)).collect(Collectors.toList());
if (invRows.isEmpty() || code.equals("")) {
selectedInventoryRow.setNewLot(true);
Expand Down Expand Up @@ -963,7 +964,6 @@ private JButton getCleanTableButton() {
model.setRowCount(0);
model.setColumnCount(0);
jTableInventoryRow.updateUI();
adjustWidth();
}
});
return resetButton;
Expand Down Expand Up @@ -994,7 +994,7 @@ private JButton getValidateButton() {
String lastReference = inventory.getInventoryReference();
LocalDateTime lastDate = inventory.getInventoryDate();
if (checkParameters(wardCode, chargeCode, dischargeCode, supplierId, lastReference, lastDate) || !lotsSaved.isEmpty()
|| !inventoryRowListAdded.isEmpty() || !inventoryRowsToDelete.isEmpty()) {
|| !inventoryRowListAdded.isEmpty() || !inventoryRowsToDelete.isEmpty()) {
saveButton.doClick();
chargeCode = inventory.getChargeType();
dischargeCode = inventory.getDischargeType();
Expand Down Expand Up @@ -1032,7 +1032,6 @@ private JButton getValidateButton() {
confirmButton.setEnabled(true);
jTableInventoryRow.setModel(new InventoryRowModel());
fireInventoryUpdated();
adjustWidth();
} catch (OHServiceException e1) {
OHServiceExceptionUtil.showMessages(e1);
}
Expand Down Expand Up @@ -1122,6 +1121,7 @@ private JTable getJTableInventoryRow() throws OHServiceException {
jTableInventoryRow.setFillsViewportHeight(true);
model = new InventoryRowModel();
jTableInventoryRow.setModel(model);
jTableInventoryRow.setAutoCreateColumnsFromModel(false);
for (int i = 0; i < pColumnVisible.length; i++) {
jTableInventoryRow.getColumnModel().getColumn(i).setCellRenderer(new EnabledTableCellRenderer());
jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(pColumwidth[i]);
Expand Down Expand Up @@ -1200,6 +1200,7 @@ public InventoryRowModel(boolean add) throws OHServiceException {
}

public InventoryRowModel() throws OHServiceException {
inventoryRowList.clear();
inventoryRowSearchList.clear();
if (inventory != null) {
inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId());
Expand Down Expand Up @@ -1378,20 +1379,6 @@ public boolean isCellEditable(int rowIndex, int columnIndex) {
}
}

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 Lot getLot(Lot lotToUpdate) throws OHServiceException {
Lot lot = null;
if (isAutomaticLotIn()) {
Expand Down Expand Up @@ -1443,10 +1430,10 @@ private Lot askLot(Lot lotToUpdate) {
panel.add(expireDateChooser);
do {
int ok = JOptionPane.showConfirmDialog(
this,
panel,
MessageBundle.getMessage("angal.medicalstock.multiplecharging.lotinformations"),
JOptionPane.OK_CANCEL_OPTION);
this,
panel,
MessageBundle.getMessage("angal.medicalstock.multiplecharging.lotinformations"),
JOptionPane.OK_CANCEL_OPTION);

if (ok == JOptionPane.OK_OPTION) {
String lotName = lotNameTextField.getText();
Expand Down Expand Up @@ -1481,8 +1468,8 @@ private BigDecimal askCost(int qty, BigDecimal lastCost) {
double cost = 0.;
do {
String input = JOptionPane.showInputDialog(this,
MessageBundle.getMessage("angal.medicalstock.multiplecharging.unitcost"),
lastCost);
MessageBundle.getMessage("angal.medicalstock.multiplecharging.unitcost"),
lastCost);
if (input != null) {
try {
cost = Double.parseDouble(input);
Expand Down Expand Up @@ -1510,8 +1497,8 @@ protected LocalDateTime askExpiringDate() {
panel.add(expireDateChooser);

int ok = JOptionPane.showConfirmDialog(this, panel,
MessageBundle.getMessage("angal.medicalstock.multiplecharging.expiringdate"),
JOptionPane.OK_CANCEL_OPTION);
MessageBundle.getMessage("angal.medicalstock.multiplecharging.expiringdate"),
JOptionPane.OK_CANCEL_OPTION);

if (ok == JOptionPane.OK_OPTION) {
date = expireDateChooser.getLocalDateTime();
Expand All @@ -1521,8 +1508,8 @@ protected LocalDateTime askExpiringDate() {

protected double askTotalCost() {
String input = JOptionPane.showInputDialog(this,
MessageBundle.getMessage("angal.medicalstock.multiplecharging.totalcost"),
0.);
MessageBundle.getMessage("angal.medicalstock.multiplecharging.totalcost"),
0.);
double total = 0.;
if (input != null) {
try {
Expand Down Expand Up @@ -2035,7 +2022,7 @@ private int getPosition(MedicalInventoryRow inventoryRow) {
private boolean existInInventorySearchList(MedicalInventoryRow inventoryRow) {
boolean found = false;
List<MedicalInventoryRow> invRows = inventoryRowSearchList.stream()
.filter(inv -> inv.getMedical().getCode().equals(inventoryRow.getMedical().getCode())).collect(Collectors.toList());
.filter(inv -> inv.getMedical().getCode().equals(inventoryRow.getMedical().getCode())).collect(Collectors.toList());
if (!invRows.isEmpty()) {
for (MedicalInventoryRow invR : invRows) {
if (inventoryRow.getLot() != null && invR.getLot() != null) {
Expand All @@ -2054,7 +2041,7 @@ private boolean existInInventorySearchList(MedicalInventoryRow inventoryRow) {

return found;
}

private void addMedInRowInInventorySearchList(MedicalInventoryRow inventoryRow) {
int position = getPosition(inventoryRow);
if (position == -1) {
Expand All @@ -2067,7 +2054,7 @@ private void addMedInRowInInventorySearchList(MedicalInventoryRow inventoryRow)
inventoryRowListAdded.add(inventoryRow);
}
}

private void resetVariable() {
inventoryRowsToDelete.clear();
lotsDeleted.clear();
Expand All @@ -2077,13 +2064,13 @@ private void resetVariable() {

private boolean checkParameters(String wardCode, String chargeCode, String dischargeCode, Integer suplierId, String reference, LocalDateTime date) {
if (!lotsSaved.isEmpty() || !inventoryRowListAdded.isEmpty() || !lotsDeleted.isEmpty() || !inventoryRowsToDelete.isEmpty()
|| (destination != null && !destination.getCode().equals(wardCode))
|| (chargeType != null && !chargeType.getCode().equals(chargeCode))
|| (dischargeType != null && !dischargeType.getCode().equals(dischargeCode))
|| (supplier != null && supplier.getSupId() != suplierId) || (destination == null && wardCode != null)
|| (chargeType == null && chargeCode != null) || (dischargeType == null && dischargeCode != null)
|| (supplier == null && suplierId != null) || (reference != null && !reference.equals(newReference))
|| !date.toLocalDate().equals(dateInventory.toLocalDate())) {
|| (destination != null && !destination.getCode().equals(wardCode))
|| (chargeType != null && !chargeType.getCode().equals(chargeCode))
|| (dischargeType != null && !dischargeType.getCode().equals(dischargeCode))
|| (supplier != null && supplier.getSupId() != suplierId) || (destination == null && wardCode != null)
|| (chargeType == null && chargeCode != null) || (dischargeType == null && dischargeCode != null)
|| (supplier == null && suplierId != null) || (reference != null && !reference.equals(newReference))
|| !date.toLocalDate().equals(dateInventory.toLocalDate())) {
return true;
}
return false;
Expand Down Expand Up @@ -2140,16 +2127,16 @@ private JButton getCancelButton() {
jButtonCancel.addActionListener(actionEvent -> frame.dispose());
return jButtonCancel;
}

private List<MedicalInventoryRow> loadNewInventoryTable(boolean withNonZeroQty, MedicalType medicalTypeSelected) throws OHServiceException {
List<MedicalInventoryRow> inventoryRowsList = getMedicalInventoryRows(null);
if (withNonZeroQty) {
inventoryRowsList = inventoryRowsList.stream().filter(inv -> inv.getTheoreticQty() > 0).collect(Collectors.toList());
}
if (medicalTypeSelected != null) {
inventoryRowsList = inventoryRowsList.stream()
.filter(inv -> inv.getMedical().getType().getDescription().equals(medicalTypeSelected.getDescription()))
.collect(Collectors.toList());
.filter(inv -> inv.getMedical().getType().getDescription().equals(medicalTypeSelected.getDescription()))
.collect(Collectors.toList());
}
return inventoryRowsList;
}
Expand All @@ -2158,8 +2145,8 @@ private List<MedicalInventoryRow> loadNewInventoryTable(MedicalType medicalTypeS
List<MedicalInventoryRow> inventoryRowsList = getMedicalInventoryRowsWithMovement();
if (medicalTypeSelected != null) {
inventoryRowsList = inventoryRowsList.stream()
.filter(inv -> inv.getMedical().getType().getDescription().equals(medicalTypeSelected.getDescription()))
.collect(Collectors.toList());
.filter(inv -> inv.getMedical().getType().getDescription().equals(medicalTypeSelected.getDescription()))
.collect(Collectors.toList());
}
return inventoryRowsList;
}
Expand All @@ -2170,16 +2157,16 @@ private JButton getOkButton() {
jButtonOk.setMnemonic(MessageBundle.getMnemonic("angal.common.ok.btn.key"));
jButtonOk.addActionListener(actionEvent -> {
actions.forEach((key, value) -> {
if (key.isSelected()) {
actions.get(key).run();
}
});
if (key.isSelected()) {
actions.get(key).run();
}
});
jButtonCancel.doClick();
});
}
return jButtonOk;
}

private boolean areAllMedicalsInInventory() throws OHServiceException {
Set<Medical> inventorySet = new HashSet<>();
for (MedicalInventoryRow row : inventoryRowSearchList) {
Expand All @@ -2190,18 +2177,19 @@ private boolean areAllMedicalsInInventory() throws OHServiceException {
}
return false;
}

private void initializeActions() {
actions.put(radioButtonAll, () -> {
if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION;
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(true));
}
fireInventoryUpdated();
adjustWidth();
MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg");
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
Expand All @@ -2212,13 +2200,14 @@ private void initializeActions() {
} else {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION;
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem();
MedicalType medType = (MedicalType) medicalTypeComboBox.getSelectedItem();
jTableInventoryRow.setModel(new InventoryRowModel(medType));
}
fireInventoryUpdated();
adjustWidth();
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
Expand All @@ -2228,17 +2217,18 @@ private void initializeActions() {
}
}
});

actions.put(radioOnlyNonZero, () -> {
if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION;
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(true, null));
}
fireInventoryUpdated();
adjustWidth();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
Expand All @@ -2251,16 +2241,17 @@ private void initializeActions() {
} else {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION;
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem();
MedicalType medType = (MedicalType) medicalTypeComboBox.getSelectedItem();
jTableInventoryRow.setModel(new InventoryRowModel(true, medType));
fireInventoryUpdated();
adjustWidth();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
}
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
Expand All @@ -2269,16 +2260,17 @@ private void initializeActions() {
}
}
});

actions.put(radioWithMovement, () -> {
if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION;
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(null, true));
fireInventoryUpdated();
adjustWidth();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
Expand All @@ -2292,16 +2284,17 @@ private void initializeActions() {
} else {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION;
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem();
MedicalType medType = (MedicalType) medicalTypeComboBox.getSelectedItem();
jTableInventoryRow.setModel(new InventoryRowModel(medType, true));
fireInventoryUpdated();
adjustWidth();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
}
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
Expand Down

0 comments on commit 53dac51

Please sign in to comment.