Rev 21591 | Rev 21598 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;import javax.servlet.http.HttpServletRequest;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import com.spice.profitmandi.common.model.CustomItem;import com.spice.profitmandi.common.model.CustomLineItem;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.dao.repository.InventoryItemRepository;import com.spice.profitmandi.dao.repository.OrderRepository;import com.spice.profitmandi.web.model.FofoDetails;import com.spice.profitmandi.web.util.CookiesFetcher;import com.spice.profitmandi.web.util.MVCResponseSender;import in.shop2020.model.v1.catalog.ItemType;@Controllerpublic class PurchaseController {private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);@AutowiredOrderRepository orderRepository;@AutowiredInventoryItemRepository inventoryItemRepository;@AutowiredMVCResponseSender mvcResponseSender;@AutowiredCookiesFetcher cookiesFetcher;@RequestMapping(value = "/purchase", method = RequestMethod.POST)public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws Throwable{FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);List<Object[]> rows = orderRepository.selectByAirwayBillOrInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());Set<Integer> itemIds = new HashSet<>();String invoiceNumber = null;for(Object[] row : rows){itemIds.add((int)row[0]);invoiceNumber = (String)row[9];}List<Object[]> itemIdCounts = inventoryItemRepository.selectScannedCount(itemIds, fofoDetails.getFofoId(), invoiceNumber);List<CustomItem> customItems = new ArrayList<>();for(Object[] itemIdCount : itemIdCounts){for(Object[] row : rows){if((int)itemIdCount[0] == (int)row[0]){customItems.add(this.createCustomLineItem(row, (int)row[1] == (int)itemIdCount[1] ? true : false));}}}model.addAttribute("customItems", customItems);return "purchase";}@RequestMapping(value = "/purchase", method = RequestMethod.GET)public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request) throws Exception{return "purchase";}private CustomItem createCustomLineItem(Object[] row, boolean scanned){CustomItem customItem = new CustomItem();customItem.setItemId((int)row[0]);CustomLineItem customLineItem = new CustomLineItem();customLineItem.setBrand((String)row[1]);customLineItem.setModelName((String)row[2]);customLineItem.setModelNumber((String)row[3]);customLineItem.setColor((String)row[4]);customLineItem.setQuantity((float)row[5]);customLineItem.setUnitPrice((float)row[6]);customItem.setItemDetail(customLineItem);customItem.setType(ItemType.valueOf((String)row[7]));customItem.setScanned(scanned);return customItem;}}