Subversion Repositories SmartDukaan

Rev

Rev 27749 | Rev 27893 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27749 Rev 27867
Line 4... Line 4...
4
import java.io.ByteArrayOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
5
import java.io.IOException;
6
import java.io.InputStream;
6
import java.io.InputStream;
7
import java.io.InputStreamReader;
7
import java.io.InputStreamReader;
8
import java.net.URISyntaxException;
8
import java.net.URISyntaxException;
-
 
9
import java.time.Duration;
9
import java.time.LocalDate;
10
import java.time.LocalDate;
10
import java.time.LocalDateTime;
11
import java.time.LocalDateTime;
11
import java.time.LocalTime;
12
import java.time.LocalTime;
12
import java.time.YearMonth;
13
import java.time.YearMonth;
13
import java.time.format.DateTimeFormatter;
14
import java.time.format.DateTimeFormatter;
-
 
15
import java.time.temporal.ChronoUnit;
14
import java.util.ArrayList;
16
import java.util.ArrayList;
15
import java.util.Arrays;
17
import java.util.Arrays;
16
import java.util.Collection;
18
import java.util.Collection;
-
 
19
import java.util.Comparator;
-
 
20
import java.util.Date;
17
import java.util.HashMap;
21
import java.util.HashMap;
18
import java.util.HashSet;
22
import java.util.HashSet;
19
import java.util.Iterator;
23
import java.util.Iterator;
20
import java.util.List;
24
import java.util.List;
21
import java.util.Map;
25
import java.util.Map;
22
import java.util.Optional;
26
import java.util.Optional;
23
import java.util.Set;
27
import java.util.Set;
24
import java.util.stream.Collectors;
28
import java.util.stream.Collectors;
-
 
29
import java.util.stream.Stream;
25
 
30
 
26
import javax.servlet.http.HttpServletRequest;
31
import javax.servlet.http.HttpServletRequest;
27
import javax.servlet.http.HttpServletResponse;
32
import javax.servlet.http.HttpServletResponse;
28
 
33
 
29
import org.apache.commons.csv.CSVFormat;
34
import org.apache.commons.csv.CSVFormat;
Line 31... Line 36...
31
import org.apache.commons.csv.CSVRecord;
36
import org.apache.commons.csv.CSVRecord;
32
import org.apache.commons.io.FileUtils;
37
import org.apache.commons.io.FileUtils;
33
import org.apache.commons.lang3.StringUtils;
38
import org.apache.commons.lang3.StringUtils;
34
import org.apache.logging.log4j.LogManager;
39
import org.apache.logging.log4j.LogManager;
35
import org.apache.logging.log4j.Logger;
40
import org.apache.logging.log4j.Logger;
-
 
41
import org.apache.poi.ss.formula.functions.Days360;
36
import org.apache.thrift.TException;
42
import org.apache.thrift.TException;
37
import org.hibernate.type.CurrencyType;
43
import org.hibernate.type.CurrencyType;
38
import org.json.JSONObject;
44
import org.json.JSONObject;
39
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.beans.factory.annotation.Autowired;
40
import org.springframework.beans.factory.annotation.Qualifier;
46
import org.springframework.beans.factory.annotation.Qualifier;
Line 85... Line 91...
85
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
91
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
86
import com.spice.profitmandi.dao.entity.transaction.NotifyMessage;
92
import com.spice.profitmandi.dao.entity.transaction.NotifyMessage;
87
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
93
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
88
import com.spice.profitmandi.dao.entity.transaction.Order;
94
import com.spice.profitmandi.dao.entity.transaction.Order;
89
import com.spice.profitmandi.dao.model.BrandItemWiseTertiaryModel;
95
import com.spice.profitmandi.dao.model.BrandItemWiseTertiaryModel;
-
 
