TavernerPOS - Source Code

Clone: 

git clone http://www.librarysmith.co.uk/tavernerPOS

 

viewgit/viewgit/inc/functions.php:49 Function create_function() is deprecated [8192]

Index » tavernerPOS : Commitdiff 46c9b0

Add option to Automatically set Terminal ID based on last 9 decimal digits of network MAC Address

Matt Smith [15-11-04 14:26]
Add option to Automatically set Terminal ID based on last 9 decimal digits of network MAC Address
diff --git a/i18n/messages.properties b/i18n/messages.properties
index 8a8af69..7cd6175 100755
--- a/i18n/messages.properties
+++ b/i18n/messages.properties
@@ -1304,3 +1304,4 @@ UserPermission.9=Drawer Pull
 BARMOD_TicketListView.21=Are you sure you want to clear all item?
 BARMOD_TicketListView.20=Clear All Items?
 BARMOD_AutoSaveOpen.1=Automatically Save/Open Open take out tickets on Logout/Login?
+BARMOD_AutoTerminalID.1=Automatically set Terminal ID based on last 9 decimal digits of network MAC Address.
\ No newline at end of file
diff --git a/src/com/floreantpos/config/TerminalConfig.java b/src/com/floreantpos/config/TerminalConfig.java
index 29b2eb2..d734c09 100755
--- a/src/com/floreantpos/config/TerminalConfig.java
+++ b/src/com/floreantpos/config/TerminalConfig.java
@@ -6,6 +6,7 @@ import org.apache.commons.lang.StringUtils;
 import com.floreantpos.model.OrderTypeFilter;
 import com.floreantpos.model.PaymentStatusFilter;
 import com.floreantpos.util.PasswordHasher;
