Subversion Repositories SmartDukaan

Rev

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

Rev 30043 Rev 30157
Line 1... Line 1...
1
package com.spice.profitmandi.service.order;
1
package com.spice.profitmandi.service.order;
2
 
2
 
-
 
3
import java.io.ByteArrayInputStream;
-
 
4
import java.io.InputStream;
-
 
5
import java.time.LocalDate;
-
 
6
import java.time.LocalDateTime;
-
 
7
import java.time.LocalTime;
-
 
8
import java.util.AbstractMap.SimpleEntry;
-
 
9
import java.util.ArrayList;
-
 
10
import java.util.Arrays;
-
 
11
import java.util.HashMap;
-
 
12
import java.util.HashSet;
-
 
13
import java.util.Iterator;
-
 
14
import java.util.List;
-
 
15
import java.util.Map;
-
 
16
import java.util.Optional;
-
 
17
import java.util.Random;
-
 
18
import java.util.Set;
-
 
19
import java.util.function.Function;
-
 
20
import java.util.stream.Collectors;
-
 
21
 
-
 
22
import javax.persistence.criteria.CriteriaBuilder;
-
 
23
import javax.persistence.criteria.CriteriaQuery;
-
 
24
import javax.persistence.criteria.Predicate;
-
 
25
import javax.persistence.criteria.Root;
-
 
26
 
-
 
27
import org.apache.logging.log4j.LogManager;
-
 
28
import org.apache.logging.log4j.Logger;
-
 
29
import org.hibernate.Session;
-
 
30
import org.hibernate.SessionFactory;
-
 
31
import org.json.JSONObject;
-
 
32
import org.springframework.beans.factory.annotation.Autowired;
-
 
33
import org.springframework.beans.factory.annotation.Qualifier;
-
 
34
import org.springframework.beans.factory.annotation.Value;
-
 
35
import org.springframework.cache.annotation.Cacheable;
-
 
36
import org.springframework.core.io.InputStreamResource;
-
 
37
import org.springframework.http.HttpHeaders;
-
 
38
import org.springframework.http.HttpStatus;
-
 
39
import org.springframework.http.ResponseEntity;
-
 
40
import org.springframework.stereotype.Component;
-
 
41
 
3
import com.spice.profitmandi.common.enumuration.ItemType;
42
import com.spice.profitmandi.common.enumuration.ItemType;
4
import com.spice.profitmandi.common.enumuration.SearchType;
43
import com.spice.profitmandi.common.enumuration.SearchType;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
45
import com.spice.profitmandi.common.model.BadReturnRequest;
-
 
46
import com.spice.profitmandi.common.model.CartFofo;
-
 
47
import com.spice.profitmandi.common.model.CreateOrderRequest;
-
 
48
import com.spice.profitmandi.common.model.CreditNotePdfModel;
-
 
49
import com.spice.profitmandi.common.model.CustomAddress;
-
 
50
import com.spice.profitmandi.common.model.CustomCustomer;
-
 
51
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
-
 
52
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
-
 
53
import com.spice.profitmandi.common.model.CustomOrderItem;
-
 
54
import com.spice.profitmandi.common.model.CustomPaymentOption;
-
 
55
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
56
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
6
import com.spice.profitmandi.common.model.*;
57
import com.spice.profitmandi.common.model.GstRate;
-
 
58
import com.spice.profitmandi.common.model.InsuranceModel;
-
 
59
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
-
 
60
import com.spice.profitmandi.common.model.PdfModel;
-
 
61
import com.spice.profitmandi.common.model.PriceModel;
-
 
62
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
63
import com.spice.profitmandi.common.model.Quantity;
-
 
64
import com.spice.profitmandi.common.model.SerialNumberDetail;
7
import com.spice.profitmandi.common.util.FormattingUtils;
65
import com.spice.profitmandi.common.util.FormattingUtils;
8
import com.spice.profitmandi.common.util.StringUtils;
66
import com.spice.profitmandi.common.util.StringUtils;
9
import com.spice.profitmandi.common.util.Utils;
67
import com.spice.profitmandi.common.util.Utils;
10
import com.spice.profitmandi.common.web.client.RestClient;
68
import com.spice.profitmandi.common.web.client.RestClient;
11
import com.spice.profitmandi.dao.entity.catalog.Item;
69
import com.spice.profitmandi.dao.entity.catalog.Item;
12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
70
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
71
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
-
 
72
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
-
 
73
import com.spice.profitmandi.dao.entity.dtr.Retailer;
-
 
74
import com.spice.profitmandi.dao.entity.dtr.ScratchOffer;
13
import com.spice.profitmandi.dao.entity.dtr.*;
75
import com.spice.profitmandi.dao.entity.dtr.User;
-
 
76
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
14
import com.spice.profitmandi.dao.entity.fofo.*;
77
import com.spice.profitmandi.dao.entity.fofo.Customer;
-
 
78
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
-
 
79
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
-
 
80
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
-
 
81
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
-
 
82
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
-
 
83
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
-
 
84
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
85
import com.spice.profitmandi.dao.entity.fofo.HygieneData;
-
 
86
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
-
 
87
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
-
 
88
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
-
 
89
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
-
 
90
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
-
 
