| 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;
|
|
|
13 |
import in.shop2020.warehouse.InventoryItem;
|
| 21234 |
kshitij.so |
14 |
|
|
|
15 |
import java.io.File;
|
|
|
16 |
import java.io.FileInputStream;
|
|
|
17 |
import java.util.ArrayList;
|
| 21242 |
kshitij.so |
18 |
import java.util.HashMap;
|
| 21234 |
kshitij.so |
19 |
import java.util.List;
|
| 21242 |
kshitij.so |
20 |
import java.util.Map;
|
| 21247 |
kshitij.so |
21 |
import java.util.Set;
|
| 21234 |
kshitij.so |
22 |
|
| 21244 |
kshitij.so |
23 |
import org.apache.poi.hssf.usermodel.HSSFCell;
|
| 21234 |
kshitij.so |
24 |
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
25 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 21244 |
kshitij.so |
26 |
import org.apache.poi.ss.usermodel.DataFormatter;
|
| 21247 |
kshitij.so |
27 |
import org.apache.thrift.TException;
|
| 21234 |
kshitij.so |
28 |
import org.slf4j.Logger;
|
|
|
29 |
import org.slf4j.LoggerFactory;
|
|
|
30 |
|
| 21247 |
kshitij.so |
31 |
import com.providers.logistics.Provider;
|
|
|
32 |
import com.providers.logistics.ProviderFactory;
|
| 21242 |
kshitij.so |
33 |
|
| 21247 |
kshitij.so |
34 |
|
| 21234 |
kshitij.so |
35 |
public class ProcessBulkBilling{
|
|
|
36 |
private static Logger logger = LoggerFactory.getLogger(ProcessBulkBilling.class);
|
| 21242 |
kshitij.so |
37 |
|
| 21237 |
kshitij.so |
38 |
private String fileName;
|
|
|
39 |
private String logisticsTransactionId;
|
|
|
40 |
private String packageDimensions;
|
| 21242 |
kshitij.so |
41 |
private List<InventoryItem> inventoryItems;
|
|
|
42 |
private Map<Long, Long> itemQuantityMap= new HashMap<Long, Long>();
|
|
|
43 |
private Map<Long, List<InventoryItem>> inventoryItemMap= new HashMap<Long, List<InventoryItem>>();
|
| 21237 |
kshitij.so |
44 |
private ArrayList<String> imei_list = new ArrayList<String>();
|
| 21247 |
kshitij.so |
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";
|
| 21242 |
kshitij.so |
53 |
|
|
|
54 |
|
| 21247 |
kshitij.so |
55 |
ProcessBulkBilling(String fileName, String logisticsTransactionId, String packageDimensions, BillingType billingType, String user) {
|
|
|
56 |
logger.info("FileName "+fileName+" logisticsTransactionId "+logisticsTransactionId+" packageDimension "+packageDimensions+" billingType "+billingType+" user "+user);
|
| 21237 |
kshitij.so |
57 |
this.fileName = fileName;
|
|
|
58 |
this.logisticsTransactionId = logisticsTransactionId;
|
|
|
59 |
this.packageDimensions = packageDimensions;
|
| 21247 |
kshitij.so |
60 |
this.billingType = billingType;
|
|
|
61 |
this.user = user;
|
| 21237 |
kshitij.so |
62 |
}
|
| 21234 |
kshitij.so |
63 |
|
| 21237 |
kshitij.so |
64 |
public boolean processReport() {
|
| 21234 |
kshitij.so |
65 |
try{
|
|
|
66 |
|
|
|
67 |
FileInputStream iFile = new FileInputStream(new File(fileName));
|
|
|
68 |
HSSFWorkbook workbook = new HSSFWorkbook(iFile);
|
|
|
69 |
HSSFSheet sheet = workbook.getSheetAt(0);
|
| 21244 |
kshitij.so |
70 |
DataFormatter formatter = new DataFormatter();
|
| 21234 |
kshitij.so |
71 |
for (int iterator=sheet.getFirstRowNum()+1;iterator<=sheet.getLastRowNum();iterator++){
|
| 21244 |
kshitij.so |
72 |
HSSFCell imei_cell = sheet.getRow(iterator).getCell(0);
|
|
|
73 |
String imei = formatter.formatCellValue(imei_cell).trim();
|
| 21237 |
kshitij.so |
74 |
if (imei == null || imei.isEmpty()){
|
|
|
75 |
break;
|
|
|
76 |
}
|
| 21242 |
kshitij.so |
77 |
if (imei_list.contains(imei)){
|
|
|
78 |
return false;
|
|
|
79 |
}
|
| 21237 |
kshitij.so |
80 |
imei_list.add(imei);
|
| 21234 |
kshitij.so |
81 |
}
|
|
|
82 |
return true;
|
|
|
83 |
}
|
|
|
84 |
catch(Exception e){
|
|
|
85 |
e.printStackTrace();
|
|
|
86 |
return false;
|
|
|
87 |
}
|
|
|
88 |
}
|
| 21242 |
kshitij.so |
89 |
|
| 21247 |
kshitij.so |
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 |
if(!status)
|
|
|
151 |
return "Couldn't add billing info on server";
|
|
|
152 |
|
|
|
153 |
return "Billing Info added successfully";
|
|
|
154 |
} catch(TransactionServiceException tse){
|
|
|
155 |
logger.error("Exception while adding InventoryServiceHandlerjacket number", tse);
|
|
|
156 |
return "Error While Billing Order:" + tse.getMessage();
|
|
|
157 |
} catch (TException e) {
|
|
|
158 |
return "Unknown exception from server:" + e.getMessage();
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
|
| 21237 |
kshitij.so |
162 |
public String checkBillingDetails(){
|
|
|
163 |
try{
|
| 21242 |
kshitij.so |
164 |
Client tc = new TransactionClient().getClient();
|
|
|
165 |
orders_list = tc.getGroupOrdersByLogisticsTxnId(logisticsTransactionId);
|
| 21237 |
kshitij.so |
166 |
}
|
|
|
167 |
catch(Exception e){
|
|
|
168 |
e.printStackTrace();
|
|
|
169 |
return "Service Error!!!";
|
|
|
170 |
}
|
|
|
171 |
long total_quantity = 0;
|
|
|
172 |
for (Order o : orders_list){
|
| 21242 |
kshitij.so |
173 |
if (itemQuantityMap.containsKey(o.getLineitems().get(0).getItem_id())){
|
|
|
174 |
itemQuantityMap.put(o.getLineitems().get(0).getItem_id(), itemQuantityMap.get(o.getLineitems().get(0).getItem_id())+(long)o.getLineitems().get(0).getQuantity());
|
|
|
175 |
}
|
|
|
176 |
else{
|
|
|
177 |
itemQuantityMap.put(o.getLineitems().get(0).getItem_id(), (long)o.getLineitems().get(0).getQuantity());
|
|
|
178 |
}
|
| 21237 |
kshitij.so |
179 |
total_quantity = (long) (total_quantity + o.getLineitems().get(0).getQuantity());
|
|
|
180 |
}
|
|
|
181 |
if (total_quantity != imei_list.size()){
|
|
|
182 |
return "Quantity and imei mismatch.Supplied imei's not equal to quantity to bill";
|
|
|
183 |
}
|
| 21242 |
kshitij.so |
184 |
try{
|
|
|
185 |
in.shop2020.warehouse.WarehouseService.Client wc = new WarehouseClient().getClient();
|
|
|
186 |
inventoryItems = wc.getInventoryItems(imei_list);
|
|
|
187 |
for (InventoryItem it : inventoryItems){
|
|
|
188 |
if (inventoryItemMap.containsKey(it.getItemId())){
|
|
|
189 |
inventoryItemMap.get(it.getItemId()).add(it);
|
|
|
190 |
}
|
|
|
191 |
else{
|
|
|
192 |
List<InventoryItem> it_list = new ArrayList<InventoryItem>();
|
|
|
193 |
it_list.add(it);
|
|
|
194 |
inventoryItemMap.put(it.getItemId(), it_list);
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
catch(Exception e){
|
|
|
199 |
return "Exception while getting inventory items from warehouse";
|
|
|
200 |
}
|
|
|
201 |
logger.info("itemQuantityMap "+itemQuantityMap);
|
|
|
202 |
logger.info("inventoryItemMap "+inventoryItemMap);
|
| 21247 |
kshitij.so |
203 |
for(Map.Entry<Long, Long> entry : itemQuantityMap.entrySet()){
|
|
|
204 |
List<InventoryItem> inventory_items = inventoryItemMap.get(entry.getKey());
|
| 21252 |
kshitij.so |
205 |
if (inventory_items == null){
|
|
|
206 |
return "Mismatch in inventory items.Quantity to bill "+entry.getValue()+".InventoryItem available 0 for item_id "+entry.getKey();
|
| 21247 |
kshitij.so |
207 |
}
|
| 21252 |
kshitij.so |
208 |
if (inventory_items.size()!= entry.getValue()){
|
|
|
209 |
return "Mismatch in inventory items.Quantity to bill "+entry.getValue()+".InventoryItem available "+inventory_items.size()+" for item_id "+entry.getKey();
|
|
|
210 |
}
|
| 21247 |
kshitij.so |
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>();
|
|
|
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();
|
| 21237 |
kshitij.so |
241 |
}
|
| 21234 |
kshitij.so |
242 |
|
|
|
243 |
}
|