+import com.floreantpos.getnetinfo.NetInfo;

 public class TerminalConfig {
 	private static final String USE_SETTLEMENT_PROMPT = "UseSettlementPrompt"; //$NON-NLS-1$
@@ -45,9 +46,18 @@ public class TerminalConfig {

 	private static final String AUTOSAVEANDOPEN_TAKEOUT_TICKET = "auto_save_and_open";//$NON-NLS-1$

+	private static final String AUTOTERMINAL_ID= "auto_terminal_id";//$NON-NLS-1$
+
 	private static PropertiesConfiguration config = AppConfig.getConfig();

 	public static int getTerminalId() {
+
+		if (config.getBoolean(AUTOTERMINAL_ID)==true) {
+			int terminalID=NetInfo.getTerminalIDFromMACAddr();
+			if (terminalID!=-1l) {
+				return(terminalID);
+			}
+		}
 		return config.getInt(TERMINAL_ID, -1);
 	}

@@ -55,6 +65,7 @@ public class TerminalConfig {
 		config.setProperty(TERMINAL_ID, id);
 	}

+
 	public static boolean isFullscreenMode() {
 		return config.getBoolean(FULLSCREEN_MODE, false);
 	}
@@ -239,6 +250,15 @@ public class TerminalConfig {
 		config.setProperty(AUTOSAVEANDOPEN_TAKEOUT_TICKET, autosaveandopen);
 	}

+
+	public static boolean isAutoTerminalID() {
+		return config.getBoolean(AUTOTERMINAL_ID, false);
+	}
+
+	public static void setAutoTerminalID(boolean autoterminalid) {
+		config.setProperty(AUTOTERMINAL_ID, autoterminalid);
+	}
+

 	public static char[] getDrawerControlCodesArray() {
 		String drawerControlCodes = getDefaultDrawerControlCodes();
diff --git a/src/com/floreantpos/config/ui/TerminalConfigurationView.java b/src/com/floreantpos/config/ui/TerminalConfigurationView.java
index 147cb9c..b765b0e 100755
--- a/src/com/floreantpos/config/ui/TerminalConfigurationView.java
+++ b/src/com/floreantpos/config/ui/TerminalConfigurationView.java
@@ -39,7 +39,7 @@ public class TerminalConfigurationView extends ConfigurationView {
 	private JCheckBox cbUseSettlementPrompt = new JCheckBox(Messages.getString("TerminalConfigurationView.4")); //$NON-NLS-1$
 	private JCheckBox cbShowDbConfiguration = new JCheckBox(Messages.getString("TerminalConfigurationView.5")); //$NON-NLS-1$
 	private JCheckBox cbAutoSaveOpen = new JCheckBox(Messages.getString("BARMOD_AutoSaveOpen.1")); //$NON-NLS-1$
-
+	private JCheckBox cbAutoTerminalID = new JCheckBox(Messages.getString("BARMOD_AutoTerminalID.1")); //$NON-NLS-1$

 	private JComboBox<String> cbFonts = new JComboBox<String>();

@@ -66,6 +66,9 @@ public class TerminalConfigurationView extends ConfigurationView {
 		JLabel lblTerminalNumber = new JLabel(Messages.getString("TerminalConfigurationView.TERMINAL_NUMBER")); //$NON-NLS-1$
 		add(lblTerminalNumber, "alignx left,aligny center"); //$NON-NLS-1$

+		add(cbAutoTerminalID,"newline, span"); //$NON-NLS-1$
+
+
 		tfTerminalNumber = new IntegerTextField();
 		tfTerminalNumber.setColumns(10);
 		add(tfTerminalNumber, "aligny top, wrap"); //$NON-NLS-1$
@@ -243,6 +246,8 @@ public class TerminalConfigurationView extends ConfigurationView {
 		TerminalConfig.setAutoLogoffTime(tfLogoffTime.getInteger() <= 0 ? 10 : tfLogoffTime.getInteger());

 		TerminalConfig.setAutoSaveOpen(cbAutoSaveOpen.isSelected());
+		TerminalConfig.setAutoTerminalID(cbAutoTerminalID.isSelected());
+

 		TerminalConfig.setUseSettlementPrompt(cbUseSettlementPrompt.isSelected());

@@ -291,6 +296,8 @@ public class TerminalConfigurationView extends ConfigurationView {
 		tfLogoffTime.setEnabled(cbAutoLogoff.isSelected());

 		cbAutoSaveOpen.setSelected(TerminalConfig.isAutoSaveOpen());
+		cbAutoTerminalID.setSelected(TerminalConfig.isAutoTerminalID());
+

 		initializeFontConfig();

diff --git a/src/com/floreantpos/getnetinfo/NetInfo.java b/src/com/floreantpos/getnetinfo/NetInfo.java
new file mode 100755
index 0000000..f26f3c8
--- /dev/null
+++ b/src/com/floreantpos/getnetinfo/NetInfo.java
@@ -0,0 +1,72 @@
+package com.floreantpos.getnetinfo;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+
+/* CREDIT: Taken from http://www.mkyong.com/java/how-to-get-mac-address-in-java/ */
+
+public class NetInfo {
+
+	 public static String getIPAddr(){
+
+			InetAddress ip;
+			try {
+
+				ip = InetAddress.getLocalHost();
+				return(ip.getHostAddress());
+
+			} catch (UnknownHostException e) {
+
+				//e.printStackTrace();
+
+			}
+		return(null);
+	 }
+
+	 public static String getMACAddr() {
+
+			InetAddress ip;
+			try {
+
+				ip = InetAddress.getLocalHost();
+
+				NetworkInterface network = NetworkInterface.getByInetAddress(ip);
+
+				byte[] mac = network.getHardwareAddress();
+
+				StringBuilder sb = new StringBuilder();
+				for (int i = 0; i < mac.length; i++) {
+					//sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
+					sb.append(String.format("%03d%s", mac[i], (i < mac.length - 1) ? "-" : ""));
+				}
+				return(sb.toString());
+
+			} catch (UnknownHostException e) {
+
+				//e.printStackTrace();
+
+			} catch (SocketException e){
+
+				//e.printStackTrace();
+
+			}
+
+			return(null);
+
+		   }
+
+	 public static int getTerminalIDFromMACAddr() {
+
+		 String mac=getMACAddr();
+	 	 String terminalID = null;
+		  if ( mac != null) {
+		 	 terminalID=mac.replace("-","");
+			 terminalID=terminalID.substring(terminalID.length() - 10);
+		 	} else return(-1);
+			return(Integer.parseInt(terminalID));
+		  }
+
+
+}

Add comment
These comments are moderated so so won't be published until reviewed.