Subversion Repositories SmartDukaan

Rev

Rev 19979 | Rev 19985 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19979 Rev 19980
Line 71... Line 71...
71
import in.shop2020.model.v1.order.OrderStatus;
71
import in.shop2020.model.v1.order.OrderStatus;
72
import in.shop2020.model.v1.order.OrderType;
72
import in.shop2020.model.v1.order.OrderType;
73
import in.shop2020.model.v1.order.ProductCondition;
73
import in.shop2020.model.v1.order.ProductCondition;
74
import in.shop2020.model.v1.order.SellerInfo;
74
import in.shop2020.model.v1.order.SellerInfo;
75
import in.shop2020.model.v1.order.SnapdealOrder;
75
import in.shop2020.model.v1.order.SnapdealOrder;
-
 
76
import in.shop2020.model.v1.order.WarehouseAddress;
76
import in.shop2020.model.v1.user.Address;
77
import in.shop2020.model.v1.user.Address;
77
import in.shop2020.thrift.clients.CatalogClient;
78
import in.shop2020.thrift.clients.CatalogClient;
78
import in.shop2020.thrift.clients.InventoryClient;
79
import in.shop2020.thrift.clients.InventoryClient;
79
import in.shop2020.thrift.clients.LogisticsClient;
80
import in.shop2020.thrift.clients.LogisticsClient;
80
import in.shop2020.thrift.clients.TransactionClient;
81
import in.shop2020.thrift.clients.TransactionClient;
Line 163... Line 164...
163
 
164
 
164
	private static final String delhiPincodePrefix = "11";
165
	private static final String delhiPincodePrefix = "11";
165
	private static final String[] maharashtraPincodePrefix = {"40", "41", "42", "43", "44"};
166
	private static final String[] maharashtraPincodePrefix = {"40", "41", "42", "43", "44"};
166
	private static final String[] karnatakaPincodePrefix = {"56", "57", "58", "59"};
167
	private static final String[] karnatakaPincodePrefix = {"56", "57", "58", "59"};
167
	private static final String[] telanganaPincodes = {"500001","500002","500003","500004","500005","500006","500007","500008","500009","500010","500011","500012","500013","500014","500015","500016","500017","500018","500019","500020","500021","500022","500023","500024","500025","500026","500027","500028","500029","500030","500031","500032","500033","500034","500035","500036","500037","500038","500039","500040","500041","500042","500043","500044","500045","500046","500047","500048","500049","500050","500051","500052","500053","500054","500055","500056","500057","500058","500059","500060","500061","500062","500063","500064","500065","500066","500067","500068","500069","500070","500071","500072","500073","500074","500075","500076","500077","500078","500079","500080","500081","500082","500083","500084","500085","500086","500087","500088","500089","500090","500091","500092","500093","500094","500095","500096","500097","500098","500178","500409","501218","501301","501401","501510","501511","501512","502307","502319","517501","517502","517503","517505","517507","520001","520002","520003","520004","520005","520006","520007","520008","520009","520010","520011","520012","520013","520014","520015","521108","521225","522001","522002","522003","522004","522005","522006","522007","522019","522509","530001","530002","530003","530004","530005","530007","530008","530009","530010","530010","530011","530012","530013","530014","530015","530016","530017","530018","530020","530021","530022","530023","530024","530026","530027","530028","530029","530032","530035","530040","530041","530043","530044","530045","530046","531001","533101","533103","533104","533105"};
