| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 4 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
5 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
| 5 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
6 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
| - |
|
7 |
import com.spice.profitmandi.dao.entity.logistics.WarehouseProvider;
|
| - |
|
8 |
import com.spice.profitmandi.dao.entity.logistics.WarehouseRider;
|
| 6 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
9 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| - |
|
10 |
import com.spice.profitmandi.dao.entity.transaction.TransactionShipmentSequence;
|
| 7 |
import com.spice.profitmandi.dao.model.DispatchNotificationModel;
|
11 |
import com.spice.profitmandi.dao.model.DispatchNotificationModel;
|
| 8 |
import com.spice.profitmandi.dao.repository.logistics.ProviderTatRepository;
|
12 |
import com.spice.profitmandi.dao.repository.logistics.*;
|
| 9 |
import com.spice.profitmandi.dao.repository.logistics.PublicHolidaysRepository;
|
13 |
import com.spice.profitmandi.dao.repository.transaction.TransactionShipmentSequenceRepository;
|
| - |
|
14 |
import com.spice.profitmandi.service.integrations.gstpro.api.model.E_InvoiceCommon;
|
| 10 |
import in.shop2020.model.v1.order.OrderStatus;
|
15 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 11 |
import org.apache.commons.lang.StringUtils;
|
16 |
import org.apache.commons.lang.StringUtils;
|
| 12 |
import org.springframework.beans.factory.annotation.Autowired;
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 13 |
import org.springframework.stereotype.Component;
|
18 |
import org.springframework.stereotype.Component;
|
| 14 |
|
19 |
|
| Line 21... |
Line 26... |
| 21 |
import java.util.stream.Collectors;
|
26 |
import java.util.stream.Collectors;
|
| 22 |
|
27 |
|
| 23 |
@Component
|
28 |
@Component
|
| 24 |
public class LogisticsServiceImpl implements LogisticsService {
|
29 |
public class LogisticsServiceImpl implements LogisticsService {
|
| 25 |
|
30 |
|
| 26 |
@Autowired
|
31 |
@Autowired
|
| 27 |
private PublicHolidaysRepository publicHolidaysRepository;
|
32 |
private PublicHolidaysRepository publicHolidaysRepository;
|
| 28 |
|
33 |
|
| 29 |
@Autowired
|
34 |
@Autowired
|
| 30 |
private ProviderTatRepository providerTatRepository;
|
35 |
private ProviderTatRepository providerTatRepository;
|
| 31 |
|
36 |
|
| 32 |
@Override
|
37 |
@Autowired
|
| 33 |
public LocalDate calculateDeliveryTimeline(LocalDate date, ProviderTat providerTat, int delayDays) {
|
- |
|
| 34 |
int businessDays = 0;
|
- |
|
| 35 |
int deliveryTat = 3;
|
- |
|
| 36 |
if (providerTat != null) {
|
- |
|
| 37 |
deliveryTat = providerTat.getDeliveryTime();
|
- |
|
| 38 |
}
|
- |
|
| 39 |
deliveryTat = deliveryTat + delayDays;
|
- |
|
| 40 |
LocalDate currDate = date.plusDays(1);
|
- |
|
| 41 |
List<LocalDate> ph = publicHolidaysRepository.selectAllByDate(currDate).stream().map(x -> x.getDate())
|
- |
|
| 42 |
.collect(Collectors.toList());
|
- |
|
| 43 |
while (businessDays < deliveryTat) {
|
- |
|
| 44 |
if (ph.contains(currDate) || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
|
- |
|
| 45 |
} else {
|
- |
|
| 46 |
businessDays++;
|
- |
|
| 47 |
}
|
- |
|
| 48 |
currDate = currDate.plusDays(1);
|
- |
|
| 49 |
}
|
- |
|
| 50 |
return currDate;
|
- |
|
| 51 |
}
|
- |
|
| 52 |
|
- |
|
| 53 |
@Override
|
- |
|
| 54 |
public Map<String, DispatchNotificationModel> markedOrderShippedDetail(List<Order> orders, Provider provider,
|
- |
|
| 55 |
Map<String, DispatchNotificationModel> dispatchNotication, String airwaybillNo, LocalDateTime shippingTimestamp)
|
- |
|
| 56 |
throws ProfitMandiBusinessException {
|
- |
|
| 57 |
|
- |
|
| 58 |
for (Order order : orders) {
|
- |
|
| 59 |
if (order.getStatus().equals(OrderStatus.BILLED)) {
|
- |
|
| 60 |
if(order.getBillingTimestamp().isAfter(shippingTimestamp)) {
|
- |
|
| 61 |
throw new ProfitMandiBusinessException("Uploaded File", "",
|
- |
|
| 62 |
"Invoice Number " + order.getInvoiceNumber() + " cannot be shipped before billing date");
|
- |
|
| 63 |
}
|
- |
|
| 64 |
if (StringUtils.isEmpty(airwaybillNo)) {
|
- |
|
| 65 |
throw new ProfitMandiBusinessException("Uploaded File", "",
|
- |
|
| 66 |
"Invoice Number " + order.getInvoiceNumber() + " airwaybill_no is empty");
|
- |
|
| 67 |
|
- |
|
| 68 |
}
|
- |
|
| 69 |
|
- |
|
| 70 |
if (airwaybillNo.equals("Error")) {
|
- |
|
| 71 |
break;
|
- |
|
| 72 |
}
|
- |
|
| 73 |
order.setLogisticsProviderId(provider.getId());
|
38 |
ProviderRepository providerRepository;
|
| 74 |
order.setAirwayBillNumber(airwaybillNo);
|
- |
|
| 75 |
order.setStatus(OrderStatus.SHIPPED_FROM_WH);
|
- |
|
| 76 |
order.setStatusDescription("Order shipped from warehouses");
|
- |
|
| 77 |
|
- |
|
| 78 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
- |
|
| 79 |
order.getWarehouseId(), order.getRetailerPinCode());
|
- |
|
| 80 |
order.setShippingTimestamp(shippingTimestamp);
|
- |
|
| 81 |
|
- |
|
| 82 |
LocalDate deliveryDate = this.calculateDeliveryTimeline(LocalDate.now(), pt, 0);
|
- |
|
| 83 |
order.setExpectedDeliveryTime(deliveryDate.atStartOfDay());
|
- |
|
| 84 |
|
- |
|
| 85 |
if (dispatchNotication.get(airwaybillNo) != null) {
|
- |
|
| 86 |
DispatchNotificationModel dnm = dispatchNotication.get(airwaybillNo);
|
- |
|
| 87 |
List<String> invoiceNumbers = dnm.getInvoiceNumber();
|
- |
|
| 88 |
invoiceNumbers.add(order.getInvoiceNumber());
|
- |
|
| 89 |
dnm.setInvoiceNumber(invoiceNumbers);
|
- |
|
| 90 |
Float totalAmount = dnm.getTotalAmount();
|
- |
|
| 91 |
dnm.setTotalAmount(totalAmount + order.getTotalAmount());
|
- |
|
| 92 |
|
- |
|
| 93 |
int totalQty = dnm.getTotalQty();
|
- |
|
| 94 |
dnm.setTotalQty(totalQty + order.getLineItem().getQuantity());
|
- |
|
| 95 |
|
- |
|
| 96 |
dispatchNotication.put(airwaybillNo, dnm);
|
- |
|
| 97 |
|
- |
|
| 98 |
} else {
|
- |
|
| 99 |
DispatchNotificationModel dnm = new DispatchNotificationModel();
|
- |
|
| 100 |
List<String> invoiceNumber = new ArrayList<>();
|
- |
|
| 101 |
invoiceNumber.add(order.getInvoiceNumber());
|
- |
|
| 102 |
dnm.setInvoiceNumber(invoiceNumber);
|
- |
|
| 103 |
dnm.setTotalAmount(order.getTotalAmount());
|
- |
|
| 104 |
dnm.setTotalQty(order.getLineItem().getQuantity());
|
- |
|
| 105 |
dnm.setFofoId(order.getRetailerId());
|
- |
|
| 106 |
dnm.setProviderId(order.getLogisticsProviderId());
|
- |
|
| 107 |
dnm.setDate(deliveryDate);
|
- |
|
| 108 |
dnm.setShippingDate(shippingTimestamp.toLocalDate());
|
- |
|
| 109 |
dispatchNotication.put(airwaybillNo, dnm);
|
- |
|
| 110 |
|
39 |
|
| - |
|
40 |
@Override
|
| - |
|
41 |
public LocalDate calculateDeliveryTimeline(LocalDate date, ProviderTat providerTat, int delayDays) {
|
| - |
|
42 |
int businessDays = 0;
|
| - |
|
43 |
int deliveryTat = 3;
|
| - |
|
44 |
if (providerTat != null) {
|
| - |
|
45 |
deliveryTat = providerTat.getDeliveryTime();
|
| - |
|
46 |
}
|
| - |
|
47 |
deliveryTat = deliveryTat + delayDays;
|
| - |
|
48 |
LocalDate currDate = date.plusDays(1);
|
| - |
|
49 |
List<LocalDate> ph = publicHolidaysRepository.selectAllByDate(currDate).stream().map(x -> x.getDate())
|
| - |
|
50 |
.collect(Collectors.toList());
|
| - |
|
51 |
while (businessDays < deliveryTat) {
|
| - |
|
52 |
if (ph.contains(currDate) || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
|
| - |
|
53 |
} else {
|
| - |
|
54 |
businessDays++;
|
| - |
|
55 |
}
|
| - |
|
56 |
currDate = currDate.plusDays(1);
|
| - |
|
57 |
}
|
| - |
|
58 |
return currDate;
|
| - |
|
59 |
}
|
| - |
|
60 |
|
| - |
|
61 |
@Override
|
| - |
|
62 |
public Map<String, DispatchNotificationModel> markedOrderShippedDetail(List<Order> orders, Provider provider,
|
| - |
|
63 |
Map<String, DispatchNotificationModel> dispatchNotication, String airwaybillNo, LocalDateTime shippingTimestamp)
|
| - |
|
64 |
throws ProfitMandiBusinessException {
|
| - |
|
65 |
|
| - |
|
66 |
for (Order order : orders) {
|
| - |
|
67 |
if (order.getStatus().equals(OrderStatus.BILLED)) {
|
| - |
|
68 |
if (order.getBillingTimestamp().isAfter(shippingTimestamp)) {
|
| - |
|
69 |
throw new ProfitMandiBusinessException("Uploaded File", "",
|
| - |
|
70 |
"Invoice Number " + order.getInvoiceNumber() + " cannot be shipped before billing date");
|
| - |
|
71 |
}
|
| - |
|
72 |
if (StringUtils.isEmpty(airwaybillNo)) {
|
| - |
|
73 |
throw new ProfitMandiBusinessException("Uploaded File", "",
|
| - |
|
74 |
"Invoice Number " + order.getInvoiceNumber() + " airwaybill_no is empty");
|
| - |
|
75 |
}
|
| - |
|
76 |
if (airwaybillNo.equals("Error")) {
|
| - |
|
77 |
break;
|
| - |
|
78 |
}
|
| - |
|
79 |
order.setLogisticsProviderId(provider.getId());
|
| - |
|
80 |
order.setAirwayBillNumber(airwaybillNo);
|
| - |
|
81 |
order.setStatus(OrderStatus.SHIPPED_FROM_WH);
|
| - |
|
82 |
order.setStatusDescription("Order shipped from warehouses");
|
| - |
|
83 |
|
| - |
|
84 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
| - |
|
85 |
order.getWarehouseId(), order.getRetailerPinCode());
|
| - |
|
86 |
order.setShippingTimestamp(shippingTimestamp);
|
| - |
|
87 |
|
| - |
|
88 |
LocalDate deliveryDate = this.calculateDeliveryTimeline(LocalDate.now(), pt, 0);
|
| - |
|
89 |
order.setExpectedDeliveryTime(deliveryDate.atStartOfDay());
|
| - |
|
90 |
|
| - |
|
91 |
if (dispatchNotication.get(airwaybillNo) != null) {
|
| - |
|
92 |
DispatchNotificationModel dnm = dispatchNotication.get(airwaybillNo);
|
| - |
|
93 |
List<String> invoiceNumbers = dnm.getInvoiceNumber();
|
| - |
|
94 |
invoiceNumbers.add(order.getInvoiceNumber());
|
| - |
|
95 |
dnm.setInvoiceNumber(invoiceNumbers);
|
| - |
|
96 |
Float totalAmount = dnm.getTotalAmount();
|
| - |
|
97 |
dnm.setTotalAmount(totalAmount + order.getTotalAmount());
|
| - |
|
98 |
|
| - |
|
99 |
int totalQty = dnm.getTotalQty();
|
| - |
|
100 |
dnm.setTotalQty(totalQty + order.getLineItem().getQuantity());
|
| - |
|
101 |
|
| - |
|
102 |
dispatchNotication.put(airwaybillNo, dnm);
|
| - |
|
103 |
|
| - |
|
104 |
} else {
|
| - |
|
105 |
DispatchNotificationModel dnm = new DispatchNotificationModel();
|
| - |
|
106 |
List<String> invoiceNumber = new ArrayList<>();
|
| - |
|
107 |
invoiceNumber.add(order.getInvoiceNumber());
|
| - |
|
108 |
dnm.setInvoiceNumber(invoiceNumber);
|
| - |
|
109 |
dnm.setTotalAmount(order.getTotalAmount());
|
| - |
|
110 |
dnm.setTotalQty(order.getLineItem().getQuantity());
|
| - |
|
111 |
dnm.setFofoId(order.getRetailerId());
|
| - |
|
112 |
dnm.setProviderId(order.getLogisticsProviderId());
|
| - |
|
113 |
dnm.setDate(deliveryDate);
|
| - |
|
114 |
dnm.setShippingDate(shippingTimestamp.toLocalDate());
|
| - |
|
115 |
dispatchNotication.put(airwaybillNo, dnm);
|
| - |
|
116 |
|
| - |
|
117 |
}
|
| - |
|
118 |
|
| - |
|
119 |
}
|
| - |
|
120 |
|
| - |
|
121 |
}
|
| - |
|
122 |
return dispatchNotication;
|
| - |
|
123 |
|
| 111 |
}
|
124 |
}
|
| - |
|
125 |
|
| - |
|
126 |
@Autowired
|
| - |
|
127 |
WarehouseProviderRepository warehouseProviderRepository;
|
| - |
|
128 |
|
| - |
|
129 |
@Autowired
|
| - |
|
130 |
WarehouseRiderRepository warehouseRiderRepository;
|
| - |
|
131 |
|
| - |
|
132 |
@Autowired
|
| - |
|
133 |
TransactionShipmentSequenceRepository transactionShipmentSequenceRepository;
|
| - |
|
134 |
|
| - |
|
135 |
|
| - |
|
136 |
@Override
|
| - |
|
137 |
public E_InvoiceCommon.ReqPlGenIRN.EwbDetails getEwbDetails(Order order) {
|
| - |
|
138 |
|
| - |
|
139 |
E_InvoiceCommon.ReqPlGenIRN.EwbDetails ewbDetails = new E_InvoiceCommon.ReqPlGenIRN.EwbDetails();
|
| - |
|
140 |
//ewbDetails.Distance = String.valueOf(200);
|
| - |
|
141 |
//1 is road, 2 is rail, 3 is air, 4 is ship
|
| - |
|
142 |
|
| - |
|
143 |
if (order.getLogisticsProviderId() == ProfitMandiConstants.LOGISTICS_PROVIDER_SELF_PICKUP
|
| - |
|
144 |
|| order.getLogisticsProviderId() == ProfitMandiConstants.LOGISTICS_PROVIDER_RUNNER) {
|
| - |
|
145 |
TransactionShipmentSequence transactionShipmentSequence = transactionShipmentSequenceRepository.selectByTransactionShipmentSequence(order.getLogisticsTransactionId());
|
| - |
|
146 |
ewbDetails.VehNo = transactionShipmentSequence.getVehicleNumber();
|
| - |
|
147 |
ewbDetails.VehType = "R";
|
| - |
|
148 |
ewbDetails.TransMode = "1";
|
| - |
|
149 |
} else {
|
| - |
|
150 |
WarehouseProvider warehouseProvider = warehouseProviderRepository.selectByProviderWarehouse(order.getLogisticsProviderId(), order.getWarehouseId());
|
| - |
|
151 |
Provider provider = providerRepository.selectById(order.getLogisticsProviderId());
|
| - |
|
152 |
//Get logistics Provider Detail here
|
| - |
|
153 |
ewbDetails.TransId = warehouseProvider.getGstin();
|
| - |
|
154 |
ewbDetails.TransName = provider.getName();
|
| - |
|
155 |
}
|
| 112 |
|
156 |
|
| - |
|
157 |
ewbDetails.Distance = "0";
|
| 113 |
}
|
158 |
return ewbDetails;
|
| 114 |
|
159 |
|
| 115 |
}
|
160 |
}
|
| 116 |
return dispatchNotication;
|
- |
|
| 117 |
|
- |
|
| 118 |
}
|
- |
|
| 119 |
|
161 |
|
| 120 |
}
|
162 |
}
|