Skip to content

Commit

Permalink
Merge pull request #4570 from hmislk/Issue#3917
Browse files Browse the repository at this point in the history
Closes #3917 #4568
  • Loading branch information
buddhika75 authored Apr 10, 2024
2 parents c6e0d2b + 5560893 commit 5f0bc5d
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 78 deletions.
43 changes: 21 additions & 22 deletions src/main/java/com/divudi/bean/common/VersionController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
*/
package com.divudi.bean.common;

import javax.inject.Named;
Expand All @@ -10,7 +6,6 @@
import java.nio.file.Paths;
import java.io.IOException;


/**
*
* @author L C J Samarasekara <[email protected]>
Expand All @@ -26,30 +21,34 @@ public VersionController() {
readFirstLine(); // Load first line content upon bean instantiation
}

/**
* Reads the first line of the text file and checks if it contains the system version.
*/
public void readFirstLine() {
try {
// Read the first line from the file
String firstLine = Files.lines(Paths.get(fileName)).findFirst().orElse(null);
if (firstLine != null && !firstLine.isEmpty()) {
// Set systemVersion to the content of the first line
systemVersion = firstLine.trim();
} else {
// If the first line is empty or the file does not exist, set systemVersion to "0.0.0.0"
try {
// Check if the file exists, if not, create it
java.nio.file.Path path = Paths.get(fileName);
if (!Files.exists(path)) {
Files.createFile(path);
}

// Read the first line from the file
String firstLine = Files.lines(path).findFirst().orElse(null);
if (firstLine != null && !firstLine.isEmpty()) {
// Set systemVersion to the content of the first line
systemVersion = firstLine.trim();
} else {
// If the first line is empty or the file does not exist, set systemVersion to null
systemVersion = null;
}
} catch (IOException e) {
// Handle IOException by printing the stack trace
e.printStackTrace();
// Set systemVersion to null if an IOException occurs
systemVersion = null;
}
} catch (IOException e) {
// Handle IOException by printing the stack trace
e.printStackTrace();
// Set systemVersion to "0.0.0.0" if an IOException occurs
systemVersion = null;
}
}

// Getter for systemVersion (to make it accessible from XHTML)
public String getSystemVersion() {
return systemVersion;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void removeFromPackage() {
getFacade().edit(getCurrent());
JsfUtil.addSuccessMessage("Item Removed");
recreateModel();
listItemForDistributer();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ public String navigateToImporters() {
importerController.getCurrent();
return "/pharmacy/pharmacy_importer?faces-redirect=true";
}

public String navigateToSuppliers(){
return "/pharmacy/pharmacy_dealer?faces-redirect=true";
}

public String navigateToItemSuppliers(){
return "/pharmacy/pharmacy_items_distributors?faces-redirect=true";
}

public String navigateToVmp() {
return "/pharmacy/admin/vmp?faces-redirect=true";
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/pharmacy/admin/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
<div class="d-grid gap-2">
<p:commandButton class="w-100" ajax="false" value="Manufacturers" action="#{pharmacyController.navigateToManufacturers()}" ></p:commandButton>
<p:commandButton class="w-100" ajax="false" value="Importers" action="#{pharmacyController.navigateToImporters()}" ></p:commandButton>
<p:commandButton class="w-100" ajax="false" value="Supplier" action="/pharmacy/pharmacy_dealer" ></p:commandButton>
<p:commandButton class="w-100" ajax="false" value="Item Suppliers" action="/pharmacy/pharmacy_items_distributors" ></p:commandButton>
<p:commandButton class="w-100" ajax="false" value="Supplier" action="#{pharmacyController.navigateToSuppliers()}" ></p:commandButton>
<p:commandButton class="w-100" ajax="false" value="Item Suppliers" action="#{pharmacyController.navigateToItemSuppliers()}" ></p:commandButton>
</div>
</p:tab>
<p:tab title="Check Entered Data">
Expand Down
120 changes: 66 additions & 54 deletions src/main/webapp/pharmacy/pharmacy_items_distributors.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,75 @@
<f:facet name="header">
<div class="d-flex justify-content-between">
<div><p:outputLabel value="Item Suppliers" class="mt-2"/></div>
<div class="d-flex gap-2">
<p:outputLabel value="Select Supplier" style="font-size: 16px;" class="mt-2"/>
<p:autoComplete
converter="deal"
id="lstSelect"
value="#{itemsDistributorsController.currentInstituion}"
forceSelection="true"
completeMethod="#{dealerController.completeDealor}"
var="myItem" itemValue="#{myItem}"
style="width: 20em;"
inputStyleClass="form-control"
itemLabel="#{myItem.name}" >
<p:column headerText="Item">
<h:outputLabel value="#{myItem.name}" ></h:outputLabel>
</p:column>
<f:ajax event="itemSelect" render="gpDetail" execute="lstSelect" >
</f:ajax>
</p:autoComplete>
<p:commandButton
ajax="false"
value="List Items"
action="#{itemsDistributorsController.listItemForDistributer()}">
</p:commandButton>
</div>


</div>
</f:facet>

<div class="d-flex gap-2 mb-3">
<p:autoComplete
value="#{itemsDistributorsController.currentItem}"
forceSelection="true"
class="col-md-4"
inputStyleClass="form-control"
id="acItem"
maxResults="15"
completeMethod="#{itemController.completeAmpItem}"
var="vt"
itemLabel="#{vt.name}"
itemValue="#{vt}" >
<p:column headerText="Name" >
<h:outputLabel value="#{vt.name}" ></h:outputLabel>
</p:column>
<p:column headerText="Code" >
<h:outputLabel value="#{vt.code}" ></h:outputLabel>
</p:column>
</p:autoComplete>
<p:watermark for="acItem" value="Select Item to Add" ></p:watermark>
<p:commandButton
id="btnAdd"
class="ui-button-success"
icon="fa fa-plus"
ajax="false"
value="Add Item"
action="#{itemsDistributorsController.addItemToDistributor()}">
</p:commandButton>
<p:defaultCommand target="btnAdd"/>
<div class="row d-flex gap-2 mb-3">
<div class="d-flex gap-2">
<p:outputLabel value="Select Supplier" style="font-size: 16px; width: 10em;" class="mt-2"/>
<p:autoComplete
converter="deal"
id="lstSelect"
value="#{itemsDistributorsController.currentInstituion}"
forceSelection="true"
completeMethod="#{dealerController.completeDealor}"
var="myItem" itemValue="#{myItem}"
maxResults="10"
minQueryLength="3"
style="width: 40em;"
inputStyleClass="form-control"
itemLabel="#{myItem.name}" >
<p:column headerText="Item">
<h:outputLabel value="#{myItem.name}" ></h:outputLabel>
</p:column>
<f:ajax event="itemSelect" render="gpDetail" execute="lstSelect" >
</f:ajax>
</p:autoComplete>
<p:commandButton
ajax="false"
style="width: 20em;"
value="List Items Supplied by the Supplier"
action="#{itemsDistributorsController.listItemForDistributer()}">
</p:commandButton>
</div>

</div>
<div class="row d-flex gap-2 mb-3">
<div class="d-flex gap-2">
<p:outputLabel value="Item" style="font-size: 16px; width: 10em;" class="mt-2"/>
<p:autoComplete
value="#{itemsDistributorsController.currentItem}"
forceSelection="true"
class="col-md-4"
inputStyleClass="form-control"
id="acItem"
style="width: 40em;"
maxResults="15"
completeMethod="#{itemController.completeAmpItem}"
var="vt"
itemLabel="#{vt.name}"
itemValue="#{vt}" >
<p:column headerText="Name" >
<h:outputLabel value="#{vt.name}" ></h:outputLabel>
</p:column>
<p:column headerText="Code" >
<h:outputLabel value="#{vt.code}" ></h:outputLabel>
</p:column>
</p:autoComplete>
<p:watermark for="acItem" value="Select Item to Add" ></p:watermark>
<p:commandButton
id="btnAdd"
class="ui-button-success"
icon="fa fa-plus"
ajax="false"
style="width: 20em;"
value="Add Item to Supplier"
action="#{itemsDistributorsController.addItemToDistributor()}">
</p:commandButton>
<p:defaultCommand target="btnAdd"/>
</div>
</div>

<h:panelGroup id="gpDetail" >
Expand Down Expand Up @@ -106,7 +118,7 @@
</p:dataTable>
</h:panelGroup>
</p:panel>

</h:form>
</ui:define>
</ui:composition>

0 comments on commit 5f0bc5d

Please sign in to comment.