| Line 12... |
Line 12... |
| 12 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 13 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| 14 |
|
14 |
|
| 15 |
import javax.servlet.http.HttpServletRequest;
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 16 |
import javax.servlet.http.HttpServletResponse;
|
16 |
import javax.servlet.http.HttpServletResponse;
|
| 17 |
import javax.transaction.Transactional;
|
- |
|
| 18 |
|
17 |
|
| 19 |
import org.json.JSONObject;
|
18 |
import org.json.JSONObject;
|
| 20 |
import org.slf4j.Logger;
|
19 |
import org.slf4j.Logger;
|
| 21 |
import org.slf4j.LoggerFactory;
|
20 |
import org.slf4j.LoggerFactory;
|
| 22 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| Line 24... |
Line 23... |
| 24 |
import org.springframework.http.HttpHeaders;
|
23 |
import org.springframework.http.HttpHeaders;
|
| 25 |
import org.springframework.http.HttpStatus;
|
24 |
import org.springframework.http.HttpStatus;
|
| 26 |
import org.springframework.http.MediaType;
|
25 |
import org.springframework.http.MediaType;
|
| 27 |
import org.springframework.http.ResponseEntity;
|
26 |
import org.springframework.http.ResponseEntity;
|
| 28 |
import org.springframework.stereotype.Controller;
|
27 |
import org.springframework.stereotype.Controller;
|
| - |
|
28 |
import org.springframework.transaction.annotation.Transactional;
|
| 29 |
import org.springframework.ui.Model;
|
29 |
import org.springframework.ui.Model;
|
| 30 |
import org.springframework.web.bind.annotation.RequestBody;
|
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 33 |
import org.springframework.web.bind.annotation.RequestParam;
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
| Line 151... |
Line 151... |
| 151 |
@Autowired
|
151 |
@Autowired
|
| 152 |
CookiesFetcher cookiesFetcher;
|
152 |
CookiesFetcher cookiesFetcher;
|
| 153 |
|
153 |
|
| 154 |
@RequestMapping(value = "/order")
|
154 |
@RequestMapping(value = "/order")
|
| 155 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
155 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| 156 |
FofoDetails fofoDetails;
|
- |
|
| 157 |
try {
|
156 |
try {
|
| 158 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
157 |
cookiesFetcher.getCookiesObject(request);
|
| 159 |
} catch (ProfitMandiBusinessException e) {
|
158 |
} catch (ProfitMandiBusinessException e) {
|
| 160 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
159 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| 161 |
return "response";
|
160 |
return "response";
|
| 162 |
}
|
161 |
}
|
| 163 |
JSONObject cartObject = new JSONObject(cartData);
|
162 |
JSONObject cartObject = new JSONObject(cartData);
|
| Line 222... |
Line 221... |
| 222 |
return null;
|
221 |
return null;
|
| 223 |
}
|
222 |
}
|
| 224 |
|
223 |
|
| 225 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
224 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 226 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{
|
225 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{
|
| 227 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
- |
|
| 228 |
LOGGER.info("/order request {}", createOrderRequest);
|
226 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 229 |
FofoDetails fofoDetails;
|
227 |
FofoDetails fofoDetails;
|
| 230 |
try {
|
228 |
try {
|
| 231 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
229 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 232 |
} catch (ProfitMandiBusinessException e) {
|
230 |
} catch (ProfitMandiBusinessException e) {
|
| 233 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
231 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| Line 495... |
Line 493... |
| 495 |
return "error";
|
493 |
return "error";
|
| 496 |
}
|
494 |
}
|
| 497 |
|
495 |
|
| 498 |
Customer customer = null;
|
496 |
Customer customer = null;
|
| 499 |
try{
|
497 |
try{
|
| 500 |
//TODO:remove email id
|
- |
|
| 501 |
customer = customerRepository.selectByMobileNumber(customCustomer.getMobileNumber());
|
498 |
customer = customerRepository.selectByMobileNumber(customCustomer.getMobileNumber());
|
| 502 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
499 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 503 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
500 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 504 |
customer = new Customer();
|
501 |
customer = new Customer();
|
| 505 |
customer.setName(customCustomer.getName());
|
502 |
customer.setName(customCustomer.getName());
|
| Line 510... |
Line 507... |
| 510 |
//TODO:Check if createOrderRequest contains addressId
|
507 |
//TODO:Check if createOrderRequest contains addressId
|
| 511 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
508 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
| 512 |
customerAddress.setCustomerId(customer.getId());
|
509 |
customerAddress.setCustomerId(customer.getId());
|
| 513 |
customerAddressRepository.persist(customerAddress);
|
510 |
customerAddressRepository.persist(customerAddress);
|
| 514 |
|
511 |
|
| 515 |
/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
|
- |
|
| 516 |
|
- |
|
| 517 |
|
- |
|
| 518 |
FofoOrder fofoOrder = new FofoOrder();
|
512 |
FofoOrder fofoOrder = new FofoOrder();
|
| 519 |
fofoOrder.setCustomerId(customer.getId());
|
513 |
fofoOrder.setCustomerId(customer.getId());
|
| 520 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
514 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
| 521 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
515 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
| 522 |
fofoOrder.setTotalAmount(totalAmount);
|
516 |
fofoOrder.setTotalAmount(totalAmount);
|
| Line 530... |
Line 524... |
| 530 |
paymentOption.setType(customPaymentOption.getType());
|
524 |
paymentOption.setType(customPaymentOption.getType());
|
| 531 |
paymentOptionRepository.persist(paymentOption);
|
525 |
paymentOptionRepository.persist(paymentOption);
|
| 532 |
}
|
526 |
}
|
| 533 |
|
527 |
|
| 534 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoDetails.getFofoId()));
|
528 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoDetails.getFofoId()));
|
| - |
|
529 |
Map<String, GstRate> gstRateMap = null;
|
| - |
|
530 |
if(retailerAddress.getState().equals(customerAddress.getState())){
|
| - |
|
531 |
gstRateMap = Utils.getGstRates(retailerAddress.getState());
|
| - |
|
532 |
}else{
|
| - |
|
533 |
LOGGER.info("inter gstRate = true");
|
| - |
|
534 |
gstRateMap = Utils.getInterGstRates();
|
| 535 |
//
|
535 |
}
|
| 536 |
Map<String, GstRate> gstRateMap = Utils.getGstRates(retailerAddress.getState());
|
536 |
LOGGER.info("gstRateMap {}", gstRateMap);
|
| 537 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
537 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
| 538 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
538 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
| 539 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
539 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
| 540 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
540 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
| 541 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
541 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
| Line 595... |
Line 595... |
| 595 |
}
|
595 |
}
|
| 596 |
}
|
596 |
}
|
| 597 |
return null;
|
597 |
return null;
|
| 598 |
}
|
598 |
}
|
| 599 |
|
599 |
|
| 600 |
|
- |
|
| 601 |
private Map<Integer, Item> toItemMap(List<Item> items){
|
- |
|
| 602 |
Map<Integer, Item> map = new HashMap<>();
|
- |
|
| 603 |
for(Item item : items){
|
- |
|
| 604 |
map.put(item.getId(), item);
|
- |
|
| 605 |
}
|
- |
|
| 606 |
return map;
|
- |
|
| 607 |
}
|
- |
|
| 608 |
|
- |
|
| 609 |
/*private Address createAddress(CustomAddress customAddress){
|
- |
|
| 610 |
Address address = new Address();
|
- |
|
| 611 |
address.setName(customAddress.getName());
|
- |
|
| 612 |
address.setLine1(customAddress.getLine1());
|
- |
|
| 613 |
address.setLine2(customAddress.getLine2());
|
- |
|
| 614 |
address.setLandmark(customAddress.getLandmark());
|
- |
|
| 615 |
address.setCity(customAddress.getCity());
|
- |
|
| 616 |
address.setPinCode(customAddress.getPinCode());
|
- |
|
| 617 |
address.setState(customAddress.getState());
|
- |
|
| 618 |
address.setCountry(customAddress.getCountry());
|
- |
|
| 619 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
- |
|
| 620 |
address.setEnabled(true);
|
- |
|
| 621 |
return address;
|
- |
|
| 622 |
}*/
|
- |
|
| 623 |
|
- |
|
| 624 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
600 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
| 625 |
CustomerAddress customerAddress = new CustomerAddress();
|
601 |
CustomerAddress customerAddress = new CustomerAddress();
|
| 626 |
customerAddress.setName(customAddress.getName());
|
602 |
customerAddress.setName(customAddress.getName());
|
| 627 |
customerAddress.setLine1(customAddress.getLine1());
|
603 |
customerAddress.setLine1(customAddress.getLine1());
|
| 628 |
customerAddress.setLine2(customAddress.getLine2());
|
604 |
customerAddress.setLine2(customAddress.getLine2());
|
| Line 681... |
Line 657... |
| 681 |
}
|
657 |
}
|
| 682 |
|
658 |
|
| 683 |
|
659 |
|
| 684 |
@RequestMapping(value = "/generateInvoice")
|
660 |
@RequestMapping(value = "/generateInvoice")
|
| 685 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
661 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
| 686 |
LOGGER.info("Request received at url {} with params {} ", request.getRequestURI(), request.getParameterMap());
|
662 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(), ProfitMandiConstants.ORDER_ID, orderId);
|
| 687 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
663 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 688 |
|
664 |
|
| 689 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
665 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 690 |
PdfModel pdfModel = new PdfModel();
|
666 |
PdfModel pdfModel = new PdfModel();
|
| 691 |
pdfModel.setAuther("profitmandi");
|
667 |
pdfModel.setAuther("profitmandi");
|
| Line 718... |
Line 694... |
| 718 |
float totalTaxRate = fofoLineItem.getIgstRate() + fofoLineItem.getSgstRate() + fofoLineItem.getCgstRate();
|
694 |
float totalTaxRate = fofoLineItem.getIgstRate() + fofoLineItem.getSgstRate() + fofoLineItem.getCgstRate();
|
| 719 |
float taxableSellingPrice = fofoLineItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
695 |
float taxableSellingPrice = fofoLineItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
| 720 |
|
696 |
|
| 721 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * taxableSellingPrice);
|
697 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * taxableSellingPrice);
|
| 722 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
698 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
| 723 |
//float taxableTotalAmount = customFofoOrderItem.getAmount() / (1 + (totalTaxRate / 100));
|
- |
|
| 724 |
//float itemTotal = customFofoOrderItem.getAmount() + taxableAmount;
|
- |
|
| 725 |
//LOGGER.info("totalTaxRate ={}, taxableAmount ={}, itemTotal ={}", totalTaxRate, taxableAmount, itemTotal);
|
- |
|
| 726 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
699 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
| 727 |
customFofoOrderItem.setQuantity(fofoLineItem.getQuantity());
|
700 |
customFofoOrderItem.setQuantity(fofoLineItem.getQuantity());
|
| 728 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getIgstRate()) / 100;
|
701 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getIgstRate()) / 100;
|
| 729 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getCgstRate()) / 100;
|
702 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getCgstRate()) / 100;
|
| 730 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getSgstRate()) / 100;
|
703 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getSgstRate()) / 100;
|
| 731 |
//LOGGER.info("igst [{},{}], cgst [{},{}], sgst[{},{}]", fofoLineItem.getIgstRate(), igstAmount, fofoLineItem.getCgstRate(), cgstAmount, fofoLineItem.getSgstRate(), sgstAmount);
|
- |
|
| 732 |
customFofoOrderItem.setIgstRate(fofoLineItem.getIgstRate());
|
704 |
customFofoOrderItem.setIgstRate(fofoLineItem.getIgstRate());
|
| 733 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
705 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
| 734 |
customFofoOrderItem.setCgstRate(fofoLineItem.getCgstRate());
|
706 |
customFofoOrderItem.setCgstRate(fofoLineItem.getCgstRate());
|
| 735 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
707 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
| 736 |
customFofoOrderItem.setSgstRate(fofoLineItem.getSgstRate());
|
708 |
customFofoOrderItem.setSgstRate(fofoLineItem.getSgstRate());
|
| 737 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
709 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
| 738 |
customFofoOrderItem.setHsnCode(fofoLineItem.getHsnCode());
|
710 |
customFofoOrderItem.setHsnCode(fofoLineItem.getHsnCode());
|
| 739 |
//customFofoOrderItem.setItemTotal(customFofoOrderItem.getAmount() + igstAmount + cgstAmount + sgstAmount);
|
- |
|
| 740 |
//customFofoOrderItem.setAmount(taxableTotalAmount);
|
- |
|
| 741 |
customFofoOrderItem.setSerialNumbers(String.join(", ",this.toSerialNumbers(fofoLineItem.getFofoLineItemSerialNumbers())));
|
711 |
customFofoOrderItem.setSerialNumbers(String.join(", ",this.toSerialNumbers(fofoLineItem.getFofoLineItemSerialNumbers())));
|
| 742 |
customerFofoOrderItems.add(customFofoOrderItem);
|
712 |
customerFofoOrderItems.add(customFofoOrderItem);
|
| 743 |
//pdfModel.setTotalAmount(pdfModel.getTotalAmount() + customFofoOrderItem.getItemTotal());
|
- |
|
| 744 |
}
|
713 |
}
|
| 745 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
714 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 746 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
715 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 747 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
716 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
| 748 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|
717 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|