| 22866 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 22889 |
amit.gupta |
3 |
import java.io.ByteArrayOutputStream;
|
|
|
4 |
import java.io.File;
|
|
|
5 |
import java.io.FileOutputStream;
|
|
|
6 |
import java.io.IOException;
|
|
|
7 |
import java.io.OutputStream;
|
|
|
8 |
import java.text.MessageFormat;
|
|
|
9 |
import java.time.LocalDate;
|
| 22907 |
amit.gupta |
10 |
import java.time.LocalDateTime;
|
| 22889 |
amit.gupta |
11 |
import java.time.format.DateTimeFormatter;
|
| 33314 |
ranu |
12 |
import java.util.*;
|
| 29597 |
amit.gupta |
13 |
import java.util.stream.Collectors;
|
| 22889 |
amit.gupta |
14 |
|
|
|
15 |
import javax.mail.internet.InternetAddress;
|
|
|
16 |
import javax.mail.internet.MimeMessage;
|
| 22866 |
ashik.ali |
17 |
import javax.servlet.http.HttpServletRequest;
|
|
|
18 |
|
| 22889 |
amit.gupta |
19 |
import org.apache.commons.io.FileUtils;
|
| 26655 |
amit.gupta |
20 |
import org.apache.logging.log4j.LogManager;
|
|
|
21 |
import org.apache.logging.log4j.Logger;
|
| 22993 |
amit.gupta |
22 |
import org.json.JSONObject;
|
| 22866 |
ashik.ali |
23 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23015 |
amit.gupta |
24 |
import org.springframework.beans.factory.annotation.Value;
|
| 22866 |
ashik.ali |
25 |
import org.springframework.http.ResponseEntity;
|
| 22889 |
amit.gupta |
26 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
27 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 22866 |
ashik.ali |
28 |
import org.springframework.stereotype.Controller;
|
|
|
29 |
import org.springframework.transaction.annotation.Transactional;
|
| 22889 |
amit.gupta |
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 22866 |
ashik.ali |
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
33 |
|
| 22889 |
amit.gupta |
34 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
35 |
import com.spice.profitmandi.common.model.CustomAddress;
|
|
|
36 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
|
|
37 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
|
|
38 |
import com.spice.profitmandi.common.model.CustomOrderItem;
|
|
|
39 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
|
|
40 |
import com.spice.profitmandi.common.model.GadgetCopsDocumentInsuranceModel;
|
| 30330 |
tejbeer |
41 |
import com.spice.profitmandi.common.model.InvoicePdfModel;
|
|
|
42 |
|
| 22866 |
ashik.ali |
43 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22889 |
amit.gupta |
44 |
import com.spice.profitmandi.common.util.InsuranceUtils;
|
|
|
45 |
import com.spice.profitmandi.common.util.PdfUtils;
|
|
|
46 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 22866 |
ashik.ali |
47 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 29597 |
amit.gupta |
48 |
import com.spice.profitmandi.dao.entity.catalog.RangeItem;
|
|
|
49 |
import com.spice.profitmandi.dao.entity.catalog.RangeItemPrice;
|
| 22889 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
|
|
51 |
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
|
|
|
52 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
|
|
53 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
|
|
54 |
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
|
|
|
55 |
import com.spice.profitmandi.dao.entity.dtr.ThirdPartyInvoiceSequence;
|
|
|
56 |
import com.spice.profitmandi.dao.enumuration.dtr.ThirdParty;
|
|
|
57 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 29597 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.repository.catalog.RangeItemPriceRepository;
|
|
|
59 |
import com.spice.profitmandi.dao.repository.catalog.RangeItemRepository;
|
| 22889 |
amit.gupta |
60 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 22866 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.repository.dtr.GadgetCopsInsuranceCalcRepository;
|
| 22889 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
|
|
63 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
|
|
64 |
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
|
|
|
65 |
import com.spice.profitmandi.dao.repository.dtr.ThirdPartyInvoiceSequenceRepository;
|
|
|
66 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
67 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
| 22898 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 22889 |
amit.gupta |
69 |
import com.spice.profitmandi.service.pricing.PricingService;
|
|
|
70 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 33514 |
tejus.loha |
71 |
import com.spice.profitmandi.dao.service.OtpProcessor;
|
| 22866 |
ashik.ali |
72 |
|
| 22889 |
amit.gupta |
73 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
74 |
|
| 22866 |
ashik.ali |
75 |
@Controller
|
| 22889 |
amit.gupta |
76 |
@Transactional(rollbackFor = Throwable.class)
|
| 22866 |
ashik.ali |
77 |
public class InsuranceController {
|
| 23568 |
govind |
78 |
private static final Logger LOGGER = LogManager.getLogger(InsuranceController.class);
|
| 22889 |
amit.gupta |
79 |
private static final String gadgetCopsFilePath = "/GadgetCops";
|
| 22866 |
ashik.ali |
80 |
|
|
|
81 |
@Autowired
|
| 29597 |
amit.gupta |
82 |
private RangeItemPriceRepository rangeItemPriceRepository;
|
| 30330 |
tejbeer |
83 |
|
| 29597 |
amit.gupta |
84 |
@Autowired
|
|
|
85 |
private RangeItemRepository rangeItemRepository;
|
| 30330 |
tejbeer |
86 |
|
|
|
87 |
// This is now unused as we are not supporting multiple companies.
|
| 23015 |
amit.gupta |
88 |
@Value("${fofo.warehouseIds}")
|
| 30330 |
tejbeer |
89 |
private int[] warehouseIds;
|
| 22889 |
amit.gupta |
90 |
|
| 30330 |
tejbeer |
91 |
@Autowired
|
|
|
92 |
OtpProcessor otpProcessor;
|
|
|
93 |
|
| 22889 |
amit.gupta |
94 |
@RequestMapping(value = ProfitMandiConstants.URL_INSURANCE_GADGET_COPS_MAPPING, method = RequestMethod.GET)
|
|
|
95 |
public ResponseEntity<?> getById(HttpServletRequest request) {
|
|
|
96 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 30330 |
tejbeer |
97 |
Map<Integer, List<RangeItemPrice>> rangeItemPrices = rangeItemPriceRepository.selectAll().stream()
|
|
|
98 |
.collect(Collectors.groupingBy(RangeItemPrice::getRangeItemId, Collectors.toList()));
|
| 29597 |
amit.gupta |
99 |
List<RangeItem> rangeItems = rangeItemRepository.selectAll();
|
| 30330 |
tejbeer |
100 |
rangeItems.stream().forEach(x -> x.setRangeItemPrices(rangeItemPrices.get(x.getId())));
|
| 29597 |
amit.gupta |
101 |
return responseSender.ok(rangeItems);
|
| 22889 |
amit.gupta |
102 |
}
|
|
|
103 |
|
|
|
104 |
@Autowired
|
| 22866 |
ashik.ali |
105 |
ResponseSender<?> responseSender;
|
| 30330 |
tejbeer |
106 |
|
| 29597 |
amit.gupta |
107 |
@Autowired
|
|
|
108 |
GadgetCopsInsuranceCalcRepository gadgetCopsInsuranceCalcRepository;
|
| 22889 |
amit.gupta |
109 |
|
|
|
110 |
@Autowired
|
|
|
111 |
ThirdPartyInvoiceSequenceRepository thirdPartyInvoiceSequenceRepository;
|
|
|
112 |
|
|
|
113 |
@Autowired
|
|
|
114 |
DocumentRepository documentRepository;
|
|
|
115 |
|
|
|
116 |
@Autowired
|
|
|
117 |
InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
| 30330 |
tejbeer |
118 |
|
| 22889 |
amit.gupta |
119 |
@Autowired
|
|
|
120 |
InsurancePolicyRepository insurancePolicyRepository;
|
|
|
121 |
|
|
|
122 |
@Autowired
|
|
|
123 |
PricingService pricingService;
|
| 30330 |
tejbeer |
124 |
|
| 22866 |
ashik.ali |
125 |
@Autowired
|
| 22889 |
amit.gupta |
126 |
JavaMailSender mailSender;
|
|
|
127 |
|
|
|
128 |
@Autowired
|
|
|
129 |
InsuranceProviderRepository insuranceProviderRepository;
|
|
|
130 |
|
|
|
131 |
@Autowired
|
|
|
132 |
UserAccountRepository userAccountRepository;
|
| 30330 |
tejbeer |
133 |
|
| 22889 |
amit.gupta |
134 |
@Autowired
|
|
|
135 |
WalletService walletService;
|
|
|
136 |
|
|
|
137 |
@Autowired
|
| 22898 |
amit.gupta |
138 |
UserWalletRepository userWalletRepositoy;
|
|
|
139 |
|
|
|
140 |
@Autowired
|
| 22889 |
amit.gupta |
141 |
PolicyNumberGenerationSequenceRepository policyNumberGenerationSequenceRepository;
|
|
|
142 |
|
|
|
143 |
@RequestMapping(value = ProfitMandiConstants.URL_DAMAGE_INSURANCE, method = RequestMethod.POST)
|
| 23015 |
amit.gupta |
144 |
public ResponseEntity<?> createDamageProtection(HttpServletRequest request,
|
| 22889 |
amit.gupta |
145 |
@RequestBody GadgetCopsDocumentInsuranceModel insuranceModel) throws Throwable {
|
| 30330 |
tejbeer |
146 |
insuranceModel
|
|
|
147 |
.setCustomerDateOfBirth(StringUtils.fromHypendatedDate(insuranceModel.getCustomerDateOfBirthString()));
|
| 22896 |
amit.gupta |
148 |
insuranceModel.setInvoiceCreationDate(LocalDate.now());
|
| 22893 |
amit.gupta |
149 |
insuranceModel.validate();
|
|
|
150 |
int userId = (int) request.getAttribute("userId");
|
|
|
151 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
152 |
PolicyNumberGenerationSequence policyNumberGenerationSequence = null;
|
|
|
153 |
try {
|
|
|
154 |
policyNumberGenerationSequence = policyNumberGenerationSequenceRepository.select();
|
|
|
155 |
policyNumberGenerationSequence.setSequence(policyNumberGenerationSequence.getSequence() + 1);
|
|
|
156 |
policyNumberGenerationSequenceRepository.persist(policyNumberGenerationSequence);
|
|
|
157 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
158 |
policyNumberGenerationSequence = new PolicyNumberGenerationSequence();
|
|
|
159 |
policyNumberGenerationSequence.setSequence(1);
|
|
|
160 |
policyNumberGenerationSequenceRepository.persist(policyNumberGenerationSequence);
|
|
|
161 |
}
|
|
|
162 |
String policyNumber = StringUtils.generatePolicyNumber(ProfitMandiConstants.POLICY_NUMBER_PREFIX,
|
|
|
163 |
policyNumberGenerationSequence.getSequence());
|
| 22889 |
amit.gupta |
164 |
|
| 22893 |
amit.gupta |
165 |
InsuranceProvider insuranceProvider = insuranceProviderRepository
|
|
|
166 |
.selectByName(ProfitMandiConstants.GADGET_COPS);
|
|
|
167 |
Set<Float> devicePriceSet = new HashSet<>();
|
|
|
168 |
devicePriceSet.add(insuranceModel.getPrice());
|
|
|
169 |
Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap = pricingService.getInsurancePrices(devicePriceSet,
|
|
|
170 |
ProfitMandiConstants.GADGET_COPS);
|
|
|
171 |
InsurancePolicy insurancePolicy = new InsurancePolicy();
|
|
|
172 |
insurancePolicy.setInvoiceNumber(insuranceModel.getInvoiceNumber());
|
|
|
173 |
insurancePolicy.setRetailerId(uc.getUserId());
|
|
|
174 |
insurancePolicy.setPurchaseAmount(insurancePricesMap.get(insuranceModel.getPrice()).getDealerPrice());
|
|
|
175 |
insurancePolicy.setSaleAmount(insurancePricesMap.get(insuranceModel.getPrice()).getSellingPrice());
|
|
|
176 |
insurancePolicy.setSellingPrice(insuranceModel.getPrice());
|
|
|
177 |
insurancePolicy.setSerialNumber(insuranceModel.getSerialNumber());
|
|
|
178 |
insurancePolicy.setModelName(insuranceModel.getModelName());
|
|
|
179 |
insurancePolicy.setBrand(insuranceModel.getBrand());
|
|
|
180 |
insurancePolicy.setPolicyNumber(policyNumber);
|
|
|
181 |
insurancePolicy.setProviderId(insuranceProvider.getId());
|
|
|
182 |
insurancePolicy.setCustomerFirstName(insuranceModel.getCustomerFirstName());
|
|
|
183 |
insurancePolicy.setCustomerLastName(insuranceModel.getCustomerFirstName());
|
|
|
184 |
insurancePolicy.setCustomerMobileNumber(insuranceModel.getCustomerMobileNumber());
|
|
|
185 |
insurancePolicy.setCustomerEmailId(insuranceModel.getCustomerEmailId());
|
|
|
186 |
insurancePolicy.setCustomerDateOfBirth(insuranceModel.getCustomerDateOfBirth());
|
|
|
187 |
insurancePolicy.setCustomerAddress1(insuranceModel.getCustomerAddress1());
|
|
|
188 |
insurancePolicy.setCustomerAddress2(insuranceModel.getCustomerAddress2());
|
|
|
189 |
insurancePolicy.setCustomerCity(insuranceModel.getCustomerCity());
|
|
|
190 |
insurancePolicy.setCustomerPinCode(insuranceModel.getCustomerPinCode());
|
|
|
191 |
insurancePolicy.setCustomerState(insuranceModel.getCustomerState());
|
|
|
192 |
insurancePolicyRepository.persist(insurancePolicy);
|
| 22915 |
amit.gupta |
193 |
insuranceModel.setPolicyNumber(insurancePolicy.getPolicyNumber());
|
| 30330 |
tejbeer |
194 |
String walletDescription = "Purchased Damage Protection policy " + insurancePolicy.getPolicyNumber() + " for "
|
|
|
195 |
+ insurancePolicy.getCustomerFirstName();
|
|
|
196 |
|
|
|
197 |
walletService.consumeAmountFromWallet(uc.getUserId(), insurancePolicy.getId(),
|
|
|
198 |
WalletReferenceType.DAMAGE_PROTECTION, walletDescription, insurancePolicy.getSaleAmount(),
|
|
|
199 |
LocalDateTime.now());
|
|
|
200 |
|
|
|
201 |
try {
|
| 22893 |
amit.gupta |
202 |
InsuranceUtils.submitToGadgetCops(insuranceModel);
|
|
|
203 |
insurancePolicy.setPosted(true);
|
| 30330 |
tejbeer |
204 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
205 |
LOGGER.info("Unable to submit insurance policy details to {}", insuranceProvider.getName(),
|
|
|
206 |
profitMandiBusinessException);
|
| 22994 |
amit.gupta |
207 |
throw new ProfitMandiBusinessException("", "", "GDTCPSServerDown_1000");
|
| 22893 |
amit.gupta |
208 |
}
|
| 30330 |
tejbeer |
209 |
insurancePolicyRepository.persist(insurancePolicy);
|
| 22889 |
amit.gupta |
210 |
|
| 30330 |
tejbeer |
211 |
InvoicePdfModel pdfModel = this.getInvoicePdfModel(insurancePolicy);
|
| 22893 |
amit.gupta |
212 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 24873 |
amit.gupta |
213 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 22889 |
amit.gupta |
214 |
|
| 22893 |
amit.gupta |
215 |
Document deviceDocument = documentRepository.selectById(insuranceModel.getDeviceImageDocumentId());
|
|
|
216 |
File deviceImg = new File(deviceDocument.getPath() + deviceDocument.getName());
|
|
|
217 |
Document invoiceDocument = documentRepository.selectById(insuranceModel.getDeviceImageDocumentId());
|
|
|
218 |
File deviceInvoiceImg = new File(invoiceDocument.getPath() + invoiceDocument.getName());
|
| 22889 |
amit.gupta |
219 |
|
| 30330 |
tejbeer |
220 |
List<File> attachments = this.savePolicyDocs(insurancePolicy.getPolicyNumber(), byteArrayOutputStream,
|
|
|
221 |
deviceImg, deviceInvoiceImg);
|
| 22893 |
amit.gupta |
222 |
String messageText = MessageFormat.format(
|
|
|
223 |
"Dear {0}, Thank you for purchasing Damage Protection Plan. Your Policy number is {1}",
|
|
|
224 |
insurancePolicy.getCustomerFirstName(), insurancePolicy.getPolicyNumber());
|
| 30330 |
tejbeer |
225 |
// TODO: add template if needed
|
| 28307 |
amit.gupta |
226 |
otpProcessor.sendSms("", messageText, insurancePolicy.getCustomerMobileNumber());
|
| 23015 |
amit.gupta |
227 |
messageText += "\n Please find your Invoice and Documents submitted by you.";
|
| 22913 |
amit.gupta |
228 |
String subject = "Your Gadget Cop damage Protection purchase is successful";
|
| 30330 |
tejbeer |
229 |
this.sendMailWithAttachments(insuranceModel.getCustomerEmailId(), subject, messageText, attachments);
|
| 22913 |
amit.gupta |
230 |
|
| 30330 |
tejbeer |
231 |
float taxableInsuranceMargin = (insurancePolicy.getSaleAmount() - insurancePolicy.getPurchaseAmount())
|
|
|
232 |
/ (1 + ProfitMandiConstants.INSURANCE_TAX_RATE / 100);
|
|
|
233 |
walletService.addAmountToWallet(uc.getUserId(), insurancePolicy.getId(), WalletReferenceType.CASHBACK,
|
|
|
234 |
"Cashback against insurance policy", taxableInsuranceMargin, LocalDateTime.now());
|
| 22889 |
amit.gupta |
235 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22993 |
amit.gupta |
236 |
JSONObject jsonObject = new JSONObject();
|
| 23000 |
amit.gupta |
237 |
jsonObject.put("policyNumber", insurancePolicy.getPolicyNumber());
|
|
|
238 |
jsonObject.put("premiumCharged", insurancePolicy.getSaleAmount());
|
| 22997 |
amit.gupta |
239 |
return responseSender.ok(jsonObject.toString());
|
| 22866 |
ashik.ali |
240 |
}
|
| 22889 |
amit.gupta |
241 |
|
| 30330 |
tejbeer |
242 |
private void sendMailWithAttachments(String email, String subject, String body, List<File> attachments)
|
|
|
243 |
throws Exception {
|
|
|
244 |
|
|
|
245 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
246 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
247 |
helper.setSubject(subject);
|
|
|
248 |
helper.setText(body);
|
|
|
249 |
String[] cc = { "backup@shop2020.in", "gadgetcops.01@gmail.com" };
|
|
|
250 |
// String[] cc = {"amit.gupta@shop2020.in"};
|
|
|
251 |
helper.setCc(cc);
|
|
|
252 |
helper.setTo(email);
|
|
|
253 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
|
|
254 |
helper.setTo("help@smartdukaan.com");
|
|
|
255 |
helper.setFrom(senderAddress);
|
|
|
256 |
for (File file : attachments) {
|
|
|
257 |
helper.addAttachment(file.getName(), file);
|
|
|
258 |
}
|
|
|
259 |
mailSender.send(message);
|
|
|
260 |
|
| 22889 |
amit.gupta |
261 |
}
|
|
|
262 |
|
|
|
263 |
private List<File> savePolicyDocs(String policyNumber, ByteArrayOutputStream pdfInvoiceStream, File deviceImg,
|
|
|
264 |
File deviceInvoiceImg) throws Exception {
|
|
|
265 |
// save file to gadgetCops/policyname
|
|
|
266 |
String policyFolderPath = gadgetCopsFilePath + File.separator + policyNumber;
|
|
|
267 |
File destDeviceInvoiceImg = new File(policyFolderPath + File.separator + "deviceInvoice.jpg");
|
|
|
268 |
File destDeviceImg = new File(policyFolderPath + File.separator + "device.jpg");
|
|
|
269 |
FileUtils.copyFile(deviceImg, destDeviceImg);
|
|
|
270 |
FileUtils.copyFile(deviceInvoiceImg, destDeviceInvoiceImg);
|
|
|
271 |
|
|
|
272 |
OutputStream outStream = null;
|
|
|
273 |
try {
|
|
|
274 |
outStream = new FileOutputStream(policyFolderPath + File.separator + "invoice.pdf");
|
|
|
275 |
pdfInvoiceStream.writeTo(outStream);
|
| 22911 |
amit.gupta |
276 |
pdfInvoiceStream.flush();
|
| 22889 |
amit.gupta |
277 |
} catch (IOException e) {
|
|
|
278 |
e.printStackTrace();
|
|
|
279 |
} finally {
|
|
|
280 |
outStream.close();
|
|
|
281 |
pdfInvoiceStream.close();
|
|
|
282 |
}
|
| 30330 |
tejbeer |
283 |
|
| 22889 |
amit.gupta |
284 |
File pdfInvoice = new File(policyFolderPath + File.separator + "invoice.pdf");
|
|
|
285 |
return Arrays.asList(pdfInvoice, destDeviceImg, destDeviceInvoiceImg);
|
|
|
286 |
}
|
|
|
287 |
|
| 22907 |
amit.gupta |
288 |
public String getFormattedDate(LocalDateTime localDate) {
|
| 22889 |
amit.gupta |
289 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
|
|
|
290 |
return localDate.format(formatter);
|
|
|
291 |
}
|
|
|
292 |
|
| 30330 |
tejbeer |
293 |
private InvoicePdfModel getInvoicePdfModel(InsurancePolicy insurancePolicy) throws ProfitMandiBusinessException {
|
| 22889 |
amit.gupta |
294 |
|
| 30330 |
tejbeer |
295 |
InvoicePdfModel pdfModel = new InvoicePdfModel();
|
| 22889 |
amit.gupta |
296 |
pdfModel.setAuther("profitmandi");
|
|
|
297 |
pdfModel.setTitle("Retailer Invoice");
|
| 22907 |
amit.gupta |
298 |
pdfModel.setInvoiceDate(getFormattedDate(insurancePolicy.getCreateTimestamp()));
|
| 22889 |
amit.gupta |
299 |
|
|
|
300 |
// insurance calculation
|
| 33314 |
ranu |
301 |
List<CustomInsurancePolicy> customInsurancePolicies = new ArrayList<>();
|
| 22889 |
amit.gupta |
302 |
final float totalInsuranceTaxRate = 18;
|
|
|
303 |
|
|
|
304 |
float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
|
|
|
305 |
CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
|
|
|
306 |
customInsurancePolicy.setDescription("Damage Protection Plan for device IMEI #"
|
|
|
307 |
+ insurancePolicy.getSerialNumber() + "\n Certificate No. " + insurancePolicy.getPolicyNumber());
|
|
|
308 |
customInsurancePolicy.setHsnCode("998716");
|
|
|
309 |
customInsurancePolicy.setRate(taxableInsurancePrice);
|
|
|
310 |
customInsurancePolicy.setIgstRate(18);
|
|
|
311 |
customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 / 100);
|
|
|
312 |
customInsurancePolicy.setCgstRate(9);
|
|
|
313 |
customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 / 100);
|
|
|
314 |
customInsurancePolicy.setSgstRate(9);
|
|
|
315 |
customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 / 100);
|
|
|
316 |
customInsurancePolicy.setNetAmount(insurancePolicy.getSaleAmount());
|
|
|
317 |
customInsurancePolicies.add(customInsurancePolicy);
|
|
|
318 |
|
|
|
319 |
pdfModel.setInsurancePolicies(customInsurancePolicies);
|
|
|
320 |
CustomCustomer customCustomer = new CustomCustomer();
|
|
|
321 |
customCustomer.setFirstName(insurancePolicy.getCustomerFirstName());
|
|
|
322 |
customCustomer.setLastName(insurancePolicy.getCustomerLastName());
|
|
|
323 |
customCustomer.setEmailId(insurancePolicy.getCustomerEmailId());
|
|
|
324 |
customCustomer.setMobileNumber(insurancePolicy.getCustomerMobileNumber());
|
|
|
325 |
|
|
|
326 |
CustomAddress customAddress = new CustomAddress();
|
|
|
327 |
customAddress.setName(insurancePolicy.getCustomerFirstName() + " " + insurancePolicy.getCustomerLastName());
|
|
|
328 |
customAddress.setLine1(insurancePolicy.getCustomerAddress1());
|
|
|
329 |
customAddress.setLine2(insurancePolicy.getCustomerAddress2());
|
|
|
330 |
customAddress.setLandmark("");
|
|
|
331 |
customAddress.setCity(insurancePolicy.getCustomerCity());
|
|
|
332 |
customAddress.setPinCode(insurancePolicy.getCustomerPinCode());
|
|
|
333 |
customAddress.setState(insurancePolicy.getCustomerState());
|
|
|
334 |
customAddress.setPhoneNumber(insurancePolicy.getCustomerMobileNumber());
|
|
|
335 |
customCustomer.setAddress(customAddress);
|
|
|
336 |
pdfModel.setCustomer(customCustomer);
|
|
|
337 |
|
|
|
338 |
// TODO get invoice number for damageProtection provider
|
|
|
339 |
pdfModel.setInvoiceNumber(thirdPartyInvoiceSequenceRepository.getNextSequence(ThirdParty.GADGET_COP));
|
|
|
340 |
pdfModel.setTotalAmount(gadgetCopsInsuranceCalcRepository.selectByPrice(insurancePolicy.getSellingPrice()));
|
|
|
341 |
|
|
|
342 |
// Here bill is generated on behalf of GadgetCop
|
|
|
343 |
ThirdPartyInvoiceSequence damageProtectionProvider = thirdPartyInvoiceSequenceRepository
|
|
|
344 |
.selectByThirdParty(ThirdParty.GADGET_COP);
|
|
|
345 |
// Gadget Cop
|
|
|
346 |
// Gadget cop mobile
|
|
|
347 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
348 |
customRetailer.setBusinessName(damageProtectionProvider.getName());
|
|
|
349 |
customRetailer.setMobileNumber(damageProtectionProvider.getMobileNumber());
|
|
|
350 |
customRetailer.setGstNumber(damageProtectionProvider.getGstNumber());
|
| 30330 |
tejbeer |
351 |
// customRetailer.setAddress(address);
|
|
|
352 |
|
| 22889 |
amit.gupta |
353 |
CustomAddress providerAddress = new CustomAddress();
|
|
|
354 |
providerAddress.setCity(damageProtectionProvider.getCity());
|
|
|
355 |
providerAddress.setLine1(damageProtectionProvider.getLine1());
|
|
|
356 |
providerAddress.setLine2(damageProtectionProvider.getLine2());
|
|
|
357 |
providerAddress.setPinCode(damageProtectionProvider.getPin());
|
|
|
358 |
providerAddress.setPhoneNumber(damageProtectionProvider.getMobileNumber());
|
|
|
359 |
providerAddress.setState(damageProtectionProvider.getState());
|
| 30330 |
tejbeer |
360 |
|
| 22912 |
amit.gupta |
361 |
customRetailer.setAddress(providerAddress);
|
| 22889 |
amit.gupta |
362 |
pdfModel.setRetailer(customRetailer);
|
|
|
363 |
|
| 33314 |
ranu |
364 |
List<CustomOrderItem> customerFofoOrderItems = new ArrayList<>();
|
| 22889 |
amit.gupta |
365 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 23001 |
amit.gupta |
366 |
pdfModel.setTncs(Arrays.asList("Please check out Policy Schedule for detailed terms and conditions."));
|
| 22889 |
amit.gupta |
367 |
return pdfModel;
|
|
|
368 |
}
|
|
|
369 |
|
| 22866 |
ashik.ali |
370 |
}
|