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