168
	private static final String[] telanganaPincodes = {"500001","500002","500003","500004","500005","500006","500007","500008","500009","500010","500011","500012","500013","500014","500015","500016","500017","500018","500019","500020","500021","500022","500023","500024","500025","500026","500027","500028","500029","500030","500031","500032","500033","500034","500035","500036","500037","500038","500039","500040","500041","500042","500043","500044","500045","500046","500047","500048","500049","500050","500051","500052","500053","500054","500055","500056","500057","500058","500059","500060","500061","500062","500063","500064","500065","500066","500067","500068","500069","500070","500071","500072","500073","500074","500075","500076","500077","500078","500079","500080","500081","500082","500083","500084","500085","500086","500087","500088","500089","500090","500091","500092","500093","500094","500095","500096","500097","500098","500178","500409","501218","501301","501401","501510","501511","501512","502307","502319","517501","517502","517503","517505","517507","520001","520002","520003","520004","520005","520006","520007","520008","520009","520010","520011","520012","520013","520014","520015","521108","521225","522001","522002","522003","522004","522005","522006","522007","522019","522509","530001","530002","530003","530004","530005","530007","530008","530009","530010","530010","530011","530012","530013","530014","530015","530016","530017","530018","530020","530021","530022","530023","530024","530026","530027","530028","530029","530032","530035","530040","530041","530043","530044","530045","530046","531001","533101","533103","533104","533105"};
-
 
169
	static final Map<Long,SellerInfo> sellerInfoMap = new HashMap<Long, SellerInfo>();
-
 
170
	static final Map<Long,WarehouseAddress> whAddressInfoMap = new HashMap<Long, WarehouseAddress>();
168
	private Address billingAddress;
171
	private Address billingAddress;
169
	private SellerInfo sellerInfo;
172
	private SellerInfo sellerInfo;
-
 
173
	private WarehouseAddress addressInfo;
170
 
174
 
171
	public InvoiceGenerationService() {
175
	public InvoiceGenerationService() {
172
		try {
176
		try {
173
			tsc = new TransactionClient();
177
			tsc = new TransactionClient();
174
			csc = new InventoryClient();
178
			csc = new InventoryClient();
Line 229... Line 233...
229
				if(!tclient.isAlive()){
233
				if(!tclient.isAlive()){
230
					tclient = tsc.getClient();
234
					tclient = tsc.getClient();
231
				}
235
				}
232
				orders.add(tclient.getOrder(orderId));
236
				orders.add(tclient.getOrder(orderId));
233
				Order o = orders.get(0);
237
				Order o = orders.get(0);
-
 
238
				try {
234
				sellerInfo = tclient.getSellerInfo(o.getSeller_id());
239
					sellerInfo = getSellerInfo(o.getSeller_id(), tclient);
-
 
240
					addressInfo = getWarehouseAddress(o.getWarehouse_address_id(), tclient);
-
 
241
				} catch (Exception e) {
-
 
242
					logger.info("Error occurred while getting address/seller info", e);
-
 
243
				}
235
				if(o.isSetLogisticsTransactionId()){
244
				if(o.isSetLogisticsTransactionId()){
236
					List<Order> groupOrdersList = tclient.getGroupOrdersByLogisticsTxnId(o.getLogisticsTransactionId());
245
					List<Order> groupOrdersList = tclient.getGroupOrdersByLogisticsTxnId(o.getLogisticsTransactionId());
237
					logisticsTxnIdOrdersMap.put(o.getLogisticsTransactionId(), groupOrdersList);
246
					logisticsTxnIdOrdersMap.put(o.getLogisticsTransactionId(), groupOrdersList);
238
				}
247
				}
239
			}
248
			}
Line 243... Line 252...
243
					List<Order> ordersList = logisticsTxnIdOrdersMap.get(logisticsTxnId);
252
					List<Order> ordersList = logisticsTxnIdOrdersMap.get(logisticsTxnId);
244
					Order singleOrder = ordersList.get(0);
253
					Order singleOrder = ordersList.get(0);
245
					Warehouse warehouse = null;
254
					Warehouse warehouse = null;
246
					Provider provider = null;
255
					Provider provider = null;
247
					String destCode = null;
256
					String destCode = null;
248
					Warehouse shippingLocation = null;
-
 
249
					int barcodeFontSize = 0;
257
					int barcodeFontSize = 0;
250
					String invoiceFormat = null;
258
					String invoiceFormat = null;
251
					try {
259
					try {
252
						warehouse = iclient.getWarehouse(singleOrder.getWarehouse_id());
260
						warehouse = iclient.getWarehouse(singleOrder.getWarehouse_id());
253
						long providerId = singleOrder.getLogistics_provider_id();
261
						long providerId = singleOrder.getLogistics_provider_id();
Line 257... Line 265...
257
						else
265
						else
258
							destCode = logisticsClient.getDestinationCode(providerId, singleOrder.getCustomer_pincode());
266
							destCode = logisticsClient.getDestinationCode(providerId, singleOrder.getCustomer_pincode());
259
 
267
 
260
						barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
268
						barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
261
						
269
						
262
						shippingLocation = CatalogUtils.getWarehouse(warehouse.getShippingWarehouseId());
-
 
263
						invoiceFormat = tclient.getInvoiceFormatLogisticsTxnId(singleOrder.getTransactionId(), Long.parseLong(logisticsTxnId.split("-")[1])); 
270
						invoiceFormat = tclient.getInvoiceFormatLogisticsTxnId(singleOrder.getTransactionId(), Long.parseLong(logisticsTxnId.split("-")[1])); 
264
					} catch (InventoryServiceException ise) {
271
					} catch (InventoryServiceException ise) {
265
						logger.error("Error while getting the warehouse information.", ise);
272
						logger.error("Error while getting the warehouse information.", ise);
266
						return baosPDF;
273
						return baosPDF;
267
					} catch (LogisticsServiceException lse) {
274
					} catch (LogisticsServiceException lse) {
Line 305... Line 312...
305
									dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
312
									dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
306
								}
313
								}
307
							}
314
							}
