| 23365 |
ashik.ali |
1 |
package com.spice.profitmandi.service.order;
|
| 22859 |
ashik.ali |
2 |
|
| 24264 |
amit.gupta |
3 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
| 23202 |
ashik.ali |
4 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 22859 |
ashik.ali |
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30321 |
amit.gupta |
6 |
import com.spice.profitmandi.common.model.*;
|
| 23650 |
amit.gupta |
7 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 22859 |
ashik.ali |
8 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23172 |
ashik.ali |
9 |
import com.spice.profitmandi.common.util.Utils;
|
| 29515 |
tejbeer |
10 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 22859 |
ashik.ali |
11 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 25103 |
amit.gupta |
12 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 30321 |
amit.gupta |
13 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 28978 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
| 24917 |
tejbeer |
16 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 22859 |
ashik.ali |
17 |
import com.spice.profitmandi.dao.entity.user.Address;
|
|
|
18 |
import com.spice.profitmandi.dao.entity.user.Counter;
|
|
|
19 |
import com.spice.profitmandi.dao.entity.user.PrivateDealUser;
|
| 27516 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.entity.warehouse.WarehouseInventoryItem;
|
| 24264 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 23546 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
| 23650 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.enumuration.fofo.ReturnType;
|
| 22859 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 23655 |
amit.gupta |
25 |
import com.spice.profitmandi.dao.enumuration.fofo.SettlementType;
|
| 29515 |
tejbeer |
26 |
import com.spice.profitmandi.dao.enumuration.inventory.ScratchedGift;
|
| 28339 |
tejbeer |
27 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 22859 |
ashik.ali |
28 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 26817 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| 24823 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 30321 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
|
|
32 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 24854 |
amit.gupta |
33 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 24917 |
tejbeer |
34 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 22859 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
|
|
36 |
import com.spice.profitmandi.dao.repository.user.CounterRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
| 27516 |
amit.gupta |
38 |
import com.spice.profitmandi.dao.repository.warehouse.WarehouseInventoryItemRepository;
|
| 25724 |
amit.gupta |
39 |
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
|
| 23418 |
ashik.ali |
40 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 23655 |
amit.gupta |
41 |
import com.spice.profitmandi.service.inventory.PurchaseReturnService;
|
| 26891 |
amit.gupta |
42 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 28166 |
tejbeer |
43 |
import com.spice.profitmandi.service.offers.ItemCriteria;
|
| 22859 |
ashik.ali |
44 |
import com.spice.profitmandi.service.pricing.PricingService;
|
|
|
45 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 23655 |
amit.gupta |
46 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23395 |
amit.gupta |
47 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 30321 |
amit.gupta |
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.core.io.InputStreamResource;
|
|
|
58 |
import org.springframework.http.HttpHeaders;
|
|
|
59 |
import org.springframework.http.HttpStatus;
|
|
|
60 |
import org.springframework.http.ResponseEntity;
|
|
|
61 |
import org.springframework.stereotype.Component;
|
| 22859 |
ashik.ali |
62 |
|
| 30321 |
amit.gupta |
63 |
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
64 |
import javax.persistence.criteria.CriteriaQuery;
|
|
|
65 |
import javax.persistence.criteria.Predicate;
|
|
|
66 |
import javax.persistence.criteria.Root;
|
|
|
67 |
import java.io.ByteArrayInputStream;
|
|
|
68 |
import java.io.InputStream;
|
|
|
69 |
import java.time.LocalDate;
|
|
|
70 |
import java.time.LocalDateTime;
|
|
|
71 |
import java.time.LocalTime;
|
|
|
72 |
import java.util.AbstractMap.SimpleEntry;
|
|
|
73 |
import java.util.*;
|
|
|
74 |
import java.util.function.Function;
|
|
|
75 |
import java.util.stream.Collectors;
|
|
|
76 |
|
| 22859 |
ashik.ali |
77 |
@Component
|
|
|
78 |
public class OrderServiceImpl implements OrderService {
|
|
|
79 |
|
| 23568 |
govind |
80 |
private static final Logger LOGGER = LogManager.getLogger(OrderServiceImpl.class);
|
| 22859 |
ashik.ali |
81 |
|
| 28353 |
amit.gupta |
82 |
private static Map<String, Integer> serialNumberOrderIdMap = new HashMap<>();
|
| 31030 |
amit.gupta |
83 |
|
| 28353 |
amit.gupta |
84 |
static {
|
|
|
85 |
serialNumberOrderIdMap.put("862897055749275", 67228);
|
|
|
86 |
}
|
| 31030 |
amit.gupta |
87 |
|
| 22859 |
ashik.ali |
88 |
@Autowired
|
| 23781 |
ashik.ali |
89 |
@Qualifier("fofoInventoryItemRepository")
|
| 22859 |
ashik.ali |
90 |
private InventoryItemRepository inventoryItemRepository;
|
| 27083 |
amit.gupta |
91 |
|
| 26817 |
amit.gupta |
92 |
@Autowired
|
|
|
93 |
private StateGstRateRepository stateGstRateRepository;
|
| 23650 |
amit.gupta |
94 |
|
| 23395 |
amit.gupta |
95 |
@Autowired
|
| 26891 |
amit.gupta |
96 |
private SaholicInventoryService saholicInventoryService;
|
| 27083 |
amit.gupta |
97 |
|
| 26891 |
amit.gupta |
98 |
@Autowired
|
| 24470 |
tejbeer |
99 |
private LiveDemoBillingRespository liveDemoBillingRespository;
|
| 24823 |
amit.gupta |
100 |
|
| 24470 |
tejbeer |
101 |
@Autowired
|
| 25724 |
amit.gupta |
102 |
private InsuranceService insuranceService;
|
|
|
103 |
|
|
|
104 |
@Autowired
|
| 23395 |
amit.gupta |
105 |
private WalletService walletService;
|
| 22859 |
ashik.ali |
106 |
|
|
|
107 |
@Autowired
|
| 23781 |
ashik.ali |
108 |
@Qualifier("fofoCurrentInventorySnapshotRepository")
|
| 22859 |
ashik.ali |
109 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
110 |
|
|
|
111 |
@Autowired
|
|
|
112 |
private InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
|
|
113 |
|
|
|
114 |
@Autowired
|
| 23655 |
amit.gupta |
115 |
private PurchaseReturnService purchaseReturnService;
|
|
|
116 |
|
|
|
117 |
@Autowired
|
|
|
118 |
private RetailerService retailerService;
|
|
|
119 |
|
|
|
120 |
@Autowired
|
| 22859 |
ashik.ali |
121 |
private CustomerRepository customerRepository;
|
| 23650 |
amit.gupta |
122 |
|
| 23566 |
amit.gupta |
123 |
@Autowired
|
|
|
124 |
private PurchaseReturnItemRepository purchaseReturnItemRepository;
|
| 22859 |
ashik.ali |
125 |
|
|
|
126 |
@Autowired
|
|
|
127 |
private AddressRepository addressRepository;
|
|
|
128 |
|
|
|
129 |
@Autowired
|
|
|
130 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
131 |
|
|
|
132 |
@Autowired
|
| 27516 |
amit.gupta |
133 |
private WarehouseInventoryItemRepository warehouseInventoryItemRepository;
|
|
|
134 |
|
|
|
135 |
@Autowired
|
| 22859 |
ashik.ali |
136 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 23650 |
amit.gupta |
137 |
|
| 22859 |
ashik.ali |
138 |
@Autowired
|
|
|
139 |
private PaymentOptionRepository paymentOptionRepository;
|
|
|
140 |
|
|
|
141 |
@Autowired
|
| 23650 |
amit.gupta |
142 |
private CustomerReturnItemRepository customerReturnItemRepository;
|
|
|
143 |
|
|
|
144 |
@Autowired
|
| 23781 |
ashik.ali |
145 |
@Qualifier("fofoScanRecordRepository")
|
| 22859 |
ashik.ali |
146 |
private ScanRecordRepository scanRecordRepository;
|
|
|
147 |
|
|
|
148 |
@Autowired
|
|
|
149 |
private FofoOrderRepository fofoOrderRepository;
|
|
|
150 |
|
|
|
151 |
@Autowired
|
|
|
152 |
private RetailerRepository retailerRepository;
|
|
|
153 |
|
|
|
154 |
@Autowired
|
|
|
155 |
private UserRepository userRepository;
|
|
|
156 |
|
|
|
157 |
@Autowired
|
|
|
158 |
private UserAccountRepository userAccountRepository;
|
|
|
159 |
|
|
|
160 |
@Autowired
|
|
|
161 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
162 |
|
|
|
163 |
@Autowired
|
|
|
164 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
165 |
|
|
|
166 |
@Autowired
|
| 23781 |
ashik.ali |
167 |
@Qualifier("catalogItemRepository")
|
| 22859 |
ashik.ali |
168 |
private ItemRepository itemRepository;
|
| 23650 |
amit.gupta |
169 |
|
| 22859 |
ashik.ali |
170 |
@Autowired
|
|
|
171 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 23650 |
amit.gupta |
172 |
|
| 22859 |
ashik.ali |
173 |
@Autowired
|
|
|
174 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 24917 |
tejbeer |
175 |
|
| 24854 |
amit.gupta |
176 |
@Autowired
|
|
|
177 |
private StateRepository stateRepository;
|
| 23650 |
amit.gupta |
178 |
|
| 22859 |
ashik.ali |
179 |
@Autowired
|
|
|
180 |
private PolicyNumberGenerationSequenceRepository policyNumberGenerationSequenceRepository;
|
| 23650 |
amit.gupta |
181 |
|
| 22859 |
ashik.ali |
182 |
@Autowired
|
|
|
183 |
private PricingService pricingService;
|
| 23650 |
amit.gupta |
184 |
|
| 22859 |
ashik.ali |
185 |
@Autowired
|
|
|
186 |
private PrivateDealUserRepository privateDealUserRepository;
|
| 23650 |
amit.gupta |
187 |
|
| 22859 |
ashik.ali |
188 |
@Autowired
|
| 24823 |
amit.gupta |
189 |
private TagListingRepository tagListingRepository;
|
|
|
190 |
|
|
|
191 |
@Autowired
|
| 22859 |
ashik.ali |
192 |
private CounterRepository counterRepository;
|
| 23650 |
amit.gupta |
193 |
|
| 22859 |
ashik.ali |
194 |
@Autowired
|
| 23202 |
ashik.ali |
195 |
private FofoStoreRepository fofoStoreRepository;
|
| 23650 |
amit.gupta |
196 |
|
| 23202 |
ashik.ali |
197 |
@Autowired
|
| 23546 |
ashik.ali |
198 |
private PaymentOptionTransactionRepository paymentOptionTransactionRepository;
|
| 23650 |
amit.gupta |
199 |
|
| 23365 |
ashik.ali |
200 |
@Autowired
|
| 22859 |
ashik.ali |
201 |
private SchemeService schemeService;
|
| 23650 |
amit.gupta |
202 |
|
| 27522 |
amit.gupta |
203 |
private static final List<Integer> orderIdsConsumed = new ArrayList<>();
|
| 28166 |
tejbeer |
204 |
|
| 23418 |
ashik.ali |
205 |
@Autowired
|
| 23781 |
ashik.ali |
206 |
@Qualifier("fofoInventoryService")
|
| 23418 |
ashik.ali |
207 |
private InventoryService inventoryService;
|
| 23650 |
amit.gupta |
208 |
|
| 23418 |
ashik.ali |
209 |
@Autowired
|
| 23650 |
amit.gupta |
210 |
private CustomerCreditNoteRepository customerCreditNoteRepository;
|
|
|
211 |
|
| 24917 |
tejbeer |
212 |
@Autowired
|
|
|
213 |
private OrderRepository orderRepository;
|
|
|
214 |
|
| 25640 |
tejbeer |
215 |
@Autowired
|
|
|
216 |
private HygieneDataRepository hygieneDataRepository;
|
|
|
217 |
|
| 28166 |
tejbeer |
218 |
@Autowired
|
|
|
219 |
private SessionFactory sessionFactory;
|
|
|
220 |
|
|
|
221 |
@Autowired
|
|
|
222 |
private Mongo mongoClient;
|
| 28964 |
tejbeer |
223 |
|
| 28339 |
tejbeer |
224 |
@Autowired
|
|
|
225 |
private PendingOrderRepository pendingOrderRepository;
|
| 28964 |
tejbeer |
226 |
|
| 28339 |
tejbeer |
227 |
@Autowired
|
|
|
228 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
| 28166 |
tejbeer |
229 |
|
| 29515 |
tejbeer |
230 |
@Autowired
|
|
|
231 |
private ScratchOfferRepository scratchOfferRepository;
|
|
|
232 |
|
|
|
233 |
@Autowired
|
|
|
234 |
RestClient restClient;
|
|
|
235 |
|
|
|
236 |
@Value("${prod}")
|
|
|
237 |
private boolean prodEnv;
|
|
|
238 |
|
|
|
239 |
private static final String SMS_GATEWAY = "http://api.pinnacle.in/index.php/sms/send";
|
|
|
240 |
private static final String SENDER = "SMTDKN";
|
|
|
241 |
|
|
|
242 |
public static final String APP_DOWNLOAD_BILLING_TEMPLATE_ID = "1507163542403945677";
|
|
|
243 |
|
|
|
244 |
public static final String APP_DOWNLOAD_BILLING_OFFER = "Dear Customer, Thank you for purchasing from SmartDukaan pls click %s to download our app to see you invoice and special offers. SmartDukaan";
|
|
|
245 |
|
| 22859 |
ashik.ali |
246 |
@Override
|
| 24275 |
amit.gupta |
247 |
public int createOrder(CreateOrderRequest createOrderRequest, int fofoId, boolean accessoriesDeals)
|
|
|
248 |
throws ProfitMandiBusinessException {
|
| 25724 |
amit.gupta |
249 |
LOGGER.info("fofoId -- {} Order Request -- {}", fofoId, createOrderRequest);
|
| 22872 |
ashik.ali |
250 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
|
|
251 |
|
| 23650 |
amit.gupta |
252 |
if (!StringUtils.isValidGstNumber(customCustomer.getGstNumber())) {
|
| 23369 |
ashik.ali |
253 |
LOGGER.error("invalid customer gstNumber {} ", customCustomer.getGstNumber());
|
| 23650 |
amit.gupta |
254 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.CUSTOMER_GST_NUMBER,
|
|
|
255 |
customCustomer.getGstNumber(), "VE_1072");
|
| 23369 |
ashik.ali |
256 |
}
|
| 23650 |
amit.gupta |
257 |
|
|
|
258 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); // this is for error
|
| 22872 |
ashik.ali |
259 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap = new HashMap<>();
|
| 23650 |
amit.gupta |
260 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); // this is for pricing error
|
|
|
261 |
|
| 22859 |
ashik.ali |
262 |
float totalAmount = 0;
|
| 24226 |
amit.gupta |
263 |
boolean noGST = false;
|
| 23650 |
amit.gupta |
264 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
|
|
265 |
// itemIds.add(customFofoOrderItem.getItemId());
|
|
|
266 |
Set<String> serialNumbers = this
|
|
|
267 |
.serialNumberDetailsToSerialNumbers(customFofoOrderItem.getSerialNumberDetails());
|
|
|
268 |
if (!serialNumbers.isEmpty() && customFofoOrderItem.getQuantity() != serialNumbers.size()) {
|
| 22859 |
ashik.ali |
269 |
itemIdQuantity.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getQuantity());
|
|
|
270 |
}
|
| 23650 |
amit.gupta |
271 |
if (!(customFofoOrderItem.getSellingPrice() > 0)) {
|
| 22859 |
ashik.ali |
272 |
lineItemPrice.put(customFofoOrderItem.getItemId(), customFofoOrderItem.getSellingPrice());
|
| 23650 |
amit.gupta |
273 |
} else {
|
| 22863 |
ashik.ali |
274 |
totalAmount = totalAmount + customFofoOrderItem.getSellingPrice() * customFofoOrderItem.getQuantity();
|
| 23650 |
amit.gupta |
275 |
for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
|
| 24440 |
amit.gupta |
276 |
if (serialNumberDetail.getAmount() > 0) {
|
| 22859 |
ashik.ali |
277 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
}
|
| 23650 |
amit.gupta |
281 |
|
| 22872 |
ashik.ali |
282 |
itemIdCustomFofoOrderItemMap.put(customFofoOrderItem.getItemId(), customFofoOrderItem);
|
| 22859 |
ashik.ali |
283 |
}
|
| 23650 |
amit.gupta |
284 |
if (!itemIdQuantity.isEmpty()) {
|
| 22859 |
ashik.ali |
285 |
// if item quantity does not match with given serialnumbers size
|
|
|
286 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
| 22925 |
ashik.ali |
287 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "FFORDR_1001");
|
| 23650 |
amit.gupta |
288 |
// return "error";
|
| 22859 |
ashik.ali |
289 |
}
|
| 23650 |
amit.gupta |
290 |
|
| 24275 |
amit.gupta |
291 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
|
| 23650 |
amit.gupta |
292 |
|
|
|
293 |
if (!lineItemPrice.isEmpty()) {
|
| 22859 |
ashik.ali |
294 |
// given fofo line item price must be greater than zero
|
|
|
295 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
| 22925 |
ashik.ali |
296 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PRICE, lineItemPrice, "FFORDR_1002");
|
| 22859 |
ashik.ali |
297 |
}
|
|
|
298 |
|
| 23650 |
amit.gupta |
299 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
300 |
.selectByFofoItemIds(fofoId, itemIdCustomFofoOrderItemMap.keySet());
|
|
|
301 |
|
| 22872 |
ashik.ali |
302 |
this.validateCurrentInventorySnapshotQuantities(currentInventorySnapshots, itemIdCustomFofoOrderItemMap);
|
| 22859 |
ashik.ali |
303 |
|
| 22872 |
ashik.ali |
304 |
List<Item> items = itemRepository.selectByIds(itemIdCustomFofoOrderItemMap.keySet());
|
| 23650 |
amit.gupta |
305 |
if (items.size() != itemIdCustomFofoOrderItemMap.keySet().size()) {
|
| 22872 |
ashik.ali |
306 |
LOGGER.error("Requested ItemIds not found in catalog");
|
| 23650 |
amit.gupta |
307 |
// invalid itemIds
|
|
|
308 |
throw new ProfitMandiBusinessException("invalidItemIds", itemIdCustomFofoOrderItemMap.keySet(),
|
|
|
309 |
"FFORDR_1003");
|
| 22872 |
ashik.ali |
310 |
}
|
| 23650 |
amit.gupta |
311 |
|
|
|
312 |
Map<Integer, Item> itemMap = this.toItemMap(items);
|
|
|
313 |
|
| 22859 |
ashik.ali |
314 |
Set<Integer> nonSerializedItemIds = new HashSet<>();
|
|
|
315 |
Set<String> serialNumbers = new HashSet<>();
|
| 25724 |
amit.gupta |
316 |
List<InsuranceModel> insuredModels = new ArrayList<>();
|
| 23650 |
amit.gupta |
317 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
| 22872 |
ashik.ali |
318 |
Item item = itemMap.get(customFofoOrderItem.getItemId());
|
| 24275 |
amit.gupta |
319 |
noGST = item.getHsnCode().equals("NOGST");
|
| 23650 |
amit.gupta |
320 |
if (item.getType().equals(ItemType.SERIALIZED)) {
|
|
|
321 |
for (SerialNumberDetail serialNumberDetail : customFofoOrderItem.getSerialNumberDetails()) {
|
| 22859 |
ashik.ali |
322 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
| 24440 |
amit.gupta |
323 |
if (serialNumberDetail.getAmount() > 0) {
|
|
|
324 |
InsuranceModel im = new InsuranceModel();
|
|
|
325 |
im.setBrand(item.getBrand());
|
| 25724 |
amit.gupta |
326 |
im.setColor(item.getColor());
|
|
|
327 |
im.setModelName(item.getModelName() + item.getModelNumber());
|
| 24440 |
amit.gupta |
328 |
im.setInsuranceAmount(serialNumberDetail.getAmount());
|
|
|
329 |
im.setDeviceSellingPrice(customFofoOrderItem.getSellingPrice());
|
| 25724 |
amit.gupta |
330 |
im.setInsuranceId(serialNumberDetail.getInsurance());
|
|
|
331 |
im.setSerialNumber(serialNumberDetail.getSerialNumber());
|
| 25793 |
amit.gupta |
332 |
im.setMemory(serialNumberDetail.getMemory());
|
|
|
333 |
im.setRam(serialNumberDetail.getRam());
|
| 25778 |
amit.gupta |
334 |
im.setMfgDate(serialNumberDetail.getMfgDate());
|
| 25724 |
amit.gupta |
335 |
insuredModels.add(im);
|
| 22859 |
ashik.ali |
336 |
}
|
|
|
337 |
}
|
| 23650 |
amit.gupta |
338 |
} else {
|
| 22872 |
ashik.ali |
339 |
nonSerializedItemIds.add(customFofoOrderItem.getItemId());
|
| 22859 |
ashik.ali |
340 |
}
|
|
|
341 |
}
|
| 23650 |
amit.gupta |
342 |
|
| 22859 |
ashik.ali |
343 |
Map<Integer, Set<InventoryItem>> serializedInventoryItemMap = new HashMap<>();
|
|
|
344 |
Map<Integer, Set<InventoryItem>> nonSerializedInventoryItemMap = new HashMap<>();
|
| 23650 |
amit.gupta |
345 |
// Map<String, Float> serialNumberItemPrice = new HashMap<>();
|
|
|
346 |
|
|
|
347 |
if (!serialNumbers.isEmpty()) {
|
|
|
348 |
List<InventoryItem> serializedInventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoId,
|
| 23968 |
amit.gupta |
349 |
serialNumbers, false);
|
| 23397 |
amit.gupta |
350 |
LOGGER.info("serializedInventoryItems {}", serializedInventoryItems);
|
| 23650 |
amit.gupta |
351 |
for (InventoryItem inventoryItem : serializedInventoryItems) {
|
|
|
352 |
if (inventoryItem.getGoodQuantity() == 1) {
|
|
|
353 |
if (serializedInventoryItemMap.containsKey(inventoryItem.getItemId())) {
|
| 23397 |
amit.gupta |
354 |
serializedInventoryItemMap.get(inventoryItem.getItemId()).add(inventoryItem);
|
| 23650 |
amit.gupta |
355 |
} else {
|
| 23397 |
amit.gupta |
356 |
Set<InventoryItem> itemIdInventoryItems = new HashSet<>();
|
|
|
357 |
itemIdInventoryItems.add(inventoryItem);
|
|
|
358 |
serializedInventoryItemMap.put(inventoryItem.getItemId(), itemIdInventoryItems);
|
|
|
359 |
}
|
|
|
360 |
}
|
|
|
361 |
}
|
|
|
362 |
}
|
| 23418 |
ashik.ali |
363 |
|
| 23650 |
amit.gupta |
364 |
if (!nonSerializedItemIds.isEmpty()) {
|
|
|
365 |
List<InventoryItem> nonSerializedInventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoId,
|
|
|
366 |
nonSerializedItemIds);
|
| 22872 |
ashik.ali |
367 |
LOGGER.info("nonSerializedInventoryItems {}", nonSerializedInventoryItems);
|
| 23650 |
amit.gupta |
368 |
for (InventoryItem it : nonSerializedInventoryItems) {
|
|
|
369 |
if (it.getGoodQuantity() > 0) {
|
|
|
370 |
if (nonSerializedInventoryItemMap.containsKey(it.getItemId())) {
|
| 22859 |
ashik.ali |
371 |
nonSerializedInventoryItemMap.get(it.getItemId()).add(it);
|
| 23650 |
amit.gupta |
372 |
} else {
|
| 22859 |
ashik.ali |
373 |
Set<InventoryItem> tmp = new HashSet<>();
|
|
|
374 |
tmp.add(it);
|
|
|
375 |
nonSerializedInventoryItemMap.put(it.getItemId(), tmp);
|
|
|
376 |
}
|
|
|
377 |
}
|
|
|
378 |
}
|
|
|
379 |
}
|
| 23650 |
amit.gupta |
380 |
|
| 22872 |
ashik.ali |
381 |
this.validateItemsSerializedNonSerialized(items, itemIdCustomFofoOrderItemMap);
|
| 22859 |
ashik.ali |
382 |
|
|
|
383 |
Map<Integer, Set<InventoryItem>> inventoryItemsToBill = new HashMap<>();
|
| 23650 |
amit.gupta |
384 |
Map<Integer, Integer> inventoryItemIdQuantityUsed = new HashMap<>(); // to keep track of inventoryitem quanity
|
| 31030 |
amit.gupta |
385 |
// used for scan records insertion
|
| 22859 |
ashik.ali |
386 |
|
|
|
387 |
LOGGER.info("itemMap keys {}", itemMap.keySet());
|
| 23650 |
amit.gupta |
388 |
// Lets reduce quantity and decide what inventory items to use.
|
|
|
389 |
for (Item item : items) {
|
|
|
390 |
if (item.getType().equals(ItemType.SERIALIZED)) {
|
|
|
391 |
// TODO:handle null
|
|
|
392 |
if (serializedInventoryItemMap.get(item.getId()) == null
|
|
|
393 |
|| itemIdCustomFofoOrderItemMap.get(item.getId()).getSerialNumberDetails()
|
| 31030 |
amit.gupta |
394 |
.size() != serializedInventoryItemMap.get(item.getId()).size()) {
|
| 24440 |
amit.gupta |
395 |
|
|
|
396 |
List<String> invalidSerialNumbers = itemIdCustomFofoOrderItemMap.get(item.getId())
|
|
|
397 |
.getSerialNumberDetails().stream().map(x -> x.getSerialNumber())
|
|
|
398 |
.collect(Collectors.toList());
|
|
|
399 |
throw new ProfitMandiBusinessException("invalidSerialNumbers", invalidSerialNumbers, "FFORDR_1004");
|
| 22872 |
ashik.ali |
400 |
}
|
| 24470 |
tejbeer |
401 |
List<String> serialNumberList = liveDemoBillingRespository.selectAllSerialNumber();
|
| 24823 |
amit.gupta |
402 |
|
| 22859 |
ashik.ali |
403 |
Set<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(item.getId());
|
| 23650 |
amit.gupta |
404 |
for (InventoryItem inventoryItem : inventoryItemsSerializedserialized) {
|
| 22872 |
ashik.ali |
405 |
inventoryItem.setGoodQuantity(0);
|
|
|
406 |
inventoryItemIdQuantityUsed.put(inventoryItem.getId(), 1);
|
| 24823 |
amit.gupta |
407 |
if (serialNumberList.contains(inventoryItem.getSerialNumber())) {
|
|
|
408 |
LiveDemoSerialNumber liveDemoSerialNumber = liveDemoBillingRespository
|
|
|
409 |
.selectBySerialNumber(inventoryItem.getSerialNumber());
|
| 24470 |
tejbeer |
410 |
liveDemoBillingRespository.delete(liveDemoSerialNumber);
|
|
|
411 |
}
|
| 22859 |
ashik.ali |
412 |
}
|
|
|
413 |
inventoryItemsToBill.put(item.getId(), inventoryItemsSerializedserialized);
|
| 23650 |
amit.gupta |
414 |
} else {
|
| 22859 |
ashik.ali |
415 |
Set<InventoryItem> inventoryItemsNonSerialized = nonSerializedInventoryItemMap.get(item.getId());
|
| 22872 |
ashik.ali |
416 |
int quantityToBill = itemIdCustomFofoOrderItemMap.get(item.getId()).getQuantity();
|
| 22859 |
ashik.ali |
417 |
int totalLeft = quantityToBill;
|
|
|
418 |
Set<InventoryItem> inventoryItemsNonSerializedUsed = new HashSet<>();
|
| 23650 |
amit.gupta |
419 |
if (inventoryItemsNonSerialized != null) {
|
|
|
420 |
for (InventoryItem inventoryItem : inventoryItemsNonSerialized) {
|
|
|
421 |
if (totalLeft > 0) {
|
| 22859 |
ashik.ali |
422 |
int toUse = Math.min(totalLeft, inventoryItem.getGoodQuantity());
|
|
|
423 |
inventoryItemIdQuantityUsed.put(inventoryItem.getId(), toUse);
|
| 23650 |
amit.gupta |
424 |
inventoryItem.setGoodQuantity(inventoryItem.getGoodQuantity() - toUse);
|
| 22859 |
ashik.ali |
425 |
totalLeft = totalLeft - toUse;
|
|
|
426 |
inventoryItemsNonSerializedUsed.add(inventoryItem);
|
|
|
427 |
}
|
|
|
428 |
}
|
|
|
429 |
}
|
| 23650 |
amit.gupta |
430 |
|
|
|
431 |
if (totalLeft > 0) {
|
|
|
432 |
// not enough quanity for non-serialized
|
| 22859 |
ashik.ali |
433 |
LOGGER.error("not enough quanity for non-serialized");
|
| 23650 |
amit.gupta |
434 |
throw new ProfitMandiBusinessException("notEnoughQuantityForNonSerialized", totalLeft,
|
|
|
435 |
"FFORDR_1005");
|
| 22859 |
ashik.ali |
436 |
}
|
|
|
437 |
inventoryItemsToBill.put(item.getId(), inventoryItemsNonSerializedUsed);
|
|
|
438 |
}
|
|
|
439 |
}
|
| 23650 |
amit.gupta |
440 |
|
|
|
441 |
Map<Integer, PriceModel> itemIdMopPriceMap = pricingService
|
|
|
442 |
.getPurchasePriceMopPriceNotFound(itemIdCustomFofoOrderItemMap.keySet(), fofoId);
|
| 28964 |
tejbeer |
443 |
LOGGER.info("itemIdMopMap {}", itemIdMopPriceMap);
|
| 24275 |
amit.gupta |
444 |
if (accessoriesDeals) {
|
| 23823 |
amit.gupta |
445 |
this.validateDpPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
|
|
446 |
} else {
|
|
|
447 |
this.validateMopPrice(itemIdMopPriceMap, itemIdCustomFofoOrderItemMap);
|
|
|
448 |
}
|
| 23650 |
amit.gupta |
449 |
|
| 23202 |
ashik.ali |
450 |
String fofoStoreCode = this.getFofoStoreCode(fofoId);
|
| 24226 |
amit.gupta |
451 |
String documentNumber = null;
|
| 24275 |
amit.gupta |
452 |
if (noGST) {
|
| 24226 |
amit.gupta |
453 |
documentNumber = this.getSecurityDepositNumber(fofoId, fofoStoreCode);
|
| 24275 |
amit.gupta |
454 |
|
| 24226 |
amit.gupta |
455 |
} else {
|
|
|
456 |
documentNumber = this.getInvoiceNumber(fofoId, fofoStoreCode);
|
|
|
457 |
}
|
| 22859 |
ashik.ali |
458 |
|
| 26817 |
amit.gupta |
459 |
Customer customer = customerRepository.selectById(customCustomer.getCustomerId());
|
| 23650 |
amit.gupta |
460 |
|
| 27083 |
amit.gupta |
461 |
CustomerAddress customerAddress = customer.getCustomerAddress().stream()
|
|
|
462 |
.filter(x -> x.getId() == customCustomer.getCustomerAddressId()).findFirst().get();
|
| 23650 |
amit.gupta |
463 |
|
|
|
464 |
FofoOrder fofoOrder = this.createAndGetFofoOrder(customer.getId(), customCustomer.getGstNumber(), fofoId,
|
| 24226 |
amit.gupta |
465 |
documentNumber, totalAmount, customerAddress.getId());
|
| 23650 |
amit.gupta |
466 |
|
| 23612 |
amit.gupta |
467 |
this.createPaymentOptions(fofoOrder, createOrderRequest.getPaymentOptions());
|
| 23650 |
amit.gupta |
468 |
|
| 23172 |
ashik.ali |
469 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
|
| 23650 |
amit.gupta |
470 |
|
| 23172 |
ashik.ali |
471 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 23650 |
amit.gupta |
472 |
|
| 23172 |
ashik.ali |
473 |
Integer stateId = null;
|
| 23650 |
amit.gupta |
474 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
475 |
try {
|
| 28978 |
amit.gupta |
476 |
State state = stateRepository.selectByName(customerAddress.getState());
|
|
|
477 |
stateId = Long.valueOf(state.getId()).intValue();
|
| 23650 |
amit.gupta |
478 |
} catch (Exception e) {
|
| 23172 |
ashik.ali |
479 |
LOGGER.error("Unable to get state rates");
|
|
|
480 |
}
|
|
|
481 |
}
|
| 23650 |
amit.gupta |
482 |
|
|
|
483 |
for (CustomFofoOrderItem customFofoOrderItem : createOrderRequest.getFofoOrderItems()) {
|
|
|
484 |
FofoOrderItem fofoOrderItem = this.createAndGetFofoOrderItem(customFofoOrderItem, fofoOrder.getId(),
|
|
|
485 |
itemMap, inventoryItemsToBill.get(customFofoOrderItem.getItemId()), stateId);
|
|
|
486 |
|
| 22859 |
ashik.ali |
487 |
Set<InventoryItem> inventoryItems = inventoryItemsToBill.get(customFofoOrderItem.getItemId());
|
| 23650 |
amit.gupta |
488 |
|
| 22859 |
ashik.ali |
489 |
this.createFofoLineItem(fofoOrderItem.getId(), inventoryItems, inventoryItemIdQuantityUsed);
|
| 23650 |
amit.gupta |
490 |
|
|
|
491 |
this.updateCurrentInventorySnapshot(currentInventorySnapshots, fofoId, customFofoOrderItem.getItemId(),
|
|
|
492 |
customFofoOrderItem.getQuantity());
|
|
|
493 |
|
| 24275 |
amit.gupta |
494 |
this.updateInventoryItemsAndScanRecord(inventoryItems, fofoId, inventoryItemIdQuantityUsed,
|
|
|
495 |
fofoOrder.getId());
|
| 22859 |
ashik.ali |
496 |
}
|
| 23650 |
amit.gupta |
497 |
|
| 25647 |
tejbeer |
498 |
List<FofoOrderItem> fofoItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
499 |
|
|
|
500 |
for (FofoOrderItem fofoItem : fofoItems) {
|
|
|
501 |
Item orderItem = itemRepository.selectById(fofoItem.getItemId());
|
|
|
502 |
if (orderItem.getCategoryId() == ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
|
|
503 |
this.createAndGetHygieneData(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
504 |
}
|
|
|
505 |
}
|
| 22859 |
ashik.ali |
506 |
// insurance calculation is insurance flag is enabled
|
| 24440 |
amit.gupta |
507 |
//
|
| 25724 |
amit.gupta |
508 |
if (insuredModels.size() > 0) {
|
| 24440 |
amit.gupta |
509 |
LOGGER.info("Processing insurane for serialNumbers");
|
| 27734 |
amit.gupta |
510 |
LOGGER.info("InsuranceModels {}", insuredModels);
|
| 24440 |
amit.gupta |
511 |
LocalDate customerDateOfBirth = LocalDate.from(createOrderRequest.getCustomer().getDateOfBirth());
|
| 25724 |
amit.gupta |
512 |
fofoOrder.setDateOfBirth(customerDateOfBirth);
|
|
|
513 |
for (InsuranceModel insuranceModel : insuredModels) {
|
| 29524 |
amit.gupta |
514 |
insuranceService.createInsurance(fofoOrder, insuranceModel);
|
| 22859 |
ashik.ali |
515 |
}
|
|
|
516 |
}
|
| 25686 |
amit.gupta |
517 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoId);
|
| 28339 |
tejbeer |
518 |
|
|
|
519 |
if (createOrderRequest.getPoId() != 0) {
|
|
|
520 |
PendingOrder po = pendingOrderRepository.selectById(createOrderRequest.getPoId());
|
|
|
521 |
po.setBilledAmount(po.getBilledAmount() + totalAmount);
|
|
|
522 |
PendingOrderItem poi = pendingOrderItemRepository.selectById(createOrderRequest.getPoItemId());
|
|
|
523 |
poi.setStatus(OrderStatus.BILLED);
|
|
|
524 |
poi.setBilledTimestamp(LocalDateTime.now());
|
|
|
525 |
}
|
| 29515 |
tejbeer |
526 |
|
|
|
527 |
LocalDate startDate = LocalDate.of(2021, 10, 29);
|
|
|
528 |
LocalDate endDate = LocalDate.of(2021, 11, 8);
|
|
|
529 |
|
|
|
530 |
if (LocalDateTime.now().isAfter(startDate.atStartOfDay())
|
|
|
531 |
&& LocalDateTime.now().isBefore(endDate.atStartOfDay())) {
|
|
|
532 |
|
|
|
533 |
try {
|
|
|
534 |
this.sendAppDownloadBillingOffer(customer.getMobileNumber());
|
|
|
535 |
} catch (Exception e) {
|
|
|
536 |
// TODO Auto-generated catch block
|
|
|
537 |
e.printStackTrace();
|
|
|
538 |
}
|
|
|
539 |
this.createScratchOffer(fofoOrder.getInvoiceNumber(), fofoOrder.getCustomerId());
|
|
|
540 |
}
|
| 22859 |
ashik.ali |
541 |
return fofoOrder.getId();
|
|
|
542 |
}
|
| 23650 |
amit.gupta |
543 |
|
| 29515 |
tejbeer |
544 |
public void sendAppDownloadBillingOffer(String mobileNumber) throws Exception {
|
|
|
545 |
// In case of Cant receive SMS?
|
|
|
546 |
// String mailMessage = java.text.MessageFormat.format(text, otp.getOtp());
|
|
|
547 |
String sdurl = "http://surl.li/anhfn";
|
|
|
548 |
try {
|
|
|
549 |
if (prodEnv) {
|
|
|
550 |
this.sendSms(APP_DOWNLOAD_BILLING_TEMPLATE_ID, String.format(APP_DOWNLOAD_BILLING_OFFER, sdurl),
|
|
|
551 |
mobileNumber);
|
|
|
552 |
}
|
|
|
553 |
} catch (Exception e) {
|
|
|
554 |
e.printStackTrace();
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
public void sendSms(String dltTemplateId, String message, String mobileNumber) throws Exception {
|
|
|
560 |
Map<String, String> map = new HashMap<>();
|
|
|
561 |
|
|
|
562 |
map.put("sender", SENDER);
|
|
|
563 |
map.put("messagetype", "TXT");
|
|
|
564 |
map.put("apikey", "b866f7-c6c483-682ff5-054420-ad9e2c");
|
|
|
565 |
|
|
|
566 |
map.put("numbers", "91" + mobileNumber);
|
|
|
567 |
LOGGER.info("Message {}", message);
|
|
|
568 |
// OTP Message Template
|
|
|
569 |
map.put("message", message);
|
|
|
570 |
map.put("dlttempid", dltTemplateId);
|
|
|
571 |
|
|
|
572 |
String response = restClient.post(SMS_GATEWAY, map, new HashMap<>());
|
|
|
573 |
LOGGER.info(response);
|
|
|
574 |
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
private void createScratchOffer(String invoiceNumber, int customerId) {
|
|
|
578 |
|
|
|
579 |
ScratchOffer so = new ScratchOffer();
|
|
|
580 |
so.setInvoiceNumber(invoiceNumber);
|
|
|
581 |
so.setOfferName(ScratchedGift.OTSR);
|
|
|
582 |
so.setScratched(false);
|
|
|
583 |
so.setCreatedTimestamp(LocalDateTime.now());
|
|
|
584 |
so.setExpiredTimestamp(so.getCreatedTimestamp().plusDays(1));
|
|
|
585 |
so.setUnlockedAt(LocalDateTime.now());
|
|
|
586 |
so.setCustomerId(customerId);
|
|
|
587 |
scratchOfferRepository.persist(so);
|
|
|
588 |
|
|
|
589 |
ScratchOffer so2 = new ScratchOffer();
|
|
|
590 |
so2.setInvoiceNumber(invoiceNumber);
|
|
|
591 |
so2.setScratched(false);
|
|
|
592 |
so2.setCreatedTimestamp(LocalDateTime.now());
|
|
|
593 |
so2.setExpiredTimestamp(so.getCreatedTimestamp().plusDays(1));
|
| 29539 |
tejbeer |
594 |
so2.setOfferName(ScratchedGift.ADTL);
|
| 29515 |
tejbeer |
595 |
so2.setCustomerId(customerId);
|
|
|
596 |
so2.setUnlockedAt(LocalDate.now().plusDays(1).atStartOfDay());
|
|
|
597 |
scratchOfferRepository.persist(so2);
|
|
|
598 |
|
|
|
599 |
}
|
|
|
600 |
|
| 25640 |
tejbeer |
601 |
private HygieneData createAndGetHygieneData(int id, int fofoId) {
|
|
|
602 |
HygieneData hygieneData = new HygieneData();
|
|
|
603 |
hygieneData.setOrderId(id);
|
|
|
604 |
hygieneData.setFofoId(fofoId);
|
|
|
605 |
hygieneData.setCreatedTimestamp(LocalDateTime.now());
|
|
|
606 |
hygieneDataRepository.persist(hygieneData);
|
|
|
607 |
|
|
|
608 |
return hygieneData;
|
|
|
609 |
}
|
|
|
610 |
|
| 24807 |
amit.gupta |
611 |
@Override
|
|
|
612 |
public String getInvoiceNumber(int fofoId, String fofoStoreCode) {
|
| 24236 |
amit.gupta |
613 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
|
|
|
614 |
try {
|
|
|
615 |
invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
|
|
|
616 |
invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
|
|
|
617 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
618 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
|
|
619 |
invoiceNumberGenerationSequence.setFofoId(fofoId);
|
|
|
620 |
invoiceNumberGenerationSequence.setPrefix(fofoStoreCode);
|
|
|
621 |
invoiceNumberGenerationSequence.setSequence(1);
|
|
|
622 |
}
|
|
|
623 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
|
|
624 |
return invoiceNumberGenerationSequence.getPrefix() + "/" + invoiceNumberGenerationSequence.getSequence();
|
|
|
625 |
}
|
| 24275 |
amit.gupta |
626 |
|
|
|
627 |
private String getSecurityDepositNumber(int fofoId, String fofoStoreCode) {
|
| 24226 |
amit.gupta |
628 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
|
|
|
629 |
try {
|
|
|
630 |
invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoId);
|
| 24275 |
amit.gupta |
631 |
invoiceNumberGenerationSequence
|
|
|
632 |
.setChallanNumberSequence(invoiceNumberGenerationSequence.getChallanNumberSequence() + 1);
|
| 24226 |
amit.gupta |
633 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
634 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
|
|
635 |
invoiceNumberGenerationSequence.setFofoId(fofoId);
|
|
|
636 |
invoiceNumberGenerationSequence.setPrefix(fofoStoreCode);
|
|
|
637 |
invoiceNumberGenerationSequence.setChallanNumberSequence(1);
|
|
|
638 |
}
|
|
|
639 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
| 24275 |
amit.gupta |
640 |
return invoiceNumberGenerationSequence.getPrefix() + "/SEC"
|
|
|
641 |
+ invoiceNumberGenerationSequence.getChallanNumberSequence();
|
| 24226 |
amit.gupta |
642 |
}
|
|
|
643 |
|
| 23650 |
amit.gupta |
644 |
private Set<String> serialNumberDetailsToSerialNumbers(Set<SerialNumberDetail> serialNumberDetails) {
|
| 23377 |
ashik.ali |
645 |
Set<String> serialNumbers = new HashSet<>();
|
| 23650 |
amit.gupta |
646 |
for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
|
|
|
647 |
if (serialNumberDetail.getSerialNumber() != null && !serialNumberDetail.getSerialNumber().isEmpty()) {
|
| 23377 |
ashik.ali |
648 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
|
|
649 |
}
|
|
|
650 |
}
|
|
|
651 |
return serialNumbers;
|
|
|
652 |
}
|
| 23650 |
amit.gupta |
653 |
|
| 22859 |
ashik.ali |
654 |
@Override
|
| 30321 |
amit.gupta |
655 |
public InvoicePdfModel getInvoicePdfModel(int orderId) throws ProfitMandiBusinessException {
|
| 23596 |
ashik.ali |
656 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
|
|
657 |
return this.getInvoicePdfModel(fofoOrder);
|
|
|
658 |
}
|
| 23650 |
amit.gupta |
659 |
|
| 27516 |
amit.gupta |
660 |
@Override
|
|
|
661 |
@Cacheable(value = "order.dummymodel", cacheManager = "oneDayCacheManager")
|
| 30321 |
amit.gupta |
662 |
public InvoicePdfModel getDummyPdfModel(String serialNumber) throws ProfitMandiBusinessException {
|
| 27516 |
amit.gupta |
663 |
List<WarehouseInventoryItem> warehouseInventoryItems = warehouseInventoryItemRepository
|
|
|
664 |
.selectWarehouseInventoryItemBySerailNumbers(Arrays.asList(serialNumber));
|
|
|
665 |
if (warehouseInventoryItems.size() > 0) {
|
|
|
666 |
WarehouseInventoryItem warehouseInventoryItem = warehouseInventoryItems.get(0);
|
|
|
667 |
int currentQuantity = warehouseInventoryItems.get(0).getCurrentQuantity();
|
|
|
668 |
if (currentQuantity > 0) {
|
|
|
669 |
throw new ProfitMandiBusinessException("Serial Number", serialNumber,
|
|
|
670 |
"Serial Number exist in our warehouse");
|
|
|
671 |
} else {
|
|
|
672 |
try {
|
|
|
673 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumber(serialNumber);
|
|
|
674 |
if (inventoryItem.getGoodQuantity() > 0) {
|
|
|
675 |
throw new ProfitMandiBusinessException("Serial Number", serialNumber,
|
|
|
676 |
"Serial Number is not yet billed by the partner");
|
|
|
677 |
} else {
|
|
|
678 |
List<ScanRecord> scanRecords = scanRecordRepository
|
|
|
679 |
.selectByInventoryItemId(inventoryItem.getId());
|
|
|
680 |
Optional<ScanRecord> scanRecord = scanRecords.stream().filter(x -> x.getOrderId() != 0)
|
|
|
681 |
.findFirst();
|
|
|
682 |
if (scanRecord.isPresent()) {
|
|
|
683 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.get().getOrderId());
|
| 27522 |
amit.gupta |
684 |
orderIdsConsumed.add(fofoOrder.getId());
|
| 27516 |
amit.gupta |
685 |
return this.getInvoicePdfModel(fofoOrder);
|
|
|
686 |
} else {
|
|
|
687 |
throw new ProfitMandiBusinessException("Serial Number", serialNumber,
|
|
|
688 |
"Serial Number returned by partner, but in transit");
|
|
|
689 |
}
|
|
|
690 |
}
|
|
|
691 |
} catch (Exception e) {
|
| 28353 |
amit.gupta |
692 |
int itemId = warehouseInventoryItem.getItemId();
|
| 28964 |
tejbeer |
693 |
if (serialNumberOrderIdMap.containsKey(serialNumber)) {
|
|
|
694 |
FofoOrder fofoOrder = fofoOrderRepository
|
|
|
695 |
.selectByOrderId(serialNumberOrderIdMap.get(serialNumber));
|
| 30321 |
amit.gupta |
696 |
InvoicePdfModel pdfModel = this.getInvoicePdfModel(fofoOrder.getId());
|
| 28353 |
amit.gupta |
697 |
this.modifyDummyModel(fofoOrder, pdfModel, itemId, serialNumber);
|
|
|
698 |
return pdfModel;
|
|
|
699 |
}
|
| 27516 |
amit.gupta |
700 |
// Map this serialNumber for dummy billing
|
|
|
701 |
LocalDateTime grnDate = warehouseInventoryItem.getCreated();
|
|
|
702 |
Random random = new Random();
|
|
|
703 |
int randomDays = random.ints(2, 15).findFirst().getAsInt();
|
|
|
704 |
LocalDateTime saleDate = grnDate.plusDays(randomDays);
|
| 28166 |
tejbeer |
705 |
if (saleDate.isAfter(LocalDate.now().atStartOfDay())) {
|
| 27521 |
amit.gupta |
706 |
saleDate = LocalDateTime.now().minusDays(2);
|
|
|
707 |
}
|
| 27522 |
amit.gupta |
708 |
Random offsetRandom = new Random();
|
|
|
709 |
int offset = offsetRandom.ints(2, 100).findFirst().getAsInt();
|
|
|
710 |
FofoOrder fofoOrder = fofoOrderRepository.selectFirstOrderAfterDate(saleDate, offset);
|
|
|
711 |
while (orderIdsConsumed.contains(fofoOrder.getId())) {
|
|
|
712 |
Random offsetRandom2 = new Random();
|
|
|
713 |
int offset2 = offsetRandom2.ints(2, 100).findFirst().getAsInt();
|
|
|
714 |
FofoOrder fofoOrder2 = fofoOrderRepository.selectFirstOrderAfterDate(saleDate, offset2);
|
| 28166 |
tejbeer |
715 |
if (fofoOrder2 != null) {
|
| 27522 |
amit.gupta |
716 |
fofoOrder = fofoOrder2;
|
|
|
717 |
}
|
|
|
718 |
}
|
| 30321 |
amit.gupta |
719 |
InvoicePdfModel pdfModel = this.getInvoicePdfModel(fofoOrder.getId());
|
| 27523 |
amit.gupta |
720 |
orderIdsConsumed.add(fofoOrder.getId());
|
| 27516 |
amit.gupta |
721 |
this.modifyDummyModel(fofoOrder, pdfModel, itemId, serialNumber);
|
|
|
722 |
return pdfModel;
|
|
|
723 |
|
|
|
724 |
}
|
|
|
725 |
}
|
|
|
726 |
} else {
|
|
|
727 |
throw new ProfitMandiBusinessException("Serial Number", serialNumber,
|
|
|
728 |
"Serial Number does not exist in our warehouse");
|
|
|
729 |
}
|
|
|
730 |
}
|
|
|
731 |
|
| 30321 |
amit.gupta |
732 |
void modifyDummyModel(FofoOrder fofoOrder, InvoicePdfModel pdfModel, int itemId, String serialNumber)
|
| 28166 |
tejbeer |
733 |
throws ProfitMandiBusinessException {
|
|
|
734 |
|
| 27516 |
amit.gupta |
735 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
|
|
736 |
|
|
|
737 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
738 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
739 |
|
|
|
740 |
CustomerAddress customerAddress = customer.getCustomerAddress().stream()
|
|
|
741 |
.filter(x -> x.getId() == fofoOrder.getCustomerAddressId()).findFirst().get();
|
|
|
742 |
|
|
|
743 |
Integer stateId = null;
|
|
|
744 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
745 |
try {
|
| 30527 |
tejbeer |
746 |
// stateId =
|
|
|
747 |
// Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
|
|
748 |
|
|
|
749 |
stateId = Long.valueOf(stateRepository.selectByName(customerAddress.getState()).getId()).intValue();
|
| 27516 |
amit.gupta |
750 |
} catch (Exception e) {
|
|
|
751 |
LOGGER.error("Unable to get state rates");
|
|
|
752 |
}
|
|
|
753 |
}
|
|
|
754 |
CustomOrderItem cli = pdfModel.getOrderItems().stream().findFirst().get();
|
| 28166 |
tejbeer |
755 |
List<FofoOrderItem> fofoOrderItems = Arrays
|
|
|
756 |
.asList(this.getDummyFofoOrderItem(itemId, fofoOrder.getId(), serialNumber, stateId));
|
| 28093 |
amit.gupta |
757 |
pdfModel.setPaymentOptions(pdfModel.getPaymentOptions().stream().limit(1).collect(Collectors.toList()));
|
| 27516 |
amit.gupta |
758 |
CustomPaymentOption paymentOption = pdfModel.getPaymentOptions().get(0);
|
|
|
759 |
paymentOption.setAmount(fofoOrderItems.get(0).getMop());
|
|
|
760 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
|
|
761 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
|
|
762 |
CustomOrderItem customFofoOrderItem = new CustomOrderItem();
|
|
|
763 |
float totalTaxRate = fofoOrderItem.getIgstRate() + fofoOrderItem.getSgstRate()
|
|
|
764 |
+ fofoOrderItem.getCgstRate();
|
|
|
765 |
float taxableSellingPrice = fofoOrderItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
|
|
766 |
float taxableDiscountPrice = fofoOrderItem.getDiscount() / (1 + totalTaxRate / 100);
|
|
|
767 |
|
|
|
768 |
customFofoOrderItem.setAmount(fofoOrderItem.getQuantity() * (taxableSellingPrice - taxableDiscountPrice));
|
|
|
769 |
customFofoOrderItem.setDescription(fofoOrderItem.getBrand() + " " + fofoOrderItem.getModelName() + " "
|
|
|
770 |
+ fofoOrderItem.getModelNumber() + "-" + fofoOrderItem.getColor());
|
|
|
771 |
Set<String> serialNumbers = this.toSerialNumbers(fofoOrderItem.getFofoLineItems());
|
|
|
772 |
// LOGGER.info("serialNumbers {}", serialNumbers);
|
|
|
773 |
// LOGGER.info("serialNumbers is empty {}", serialNumbers.isEmpty());
|
|
|
774 |
if (!serialNumbers.isEmpty()) {
|
|
|
775 |
customFofoOrderItem.setDescription(
|
|
|
776 |
customFofoOrderItem.getDescription() + "\n IMEIS - " + String.join(", ", serialNumbers));
|
|
|
777 |
}
|
|
|
778 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
|
|
779 |
customFofoOrderItem.setDiscount(taxableDiscountPrice);
|
|
|
780 |
customFofoOrderItem.setQuantity(fofoOrderItem.getQuantity());
|
|
|
781 |
customFofoOrderItem.setNetAmount(
|
|
|
782 |
(fofoOrderItem.getSellingPrice() - fofoOrderItem.getDiscount()) * fofoOrderItem.getQuantity());
|
|
|
783 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getIgstRate()) / 100;
|
|
|
784 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getCgstRate()) / 100;
|
|
|
785 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getSgstRate()) / 100;
|
|
|
786 |
customFofoOrderItem.setIgstRate(fofoOrderItem.getIgstRate());
|
|
|
787 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
|
|
788 |
customFofoOrderItem.setCgstRate(fofoOrderItem.getCgstRate());
|
|
|
789 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
|
|
790 |
customFofoOrderItem.setSgstRate(fofoOrderItem.getSgstRate());
|
|
|
791 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
|
|
792 |
customFofoOrderItem.setHsnCode(fofoOrderItem.getHsnCode());
|
|
|
793 |
customerFofoOrderItems.add(customFofoOrderItem);
|
|
|
794 |
}
|
| 28091 |
amit.gupta |
795 |
pdfModel.setTotalAmount(paymentOption.getAmount());
|
| 27516 |
amit.gupta |
796 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 28166 |
tejbeer |
797 |
|
| 27516 |
amit.gupta |
798 |
}
|
|
|
799 |
|
| 30321 |
amit.gupta |
800 |
private InvoicePdfModel getInvoicePdfModel(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
801 |
|
|
|
802 |
List<PaymentOptionTransaction> paymentOptionTransactions = paymentOptionTransactionRepository
|
|
|
803 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
804 |
|
| 23552 |
amit.gupta |
805 |
List<CustomPaymentOption> paymentOptions = new ArrayList<>();
|
|
|
806 |
|
| 30321 |
amit.gupta |
807 |
InvoicePdfModel pdfModel = new InvoicePdfModel();
|
| 23650 |
amit.gupta |
808 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23552 |
amit.gupta |
809 |
CustomPaymentOption cpi = new CustomPaymentOption();
|
| 28090 |
amit.gupta |
810 |
cpi.setAmount(paymentOptionTransaction.getAmount());
|
| 23650 |
amit.gupta |
811 |
cpi.setPaymentOption(
|
|
|
812 |
paymentOptionRepository.selectById(paymentOptionTransaction.getPaymentOptionId()).getName());
|
| 23558 |
amit.gupta |
813 |
paymentOptions.add(cpi);
|
| 23552 |
amit.gupta |
814 |
}
|
| 24215 |
amit.gupta |
815 |
List<FofoOrderItem> fofoOrderItems = this.getByOrderId(fofoOrder.getId());
|
|
|
816 |
|
|
|
817 |
pdfModel.setTitle("Retailer Invoice");
|
| 24275 |
amit.gupta |
818 |
if (fofoOrderItems.stream().findAny().get().getHsnCode().equals("NOGST")) {
|
| 24215 |
amit.gupta |
819 |
pdfModel.setTitle("Security Deposit Receipt");
|
|
|
820 |
}
|
| 23552 |
amit.gupta |
821 |
pdfModel.setPaymentOptions(paymentOptions);
|
| 24215 |
amit.gupta |
822 |
pdfModel.setAuther("SmartDukaan");
|
| 24400 |
amit.gupta |
823 |
pdfModel.setInvoiceDate(FormattingUtils.formatDate(fofoOrder.getCreateTimestamp()));
|
| 23650 |
amit.gupta |
824 |
|
| 22859 |
ashik.ali |
825 |
// insurance calculation
|
| 23650 |
amit.gupta |
826 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
| 31045 |
amit.gupta |
827 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| 22859 |
ashik.ali |
828 |
Set<CustomInsurancePolicy> customInsurancePolicies = new HashSet<>();
|
|
|
829 |
final float totalInsuranceTaxRate = 18;
|
| 23650 |
amit.gupta |
830 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 22859 |
ashik.ali |
831 |
float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
|
|
|
832 |
CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
|
| 30723 |
amit.gupta |
833 |
customInsurancePolicy.setDescription(insurancePolicy.getPolicyPlan() + " for Device #"
|
|
|
834 |
+ insurancePolicy.getSerialNumber() + "\n Plan Reference - " + insurancePolicy.getPolicyNumber());
|
| 22859 |
ashik.ali |
835 |
customInsurancePolicy.setHsnCode("998716");
|
|
|
836 |
customInsurancePolicy.setRate(taxableInsurancePrice);
|
|
|
837 |
customInsurancePolicy.setIgstRate(18);
|
| 23650 |
amit.gupta |
838 |
customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 / 100);
|
| 22936 |
amit.gupta |
839 |
customInsurancePolicy.setCgstRate(9);
|
| 23650 |
amit.gupta |
840 |
customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 / 100);
|
| 22859 |
ashik.ali |
841 |
customInsurancePolicy.setSgstRate(9);
|
| 23650 |
amit.gupta |
842 |
customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 / 100);
|
| 22859 |
ashik.ali |
843 |
customInsurancePolicy.setNetAmount(insurancePolicy.getSaleAmount());
|
|
|
844 |
customInsurancePolicies.add(customInsurancePolicy);
|
|
|
845 |
}
|
|
|
846 |
pdfModel.setInsurancePolicies(customInsurancePolicies);
|
| 24275 |
amit.gupta |
847 |
|
| 23655 |
amit.gupta |
848 |
pdfModel.setCustomer(getCustomCustomer(fofoOrder));
|
| 22859 |
ashik.ali |
849 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
850 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
| 23650 |
amit.gupta |
851 |
|
| 23596 |
ashik.ali |
852 |
Retailer retailer = retailerRepository.selectById(fofoOrder.getFofoId());
|
| 22859 |
ashik.ali |
853 |
PrivateDealUser privateDealUser = null;
|
| 23650 |
amit.gupta |
854 |
try {
|
| 22859 |
ashik.ali |
855 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| 23650 |
amit.gupta |
856 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 22859 |
ashik.ali |
857 |
LOGGER.error("Private Deal User not found : ", profitMandiBusinessException);
|
|
|
858 |
}
|
| 23650 |
amit.gupta |
859 |
|
| 22859 |
ashik.ali |
860 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
|
|
861 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
862 |
customRetailer.setBusinessName(retailer.getName());
|
|
|
863 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
| 23650 |
amit.gupta |
864 |
// customRetailer.setTinNumber(retailer.getNumber());
|
|
|
865 |
if (privateDealUser == null) {
|
| 22859 |
ashik.ali |
866 |
customRetailer.setGstNumber(null);
|
| 23650 |
amit.gupta |
867 |
} else {
|
|
|
868 |
if (null != privateDealUser.getCounterId()) {
|
| 22859 |
ashik.ali |
869 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
|
|
870 |
customRetailer.setGstNumber(counter.getGstin());
|
| 23650 |
amit.gupta |
871 |
} else {
|
| 22859 |
ashik.ali |
872 |
customRetailer.setGstNumber(null);
|
|
|
873 |
}
|
|
|
874 |
}
|
| 23650 |
amit.gupta |
875 |
Address retailerAddress = addressRepository
|
|
|
876 |
.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
| 22859 |
ashik.ali |
877 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
|
|
878 |
pdfModel.setRetailer(customRetailer);
|
| 23650 |
amit.gupta |
879 |
|
| 22859 |
ashik.ali |
880 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
| 23650 |
amit.gupta |
881 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
| 28390 |
amit.gupta |
882 |
float discount = fofoOrderItem.getDiscount();
|
| 22859 |
ashik.ali |
883 |
CustomOrderItem customFofoOrderItem = new CustomOrderItem();
|
| 23650 |
amit.gupta |
884 |
float totalTaxRate = fofoOrderItem.getIgstRate() + fofoOrderItem.getSgstRate()
|
|
|
885 |
+ fofoOrderItem.getCgstRate();
|
| 28390 |
amit.gupta |
886 |
float taxableSellingPrice = (fofoOrderItem.getSellingPrice() + discount) / (1 + totalTaxRate / 100);
|
|
|
887 |
float taxableDiscountPrice = discount / (1 + totalTaxRate / 100);
|
| 23650 |
amit.gupta |
888 |
|
| 22859 |
ashik.ali |
889 |
customFofoOrderItem.setAmount(fofoOrderItem.getQuantity() * (taxableSellingPrice - taxableDiscountPrice));
|
| 23650 |
amit.gupta |
890 |
customFofoOrderItem.setDescription(fofoOrderItem.getBrand() + " " + fofoOrderItem.getModelName() + " "
|
|
|
891 |
+ fofoOrderItem.getModelNumber() + "-" + fofoOrderItem.getColor());
|
| 23377 |
ashik.ali |
892 |
Set<String> serialNumbers = this.toSerialNumbers(fofoOrderItem.getFofoLineItems());
|
| 23650 |
amit.gupta |
893 |
// LOGGER.info("serialNumbers {}", serialNumbers);
|
|
|
894 |
// LOGGER.info("serialNumbers is empty {}", serialNumbers.isEmpty());
|
|
|
895 |
if (!serialNumbers.isEmpty()) {
|
|
|
896 |
customFofoOrderItem.setDescription(
|
|
|
897 |
customFofoOrderItem.getDescription() + "\n IMEIS - " + String.join(", ", serialNumbers));
|
| 23377 |
ashik.ali |
898 |
}
|
| 22859 |
ashik.ali |
899 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
|
|
900 |
customFofoOrderItem.setDiscount(taxableDiscountPrice);
|
|
|
901 |
customFofoOrderItem.setQuantity(fofoOrderItem.getQuantity());
|
| 28390 |
amit.gupta |
902 |
customFofoOrderItem.setNetAmount(fofoOrderItem.getSellingPrice() * fofoOrderItem.getQuantity());
|
| 22859 |
ashik.ali |
903 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getIgstRate()) / 100;
|
|
|
904 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getCgstRate()) / 100;
|
|
|
905 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getSgstRate()) / 100;
|
|
|
906 |
customFofoOrderItem.setIgstRate(fofoOrderItem.getIgstRate());
|
|
|
907 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
|
|
908 |
customFofoOrderItem.setCgstRate(fofoOrderItem.getCgstRate());
|
|
|
909 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
|
|
910 |
customFofoOrderItem.setSgstRate(fofoOrderItem.getSgstRate());
|
|
|
911 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
|
|
912 |
customFofoOrderItem.setHsnCode(fofoOrderItem.getHsnCode());
|
|
|
913 |
customerFofoOrderItems.add(customFofoOrderItem);
|
|
|
914 |
}
|
|
|
915 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 24917 |
tejbeer |
916 |
String partnerAddressStateCode = stateRepository.selectByName(pdfModel.getRetailer().getAddress().getState())
|
|
|
917 |
.getCode();
|
|
|
918 |
String customerAddressStateCode = stateRepository.selectByName(pdfModel.getCustomer().getAddress().getState())
|
|
|
919 |
.getCode();
|
| 24854 |
amit.gupta |
920 |
pdfModel.setPartnerAddressStateCode(partnerAddressStateCode);
|
|
|
921 |
pdfModel.setCustomerAddressStateCode(customerAddressStateCode);
|
| 28458 |
amit.gupta |
922 |
pdfModel.setCancelled(fofoOrder.getCancelledTimestamp() != null);
|
| 28456 |
amit.gupta |
923 |
List<String> tncs = new ArrayList<>();
|
|
|
924 |
tncs.add("I agree that goods received are in good working condition");
|
|
|
925 |
tncs.add("Goods once sold cannot be exchanged or taken back");
|
|
|
926 |
tncs.add("Warranty for the goods received by me is the responsibility of the manufacturer only.");
|
|
|
927 |
tncs.add("Customer needs to activate the handset at the time of delivery to be eligible for the discount");
|
|
|
928 |
tncs.add(
|
|
|
929 |
"Tempered Glass Replacement will be done only for the Mobile Phone which was purchased from SmartDukaan");
|
|
|
930 |
tncs.add(
|
|
|
931 |
"Customers requesting Tempered Glass Replacement will have to bring the broken tempered glass, either pasted on the phone or along with the phone");
|
|
|
932 |
tncs.add("Service fee of Rs.20 will be chargeable for each Tempered Glass Replacement");
|
|
|
933 |
if (pdfModel.getInsurancePolicies() != null && pdfModel.getInsurancePolicies().size() > 0) {
|
|
|
934 |
tncs.add("Damage protection provided is the responisibility of Protection Provider only");
|
|
|
935 |
}
|
|
|
936 |
pdfModel.setTncs(tncs);
|
| 22859 |
ashik.ali |
937 |
return pdfModel;
|
| 23650 |
amit.gupta |
938 |
|
| 22859 |
ashik.ali |
939 |
}
|
| 23650 |
amit.gupta |
940 |
|
| 30321 |
amit.gupta |
941 |
private InvoicePdfModel getInsuranceInvoicePdfModel(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
| 29707 |
tejbeer |
942 |
|
|
|
943 |
List<PaymentOptionTransaction> paymentOptionTransactions = paymentOptionTransactionRepository
|
|
|
944 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.INSURANCE);
|
|
|
945 |
|
|
|
946 |
List<CustomPaymentOption> paymentOptions = new ArrayList<>();
|
|
|
947 |
|
| 30321 |
amit.gupta |
948 |
InvoicePdfModel pdfModel = new InvoicePdfModel();
|
| 29707 |
tejbeer |
949 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
|
|
950 |
CustomPaymentOption cpi = new CustomPaymentOption();
|
|
|
951 |
cpi.setAmount(paymentOptionTransaction.getAmount());
|
|
|
952 |
cpi.setPaymentOption(
|
|
|
953 |
paymentOptionRepository.selectById(paymentOptionTransaction.getPaymentOptionId()).getName());
|
|
|
954 |
paymentOptions.add(cpi);
|
|
|
955 |
}
|
|
|
956 |
|
|
|
957 |
pdfModel.setTitle("Retailer Invoice");
|
|
|
958 |
|
|
|
959 |
pdfModel.setPaymentOptions(paymentOptions);
|
|
|
960 |
pdfModel.setAuther("SmartDukaan");
|
|
|
961 |
pdfModel.setInvoiceDate(FormattingUtils.formatDate(fofoOrder.getCreateTimestamp()));
|
|
|
962 |
|
|
|
963 |
// insurance calculation
|
|
|
964 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
965 |
.selectByRetailerIdDeviceInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
|
|
966 |
Set<CustomInsurancePolicy> customInsurancePolicies = new HashSet<>();
|
|
|
967 |
final float totalInsuranceTaxRate = 18;
|
|
|
968 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
|
|
969 |
float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
|
|
|
970 |
CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
|
|
|
971 |
customInsurancePolicy.setDescription("Damage Protection Plan for device IMEI #"
|
|
|
972 |
+ insurancePolicy.getSerialNumber() + "\n Certificate No. " + insurancePolicy.getPolicyNumber());
|
|
|
973 |
customInsurancePolicy.setHsnCode("998716");
|
|
|
974 |
customInsurancePolicy.setRate(taxableInsurancePrice);
|
|
|
975 |
customInsurancePolicy.setIgstRate(18);
|
|
|
976 |
customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 / 100);
|
|
|
977 |
customInsurancePolicy.setCgstRate(9);
|
|
|
978 |
customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 / 100);
|
|
|
979 |
customInsurancePolicy.setSgstRate(9);
|
|
|
980 |
customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 / 100);
|
|
|
981 |
customInsurancePolicy.setNetAmount(insurancePolicy.getSaleAmount());
|
|
|
982 |
customInsurancePolicies.add(customInsurancePolicy);
|
|
|
983 |
}
|
|
|
984 |
pdfModel.setInsurancePolicies(customInsurancePolicies);
|
|
|
985 |
|
|
|
986 |
pdfModel.setCustomer(getCustomCustomer(fofoOrder));
|
|
|
987 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
988 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
|
|
989 |
|
|
|
990 |
Retailer retailer = retailerRepository.selectById(fofoOrder.getFofoId());
|
|
|
991 |
PrivateDealUser privateDealUser = null;
|
|
|
992 |
try {
|
|
|
993 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
|
|
994 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
995 |
LOGGER.error("Private Deal User not found : ", profitMandiBusinessException);
|
|
|
996 |
}
|
|
|
997 |
|
|
|
998 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
|
|
999 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
1000 |
customRetailer.setBusinessName(retailer.getName());
|
|
|
1001 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
|
|
1002 |
// customRetailer.setTinNumber(retailer.getNumber());
|
|
|
1003 |
if (privateDealUser == null) {
|
|
|
1004 |
customRetailer.setGstNumber(null);
|
|
|
1005 |
} else {
|
|
|
1006 |
if (null != privateDealUser.getCounterId()) {
|
|
|
1007 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
|
|
1008 |
customRetailer.setGstNumber(counter.getGstin());
|
|
|
1009 |
} else {
|
|
|
1010 |
customRetailer.setGstNumber(null);
|
|
|
1011 |
}
|
|
|
1012 |
}
|
|
|
1013 |
Address retailerAddress = addressRepository
|
|
|
1014 |
.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
|
|
1015 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
|
|
1016 |
pdfModel.setRetailer(customRetailer);
|
|
|
1017 |
|
|
|
1018 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
|
|
1019 |
|
|
|
1020 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
|
|
1021 |
String partnerAddressStateCode = stateRepository.selectByName(pdfModel.getRetailer().getAddress().getState())
|
|
|
1022 |
.getCode();
|
|
|
1023 |
String customerAddressStateCode = stateRepository.selectByName(pdfModel.getCustomer().getAddress().getState())
|
|
|
1024 |
.getCode();
|
|
|
1025 |
pdfModel.setPartnerAddressStateCode(partnerAddressStateCode);
|
|
|
1026 |
pdfModel.setCustomerAddressStateCode(customerAddressStateCode);
|
|
|
1027 |
pdfModel.setCancelled(fofoOrder.getCancelledTimestamp() != null);
|
|
|
1028 |
List<String> tncs = new ArrayList<>();
|
|
|
1029 |
tncs.add("I agree that goods received are in good working condition");
|
|
|
1030 |
tncs.add("Goods once sold cannot be exchanged or taken back");
|
|
|
1031 |
tncs.add("Warranty for the goods received by me is the responsibility of the manufacturer only.");
|
|
|
1032 |
tncs.add("Customer needs to activate the handset at the time of delivery to be eligible for the discount");
|
|
|
1033 |
tncs.add(
|
|
|
1034 |
"Tempered Glass Replacement will be done only for the Mobile Phone which was purchased from SmartDukaan");
|
|
|
1035 |
tncs.add(
|
|
|
1036 |
"Customers requesting Tempered Glass Replacement will have to bring the broken tempered glass, either pasted on the phone or along with the phone");
|
|
|
1037 |
tncs.add("Service fee of Rs.20 will be chargeable for each Tempered Glass Replacement");
|
|
|
1038 |
if (pdfModel.getInsurancePolicies() != null && pdfModel.getInsurancePolicies().size() > 0) {
|
|
|
1039 |
tncs.add("Damage protection provided is the responisibility of Protection Provider only");
|
|
|
1040 |
}
|
|
|
1041 |
pdfModel.setTncs(tncs);
|
|
|
1042 |
return pdfModel;
|
|
|
1043 |
|
|
|
1044 |
}
|
|
|
1045 |
|
| 23655 |
amit.gupta |
1046 |
private CustomCustomer getCustomCustomer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
|
|
1047 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
1048 |
CustomCustomer customCustomer = new CustomCustomer();
|
|
|
1049 |
customCustomer.setFirstName(customer.getFirstName());
|
|
|
1050 |
customCustomer.setLastName(customer.getLastName());
|
|
|
1051 |
customCustomer.setEmailId(customer.getEmailId());
|
|
|
1052 |
customCustomer.setMobileNumber(customer.getMobileNumber());
|
|
|
1053 |
customCustomer.setGstNumber(fofoOrder.getCustomerGstNumber());
|
|
|
1054 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
1055 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
|
|
1056 |
return customCustomer;
|
|
|
1057 |
}
|
|
|
1058 |
|
| 23596 |
ashik.ali |
1059 |
@Override
|
| 30321 |
amit.gupta |
1060 |
public InvoicePdfModel getInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
| 23596 |
ashik.ali |
1061 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, orderId);
|
|
|
1062 |
return this.getInvoicePdfModel(fofoOrder);
|
|
|
1063 |
}
|
| 23650 |
amit.gupta |
1064 |
|
| 29707 |
tejbeer |
1065 |
@Override
|
| 30321 |
amit.gupta |
1066 |
public InvoicePdfModel getInsuranceInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
| 29707 |
tejbeer |
1067 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, orderId);
|
|
|
1068 |
return this.getInsuranceInvoicePdfModel(fofoOrder);
|
|
|
1069 |
}
|
|
|
1070 |
|
| 22859 |
ashik.ali |
1071 |
public String getBillingAddress(CustomerAddress customerAddress) {
|
|
|
1072 |
StringBuilder address = new StringBuilder();
|
|
|
1073 |
if ((customerAddress.getLine1() != null) && (!customerAddress.getLine1().isEmpty())) {
|
|
|
1074 |
address.append(customerAddress.getLine1());
|
|
|
1075 |
address.append(", ");
|
|
|
1076 |
}
|
|
|
1077 |
|
|
|
1078 |
if ((customerAddress.getLine2() != null) && (!customerAddress.getLine2().isEmpty())) {
|
|
|
1079 |
address.append(customerAddress.getLine2());
|
|
|
1080 |
address.append(", ");
|
|
|
1081 |
}
|
|
|
1082 |
|
|
|
1083 |
if ((customerAddress.getLandmark() != null) && (!customerAddress.getLandmark().isEmpty())) {
|
|
|
1084 |
address.append(customerAddress.getLandmark());
|
|
|
1085 |
address.append(", ");
|
|
|
1086 |
}
|
|
|
1087 |
|
|
|
1088 |
if ((customerAddress.getCity() != null) && (!customerAddress.getCity().isEmpty())) {
|
|
|
1089 |
address.append(customerAddress.getCity());
|
|
|
1090 |
address.append(", ");
|
|
|
1091 |
}
|
|
|
1092 |
|
|
|
1093 |
if ((customerAddress.getState() != null) && (!customerAddress.getState().isEmpty())) {
|
|
|
1094 |
address.append(customerAddress.getState());
|
|
|
1095 |
}
|
|
|
1096 |
|
|
|
1097 |
if ((customerAddress.getPinCode() != null) && (!customerAddress.getPinCode().isEmpty())) {
|
|
|
1098 |
address.append("- ");
|
|
|
1099 |
address.append(customerAddress.getPinCode());
|
|
|
1100 |
}
|
|
|
1101 |
|
|
|
1102 |
return address.toString();
|
|
|
1103 |
}
|
| 23650 |
amit.gupta |
1104 |
|
| 22859 |
ashik.ali |
1105 |
@Override
|
| 23650 |
amit.gupta |
1106 |
public List<CartFofo> cartCheckout(String cartJson) throws ProfitMandiBusinessException {
|
|
|
1107 |
try {
|
| 22859 |
ashik.ali |
1108 |
JSONObject cartObject = new JSONObject(cartJson);
|
|
|
1109 |
Iterator<?> keys = cartObject.keys();
|
| 23650 |
amit.gupta |
1110 |
|
| 22859 |
ashik.ali |
1111 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
1112 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
| 23650 |
amit.gupta |
1113 |
|
|
|
1114 |
while (keys.hasNext()) {
|
|
|
1115 |
String key = (String) keys.next();
|
|
|
1116 |
if (cartObject.get(key) instanceof JSONObject) {
|
| 22859 |
ashik.ali |
1117 |
LOGGER.info(cartObject.get(key).toString());
|
|
|
1118 |
}
|
|
|
1119 |
CartFofo cf = new CartFofo();
|
|
|
1120 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
1121 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
| 28339 |
tejbeer |
1122 |
if (cartObject.getJSONObject(key).has("poId")) {
|
| 23650 |
amit.gupta |
1123 |
|
| 28339 |
tejbeer |
1124 |
cf.setPoId(cartObject.getJSONObject(key).getInt("poId"));
|
|
|
1125 |
cf.setPoItemId(cartObject.getJSONObject(key).getInt("poItemId"));
|
|
|
1126 |
}
|
| 23650 |
amit.gupta |
1127 |
if (cf.getQuantity() <= 0) {
|
| 22859 |
ashik.ali |
1128 |
continue;
|
|
|
1129 |
}
|
|
|
1130 |
cartItems.add(cf);
|
|
|
1131 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
1132 |
}
|
| 23650 |
amit.gupta |
1133 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
|
|
1134 |
if (itemIds.size() > 0) {
|
| 22859 |
ashik.ali |
1135 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| 23650 |
amit.gupta |
1136 |
for (Item i : items) {
|
| 22859 |
ashik.ali |
1137 |
itemMap.put(i.getId(), i);
|
|
|
1138 |
}
|
| 23650 |
amit.gupta |
1139 |
|
| 22859 |
ashik.ali |
1140 |
}
|
| 23650 |
amit.gupta |
1141 |
for (CartFofo cf : cartItems) {
|
| 22859 |
ashik.ali |
1142 |
Item i = itemMap.get(cf.getItemId());
|
| 23650 |
amit.gupta |
1143 |
if (i == null) {
|
| 22859 |
ashik.ali |
1144 |
continue;
|
|
|
1145 |
}
|
| 23650 |
amit.gupta |
1146 |
cf.setDisplayName(getValidName(i.getBrand()) + " " + getValidName(i.getModelName()) + " "
|
|
|
1147 |
+ getValidName(i.getModelNumber()) + " " + getValidName(i.getColor()).replaceAll("\\s+", " "));
|
| 22859 |
ashik.ali |
1148 |
cf.setItemType(i.getType());
|
|
|
1149 |
}
|
|
|
1150 |
return cartItems;
|
| 23650 |
amit.gupta |
1151 |
} catch (Exception e) {
|
| 22859 |
ashik.ali |
1152 |
LOGGER.error("Unable to Prepare cart to place order...", e);
|
| 22925 |
ashik.ali |
1153 |
throw new ProfitMandiBusinessException("cartData", cartJson, "FFORDR_1006");
|
| 22859 |
ashik.ali |
1154 |
}
|
|
|
1155 |
}
|
| 23650 |
amit.gupta |
1156 |
|
| 23202 |
ashik.ali |
1157 |
@Override
|
| 23650 |
amit.gupta |
1158 |
public Map<String, Object> getSaleHistory(int fofoId, SearchType searchType, String searchValue,
|
| 31030 |
amit.gupta |
1159 |
LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
1160 |
long countItems = 0;
|
|
|
1161 |
List<FofoOrder> fofoOrders = new ArrayList<>();
|
| 23650 |
amit.gupta |
1162 |
|
|
|
1163 |
if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1164 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, null, null,
|
|
|
1165 |
offset, limit);
|
|
|
1166 |
countItems = fofoOrderRepository.selectCountByCustomerMobileNumber(fofoId, searchValue, null, null);
|
| 23650 |
amit.gupta |
1167 |
} else if (searchType == SearchType.CUSTOMER_NAME && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1168 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerName(fofoId, searchValue, null, null, offset,
|
|
|
1169 |
limit);
|
| 23973 |
govind |
1170 |
countItems = fofoOrderRepository.selectCountByCustomerName(fofoId, searchValue, null, null);
|
| 23650 |
amit.gupta |
1171 |
} else if (searchType == SearchType.IMEI && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1172 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndSerialNumber(fofoId, searchValue, null, null, offset,
|
|
|
1173 |
limit);
|
| 23973 |
govind |
1174 |
countItems = fofoOrderRepository.selectCountBySerialNumber(fofoId, searchValue, null, null);
|
| 23650 |
amit.gupta |
1175 |
} else if (searchType == SearchType.ITEM_NAME && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1176 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndItemName(fofoId, searchValue, null, null, offset, limit);
|
|
|
1177 |
countItems = fofoOrderRepository.selectCountByItemName(fofoId, searchValue, null, null);
|
| 23953 |
amit.gupta |
1178 |
} else if (searchType == SearchType.INVOICE_NUMBER && !searchValue.isEmpty()) {
|
|
|
1179 |
fofoOrders = Arrays.asList(fofoOrderRepository.selectByFofoIdAndInvoiceNumber(fofoId, searchValue));
|
|
|
1180 |
countItems = fofoOrders.size();
|
| 24275 |
amit.gupta |
1181 |
} else if (searchType == SearchType.DATE_RANGE) {
|
| 23891 |
amit.gupta |
1182 |
fofoOrders = fofoOrderRepository.selectByFofoId(fofoId, startDate, endDate, offset, limit);
|
|
|
1183 |
countItems = fofoOrderRepository.selectCountByFofoId(fofoId, startDate, endDate);
|
| 23202 |
ashik.ali |
1184 |
}
|
|
|
1185 |
Map<String, Object> map = new HashMap<>();
|
| 23650 |
amit.gupta |
1186 |
|
| 23202 |
ashik.ali |
1187 |
map.put("saleHistories", fofoOrders);
|
|
|
1188 |
map.put("start", offset + 1);
|
|
|
1189 |
map.put("size", countItems);
|
|
|
1190 |
map.put("searchType", searchType);
|
| 23351 |
ashik.ali |
1191 |
map.put("searchTypes", SearchType.values());
|
| 23891 |
amit.gupta |
1192 |
map.put("startDate", startDate);
|
| 23973 |
govind |
1193 |
map.put("searchValue", searchValue);
|
| 23891 |
amit.gupta |
1194 |
map.put(ProfitMandiConstants.END_TIME, endDate);
|
| 23650 |
amit.gupta |
1195 |
if (fofoOrders.size() < limit) {
|
| 23202 |
ashik.ali |
1196 |
map.put("end", offset + fofoOrders.size());
|
| 23650 |
amit.gupta |
1197 |
} else {
|
| 23202 |
ashik.ali |
1198 |
map.put("end", offset + limit);
|
|
|
1199 |
}
|
|
|
1200 |
return map;
|
|
|
1201 |
}
|
| 30426 |
tejbeer |
1202 |
|
|
|
1203 |
public ResponseEntity<?> downloadReportInCsv(org.apache.commons.io.output.ByteArrayOutputStream baos,
|
| 31030 |
amit.gupta |
1204 |
List<List<?>> rows, String fileName) {
|
| 30157 |
manish |
1205 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
1206 |
headers.set("Content-Type", "text/csv");
|
| 30426 |
tejbeer |
1207 |
|
|
|
1208 |
headers.set("Content-disposition", "inline; filename=" + fileName + ".csv");
|
| 30157 |
manish |
1209 |
headers.setContentLength(baos.toByteArray().length);
|
| 23202 |
ashik.ali |
1210 |
|
| 30157 |
manish |
1211 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
1212 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| 30426 |
tejbeer |
1213 |
|
| 30157 |
manish |
1214 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
1215 |
}
|
|
|
1216 |
|
| 23202 |
ashik.ali |
1217 |
@Override
|
| 23650 |
amit.gupta |
1218 |
public Map<String, Object> getSaleHistoryPaginated(int fofoId, SearchType searchType, String searchValue,
|
| 31030 |
amit.gupta |
1219 |
LocalDateTime startDate, LocalDateTime endDate, int offset, int limit) throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
1220 |
List<FofoOrder> fofoOrders = new ArrayList<>();
|
| 23650 |
amit.gupta |
1221 |
|
|
|
1222 |
if (searchType == SearchType.CUSTOMER_MOBILE_NUMBER && !searchValue.isEmpty()) {
|
| 23891 |
amit.gupta |
1223 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerMobileNumber(fofoId, searchValue, startDate,
|
|
|
1224 |
endDate, offset, limit);
|
| 23650 |
amit.gupta |
1225 |
} else if (searchType == SearchType.CUSTOMER_NAME && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1226 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndCustomerName(fofoId, searchValue, startDate, endDate,
|
|
|
1227 |
offset, limit);
|
| 23650 |
amit.gupta |
1228 |
} else if (searchType == SearchType.IMEI && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1229 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndSerialNumber(fofoId, searchValue, startDate, endDate,
|
|
|
1230 |
offset, limit);
|
| 23650 |
amit.gupta |
1231 |
} else if (searchType == SearchType.ITEM_NAME && !searchValue.isEmpty()) {
|
| 24275 |
amit.gupta |
1232 |
fofoOrders = fofoOrderRepository.selectByFofoIdAndItemName(fofoId, searchValue, startDate, endDate, offset,
|
|
|
1233 |
limit);
|
|
|
1234 |
|
|
|
1235 |
} else if (searchType == SearchType.DATE_RANGE) {
|
| 23891 |
amit.gupta |
1236 |
fofoOrders = fofoOrderRepository.selectByFofoId(fofoId, startDate, endDate, offset, limit);
|
| 23202 |
ashik.ali |
1237 |
}
|
|
|
1238 |
Map<String, Object> map = new HashMap<>();
|
|
|
1239 |
map.put("saleHistories", fofoOrders);
|
| 23973 |
govind |
1240 |
map.put("searchType", searchType);
|
|
|
1241 |
map.put("searchTypes", SearchType.values());
|
|
|
1242 |
map.put("startDate", startDate);
|
|
|
1243 |
map.put("searchValue", searchValue);
|
|
|
1244 |
map.put(ProfitMandiConstants.END_TIME, endDate);
|
| 23202 |
ashik.ali |
1245 |
return map;
|
|
|
1246 |
}
|
| 23650 |
amit.gupta |
1247 |
|
|
|
1248 |
private String getFofoStoreCode(int fofoId) throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
1249 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 23370 |
ashik.ali |
1250 |
return fofoStore.getCode();
|
| 23202 |
ashik.ali |
1251 |
}
|
| 23650 |
amit.gupta |
1252 |
|
|
|
1253 |
private String getValidName(String name) {
|
|
|
1254 |
return name != null ? name : "";
|
| 22859 |
ashik.ali |
1255 |
}
|
| 23650 |
amit.gupta |
1256 |
|
|
|
1257 |
private Set<String> toSerialNumbers(Set<FofoLineItem> fofoLineItems) {
|
| 23377 |
ashik.ali |
1258 |
Set<String> serialNumbers = new HashSet<>();
|
| 23650 |
amit.gupta |
1259 |
for (FofoLineItem fofoLineItem : fofoLineItems) {
|
|
|
1260 |
if (fofoLineItem.getSerialNumber() != null && !fofoLineItem.getSerialNumber().isEmpty()) {
|
| 23377 |
ashik.ali |
1261 |
serialNumbers.add(fofoLineItem.getSerialNumber());
|
| 22955 |
ashik.ali |
1262 |
}
|
| 23377 |
ashik.ali |
1263 |
}
|
|
|
1264 |
return serialNumbers;
|
| 22859 |
ashik.ali |
1265 |
}
|
| 23650 |
amit.gupta |
1266 |
|
| 23823 |
amit.gupta |
1267 |
private void validateDpPrice(Map<Integer, PriceModel> itemIdMopPriceMap,
|
| 31030 |
amit.gupta |
1268 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
| 23823 |
amit.gupta |
1269 |
for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoLineItemMap.entrySet()) {
|
|
|
1270 |
int itemId = entry.getKey();
|
|
|
1271 |
CustomFofoOrderItem customFofoOrderItem = entry.getValue();
|
| 29548 |
amit.gupta |
1272 |
LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
|
| 23823 |
amit.gupta |
1273 |
PriceModel priceModel = itemIdMopPriceMap.get(itemId);
|
| 29752 |
amit.gupta |
1274 |
Item item = itemRepository.selectById(itemId);
|
| 30426 |
tejbeer |
1275 |
if (!item.getBrand().equals("Live Demo")
|
|
|
1276 |
&& (item.getCategoryId() == ProfitMandiConstants.MOBILE_CATEGORY_ID
|
| 30993 |
amit.gupta |
1277 |
|| item.getCategoryId() == ProfitMandiConstants.TABLET_CATEGORY_ID || item.getCategoryId() == ProfitMandiConstants.LED_CATEGORY_ID)
|
| 30426 |
tejbeer |
1278 |
&& customFofoOrderItem.getSerialNumberDetails().stream()
|
| 31030 |
amit.gupta |
1279 |
.filter(x -> org.apache.commons.lang.StringUtils.isNotEmpty(x.getSerialNumber()))
|
|
|
1280 |
.collect(Collectors.toList()).size() > 0) {
|
| 29707 |
tejbeer |
1281 |
if (Utils.compareFloat(priceModel.getPrice(),
|
|
|
1282 |
customFofoOrderItem.getSellingPrice() + customFofoOrderItem.getDiscountAmount()) > 0) {
|
| 30426 |
tejbeer |
1283 |
throw new ProfitMandiBusinessException("Selling Price for ", item.getItemDescription(),
|
|
|
1284 |
"FFORDR_1010");
|
| 23823 |
amit.gupta |
1285 |
}
|
|
|
1286 |
} else {
|
| 30426 |
tejbeer |
1287 |
if (!item.getBrand().equals("Live Demo")
|
|
|
1288 |
&& priceModel.getPurchasePrice() > customFofoOrderItem.getSellingPrice()) {
|
| 24275 |
amit.gupta |
1289 |
throw new ProfitMandiBusinessException("Selling Price",
|
|
|
1290 |
itemRepository.selectById(itemId).getItemDescription(),
|
|
|
1291 |
"Selling Price should not be less than DP");
|
| 23823 |
amit.gupta |
1292 |
}
|
|
|
1293 |
}
|
|
|
1294 |
}
|
|
|
1295 |
}
|
| 24275 |
amit.gupta |
1296 |
|
| 23650 |
amit.gupta |
1297 |
private void validateMopPrice(Map<Integer, PriceModel> itemIdMopPriceMap,
|
| 31030 |
amit.gupta |
1298 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoLineItemMap) throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1299 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
| 23650 |
amit.gupta |
1300 |
for (Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()) {
|
| 22872 |
ashik.ali |
1301 |
CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoLineItemMap.get(entry.getKey());
|
| 29755 |
amit.gupta |
1302 |
Item item = itemRepository.selectById(customFofoOrderItem.getItemId());
|
| 30426 |
tejbeer |
1303 |
if (!(item.getBrand().equals("Live Demo") || item.getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID
|
|
|
1304 |
|| item.getCategoryId() != ProfitMandiConstants.TABLET_CATEGORY_ID)
|
|
|
1305 |
&& customFofoOrderItem.getSellingPrice() + customFofoOrderItem.getDiscountAmount() < entry
|
| 31030 |
amit.gupta |
1306 |
.getValue().getPrice()) {
|
| 22872 |
ashik.ali |
1307 |
invalidMopItemIdPriceMap.put(entry.getKey(), customFofoOrderItem.getSellingPrice());
|
| 22859 |
ashik.ali |
1308 |
}
|
|
|
1309 |
}
|
| 23650 |
amit.gupta |
1310 |
|
|
|
1311 |
if (!invalidMopItemIdPriceMap.isEmpty()) {
|
|
|
1312 |
LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}",
|
|
|
1313 |
invalidMopItemIdPriceMap, itemIdMopPriceMap);
|
| 22925 |
ashik.ali |
1314 |
throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidMopItemIdPriceMap, "FFORDR_1010");
|
| 22859 |
ashik.ali |
1315 |
}
|
| 23650 |
amit.gupta |
1316 |
|
| 22859 |
ashik.ali |
1317 |
}
|
| 23650 |
amit.gupta |
1318 |
|
|
|
1319 |
private void updateInventoryItemsAndScanRecord(Set<InventoryItem> inventoryItems, int fofoId,
|
| 31030 |
amit.gupta |
1320 |
Map<Integer, Integer> inventoryItemQuantityUsed, int fofoOrderId) {
|
| 23650 |
amit.gupta |
1321 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 22859 |
ashik.ali |
1322 |
inventoryItem.setLastScanType(ScanType.SALE);
|
|
|
1323 |
ScanRecord scanRecord = new ScanRecord();
|
|
|
1324 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
|
|
1325 |
scanRecord.setFofoId(fofoId);
|
| 24264 |
amit.gupta |
1326 |
scanRecord.setOrderId(fofoOrderId);
|
| 23650 |
amit.gupta |
1327 |
// correct this
|
| 22859 |
ashik.ali |
1328 |
scanRecord.setQuantity(inventoryItemQuantityUsed.get(inventoryItem.getId()));
|
|
|
1329 |
scanRecord.setType(ScanType.SALE);
|
|
|
1330 |
scanRecordRepository.persist(scanRecord);
|
| 23566 |
amit.gupta |
1331 |
purchaseReturnItemRepository.deleteById(inventoryItem.getId());
|
| 23650 |
amit.gupta |
1332 |
|
| 22859 |
ashik.ali |
1333 |
}
|
|
|
1334 |
}
|
| 23650 |
amit.gupta |
1335 |
|
|
|
1336 |
private void createFofoLineItem(int fofoOrderItemId, Set<InventoryItem> inventoryItems,
|
| 31030 |
amit.gupta |
1337 |
Map<Integer, Integer> inventoryItemIdQuantityUsed) {
|
| 23650 |
amit.gupta |
1338 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 22859 |
ashik.ali |
1339 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
|
|
1340 |
fofoLineItem.setFofoOrderItemId(fofoOrderItemId);
|
|
|
1341 |
fofoLineItem.setSerialNumber(inventoryItem.getSerialNumber());
|
|
|
1342 |
fofoLineItem.setInventoryItemId(inventoryItem.getId());
|
|
|
1343 |
fofoLineItem.setQuantity(inventoryItemIdQuantityUsed.get(inventoryItem.getId()));
|
|
|
1344 |
fofoLineItemRepository.persist(fofoLineItem);
|
|
|
1345 |
}
|
|
|
1346 |
}
|
| 23650 |
amit.gupta |
1347 |
|
|
|
1348 |
private FofoOrderItem createAndGetFofoOrderItem(CustomFofoOrderItem customFofoOrderItem, int fofoOrderId,
|
| 31030 |
amit.gupta |
1349 |
Map<Integer, Item> itemMap, Set<InventoryItem> inventoryItems, Integer stateId)
|
| 23650 |
amit.gupta |
1350 |
throws ProfitMandiBusinessException {
|
| 22859 |
ashik.ali |
1351 |
FofoOrderItem fofoOrderItem = new FofoOrderItem();
|
|
|
1352 |
fofoOrderItem.setItemId(customFofoOrderItem.getItemId());
|
|
|
1353 |
fofoOrderItem.setQuantity(customFofoOrderItem.getQuantity());
|
|
|
1354 |
fofoOrderItem.setSellingPrice(customFofoOrderItem.getSellingPrice());
|
|
|
1355 |
fofoOrderItem.setOrderId(fofoOrderId);
|
| 25103 |
amit.gupta |
1356 |
TagListing tl = tagListingRepository.selectByItemId(customFofoOrderItem.getItemId());
|
| 25162 |
amit.gupta |
1357 |
// In case listing gets removed rebill it using the selling price
|
|
|
1358 |
if (tl != null) {
|
| 25103 |
amit.gupta |
1359 |
fofoOrderItem.setDp(tl.getSellingPrice());
|
| 26332 |
amit.gupta |
1360 |
fofoOrderItem.setMop(tl.getMop());
|
| 25103 |
amit.gupta |
1361 |
} else {
|
|
|
1362 |
fofoOrderItem.setDp(customFofoOrderItem.getSellingPrice());
|
| 26332 |
amit.gupta |
1363 |
fofoOrderItem.setMop(customFofoOrderItem.getSellingPrice());
|
| 25103 |
amit.gupta |
1364 |
}
|
| 22859 |
ashik.ali |
1365 |
fofoOrderItem.setDiscount(customFofoOrderItem.getDiscountAmount());
|
| 24823 |
amit.gupta |
1366 |
|
| 22859 |
ashik.ali |
1367 |
Item item = itemMap.get(customFofoOrderItem.getItemId());
|
| 23172 |
ashik.ali |
1368 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
1369 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 23650 |
amit.gupta |
1370 |
if (stateId != null) {
|
| 26817 |
amit.gupta |
1371 |
itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(new ArrayList<>(itemMap.keySet()), stateId);
|
| 23650 |
amit.gupta |
1372 |
} else {
|
| 26817 |
amit.gupta |
1373 |
itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(new ArrayList<>(itemMap.keySet()));
|
| 23172 |
ashik.ali |
1374 |
}
|
| 23650 |
amit.gupta |
1375 |
for (InventoryItem inventoryItem : inventoryItems) {
|
|
|
1376 |
if (stateId == null) {
|
| 23172 |
ashik.ali |
1377 |
fofoOrderItem.setIgstRate(itemIdIgstTaxRateMap.get(inventoryItem.getItemId()));
|
| 23650 |
amit.gupta |
1378 |
} else {
|
| 23172 |
ashik.ali |
1379 |
fofoOrderItem.setCgstRate(itemIdStateTaxRateMap.get(inventoryItem.getItemId()).getCgstRate());
|
|
|
1380 |
fofoOrderItem.setSgstRate(itemIdStateTaxRateMap.get(inventoryItem.getItemId()).getSgstRate());
|
|
|
1381 |
}
|
| 23650 |
amit.gupta |
1382 |
|
| 22859 |
ashik.ali |
1383 |
fofoOrderItem.setHsnCode(inventoryItem.getHsnCode());
|
|
|
1384 |
break;
|
|
|
1385 |
}
|
|
|
1386 |
fofoOrderItem.setBrand(item.getBrand());
|
|
|
1387 |
fofoOrderItem.setModelName(item.getModelName());
|
|
|
1388 |
fofoOrderItem.setModelNumber(item.getModelNumber());
|
|
|
1389 |
fofoOrderItem.setColor(item.getColor());
|
|
|
1390 |
fofoOrderItemRepository.persist(fofoOrderItem);
|
|
|
1391 |
return fofoOrderItem;
|
|
|
1392 |
}
|
| 23650 |
amit.gupta |
1393 |
|
| 28166 |
tejbeer |
1394 |
private FofoOrderItem getDummyFofoOrderItem(int itemId, int fofoOrderId, String serialNumber, Integer stateId)
|
|
|
1395 |
throws ProfitMandiBusinessException {
|
| 27516 |
amit.gupta |
1396 |
Item item = itemRepository.selectById(itemId);
|
|
|
1397 |
TagListing tl = tagListingRepository.selectByItemId(itemId);
|
|
|
1398 |
FofoOrderItem fofoOrderItem = new FofoOrderItem();
|
|
|
1399 |
fofoOrderItem.setItemId(itemId);
|
|
|
1400 |
fofoOrderItem.setQuantity(1);
|
|
|
1401 |
fofoOrderItem.setSellingPrice(tl.getMop());
|
|
|
1402 |
fofoOrderItem.setOrderId(fofoOrderId);
|
|
|
1403 |
// In case listing gets removed rebill it using the selling price
|
|
|
1404 |
fofoOrderItem.setDp(tl.getSellingPrice());
|
|
|
1405 |
fofoOrderItem.setMop(tl.getMop());
|
|
|
1406 |
fofoOrderItem.setDiscount(0);
|
|
|
1407 |
|
|
|
1408 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
1409 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
|
|
1410 |
if (stateId != null) {
|
|
|
1411 |
itemIdStateTaxRateMap = stateGstRateRepository.getStateTaxRate(Arrays.asList(itemId), stateId);
|
|
|
1412 |
} else {
|
|
|
1413 |
itemIdIgstTaxRateMap = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId));
|
|
|
1414 |
}
|
|
|
1415 |
|
|
|
1416 |
if (stateId == null) {
|
|
|
1417 |
fofoOrderItem.setIgstRate(itemIdIgstTaxRateMap.get(itemId));
|
|
|
1418 |
} else {
|
|
|
1419 |
fofoOrderItem.setCgstRate(itemIdStateTaxRateMap.get(itemId).getCgstRate());
|
|
|
1420 |
fofoOrderItem.setSgstRate(itemIdStateTaxRateMap.get(itemId).getSgstRate());
|
|
|
1421 |
}
|
|
|
1422 |
|
|
|
1423 |
fofoOrderItem.setHsnCode(item.getHsnCode());
|
|
|
1424 |
fofoOrderItem.setBrand(item.getBrand());
|
|
|
1425 |
fofoOrderItem.setModelName(item.getModelName());
|
|
|
1426 |
fofoOrderItem.setModelNumber(item.getModelNumber());
|
|
|
1427 |
fofoOrderItem.setColor(item.getColor());
|
|
|
1428 |
|
|
|
1429 |
Set<FofoLineItem> fofoLineItems = new HashSet<>();
|
|
|
1430 |
FofoLineItem fli = new FofoLineItem();
|
|
|
1431 |
fli.setQuantity(1);
|
|
|
1432 |
fli.setSerialNumber(serialNumber);
|
|
|
1433 |
fofoLineItems.add(fli);
|
|
|
1434 |
fofoOrderItem.setFofoLineItems(fofoLineItems);
|
|
|
1435 |
|
|
|
1436 |
return fofoOrderItem;
|
|
|
1437 |
}
|
|
|
1438 |
|
| 23650 |
amit.gupta |
1439 |
private void updateCurrentInventorySnapshot(List<CurrentInventorySnapshot> currentInventorySnapshots, int fofoId,
|
| 31030 |
amit.gupta |
1440 |
int itemId, int quantity) throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
1441 |
for (CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
|
|
|
1442 |
if (currentInventorySnapshot.getItemId() == itemId && currentInventorySnapshot.getFofoId() == fofoId) {
|
|
|
1443 |
currentInventorySnapshotRepository.updateAvailabilityByItemIdAndFofoId(itemId, fofoId,
|
|
|
1444 |
currentInventorySnapshot.getAvailability() - quantity);
|
| 22859 |
ashik.ali |
1445 |
}
|
|
|
1446 |
}
|
|
|
1447 |
}
|
| 23650 |
amit.gupta |
1448 |
|
|
|
1449 |
private void createPaymentOptions(FofoOrder fofoOrder, Set<CustomPaymentOption> customPaymentOptions)
|
|
|
1450 |
throws ProfitMandiBusinessException {
|
|
|
1451 |
for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
|
|
|
1452 |
if (customPaymentOption.getAmount() > 0) {
|
| 23546 |
ashik.ali |
1453 |
PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
|
| 23612 |
amit.gupta |
1454 |
paymentOptionTransaction.setReferenceId(fofoOrder.getId());
|
| 23546 |
ashik.ali |
1455 |
paymentOptionTransaction.setPaymentOptionId(customPaymentOption.getPaymentOptionId());
|
|
|
1456 |
paymentOptionTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
1457 |
paymentOptionTransaction.setAmount(customPaymentOption.getAmount());
|
| 23612 |
amit.gupta |
1458 |
paymentOptionTransaction.setFofoId(fofoOrder.getFofoId());
|
| 23546 |
ashik.ali |
1459 |
paymentOptionTransactionRepository.persist(paymentOptionTransaction);
|
| 23371 |
ashik.ali |
1460 |
}
|
| 22859 |
ashik.ali |
1461 |
}
|
|
|
1462 |
}
|
| 23650 |
amit.gupta |
1463 |
|
| 24275 |
amit.gupta |
1464 |
private FofoOrder createAndGetFofoOrder(int customerId, String customerGstNumber, int fofoId, String documentNumber,
|
| 31030 |
amit.gupta |
1465 |
float totalAmount, int customerAddressId) {
|
| 22859 |
ashik.ali |
1466 |
FofoOrder fofoOrder = new FofoOrder();
|
| 23369 |
ashik.ali |
1467 |
fofoOrder.setCustomerGstNumber(customerGstNumber);
|
| 22859 |
ashik.ali |
1468 |
fofoOrder.setCustomerId(customerId);
|
|
|
1469 |
fofoOrder.setFofoId(fofoId);
|
| 24226 |
amit.gupta |
1470 |
fofoOrder.setInvoiceNumber(documentNumber);
|
| 22859 |
ashik.ali |
1471 |
fofoOrder.setTotalAmount(totalAmount);
|
|
|
1472 |
fofoOrder.setCustomerAddressId(customerAddressId);
|
|
|
1473 |
fofoOrderRepository.persist(fofoOrder);
|
|
|
1474 |
return fofoOrder;
|
|
|
1475 |
}
|
| 23650 |
amit.gupta |
1476 |
|
|
|
1477 |
private void validateItemsSerializedNonSerialized(List<Item> items,
|
| 31030 |
amit.gupta |
1478 |
Map<Integer, CustomFofoOrderItem> customFofoOrderItemMap) throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
1479 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
| 22859 |
ashik.ali |
1480 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|
| 23650 |
amit.gupta |
1481 |
for (Item i : items) {
|
| 22872 |
ashik.ali |
1482 |
CustomFofoOrderItem customFofoOrderItem = customFofoOrderItemMap.get(i.getId());
|
| 23650 |
amit.gupta |
1483 |
if (i.getType().equals(ItemType.SERIALIZED)) {
|
|
|
1484 |
if (customFofoOrderItem == null || customFofoOrderItem.getSerialNumberDetails().isEmpty()) {
|
| 22872 |
ashik.ali |
1485 |
invalidItemIdSerialNumbers.add(i.getId());
|
| 22859 |
ashik.ali |
1486 |
}
|
| 23650 |
amit.gupta |
1487 |
} else {
|
|
|
1488 |
Set<String> serialNumbers = this
|
|
|
1489 |
.serialNumberDetailsToSerialNumbers(customFofoOrderItem.getSerialNumberDetails());
|
|
|
1490 |
if (customFofoOrderItem == null || !serialNumbers.isEmpty()) {
|
| 22872 |
ashik.ali |
1491 |
itemIdNonSerializedSerialNumbers.add(i.getId());
|
| 22859 |
ashik.ali |
1492 |
}
|
|
|
1493 |
}
|
|
|
1494 |
}
|
|
|
1495 |
|
| 23650 |
amit.gupta |
1496 |
if (!invalidItemIdSerialNumbers.isEmpty()) {
|
| 22859 |
ashik.ali |
1497 |
LOGGER.error("Invalid itemId's serialNumbers for serialized{}", invalidItemIdSerialNumbers);
|
|
|
1498 |
// itemId's are serialized you are saying these are not serialized
|
| 23650 |
amit.gupta |
1499 |
throw new ProfitMandiBusinessException("invalidItemIdSerialNumbers", invalidItemIdSerialNumbers,
|
|
|
1500 |
"FFORDR_1013");
|
| 22859 |
ashik.ali |
1501 |
}
|
|
|
1502 |
|
| 23650 |
amit.gupta |
1503 |
if (!itemIdNonSerializedSerialNumbers.isEmpty()) {
|
| 22859 |
ashik.ali |
1504 |
LOGGER.error("Invalid itemId's serialNumbers for non serialized{}", itemIdNonSerializedSerialNumbers);
|
|
|
1505 |
// itemId's are non serialized you are saying these are serialized
|
| 23650 |
amit.gupta |
1506 |
throw new ProfitMandiBusinessException("itemIdNonSerializedSerialNumbers", itemIdNonSerializedSerialNumbers,
|
|
|
1507 |
"FFORDR_1014");
|
| 22859 |
ashik.ali |
1508 |
}
|
|
|
1509 |
}
|
| 23650 |
amit.gupta |
1510 |
|
|
|
1511 |
private void validateCurrentInventorySnapshotQuantities(List<CurrentInventorySnapshot> currentInventorySnapshots,
|
| 31030 |
amit.gupta |
1512 |
Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap) throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
1513 |
if (itemIdCustomFofoOrderItemMap.keySet().size() != currentInventorySnapshots.size()) {
|
| 22859 |
ashik.ali |
1514 |
throw new ProfitMandiBusinessException("quantiiesSize", currentInventorySnapshots.size(), "");
|
|
|
1515 |
}
|
| 23650 |
amit.gupta |
1516 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); // this is for error
|
|
|
1517 |
LOGGER.info("currentInventorySnapshots " + currentInventorySnapshots);
|
| 22872 |
ashik.ali |
1518 |
LOGGER.info("CustomFofoLineItemMap {}", itemIdCustomFofoOrderItemMap);
|
| 23650 |
amit.gupta |
1519 |
for (CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
|
|
|
1520 |
CustomFofoOrderItem customFofoOrderItem = itemIdCustomFofoOrderItemMap
|
|
|
1521 |
.get(currentInventorySnapshot.getItemId());
|
| 22872 |
ashik.ali |
1522 |
LOGGER.info("customFofoOrderItem {}", customFofoOrderItem);
|
| 23650 |
amit.gupta |
1523 |
if (customFofoOrderItem.getQuantity() > currentInventorySnapshot.getAvailability()) {
|
|
|
1524 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
|
|
1525 |
itemIdQuantityAvailability.setItemId(customFofoOrderItem.getItemId());
|
|
|
1526 |
Quantity quantity = new Quantity();
|
|
|
1527 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
|
|
1528 |
quantity.setRequested(customFofoOrderItem.getQuantity());
|
|
|
1529 |
itemIdQuantityAvailability.setQuantity(quantity);
|
|
|
1530 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
|
|
1531 |
}
|
| 22859 |
ashik.ali |
1532 |
}
|
|
|
1533 |
|
| 23650 |
amit.gupta |
1534 |
if (!itemIdQuantityAvailabilities.isEmpty()) {
|
| 22859 |
ashik.ali |
1535 |
// itemIdQuantity request is not valid
|
| 23650 |
amit.gupta |
1536 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}",
|
|
|
1537 |
itemIdQuantityAvailabilities);
|
|
|
1538 |
throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities,
|
|
|
1539 |
"FFORDR_1015");
|
| 22859 |
ashik.ali |
1540 |
}
|
|
|
1541 |
}
|
| 23650 |
amit.gupta |
1542 |
|
|
|
1543 |
private int getItemIdFromSerialNumber(Map<Integer, CustomFofoOrderItem> itemIdCustomFofoOrderItemMap,
|
| 31030 |
amit.gupta |
1544 |
String serialNumber) {
|
| 22872 |
ashik.ali |
1545 |
int itemId = 0;
|
| 23650 |
amit.gupta |
1546 |
for (Map.Entry<Integer, CustomFofoOrderItem> entry : itemIdCustomFofoOrderItemMap.entrySet()) {
|
| 22872 |
ashik.ali |
1547 |
Set<SerialNumberDetail> serialNumberDetails = entry.getValue().getSerialNumberDetails();
|
| 23650 |
amit.gupta |
1548 |
for (SerialNumberDetail serialNumberDetail : serialNumberDetails) {
|
|
|
1549 |
if (serialNumberDetail.getSerialNumber().equals(serialNumber)) {
|
| 22872 |
ashik.ali |
1550 |
itemId = entry.getKey();
|
|
|
1551 |
break;
|
|
|
1552 |
}
|
| 22859 |
ashik.ali |
1553 |
}
|
|
|
1554 |
}
|
| 22872 |
ashik.ali |
1555 |
return itemId;
|
| 22859 |
ashik.ali |
1556 |
}
|
| 23650 |
amit.gupta |
1557 |
|
|
|
1558 |
private Map<Integer, Item> toItemMap(List<Item> items) {
|
| 22955 |
ashik.ali |
1559 |
Function<Item, Integer> itemIdFunction = new Function<Item, Integer>() {
|
|
|
1560 |
@Override
|
|
|
1561 |
public Integer apply(Item item) {
|
|
|
1562 |
return item.getId();
|
|
|
1563 |
}
|
|
|
1564 |
};
|
|
|
1565 |
Function<Item, Item> itemFunction = new Function<Item, Item>() {
|
|
|
1566 |
@Override
|
|
|
1567 |
public Item apply(Item item) {
|
|
|
1568 |
return item;
|
|
|
1569 |
}
|
|
|
1570 |
};
|
|
|
1571 |
return items.stream().collect(Collectors.toMap(itemIdFunction, itemFunction));
|
| 22859 |
ashik.ali |
1572 |
}
|
|
|
1573 |
|
| 23650 |
amit.gupta |
1574 |
private void setCustomerAddress(CustomerAddress customerAddress, CustomAddress customAddress) {
|
| 22859 |
ashik.ali |
1575 |
customerAddress.setName(customAddress.getName());
|
| 29068 |
amit.gupta |
1576 |
customerAddress.setLastName(customAddress.getLastName());
|
| 22859 |
ashik.ali |
1577 |
customerAddress.setLine1(customAddress.getLine1());
|
|
|
1578 |
customerAddress.setLine2(customAddress.getLine2());
|
|
|
1579 |
customerAddress.setLandmark(customAddress.getLandmark());
|
|
|
1580 |
customerAddress.setCity(customAddress.getCity());
|
|
|
1581 |
customerAddress.setPinCode(customAddress.getPinCode());
|
|
|
1582 |
customerAddress.setState(customAddress.getState());
|
|
|
1583 |
customerAddress.setCountry(customAddress.getCountry());
|
|
|
1584 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
|
|
1585 |
}
|
|
|
1586 |
|
| 23650 |
amit.gupta |
1587 |
private CustomAddress createCustomAddress(Address address) {
|
| 22859 |
ashik.ali |
1588 |
CustomAddress customAddress = new CustomAddress();
|
|
|
1589 |
customAddress.setName(address.getName());
|
|
|
1590 |
customAddress.setLine1(address.getLine1());
|
|
|
1591 |
customAddress.setLine2(address.getLine2());
|
|
|
1592 |
customAddress.setLandmark(address.getLandmark());
|
|
|
1593 |
customAddress.setCity(address.getCity());
|
|
|
1594 |
customAddress.setPinCode(address.getPinCode());
|
|
|
1595 |
customAddress.setState(address.getState());
|
|
|
1596 |
customAddress.setCountry(address.getCountry());
|
|
|
1597 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
|
|
1598 |
return customAddress;
|
|
|
1599 |
}
|
|
|
1600 |
|
| 23650 |
amit.gupta |
1601 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress) {
|
| 22859 |
ashik.ali |
1602 |
CustomAddress customAddress = new CustomAddress();
|
|
|
1603 |
customAddress.setName(customerAddress.getName());
|
| 26817 |
amit.gupta |
1604 |
customAddress.setLastName(customerAddress.getLastName());
|
| 22859 |
ashik.ali |
1605 |
customAddress.setLine1(customerAddress.getLine1());
|
|
|
1606 |
customAddress.setLine2(customerAddress.getLine2());
|
|
|
1607 |
customAddress.setLandmark(customerAddress.getLandmark());
|
|
|
1608 |
customAddress.setCity(customerAddress.getCity());
|
|
|
1609 |
customAddress.setPinCode(customerAddress.getPinCode());
|
|
|
1610 |
customAddress.setState(customerAddress.getState());
|
|
|
1611 |
customAddress.setCountry(customerAddress.getCountry());
|
|
|
1612 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
|
|
1613 |
return customAddress;
|
|
|
1614 |
}
|
|
|
1615 |
|
| 23650 |
amit.gupta |
1616 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount)
|
|
|
1617 |
throws ProfitMandiBusinessException {
|
| 23365 |
ashik.ali |
1618 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23650 |
amit.gupta |
1619 |
|
| 22859 |
ashik.ali |
1620 |
float calculatedAmount = 0;
|
| 23650 |
amit.gupta |
1621 |
for (CustomPaymentOption customPaymentOption : customPaymentOptions) {
|
| 23365 |
ashik.ali |
1622 |
paymentOptionIds.add(customPaymentOption.getPaymentOptionId());
|
|
|
1623 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
| 22859 |
ashik.ali |
1624 |
}
|
| 23650 |
amit.gupta |
1625 |
if (calculatedAmount != totalAmount) {
|
| 28390 |
amit.gupta |
1626 |
LOGGER.warn("Error occured while validating payment options amount - {} != TotalAmount {}",
|
| 23650 |
amit.gupta |
1627 |
calculatedAmount, totalAmount);
|
|
|
1628 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT,
|
|
|
1629 |
calculatedAmount, "FFORDR_1016");
|
| 22859 |
ashik.ali |
1630 |
}
|
| 23650 |
amit.gupta |
1631 |
|
| 23365 |
ashik.ali |
1632 |
List<Integer> foundPaymentOptionIds = paymentOptionRepository.selectIdsByIds(paymentOptionIds);
|
| 23650 |
amit.gupta |
1633 |
if (foundPaymentOptionIds.size() != paymentOptionIds.size()) {
|
| 23365 |
ashik.ali |
1634 |
paymentOptionIds.removeAll(foundPaymentOptionIds);
|
| 23650 |
amit.gupta |
1635 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_ID, paymentOptionIds,
|
|
|
1636 |
"FFORDR_1017");
|
| 23365 |
ashik.ali |
1637 |
}
|
| 22859 |
ashik.ali |
1638 |
}
|
| 23650 |
amit.gupta |
1639 |
|
| 22925 |
ashik.ali |
1640 |
@Override
|
|
|
1641 |
public List<FofoOrderItem> getByOrderId(int orderId) throws ProfitMandiBusinessException {
|
|
|
1642 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(orderId);
|
| 23650 |
amit.gupta |
1643 |
if (!fofoOrderItems.isEmpty()) {
|
| 22925 |
ashik.ali |
1644 |
List<FofoOrderItem> newFofoOrderItems = new ArrayList<>();
|
| 23650 |
amit.gupta |
1645 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = this
|
|
|
1646 |
.toFofoOrderItemIdFofoLineItems(fofoOrderItems);
|
| 22925 |
ashik.ali |
1647 |
Iterator<FofoOrderItem> fofoOrderItemsIterator = fofoOrderItems.iterator();
|
| 23650 |
amit.gupta |
1648 |
while (fofoOrderItemsIterator.hasNext()) {
|
| 22925 |
ashik.ali |
1649 |
FofoOrderItem fofoOrderItem = fofoOrderItemsIterator.next();
|
|
|
1650 |
fofoOrderItem.setFofoLineItems(fofoOrderItemIdFofoLineItemsMap.get(fofoOrderItem.getId()));
|
|
|
1651 |
newFofoOrderItems.add(fofoOrderItem);
|
|
|
1652 |
fofoOrderItemsIterator.remove();
|
|
|
1653 |
}
|
|
|
1654 |
fofoOrderItems = newFofoOrderItems;
|
|
|
1655 |
}
|
|
|
1656 |
return fofoOrderItems;
|
|
|
1657 |
}
|
| 23650 |
amit.gupta |
1658 |
|
|
|
1659 |
private Set<Integer> toFofoOrderItemIds(List<FofoOrderItem> fofoOrderItems) {
|
| 22955 |
ashik.ali |
1660 |
Function<FofoOrderItem, Integer> fofoOrderItemToFofoOrderItemIdFunction = new Function<FofoOrderItem, Integer>() {
|
|
|
1661 |
@Override
|
|
|
1662 |
public Integer apply(FofoOrderItem fofoOrderItem) {
|
|
|
1663 |
return fofoOrderItem.getId();
|
|
|
1664 |
}
|
|
|
1665 |
};
|
|
|
1666 |
return fofoOrderItems.stream().map(fofoOrderItemToFofoOrderItemIdFunction).collect(Collectors.toSet());
|
| 22925 |
ashik.ali |
1667 |
}
|
| 23650 |
amit.gupta |
1668 |
|
|
|
1669 |
private Map<Integer, Set<FofoLineItem>> toFofoOrderItemIdFofoLineItems(List<FofoOrderItem> fofoOrderItems) {
|
| 22925 |
ashik.ali |
1670 |
Set<Integer> fofoOrderItemIds = this.toFofoOrderItemIds(fofoOrderItems);
|
|
|
1671 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByFofoOrderItemIds(fofoOrderItemIds);
|
|
|
1672 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = new HashMap<>();
|
| 23650 |
amit.gupta |
1673 |
for (FofoLineItem fofoLineItem : fofoLineItems) {
|
|
|
1674 |
if (!fofoOrderItemIdFofoLineItemsMap.containsKey(fofoLineItem.getFofoOrderItemId())) {
|
| 22925 |
ashik.ali |
1675 |
Set<FofoLineItem> fofoLineItems2 = new HashSet<>();
|
|
|
1676 |
fofoLineItems2.add(fofoLineItem);
|
|
|
1677 |
fofoOrderItemIdFofoLineItemsMap.put(fofoLineItem.getFofoOrderItemId(), fofoLineItems2);
|
| 23650 |
amit.gupta |
1678 |
} else {
|
| 22925 |
ashik.ali |
1679 |
fofoOrderItemIdFofoLineItemsMap.get(fofoLineItem.getFofoOrderItemId()).add(fofoLineItem);
|
|
|
1680 |
}
|
|
|
1681 |
}
|
|
|
1682 |
return fofoOrderItemIdFofoLineItemsMap;
|
|
|
1683 |
}
|
| 23650 |
amit.gupta |
1684 |
|
| 23418 |
ashik.ali |
1685 |
@Override
|
| 23650 |
amit.gupta |
1686 |
public void updateCustomerDetails(CustomCustomer customCustomer, String invoiceNumber)
|
|
|
1687 |
throws ProfitMandiBusinessException {
|
| 23582 |
ashik.ali |
1688 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
|
|
1689 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
1690 |
customer.setFirstName(customCustomer.getFirstName());
|
|
|
1691 |
customer.setLastName(customCustomer.getLastName());
|
| 24121 |
govind |
1692 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
|
|
1693 |
customer.setEmailId(customCustomer.getEmailId());
|
| 23582 |
ashik.ali |
1694 |
customerRepository.persist(customer);
|
|
|
1695 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 27411 |
amit.gupta |
1696 |
if (!customerAddress.getState().equalsIgnoreCase(customCustomer.getAddress().getState())) {
|
| 25101 |
amit.gupta |
1697 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1698 |
resetTaxation(fofoOrder.getFofoId(), customerAddress, fofoOrderItems);
|
|
|
1699 |
}
|
| 23582 |
ashik.ali |
1700 |
this.setCustomerAddress(customerAddress, customCustomer.getAddress());
|
|
|
1701 |
customerAddressRepository.persist(customerAddress);
|
| 24121 |
govind |
1702 |
fofoOrder.setCustomerGstNumber(customCustomer.getGstNumber());
|
| 23582 |
ashik.ali |
1703 |
}
|
| 23418 |
ashik.ali |
1704 |
|
| 25101 |
amit.gupta |
1705 |
private void resetTaxation(int fofoId, CustomerAddress customerAddress, List<FofoOrderItem> fofoOrderItems)
|
|
|
1706 |
throws ProfitMandiBusinessException {
|
|
|
1707 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoId);
|
|
|
1708 |
|
|
|
1709 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
1710 |
|
|
|
1711 |
Integer stateId = null;
|
| 27411 |
amit.gupta |
1712 |
if (customerAddress.getState().equalsIgnoreCase(retailerAddress.getState())) {
|
| 25101 |
amit.gupta |
1713 |
try {
|
| 30527 |
tejbeer |
1714 |
stateId = Long.valueOf(stateRepository.selectByName(customerAddress.getState()).getId()).intValue();
|
| 25101 |
amit.gupta |
1715 |
} catch (Exception e) {
|
|
|
1716 |
LOGGER.error("Unable to get state rates");
|
|
|
1717 |
}
|
|
|
1718 |
}
|
|
|
1719 |
List<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
|
|
1720 |
final Map<Integer, GstRate> gstRates;
|
|
|
1721 |
if (stateId != null) {
|
| 26817 |
amit.gupta |
1722 |
gstRates = stateGstRateRepository.getStateTaxRate(itemIds, stateId);
|
| 25101 |
amit.gupta |
1723 |
} else {
|
|
|
1724 |
gstRates = new HashMap<>();
|
| 26817 |
amit.gupta |
1725 |
stateGstRateRepository.getIgstTaxRate(itemIds).entrySet().forEach(x -> {
|
| 25101 |
amit.gupta |
1726 |
GstRate gstRate = new GstRate();
|
|
|
1727 |
gstRate.setIgstRate(x.getValue());
|
|
|
1728 |
gstRate.setCgstRate(0f);
|
|
|
1729 |
gstRate.setSgstRate(0f);
|
|
|
1730 |
gstRates.put(x.getKey(), gstRate);
|
|
|
1731 |
|
|
|
1732 |
});
|
|
|
1733 |
}
|
|
|
1734 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
|
|
1735 |
GstRate rate = gstRates.get(fofoOrderItem.getItemId());
|
|
|
1736 |
fofoOrderItem.setCgstRate(rate.getCgstRate());
|
|
|
1737 |
fofoOrderItem.setSgstRate(rate.getSgstRate());
|
|
|
1738 |
fofoOrderItem.setIgstRate(rate.getIgstRate());
|
|
|
1739 |
}
|
|
|
1740 |
}
|
|
|
1741 |
|
| 23638 |
amit.gupta |
1742 |
@Override
|
| 24275 |
amit.gupta |
1743 |
public CustomerCreditNote badReturn(int fofoId, FoiBadReturnRequest foiBadReturnRequest)
|
|
|
1744 |
throws ProfitMandiBusinessException {
|
| 23655 |
amit.gupta |
1745 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
|
| 23650 |
amit.gupta |
1746 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
| 23655 |
amit.gupta |
1747 |
if (fofoOrder.getFofoId() != fofoId) {
|
| 23638 |
amit.gupta |
1748 |
throw new ProfitMandiBusinessException("Partner Auth", "", "Invalid Order");
|
|
|
1749 |
}
|
| 23655 |
amit.gupta |
1750 |
int billedQty = foi.getQuantity() - customerReturnItemRepository.selectAllByOrderItemId(foi.getId()).size();
|
| 24275 |
amit.gupta |
1751 |
if (foiBadReturnRequest.getMarkedBadArr().size() > billedQty) {
|
| 23655 |
amit.gupta |
1752 |
throw new ProfitMandiBusinessException("Cant bad return more than what is billed", "", "Invalid Quantity");
|
|
|
1753 |
}
|
| 23650 |
amit.gupta |
1754 |
List<CustomerReturnItem> customerReturnItems = new ArrayList<>();
|
| 23655 |
amit.gupta |
1755 |
for (BadReturnRequest badReturnRequest : foiBadReturnRequest.getMarkedBadArr()) {
|
| 23650 |
amit.gupta |
1756 |
CustomerReturnItem customerReturnItem = new CustomerReturnItem();
|
|
|
1757 |
customerReturnItem.setFofoId(fofoId);
|
| 23655 |
amit.gupta |
1758 |
customerReturnItem.setFofoOrderItemId(foiBadReturnRequest.getFofoOrderItemId());
|
| 24264 |
amit.gupta |
1759 |
customerReturnItem.setFofoOrderId(fofoOrder.getId());
|
| 23655 |
amit.gupta |
1760 |
customerReturnItem.setRemarks(badReturnRequest.getRemarks());
|
| 23650 |
amit.gupta |
1761 |
customerReturnItem.setInventoryItemId(badReturnRequest.getInventoryItemId());
|
|
|
1762 |
customerReturnItem.setQuantity(1);
|
|
|
1763 |
customerReturnItem.setType(ReturnType.BAD);
|
| 24275 |
amit.gupta |
1764 |
// customerReturnItemRepository.persist(customerReturnItem);
|
| 23650 |
amit.gupta |
1765 |
inventoryService.saleReturnInventoryItem(customerReturnItem);
|
|
|
1766 |
customerReturnItems.add(customerReturnItem);
|
| 23638 |
amit.gupta |
1767 |
}
|
| 23655 |
amit.gupta |
1768 |
CustomerCreditNote creditNote = generateCreditNote(fofoOrder, customerReturnItems);
|
| 24275 |
amit.gupta |
1769 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
1770 |
purchaseReturnService.returnInventoryItem(fofoId, false, customerReturnItem.getInventoryItemId(),
|
|
|
1771 |
ReturnType.BAD);
|
| 23655 |
amit.gupta |
1772 |
}
|
| 27516 |
amit.gupta |
1773 |
// This should cancel the order
|
| 29562 |
amit.gupta |
1774 |
fofoOrder.setCancelledTimestamp(LocalDateTime.now());
|
| 29548 |
amit.gupta |
1775 |
this.reverseScheme(fofoOrder);
|
| 24275 |
amit.gupta |
1776 |
return creditNote;
|
| 23638 |
amit.gupta |
1777 |
}
|
|
|
1778 |
|
| 24275 |
amit.gupta |
1779 |
private CustomerCreditNote generateCreditNote(FofoOrder fofoOrder, List<CustomerReturnItem> customerReturnItems)
|
|
|
1780 |
throws ProfitMandiBusinessException {
|
| 23650 |
amit.gupta |
1781 |
|
| 23638 |
amit.gupta |
1782 |
InvoiceNumberGenerationSequence sequence = invoiceNumberGenerationSequenceRepository
|
| 23650 |
amit.gupta |
1783 |
.selectByFofoId(fofoOrder.getFofoId());
|
|
|
1784 |
sequence.setCreditNoteSequence(sequence.getCreditNoteSequence() + 1);
|
| 23638 |
amit.gupta |
1785 |
invoiceNumberGenerationSequenceRepository.persist(sequence);
|
| 24275 |
amit.gupta |
1786 |
|
| 23655 |
amit.gupta |
1787 |
String creditNoteNumber = sequence.getPrefix() + "/" + sequence.getCreditNoteSequence();
|
| 23650 |
amit.gupta |
1788 |
CustomerCreditNote creditNote = new CustomerCreditNote();
|
|
|
1789 |
creditNote.setCreditNoteNumber(creditNoteNumber);
|
|
|
1790 |
creditNote.setFofoId(fofoOrder.getFofoId());
|
| 23655 |
amit.gupta |
1791 |
creditNote.setFofoOrderId(fofoOrder.getId());
|
|
|
1792 |
creditNote.setFofoOrderItemId(customerReturnItems.get(0).getFofoOrderItemId());
|
|
|
1793 |
creditNote.setSettlementType(SettlementType.UNSETTLED);
|
| 23650 |
amit.gupta |
1794 |
customerCreditNoteRepository.persist(creditNote);
|
| 24275 |
amit.gupta |
1795 |
|
| 23650 |
amit.gupta |
1796 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
1797 |
customerReturnItem.setCreditNoteId(creditNote.getId());
|
|
|
1798 |
customerReturnItemRepository.persist(customerReturnItem);
|
| 23638 |
amit.gupta |
1799 |
}
|
| 24275 |
amit.gupta |
1800 |
// this.returnInventoryItems(inventoryItems, debitNote);
|
| 23638 |
amit.gupta |
1801 |
|
| 23655 |
amit.gupta |
1802 |
return creditNote;
|
| 23650 |
amit.gupta |
1803 |
}
|
| 24275 |
amit.gupta |
1804 |
|
| 23655 |
amit.gupta |
1805 |
@Override
|
|
|
1806 |
public CreditNotePdfModel getCreditNotePdfModel(int customerCreditNoteId) throws ProfitMandiBusinessException {
|
|
|
1807 |
CustomerCreditNote creditNote = customerCreditNoteRepository.selectById(customerCreditNoteId);
|
|
|
1808 |
return getCreditNotePdfModel(creditNote);
|
|
|
1809 |
}
|
| 24275 |
amit.gupta |
1810 |
|
|
|
1811 |
private CreditNotePdfModel getCreditNotePdfModel(CustomerCreditNote creditNote)
|
|
|
1812 |
throws ProfitMandiBusinessException {
|
| 23655 |
amit.gupta |
1813 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(creditNote.getFofoOrderId());
|
| 24275 |
amit.gupta |
1814 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
1815 |
.selectAllByCreditNoteId(creditNote.getId());
|
| 23655 |
amit.gupta |
1816 |
CustomCustomer customCustomer = getCustomCustomer(fofoOrder);
|
| 24275 |
amit.gupta |
1817 |
|
| 23655 |
amit.gupta |
1818 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
| 30426 |
tejbeer |
1819 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoOrder.getFofoId());
|
| 23655 |
amit.gupta |
1820 |
|
|
|
1821 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectById(creditNote.getFofoOrderItemId());
|
|
|
1822 |
float totalTaxRate = fofoOrderItem.getIgstRate() + fofoOrderItem.getSgstRate() + fofoOrderItem.getCgstRate();
|
|
|
1823 |
float taxableSellingPrice = fofoOrderItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
|
|
1824 |
float taxableDiscountPrice = fofoOrderItem.getDiscount() / (1 + totalTaxRate / 100);
|
|
|
1825 |
|
|
|
1826 |
CustomOrderItem customFofoOrderItem = new CustomOrderItem();
|
|
|
1827 |
customFofoOrderItem.setAmount(customerReturnItems.size() * (taxableSellingPrice - taxableDiscountPrice));
|
|
|
1828 |
customFofoOrderItem.setDescription(fofoOrderItem.getBrand() + " " + fofoOrderItem.getModelName() + " "
|
|
|
1829 |
+ fofoOrderItem.getModelNumber() + "-" + fofoOrderItem.getColor());
|
| 24275 |
amit.gupta |
1830 |
|
|
|
1831 |
if (ItemType.SERIALIZED.equals(itemRepository.selectById(fofoOrderItem.getItemId()).getType())) {
|
| 23655 |
amit.gupta |
1832 |
Set<Integer> inventoryItemIds = customerReturnItems.stream().map(x -> x.getInventoryItemId())
|
|
|
1833 |
.collect(Collectors.toSet());
|
|
|
1834 |
List<String> serialNumbers = inventoryItemRepository.selectByIds(inventoryItemIds).stream()
|
|
|
1835 |
.map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
|
|
1836 |
customFofoOrderItem.setDescription(
|
|
|
1837 |
customFofoOrderItem.getDescription() + "\n IMEIS - " + String.join(", ", serialNumbers));
|
|
|
1838 |
}
|
| 24275 |
amit.gupta |
1839 |
|
| 23655 |
amit.gupta |
1840 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
|
|
1841 |
customFofoOrderItem.setDiscount(taxableDiscountPrice);
|
|
|
1842 |
customFofoOrderItem.setQuantity(customerReturnItems.size());
|
| 24275 |
amit.gupta |
1843 |
customFofoOrderItem.setNetAmount(
|
|
|
1844 |
(fofoOrderItem.getSellingPrice() - fofoOrderItem.getDiscount()) * customFofoOrderItem.getQuantity());
|
| 23655 |
amit.gupta |
1845 |
|
|
|
1846 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getIgstRate()) / 100;
|
|
|
1847 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getCgstRate()) / 100;
|
|
|
1848 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoOrderItem.getSgstRate()) / 100;
|
|
|
1849 |
LOGGER.info("fofoOrderItem - {}", fofoOrderItem);
|
|
|
1850 |
customFofoOrderItem.setIgstRate(fofoOrderItem.getIgstRate());
|
|
|
1851 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
|
|
1852 |
customFofoOrderItem.setCgstRate(fofoOrderItem.getCgstRate());
|
|
|
1853 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
|
|
1854 |
customFofoOrderItem.setSgstRate(fofoOrderItem.getSgstRate());
|
|
|
1855 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
|
|
1856 |
customFofoOrderItem.setHsnCode(fofoOrderItem.getHsnCode());
|
| 23721 |
amit.gupta |
1857 |
customFofoOrderItem.setOrderId(1);
|
| 23655 |
amit.gupta |
1858 |
customerFofoOrderItems.add(customFofoOrderItem);
|
| 24275 |
amit.gupta |
1859 |
|
| 30321 |
amit.gupta |
1860 |
InvoicePdfModel pdfModel = new InvoicePdfModel();
|
| 23650 |
amit.gupta |
1861 |
pdfModel.setAuther("NSSPL");
|
| 23655 |
amit.gupta |
1862 |
pdfModel.setCustomer(customCustomer);
|
|
|
1863 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
1864 |
pdfModel.setInvoiceDate(FormattingUtils.formatDate(fofoOrder.getCreateTimestamp()));
|
|
|
1865 |
pdfModel.setTitle("Credit Note");
|
|
|
1866 |
pdfModel.setRetailer(customRetailer);
|
|
|
1867 |
pdfModel.setTotalAmount(customFofoOrderItem.getNetAmount());
|
|
|
1868 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 24275 |
amit.gupta |
1869 |
|
| 23650 |
amit.gupta |
1870 |
CreditNotePdfModel creditNotePdfModel = new CreditNotePdfModel();
|
|
|
1871 |
creditNotePdfModel.setCreditNoteDate(FormattingUtils.formatDate(creditNote.getCreateTimestamp()));
|
|
|
1872 |
creditNotePdfModel.setCreditNoteNumber(creditNote.getCreditNoteNumber());
|
|
|
1873 |
creditNotePdfModel.setPdfModel(pdfModel);
|
|
|
1874 |
return creditNotePdfModel;
|
|
|
1875 |
}
|
| 23638 |
amit.gupta |
1876 |
|
| 24275 |
amit.gupta |
1877 |
// This will remove the order and maintain order record and reverse inventory
|
|
|
1878 |
// and scheme
|
| 24264 |
amit.gupta |
1879 |
@Override
|
| 29548 |
amit.gupta |
1880 |
public void cancelOrder(List<String> invoiceNumbers) throws ProfitMandiBusinessException {
|
| 24275 |
amit.gupta |
1881 |
for (String invoiceNumber : invoiceNumbers) {
|
| 28166 |
tejbeer |
1882 |
// Cancel only when not cancelled
|
| 24264 |
amit.gupta |
1883 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 28166 |
tejbeer |
1884 |
if (fofoOrder.getCancelledTimestamp() == null) {
|
| 27734 |
amit.gupta |
1885 |
fofoOrder.setCancelledTimestamp(LocalDateTime.now());
|
| 29548 |
amit.gupta |
1886 |
PaymentOptionTransaction paymentTransaction = new PaymentOptionTransaction();
|
|
|
1887 |
paymentTransaction.setAmount(-fofoOrder.getTotalAmount());
|
|
|
1888 |
paymentTransaction.setFofoId(fofoOrder.getFofoId());
|
|
|
1889 |
paymentTransaction.setReferenceId(fofoOrder.getId());
|
|
|
1890 |
paymentTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
1891 |
paymentTransaction.setPaymentOptionId(1);
|
|
|
1892 |
paymentOptionTransactionRepository.persist(paymentTransaction);
|
| 29707 |
tejbeer |
1893 |
|
| 27734 |
amit.gupta |
1894 |
List<FofoOrderItem> fois = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1895 |
List<InventoryItem> inventoryItems = new ArrayList<>();
|
|
|
1896 |
fois.stream().forEach(x -> {
|
| 29707 |
tejbeer |
1897 |
x.getFofoLineItems().stream().forEach(y -> {
|
| 28166 |
tejbeer |
1898 |
inventoryService.rollbackInventory(y.getInventoryItemId(), y.getQuantity(),
|
|
|
1899 |
fofoOrder.getFofoId());
|
| 27734 |
amit.gupta |
1900 |
inventoryItems.add(inventoryItemRepository.selectById(y.getInventoryItemId()));
|
|
|
1901 |
});
|
|
|
1902 |
});
|
| 29707 |
tejbeer |
1903 |
// if(invoice)
|
| 29548 |
amit.gupta |
1904 |
this.reverseScheme(fofoOrder);
|
| 29557 |
amit.gupta |
1905 |
insuranceService.cancelInsurance(fofoOrder);
|
| 24264 |
amit.gupta |
1906 |
}
|
|
|
1907 |
}
|
|
|
1908 |
}
|
| 29707 |
tejbeer |
1909 |
|
| 29548 |
amit.gupta |
1910 |
@Override
|
|
|
1911 |
public void reverseScheme(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
|
|
1912 |
String reversalReason = "Order Rolledback/Cancelled/Returned for Invoice #" + fofoOrder.getInvoiceNumber();
|
|
|
1913 |
List<FofoOrderItem> fois = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 29707 |
tejbeer |
1914 |
Set<Integer> inventoryItemIds = fois.stream()
|
|
|
1915 |
.flatMap(x -> x.getFofoLineItems().stream().map(y -> y.getInventoryItemId()))
|
|
|
1916 |
.collect(Collectors.toSet());
|
| 29548 |
amit.gupta |
1917 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds);
|
| 29707 |
tejbeer |
1918 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason, SchemeService.OUT_SCHEME_TYPES);
|
| 29548 |
amit.gupta |
1919 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
|
|
1920 |
Arrays.asList(SchemeType.INVESTMENT));
|
|
|
1921 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
|
|
1922 |
Arrays.asList(SchemeType.ACTIVATION));
|
| 30449 |
amit.gupta |
1923 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
|
|
1924 |
Arrays.asList(SchemeType.SPECIAL_SUPPORT));
|
| 29707 |
tejbeer |
1925 |
|
| 29548 |
amit.gupta |
1926 |
}
|
| 24264 |
amit.gupta |
1927 |
|
| 24271 |
amit.gupta |
1928 |
@Override
|
| 31030 |
amit.gupta |
1929 |
public void reverseActivationScheme(List<Integer> inventoryItemIds) throws ProfitMandiBusinessException {
|
|
|
1930 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectAllByIds(inventoryItemIds);
|
|
|
1931 |
for (InventoryItem inventoryItem : inventoryItems) {
|
|
|
1932 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByInventoryItemId(inventoryItem.getId());
|
|
|
1933 |
FofoLineItem fofoLineItem = fofoLineItems.get(0);
|
|
|
1934 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectById(fofoLineItem.getFofoOrderItemId());
|
|
|
1935 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(fofoOrderItem.getOrderId());
|
|
|
1936 |
String reversalReason = "Scheme rolled back as activation date is invalid for imei " + inventoryItem.getSerialNumber();
|
|
|
1937 |
schemeService.reverseSchemes(Arrays.asList(inventoryItem), fofoOrder.getId(), reversalReason,
|
|
|
1938 |
Arrays.asList(SchemeType.ACTIVATION));
|
| 31032 |
amit.gupta |
1939 |
schemeService.reverseSchemes(Arrays.asList(inventoryItem), fofoOrder.getId(), reversalReason,
|
| 31030 |
amit.gupta |
1940 |
Arrays.asList(SchemeType.SPECIAL_SUPPORT));
|
|
|
1941 |
|
|
|
1942 |
}
|
|
|
1943 |
|
|
|
1944 |
}
|
|
|
1945 |
|
|
|
1946 |
@Override
|
| 24271 |
amit.gupta |
1947 |
public float getSales(int fofoId, LocalDateTime startDate, LocalDateTime endDate) {
|
| 24287 |
amit.gupta |
1948 |
Float sales = fofoOrderRepository.selectSaleSumGroupByFofoIds(startDate, endDate).get(fofoId);
|
| 24285 |
amit.gupta |
1949 |
return sales == null ? 0f : sales;
|
| 24271 |
amit.gupta |
1950 |
}
|
|
|
1951 |
|
|
|
1952 |
@Override
|
| 27083 |
amit.gupta |
1953 |
public LocalDateTime getMaxSalesDate(int fofoId, LocalDateTime startDate, LocalDateTime endDate) {
|
|
|
1954 |
LocalDateTime dateTime = fofoOrderRepository.selectMaxSaleDateGroupByFofoIds(startDate, endDate).get(fofoId);
|
|
|
1955 |
return dateTime;
|
|
|
1956 |
}
|
|
|
1957 |
|
|
|
1958 |
@Override
|
| 27516 |
amit.gupta |
1959 |
// Only being used internally
|
| 24271 |
amit.gupta |
1960 |
public float getSales(int fofoId, LocalDate onDate) {
|
| 24285 |
amit.gupta |
1961 |
LocalDateTime startTime = LocalDateTime.of(onDate, LocalTime.MIDNIGHT);
|
|
|
1962 |
LocalDateTime endTime = LocalDateTime.of(onDate, LocalTime.MIDNIGHT).plusDays(1);
|
|
|
1963 |
return this.getSales(fofoId, startTime, endTime);
|
| 24271 |
amit.gupta |
1964 |
}
|
|
|
1965 |
|
|
|
1966 |
@Override
|
|
|
1967 |
public float getSales(LocalDateTime onDate) {
|
|
|
1968 |
// TODO Auto-generated method stub
|
|
|
1969 |
return 0;
|
|
|
1970 |
}
|
|
|
1971 |
|
|
|
1972 |
@Override
|
|
|
1973 |
public float getSales(LocalDateTime startDate, LocalDateTime endDate) {
|
|
|
1974 |
// TODO Auto-generated method stub
|
|
|
1975 |
return 0;
|
|
|
1976 |
}
|
|
|
1977 |
|
| 24917 |
tejbeer |
1978 |
@Override
|
|
|
1979 |
public boolean notifyColorChange(int orderId, int itemId) throws ProfitMandiBusinessException {
|
|
|
1980 |
Order order = orderRepository.selectById(orderId);
|
| 26891 |
amit.gupta |
1981 |
saholicInventoryService.reservationCountByColor(itemId, order);
|
| 25101 |
amit.gupta |
1982 |
|
|
|
1983 |
order.getLineItem().setItemId(itemId);
|
|
|
1984 |
Item item = itemRepository.selectById(itemId);
|
| 24917 |
tejbeer |
1985 |
order.getLineItem().setColor(item.getColor());
|
|
|
1986 |
return true;
|
|
|
1987 |
}
|
|
|
1988 |
|
| 25083 |
amit.gupta |
1989 |
@Override
|
|
|
1990 |
public FofoOrder getOrderByInventoryItemId(int inventoryItemId) throws Exception {
|
|
|
1991 |
List<FofoLineItem> lineItems = fofoLineItemRepository.selectByInventoryItemId(inventoryItemId);
|
| 25101 |
amit.gupta |
1992 |
if (lineItems.size() > 0) {
|
| 25083 |
amit.gupta |
1993 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectById(lineItems.get(0).getFofoOrderItemId());
|
|
|
1994 |
fofoOrderItem.setFofoLineItems(new HashSet<>(lineItems));
|
|
|
1995 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(fofoOrderItem.getOrderId());
|
|
|
1996 |
fofoOrder.setOrderItem(fofoOrderItem);
|
|
|
1997 |
return fofoOrder;
|
|
|
1998 |
} else {
|
|
|
1999 |
throw new Exception(String.format("Could not find inventoryItemId - %s", inventoryItemId));
|
|
|
2000 |
}
|
|
|
2001 |
}
|
| 28166 |
tejbeer |
2002 |
|
|
|
2003 |
@Override
|
|
|
2004 |
public Map<Integer, Long> carryBagCreditCount(int fofoId) throws ProfitMandiBusinessException {
|
|
|
2005 |
|
|
|
2006 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
2007 |
LocalDateTime lastCredit = fs.getBagsLastCredited();
|
|
|
2008 |
/*
|
|
|
2009 |
* long carryBagCount = 0; List<FofoOrder> fofoOrders =
|
|
|
2010 |
* fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(fofoId,
|
|
|
2011 |
* lastCredit.atStartOfDay(), LocalDate.now().plusDays(1).atStartOfDay()); for
|
|
|
2012 |
* (FofoOrder fo : fofoOrders) { carryBagCount +=
|
|
|
2013 |
* fofoOrderItemRepository.selectByOrderId(fo.getId()).stream() .filter(x ->
|
|
|
2014 |
* x.getSellingPrice() >= 12000).count();
|
| 30449 |
amit.gupta |
2015 |
*
|
| 28166 |
tejbeer |
2016 |
* }
|
|
|
2017 |
*/
|
|
|
2018 |
|
|
|
2019 |
Session session = sessionFactory.getCurrentSession();
|
|
|
2020 |
CriteriaBuilder cb = session.getCriteriaBuilder();
|
|
|
2021 |
|
|
|
2022 |
CriteriaQuery<SimpleEntry> query = cb.createQuery(SimpleEntry.class);
|
|
|
2023 |
Root<FofoOrder> fofoOrder = query.from(FofoOrder.class);
|
|
|
2024 |
Root<FofoOrderItem> fofoOrderItem = query.from(FofoOrderItem.class);
|
| 30449 |
amit.gupta |
2025 |
Root<TagListing> tagListingRoot = query.from(TagListing.class);
|
|
|
2026 |
Root<Item> itemRoot = query.from(Item.class);
|
| 28166 |
tejbeer |
2027 |
|
|
|
2028 |
Predicate p2 = cb.between(fofoOrder.get(ProfitMandiConstants.CREATE_TIMESTAMP), lastCredit,
|
|
|
2029 |
LocalDate.now().atStartOfDay());
|
|
|
2030 |
Predicate p3 = cb.isNull(fofoOrder.get("cancelledTimestamp"));
|
| 30449 |
amit.gupta |
2031 |
Predicate joinPredicate = cb.and(
|
|
|
2032 |
cb.equal(fofoOrder.get(ProfitMandiConstants.ID), fofoOrderItem.get(ProfitMandiConstants.ORDER_ID)),
|
|
|
2033 |
cb.equal(fofoOrderItem.get("itemId"), tagListingRoot.get("itemId")),
|
|
|
2034 |
cb.equal(itemRoot.get("id"), tagListingRoot.get("itemId")),
|
| 30527 |
tejbeer |
2035 |
cb.equal(fofoOrder.get(ProfitMandiConstants.FOFO_ID), fofoId));
|
| 28166 |
tejbeer |
2036 |
ItemCriteria itemCriteria = new ItemCriteria();
|
|
|
2037 |
itemCriteria.setBrands(mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
2038 |
.collect(Collectors.toList()));
|
|
|
2039 |
float startValue = 12000;
|
|
|
2040 |
itemCriteria.setStartPrice(startValue);
|
|
|
2041 |
itemCriteria.setEndPrice(0);
|
|
|
2042 |
itemCriteria.setFeaturedPhone(false);
|
|
|
2043 |
itemCriteria.setSmartPhone(true);
|
|
|
2044 |
itemCriteria.setCatalogIds(new ArrayList<>());
|
|
|
2045 |
itemCriteria.setExcludeCatalogIds(new ArrayList<>());
|
| 30449 |
amit.gupta |
2046 |
Predicate itemPredicate = itemRepository.getItemPredicate(itemCriteria, cb, itemRoot, tagListingRoot);
|
|
|
2047 |
Predicate finalPredicate = cb.and(itemPredicate, p2, p3, joinPredicate);
|
| 28166 |
tejbeer |
2048 |
query = query.multiselect(fofoOrder.get(ProfitMandiConstants.FOFO_ID), cb.count(fofoOrder))
|
|
|
2049 |
.where(finalPredicate).groupBy(fofoOrder.get(ProfitMandiConstants.FOFO_ID));
|
|
|
2050 |
List<SimpleEntry> simpleEntries = session.createQuery(query).getResultList();
|
|
|
2051 |
Map<Integer, Long> returnMap = new HashMap<>();
|
|
|
2052 |
|
|
|
2053 |
for (SimpleEntry simpleEntry : simpleEntries) {
|
|
|
2054 |
returnMap.put((Integer) simpleEntry.getKey(), (Long) simpleEntry.getValue());
|
|
|
2055 |
}
|
|
|
2056 |
return returnMap;
|
|
|
2057 |
|
|
|
2058 |
}
|
| 25724 |
amit.gupta |
2059 |
}
|