96
import com.spice.profitmandi.dao.model.BrandRegionModel;
90
import com.spice.profitmandi.dao.model.BrandWiseTertiaryModel;
97
import com.spice.profitmandi.dao.model.BrandWiseTertiaryModel;
91
import com.spice.profitmandi.dao.model.ContentPojo;
98
import com.spice.profitmandi.dao.model.ContentPojo;
92
import com.spice.profitmandi.dao.model.OpenPoItemModel;
99
import com.spice.profitmandi.dao.model.OpenPoItemModel;
93
import com.spice.profitmandi.dao.model.OpenPoModel;
100
import com.spice.profitmandi.dao.model.OpenPoModel;
94
import com.spice.profitmandi.dao.model.OurPurchaseItemModel;
101
import com.spice.profitmandi.dao.model.OurPurchaseItemModel;
95
import com.spice.profitmandi.dao.model.OurPurchaseModel;
102
import com.spice.profitmandi.dao.model.OurPurchaseModel;
-
 
103
import com.spice.profitmandi.dao.model.SecondaeryOrderDateRange;
96
import com.spice.profitmandi.dao.model.SecondaryOrderBillingModel;
104
import com.spice.profitmandi.dao.model.SecondaryOrderBillingModel;
97
import com.spice.profitmandi.dao.model.SecondaryOrderItemBillingModel;
105
import com.spice.profitmandi.dao.model.SecondaryOrderItemBillingModel;
-
 
106
import com.spice.profitmandi.dao.model.SecondaryWarehouseWiseOrderBilllingModel;
98
import com.spice.profitmandi.dao.model.Specification;
107
import com.spice.profitmandi.dao.model.Specification;
99
import com.spice.profitmandi.dao.model.SpecificationGroup;
108
import com.spice.profitmandi.dao.model.SpecificationGroup;
100
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
109
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
101
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
110
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
102
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
111
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
Line 1525... Line 1534...
1525
 
1534
 
1526
		return "inventory-listing-purchase-item";
1535
		return "inventory-listing-purchase-item";
1527
 
1536
 
1528
	}
1537
	}
1529
 
1538
 
1530
	@RequestMapping(value = "/getSecondaryBillingItemByBrand", method = RequestMethod.GET)
1539
	@RequestMapping(value = "/getWarehouseWiseSecondaryBillingByBrand", method = RequestMethod.GET)