308
						}
315
						}
309
						else {
316
						else {
310
							dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
317
							dispatchAdviceTable = getDispatchAdviceTable(ordersList, provider, barcodeFontSize, destCode, withBill, invoiceFormat);
311
						}
318
						}
312
					} else {
319
					} else {
313
						dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
320
						dispatchAdviceTable = getDispatchAdviceTable(ordersList, provider, barcodeFontSize, destCode, withBill, invoiceFormat);
314
					}
321
					}
315
					
322
					
316
					dispatchAdviceTable.setSpacingAfter(10.0f);
323
					dispatchAdviceTable.setSpacingAfter(10.0f);
317
					dispatchAdviceTable.setWidthPercentage(90.0f);
324
					dispatchAdviceTable.setWidthPercentage(90.0f);
318
					document.add(dispatchAdviceTable);
325
					document.add(dispatchAdviceTable);
Line 325... Line 332...
325
					
332
					
326
					if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7) &&(ordersList.size()==1)) {
333
					if ((new Long(order.getSource()).intValue() == OrderSource.EBAY.getValue()) && (order.getLogistics_provider_id()>7) &&(ordersList.size()==1)) {
327
						if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty() 
334
						if (order.getAirwaybill_no()== null || order.getAirwaybill_no().equals("null") || order.getAirwaybill_no().isEmpty() 
328
								|| order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
335
								|| order.getWarehouse_id() == 7 || order.getWarehouse_id() == 5 || order.getWarehouse_id() == 9) {
329
							if(withBill){
336
							if(withBill){
330
								PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , sellerInfo.getTin(), invoiceFormat);
337
								PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, addressInfo.getAddress() + "-" + addressInfo.getPin() , sellerInfo.getTin(), invoiceFormat);
331
								taxTable.setSpacingBefore(5.0f);
338
								taxTable.setSpacingBefore(5.0f);
332
								taxTable.setWidthPercentage(90.0f);
339
								taxTable.setWidthPercentage(90.0f);
333
								document.add(new DottedLineSeparator());
340
								document.add(new DottedLineSeparator());
334
								document.add(taxTable);
341
								document.add(taxTable);
335
							}else{
342
							}else{
Line 342... Line 349...
342
						} else {
349
						} else {
343
							document.newPage();
350
							document.newPage();
344
						}
351
						}
345
					} else if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue() &&(ordersList.size()==1)) {
352
					} else if (new Long(order.getSource()).intValue() == OrderSource.SNAPDEAL.getValue() &&(ordersList.size()==1)) {
346
						if(withBill){
353
						if(withBill){
347
							PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , sellerInfo.getTin(), invoiceFormat);
354
							PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, addressInfo.getAddress() + "-" + addressInfo.getPin() , sellerInfo.getTin(), invoiceFormat);
348
							taxTable.setSpacingBefore(5.0f);
355
							taxTable.setSpacingBefore(5.0f);
349
							taxTable.setWidthPercentage(90.0f);
356
							taxTable.setWidthPercentage(90.0f);
350
							document.add(new DottedLineSeparator());
357
							document.add(new DottedLineSeparator());
351
							document.add(taxTable);
358
							document.add(taxTable);
352
						}else{
359
						}else{
Line 356... Line 363...
356
							document.add(new DottedLineSeparator());
363
							document.add(new DottedLineSeparator());
357
							document.add(extraInfoTable);
364
							document.add(extraInfoTable);
358
						}
