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