Skip to content

Commit

Permalink
Merge pull request #2109 from ArnaudFofou/OP-1304
Browse files Browse the repository at this point in the history
OP-1304 | Enhance the Code with also to enhance Product Selection
  • Loading branch information
mwithi authored Dec 28, 2024
2 parents 53dac51 + f0fc4aa commit 5843761
Showing 1 changed file with 89 additions and 182 deletions.
271 changes: 89 additions & 182 deletions src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,12 @@ private JButton getCleanTableButton() {
if (inventory != null) {
List<MedicalInventoryRow> invRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId());
medicalInventoryRowManager.deleteMedicalInventoryRows(invRows);
inventoryRowSearchList.clear();
} else {
inventoryRowSearchList.clear();
}

} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
inventoryRowSearchList = new ArrayList<>();
inventoryRowSearchList.clear();
DefaultTableModel model = (DefaultTableModel) jTableInventoryRow.getModel();
model.setRowCount(0);
model.setColumnCount(0);
Expand Down Expand Up @@ -1190,61 +1187,61 @@ class InventoryRowModel extends DefaultTableModel {

private static final long serialVersionUID = 1L;

public InventoryRowModel(boolean add) throws OHServiceException {
inventoryRowList = loadNewInventoryTable(null, inventory, add);
if (!inventoryRowList.isEmpty()) {
for (MedicalInventoryRow invRow : inventoryRowList) {
addMedInRowInInventorySearchList(invRow);
}
}
}

public InventoryRowModel() throws OHServiceException {
inventoryRowList.clear();
inventoryRowSearchList.clear();
if (inventory != null) {
inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId());
}
if (!inventoryRowList.isEmpty()) {
for (MedicalInventoryRow invRow : inventoryRowList) {
addMedInRowInInventorySearchList(invRow);
if (invRow.getId() == 0) {
inventoryRowListAdded.add(invRow);
}
}
}
}

public InventoryRowModel(MedicalType medType) throws OHServiceException {
inventoryRowList = loadNewInventoryTableByMedicalType(medType);
if (!inventoryRowList.isEmpty()) {
for (MedicalInventoryRow invRow : inventoryRowList) {
addMedInRowInInventorySearchList(invRow);
}
}
}

public InventoryRowModel(boolean withNoZeroQty, MedicalType medType) throws OHServiceException {
inventoryRowList = loadNewInventoryTable(withNoZeroQty, medType);
if (!inventoryRowList.isEmpty()) {
for (MedicalInventoryRow invRow : inventoryRowList) {
addMedInRowInInventorySearchList(invRow);
}
} else {
MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg");
}
}

public InventoryRowModel(MedicalType medType, boolean withMovement) throws OHServiceException {
inventoryRowList = loadNewInventoryTable(medType);
if (!inventoryRowList.isEmpty()) {
for (MedicalInventoryRow invRow : inventoryRowList) {
addMedInRowInInventorySearchList(invRow);
}
} else {
MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg");
}
}
this(null, false, false, false);
}

public InventoryRowModel(boolean add) throws OHServiceException {
this(null, false, add, false);
}

public InventoryRowModel(MedicalType medType) throws OHServiceException {
this(medType, false, false, false);
}

public InventoryRowModel(boolean withNoZeroQty, MedicalType medType) throws OHServiceException {
this(medType, withNoZeroQty, false, false);
}

public InventoryRowModel(MedicalType medType, boolean withMovement) throws OHServiceException {
this(medType, false, false, withMovement);
}

public InventoryRowModel(MedicalType medType, boolean withNoZeroQty, boolean includeAll, boolean withMovement) throws OHServiceException {
if (includeAll) {
if (medType == null) {
inventoryRowList = loadNewInventoryTable(null, inventory, true);
} else {
inventoryRowList = loadNewInventoryTableByMedicalType(medType);
}
} else if (withMovement) {
inventoryRowList = loadNewInventoryTable(medType);
} else if (withNoZeroQty) {
if (medType == null) {
inventoryRowList = loadNewInventoryTable(true, null);
} else {
inventoryRowList = loadNewInventoryTable(true, medType);
}
} else {
inventoryRowSearchList.clear();
if (inventory != null) {
inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId());
}
}

if (!inventoryRowList.isEmpty()) {
for (MedicalInventoryRow invRow : inventoryRowList) {
addMedInRowInInventorySearchList(invRow);
if (!includeAll && invRow.getId() == 0) {
inventoryRowListAdded.add(invRow);
}
}
} else {
if (!mode.equals("new")) {
MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg");
}
}
}

public Class< ? > getColumnClass(int c) {
if (c == 0) {
Expand Down Expand Up @@ -2179,129 +2176,39 @@ private boolean areAllMedicalsInInventory() throws OHServiceException {
}

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;
if (info == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(true));
}
fireInventoryUpdated();
MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg");
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
} else {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
MedicalType medType = (MedicalType) medicalTypeComboBox.getSelectedItem();
jTableInventoryRow.setModel(new InventoryRowModel(medType));
}
fireInventoryUpdated();
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
}
});

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;
if (info == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(true, null));
}
fireInventoryUpdated();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
} else {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
MedicalType medType = (MedicalType) medicalTypeComboBox.getSelectedItem();
jTableInventoryRow.setModel(new InventoryRowModel(true, medType));
fireInventoryUpdated();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
}
});

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;
if (info == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(null, true));
fireInventoryUpdated();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
} else {
try {
if (!areAllMedicalsInInventory()) {
int info = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;
if (info == JOptionPane.YES_OPTION) {
MedicalType medType = (MedicalType) medicalTypeComboBox.getSelectedItem();
jTableInventoryRow.setModel(new InventoryRowModel(medType, true));
fireInventoryUpdated();
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
}
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
}
});
actions.put(radioButtonAll, () -> handleInventoryUpdate(true, false, false));
actions.put(radioOnlyNonZero, () -> handleInventoryUpdate(false, false, true));
actions.put(radioWithMovement, () -> handleInventoryUpdate(false, true, false));
}

private void handleInventoryUpdate(boolean includeAll, boolean withMovement, boolean nonZero) {
boolean isAllSelected = medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"));
MedicalType medType = isAllSelected ? null : (MedicalType) medicalTypeComboBox.getSelectedItem();

try {
if (!areAllMedicalsInInventory()) {
int userChoice = (!inventoryRowSearchList.isEmpty())
? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg")
: JOptionPane.YES_OPTION;

if (userChoice == JOptionPane.YES_OPTION) {
jTableInventoryRow.setModel(new InventoryRowModel(medType, nonZero, includeAll, withMovement));
fireInventoryUpdated();
showUpdateSuccessMessage();
}
} else {
MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg");
}
} catch (OHServiceException e) {
OHServiceExceptionUtil.showMessages(e);
}
}

private void showUpdateSuccessMessage() {
if (!inventoryRowList.isEmpty()) {
MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg");
} else {
MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg");
}
}
}

0 comments on commit 5843761

Please sign in to comment.