diff --git a/src/main/java/com/poseidon/invoice/dao/entities/Invoice.java b/src/main/java/com/poseidon/invoice/dao/entities/Invoice.java index 426cda80..be58afbe 100644 --- a/src/main/java/com/poseidon/invoice/dao/entities/Invoice.java +++ b/src/main/java/com/poseidon/invoice/dao/entities/Invoice.java @@ -5,8 +5,11 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; import javax.persistence.Table; import java.time.OffsetDateTime; +import java.time.ZoneId; @Entity //todo : add schema @@ -167,4 +170,16 @@ public String getModifiedBy() { public void setModifiedBy(final String modifiedBy) { this.modifiedBy = modifiedBy; } + + /** + * initialize / update date fields. + */ + @PrePersist + @PreUpdate + public void initializeDate() { + if (this.getInvoiceId() == null) { + createdOn = OffsetDateTime.now(ZoneId.systemDefault()); + } + modifiedOn = OffsetDateTime.now(ZoneId.systemDefault()); + } } diff --git a/src/main/java/com/poseidon/invoice/dao/impl/InvoiceDAOImpl.java b/src/main/java/com/poseidon/invoice/dao/impl/InvoiceDAOImpl.java index 719951e1..76bd365f 100644 --- a/src/main/java/com/poseidon/invoice/dao/impl/InvoiceDAOImpl.java +++ b/src/main/java/com/poseidon/invoice/dao/impl/InvoiceDAOImpl.java @@ -287,6 +287,8 @@ private Invoice convertInvoiceVOToInvoice(final InvoiceVO currentInvoiceVO) { invoice.setRate(String.valueOf(currentInvoiceVO.getRate())); invoice.setCustomerId(currentInvoiceVO.getCustomerId()); invoice.setCustomerName(currentInvoiceVO.getCustomerName()); + invoice.setCreatedBy(currentInvoiceVO.getCreatedBy()); + invoice.setModifiedBy(currentInvoiceVO.getModifiedBy()); return invoice; } } diff --git a/src/main/java/com/poseidon/invoice/web/controller/InvoiceController.java b/src/main/java/com/poseidon/invoice/web/controller/InvoiceController.java index 681bb27d..70b0bead 100644 --- a/src/main/java/com/poseidon/invoice/web/controller/InvoiceController.java +++ b/src/main/java/com/poseidon/invoice/web/controller/InvoiceController.java @@ -113,9 +113,10 @@ public ModelAndView saveInvoice(final InvoiceForm invoiceForm) { } catch (TransactionException ex) { LOG.error(ex.getLocalizedMessage()); } - + LOG.info("Found transactions :" + transactionVOs.size()); if (transactionVOs != null && !transactionVOs.isEmpty()) { invoiceService.addInvoice(invoiceForm.getCurrentInvoiceVo()); + LOG.info("Successfully saved the new invoice Detail"); invoiceForm.setStatusMessage("Successfully saved the new invoice Detail"); invoiceForm.setStatusMessageType("success"); //update the transaction @@ -132,6 +133,7 @@ public ModelAndView saveInvoice(final InvoiceForm invoiceForm) { invoiceForm.setStatusMessageType(ERROR); LOG.error(ex.getLocalizedMessage()); } + LOG.info("fetching invoice for listing...."); List invoiceVOs; try { invoiceVOs = invoiceService.fetchInvoiceForListOfTransactions(); diff --git a/src/main/java/com/poseidon/transaction/dao/impl/TransactionDAOImpl.java b/src/main/java/com/poseidon/transaction/dao/impl/TransactionDAOImpl.java index 0f92724d..c44fed11 100644 --- a/src/main/java/com/poseidon/transaction/dao/impl/TransactionDAOImpl.java +++ b/src/main/java/com/poseidon/transaction/dao/impl/TransactionDAOImpl.java @@ -53,6 +53,22 @@ public class TransactionDAOImpl implements TransactionDAO { @PersistenceContext private EntityManager em; + /** + * list all transactions. + * + * @return list of transactions + */ + @Override + public List listAllTransactions() throws TransactionException { + try { + List transactions = transactionRepository.findAll(); + return transactions.stream().map(this::convertToVO).collect(Collectors.toList()); + } catch (Exception ex) { + LOG.error(ex.getLocalizedMessage()); + throw new TransactionException(TransactionException.DATABASE_ERROR); + } + } + /** * list today's transactions. */ @@ -182,22 +198,6 @@ public void updateTransactionStatus(final Long id, final String status) throws T } } - /** - * list all transactions. - * - * @return list of transactions - */ - @Override - public List listAllTransactions() throws TransactionException { - try { - List transactions = transactionRepository.findAll(); - return transactions.stream().map(this::convertToVO).collect(Collectors.toList()); - } catch (Exception ex) { - LOG.error(ex.getLocalizedMessage()); - throw new TransactionException(TransactionException.DATABASE_ERROR); - } - } - /** * search transactions. * @@ -366,7 +366,7 @@ private TransactionVO convertToVO(final Transaction txn) { transactionVO.setAccessories(txn.getAccessories()); transactionVO.setComplaintReported(txn.getComplaintReported()); transactionVO.setComplaintDiagonsed(txn.getComplaintDiagnosed()); - transactionVO.setEndDate(txn.getEngineerRemarks()); + transactionVO.setEnggRemark(txn.getEngineerRemarks()); transactionVO.setRepairAction(txn.getRepairAction()); transactionVO.setNotes(txn.getNote()); return transactionVO; diff --git a/src/main/java/com/poseidon/transaction/web/controller/TransactionController.java b/src/main/java/com/poseidon/transaction/web/controller/TransactionController.java index eb2e8f4e..2d0651c9 100644 --- a/src/main/java/com/poseidon/transaction/web/controller/TransactionController.java +++ b/src/main/java/com/poseidon/transaction/web/controller/TransactionController.java @@ -24,7 +24,7 @@ import java.io.PrintWriter; import java.time.OffsetDateTime; import java.time.ZoneId; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -65,8 +65,6 @@ public class TransactionController { */ @PostMapping("/txs/List.htm") public ModelAndView list(final TransactionForm transactionForm) { - LOG.info(" Inside List method of TransactionController "); - LOG.info(" form details are {}", transactionForm); List transactionVOs = null; try { transactionVOs = transactionService.listAllTransactions(); @@ -78,32 +76,26 @@ public ModelAndView list(final TransactionForm transactionForm) { transactionForm.setTransactionsList(transactionVOs); } //get all the make list for displaying in search + transactionForm.setMakeVOs(getMakeVOS()); + transactionForm.setSearchTransaction(new TransactionVO()); + transactionForm.setLoggedInRole(transactionForm.getLoggedInRole()); + transactionForm.setLoggedInUser(transactionForm.getLoggedInUser()); + transactionForm.setStatusList(populateStatus()); + return new ModelAndView(TRANSACTION_LIST, TRANSACTION_FORM, transactionForm); + } + + private List getMakeVOS() { List makeVOs = null; try { makeVOs = makeService.fetchMakes(); } catch (Exception ex) { LOG.error(ex.getMessage()); } - if (makeVOs != null) { - makeVOs.stream().map(makeVO -> "make vo is" + makeVO).forEach(LOG::info); - transactionForm.setMakeVOs(makeVOs); - } - transactionForm.setSearchTransaction(new TransactionVO()); - transactionForm.setLoggedInRole(transactionForm.getLoggedInRole()); - transactionForm.setLoggedInUser(transactionForm.getLoggedInUser()); - transactionForm.setStatusList(populateStatus()); - return new ModelAndView(TRANSACTION_LIST, TRANSACTION_FORM, transactionForm); + return makeVOs; } private List populateStatus() { - List statusList = new ArrayList<>(); - statusList.add("NEW"); - statusList.add("ACCEPTED"); - statusList.add("VERIFIED"); - statusList.add("CLOSED"); - statusList.add("REJECTED"); - statusList.add("INVOICED"); - return statusList; + return Arrays.stream(TransactionStatus.values()).map(Enum::name).collect(Collectors.toList()); } /** @@ -116,15 +108,9 @@ private List populateStatus() { public ModelAndView addTxn(final TransactionForm transactionForm) { LOG.info(" Inside AddTxn method of TransactionController "); //get all the make list for displaying in search - List makeVOs = null; - try { - makeVOs = makeService.fetchMakes(); - } catch (Exception ex) { - LOG.error(ex.getLocalizedMessage()); - } + List makeVOs = getMakeVOS(); List makeAndModelVOs = null; if (makeVOs != null && !makeVOs.isEmpty()) { - makeVOs.stream().map(makeVO -> "make vo is" + makeVO).forEach(LOG::info); transactionForm.setMakeVOs(makeVOs); LOG.info("The selected make id is {}", makeVOs.get(0).getId()); makeAndModelVOs = makeService.getAllModelsFromMakeId(makeVOs.get(0).getId()); @@ -235,17 +221,7 @@ public ModelAndView searchTxn(final TransactionForm transactionForm) { transactionVOs.forEach(transactionVO -> LOG.debug(TRANSACTION_VO, transactionVO)); transactionForm.setTransactionsList(transactionVOs); } - //get all the make list for displaying in search - List makeVOs = null; - try { - makeVOs = makeService.fetchMakes(); - } catch (Exception ex) { - LOG.error(ex.getLocalizedMessage()); - } - if (makeVOs != null) { - makeVOs.forEach(makeVO -> LOG.debug(MAKE_VO, makeVO)); - transactionForm.setMakeVOs(makeVOs); - } + transactionForm.setMakeVOs(getMakeVOS()); transactionForm.setLoggedInRole(transactionForm.getLoggedInRole()); transactionForm.setLoggedInUser(transactionForm.getLoggedInUser()); transactionForm.setStatusList(populateStatus()); @@ -270,16 +246,7 @@ public ModelAndView editTxn(final TransactionForm transactionForm) { customerVO = customerService.getCustomerFromId(transactionVO.getCustomerId()); } if (transactionVO != null && transactionVO.getMakeId() != null && transactionVO.getMakeId() > 0) { - List makeVOs = null; - try { - makeVOs = makeService.fetchMakes(); - } catch (Exception ex) { - LOG.error(ex.getLocalizedMessage()); - } - if (makeVOs != null) { - makeVOs.forEach(makeVO -> LOG.info(MAKE_VO, makeVO)); - transactionForm.setMakeVOs(makeVOs); - } + transactionForm.setMakeVOs(getMakeVOS()); List makeAndModelVOs; makeAndModelVOs = makeService.getAllModelsFromMakeId(transactionVO.getMakeId()); if (makeAndModelVOs != null) { @@ -349,17 +316,7 @@ public ModelAndView updateTxn(final TransactionForm transactionForm) { transactionVOs.forEach(transactionVO -> LOG.info(TRANSACTION_VO, transactionVO)); transactionForm.setTransactionsList(transactionVOs); } - //get all the make list for displaying in search - List makeVOs = null; - try { - makeVOs = makeService.fetchMakes(); - } catch (Exception ex) { - LOG.error(ex.getLocalizedMessage()); - } - if (makeVOs != null) { - makeVOs.forEach(makeVO -> LOG.info(MAKE_VO, makeVO)); - transactionForm.setMakeVOs(makeVOs); - } + transactionForm.setMakeVOs(getMakeVOS()); transactionForm.setSearchTransaction(new TransactionVO()); transactionForm.setLoggedInRole(transactionForm.getLoggedInRole()); transactionForm.setLoggedInUser(transactionForm.getLoggedInUser()); @@ -407,17 +364,7 @@ public ModelAndView deleteTxn(final TransactionForm transactionForm) { transactionVOs.forEach(transactionVO -> LOG.info(TRANSACTION_VO, transactionVO)); transactionForm.setTransactionsList(transactionVOs); } - //get all the make list for displaying in search - List makeVOs = null; - try { - makeVOs = makeService.fetchMakes(); - } catch (Exception ex) { - LOG.error(ex.getLocalizedMessage()); - } - if (makeVOs != null) { - makeVOs.forEach(makeVO -> LOG.info(MAKE_VO, makeVO)); - transactionForm.setMakeVOs(makeVOs); - } + transactionForm.setMakeVOs(getMakeVOS()); transactionForm.setSearchTransaction(new TransactionVO()); transactionForm.setLoggedInRole(transactionForm.getLoggedInRole()); transactionForm.setLoggedInUser(transactionForm.getLoggedInUser()); diff --git a/src/main/java/com/poseidon/transaction/web/controller/TransactionStatus.java b/src/main/java/com/poseidon/transaction/web/controller/TransactionStatus.java new file mode 100644 index 00000000..11fd0fc6 --- /dev/null +++ b/src/main/java/com/poseidon/transaction/web/controller/TransactionStatus.java @@ -0,0 +1,5 @@ +package com.poseidon.transaction.web.controller; + +public enum TransactionStatus { + NEW, ACCEPTED, VERIFIED, CLOSED, REJECTED, INVOICED +} diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index f7b07c87..d7bbc611 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -41,7 +41,10 @@ insert into model (id, modelName, makeId, createdOn, modifiedOn, createdBy, modi (2, 'MacBook Air', 1 ,'2019-08-01 00:00:00','2019-08-01 09:23:00','admin','admin'); insert into model (id, modelName, makeId, createdOn, modifiedOn, createdBy, modifiedBy) values -(3, 'ThinkPad', 3 ,'2019-08-01 00:00:00','2019-08-01 09:25:00','admin','admin'); +(3, 'Inspiron', 2 ,'2019-08-01 00:00:00','2019-08-01 09:23:00','admin','admin'); + +insert into model (id, modelName, makeId, createdOn, modifiedOn, createdBy, modifiedBy) values +(4, 'ThinkPad', 3 ,'2019-08-01 00:00:00','2019-08-01 09:25:00','admin','admin'); insert into customer (id, name, address1, address2, phone, mobile, email,createdBy, createdOn, modifiedBy, modifiedOn) values (1, 'John Wick', '5630 N Sheridan', 'Chicago', '0404 232323', '555888999', 'test@testmail.com', @@ -75,4 +78,11 @@ insert into transaction (id, tagNo, dateReported, customerId, productCategory, m createdBy, createdOn, modifiedBy, modifiedOn) values (1, 'WON2N1', '2020-06-15 00:00:00', 1 , 'LAPTOP', 1, 1, 'AEPEP88990', 'Charger', 'Startup failure', 'Battery connectivity', 'Power circuit broken', 'Replace Board', 'Purchase new board', 'ACCEPTED', - 'admin', '2020-06-15 00:00:00', 'admin', '2020-06-15 00:00:00') \ No newline at end of file + 'admin', '2020-06-15 00:00:00', 'admin', '2020-06-15 00:00:00') + +insert into transaction (id, tagNo, dateReported, customerId, productCategory, makeId, modelId, + serialNo, accessories, complaintReported, complaintDiagnosed, engineerRemarks, repairAction, note, status, + createdBy, createdOn, modifiedBy, modifiedOn) values (2, 'WON2N2', '2020-06-16 00:00:00', 2 , 'LAPTOP', 1, 2, + 'PQRS12345', 'Charger', 'Display failure', 'Display connectivity', 'Display circuit broken', + 'Replace Board', 'Purchase new board', 'VERIFIED', + 'admin', '2020-06-16 00:00:00', 'admin', '2020-06-16 00:00:00') \ No newline at end of file diff --git a/src/main/resources/static/js/transaction-scripts.js b/src/main/resources/static/js/transaction-scripts.js index 6566fda7..516331fd 100644 --- a/src/main/resources/static/js/transaction-scripts.js +++ b/src/main/resources/static/js/transaction-scripts.js @@ -14,10 +14,12 @@ function checkCall(e) { } } } + function search() { document.forms[0].action = "SearchTxn.htm"; document.forms[0].submit(); } + function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); } @@ -234,27 +236,23 @@ function invoiceTxn() { } function invoiceRow() { - var userRow; var checks = document.getElementsByName('checkField'); if (checks.checked) { userRow = document.getElementById("myTable").rows[0]; - document.getElementById("id").value = userRow.cells[0].childNodes[0].value; - document.forms[0].action="${contextPath}/invoice/InvoiceTxn.htm"; - document.forms[0].submit(); } else { for (var i = 0; i < checks.length; i++) { if (checks[i].checked) { userRow = document.getElementById("myTable").rows[i + 1]; } } - document.getElementById("id").value = userRow.cells[0].childNodes[0].value; - document.forms[0].action="${contextPath}/invoice/InvoiceTxn.htm"; - document.forms[0].submit(); } + document.getElementById("id").value = userRow.cells[0].childNodes[0].value; + document.forms[0].action="/invoice/InvoiceTxn.htm"; + document.forms[0].submit(); } -function hideAlerts(){ +function hideAlerts() { document.getElementById('txnmgt').text = "Transactions Transactions"; } diff --git a/src/main/webapp/txs/TxnAdd.jsp b/src/main/webapp/txs/TxnAdd.jsp index 241d2927..f6aaecdb 100644 --- a/src/main/webapp/txs/TxnAdd.jsp +++ b/src/main/webapp/txs/TxnAdd.jsp @@ -141,57 +141,6 @@ - - - - - - - -   - - - - - - -   - - - - - - - - -   - - - - - - -   - - - - - - -   diff --git a/src/main/webapp/txs/TxnEdit.jsp b/src/main/webapp/txs/TxnEdit.jsp index b9cf4225..be5bdbb2 100644 --- a/src/main/webapp/txs/TxnEdit.jsp +++ b/src/main/webapp/txs/TxnEdit.jsp @@ -150,59 +150,6 @@ id="email" readonly="true"/> - - - - - - - -   - - - - - - -   - - - - - - - - -   - - - - - - -   - - - - - - -   @@ -252,7 +199,6 @@ - @@ -260,7 +206,6 @@   - @@ -268,7 +213,6 @@   - @@ -277,7 +221,6 @@ - @@ -285,7 +228,6 @@   - @@ -293,7 +235,6 @@   -