Subversion Repositories SmartDukaan

Rev

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

Rev 23298 Rev 23343
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.ByteArrayInputStream;
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.InputStream;
5
import java.io.InputStream;
-
 
6
import java.util.HashMap;
6
import java.util.HashSet;
7
import java.util.HashSet;
7
import java.util.List;
8
import java.util.List;
8
import java.util.Map;
9
import java.util.Map;
9
import java.util.Set;
10
import java.util.Set;
10
 
11
 
Line 36... Line 37...
36
import com.spice.profitmandi.common.model.ProfitMandiConstants;
37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
37
import com.spice.profitmandi.common.util.PdfUtils;
38
import com.spice.profitmandi.common.util.PdfUtils;
38
import com.spice.profitmandi.common.util.Utils;
39
import com.spice.profitmandi.common.util.Utils;
39
import com.spice.profitmandi.common.web.util.ResponseSender;
40
import com.spice.profitmandi.common.web.util.ResponseSender;
40
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
41
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
41
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
42
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
42
import com.spice.profitmandi.dao.entity.fofo.Customer;
43
import com.spice.profitmandi.dao.entity.fofo.Customer;
43
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
44
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
44
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
45
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
45
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
46
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
46
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
47
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
47
import com.spice.profitmandi.dao.entity.user.Address;
48
import com.spice.profitmandi.dao.entity.user.Address;
48
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
49
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
-
 
50
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
49
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
51
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
50
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
52
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
51
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
53
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
52
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
54
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
53
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
55
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
Line 79... Line 81...
79
	@Autowired
81
	@Autowired
80
	private CustomerAddressRepository customerAddressRepository;
82
	private CustomerAddressRepository customerAddressRepository;
81
	
83
	
82
	@Autowired
84
	@Autowired
83
	private InsurancePolicyRepository insurancePolicyRepository;
85
	private InsurancePolicyRepository insurancePolicyRepository;
-
 
86
	
-
 
87
	@Autowired
-
 
88
	private InsuranceProviderRepository insuranceProviderRepository;
84
 
89
 
85
	@Autowired
90
	@Autowired
86
	private CookiesProcessor cookiesProcessor;
91
	private CookiesProcessor cookiesProcessor;
87
	
92
	
88
	@Autowired
93
	@Autowired
Line 139... Line 144...
139
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
144
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
140
		Customer customer  = customerRepository.selectById(fofoOrder.getCustomerId());
145
		Customer customer  = customerRepository.selectById(fofoOrder.getCustomerId());
141
		customerAddress.setPhoneNumber(customer.getMobileNumber());
146
		customerAddress.setPhoneNumber(customer.getMobileNumber());
142
		List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
147
		List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
143
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
148
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
-
 
149
		this.addInsuranceProvider(insurancePolicies);
144
		model.addAttribute("fofoOrder", fofoOrder);
150
		model.addAttribute("fofoOrder", fofoOrder);
145
		model.addAttribute("fofoLineItems", fofoLineItems);
151
		model.addAttribute("fofoLineItems", fofoLineItems);
146
		model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
152
		model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
147
		model.addAttribute("customerBillingAddressObj", customerAddress);
153
		model.addAttribute("customerBillingAddressObj", customerAddress);
148
		model.addAttribute("paymentOptions", paymentOptions);
154
		model.addAttribute("paymentOptions", paymentOptions);
149
		model.addAttribute("insurancePolicies", insurancePolicies);
155
		model.addAttribute("insurancePolicies", insurancePolicies);
150
		return "order-details";
156
		return "order-details";
151
	}
157
	}
152
	
158
	
-
 
159
	private Map<Integer, InsuranceProvider> toInsuranceProviderIdInsuranceProvider(List<InsuranceProvider> insuranceProviders){
-
 
160
		Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = new HashMap<>();
-
 
161
		for(InsuranceProvider insuranceProvider : insuranceProviders){
-
 
162
			insuranceProviderIdInsuranceProviderMap.put(insuranceProvider.getId(), insuranceProvider);
-
 
163
		}
-
 
164
		return insuranceProviderIdInsuranceProviderMap;
-
 
165
	}
-
 
166
	
-
 
167
	private void addInsuranceProvider(List<InsurancePolicy> insurancePolicies){
-
 
168
		if(insurancePolicies.isEmpty()){
-
 
169
			return;
-
 
170
		}
-
 
171
		Set<Integer> insuranceProviderIds = new HashSet<>();
-
 
172
		for(InsurancePolicy insurancePolicy : insurancePolicies){
-
 
173
			insuranceProviderIds.add(insurancePolicy.getProviderId());
-
 
174
		}
-
 
175
		LOGGER.info("insuranceProviderIds {}", insuranceProviderIds);
-
 
176
		List<InsuranceProvider> insuranceProviders = insuranceProviderRepository.selectByIds(insuranceProviderIds);
-
 
177
		Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = this.toInsuranceProviderIdInsuranceProvider(insuranceProviders);
-
 
178
		for(InsurancePolicy insurancePolicy : insurancePolicies){
-
 
179
			insurancePolicy.setInsuranceProvider(insuranceProviderIdInsuranceProviderMap.get(insurancePolicy.getProviderId()));
-
 
180
		}
-
 
181
	}
-
 
182
	
153
	
183
	
154
	@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
184
	@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
155
	public String getSaleDetails(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException{
185
	public String getSaleDetails(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException{
156
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
186
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
157
		
187
		
158
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
188
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
159
		List<FofoOrderItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
189
		List<FofoOrderItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
160
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
190
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
161
		List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
191
		List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
162
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
192
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
-
 
193
		this.addInsuranceProvider(insurancePolicies);
163
		model.addAttribute("fofoOrder", fofoOrder);
194
		model.addAttribute("fofoOrder", fofoOrder);
164
		model.addAttribute("fofoLineItems", fofoLineItems);
195
		model.addAttribute("fofoLineItems", fofoLineItems);
165
		model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
196
		model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
166
		model.addAttribute("customerBillingAddressObj", customerAddress);
197
		model.addAttribute("customerBillingAddressObj", customerAddress);
167
		model.addAttribute("paymentOptions", paymentOptions);
198
		model.addAttribute("paymentOptions", paymentOptions);