r306 - in trunk: magalie-services/src/main/java/com/franciaflex/magalie/services/service magalie-web/src/main/java/com/franciaflex/magalie/web/action magalie-web/src/main/webapp/WEB-INF/content magalie-web/src/main/webapp/js
Author: bleny Date: 2013-07-12 22:31:14 +0200 (Fri, 12 Jul 2013) New Revision: 306 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: fix withdraw-item-input workflow, renable find ordre to execute in RequestedArticleService Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RealTimeStorageMovementTask.java trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/WithdrawItemAction.java trunk/magalie-web/src/main/webapp/WEB-INF/content/withdraw-item-input.jsp trunk/magalie-web/src/main/webapp/js/withdraw-item-input.js Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RealTimeStorageMovementTask.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RealTimeStorageMovementTask.java 2013-07-12 17:43:32 UTC (rev 305) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RealTimeStorageMovementTask.java 2013-07-12 20:31:14 UTC (rev 306) @@ -40,4 +40,8 @@ } return driverLicenseRequired; } + + public boolean isSuccess() { + return storedArticle != null; + } } Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java 2013-07-12 17:43:32 UTC (rev 305) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/RequestedArticleService.java 2013-07-12 20:31:14 UTC (rev 306) @@ -52,6 +52,7 @@ import java.util.Collection; import java.util.Comparator; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -98,194 +99,173 @@ protected FindOrderToExecuteResult findOrderToExecute(Set<RequestedArticle> requestedArticlesByPriority, MagalieUser magalieUser, Building building) { - throw new UnsupportedOperationException(); + ArticleStorageService articleStorageService = + serviceContext.newService(ArticleStorageService.class); -// ArticleStorageService articleStorageService = -// serviceContext.newService(ArticleStorageService.class); -// -// BookArticleResult bookArticleResult = null; -// -// RequestedArticle requestedArticle = null; -// -// boolean success = false; -// -// Iterator<RequestedArticle> requestedArticleIterator = requestedArticlesByPriority.iterator(); -// -// boolean driverLicenseRequired = false; -// -// boolean somethingIsAvailable = false; -// -// while (!success && requestedArticleIterator.hasNext()) { -// -// requestedArticle = requestedArticleIterator.next(); -// -// Article article = requestedArticle.getArticle(); -// -// double quantity = requestedArticle.getQuantity(); -// -// Location destinationLocation = requestedArticle.getDestinationLocation(); -// -// BookArticleRequest bookArticleRequest = new BookArticleRequest(magalieUser, building, article, quantity, destinationLocation, false); -// -// // bookArticleResult = articleStorageService.bookArticle(bookArticleRequest); -// -// boolean articleIsAvailable = !bookArticleResult.isArticleUnavailable(); -// -// if (articleIsAvailable) { -// -// somethingIsAvailable = true; -// -// driverLicenseRequired |= bookArticleResult.isArticleInaccessible(); -// -// } -// -// success = bookArticleResult.isSuccess(); -// -// } -// -// FindOrderToExecuteResult findOrderToExecuteResult = new FindOrderToExecuteResult(); -// -// if (success) { -// -// if (log.isInfoEnabled()) { -// log.info("order to execute found: " + requestedArticle); -// } -// -// Preconditions.checkState(requestedArticle != null); -// -// JpaMagaliePersistenceContext persistenceContext = serviceContext.getPersistenceContext(); -// -// DeliveredRequestedArticleJpaDao dao = persistenceContext.getDeliveredRequestedArticleDao(); -// -// DeliveredRequestedArticle newDeliveredRequestedArticle = new DeliveredRequestedArticle(); -// -// newDeliveredRequestedArticle.setRequestedArticle(requestedArticle); -// -// StorageMovementOrder storageMovementOrder = bookArticleResult.getStorageMovementOrder(); -// -// // newDeliveredRequestedArticle.setStorageMovementOrder(storageMovementOrder); -// -// dao.persist(newDeliveredRequestedArticle); -// -// findOrderToExecuteResult.setStorageMovementOrder(storageMovementOrder); -// -// // deal with affectations -// DeliveredRequestedListJpaDao deliveredRequestedListDao = -// persistenceContext.getDeliveredRequestedListDao(); -// -// DeliveredRequestedList oldAffectation = -// deliveredRequestedListDao.findByAffectedTo(magalieUser); -// -// RequestedList requestedList = requestedArticle.getRequestedList(); -// -// DeliveredRequestedList newAffectation = -// deliveredRequestedListDao.findByRequestedList(requestedList); -// -// if (newAffectation == null) { -// -// newAffectation = new DeliveredRequestedList(); -// -// deliveredRequestedListDao.persist(newAffectation); -// -// } -// -// newAffectation.setAffectedTo(magalieUser); -// -// newAffectation.setRequestedList(requestedList); -// -// newAffectation.setStatus(DeliveredRequestedListStatus.AFFECTED); -// -// deliveredRequestedListDao.merge(newAffectation); -// -// if (oldAffectation == null) { -// -// if (log.isInfoEnabled()) { -// log.info("user has no previous affectation"); -// } -// -// findOrderToExecuteResult.setNewAffectation(newAffectation); -// -// } else { -// -// if (log.isInfoEnabled()) { -// log.info("user is affected to " + oldAffectation.getRequestedList().getCode()); -// } -// -// boolean affectationChanged = !oldAffectation.getRequestedList().equals(requestedList); -// -// if (affectationChanged) { -// -// if (log.isInfoEnabled()) { -// log.info("user changed affectation from " -// + oldAffectation.getRequestedList().getCode() -// + " to " + requestedList.getCode()); -// } -// -// boolean isFinished = oldAffectation.getStatus().equals(DeliveredRequestedListStatus.COMPLETE); -// -// if (!isFinished) { -// -// if (log.isInfoEnabled()) { -// log.info("request list " + oldAffectation.getRequestedList() -// + " is not complete, putting it back to pending"); -// } -// -// oldAffectation.setStatus(DeliveredRequestedListStatus.PENDING); -// -// oldAffectation.setAffectedTo(null); -// -// } -// -// findOrderToExecuteResult.setOldAffectation(oldAffectation); -// -// findOrderToExecuteResult.setNewAffectation(newAffectation); -// -// } -// -// } -// -// persistenceContext.commit(); -// -// } else { -// -// if (requestedArticlesByPriority.isEmpty()) { -// -// if (log.isInfoEnabled()) { -// log.info("no order to execute found: nothing to do"); -// } -// -// findOrderToExecuteResult.setNothingToDo(true); -// -// } else { -// -// if (somethingIsAvailable) { -// -// if (log.isInfoEnabled()) { -// log.info("no order to execute found: there is something available to do but driver license is required"); -// } -// -// Preconditions.checkState(driverLicenseRequired); -// -// findOrderToExecuteResult.setDriverLicenseRequired(driverLicenseRequired); -// -// } else { -// -// if (log.isInfoEnabled()) { -// log.info("no order to execute found: everything is unavailable"); -// } -// -// Preconditions.checkState(!driverLicenseRequired); -// -// findOrderToExecuteResult.setEverythingUnavailable(true); -// -// } -// -// } -// -// } -// -// return findOrderToExecuteResult; + RequestedArticle requestedArticle = null; + boolean success = false; + + Iterator<RequestedArticle> requestedArticleIterator = requestedArticlesByPriority.iterator(); + + boolean driverLicenseRequired = false; + + boolean somethingIsAvailable = false; + + while ( ! success && requestedArticleIterator.hasNext()) { + + requestedArticle = requestedArticleIterator.next(); + + String articleId = requestedArticle.getArticle().getId(); + + RealTimeStorageMovementTask realTimeStorageMovementTask = + articleStorageService.getRealTimeStorageMovementTask(building, magalieUser, articleId); + + boolean articleIsAvailable = ! realTimeStorageMovementTask.isArticleUnavailable(); + + if (articleIsAvailable) { + + somethingIsAvailable = true; + + driverLicenseRequired |= realTimeStorageMovementTask.isDriverLicenseRequired(); + + } + + success = realTimeStorageMovementTask.isSuccess(); + + } + + FindOrderToExecuteResult findOrderToExecuteResult = new FindOrderToExecuteResult(); + + if (success) { + + if (log.isInfoEnabled()) { + log.info("order to execute found: " + requestedArticle); + } + + Preconditions.checkState(requestedArticle != null); + + JpaMagaliePersistenceContext persistenceContext = serviceContext.getPersistenceContext(); + + findOrderToExecuteResult.setRequestedArticle(requestedArticle); + + // deal with affectations + DeliveredRequestedListJpaDao deliveredRequestedListDao = + persistenceContext.getDeliveredRequestedListDao(); + + DeliveredRequestedList oldAffectation = + deliveredRequestedListDao.findByAffectedTo(magalieUser); + + RequestedList requestedList = requestedArticle.getRequestedList(); + + DeliveredRequestedList newAffectation = + deliveredRequestedListDao.findByRequestedList(requestedList); + + if (newAffectation == null) { + + newAffectation = new DeliveredRequestedList(); + + deliveredRequestedListDao.persist(newAffectation); + + } + + newAffectation.setAffectedTo(magalieUser); + + newAffectation.setRequestedList(requestedList); + + newAffectation.setStatus(DeliveredRequestedListStatus.AFFECTED); + + deliveredRequestedListDao.merge(newAffectation); + + if (oldAffectation == null) { + + if (log.isInfoEnabled()) { + log.info("user has no previous affectation"); + } + + findOrderToExecuteResult.setNewAffectation(newAffectation); + + } else { + + if (log.isInfoEnabled()) { + log.info("user is affected to " + oldAffectation.getRequestedList().getCode()); + } + + boolean affectationChanged = !oldAffectation.getRequestedList().equals(requestedList); + + if (affectationChanged) { + + if (log.isInfoEnabled()) { + log.info("user changed affectation from " + + oldAffectation.getRequestedList().getCode() + + " to " + requestedList.getCode()); + } + + boolean isFinished = oldAffectation.getStatus().equals(DeliveredRequestedListStatus.COMPLETE); + + if (!isFinished) { + + if (log.isInfoEnabled()) { + log.info("request list " + oldAffectation.getRequestedList() + + " is not complete, putting it back to pending"); + } + + oldAffectation.setStatus(DeliveredRequestedListStatus.PENDING); + + oldAffectation.setAffectedTo(null); + + } + + findOrderToExecuteResult.setOldAffectation(oldAffectation); + + findOrderToExecuteResult.setNewAffectation(newAffectation); + + } + + } + + persistenceContext.commit(); + + } else { + + if (requestedArticlesByPriority.isEmpty()) { + + if (log.isInfoEnabled()) { + log.info("no order to execute found: nothing to do"); + } + + findOrderToExecuteResult.setNothingToDo(true); + + } else { + + if (somethingIsAvailable) { + + if (log.isInfoEnabled()) { + log.info("no order to execute found: there is something available to do but driver license is required"); + } + + Preconditions.checkState(driverLicenseRequired); + + findOrderToExecuteResult.setDriverLicenseRequired(driverLicenseRequired); + + } else { + + if (log.isInfoEnabled()) { + log.info("no order to execute found: everything is unavailable"); + } + + Preconditions.checkState(!driverLicenseRequired); + + findOrderToExecuteResult.setEverythingUnavailable(true); + + } + + } + + } + + return findOrderToExecuteResult; + } protected Set<RequestedArticle> getRequestedArticlesByPriority(List<RequestedArticle> requests, MagalieUser magalieUser) { Modified: trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/WithdrawItemAction.java =================================================================== --- trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/WithdrawItemAction.java 2013-07-12 17:43:32 UTC (rev 305) +++ trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/WithdrawItemAction.java 2013-07-12 20:31:14 UTC (rev 306) @@ -98,6 +98,10 @@ this.requestedArticleService = requestedArticleService; } + public void setRequestedArticleId(String requestedArticleId) { + this.requestedArticleId = requestedArticleId; + } + @Override public void prepare() { Modified: trunk/magalie-web/src/main/webapp/WEB-INF/content/withdraw-item-input.jsp =================================================================== --- trunk/magalie-web/src/main/webapp/WEB-INF/content/withdraw-item-input.jsp 2013-07-12 17:43:32 UTC (rev 305) +++ trunk/magalie-web/src/main/webapp/WEB-INF/content/withdraw-item-input.jsp 2013-07-12 20:31:14 UTC (rev 306) @@ -63,10 +63,12 @@ <s:url action="withdraw-item!cancel" id="cancelUrl" > <%--s:param name="storageMovementOrderId" value="%{storageMovementOrderId}" /--%> </s:url> - <s:a href="%{cancelUrl}" cssClass="btn btn-small" id="cancelLink" >Quitter (Esc)</s:a> - <input type="button" id="reportError" value="Anomalie (F5)" class="btn btn-danger btn-small" /> - <input type="button" id="next" value="Suivant" class="btn btn-primary btn-small" /> - <s:submit name="confirm" value="Terminer" cssClass="btn btn-success btn-small" /> + <s:a href="%{cancelUrl}" cssClass="btn btn-mini" id="cancelLink" >Abandon (Esc)</s:a> + <div style="display: none"> + <input type="button" id="reportError" value="Ano. (F5)" class="btn btn-danger btn-mini" /> + </div> + <s:submit name="next" value="Suivant (⏎)" cssClass="btn btn-primary btn-mini" /> + <input type="button" id="confirm" value="Terminer (F4)" class="btn btn-success btn-mini" /> </div> </s:form> <div id="storageMovementTemplate" class="template"> Modified: trunk/magalie-web/src/main/webapp/js/withdraw-item-input.js =================================================================== --- trunk/magalie-web/src/main/webapp/js/withdraw-item-input.js 2013-07-12 17:43:32 UTC (rev 305) +++ trunk/magalie-web/src/main/webapp/js/withdraw-item-input.js 2013-07-12 20:31:14 UTC (rev 306) @@ -101,7 +101,11 @@ if (storageMovement.articleUnavailable) { alert('Pas de stock'); } else { - storageMovement.expectedQuantity = Math.min(model.remaining(), storageMovement.storedArticle.quantity); + if (this.expectedQuantity) { + storageMovement.expectedQuantity = Math.min(model.remaining(), storageMovement.storedArticle.quantity); + } else { + storageMovement.expectedQuantity = storageMovement.storedArticle.quantity; + } this.storageMovements.push(storageMovement); this.storageMovementsIndex += 1; } @@ -230,19 +234,19 @@ } }, - refreshButtons : function() { - if (model.allowSubmit) { - $('#withdraw-item_next').val('Terminer').removeClass('btn-primary').addClass('btn-success'); - } else { - $('#withdraw-item_next').val('Suivant').removeClass('btn-success').addClass('btn-primary'); - } - }, +// refreshButtons : function() { +// if (model.allowSubmit) { +// $('#withdraw-item_next').val('Terminer').removeClass('btn-primary').addClass('btn-success'); +// } else { +// $('#withdraw-item_next').val('Suivant').removeClass('btn-success').addClass('btn-primary'); +// } +// }, refresh : function() { this.refreshSummary(); this.refreshLocations(); this.refreshForm(); - this.refreshButtons(); +// this.refreshButtons(); $('#withdraw-item_locationBarcode').focus(); } @@ -265,7 +269,9 @@ model.withdraw(barcode, quantity); - model.newEmptyStorageMovementForNextLocation(); + if (model.expectedQuantity && model.withdrawn() < model.expectedQuantity) { + model.newEmptyStorageMovementForNextLocation(); + } view.refresh(); @@ -291,8 +297,6 @@ model.reportError(barcode); - model.newEmptyStorageMovementForNextLocation(); - view.refresh(); } catch (ex) { @@ -305,13 +309,29 @@ } }, - onSubmit : function(e) { + onConfirm : function() { // push model as Json in a hidden field $('#withdraw-item_confirmation').val(JSON.stringify(model.getConfirmation())); + model.forceConfirm = true; + + $('#withdraw-item').submit(); + }, + onSubmit : function(e) { + + if (model.forceConfirm) { + + } else { + + e.preventDefault(); + + } + + } + }; // bindings @@ -319,8 +339,9 @@ $('#withdraw-item').submit(controller.onSubmit); $('#reportError').click(controller.onReportError); $('#reportCancel').click(controller.onCancel); - $('#next').click(controller.onNext); - // $('#withdraw-item_confirm').click(controller.confirm); + $('#withdraw-item_next').click(controller.onNext); + $('#confirm').click(controller.onConfirm); + bindKey('F4', controller.onConfirm); bindKey('F5', controller.onReportError); bindKey('Esc', function(){ redirectTo($('#cancelLink'));}); controller.onShowFirstLocation();
participants (1)
-
bleny@users.forge.codelutin.com