1531
	public String getSecondaryBillingItemByBrand(HttpServletRequest request,
1540
	public String getWarehouseWiseSecondaryBillingByBrand(HttpServletRequest request,
1532
			@RequestParam(name = "warehouseIds", required = true, defaultValue = "0") List<Integer> warehouseIds,
-
 
1533
			@RequestParam(name = "brand", required = true, defaultValue = "") List<String> brand, int timeValue,
1541
			@RequestParam(name = "brand", required = true, defaultValue = "") String brand, int timeValue, Model model)
1534
			Model model) throws Exception {
1542
			throws Exception {
1535
		model.addAttribute("warehouseId", warehouseIds);
-
 
1536
		LOGGER.info("warehouseIds" + warehouseIds);
-
 
1537
 
1543
 
1538
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
-
 
1539
		if (warehouseIds.contains(0)) {
-
 
1540
			warehouseIds.addAll(warehouseMap.keySet());
-
 
1541
		}
-
 
1542
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1544
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
1543
		int dayOfMonth = curDate.getDayOfMonth();
1545
		int dayOfMonth = curDate.getDayOfMonth();
1544
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1);
1546
		LocalDateTime startOfMonth = curDate.withDayOfMonth(1);
1545
		int lengthOfMonth = YearMonth.from(startOfMonth.minusMonths(1)).lengthOfMonth();
1547
		int lengthOfMonth = YearMonth.from(startOfMonth.minusMonths(1)).lengthOfMonth();
1546
 
1548
 
1547
		if (brand.contains("Total Values")) {
1549
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
1548
			List<String> billingbrands = orderRepository.selectAllBilledOrderGroupByBrand(warehouseIds).stream()
1550
		SecondaeryOrderDateRange sr = null;
1549
					.map(x -> x.getBrand()).collect(Collectors.toList());
1551
		if (brand.equals("Total Values")) {
1550
 
-
 
1551
			brand.addAll(billingbrands);
1552
			brand = null;
1552
		}
1553
		}
1553
		List<SecondaryOrderItemBillingModel> billedItem = null;
-
 
1554
		if (timeValue != 0) {
1554
		if (timeValue != 0) {
1555
			if (timeValue == 1) {
1555
			if (timeValue == 1) {
1556
				billedItem = orderRepository.selectAllBilledOrderItemByBrand(warehouseIds, brand,
-
 
-
 
1556
 
1557
						curDate.withDayOfMonth(1), curDate.plusDays(1));
1557
				sr = getSecondaryModel(brand, curDate.withDayOfMonth(1), curDate.plusDays(1));
1558
 
1558
 
1559
			} else if (timeValue == 2) {
1559
			} else if (timeValue == 2) {
1560
				LOGGER.info("curDate" + curDate.withDayOfMonth(1).minusMonths(1));
1560
				LOGGER.info("curDate" + curDate.withDayOfMonth(1).minusMonths(1));
1561
				LOGGER.info("curDate" + curDate.minusMonths(1).plusDays(Math.min(dayOfMonth, lengthOfMonth)));
1561
				LOGGER.info("curDate" + curDate.minusMonths(1).plusDays(Math.min(dayOfMonth, lengthOfMonth)));
1562
 
1562
 
1563
				billedItem = orderRepository.selectAllBilledOrderItemByBrand(warehouseIds, brand,
-
 
1564
						curDate.withDayOfMonth(1).minusMonths(1),
1563
				sr = getSecondaryModel(brand, curDate.withDayOfMonth(1).minusMonths(1),
1565
						startOfMonth.minusMonths(1).plusDays(Math.min(dayOfMonth, lengthOfMonth)));
1564
						startOfMonth.minusMonths(1).plusDays(Math.min(dayOfMonth, lengthOfMonth)));
-
 
1565
 
1566
			} else if (timeValue == -1) {
1566
			} else if (timeValue == -1) {
1567
				billedItem = orderRepository.selectAllBilledOrderItemByBrand(warehouseIds, brand,
-
 
-
 
1567
 
1568
						curDate.minusMonths(1).withDayOfMonth(1), startOfMonth);
1568
				sr = getSecondaryModel(brand, curDate.minusMonths(1).withDayOfMonth(1), startOfMonth);
-
 
1569
 
1569
			} else {
1570
			} else {
1570
 
1571
 
1571
				billedItem = orderRepository.selectAllBilledOrderItemByBrand(warehouseIds, brand,
-
 
1572
						curDate.minusDays(timeValue), curDate);
1572
				sr = getSecondaryModel(brand, curDate.minusDays(timeValue), curDate);
1573
			}
1573
			}
1574
 
1574
 
1575
		} else {
1575
		} else {
1576
			billedItem = orderRepository.selectTodayBilledOrderItemByBrand(warehouseIds, brand, curDate);
1576
			sr = getSecondaryModel(brand, curDate, curDate.plusDays(1));
1577
		}
1577
		}
1578
		LOGGER.info("billedItem" + billedItem);
-
 
1579
 
1578
 
-
 
1579
		Map<BrandRegionModel, Map<LocalDate, SecondaryWarehouseWiseOrderBilllingModel>> brandWarehouseOrderMap = sr
-
 
1580
				.getSecondaryModel().stream()
-
 
1581
				.collect(Collectors.groupingBy(x -> new BrandRegionModel(x.getWarehouseId(), x.getBrand()),
-
 
1582
						Collectors.collectingAndThen(Collectors.toList(),
-
 
1583
								x -> x.stream().collect(Collectors.toMap(y -> y.getBillingTimestamp(), y -> y)))));
-
 
1584
 
-
 
1585
		brandWarehouseOrderMap.entrySet().stream().forEach(x -> {
-
 
1586
			x.getKey().setTotal(
-
 
1587
					x.getValue().entrySet().stream().collect(Collectors.summingLong(y -> y.getValue().getValue())));
-
 
1588
		});
-
 
1589
 
-
 
1590
		LOGGER.info("brandWarehouseOrderMap" + brandWarehouseOrderMap);
-
 
1591
 
-
 
1592
		model.addAttribute("brandWarehouseOrderMap", brandWarehouseOrderMap);
-
 
1593
		model.addAttribute("dateRange", sr.getDateRange());
1580
		model.addAttribute("billedItem", billedItem);
1594
		model.addAttribute("warehouseMap", warehouseMap);
-
 
1595
		return "secondary-warehouse-billing-order";
-
 
1596
 
-
 
1597
	}
