Subversion Repositories SmartDukaan

Rev

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

Rev 5020 Rev 5098
Line 142... Line 142...
142
	private Map<Long, String> paymentGateways = new HashMap<Long, String>();
142
	private Map<Long, String> paymentGateways = new HashMap<Long, String>();
143
	
143
	
144
	private String reportSource;
144
	private String reportSource;
145
	private List<Long> orderIdsWithoutSuccess;
145
	private List<Long> orderIdsWithoutSuccess;
146
	
146
	
-
 
147
	private File orderIdsToBeMarkedPaid;
147
	private File hdfcSettlementReport;
148
	private File hdfcSettlementReport;
148
	
149
	
149
	private File ebsSettlementReport;
150
	private File ebsSettlementReport;
150
	private File ebsSettlementSummary;
151
	private File ebsSettlementSummary;
151
	
152
	
Line 167... Line 168...
167
	
168
	
168
	private final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
169
	private final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
169
	
170
	
170
	private int rowCount = 0;
171
	private int rowCount = 0;
171
	
172
	
172
	public VendorReconciliationController()	{
-
 
173
		try	{
-
 
174
			CatalogClient csc = new CatalogClient();
-
 
175
			Client catalogClient = csc.getClient();
-
 
176
			OrderStatusGroups orderStatusGroups = new OrderStatusGroups();
-
 
177
			refundOrderStatuses = orderStatusGroups.getRefundedOrders();
-
 
178
			
-
 
179
			vendors = catalogClient.getAllVendors();
-
 
180
			orderIdsWithoutSuccess = new ArrayList<Long>();
-
 
181
			
-
 
182
			TransactionClient tsc = new TransactionClient();
-
 
183
			in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
-
 
184
			
-
 
185
			ebsSettlementSummaries = transactionClient.getEBSSettlementSummaries();
-
 
186
			logger.info("", ebsSettlementSummaries);
-
 
187
			
-
 
188
		} catch (TException e) {
-
 
189
			logger.error("TException", e);
-
 
190
			
-
 
191
		} catch (TransactionServiceException e) {
-
 
192
			logger.error("TransactionServiceException", e);
-
 
193
		}
-
 
194
	}
-
 
195
	
-
 
196
	public String index()	{
173
	public String index()	{
-
 
174
		initiatializeDashboard();
197
		return "report";
175
		return "report";
198
	}
176
	}
199
	
177
	
200
	public HttpHeaders create()	{
178
	public HttpHeaders create()	{
201
		
179
		
Line 214... Line 192...
214
		} else if (formType.equals("uploadBluedartSettlements")) {
192
		} else if (formType.equals("uploadBluedartSettlements")) {
215
			uploadBluedartSettlements();
193
			uploadBluedartSettlements();
216
			
194
			
217
		} else if (formType.equals("uploadAramexSettlements")) {
195
		} else if (formType.equals("uploadAramexSettlements")) {
218
			uploadAramexSettlements();
196
			uploadAramexSettlements();
-
 
197
			
-
 
198
		} else if (formType.equals("markOrdersAsPaid"))	{
-
 
199
//			uploadOrderIdsToBeMarkedPaid();
219
		}
200
		}
220
	    logger.info("Order Ids where no successful payment was found", orderIdsWithoutSuccess);
201
	    logger.info("Order Ids where no successful payment was found", orderIdsWithoutSuccess);
221
	    
202
 
-
 
203
		initiatializeDashboard();
222
		return new DefaultHttpHeaders("report");
204
		return new DefaultHttpHeaders("report");
223
	}
205
	}
224
	
206
	
