From 5e759bd6d423ca333d5e14b91dad19df885003af Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud <101590821+ArnaudFonzam@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:18:56 +0100 Subject: [PATCH] OP-1188 | Delete Inventory (#2048) * add logic to delete inventory * add import * extract inventory.getStatus() * set status on UpperCamel case when create new Inventory * Update src/main/java/org/isf/medicalinventory/gui/InventoryBrowser.java * add missiong bundle --------- Co-authored-by: ArnaudFonzam Co-authored-by: Alessandro Domanico --- bundle/language_en.properties | 5 +++ .../gui/InventoryBrowser.java | 33 ++++++++++++++++++- .../medicalinventory/gui/InventoryEdit.java | 5 +-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 139bb87133..32e9ffcbc0 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -673,6 +673,11 @@ angal.inventory.cancelednoteditable.msg angal.inventory.chargetype.label = Charge Type angal.inventory.clean.btn = Clean Table angal.inventory.clean.btn.key = T +angal.inventory.deletion.confirm.msg = Do you really want to delete this inventory? +angal.inventory.deletion.confirm.title = Confirm Deletion +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.notfound.msg = Inventory not found. angal.inventory.destination.label = Destination angal.inventory.dischargetype.label = Discharge Type angal.inventory.draft = Draft diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryBrowser.java index 5be50a1aad..874f155127 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryBrowser.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryBrowser.java @@ -45,6 +45,7 @@ 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; @@ -412,14 +413,44 @@ private JButton getPrintButton() { jButtonPrint.setEnabled(false); return jButtonPrint; } - + private JButton getDeleteButton() { jButtonDelete = new JButton(MessageBundle.getMessage("angal.common.delete.btn")); jButtonDelete.setMnemonic(MessageBundle.getMnemonic("angal.common.delete.btn.key")); jButtonDelete.setEnabled(false); + + jButtonDelete.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 jButtonDelete; } + + private JButton getCloseButton() { jButtonClose = new JButton(MessageBundle.getMessage("angal.common.close.btn")); jButtonClose.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key")); diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java index 11f8e7d090..19dd1411f7 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java @@ -1589,7 +1589,8 @@ private JLabel getReferenceLabel() { private JLabel getStatusLabel() { if (statusLabel == null) { if (inventory == null) { - statusLabel = new JLabel(InventoryStatus.draft.toString()); + String currentStatus = InventoryStatus.draft.toString().toUpperCase(); + statusLabel = new JLabel(currentStatus); statusLabel.setForeground(Color.GRAY); } else { String currentStatus = inventory.getStatus().toUpperCase(); @@ -1815,4 +1816,4 @@ private void resetVariable() { inventoryRowListAdded.clear(); lotsSaved.clear(); } -} +} \ No newline at end of file