365
						}
359
					}
366
					}
360
					if(withBill){
367
					if(withBill){
361
						PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, shippingLocation.getLocation() + "-" + shippingLocation.getPincode() , this.sellerInfo.getTin(), invoiceFormat);
368
						PdfPTable taxTable = getTaxCumRetailInvoiceTable(ordersList, provider, addressInfo.getAddress() + "-" + addressInfo.getPin() , this.sellerInfo.getTin(), invoiceFormat);
362
						taxTable.setSpacingBefore(5.0f);
369
						taxTable.setSpacingBefore(5.0f);
363
						taxTable.setWidthPercentage(90.0f);
370
						taxTable.setWidthPercentage(90.0f);
364
						document.add(new DottedLineSeparator());
371
						document.add(new DottedLineSeparator());
365
						document.add(taxTable);
372
						document.add(taxTable);
366
						if(order.getSource() == OrderSource.FLIPKART.getValue()) {
373
						if(order.getSource() == OrderSource.FLIPKART.getValue()) {
Line 492... Line 499...
492
									dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
499
									dispatchAdviceTable = invoiceGenerationService.getDispatchAdviceTable(orderId, warehouseId);
493
								}
500
								}
494
							}
501
							}
495
						}
502
						}
496
						else {
503
						else {
497
							dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
504
							dispatchAdviceTable = getDispatchAdviceTable(ordersList, provider, barcodeFontSize, destCode, withBill, invoiceFormat);
498
						}
505
						}
499
					} else {
506
					} else {
500
						dispatchAdviceTable = getDispatchAdviceTable(ordersList, warehouse, provider, barcodeFontSize, destCode, withBill, shippingLocation, invoiceFormat);
507
						dispatchAdviceTable = getDispatchAdviceTable(ordersList, provider, barcodeFontSize, destCode, withBill, invoiceFormat);
501
					}
508
					}
502
					
509
					
503
					dispatchAdviceTable.setSpacingAfter(10.0f);
510
					dispatchAdviceTable.setSpacingAfter(10.0f);
504
					dispatchAdviceTable.setWidthPercentage(90.0f);
511
					dispatchAdviceTable.setWidthPercentage(90.0f);
505
					document.add(dispatchAdviceTable);
512
					document.add(dispatchAdviceTable);
Line 660... Line 667...
660
		} catch (Exception e) {
667
		} catch (Exception e) {
661
			logger.error("Error while generating Invoice: ", e);
668
			logger.error("Error while generating Invoice: ", e);
662
		}
669
		}
663
		return baosPDF;
670
		return baosPDF;
