if (!mgrLoggedIn) {
pos.showDialog("dialog/error/mgrnotloggedin");
return;
}
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
if (!trans.isOpen()) {
pos.showDialog("dialog/error/terminalclosed");
return;
}
Output output = pos.getOutput();
Input input = pos.getInput();
if (input.isFunctionSet("CLOSE")) {
String[] func = input.getFunction("CLOSE");
String lastValue = input.value();
if (UtilValidate.isNotEmpty(lastValue)) {
try {
BigDecimal amt = new BigDecimal(lastValue);
amt = amt.movePointLeft(2);
lastValue = amt.toString();
} catch (NumberFormatException e) {
Debug.logError(e, module);
}
if (UtilValidate.isNotEmpty(func[1])) {
func[1] = func[1] + "|";
}
func[1] = func[1] + lastValue;
input.setFunction("CLOSE", func[1]);
}
String[] closeInfo = new String[0];
if (UtilValidate.isNotEmpty(func[1])) {
closeInfo = func[1].split("\\|");
}
switch (closeInfo.length) {
case 0:
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntCas",Locale.getDefault()));
break;
case 1:
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntChk",Locale.getDefault()));
break;
case 2:
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntCrc",Locale.getDefault()));
break;
case 3:
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntGfc",Locale.getDefault()));
break;
case 4:
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntOth",Locale.getDefault()));
break;
case 5:
GenericValue state = trans.getTerminalState();
state.set("closedDate", UtilDateTime.nowTimestamp());
state.set("closedByUserLoginId", pos.getSession().getUserId());
state.set("actualEndingCash", new BigDecimal(closeInfo[0]));
state.set("actualEndingCheck", new BigDecimal(closeInfo[1]));
state.set("actualEndingCc", new BigDecimal(closeInfo[2]));
state.set("actualEndingGc", new BigDecimal(closeInfo[3]));
state.set("actualEndingOther", new BigDecimal(closeInfo[4]));
state.set("endingTxId", trans.getTransactionId());
Debug.log("Updated State - " + state, module);
try {
state.store();
state.refresh();
} catch (GenericEntityException e) {
Debug.logError(e, module);
pos.showDialog("dialog/error/exception", e.getMessage());
}
// print the totals report
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosWaitingFinalSales",Locale.getDefault()));
//pos.showDialog("dialog/error/terminalclosed"); JLR 14/11/06 : Pb with that don't know why, useless => commented out
printTotals(pos, state, true);
// lock the terminal for the moment
pos.getInput().setLock(true);
pos.getButtons().setLock(true);
pos.refresh(false);
// transmit final data to server
GenericValue terminal = null;
try {
terminal = state.getRelatedOne("PosTerminal");
} catch (GenericEntityException e) {
Debug.logError(e, module);
pos.showDialog("dialog/error/exception", e.getMessage());
}
if (terminal != null && terminal.get("pushEntitySyncId") != null) {
String syncId = terminal.getString("pushEntitySyncId");
SyncCallbackAdaptor cb = new SyncCallbackAdaptor(pos, syncId, state.getTimestamp("lastUpdatedTxStamp"));
pos.getSession().getDispatcher().registerCallback("runEntitySync", cb);
} else {
// no sync setting; just logout
SecurityEvents.logout(pos);
}
// unlock the terminal
pos.getInput().setLock(false);
pos.getButtons().setLock(false);
pos.refresh(true);
}
} else {
trans.popDrawer();
input.clear();
input.setFunction("CLOSE");
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosEntCas",Locale.getDefault()));
}
}