Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-1304 | Enhance the Code with also to enhance Product Selection #2109

Merged
merged 6 commits into from
Dec 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -243,6 +243,7 @@ private void fireInventoryUpdated() {
private JComboBox<MedicalType> medicalTypeComboBox;
private List<Medical> medicals = new ArrayList<>();
private Map<AbstractButton, Runnable> actions = new HashMap<>();
private boolean noData = false;
private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class);
private MedicalInventoryRowManager medicalInventoryRowManager = Context.getApplicationContext().getBean(MedicalInventoryRowManager.class);
private MedicalBrowsingManager medicalBrowsingManager = Context.getApplicationContext().getBean(MedicalBrowsingManager.class);
Expand Down Expand Up @@ -951,15 +952,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 +1188,56 @@ 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 add, boolean withMovement) throws OHServiceException {
if (add) {
inventoryRowList = loadNewInventoryTable(null, inventory, true);
} else if (withMovement) {
inventoryRowList = loadNewInventoryTable(medType);
} else if (withNoZeroQty) {
inventoryRowList = loadNewInventoryTable(withNoZeroQty, medType);
} else if (medType != null) {
inventoryRowList = loadNewInventoryTableByMedicalType(medType);
} else {
inventoryRowSearchList.clear();
if (inventory != null) {
inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId());
}
}

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

public Class< ? > getColumnClass(int c) {
if (c == 0) {
Expand Down Expand Up @@ -2179,129 +2172,43 @@ 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));
noData = 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();
adjustWidth();
mwithi marked this conversation as resolved.
Show resolved Hide resolved
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 {
if (!noData) {
MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg");
}
}
}
}
Loading