| Line 1... |
Line 1... |
| 1 |
package in.shop2020.hotspot.dashbaord.server;
|
1 |
package in.shop2020.hotspot.dashbaord.server;
|
| 2 |
|
2 |
|
| - |
|
3 |
import in.shop2020.hotspot.dashbaord.shared.actions.AddJacketNumberResponse;
|
| - |
|
4 |
import in.shop2020.model.v1.inventory.BillingType;
|
| 3 |
import in.shop2020.model.v1.order.Order;
|
5 |
import in.shop2020.model.v1.order.Order;
|
| - |
|
6 |
import in.shop2020.model.v1.order.OrderStatus;
|
| - |
|
7 |
import in.shop2020.model.v1.order.ShipmentLogisticsCostDetail;
|
| - |
|
8 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 4 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
9 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| - |
|
10 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 5 |
import in.shop2020.thrift.clients.TransactionClient;
|
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 6 |
import in.shop2020.thrift.clients.WarehouseClient;
|
12 |
import in.shop2020.thrift.clients.WarehouseClient;
|
| 7 |
import in.shop2020.warehouse.InventoryItem;
|
13 |
import in.shop2020.warehouse.InventoryItem;
|
| 8 |
|
14 |
|
| 9 |
import java.io.File;
|
15 |
import java.io.File;
|
| 10 |
import java.io.FileInputStream;
|
16 |
import java.io.FileInputStream;
|
| 11 |
import java.util.ArrayList;
|
17 |
import java.util.ArrayList;
|
| 12 |
import java.util.HashMap;
|
18 |
import java.util.HashMap;
|
| 13 |
import java.util.List;
|
19 |
import java.util.List;
|
| 14 |
import java.util.Map;
|
20 |
import java.util.Map;
|
| - |
|
21 |
import java.util.Set;
|
| 15 |
|
22 |
|
| 16 |
import org.apache.poi.hssf.usermodel.HSSFCell;
|
23 |
import org.apache.poi.hssf.usermodel.HSSFCell;
|
| 17 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
24 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
| 18 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
25 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 19 |
import org.apache.poi.ss.usermodel.DataFormatter;
|
26 |
import org.apache.poi.ss.usermodel.DataFormatter;
|
| - |
|
27 |
import org.apache.thrift.TException;
|
| 20 |
import org.slf4j.Logger;
|
28 |
import org.slf4j.Logger;
|
| 21 |
import org.slf4j.LoggerFactory;
|
29 |
import org.slf4j.LoggerFactory;
|
| 22 |
|
30 |
|
| - |
|
31 |
import com.providers.logistics.Provider;
|
| - |
|
32 |
import com.providers.logistics.ProviderFactory;
|
| - |
|
33 |
|
| 23 |
|
34 |
|
| 24 |
public class ProcessBulkBilling{
|
35 |
public class ProcessBulkBilling{
|
| 25 |
private static Logger logger = LoggerFactory.getLogger(ProcessBulkBilling.class);
|
36 |
private static Logger logger = LoggerFactory.getLogger(ProcessBulkBilling.class);
|
| 26 |
|
37 |
|
| 27 |
private String fileName;
|
38 |
private String fileName;
|
| Line 29... |
Line 40... |
| 29 |
private String packageDimensions;
|
40 |
private String packageDimensions;
|
| 30 |
private List<InventoryItem> inventoryItems;
|
41 |
private List<InventoryItem> inventoryItems;
|
| 31 |
private Map<Long, Long> itemQuantityMap= new HashMap<Long, Long>();
|
42 |
private Map<Long, Long> itemQuantityMap= new HashMap<Long, Long>();
|
| 32 |
private Map<Long, List<InventoryItem>> inventoryItemMap= new HashMap<Long, List<InventoryItem>>();
|
43 |
private Map<Long, List<InventoryItem>> inventoryItemMap= new HashMap<Long, List<InventoryItem>>();
|
| 33 |
private ArrayList<String> imei_list = new ArrayList<String>();
|
44 |
private ArrayList<String> imei_list = new ArrayList<String>();
|
| - |
|
45 |
private BillingType billingType;
|
| - |
|
46 |
private String user;
|
| - |
|
47 |
private List<Order> orders_list;
|
| - |
|
48 |
private Map<Long, List<String>> itemNumbersMap = new HashMap<Long, List<String>>();
|
| - |
|
49 |
private Map<Long, List<String>> serialNumbersMap = new HashMap<Long, List<String>>();
|
| - |
|
50 |
private Map<Long, List<Long>> freebieWarehouseIdMap = new HashMap<Long, List<Long>>();
|
| - |
|
51 |
private static final long jacket_number = 1;
|
| - |
|
52 |
private static final String invoice_type = "Individual";
|
| 34 |
|
53 |
|
| 35 |
|
54 |
|
| 36 |
ProcessBulkBilling(String fileName, String logisticsTransactionId, String packageDimensions) {
|
55 |
ProcessBulkBilling(String fileName, String logisticsTransactionId, String packageDimensions, BillingType billingType, String user) {
|
| 37 |
logger.info("FileName "+fileName+" logisticsTransactionId "+logisticsTransactionId+" packageDimension "+packageDimensions);
|
56 |
logger.info("FileName "+fileName+" logisticsTransactionId "+logisticsTransactionId+" packageDimension "+packageDimensions+" billingType "+billingType+" user "+user);
|
| 38 |
this.fileName = fileName;
|
57 |
this.fileName = fileName;
|
| 39 |
this.logisticsTransactionId = logisticsTransactionId;
|
58 |
this.logisticsTransactionId = logisticsTransactionId;
|
| 40 |
this.packageDimensions = packageDimensions;
|
59 |
this.packageDimensions = packageDimensions;
|
| - |
|
60 |
this.billingType = billingType;
|
| - |
|
61 |
this.user = user;
|
| 41 |
}
|
62 |
}
|
| 42 |
|
63 |
|
| 43 |
public boolean processReport() {
|
64 |
public boolean processReport() {
|
| 44 |
try{
|
65 |
try{
|
| 45 |
|
66 |
|
| Line 64... |
Line 85... |
| 64 |
e.printStackTrace();
|
85 |
e.printStackTrace();
|
| 65 |
return false;
|
86 |
return false;
|
| 66 |
}
|
87 |
}
|
| 67 |
}
|
88 |
}
|
| 68 |
|
89 |
|
| - |
|
90 |
private String addBillingInformation(){
|
| - |
|
91 |
|
| - |
|
92 |
Order t_order = orders_list.get(0);
|
| - |
|
93 |
try{
|
| - |
|
94 |
TransactionClient txnClient = new TransactionClient();
|
| - |
|
95 |
Client client = txnClient.getClient();
|
| - |
|
96 |
|
| - |
|
97 |
|
| - |
|
98 |
if (packageDimensions==null){
|
| - |
|
99 |
return "Illegal package dimensions";
|
| - |
|
100 |
}
|
| - |
|
101 |
|
| - |
|
102 |
try{
|
| - |
|
103 |
ShipmentLogisticsCostDetail slcd = new ShipmentLogisticsCostDetail();
|
| - |
|
104 |
slcd.setLogisticsTransactionId(t_order.getLogisticsTransactionId());
|
| - |
|
105 |
slcd.setPackageDimensions(packageDimensions);
|
| - |
|
106 |
client.addShipmentLogisticDetail(slcd);
|
| - |
|
107 |
}
|
| - |
|
108 |
catch(Exception slcd_ex){
|
| - |
|
109 |
slcd_ex.printStackTrace();
|
| - |
|
110 |
return "Unable to add ShipmentLogisticsCostDetail";
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| - |
|
113 |
|
| - |
|
114 |
if (t_order.getAirwaybill_no()==null){
|
| - |
|
115 |
String airway_billno = null;
|
| - |
|
116 |
try{
|
| - |
|
117 |
if (t_order.getLogistics_provider_id()==2){
|
| - |
|
118 |
List<in.shop2020.model.v1.order.Order> orders = client.getGroupOrdersByLogisticsTxnId(t_order.getLogisticsTransactionId());
|
| - |
|
119 |
Provider logisticsProvider = ProviderFactory.getProvider((int)orders.get(0).getLogistics_provider_id());
|
| - |
|
120 |
airway_billno = logisticsProvider.getAirwayBillNo(orders);
|
| - |
|
121 |
}
|
| - |
|
122 |
else{
|
| - |
|
123 |
LogisticsClient lc = new LogisticsClient();
|
| - |
|
124 |
airway_billno = lc.getClient().getEmptyAWB(t_order.getLogistics_provider_id(), t_order.getLogisticsTransactionId());
|
| - |
|
125 |
}
|
| - |
|
126 |
if (airway_billno==null || airway_billno.isEmpty()){
|
| - |
|
127 |
throw new Exception("Empty airway bill number");
|
| - |
|
128 |
}
|
| - |
|
129 |
}
|
| - |
|
130 |
catch(Exception airwayBillException){
|
| - |
|
131 |
airwayBillException.printStackTrace();
|
| - |
|
132 |
return "Unable to assign airway bill number";
|
| - |
|
133 |
}
|
| - |
|
134 |
client.updateMasterOrderAWB(t_order.getLogisticsTransactionId(), airway_billno);
|
| - |
|
135 |
}
|
| - |
|
136 |
|
| - |
|
137 |
|
| - |
|
138 |
if((billingType == BillingType.OURS || billingType == BillingType.OURS_EXTERNAL) && t_order.getStatus().getValue() >= OrderStatus.BILLED.getValue()){
|
| - |
|
139 |
return "Already Billed";
|
| - |
|
140 |
}
|
| - |
|
141 |
|
| - |
|
142 |
long billing_type = billingType.getValue();
|
| - |
|
143 |
|
| - |
|
144 |
Set<Long> orderIdSet = itemNumbersMap.keySet();
|
| - |
|
145 |
List<Long> order_ids = new ArrayList<Long>();
|
| - |
|
146 |
order_ids.addAll(orderIdSet);
|
| - |
|
147 |
|
| - |
|
148 |
boolean status = client.addBillingDetailsForGrouppedOrders(order_ids, "", itemNumbersMap, serialNumbersMap, freebieWarehouseIdMap , user, jacket_number, billing_type, false, invoice_type);
|
| - |
|
149 |
|
| - |
|
150 |
|
| - |
|
151 |
if(!status)
|
| - |
|
152 |
return "Couldn't add billing info on server";
|
| - |
|
153 |
|
| - |
|
154 |
return "Billing Info added successfully";
|
| - |
|
155 |
} catch(TransactionServiceException tse){
|
| - |
|
156 |
logger.error("Exception while adding InventoryServiceHandlerjacket number", tse);
|
| - |
|
157 |
return "Error While Billing Order:" + tse.getMessage();
|
| - |
|
158 |
} catch (TException e) {
|
| - |
|
159 |
return "Unknown exception from server:" + e.getMessage();
|
| - |
|
160 |
}
|
| - |
|
161 |
|
| - |
|
162 |
|
| - |
|
163 |
}
|
| - |
|
164 |
|
| 69 |
public String checkBillingDetails(){
|
165 |
public String checkBillingDetails(){
|
| 70 |
List<Order> orders_list;
|
- |
|
| 71 |
try{
|
166 |
try{
|
| 72 |
Client tc = new TransactionClient().getClient();
|
167 |
Client tc = new TransactionClient().getClient();
|
| 73 |
orders_list = tc.getGroupOrdersByLogisticsTxnId(logisticsTransactionId);
|
168 |
orders_list = tc.getGroupOrdersByLogisticsTxnId(logisticsTransactionId);
|
| 74 |
}
|
169 |
}
|
| 75 |
catch(Exception e){
|
170 |
catch(Exception e){
|
| Line 106... |
Line 201... |
| 106 |
catch(Exception e){
|
201 |
catch(Exception e){
|
| 107 |
return "Exception while getting inventory items from warehouse";
|
202 |
return "Exception while getting inventory items from warehouse";
|
| 108 |
}
|
203 |
}
|
| 109 |
logger.info("itemQuantityMap "+itemQuantityMap);
|
204 |
logger.info("itemQuantityMap "+itemQuantityMap);
|
| 110 |
logger.info("inventoryItemMap "+inventoryItemMap);
|
205 |
logger.info("inventoryItemMap "+inventoryItemMap);
|
| - |
|
206 |
for(Map.Entry<Long, Long> entry : itemQuantityMap.entrySet()){
|
| - |
|
207 |
List<InventoryItem> inventory_items = inventoryItemMap.get(entry.getKey());
|
| - |
|
208 |
if (inventory_items == null || inventory_items.size()!= entry.getValue()){
|
| - |
|
209 |
return "Mismatch in serial number and item mapping";
|
| - |
|
210 |
}
|
| - |
|
211 |
}
|
| - |
|
212 |
for (Order o : orders_list){
|
| - |
|
213 |
|
| - |
|
214 |
freebieWarehouseIdMap.put(o.getId(), new ArrayList<Long>());
|
| - |
|
215 |
|
| - |
|
216 |
for(int i=0;i< o.getLineitems().get(0).getQuantity();i++){
|
| - |
|
217 |
|
| - |
|
218 |
if (itemNumbersMap.containsKey(o.getId())){
|
| - |
|
219 |
itemNumbersMap.get(o.getId()).add("1");
|
| - |
|
220 |
}
|
| - |
|
221 |
else{
|
| - |
|
222 |
List<String> itemNumbers = new ArrayList<String>();
|
| 111 |
return "success";
|
223 |
itemNumbers.add("1");
|
| - |
|
224 |
itemNumbersMap.put(o.getId(), itemNumbers);
|
| - |
|
225 |
}
|
| - |
|
226 |
|
| - |
|
227 |
if (serialNumbersMap.containsKey(o.getId())){
|
| - |
|
228 |
InventoryItem inventory_item = inventoryItemMap.get(o.getLineitems().get(0).getItem_id()).remove(0);
|
| - |
|
229 |
serialNumbersMap.get(o.getId()).add(inventory_item.getSerialNumber());
|
| - |
|
230 |
}
|
| - |
|
231 |
else{
|
| - |
|
232 |
List<String> serialNumbers = new ArrayList<String>();
|
| - |
|
233 |
InventoryItem inventory_item = inventoryItemMap.get(o.getLineitems().get(0).getItem_id()).remove(0);
|
| - |
|
234 |
serialNumbers.add(inventory_item.getSerialNumber());
|
| - |
|
235 |
serialNumbersMap.put(o.getId(), serialNumbers);
|
| - |
|
236 |
}
|
| - |
|
237 |
}
|
| - |
|
238 |
}
|
| - |
|
239 |
|
| - |
|
240 |
return addBillingInformation();
|
| 112 |
}
|
241 |
}
|
| 113 |
|
242 |
|
| 114 |
}
|
243 |
}
|
| 115 |
|
244 |
|