-
 
1598
 
-
 
1599
	public SecondaeryOrderDateRange getSecondaryModel(String brand, LocalDateTime startDate, LocalDateTime endDate) {
1581
 
1600
 
-
 
1601
		SecondaeryOrderDateRange sr = new SecondaeryOrderDateRange();
-
 
1602
		List<SecondaryWarehouseWiseOrderBilllingModel> secondaryOrderbilling = orderRepository
-
 
1603
				.selectAllBilledOrderGroupByBrandWarehouse(brand, startDate, endDate).stream()
-
 
1604
				.sorted(Comparator.comparing(SecondaryWarehouseWiseOrderBilllingModel::getBillingTimestamp))
-
 
1605
				.collect(Collectors.toList());
-
 
1606
		long noOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate);
-
 
1607
 
-
 
1608
		List<LocalDate> dateRange = Stream.iterate(startDate.toLocalDate(), date -> date.plusDays(1))
-
 
1609
				.limit(noOfDaysBetween).collect(Collectors.toList());
-
 
1610
 
-
 
1611
		sr.setDateRange(dateRange);
-
 
1612
		sr.setSecondaryModel(secondaryOrderbilling);
-
 
1613
 
-
 
1614
		return sr;
-
 
1615
 
-
 
1616
	}
-
 
1617
 
-
 
1618
	@RequestMapping(value = "/getSecondaryBillingItemByBrand", method = RequestMethod.GET)
-
 
1619
	public String getSecondaryBillingItemByBrand(HttpServletRequest request,
-
 
1620
			@RequestParam(name = "warehouseId", required = true, defaultValue = "0") int warehouseId,
-
 
1621
			@RequestParam(name = "brand", required = true, defaultValue = "") String brand,
-
 
1622
			@RequestParam LocalDate date, Model model) throws Exception {
-
 
1623
 
-
 
1624
		List<SecondaryOrderItemBillingModel> orderItemBilling = orderRepository
-
 
1625
				.selectAllBilledOrderItemByBrand(warehouseId, brand, date);
-
 
1626
 
-
 
1627
		LOGGER.info("orderItemBilling" + orderItemBilling);
-
 
1628
		model.addAttribute("billedItem", orderItemBilling);
-
 
1629
		model.addAttribute("date", date);
-
 
1630
		model.addAttribute("brand", brand);
1582
		return "inventory-listing-billing-item";
1631
		return "inventory-listing-billing-item";
1583
 
1632
 
1584
	}
1633
	}
1585
 
1634
 
1586
	@RequestMapping(value = "/getPartnerTertiaryItemByBrand", method = RequestMethod.GET)
1635
	@RequestMapping(value = "/getPartnerTertiaryItemByBrand", method = RequestMethod.GET)
Line 1639... Line 1688...
1639
		model.addAttribute("tertiaryItem", tertiaryItem);
1688
		model.addAttribute("tertiaryItem", tertiaryItem);
1640
 
1689
 
1641
		return "inventory-item-tertiary-item";
1690
		return "inventory-item-tertiary-item";
1642
 
1691
 
1643
	}
1692
	}
1644
}
-
 
1645
1693
}
-
 
1694