diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1c510b6f32..a403a87f70 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,20 +29,27 @@ jobs: run: | # Set default FORK_REPO and BRANCH_NAME values. BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF##*/}}" - FORK_REPO="${GITHUB_HEAD_REPOSITORY:-${GITHUB_ACTOR}/openhospital-core}" - CHECK_BRANCH_URL="https://github.com/${GITHUB_ACTOR}/openhospital-core/tree/$BRANCH_NAME" - echo "Checking branch existence with: curl -s -o /dev/null -w \"%{http_code}\" $CHECK_BRANCH_URL" - # Determine FORK_REPO with fallback logic - if [[ -n "${GITHUB_HEAD_REPOSITORY}" ]]; then - echo "Using ${GITHUB_HEAD_REPOSITORY}." - FORK_REPO=${GITHUB_HEAD_REPOSITORY} - elif curl -s -o /dev/null -w "%{http_code}" $CHECK_BRANCH_URL | grep -q "200"; then - echo "Using ${GITHUB_ACTOR}/openhospital-core" - FORK_REPO=${GITHUB_ACTOR}/openhospital-core - else - echo "Using informatici/openhospital-core." + if [[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REPOSITORY" == "informatici/openhospital-gui" ]]; then + # For pushes to the main repository, default to the main core repo FORK_REPO="informatici/openhospital-core" + else + # For pull requests or other pushes, use the contributor fork if applicable + if [[ -n "$GITHUB_HEAD_REPOSITORY" ]]; then + FORK_REPO="$GITHUB_HEAD_REPOSITORY" + else + # Check if the actor's repo exists with the branch + FORK_REPO="${GITHUB_ACTOR}/openhospital-core" + CHECK_BRANCH_URL="https://github.com/$FORK_REPO/tree/$BRANCH_NAME" + echo "Checking branch existence with: curl -s -o /dev/null -w \"%{http_code}\" $CHECK_BRANCH_URL" + + if curl -s -o /dev/null -w "%{http_code}" "$CHECK_BRANCH_URL" | grep -q "200"; then + echo "Branch $BRANCH_NAME exists in $FORK_REPO." + else + # Fallback to the main repository if the branch doesn’t exist in the fork + FORK_REPO="informatici/openhospital-core" + fi + fi fi # Export FORK_REPO and BRANCH_NAME to GITHUB_ENV for the next step diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 077e044496..2eb2c974ec 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -670,43 +670,94 @@ 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.invetory.allmedicaladdedsuccessfully.msg = All medicals are added successfully. +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. +angal.inventory.cannotsaveinventorywithoutproducts.msg = Cannot save inventory without products. +angal.inventory.chargetype.label = Charge Type: +angal.inventory.choosedestinationbeforevalidation.msg = Please choose the destination 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.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.doyouwanttoactualizetheinventory.msg = Do you want to actualize this inventory? +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.doyouwanttoupdatethisinventory.msg = Do you want to update this inventory? +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 +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 continuing. +angal.inventory.inventorymustsavebeforevalidation.msg = Inventory must be saved before validation. +angal.inventory.lot.btn = Lot +angal.inventory.lot.btn.key = L 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.new.title = New inventory +angal.inventory.newlot.col = New lot +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. +angal.inventory.page.text = Page +angal.inventory.pages.text = Pages +angal.inventory.pleasesaveinventorybeforevalidateit.msg = Please save the inventory before validating it. +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.productalreadyexist.msg = {0} already exist in the list. do you still like to add it? 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 -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.specificproduct.btn = Specific product +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} +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. +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.view.btn = View inventory +angal.inventory.validate.success.msg = The inventory has been successfully validated. +angal.inventory.validated = Validated +angal.inventory.view.btn = View 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.view.title = View Inventory +angal.inventory.youcannotvalidatethisinventory.msg = You cannot validate the inventory with a medicine without a lot. +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 @@ -1849,6 +1900,7 @@ angal.ward.newward.title angal.ward.nurses.col = Nurses angal.ward.nursesedit = Number of nurses * angal.ward.opd.txt = OPD +angal.ward.opdwardmusthaveopdservicechecked.msg = OPD ward must have OPD service checked. angal.ward.pleasecheckinadmissionpatients.msg = Please check in admission / patients. angal.ward.requiredfields = * Required fields angal.ward.theemailmustbevalid.msg = The email must be valid. diff --git a/src/main/java/org/isf/accounting/gui/PatientBillEdit.java b/src/main/java/org/isf/accounting/gui/PatientBillEdit.java index 4923780d49..23349004c3 100644 --- a/src/main/java/org/isf/accounting/gui/PatientBillEdit.java +++ b/src/main/java/org/isf/accounting/gui/PatientBillEdit.java @@ -845,11 +845,13 @@ private JButton getJButtonTrashPatient() { jButtonTrashPatient.setPreferredSize(new Dimension(25, 25)); jButtonTrashPatient.setIcon(new ImageIcon("rsc/icons/remove_patient_button.png")); jButtonTrashPatient.setToolTipText(MessageBundle.getMessage("angal.newbill.removethepatientassociatedwiththisbill.tooltip")); + if (thisBill.getBillPatient() == null) { + jButtonTrashPatient.setEnabled(false); + } jButtonTrashPatient.addActionListener(actionEvent -> { // BILL thisBill.setBillPatient(null); thisBill.setIsPatient(false); - thisBill.getBillPatient().setCode(0); thisBill.setPatName(""); //$NON-NLS-1$ thisBill.setAdmission(null); // INTERFACE @@ -895,6 +897,9 @@ private void setJButtonPickPatient() { jButtonPickPatient.setText(MessageBundle.getMessage("angal.newbill.changepatient.btn")); jButtonPickPatient.setMnemonic(MessageBundle.getMnemonic("angal.newbill.changepatient.btn.key")); jButtonPickPatient.setToolTipText(MessageBundle.getMessage("angal.newbill.changethepatientassociatedwiththisbill.tooltip")); + if (jButtonTrashPatient != null) { + jButtonTrashPatient.setEnabled(true); + } } } diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java b/src/main/java/org/isf/medicalinventory/gui/InventoryWardBrowser.java index ddb4ef65f5..54cb491ab7 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,24 +21,28 @@ */ 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.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; @@ -48,11 +52,20 @@ 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.InventoryState; +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 { @@ -69,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; @@ -78,12 +91,21 @@ 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 }; - 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 " + 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() { @@ -106,16 +128,54 @@ 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(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() { @@ -152,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(getStateLabel(), 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; @@ -188,9 +248,19 @@ 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()); + panelFooter.add(getEditButton()); panelFooter.add(getDeleteButton()); panelFooter.add(getCloseButton()); } @@ -198,40 +268,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 +314,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 +322,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 getEditButton() { + editButton = new JButton(MessageBundle.getMessage("angal.common.edit.btn")); + editButton.setMnemonic(MessageBundle.getMnemonic("angal.common.edit.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); + }); 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(actionEvent -> dispose()); return closeButton; } @@ -300,6 +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); + } + } + }); } return jTableInventory; } @@ -312,23 +460,52 @@ 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 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 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]; @@ -338,6 +515,32 @@ 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; @@ -345,46 +548,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.status.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 + " " + 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) { - 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 c56d40651e..31cbd93007 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryWardEdit.java @@ -26,27 +26,27 @@ 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; +import java.awt.GridLayout; 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.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.math.BigDecimal; -import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; 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,22 +63,22 @@ 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.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; +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; @@ -93,10 +93,10 @@ 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.GoodDateTimeSpinnerChooser; import org.isf.utils.jobjects.MessageDialog; import org.isf.utils.jobjects.ModalJFrame; +import org.isf.utils.jobjects.RequestFocusListener; import org.isf.utils.jobjects.TextPrompt; import org.isf.utils.jobjects.TextPrompt.Show; import org.isf.utils.time.TimeTools; @@ -105,1002 +105,1587 @@ 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; - } - - 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(); + 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 (EventListener listener : listeners) { + ((InventoryListener) listener).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; + private LocalDateTime dateInventory = TimeTools.getServerDateTime(); + private JPanel panelHeader; + private JPanel panelFooter; + private JPanel panelContent; + private JButton closeButton; + private JButton saveButton; + private JButton resetButton; + private JButton lotButton; + private JButton printButton; + private JButton validateButton; + private JButton deleteButton; + private JScrollPane scrollPaneInventory; + private JTable jTableInventoryRow; + + private List inventoryRowList = new ArrayList<>(); + private List inventoryRowSearchList = new ArrayList<>(); + private List inventoryRowsToDelete = new ArrayList<>(); + private List inventoryRowListAdded = new ArrayList<>(); + private List lotsSaved = new ArrayList<>(); + private HashMap lotsDeleted = new HashMap<>(); + 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.newlot.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 = { 50, 50, 200, 100, 100, 100, 100, 80, 80, 80 }; + private boolean[] columnEditable = { false, false, false, false, false, false, false, true, false, false }; + private boolean[] columnEditableView = { false, false, false, false, false, false, false, false, false, false }; + private boolean[] pColumnVisible = { false, true, true, true, !GeneralData.AUTOMATICLOT_IN, true, true, true, GeneralData.LOTWITHCOST, GeneralData.LOTWITHCOST }; + private MedicalInventory inventory = null; + private JRadioButton specificRadio; + private JRadioButton allRadio; + private JLabel dateInventoryLabel; + private JTextField codeTextField; + private String code = null; + private String mode; + private JLabel statusLabel; + private String wardId = ""; + private JLabel referenceLabel; + private JTextField referenceTextField; + private JTextField jTextFieldEditor; + private JLabel wardLabel; + private JComboBox wardComboBox; + private Ward wardSelected; + private JLabel loaderLabel; + private boolean selectAll; + private String newReference; + 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(); + disabledSomeComponents(); + } + + public InventoryWardEdit(MedicalInventory inventory, String modee) { + this.inventory = inventory; + wardId = this.inventory.getWard(); + mode = modee; + initComponents(); + } + + private void initComponents() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setMinimumSize(new DimensionUIResource(950, 580)); + setLocationRelativeTo(null); // center + 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); + + panelContent = getPanelContent(); + getContentPane().add(panelContent, BorderLayout.CENTER); + + 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); + wardComboBox.setEnabled(false); + validateButton.setVisible(false); + printButton.setVisible(true); + lotButton.setVisible(false); + } 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); + wardComboBox.setEnabled(true); + validateButton.setVisible(true); + printButton.setVisible(false); + lotButton.setVisible(true); + } + } + + 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[] { 159, 191, 192, 218, 218, 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; + 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.anchor = GridBagConstraints.EAST; + 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_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_specificRadio = new GridBagConstraints(); + gbc_specificRadio.anchor = GridBagConstraints.EAST; + gbc_specificRadio.insets = new Insets(0, 0, 0, 5); + gbc_specificRadio.gridx = 0; + 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 = 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 = 4; + panelHeader.add(getAllRadio(), gbc_allRadio); + 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(getLotButton()); + panelFooter.add(getDeleteButton()); + panelFooter.add(getValidateButton()); + panelFooter.add(getCleanTableButton()); + panelFooter.add(getPrintButton()); + panelFooter.add(getCloseButton()); + } + return panelFooter; + } + + private GoodDateChooser getJCalendarFrom() { + if (jCalendarInventory == null) { + + jCalendarInventory = new GoodDateChooser(LocalDate.now(), false, false); + if (inventory != null) { + jCalendarInventory.setDate(inventory.getInventoryDate().toLocalDate()); + dateInventory = inventory.getInventoryDate(); + } + jCalendarInventory.addDateChangeListener(event -> dateInventory = jCalendarInventory.getDate().atStartOfDay()); + } + return jCalendarInventory; + } + + private JButton getSaveButton() { + 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 user = UserBrowsingManager.getCurrentUser(); + if (inventoryRowSearchList == null || inventoryRowSearchList.isEmpty()) { + MessageDialog.error(null, "angal.inventory.cannotsaveinventorywithoutproducts.msg"); + return; + } + try { + if (!lotsDeleted.isEmpty() || !inventoryRowsToDelete.isEmpty()) { + for (Map.Entry entry : lotsDeleted.entrySet()) { + MedicalInventoryRow invRow = medicalInventoryRowManager.getMedicalInventoryRowById(entry.getKey()); + if (invRow != null) { + invRow.setLot(null); + medicalInventoryRowManager.updateMedicalInventoryRow(invRow); + movStockInsertingManager.deleteLot(entry.getValue()); + } + } + medicalInventoryRowManager.deleteMedicalInventoryRows(inventoryRowsToDelete); + if (inventory.getStatus().equals(InventoryStatus.validated.toString())){ + inventory.setStatus(InventoryStatus.draft.toString()); + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); + } + } + List newMedicalInventoryRows = new ArrayList<>(); + if (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.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); + newMedicalInventoryRows.add(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 (mode.equals("update") && MessageDialog.yesNo(null, "angal.inventory.doyouwanttoupdatethisinventory.msg") == JOptionPane.YES_OPTION) { + String lastReference = inventory.getInventoryReference(); + LocalDateTime lastDateInventory = inventory.getInventoryDate(); + 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 (!inventory.getInventoryDate().equals(dateInventory)) { + inventory.setInventoryDate(dateInventory); + } + if (!inventory.getUser().equals(user)) { + inventory.setUser(user); + } + if (!newReference.equals(lastReference)) { + inventory.setInventoryReference(newReference); + } + if(inventory.getStatus().equals(InventoryStatus.validated.toString())) { + inventory.setStatus(InventoryStatus.draft.toString()); + } + if (inventoryRowListAdded.isEmpty() && lotsSaved.isEmpty() && lotsDeleted.isEmpty()) { + if (checkParameters(lastReference, lastDateInventory)) { + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); + if (inventory != null) { + MessageDialog.info(null, "angal.inventory.update.success.msg"); + statusLabel.setText(InventoryStatus.draft.toString().toUpperCase()); + statusLabel.setForeground(Color.GRAY); + 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; + } + } else { + if (!inventoryRowsToDelete.isEmpty()) { + MessageDialog.info(null, "angal.inventory.update.success.msg"); + statusLabel.setText(InventoryStatus.draft.toString().toUpperCase()); + statusLabel.setForeground(Color.GRAY); + 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; + } + } + return; + } + + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); + + for (MedicalInventoryRow medicalInventoryRow : inventoryRowSearchList) { + Medical medical = medicalInventoryRow.getMedical(); + Lot lot = medicalInventoryRow.getLot(); + if (lot != null) { + Lot lotExist = movStockInsertingManager.getLot(lot.getCode()); + if (lotExist != null) { + lot.setMedical(medical); + lot = movStockInsertingManager.updateLot(lot); + medicalInventoryRow.setLot(lot); + } else { + MedicalInventoryRow inventoryRow = medicalInventoryRowManager.getMedicalInventoryRowById(medicalInventoryRow.getId()); + if (inventoryRow != null && inventoryRow.getLock() != medicalInventoryRow.getLock()) { + Lot newLot = movStockInsertingManager.storeLot(lot.getCode(), lot, medical); + inventoryRow.setLot(newLot); + inventoryRow.setNewLot(true); + inventoryRow.setRealqty(medicalInventoryRow.getRealQty()); + medicalInventoryRow = inventoryRow; + } else { + Lot newLot = movStockInsertingManager.storeLot(lot.getCode(), lot, medical); + medicalInventoryRow.setLot(newLot); + medicalInventoryRow.setNewLot(true); + } + } + } + + medicalInventoryRow.setInventory(inventory); + medicalInventoryRow = medicalInventoryRow.getId() == 0 ? medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow) + : medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow); + + newMedicalInventoryRows.add(medicalInventoryRow); + } + MessageDialog.info(null, "angal.inventory.update.success.msg"); + statusLabel.setText(InventoryStatus.draft.toString().toUpperCase()); + statusLabel.setForeground(Color.GRAY); + resetVariable(); + fireInventoryUpdated(); + int info = MessageDialog.yesNo(null, "angal.inventory.doyouwanttocontinueediting.msg"); + if (info != JOptionPane.YES_OPTION) { + dispose(); + } + } + if (!newMedicalInventoryRows.isEmpty()) { + inventoryRowSearchList = newMedicalInventoryRows; + jTableInventoryRow.updateUI(); + } + } 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")); + 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) { + newReference = referenceTextField.getText().trim(); + String lastReference = inventory.getInventoryReference(); + LocalDateTime lastDate = inventory.getInventoryDate(); + if (checkParameters(lastReference, lastDate)) { + MessageDialog.error(null, "angal.inventory.pleasesaveinventorybeforevalidateit.msg"); + return; + } + if (!inventoryRowSearchList.stream().filter(i -> i.getLot() == null).toList().isEmpty()) { + MessageDialog.error(null, "angal.inventory.youcannotvalidatethisinventory.msg"); + return; + } + // validate inventory + String status = InventoryStatus.validated.toString(); + try { + medicalInventoryManager.validateMedicalWardInventoryRow(inventory, inventoryRowSearchList); + inventory.setStatus(status); + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); + MessageDialog.info(null, "angal.inventory.validate.success.msg"); + statusLabel.setText(status.toUpperCase()); + statusLabel.setForeground(Color.BLUE); + fireInventoryUpdated(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + int answer = MessageDialog.yesNo(null, "angal.inventory.doyouwanttoactualizetheinventory.msg"); + if (answer == JOptionPane.YES_OPTION) { + try { + inventory.setStatus(status); + medicalInventoryManager.actualizeMedicalWardInventoryRow(inventory); + statusLabel.setText(status.toUpperCase()); + statusLabel.setForeground(Color.BLUE); + jTableInventoryRow.setModel(new InventoryRowModel()); + fireInventoryUpdated(); + adjustWidth(); + } catch (OHServiceException e1) { + OHServiceExceptionUtil.showMessages(e1); + } + } else { try { - addInventoryRow(code); - } catch (OHServiceException e1) { - OHServiceExceptionUtil.showMessages(e1); + inventory.setStatus(InventoryStatus.draft.toString()); + statusLabel.setText(InventoryStatus.draft.toString().toUpperCase()); + statusLabel.setForeground(Color.GRAY); + inventory = medicalInventoryManager.updateMedicalInventory(inventory, true); + fireInventoryUpdated(); + } catch (OHServiceException ex) { + OHServiceExceptionUtil.showMessages(ex); } - 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; + }); + return validateButton; + } + + 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(); + } + }); + 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.inventory.pleaseselectatleastoneinventoryrow.msg"); + return; + } + int delete = MessageDialog.yesNo(null, "angal.inventory.doyoureallywanttodeletethisinventoryrow.msg"); + if (delete == JOptionPane.YES_OPTION) { + 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(); + } + }); + return deleteButton; + } + + private JButton getLotButton() { + lotButton = new JButton(MessageBundle.getMessage("angal.inventory.lot.btn")); + lotButton.setMnemonic(MessageBundle.getMnemonic("angal.inventory.lot.btn.key")); + lotButton.addActionListener(actionEvent -> { + int selectedRow = jTableInventoryRow.getSelectedRow(); + if (selectedRow == -1) { + MessageDialog.error(this, "angal.inventory.pleaseselectonlyoneinventory.msg"); + return; + } + MedicalInventoryRow selectedInventoryRow = (MedicalInventoryRow) jTableInventoryRow.getValueAt(selectedRow, -1); + Lot lotToUpdate = selectedInventoryRow.getLot(); + Lot lot = new Lot(); + try { + if (lotToUpdate != null && !selectedInventoryRow.isNewLot()) { + BigDecimal cost = BigDecimal.ZERO; + if (isLotWithCost()) { + cost = askCost(cost); + if (cost.compareTo(BigDecimal.ZERO) == 0) { + return; + } + } + lotToUpdate.setCost(cost); + lot = lotToUpdate; + } else { + lot = this.getLot(lotToUpdate); + String lotCode = lotToUpdate != null ? lotToUpdate.getCode() : ""; + if (lot != null && !lot.getCode().equals(lotCode)) { + Lot lotDelete = movStockInsertingManager.getLot(lotCode); + if (lotDelete != null) { + lotsDeleted.put(selectedInventoryRow.getId(), lotDelete); + } + } + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + return; + } + if (lot != null) { + code = lot.getCode(); + if (selectedInventoryRow.getLot() == null) { + List invRows = inventoryRowSearchList.stream() + .filter(inv -> inv.getLot() != null && inv.getLot().getCode().equals(code)).toList(); + if (invRows.isEmpty() || code.isEmpty()) { + selectedInventoryRow.setNewLot(true); + selectedInventoryRow.setLot(lot); + lotsSaved.add(lot); + } else { + if (lotToUpdate != null && code.equals(lotToUpdate.getCode())) { + selectedInventoryRow.setLot(lot); + lotsSaved.add(lot); + } else { + MessageDialog.error(this, "angal.inventoryrow.thislotcodealreadyexists.msg"); + lotButton.doClick(); + } + } + } else { + List invRows = inventoryRowSearchList.stream() + .filter(inv -> inv.getMedical().getCode().equals(selectedInventoryRow.getMedical().getCode())).toList(); + invRows = invRows.stream().filter(inv -> inv.getLot() != null && inv.getLot().getCode().equals(code)).toList(); + if (invRows.isEmpty() || code.isEmpty()) { + selectedInventoryRow.setNewLot(true); + selectedInventoryRow.setLot(lot); + lotsSaved.add(lot); + } else { + if (lotToUpdate != null && code.equals(lotToUpdate.getCode())) { + selectedInventoryRow.setLot(lot); + lotsSaved.add(lot); + } else { + MessageDialog.error(this, "angal.inventoryrow.thislotcodealreadyexists.msg"); + lotButton.doClick(); + } + } + } + inventoryRowSearchList.set(selectedRow, selectedInventoryRow); + jTableInventoryRow.updateUI(); + } + }); + return lotButton; + } + private BigDecimal askCost(BigDecimal lastCost) { + double cost = 0.; + do { + String input = JOptionPane.showInputDialog(this, MessageBundle.getMessage("angal.medicalstock.multiplecharging.unitcost"), + lastCost); + if (input != null) { + try { + cost = Double.parseDouble(input); + if (cost < 0) { + throw new NumberFormatException(); + } else if (cost == 0.) { + double total = askTotalCost(); + cost = total / 2; + } + } catch (NumberFormatException nfe) { + MessageDialog.error(this, "angal.medicalstock.multiplecharging.pleaseinsertavalidvalue"); + } + } else { + return BigDecimal.valueOf(cost); + } + } while (cost == 0.); + return BigDecimal.valueOf(cost); + } + + 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(actionEvent -> { + String lastReference = ""; + newReference = referenceTextField.getText().trim(); + LocalDateTime lastDate = dateInventory; + if (inventory != null) { + lastReference = inventory.getInventoryReference(); + lastDate = inventory.getInventoryDate(); + } + + if (checkParameters(lastReference, lastDate)) { + 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(); + } + } else { + resetVariable(); + dispose(); + } + }); + return closeButton; + } + + private JScrollPane getScrollPaneInventory() { + if (scrollPaneInventory == null) { + scrollPaneInventory = new JScrollPane(); + try { + scrollPaneInventory.setViewportView(getJTableInventoryRow()); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + return scrollPaneInventory; + } + + private JTable getJTableInventoryRow() throws OHServiceException { + if (jTableInventoryRow == null) { + jTableInventoryRow = new JTable(); + jTextFieldEditor = new JTextField(); + jTableInventoryRow.setFillsViewportHeight(true); + jTableInventoryRow.setModel(new InventoryRowModel()); + for (int i = 0; i < pColumnVisible.length; i++) { + 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); + jTableInventoryRow.getColumnModel().getColumn(i).setMaxWidth(0); + jTableInventoryRow.getColumnModel().getColumn(i).setPreferredWidth(0); + } + } + DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); + centerRenderer.setHorizontalAlignment(SwingConstants.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(), jTableInventoryRow.getSelectedColumn()); + } + } + }); + + DefaultCellEditor cellEditor = new DefaultCellEditor(jTextFieldEditor); + jTableInventoryRow.setDefaultEditor(Integer.class, cellEditor); + } + return jTableInventoryRow; + } + + 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 inventoryRow : inventoryRowList) { + addMedInRowInInventorySearchList(inventoryRow); + } + 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); + } + } + } + } + + @Override + public Class getColumnClass(int c) { + if (c == 0) { + return Integer.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; + } else if (c == 5) { + return String.class; + } else if (c == 6) { + return Double.class; + } else if (c == 7) { + return Integer.class; + } else if (c == 8) { + return Double.class; + } else if (c == 9) { + return Double.class; + } + return null; + } + + @Override + public int getRowCount() { + if (inventoryRowSearchList == null) { + return 0; + } + 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); + + 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.isNewLot() ? "N" : ""; + } else if (c == 4) { + return medInvtRow.getLot() == null ? "" : (medInvtRow.getLot().getCode().equals("") ? "AUTO" : medInvtRow.getLot().getCode()); + } else if (c == 5) { + if (medInvtRow.getLot() != null && medInvtRow.getLot().getDueDate() != null) { + return medInvtRow.getLot().getDueDate().format(DATE_TIME_FORMATTER); + } + return ""; + } else if (c == 6) { + return medInvtRow.getTheoreticQty(); + } else if (c == 7) { + double dblValue = medInvtRow.getRealQty(); + return (int) dblValue; + } else if (c == 8) { + if (medInvtRow.getLot() != null && medInvtRow.getLot().getCost() != null) { + return medInvtRow.getLot().getCost(); + } + return 0.0; + } else if (c == 9) { + if (medInvtRow.getLot() != null && 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 == 7) { + 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); + 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); + SwingUtilities.invokeLater(() -> jTableInventoryRow.updateUI()); + } + } + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnEditable[columnIndex]; + } + } + + 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(SwingConstants.CENTER); + jTableInventoryRow.getColumnModel().getColumn(3).setCellRenderer(centerRenderer); + } + + private List getMedicalInventoryRows(String code) throws OHServiceException { + List inventoryRowsList = new ArrayList<>(); + List medicalWardList = new ArrayList<>(); + Medical medical; + MedicalInventoryRow inventoryRowTemp; + 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, false); + } + 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; + } + + 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; + } + } + } + } + return found; + } + + private JRadioButton getSpecificRadio() { + if (specificRadio == null) { + specificRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.specificproduct.btn")); + specificRadio.addActionListener(actionEvent -> { + if (specificRadio.isSelected()) { + codeTextField.setEnabled(true); + codeTextField.setText(""); + allRadio.setSelected(false); + } + }); + } + return specificRadio; + } + + private JRadioButton getAllRadio() { + if (allRadio == null) { + allRadio = new JRadioButton(MessageBundle.getMessage("angal.inventory.allproduct.btn")); + allRadio.setSelected(inventory != null); + specificRadio.setSelected(inventory == null); + allRadio.addActionListener(actionEvent -> { + 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(); + } + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + }); + } + return allRadio; + } + + 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(inventory == null); + 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(SwingConstants.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); + } + if (inventory != null && !inventory.getStatus().equals(InventoryStatus.draft.toString())) { + inventory.setStatus(InventoryStatus.draft.toString()); + } + codeTextField.setText(""); + } + } + }); + } + return codeTextField; + } + + private void addInventoryRow(String code) throws OHServiceException { + List inventoryRowsList = new ArrayList<>(); + List medicalWardList; + List lots; + Medical medical = null; + MedicalInventoryRow inventoryRowTemp; + if (wardId.isEmpty()) { + wardId = ((Ward) Objects.requireNonNull(wardComboBox.getSelectedItem())).getCode(); + } + if (code != null) { + medical = medicalBrowsingManager.getMedicalByMedicalCode(code); + if (medical == null) { + medical = chooseMedical(code); + } + } + medicalWardList = medical != null ? movWardBrowserManager.getMedicalsWard(wardId, medical.getCode(), false) : new ArrayList<>(); + if (!medicalWardList.isEmpty()) { + boolean found = false; + for (MedicalInventoryRow row : inventoryRowSearchList) { + if (row.getMedical().getCode().equals(medical.getCode())) { + found = true; + break; + } + } + if (!found) { + inventoryRowsList = medicalWardList.stream().map(medWard -> new MedicalInventoryRow(0, medWard.getQty(), + medWard.getQty(), null, medWard.getMedical(), medWard.getLot())).toList(); + } else { + int info = MessageDialog.yesNo(null, "angal.inventory.productalreadyexist.msg", medical.getDescription()); + if (info == JOptionPane.YES_OPTION) { + inventoryRowsList.add(new MedicalInventoryRow(0, 0.0, 0.0, null, medical, null)); + } + } + + } else { + int numberOfMedicalWithoutSameLotAdded = 0; + Medical medicalWithLot = null; + lots = movStockInsertingManager.getLotByMedical(medical, false); + if (lots.isEmpty()) { + inventoryRowTemp = new MedicalInventoryRow(0, 0.0, 0.0, null, medical, null); + if (!existInInventorySearchList(inventoryRowTemp)) { + inventoryRowsList.add(inventoryRowTemp); + } else { + int info = MessageDialog.yesNo(null, "angal.inventory.productalreadyexist.msg", medical.getDescription()); + if (info == JOptionPane.YES_OPTION) { + inventoryRowsList.add(inventoryRowTemp); + } + } + } else { + medicalWithLot = medical; + for (Lot lot : lots) { + inventoryRowTemp = new MedicalInventoryRow(0, lot.getMainStoreQuantity(), lot.getMainStoreQuantity(), null, lot.getMedical(), lot); + if (!existInInventorySearchList(inventoryRowTemp)) { + inventoryRowsList.add(inventoryRowTemp); + numberOfMedicalWithoutSameLotAdded = numberOfMedicalWithoutSameLotAdded + 1; + } + } + } + if (medicalWithLot != null && numberOfMedicalWithoutSameLotAdded == 0) { + int info = MessageDialog.yesNo(null, "angal.inventory.productalreadyexist.msg", medicalWithLot.getDescription()); + if (info == JOptionPane.YES_OPTION) { + inventoryRowTemp = new MedicalInventoryRow(0, 0.0, 0.0, null, medicalWithLot, null); + inventoryRowsList.add(inventoryRowTemp); + } + } + } + if (inventoryRowSearchList == null) { + inventoryRowSearchList = new ArrayList<>(); + } + + inventoryRowsList.forEach(this::addMedInRowInInventorySearchList); + jTableInventoryRow.updateUI(); + } + + private Medical chooseMedical(String text) throws OHServiceException { + Map medicalMap; + List medicals = medicalBrowsingManager.getMedicals(); + + medicalMap = new HashMap<>(); + for (Medical med : medicals) { + String key; + key = med.getCode().toString().toLowerCase(); + medicalMap.put(key, med); + } + List medList = new ArrayList<>(); + for (Medical aMed : medicalMap.values()) { + if (NormalizeString.normalizeContains(aMed.getDescription().toLowerCase(), text)) { + medList.add(aMed); + } + } + Collections.sort(medList); + Medical med; + 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.chooseamedical")); + framas.setParentFrame(dialog); + dialog.setContentPane(framas); + dialog.setVisible(true); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + med = framas.getSelectedMedical(); + return med; + } + return null; + } + + + 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()); + } + } + 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")); + } + 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); + } + 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.addItemListener(itemEvent -> { + + + if (itemEvent.getStateChange() == ItemEvent.SELECTED) { + Object item = itemEvent.getItem(); + if (item instanceof Ward) { + wardSelected = (Ward) item; + wardId = wardSelected.getCode(); + List medicalWardInventoryDraft; + List medicalWardInventoryValidated; + try { + medicalWardInventoryDraft = medicalInventoryManager + .getMedicalInventoryByStatusAndWard(InventoryStatus.draft.toString(), wardId); + medicalWardInventoryValidated = medicalInventoryManager + .getMedicalInventoryByStatusAndWard(InventoryStatus.validated.toString(), wardId); + } catch (OHServiceException e) { + medicalWardInventoryDraft = new ArrayList<>(); + medicalWardInventoryValidated = new ArrayList<>(); + OHServiceExceptionUtil.showMessages(e); + } + + if (medicalWardInventoryDraft.isEmpty() && medicalWardInventoryValidated.isEmpty()) { + activateSomeComponents(); + } else { + MessageDialog.error(this, + "angal.inventory.cannotcreateanotherinventorywithotherinprogressinthisward.msg"); + } + } + } + }); + } + return wardComboBox; + } + + private void disabledSomeComponents() { + jCalendarInventory.setEnabled(false); + specificRadio.setEnabled(false); + codeTextField.setEnabled(false); + allRadio.setEnabled(false); + referenceTextField.setEnabled(false); + jTableInventoryRow.setEnabled(false); + saveButton.setEnabled(false); + deleteButton.setEnabled(false); + resetButton.setEnabled(false); + lotButton.setEnabled(false); + } + + private void activateSomeComponents() { + jCalendarInventory.setEnabled(true); + specificRadio.setEnabled(true); + codeTextField.setEnabled(true); + allRadio.setEnabled(true); + referenceTextField.setEnabled(true); + jTableInventoryRow.setEnabled(true); + wardComboBox.setEnabled(false); + saveButton.setEnabled(true); + deleteButton.setEnabled(true); + resetButton.setEnabled(true); + lotButton.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 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(); + lotsDeleted.clear(); + inventoryRowListAdded.clear(); + lotsSaved.clear(); + } + + private boolean isLotWithCost() { + return GeneralData.LOTWITHCOST; + } + + private boolean isAutomaticLotIn() { + return GeneralData.AUTOMATICLOT_IN; + } + + protected double askTotalCost() { + String input = JOptionPane.showInputDialog(this, MessageBundle.getMessage("angal.medicalstock.multiplecharging.totalcost"), 0.); + double total = 0.; + if (input != null) { + try { + total = Double.parseDouble(input); + if (total < 0) { + throw new NumberFormatException(); + } + } catch (NumberFormatException nfe) { + MessageDialog.error(this, "angal.medicalstock.multiplecharging.pleaseinsertavalidvalue"); + } + } + return total; + } + + private Lot getLot(Lot lotToUpdate) throws OHServiceException { + Lot lot = null; + if (isAutomaticLotIn()) { + LocalDateTime preparationDate = TimeTools.getNow().truncatedTo(ChronoUnit.MINUTES); + LocalDateTime expiringDate = askExpiringDate(); + lot = new Lot("", preparationDate, expiringDate); + // Cost + BigDecimal cost = new BigDecimal(0); + if (isLotWithCost()) { + cost = askCost(cost); + if (cost.compareTo(new BigDecimal(0)) == 0) { + return null; + } + } + lot.setCost(cost); + } else { + lot = askLot(lotToUpdate); + } + return lot; + } + + protected LocalDateTime askExpiringDate() { + LocalDateTime date = TimeTools.getNow(); + GoodDateTimeSpinnerChooser expireDateChooser = new GoodDateTimeSpinnerChooser(date); + JPanel panel = new JPanel(new GridLayout(1, 2)); + panel.add(new JLabel(MessageBundle.getMessage("angal.medicalstock.multiplecharging.expiringdate"))); + panel.add(expireDateChooser); + + int ok = JOptionPane.showConfirmDialog(this, panel, MessageBundle.getMessage("angal.medicalstock.multiplecharging.expiringdate"), + JOptionPane.OK_CANCEL_OPTION); + + if (ok == JOptionPane.OK_OPTION) { + date = expireDateChooser.getLocalDateTime(); + } + return date; + } + + private Lot askLot(Lot lotToUpdate) { + LocalDateTime preparationDate; + LocalDateTime expiringDate; + Lot lot = null; + + JTextField lotNameTextField = new JTextField(15); + lotNameTextField.addAncestorListener(new RequestFocusListener()); + TextPrompt suggestion = new TextPrompt(MessageBundle.getMessage("angal.medicalstock.multiplecharging.lotid"), lotNameTextField); + suggestion.setFont(new Font("Tahoma", Font.PLAIN, 14)); + suggestion.setForeground(Color.GRAY); + suggestion.setHorizontalAlignment(SwingConstants.CENTER); + suggestion.changeAlpha(0.5f); + suggestion.changeStyle(Font.BOLD + Font.ITALIC); + LocalDate now = LocalDate.now(); + GoodDateChooser preparationDateChooser = new GoodDateChooser(now); + GoodDateChooser expireDateChooser = new GoodDateChooser(now); + if (lotToUpdate != null) { + lotNameTextField.setText(lotToUpdate.getCode()); + preparationDateChooser = new GoodDateChooser(lotToUpdate.getPreparationDate().toLocalDate()); + expireDateChooser = new GoodDateChooser(lotToUpdate.getDueDate().toLocalDate()); + } + JPanel panel = new JPanel(new GridLayout(3, 2)); + panel.add(new JLabel(MessageBundle.getMessage("angal.medicalstock.multiplecharging.lotnumberabb"))); + panel.add(lotNameTextField); + panel.add(new JLabel(MessageBundle.getMessage("angal.medicalstock.multiplecharging.preparationdate"))); + panel.add(preparationDateChooser); + panel.add(new JLabel(MessageBundle.getMessage("angal.medicalstock.multiplecharging.expiringdate"))); + panel.add(expireDateChooser); + do { + int ok = JOptionPane.showConfirmDialog(this, panel, + MessageBundle.getMessage("angal.medicalstock.multiplecharging.lotinformations"), JOptionPane.OK_CANCEL_OPTION); + if (ok == JOptionPane.OK_OPTION) { + String lotName = lotNameTextField.getText(); + if (expireDateChooser.getDate().isBefore(preparationDateChooser.getDate())) { + MessageDialog.error(this, "angal.medicalstock.multiplecharging.expirydatebeforepreparationdate"); + } else { + expiringDate = expireDateChooser.getDateEndOfDay(); + preparationDate = preparationDateChooser.getDateStartOfDay(); + lot = new Lot(lotName, preparationDate, expiringDate); + BigDecimal cost = new BigDecimal(0); + if (isLotWithCost()) { + if (lotToUpdate != null) { + cost = askCost(lotToUpdate.getCost()); + } else { + cost = askCost(cost); + } + + if (cost.compareTo(new BigDecimal(0)) == 0) { + return null; + } else { + lot.setCost(cost); + } + } + } + } else { + return null; + } + } while (lot == null); + return lot; + } + + private boolean checkParameters(String reference, LocalDateTime date) { + return !lotsSaved.isEmpty() || !inventoryRowListAdded.isEmpty() || !lotsDeleted.isEmpty() || !inventoryRowsToDelete.isEmpty() + || (reference != null && !reference.equals(newReference)) || !date.toLocalDate().equals(dateInventory.toLocalDate()); } } 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); } diff --git a/src/main/java/org/isf/medicals/gui/MedicalBrowser.java b/src/main/java/org/isf/medicals/gui/MedicalBrowser.java index 231810640a..74b3f27d7f 100644 --- a/src/main/java/org/isf/medicals/gui/MedicalBrowser.java +++ b/src/main/java/org/isf/medicals/gui/MedicalBrowser.java @@ -595,7 +595,7 @@ private JComboBox getComboBoxMedicalType() { pbox.addItem(STR_ALL); List type; try { - type = medicalTypeManager.getMedicalType(); + type = medicalTypeManager.getAllActiveMedicalType(); for (MedicalType elem : type) { pbox.addItem(elem); } diff --git a/src/main/java/org/isf/medicals/gui/MedicalEdit.java b/src/main/java/org/isf/medicals/gui/MedicalEdit.java index 61825d0143..f953292a70 100644 --- a/src/main/java/org/isf/medicals/gui/MedicalEdit.java +++ b/src/main/java/org/isf/medicals/gui/MedicalEdit.java @@ -432,7 +432,7 @@ private JComboBox getTypeComboBox() { if (typeComboBox == null) { typeComboBox = new JComboBox<>(); try { - List types = medicalTypeManager.getMedicalType(); + List types = medicalTypeManager.getAllActiveMedicalType(); for (MedicalType elem : types) { typeComboBox.addItem(elem); } diff --git a/src/main/java/org/isf/medicalstock/gui/MovStockBrowser.java b/src/main/java/org/isf/medicalstock/gui/MovStockBrowser.java index 99ab7dc533..02b7a0c10c 100644 --- a/src/main/java/org/isf/medicalstock/gui/MovStockBrowser.java +++ b/src/main/java/org/isf/medicalstock/gui/MovStockBrowser.java @@ -618,7 +618,7 @@ private JComboBox getMedicalTypeBox() { medicalTypeBox.addItem(TEXT_ALL); try { - medical = medicalTypeBrowserManager.getMedicalType(); + medical = medicalTypeBrowserManager.getAllActiveMedicalType(); for (MedicalType aMedicalType : medical) { medicalTypeBox.addItem(aMedicalType); diff --git a/src/main/java/org/isf/medicalstockward/gui/WardPharmacy.java b/src/main/java/org/isf/medicalstockward/gui/WardPharmacy.java index 5c50678441..587ad2a2d0 100644 --- a/src/main/java/org/isf/medicalstockward/gui/WardPharmacy.java +++ b/src/main/java/org/isf/medicalstockward/gui/WardPharmacy.java @@ -1461,8 +1461,8 @@ class DrugsModel extends DefaultTableModel { public DrugsModel() { try { - tableModel = movWardBrowserManager.getMedicalsWardTotalQuantity(wardSelected.getCode().charAt(0)); - wardDrugs = movWardBrowserManager.getMedicalsWard(wardSelected.getCode().charAt(0), true); + tableModel = movWardBrowserManager.getMedicalsWardTotalQuantity(wardSelected.getCode()); + wardDrugs = movWardBrowserManager.getMedicalsWard(wardSelected.getCode(), true); } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); tableModel = new ArrayList<>(); diff --git a/src/main/java/org/isf/medicalstockward/gui/WardPharmacyRectify.java b/src/main/java/org/isf/medicalstockward/gui/WardPharmacyRectify.java index 194ade63bb..7264a6f36e 100644 --- a/src/main/java/org/isf/medicalstockward/gui/WardPharmacyRectify.java +++ b/src/main/java/org/isf/medicalstockward/gui/WardPharmacyRectify.java @@ -162,7 +162,7 @@ public WardPharmacyRectify(JFrame owner, Ward ward) { super(owner, true); selectedWard = ward; try { - wardDrugs = movWardBrowserManager.getMedicalsWard(selectedWard.getCode().charAt(0), false); + wardDrugs = movWardBrowserManager.getMedicalsWard(selectedWard.getCode(), false); } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } @@ -184,7 +184,7 @@ public WardPharmacyRectify(JFrame owner, Ward ward, Medical medical) { super(owner, true); selectedWard = ward; try { - wardDrugs = movWardBrowserManager.getMedicalsWard(selectedWard.getCode().charAt(0), false); + wardDrugs = movWardBrowserManager.getMedicalsWard(selectedWard.getCode(), false); } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } diff --git a/src/main/java/org/isf/medtype/gui/MedicalTypeBrowser.java b/src/main/java/org/isf/medtype/gui/MedicalTypeBrowser.java index 6c9fdb9d49..7e173e9744 100644 --- a/src/main/java/org/isf/medtype/gui/MedicalTypeBrowser.java +++ b/src/main/java/org/isf/medtype/gui/MedicalTypeBrowser.java @@ -54,9 +54,10 @@ public class MedicalTypeBrowser extends ModalJFrame implements MedicalTypeListen private List pMedicalType; private String[] pColumns = { MessageBundle.getMessage("angal.common.code.txt").toUpperCase(), - MessageBundle.getMessage("angal.common.description.txt").toUpperCase() + MessageBundle.getMessage("angal.common.description.txt").toUpperCase(), + MessageBundle.getMessage("angal.common.deleted.label").toUpperCase() }; - private int[] pColumnWidth = {80, 200}; + private final int[] pColumnWidth = { 20, 200, 20 }; private JPanel jContainPanel; private JPanel jButtonPanel; private JButton jNewButton; @@ -198,6 +199,7 @@ private JTable getJTable() { jTable = new JTable(model); jTable.getColumnModel().getColumn(0).setMinWidth(pColumnWidth[0]); jTable.getColumnModel().getColumn(1).setMinWidth(pColumnWidth[1]); + jTable.getColumnModel().getColumn(2).setMinWidth(pColumnWidth[2]); } return jTable; } @@ -243,6 +245,8 @@ public Object getValueAt(int r, int c) { return medType.getCode(); } else if (c == 1) { return medType.getDescription(); + } else if (c == 2) { + return medType.getDeleted() == 'Y'; } return null; } @@ -251,6 +255,11 @@ public Object getValueAt(int r, int c) { public boolean isCellEditable(int arg0, int arg1) { return false; } + + @Override + public Class getColumnClass(int column) { + return (column == 2) ? Boolean.class : String.class; + } } @Override diff --git a/src/main/java/org/isf/medtype/gui/MedicalTypeBrowserEdit.java b/src/main/java/org/isf/medtype/gui/MedicalTypeBrowserEdit.java index 82e8f69556..36e4613717 100644 --- a/src/main/java/org/isf/medtype/gui/MedicalTypeBrowserEdit.java +++ b/src/main/java/org/isf/medtype/gui/MedicalTypeBrowserEdit.java @@ -26,6 +26,7 @@ import java.util.EventListener; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; @@ -95,8 +96,10 @@ private void fireMedicalUpdated() { private JButton cancelButton; private JButton okButton; private JTextField descriptionTextField; + private JCheckBox deletedCheckbox; private VoLimitedTextField codeTextField; private String lastdescription; + private char isLastDeleted; private MedicalType medicalType; private boolean insert; private JPanel jDataPanel; @@ -110,6 +113,7 @@ public MedicalTypeBrowserEdit(JFrame owner, MedicalType old, boolean inserting) insert = inserting; medicalType = old; //medical type will be used for every operation lastdescription = medicalType.getDescription(); + isLastDeleted = medicalType.getDeleted(); initialize(); } @@ -124,6 +128,7 @@ private void initialize() { this.setTitle(MessageBundle.getMessage("angal.medtype.editmedicaltype.title")); } this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + this.getDeletedField(); this.pack(); this.setLocationRelativeTo(null); } @@ -197,7 +202,8 @@ private JButton getOkButton() { medicalType.setDescription(descriptionTextField.getText()); medicalType.setCode(codeTextField.getText()); - + medicalType.setDeleted(deletedCheckbox.isSelected() ? 'Y' : 'N'); + if (insert) { // inserting try { MedicalType insertedMedicalType = medicalTypeBrowserManager.newMedicalType(medicalType); @@ -211,7 +217,7 @@ private JButton getOkButton() { OHServiceExceptionUtil.showMessages(e1); } } else { // updating - if (descriptionTextField.getText().equals(lastdescription)) { + if (descriptionTextField.getText().equals(lastdescription) && medicalType.getDeleted() == isLastDeleted) { dispose(); } else { try { @@ -263,6 +269,14 @@ private JTextField getCodeTextField() { } return codeTextField; } + + private JCheckBox getDeletedField() { + if (deletedCheckbox == null) { + deletedCheckbox = new JCheckBox(MessageBundle.getMessage("angal.common.deleted.label")); + deletedCheckbox.setSelected(medicalType.getDeleted() == 'Y'); + } + return deletedCheckbox; + } /** * This method initializes jDataPanel @@ -276,7 +290,9 @@ private JPanel getJDataPanel() { jDataPanel.add(getCodeTextField()); jDataPanel.add(new JLabel(MessageBundle.getMessage("angal.common.description.txt") + ':')); jDataPanel.add(getDescriptionTextField()); - SpringUtilities.makeCompactGrid(jDataPanel, 2, 2, 5, 5, 5, 5); + jDataPanel.add(new JLabel(MessageBundle.getMessage("angal.common.deleted.label") + ':')); + jDataPanel.add(getDeletedField()); + SpringUtilities.makeCompactGrid(jDataPanel, 3, 2, 5, 5, 5, 5); } return jDataPanel; } diff --git a/src/main/java/org/isf/menu/gui/UserEdit.java b/src/main/java/org/isf/menu/gui/UserEdit.java index 2c444058bd..55fa9c1833 100644 --- a/src/main/java/org/isf/menu/gui/UserEdit.java +++ b/src/main/java/org/isf/menu/gui/UserEdit.java @@ -340,20 +340,24 @@ private JComboBox getUserGroupComboBox() { if (userGroupComboBox == null) { userGroupComboBox = new JComboBox<>(); try { - List group = userBrowsingManager.getUserGroup(); + List groups = userBrowsingManager.getUserGroup(); if (insert) { - if (group != null) { - for (UserGroup elem : group) { - userGroupComboBox.addItem(elem); + if (groups != null) { + for (UserGroup group : groups) { + if (!group.isDeleted()) { + userGroupComboBox.addItem(group); + } } } } else { UserGroup selectedUserGroup = null; - if (group != null) { - for (UserGroup elem : group) { - userGroupComboBox.addItem(elem); - if (user.getUserGroupName().equals(elem)) { - selectedUserGroup = elem; + if (groups != null) { + for (UserGroup group : groups) { + if (!group.isDeleted()) { + userGroupComboBox.addItem(group); + if (user.getUserGroupName().equals(group)) { + selectedUserGroup = group; + } } } } diff --git a/src/main/java/org/isf/telemetry/gui/TelemetryEdit.java b/src/main/java/org/isf/telemetry/gui/TelemetryEdit.java index 497418c7cb..6663e6c806 100644 --- a/src/main/java/org/isf/telemetry/gui/TelemetryEdit.java +++ b/src/main/java/org/isf/telemetry/gui/TelemetryEdit.java @@ -217,6 +217,7 @@ private ActionListener buildConfirmationActionListener(List che TelemetryManager telemetryManager, TelemetryUtils telemetryUtils) { return new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (!agreementCheckbox.isSelected()) { 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 1a81bf0e80..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; -} \ 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