Skip to content

Commit

Permalink
Added new transaction, updated the edit page with less customer info,…
Browse files Browse the repository at this point in the history
… successful invoicing
  • Loading branch information
surajcm committed Jun 17, 2020
1 parent 3444b06 commit 9ed5eef
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 208 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/poseidon/invoice/dao/entities/Invoice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -132,6 +133,7 @@ public ModelAndView saveInvoice(final InvoiceForm invoiceForm) {
invoiceForm.setStatusMessageType(ERROR);
LOG.error(ex.getLocalizedMessage());
}
LOG.info("fetching invoice for listing....");
List<InvoiceVO> invoiceVOs;
try {
invoiceVOs = invoiceService.fetchInvoiceForListOfTransactions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public class TransactionDAOImpl implements TransactionDAO {
@PersistenceContext
private EntityManager em;

/**
* list all transactions.
*
* @return list of transactions
*/
@Override
public List<TransactionVO> listAllTransactions() throws TransactionException {
try {
List<Transaction> 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.
*/
Expand Down Expand Up @@ -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<TransactionVO> listAllTransactions() throws TransactionException {
try {
List<Transaction> 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.
*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<TransactionVO> transactionVOs = null;
try {
transactionVOs = transactionService.listAllTransactions();
Expand All @@ -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<MakeVO> getMakeVOS() {
List<MakeVO> 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<String> populateStatus() {
List<String> 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());
}

/**
Expand All @@ -116,15 +108,9 @@ private List<String> populateStatus() {
public ModelAndView addTxn(final TransactionForm transactionForm) {
LOG.info(" Inside AddTxn method of TransactionController ");
//get all the make list for displaying in search
List<MakeVO> makeVOs = null;
try {
makeVOs = makeService.fetchMakes();
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage());
}
List<MakeVO> makeVOs = getMakeVOS();
List<MakeAndModelVO> 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());
Expand Down Expand Up @@ -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<MakeVO> 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());
Expand All @@ -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<MakeVO> 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<MakeAndModelVO> makeAndModelVOs;
makeAndModelVOs = makeService.getAllModelsFromMakeId(transactionVO.getMakeId());
if (makeAndModelVOs != null) {
Expand Down Expand Up @@ -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<MakeVO> 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());
Expand Down Expand Up @@ -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<MakeVO> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.poseidon.transaction.web.controller;

public enum TransactionStatus {
NEW, ACCEPTED, VERIFIED, CLOSED, REJECTED, INVOICED
}
14 changes: 12 additions & 2 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
'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')
14 changes: 6 additions & 8 deletions src/main/resources/static/js/transaction-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 <span class='sr-only'>Transactions</span>";
}

Loading

0 comments on commit 9ed5eef

Please sign in to comment.