| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 5 |
import com.spice.profitmandi.common.model.ScanSerializedRequest;
|
5 |
import com.spice.profitmandi.common.model.ScanSerializedRequest;
|
| - |
|
6 |
import com.spice.profitmandi.common.util.Utils;
|
| 6 |
import com.spice.profitmandi.common.web.client.RestClient;
|
7 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 7 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
8 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 8 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
9 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 9 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
10 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 10 |
import com.spice.profitmandi.dao.model.ImeiInoviceModel;
|
11 |
import com.spice.profitmandi.dao.model.ImeiInoviceModel;
|
| Line 36... |
Line 37... |
| 36 |
import java.io.ByteArrayInputStream;
|
37 |
import java.io.ByteArrayInputStream;
|
| 37 |
import java.io.ByteArrayOutputStream;
|
38 |
import java.io.ByteArrayOutputStream;
|
| 38 |
import java.io.File;
|
39 |
import java.io.File;
|
| 39 |
import java.io.InputStream;
|
40 |
import java.io.InputStream;
|
| 40 |
import java.time.LocalDateTime;
|
41 |
import java.time.LocalDateTime;
|
| - |
|
42 |
import java.time.LocalTime;
|
| - |
|
43 |
import java.time.YearMonth;
|
| 41 |
import java.util.*;
|
44 |
import java.util.*;
|
| - |
|
45 |
import java.util.function.Function;
|
| 42 |
import java.util.stream.Collectors;
|
46 |
import java.util.stream.Collectors;
|
| 43 |
import java.util.zip.ZipEntry;
|
47 |
import java.util.zip.ZipEntry;
|
| 44 |
import java.util.zip.ZipOutputStream;
|
48 |
import java.util.zip.ZipOutputStream;
|
| 45 |
|
49 |
|
| 46 |
import static org.springframework.util.FileCopyUtils.BUFFER_SIZE;
|
50 |
import static org.springframework.util.FileCopyUtils.BUFFER_SIZE;
|
| Line 161... |
Line 165... |
| 161 |
Map<String, Object> map = purchaseService.purchaseByInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
165 |
Map<String, Object> map = purchaseService.purchaseByInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
| 162 |
model.addAllAttributes(map);
|
166 |
model.addAllAttributes(map);
|
| 163 |
return "purchase";
|
167 |
return "purchase";
|
| 164 |
}
|
168 |
}
|
| 165 |
|
169 |
|
| - |
|
170 |
|
| 166 |
@RequestMapping(value = "/purchase-invoice/{invoiceNumber}", method = RequestMethod.GET)
|
171 |
@RequestMapping(value = "/purchase-invoice/{invoiceNumber}", method = RequestMethod.GET)
|
| 167 |
public ResponseEntity<?> downloadInvoice(HttpServletRequest request, @PathVariable String invoiceNumber, Model model) throws Exception {
|
172 |
public ResponseEntity<?> downloadInvoice(HttpServletRequest request, @PathVariable String invoiceNumber, Model model) throws Exception {
|
| 168 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
173 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
174 |
List<String> invoiceNumbers = null;
|
| - |
|
175 |
try {
|
| - |
|
176 |
YearMonth ym = YearMonth.parse(invoiceNumber);
|
| - |
|
177 |
if (!roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| - |
|
178 |
List<Order> orders = orderRepository.selectAllByBillingDatesBetween(fofoDetails.getFofoId(), ym.atDay(1).atStartOfDay(),
|
| - |
|
179 |
ym.atEndOfMonth().atTime(LocalTime.MAX));
|
| - |
|
180 |
invoiceNumbers = orders.stream().map(x -> x.getInvoiceNumber()).filter(Utils.distinctByKey(Function.identity())).collect(Collectors.toList());
|
| - |
|
181 |
}
|
| - |
|
182 |
} catch (Exception e) {
|
| 169 |
List<String> invoiceNumbers = Arrays.asList(invoiceNumber.replaceAll(" ", "").split(","));
|
183 |
invoiceNumbers = Arrays.asList(invoiceNumber.replaceAll(" ", "").split(","));
|
| - |
|
184 |
}
|
| 170 |
Map<String, List<Order>> invoiceOrdersMap = orderRepository.selectByInvoiceNumbers(invoiceNumbers).stream().collect(Collectors.groupingBy(x -> x.getInvoiceNumber()));
|
185 |
Map<String, List<Order>> invoiceOrdersMap = orderRepository.selectByInvoiceNumbers(invoiceNumbers).stream().collect(Collectors.groupingBy(x -> x.getInvoiceNumber()));
|
| 171 |
if (invoiceOrdersMap.size() > 0) {
|
186 |
if (invoiceOrdersMap.size() > 0) {
|
| 172 |
if (roleManager.isAdmin(fofoDetails.getRoleIds()) || invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0).getRetailerId() == fofoDetails.getFofoId()) {
|
187 |
if (roleManager.isAdmin(fofoDetails.getRoleIds()) || invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0).getRetailerId() == fofoDetails.getFofoId()) {
|
| 173 |
if (invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0).getRetailerId() == fofoDetails.getFofoId()) {
|
188 |
if (invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0).getRetailerId() == fofoDetails.getFofoId()) {
|
| 174 |
invoiceOrdersMap = invoiceOrdersMap.entrySet().stream().filter(x -> x.getValue().get(0).getRetailerId() == fofoDetails.getFofoId()).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
|
189 |
invoiceOrdersMap = invoiceOrdersMap.entrySet().stream().filter(x -> x.getValue().get(0).getRetailerId() == fofoDetails.getFofoId()).collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
|