664
	}
671
	}
-
 
672
	//Handle this case when tClient is null
-
 
673
	private static WarehouseAddress getWarehouseAddress(long addressId, in.shop2020.model.v1.order.TransactionService.Client tClient) throws Exception{
-
 
674
		if (!whAddressInfoMap.containsKey(addressId)){
-
 
675
			whAddressInfoMap.put(addressId, tClient.getWarehouseAddress(addressId));
-
 
676
		}
-
 
677
		return whAddressInfoMap.get(addressId);
-
 
678
	}
-
 
679
	//Handle this case when tClient is null
-
 
680
	
-
 
681
	private static SellerInfo getSellerInfo(long sellerId, in.shop2020.model.v1.order.TransactionService.Client tClient) throws Exception{
-
 
682
		if (!sellerInfoMap.containsKey(sellerId)){
-
 
683
			sellerInfoMap.put(sellerId, tClient.getSellerInfo(sellerId));
-
 
684
		}
-
 
685
		return sellerInfoMap.get(sellerId);
-
 
686
	}
665
	
687
	
666
	
688
	
667
	private PdfPTable getPackagingInfoTable(List<Order> orderList) throws CatalogServiceException, TException{
689
	private PdfPTable getPackagingInfoTable(List<Order> orderList) throws CatalogServiceException, TException{
668
		PdfPTable finalTable = new PdfPTable(1);
690
		PdfPTable finalTable = new PdfPTable(1);
669
		finalTable.setWidthPercentage(90.0f);
691
		finalTable.setWidthPercentage(90.0f);
Line 726... Line 748...
726
		finalTable.addCell(customerAddresTable);
748
		finalTable.addCell(customerAddresTable);
727
		finalTable.addCell(packagingTable);
749
		finalTable.addCell(packagingTable);
728
		return finalTable;
750
		return finalTable;
729
	}
751
	}
730
 
752
 
731
	private PdfPTable getDispatchAdviceTable(List<Order> orderList, Warehouse warehouse, Provider provider, float barcodeFontSize, String destCode, boolean withBill, Warehouse shippingLocation, String invoiceFormat){
753
	private PdfPTable getDispatchAdviceTable(List<Order> orderList, Provider provider, float barcodeFontSize, String destCode, boolean withBill, String invoiceFormat){
732
		Order order = orderList.get(0);
754
		Order order = orderList.get(0);
733
		Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
755
		Font barCodeFont = getBarCodeFont(provider, barcodeFontSize);
734
		
756
		
735
		double totalAmount = 0.0;
757
		double totalAmount = 0.0;
736
		double totalWeight = 0.0;
758
		double totalWeight = 0.0;
Line 763... Line 785...
763
		PdfPTable invoiceTable = getTopInvoiceTable(orderList, this.sellerInfo.getTin(), invoiceFormat);
785
		PdfPTable invoiceTable = getTopInvoiceTable(orderList, this.sellerInfo.getTin(), invoiceFormat);
764
		PdfPTable addressTable = new PdfPTable(1);
786
		PdfPTable addressTable = new PdfPTable(1);
765
		addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
787
		addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
766
		addressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
788
		addressTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
767
		
789
		
768
		PdfPCell addressCell = getAddressCell(shippingLocation.getLocation() +
790
		PdfPCell addressCell = getAddressCell(addressInfo.getAddress() +
769
				" - " + shippingLocation.getPincode() + "\nContact No.- +91-9818116289" + "\n\n");
791
				" - " + addressInfo.getPin() + "\nContact No.- +91-9818116289" + "\n\n");
770
 
792
 
771
		PdfPTable chargesTable = new PdfPTable(1);
793
		PdfPTable chargesTable = new PdfPTable(1);
772
		chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
794
		chargesTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
773
		chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
795
		chargesTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
774
		if(order.isLogisticsCod()){
796
		if(order.isLogisticsCod()){