225
	public HttpHeaders generateReconciliationReport()	{
207
	public HttpHeaders generateReconciliationReport()	{
226
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
208
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Line 538... Line 520...
538
        Sheet sheet = wb.getSheetAt(0);
520
        Sheet sheet = wb.getSheetAt(0);
539
        
521
        
540
        Row firstRow = sheet.getRow(0);
522
        Row firstRow = sheet.getRow(0);
541
        logger.info("Cell count:" + firstRow.getPhysicalNumberOfCells());
523
        logger.info("Cell count:" + firstRow.getPhysicalNumberOfCells());
542
        
524
        
543
        int indexOrderId = 16;
525
        int indexOrderId = 15;
544
        int indexAmount = 17;
526
        int indexAmount = 14;
545
        
527
        
546
        TransactionClient tsc;
528
        TransactionClient tsc;
547
    	int countSuccessfulSaves = 0;
529
    	int countSuccessfulSaves = 0;
548
        
530
        
549
        try	{
531
        try	{
Line 551... Line 533...
551
        	tsc = new TransactionClient();
533
        	tsc = new TransactionClient();
552
        	in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
534
        	in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
553
        	
535
        	
554
        	for (Row row : sheet) {
536
        	for (Row row : sheet) {
555
    			long orderId = 0;
537
    			long orderId = 0;
-
 
538
    			String orderIdString = "";
556
        		try	{
539
        		try	{
557
        			if(row.equals(firstRow))	continue;
540
        			orderIdString = row.getCell(indexOrderId).getStringCellValue(); 
558
        			orderId = Long.parseLong(row.getCell(indexOrderId).getStringCellValue());
541
        			orderId = Long.parseLong(orderIdString);
559
        			
542
        			
560
        			double amount = row.getCell(indexAmount).getNumericCellValue();
543
        			double amount = row.getCell(indexAmount).getNumericCellValue();
561
        			logger.info("Bluedart SettlementDate: " + settlementDate + ", OrderId: " + orderId + ", Amount: " + amount);
544
        			logger.info("Bluedart SettlementDate: " + settlementDate + ", OrderId: " + orderId + ", Amount: " + amount);
562
        			transactionClient.savePaymentSettlements(settlementDate, 4, orderId, 0.0, 0.0, amount);
545
        			transactionClient.savePaymentSettlements(settlementDate, 4, orderId, 0.0, 0.0, amount);
563
        			countSuccessfulSaves += 1;
546
        			countSuccessfulSaves += 1;
564
        			
547
        			
-
 
548
        		} catch (IllegalStateException e) {
-
 
549
        			logger.error("" + e);
-
 
550
				
-
 
551
        		} catch(NumberFormatException e)	{
-
 
552
        			logger.error("Extracted String: " + orderIdString + " " + e);
-
 
553
        			
565
        		} catch (NullPointerException e) {
554
        		} catch (NullPointerException e) {
566
        			logger.error("For OrderId: " + orderId + " " + e);
555
        			logger.error("For OrderId: " + orderId + " " + e);
567
        			
556
        			
568
        		} catch (TransactionServiceException e) {
557
        		} catch (TransactionServiceException e) {
569
					logger.error("For OrderId: " + orderId + " " + e);
558
					logger.error("For OrderId: " + orderId + " " + e);
Line 653... Line 642...
653
        	logger.error("" + e);
642
        	logger.error("" + e);
654
        }
643
        }
655
        addActionMessage("Successfully added Aramex settlement details for " + countSuccessfulSaves + " orders");
644
        addActionMessage("Successfully added Aramex settlement details for " + countSuccessfulSaves + " orders");
656
	}
645
	}
657
	
646
	
-
 
647
	public void uploadOrderIdsToBeMarkedPaid()	{
-
 
648
		logger.info("Uploading Order Ids to be marked as paid");
-
 
649
 
-
 
650
		Workbook wb = null;
-
 
651
        try {
-
 
652
        	wb = new XSSFWorkbook(new FileInputStream(this.orderIdsToBeMarkedPaid));
-
 
653
        } catch (FileNotFoundException e) {
-
 
654
        	addActionError(e.getMessage());
-
 
655
            logger.error("Unable to open the sheet containing orders for which vendor is paid", e);
-
 
656
        	return;
-
 
657
        } catch (IOException e) {
-
 
658
        	addActionError(e.getMessage());
-
 
659
            logger.error("Unable to open the sheet containing orders for which vendor is paid", e);
-
 
660
        	return;
-
 
661
        } catch (NullPointerException e) {
-
 
662
        	addActionError(e.getMessage());
-
 
663
        	logger.error("Unable to open the sheet containing orders for which vendor is paid", e);
-
 
664
        	return;
-
 
665
		}
-
 
666
        
-
 
667
        Sheet sheet = wb.getSheetAt(0);
-
 
668
        int indexOrderId = 0;
-
 
669
        
-
 
670
        TransactionClient tsc;
-
 
671
        int countSuccessfulSaves = 0;
-
 
672
        
-
 
673
//        try	{
-
 
674
//        	tsc = new TransactionClient();
-
 
675
//        	in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
-
 
676
//        	
-
 
677
//	    	for (Row row: sheet)	{
-
 
678
//	    		
-
 
679
//	    		if(row.getCell(indexOrderId).getStringCellValue().equals(""))	break;
-
 
680
//	    		
-
 
681
//	    		long orderId = Long.parseLong(row.getCell(indexOrderId).getStringCellValue());
-
 
682
//	    		logger.info("Aramex Settlement, Order Id: " + orderId);
-
 
683
//	    		try {
-
 
684
//	    			transactionClient.updateOrderAsPaidToVendor(orderId);
-
 
685
//					countSuccessfulSaves += 1;
-
 
686
//					
-
 
687
//				} catch (TransactionServiceException e) {
-
 
688
//					logger.error("Transaction Service Exception while getting order for id, " + orderId, e);
-
 
689
//					addActionError("Transaction Service Exception while getting order for id, " + orderId);	
-
 
690
//				}
-
 
691
//	    	}
-
 
692
//        } catch (TTransportException e) {
-
 
693
//        	addActionError(e.getMessage());
-
 
694
//        	logger.error("" + e);
-
 
695
//        	
-
 
696
//        } catch (TException e) {
-
 
697
//        	addActionError(e.getMessage());
-
 
698
//        	logger.error("" + e);
-
 
699
//        }
-
 
700
        addActionMessage("Successfully marked " + countSuccessfulSaves + " orders as paid to vendor");
-
 
701
	}
-
 
702
	
658
	// Prepares the XLS worksheet object and fills in the data with proper formatting
703
	// Prepares the XLS worksheet object and fills in the data with proper formatting
659
	private ByteArrayOutputStream getReconciliationReport(long vendorId)	{
704
	private ByteArrayOutputStream getReconciliationReport(long vendorId)	{
660
		
705
		
661
		List<PaymentSettlement> paymentSettlements = new ArrayList<PaymentSettlement>();
706
		List<PaymentSettlement> paymentSettlements = new ArrayList<PaymentSettlement>();
662
		List<PaymentSettlement> refundPaymentSettlements = new ArrayList<PaymentSettlement>();
707
		List<PaymentSettlement> refundPaymentSettlements = new ArrayList<PaymentSettlement>();
Line 971... Line 1016...
971
	    	
1016
	    	
972
	    	for (Provider provider: logisticsClient.getAllProviders())	{
1017
	    	for (Provider provider: logisticsClient.getAllProviders())	{
973
	    		codProviders.put(provider.getId(), provider.getName());
1018
	    		codProviders.put(provider.getId(), provider.getName());
974
	    	}
1019
	    	}
975
	    	
1020
	    	
-
 
1021
	    	class PaymentSettlementMap	{
-
 
1022
	    		public PaymentSettlement settlement;
-
 
1023
	    		public Payment payment;
-
 
1024
	    		public Transaction transaction;
-
 
1025
	    		public Order order;
-
 
1026
	    		
-
 
1027
	    		public PaymentSettlementMap(PaymentSettlement settlement, Payment pmt, Transaction txn, Order order)	{
-
 
1028
	    			this.settlement = settlement;
-
 
1029
	    			this.payment = pmt;
-
 
1030
	    			this.transaction = txn;
-
 
1031
	    			this.order = order;
-
 
1032
	    		}
-
 
1033
	    		
-
 
1034
	    		public PaymentSettlementMap(PaymentSettlement settlement, Payment pmt, Transaction txn)	{
-
 
1035
	    			this.settlement = settlement;
-
 
1036
	    			this.payment = pmt;
-
 
1037
	    			this.transaction = txn;
-
 
1038
	    		}
-
 
1039
	    	}
-
 
1040
 
-
 
1041
	    	List<Long> allOrderIds = new ArrayList<Long>();
-
 
1042
	    	Map<Long, PaymentSettlementMap> referenceMap = new HashMap<Long, PaymentSettlementMap>();
-
 
1043
	    	
-
 
1044
	    	for (PaymentSettlement paymentSettlement: paymentSettlements)	{
-
 
1045
	    		try {
-
 
1046
    				if(paymentSettlement.getPaymentGatewayId() == 4)	{	// If COD
-
 
1047
	    				Order order = transactionClient.getOrder(paymentSettlement.getReferenceId());
-
 
1048
	    				Transaction txn = transactionClient.getTransaction(order.getTransactionId());
-
 
1049
	    				Payment payment = paymentClient.getPaymentForTxnId(txn.getId()).get(0);
-
 
1050
	    				
-
 
1051
		    			if (order.getVendorId() == vendorId)	{
-
 
1052
		    				allOrderIds.add(order.getId());
-
 
1053
		    			}
-
 
1054
					
-
 
1055
    				} else	{	// If prepaid
-
 
1056
    					Payment payment = paymentClient.getPayment(paymentSettlement.getReferenceId());
-
 
1057
    					Transaction txn = transactionClient.getTransaction(payment.getMerchantTxnId());
-
 
1058
    					
-
 
1059
    					for (Order order: txn.getOrders())	{
-
 
1060
    						allOrderIds.add(order.getId());
-
 
1061
    					}
-
 
1062
    				}
-
 
1063
    			} catch (TransactionServiceException e) {
-
 
1064
					logger.error("TransactionServiceException " + e);
-
 
1065
				} catch (TException e) {
-
 
1066
					logger.error("TException " + e);
-
 
1067
				} catch (PaymentException e) {
-
 
1068
					logger.error("PaymentException " + e);
-
 
1069
				}
-
 
1070
	    	}
-
 
1071
	    	
976
	    	for (PaymentSettlement paymentSettlement: paymentSettlements)	{
1072
	    	for (PaymentSettlement paymentSettlement: paymentSettlements)	{
977
 
1073
 
978
    			try {
1074
    			try {
979
    				if(paymentSettlement.getPaymentGatewayId() == 4)	{	// If COD
1075
    				if(paymentSettlement.getPaymentGatewayId() == 4)	{	// If COD
980
	    				Order order = transactionClient.getOrder(paymentSettlement.getReferenceId());
1076
	    				Order order = transactionClient.getOrder(paymentSettlement.getReferenceId());
Line 1066... Line 1162...
1066
				    isFirstOrderForTransaction = false;
1162
				    isFirstOrderForTransaction = false;
1067
		    	}
1163
		    	}
1068
			}
1164
			}
1069
		}
1165
		}
1070
	}
1166
	}
1071
//9810579334
1167
	
1072
	private void outputPrepaidTransactionRows(Sheet sheet, long vendorId, PaymentSettlement paymentSettlement, Transaction txn, Payment payment)	{
1168
	private void outputPrepaidTransactionRows(Sheet sheet, long vendorId, PaymentSettlement paymentSettlement, Transaction txn, Payment payment)	{
1073
		logger.info("Printing orders for pmt Id, " + payment.getPaymentId());
1169
		logger.info("Printing orders for pmt Id, " + payment.getPaymentId());
1074
		
1170
		
1075
		boolean isFirstOrderForTransaction = true;
1171
		boolean isFirstOrderForTransaction = true;
1076
		
1172
		
Line 1137... Line 1233...
1137
	    contentRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue(txn.getCoupon_code());
1233
	    contentRow.createCell(OrderReportColumn.COUPON_CODE.getValue()).setCellValue(txn.getCoupon_code());
1138
    	contentRow.createCell(OrderReportColumn.PAYMENT_STATUS.getValue()).setCellValue(payment.getStatus().name());
1234
    	contentRow.createCell(OrderReportColumn.PAYMENT_STATUS.getValue()).setCellValue(payment.getStatus().name());
1139
    	contentRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue(payment.getPaymentId());
1235
    	contentRow.createCell(OrderReportColumn.PAYMENT_ID.getValue()).setCellValue(payment.getPaymentId());
1140
	}
1236
	}
1141
	
1237
	
-
 
1238
	private void initiatializeDashboard()	{
-
 
1239
		try	{
-
 
1240
			CatalogClient csc = new CatalogClient();
-
 
1241
			Client catalogClient = csc.getClient();
-
 
1242
			OrderStatusGroups orderStatusGroups = new OrderStatusGroups();
-
 
1243
			refundOrderStatuses = orderStatusGroups.getRefundedOrders();
-
 
1244
			
-
 
1245
			vendors = catalogClient.getAllVendors();
-
 
1246
			orderIdsWithoutSuccess = new ArrayList<Long>();
-
 
1247
			
-
 
1248
			TransactionClient tsc = new TransactionClient();
-
 
1249
			in.shop2020.model.v1.order.TransactionService.Client transactionClient = tsc.getClient();
-
 
1250
			
-
 
1251
			ebsSettlementSummaries = transactionClient.getEBSSettlementSummaries();
-
 
1252
			logger.info("", ebsSettlementSummaries);
-
 
1253
			
-
 
1254
		} catch (TException e) {
-
 
1255
			logger.error("TException", e);
-
 
1256
			
-
 
1257
		} catch (TransactionServiceException e) {
-
 
1258
			logger.error("TransactionServiceException", e);
-
 
1259
		}
-
 
1260
	}
-
 
1261
	
1142
	public List<Vendor> getAllVendors()	{
1262
	public List<Vendor> getAllVendors()	{
1143
		return this.vendors;
1263
		return this.vendors;
1144
	}
1264
	}
1145
 
1265
 
1146
	private String getValueForEmptyString(String s){
1266
	private String getValueForEmptyString(String s){
Line 1242... Line 1362...
1242
	}
1362
	}
1243
	
1363
	
1244
	public Map<Long, String> getEBSSettlementSummaries()	{
1364
	public Map<Long, String> getEBSSettlementSummaries()	{
1245
		return ebsSettlementSummaries;
1365
		return ebsSettlementSummaries;
1246
	}
1366
	}
-
 
1367
 
-
 
1368
	public void setOrderIdsToBeMarkedPaid(File orderIdsToBeMarkedPaid) {
-
 
1369
		this.orderIdsToBeMarkedPaid = orderIdsToBeMarkedPaid;
-
 
1370
	}
-
 
1371
 
-
 
1372
	public File getOrderIdsToBeMarkedPaid() {
-
 
1373
		return orderIdsToBeMarkedPaid;
-
 
1374
	}
1247
}
1375
}
1248
1376