Subversion Repositories SmartDukaan

Rev

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

Rev 23001 Rev 23015
Line 23... Line 23...
23
import org.apache.commons.io.FileUtils;
23
import org.apache.commons.io.FileUtils;
24
import org.json.JSONObject;
24
import org.json.JSONObject;
25
import org.slf4j.Logger;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
26
import org.slf4j.LoggerFactory;
27
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.beans.factory.annotation.Autowired;
-
 
28
import org.springframework.beans.factory.annotation.Value;
28
import org.springframework.http.ResponseEntity;
29
import org.springframework.http.ResponseEntity;
29
import org.springframework.mail.javamail.JavaMailSender;
30
import org.springframework.mail.javamail.JavaMailSender;
30
import org.springframework.mail.javamail.MimeMessageHelper;
31
import org.springframework.mail.javamail.MimeMessageHelper;
31
import org.springframework.stereotype.Controller;
32
import org.springframework.stereotype.Controller;
32
import org.springframework.transaction.annotation.Transactional;
33
import org.springframework.transaction.annotation.Transactional;
Line 77... Line 78...
77
	private static final Logger LOGGER = LoggerFactory.getLogger(InsuranceController.class);
78
	private static final Logger LOGGER = LoggerFactory.getLogger(InsuranceController.class);
78
	private static final String gadgetCopsFilePath = "/GadgetCops";
79
	private static final String gadgetCopsFilePath = "/GadgetCops";
79
 
80
 
80
	@Autowired
81
	@Autowired
81
	private GadgetCopsInsuranceCalcRepository gadgetCopsInsuranceCalcRepository;
82
	private GadgetCopsInsuranceCalcRepository gadgetCopsInsuranceCalcRepository;
-
 
83
	
-
 
84
	//This is now unused as we are not supporting multiple companies.
-
 
85
	@Value("${fofo.warehouseIds}")
-
 
86
	private int[] warehouseIds; 
82
 
87
 
83
	@RequestMapping(value = ProfitMandiConstants.URL_INSURANCE_GADGET_COPS_MAPPING, method = RequestMethod.GET)
88
	@RequestMapping(value = ProfitMandiConstants.URL_INSURANCE_GADGET_COPS_MAPPING, method = RequestMethod.GET)
84
	public ResponseEntity<?> getById(HttpServletRequest request) {
89
	public ResponseEntity<?> getById(HttpServletRequest request) {
85
		LOGGER.info("requested url : " + request.getRequestURL().toString());
90
		LOGGER.info("requested url : " + request.getRequestURL().toString());
86
		List<GadgetCopsInsuranceCalc> calcList = gadgetCopsInsuranceCalcRepository.selectAll();
91
		List<GadgetCopsInsuranceCalc> calcList = gadgetCopsInsuranceCalcRepository.selectAll();
Line 123... Line 128...
123
 
128
 
124
	@Autowired
129
	@Autowired
125
	PolicyNumberGenerationSequenceRepository policyNumberGenerationSequenceRepository;
130
	PolicyNumberGenerationSequenceRepository policyNumberGenerationSequenceRepository;
126
 
131
 
127
	@RequestMapping(value = ProfitMandiConstants.URL_DAMAGE_INSURANCE, method = RequestMethod.POST)
132
	@RequestMapping(value = ProfitMandiConstants.URL_DAMAGE_INSURANCE, method = RequestMethod.POST)
128
	public ResponseEntity<?> createTheftProtection(HttpServletRequest request,
133
	public ResponseEntity<?> createDamageProtection(HttpServletRequest request,
129
			@RequestBody GadgetCopsDocumentInsuranceModel insuranceModel) throws Throwable {
134
			@RequestBody GadgetCopsDocumentInsuranceModel insuranceModel) throws Throwable {
130
		insuranceModel.setCustomerDateOfBirth(StringUtils.fromHypendatedDate(insuranceModel.getCustomerDateOfBirthString()));
135
		insuranceModel.setCustomerDateOfBirth(StringUtils.fromHypendatedDate(insuranceModel.getCustomerDateOfBirthString()));
131
		insuranceModel.setInvoiceCreationDate(LocalDate.now());
136
		insuranceModel.setInvoiceCreationDate(LocalDate.now());
132
		insuranceModel.validate();
137
		insuranceModel.validate();
133
		int userId = (int) request.getAttribute("userId");
138
		int userId = (int) request.getAttribute("userId");
Line 196... Line 201...
196
		Document deviceDocument = documentRepository.selectById(insuranceModel.getDeviceImageDocumentId());
201
		Document deviceDocument = documentRepository.selectById(insuranceModel.getDeviceImageDocumentId());
197
		File deviceImg = new File(deviceDocument.getPath() + deviceDocument.getName());
202
		File deviceImg = new File(deviceDocument.getPath() + deviceDocument.getName());
198
		Document invoiceDocument = documentRepository.selectById(insuranceModel.getDeviceImageDocumentId());
203
		Document invoiceDocument = documentRepository.selectById(insuranceModel.getDeviceImageDocumentId());
199
		File deviceInvoiceImg = new File(invoiceDocument.getPath() + invoiceDocument.getName());
204
		File deviceInvoiceImg = new File(invoiceDocument.getPath() + invoiceDocument.getName());
200
 
205
 
-
 
206
		List<File> attachments = this.savePolicyDocs(insurancePolicy.getPolicyNumber(), byteArrayOutputStream, deviceImg, deviceInvoiceImg);
201
		String messageText = MessageFormat.format(
207
		String messageText = MessageFormat.format(
202
				"Dear {0}, Thank you for purchasing Damage Protection Plan. Your Policy number is {1}",
208
				"Dear {0}, Thank you for purchasing Damage Protection Plan. Your Policy number is {1}",
203
				insurancePolicy.getCustomerFirstName(), insurancePolicy.getPolicyNumber());
209
				insurancePolicy.getCustomerFirstName(), insurancePolicy.getPolicyNumber());
204
		Utils.sendSms(messageText, insurancePolicy.getCustomerMobileNumber());
210
		Utils.sendSms(messageText, insurancePolicy.getCustomerMobileNumber());
205
		List<File> attachments = this.savePolicyDocs(insurancePolicy.getPolicyNumber(), byteArrayOutputStream, deviceImg, deviceInvoiceImg);
-
 
206
		messageText += "\n Please find your Invoice, and documents submitted by you.";
211
		messageText += "\n Please find your Invoice and Documents submitted by you.";
207
		String subject = "Your Gadget Cop damage Protection purchase is successful";
212
		String subject = "Your Gadget Cop damage Protection purchase is successful";
208
		this.sendMailWithAttachments(insuranceModel.getCustomerEmailId() , subject, messageText, attachments);
213
		this.sendMailWithAttachments(insuranceModel.getCustomerEmailId() , subject, messageText, attachments);
209
 
214
 
210
		float taxableInsuranceMargin = (insurancePolicy.getSaleAmount() - insurancePolicy.getPurchaseAmount()) / (1 + ProfitMandiConstants.INSURANCE_TAX_RATE / 100);
215
		float taxableInsuranceMargin = (insurancePolicy.getSaleAmount() - insurancePolicy.getPurchaseAmount()) / (1 + ProfitMandiConstants.INSURANCE_TAX_RATE / 100);
211
		walletService.addAmountToWallet(uc.getUserId(), insurancePolicy.getId(), WalletReferenceType.CASHBACK, "Cashback against insurance policy", 
216
		walletService.addAmountToWallet(uc.getUserId(), insurancePolicy.getId(), WalletReferenceType.CASHBACK, "Cashback against insurance policy",