| 21234 |
kshitij.so |
1 |
package in.shop2020.hotspot.dashbaord.server;
|
|
|
2 |
|
| 21247 |
kshitij.so |
3 |
import in.shop2020.hotspot.dashbaord.shared.actions.AddJacketNumberResponse;
|
|
|
4 |
import in.shop2020.model.v1.inventory.BillingType;
|
| 21237 |
kshitij.so |
5 |
import in.shop2020.model.v1.order.Order;
|
| 21247 |
kshitij.so |
6 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
7 |
import in.shop2020.model.v1.order.ShipmentLogisticsCostDetail;
|
|
|
8 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 21237 |
kshitij.so |
9 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 21247 |
kshitij.so |
10 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 21234 |
kshitij.so |
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 21242 |
kshitij.so |
12 |
import in.shop2020.thrift.clients.WarehouseClient;
|
| 22588 |
amit.gupta |
13 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 21242 |
kshitij.so |
14 |
import in.shop2020.warehouse.InventoryItem;
|
| 21234 |
kshitij.so |
15 |
|
|
|
16 |
import java.io.File;
|
|
|
17 |
import java.io.FileInputStream;
|
|
|
18 |
import java.util.ArrayList;
|
| 23246 |
amit.gupta |
19 |
import java.util.Arrays;
|
| 22588 |
amit.gupta |
20 |
import java.util.Date;
|
| 21242 |
kshitij.so |
21 |
import java.util.HashMap;
|
| 21234 |
kshitij.so |
22 |
import java.util.List;
|
| 21242 |
kshitij.so |
23 |
import java.util.Map;
|
| 21247 |
kshitij.so |
24 |
import java.util.Set;
|
| 21234 |
kshitij.so |
25 |
|
| 21244 |
kshitij.so |
26 |
import org.apache.poi.hssf.usermodel.HSSFCell;
|
| 21234 |
kshitij.so |
27 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
28 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 21244 |
kshitij.so |
29 |
import org.apache.poi.ss.usermodel.DataFormatter;
|
| 21247 |
kshitij.so |
30 |
import org.apache.thrift.TException;
|
| 21234 |
kshitij.so |
31 |
import org.slf4j.Logger;
|
|
|
32 |
import org.slf4j.LoggerFactory;
|
|
|
33 |
|
| 21247 |
kshitij.so |
34 |
import com.providers.logistics.Provider;
|
|
|
35 |
import com.providers.logistics.ProviderFactory;
|
| 21242 |
kshitij.so |
36 |
|
| 21247 |
kshitij.so |
37 |
|
| 21234 |
kshitij.so |
38 |
public class ProcessBulkBilling{
|
|
|
39 |
private static Logger logger = LoggerFactory.getLogger(ProcessBulkBilling.class);
|
| 21242 |
kshitij.so |
40 |
|
| 21237 |
kshitij.so |
41 |
private String fileName;
|
|
|
42 |
private String logisticsTransactionId;
|
|
|
43 |
private String packageDimensions;
|
| 21242 |
kshitij.so |
44 |
private List<InventoryItem> inventoryItems;
|
|
|
45 |
private Map<Long, Long> itemQuantityMap= new HashMap<Long, Long>();
|
|
|
46 |
private Map<Long, List<InventoryItem>> inventoryItemMap= new HashMap<Long, List<InventoryItem>>();
|
| 21237 |
kshitij.so |
47 |
private ArrayList<String> imei_list = new ArrayList<String>();
|
| 21247 |
kshitij.so |
48 |
private BillingType billingType;
|
|
|
49 |
private String user;
|
|
|
50 |
private List<Order> orders_list;
|
|
|
51 |
private Map<Long, List<String>> itemNumbersMap = new HashMap<Long, List<String>>();
|
|
|
52 |
private Map<Long, List<String>> serialNumbersMap = new HashMap<Long, List<String>>();
|
|
|
53 |
private Map<Long, List<Long>> freebieWarehouseIdMap = new HashMap<Long, List<Long>>();
|
|
|
54 |
private static final long jacket_number = 1;
|
|
|
55 |
private static final String invoice_type = "Individual";
|
| 22588 |
amit.gupta |
56 |
|
| 22597 |
amit.gupta |
57 |
private static String live = "";
|
| 22588 |
amit.gupta |
58 |
|
|
|
59 |
static {
|
|
|
60 |
try {
|
|
|
61 |
ConfigClient cc = ConfigClient.getClient();
|
| 22699 |
amit.gupta |
62 |
live = cc.get("live");
|
| 22588 |
amit.gupta |
63 |
} catch (Exception e) {
|
|
|
64 |
e.printStackTrace();
|
|
|
65 |
}
|
|
|
66 |
}
|
| 21242 |
kshitij.so |
67 |
|
|
|
68 |
|
| 21247 |
kshitij.so |
69 |
ProcessBulkBilling(String fileName, String logisticsTransactionId, String packageDimensions, BillingType billingType, String user) {
|
|
|
70 |
logger.info("FileName "+fileName+" logisticsTransactionId "+logisticsTransactionId+" packageDimension "+packageDimensions+" billingType "+billingType+" user "+user);
|
| 21237 |
kshitij.so |
71 |
this.fileName = fileName;
|
|
|
72 |
this.logisticsTransactionId = logisticsTransactionId;
|
|
|
73 |
this.packageDimensions = packageDimensions;
|
| 21247 |
kshitij.so |
74 |
this.billingType = billingType;
|
|
|
75 |
this.user = user;
|
| 21237 |
kshitij.so |
76 |
}
|
| 21234 |
kshitij.so |
77 |
|
| 21237 |
kshitij.so |
78 |
public boolean processReport() {
|
| 21234 |
kshitij.so |
79 |
try{
|
|
|
80 |
|
|
|
81 |
FileInputStream iFile = new FileInputStream(new File(fileName));
|
|
|
82 |
HSSFWorkbook workbook = new HSSFWorkbook(iFile);
|
|
|
83 |
HSSFSheet sheet = workbook.getSheetAt(0);
|
| 21244 |
kshitij.so |
84 |
DataFormatter formatter = new DataFormatter();
|
| 21234 |
kshitij.so |
85 |
for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
|
| 22701 |
amit.gupta |
86 |
logger.info("Iterator -----" + iterator);
|
| 21244 |
kshitij.so |
87 |
HSSFCell imei_cell = sheet.getRow(iterator).getCell(0);
|
|
|
88 |
String imei = formatter.formatCellValue(imei_cell).trim();
|
| 21237 |
kshitij.so |
89 |
if (imei == null || imei.isEmpty()){
|
|
|
90 |
break;
|
|
|
91 |
}
|
| 21242 |
kshitij.so |
92 |
if (imei_list.contains(imei)){
|
|
|
93 |
return false;
|
|
|
94 |
}
|
| 22701 |
amit.gupta |
95 |
logger.info(imei);
|
| 21237 |
kshitij.so |
96 |
imei_list.add(imei);
|
| 21234 |
kshitij.so |
97 |
}
|
|
|
98 |
return true;
|
|
|
99 |
}
|
|
|
100 |
catch(Exception e){
|
|
|
101 |
e.printStackTrace();
|
|
|
102 |
return false;
|
|
|
103 |
}
|
|
|
104 |
}
|
| 21242 |
kshitij.so |
105 |
|
| 21247 |
kshitij.so |
106 |
private String addBillingInformation(){
|
|
|
107 |
|
|
|
108 |
Order t_order = orders_list.get(0);
|
|
|
109 |
try{
|
|
|
110 |
TransactionClient txnClient = new TransactionClient();
|
|
|
111 |
Client client = txnClient.getClient();
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
if (packageDimensions==null){
|
|
|
115 |
return "Illegal package dimensions";
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
try{
|
|
|
119 |
ShipmentLogisticsCostDetail slcd = new ShipmentLogisticsCostDetail();
|
|
|
120 |
slcd.setLogisticsTransactionId(t_order.getLogisticsTransactionId());
|
|
|
121 |
slcd.setPackageDimensions(packageDimensions);
|
|
|
122 |
client.addShipmentLogisticDetail(slcd);
|
|
|
123 |
}
|
|
|
124 |
catch(Exception slcd_ex){
|
|
|
125 |
slcd_ex.printStackTrace();
|
|
|
126 |
return "Unable to add ShipmentLogisticsCostDetail";
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
if (t_order.getAirwaybill_no()==null){
|
|
|
131 |
String airway_billno = null;
|
| 22588 |
amit.gupta |
132 |
if(live.equals("true")) {
|
|
|
133 |
try{
|
|
|
134 |
//If aramaex then
|
|
|
135 |
if (t_order.getLogistics_provider_id()==2){
|
| 22589 |
amit.gupta |
136 |
Provider logisticsProvider = ProviderFactory.getProvider((int)orders_list.get(0).getLogistics_provider_id());
|
|
|
137 |
airway_billno = logisticsProvider.getAirwayBillNo(orders_list);
|
| 22588 |
amit.gupta |
138 |
}
|
|
|
139 |
else{
|
|
|
140 |
LogisticsClient lc = new LogisticsClient();
|
|
|
141 |
airway_billno = lc.getClient().getEmptyAWB(t_order.getLogistics_provider_id(), t_order.getLogisticsTransactionId());
|
|
|
142 |
}
|
|
|
143 |
if (airway_billno==null || airway_billno.isEmpty()){
|
|
|
144 |
throw new Exception("Empty airway bill number");
|
|
|
145 |
}
|
| 21247 |
kshitij.so |
146 |
}
|
| 22588 |
amit.gupta |
147 |
catch(Exception airwayBillException){
|
|
|
148 |
airwayBillException.printStackTrace();
|
|
|
149 |
return "Unable to assign airway bill number";
|
| 21247 |
kshitij.so |
150 |
}
|
| 22597 |
amit.gupta |
151 |
} else if (live.equals("false")){
|
|
|
152 |
airway_billno = String.valueOf(new Date().getTime());
|
| 22588 |
amit.gupta |
153 |
} else {
|
| 22597 |
amit.gupta |
154 |
return "Config error";
|
| 21247 |
kshitij.so |
155 |
}
|
| 22589 |
amit.gupta |
156 |
client.updateMasterOrderAWB(t_order.getLogisticsTransactionId(), airway_billno);
|
| 21247 |
kshitij.so |
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
if((billingType == BillingType.OURS || billingType == BillingType.OURS_EXTERNAL) && t_order.getStatus().getValue() >= OrderStatus.BILLED.getValue()){
|
|
|
161 |
return "Already Billed";
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
long billing_type = billingType.getValue();
|
|
|
165 |
|
|
|
166 |
Set<Long> orderIdSet = itemNumbersMap.keySet();
|
|
|
167 |
List<Long> order_ids = new ArrayList<Long>();
|
|
|
168 |
order_ids.addAll(orderIdSet);
|
|
|
169 |
|
|
|
170 |
boolean status = client.addBillingDetailsForGrouppedOrders(order_ids, "", itemNumbersMap, serialNumbersMap, freebieWarehouseIdMap , user, jacket_number, billing_type, false, invoice_type);
|
| 23246 |
amit.gupta |
171 |
// If provider is ECom Express then forward shipping request after billing
|
|
|
172 |
if(t_order.getLogistics_provider_id()==49) {
|
|
|
173 |
try {
|
|
|
174 |
LogisticsClient lc = new LogisticsClient();
|
|
|
175 |
lc.getClient().pushCourierDetailsForEcomExpress(Arrays.asList(t_order.getLogisticsTransactionId()));
|
|
|
176 |
} catch (Exception e) {
|
|
|
177 |
logger.error("Error pushing courier details", e);
|
| 23248 |
amit.gupta |
178 |
return "Order billed but could not forward request to provider";
|
| 23246 |
amit.gupta |
179 |
}
|
|
|
180 |
}
|
| 21247 |
kshitij.so |
181 |
|
|
|
182 |
if(!status)
|
|
|
183 |
return "Couldn't add billing info on server";
|
|
|
184 |
|
|
|
185 |
return "Billing Info added successfully";
|
|
|
186 |
} catch(TransactionServiceException tse){
|
|
|
187 |
logger.error("Exception while adding InventoryServiceHandlerjacket number", tse);
|
|
|
188 |
return "Error While Billing Order:" + tse.getMessage();
|
|
|
189 |
} catch (TException e) {
|
|
|
190 |
return "Unknown exception from server:" + e.getMessage();
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
| 21237 |
kshitij.so |
194 |
public String checkBillingDetails(){
|
|
|
195 |
try{
|
| 21242 |
kshitij.so |
196 |
Client tc = new TransactionClient().getClient();
|
|
|
197 |
orders_list = tc.getGroupOrdersByLogisticsTxnId(logisticsTransactionId);
|
| 21237 |
kshitij.so |
198 |
}
|
|
|
199 |
catch(Exception e){
|
|
|
200 |
e.printStackTrace();
|
|
|
201 |
return "Service Error!!!";
|
|
|
202 |
}
|
|
|
203 |
long total_quantity = 0;
|
|
|
204 |
for (Order o : orders_list){
|
| 21242 |
kshitij.so |
205 |
if (itemQuantityMap.containsKey(o.getLineitems().get(0).getItem_id())){
|
|
|
206 |
itemQuantityMap.put(o.getLineitems().get(0).getItem_id(), itemQuantityMap.get(o.getLineitems().get(0).getItem_id())+(long)o.getLineitems().get(0).getQuantity());
|
|
|
207 |
}
|
|
|
208 |
else{
|
|
|
209 |
itemQuantityMap.put(o.getLineitems().get(0).getItem_id(), (long)o.getLineitems().get(0).getQuantity());
|
|
|
210 |
}
|
| 21237 |
kshitij.so |
211 |
total_quantity = (long) (total_quantity + o.getLineitems().get(0).getQuantity());
|
|
|
212 |
}
|
|
|
213 |
if (total_quantity != imei_list.size()){
|
|
|
214 |
return "Quantity and imei mismatch.Supplied imei's not equal to quantity to bill";
|
|
|
215 |
}
|
| 21242 |
kshitij.so |
216 |
try{
|
|
|
217 |
in.shop2020.warehouse.WarehouseService.Client wc = new WarehouseClient().getClient();
|
|
|
218 |
inventoryItems = wc.getInventoryItems(imei_list);
|
| 22700 |
amit.gupta |
219 |
logger.info(imei_list.toString());
|
| 22698 |
amit.gupta |
220 |
logger.info(inventoryItems.toString());
|
| 21242 |
kshitij.so |
221 |
for (InventoryItem it : inventoryItems){
|
|
|
222 |
if (inventoryItemMap.containsKey(it.getItemId())){
|
|
|
223 |
inventoryItemMap.get(it.getItemId()).add(it);
|
|
|
224 |
}
|
|
|
225 |
else{
|
|
|
226 |
List<InventoryItem> it_list = new ArrayList<InventoryItem>();
|
|
|
227 |
it_list.add(it);
|
|
|
228 |
inventoryItemMap.put(it.getItemId(), it_list);
|
|
|
229 |
}
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
catch(Exception e){
|
|
|
233 |
return "Exception while getting inventory items from warehouse";
|
|
|
234 |
}
|
|
|
235 |
logger.info("itemQuantityMap "+itemQuantityMap);
|
|
|
236 |
logger.info("inventoryItemMap "+inventoryItemMap);
|
| 21247 |
kshitij.so |
237 |
for(Map.Entry<Long, Long> entry : itemQuantityMap.entrySet()){
|
|
|
238 |
List<InventoryItem> inventory_items = inventoryItemMap.get(entry.getKey());
|
| 21252 |
kshitij.so |
239 |
if (inventory_items == null){
|
|
|
240 |
return "Mismatch in inventory items.Quantity to bill "+entry.getValue()+".InventoryItem available 0 for item_id "+entry.getKey();
|
| 21247 |
kshitij.so |
241 |
}
|
| 21252 |
kshitij.so |
242 |
if (inventory_items.size()!= entry.getValue()){
|
|
|
243 |
return "Mismatch in inventory items.Quantity to bill "+entry.getValue()+".InventoryItem available "+inventory_items.size()+" for item_id "+entry.getKey();
|
|
|
244 |
}
|
| 21247 |
kshitij.so |
245 |
}
|
|
|
246 |
for (Order o : orders_list){
|
|
|
247 |
|
|
|
248 |
freebieWarehouseIdMap.put(o.getId(), new ArrayList<Long>());
|
|
|
249 |
|
|
|
250 |
for(int i=0;i< o.getLineitems().get(0).getQuantity();i++){
|
|
|
251 |
|
|
|
252 |
if (itemNumbersMap.containsKey(o.getId())){
|
|
|
253 |
itemNumbersMap.get(o.getId()).add("1");
|
|
|
254 |
}
|
|
|
255 |
else{
|
|
|
256 |
List<String> itemNumbers = new ArrayList<String>();
|
|
|
257 |
itemNumbers.add("1");
|
|
|
258 |
itemNumbersMap.put(o.getId(), itemNumbers);
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
if (serialNumbersMap.containsKey(o.getId())){
|
|
|
262 |
InventoryItem inventory_item = inventoryItemMap.get(o.getLineitems().get(0).getItem_id()).remove(0);
|
|
|
263 |
serialNumbersMap.get(o.getId()).add(inventory_item.getSerialNumber());
|
|
|
264 |
}
|
|
|
265 |
else{
|
|
|
266 |
List<String> serialNumbers = new ArrayList<String>();
|
|
|
267 |
InventoryItem inventory_item = inventoryItemMap.get(o.getLineitems().get(0).getItem_id()).remove(0);
|
|
|
268 |
serialNumbers.add(inventory_item.getSerialNumber());
|
|
|
269 |
serialNumbersMap.put(o.getId(), serialNumbers);
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
return addBillingInformation();
|
| 21237 |
kshitij.so |
275 |
}
|
| 21234 |
kshitij.so |
276 |
|
|
|
277 |
}
|