91
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
15
import com.spice.profitmandi.dao.entity.inventory.State;
92
import com.spice.profitmandi.dao.entity.inventory.State;
16
import com.spice.profitmandi.dao.entity.transaction.Order;
93
import com.spice.profitmandi.dao.entity.transaction.Order;
17
import com.spice.profitmandi.dao.entity.user.Address;
94
import com.spice.profitmandi.dao.entity.user.Address;
18
import com.spice.profitmandi.dao.entity.user.Counter;
95
import com.spice.profitmandi.dao.entity.user.Counter;
19
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
96
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
Line 26... Line 103...
26
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
103
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
27
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
104
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
28
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
105
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
29
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
106
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
30
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
107
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
-
 
108
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
109
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
-
 
110
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
31
import com.spice.profitmandi.dao.repository.dtr.*;
111
import com.spice.profitmandi.dao.repository.dtr.Mongo;
-
 
112
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
-
 
113
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
-
 
114
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
-
 
115
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
-
 
116
import com.spice.profitmandi.dao.repository.dtr.ScratchOfferRepository;
-
 
117
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
32
import com.spice.profitmandi.dao.repository.fofo.*;
118
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
-
 
119
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
-
 
120
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
-
 
121
import com.spice.profitmandi.dao.repository.fofo.CustomerCreditNoteRepository;
-
 
122
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
-
 
123
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
-
 
124
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
-
 
125
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
-
 
126
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
-
 
127
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
-
 
128
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
-
 
129
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
-
 
130
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
-
 
131
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
-
 
132
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
-
 
133
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
-
 
134
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
-
 
135
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
33
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
136
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
34
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
137
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
35
import com.spice.profitmandi.dao.repository.user.AddressRepository;
138
import com.spice.profitmandi.dao.repository.user.AddressRepository;
36
import com.spice.profitmandi.dao.repository.user.CounterRepository;
139
import com.spice.profitmandi.dao.repository.user.CounterRepository;
37
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
140
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
Line 43... Line 146...
43
import com.spice.profitmandi.service.offers.ItemCriteria;
146
import com.spice.profitmandi.service.offers.ItemCriteria;
44
import com.spice.profitmandi.service.pricing.PricingService;
147
import com.spice.profitmandi.service.pricing.PricingService;
45
import com.spice.profitmandi.service.scheme.SchemeService;
148
import com.spice.profitmandi.service.scheme.SchemeService;
46
import com.spice.profitmandi.service.user.RetailerService;
149
import com.spice.profitmandi.service.user.RetailerService;
47
import com.spice.profitmandi.service.wallet.WalletService;
150
import com.spice.profitmandi.service.wallet.WalletService;
48
import org.apache.logging.log4j.LogManager;
-
 
49
import org.apache.logging.log4j.Logger;
-
 
50
import org.hibernate.Session;
-
 
51
import org.hibernate.SessionFactory;
-
 
52
import org.json.JSONObject;
-
 
53
import org.springframework.beans.factory.annotation.Autowired;
-
 
54
import org.springframework.beans.factory.annotation.Qualifier;
-
 
55
import org.springframework.beans.factory.annotation.Value;
-
 
56
import org.springframework.cache.annotation.Cacheable;
-
 
57
import org.springframework.stereotype.Component;
-
 
58
 
-
 
59
import javax.persistence.criteria.CriteriaBuilder;
-
 
60
import javax.persistence.criteria.CriteriaQuery;
-
 
61
import javax.persistence.criteria.Predicate;
-
 
62
import javax.persistence.criteria.Root;
-
 
63
import java.time.LocalDate;
-
 
64
import java.time.LocalDateTime;
-
 
65
import java.time.LocalTime;
-
 
66
import java.util.AbstractMap.SimpleEntry;
-
 
67
import java.util.*;
-
 
68
import java.util.function.Function;
-
 
69
import java.util.stream.Collectors;
-
 
70
 
151
 
71
@Component
152
@Component
72
public class OrderServiceImpl implements OrderService {
153
public class OrderServiceImpl implements OrderService {
73
 
154
 
74
	private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
155
	private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
Line 1186... Line 1267...
1186
		} else {
1267
		} else {
1187
			map.put("end", offset + limit);
1268
			map.put("end", offset + limit);
1188
		}
1269
		}
1189
		return map;
1270
		return map;
1190
	}
1271
	}
-
 
1272
	
-
 
1273
	public ResponseEntity<?> downloadReportInCsv( org.apache.commons.io.output.ByteArrayOutputStream baos , List<List<?>> rows, String fileName)
-
 
1274
	{
-
 
1275
		final HttpHeaders headers = new HttpHeaders();
-
 
1276
		headers.set("Content-Type", "text/csv");
-
 
1277
		headers.set("Content-disposition", "inline; filename=" + fileName);
-
 
1278
		headers.setContentLength(baos.toByteArray().length);
-
 
1279
 
-
 
1280
		final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-
 
1281
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
1282
		
-
 
1283
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
1284
	}
1191
 
1285
 
1192
	@Override
1286
	@Override
1193
	public Map<String, Object> getSaleHistoryPaginated(int fofoId, SearchType searchType, String searchValue,
1287
	public Map<String, Object> getSaleHistoryPaginated(int fofoId, SearchType searchType, String searchValue,
1194
			LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
1288
			LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
1195
		List<FofoOrder> fofoOrders = new ArrayList<>();
1289
		List<FofoOrder> fofoOrders = new ArrayList<>();